Class-DBI-SQLite-0.11/0000755000175000017500000000000010321110135015636 5ustar miyagawamiyagawa00000000000000Class-DBI-SQLite-0.11/t/0000755000175000017500000000000010321110135016101 5ustar miyagawamiyagawa00000000000000Class-DBI-SQLite-0.11/t/lib/0000755000175000017500000000000010321110135016647 5ustar miyagawamiyagawa00000000000000Class-DBI-SQLite-0.11/t/lib/Film.pm0000644000175000017500000000116310303520431020101 0ustar miyagawamiyagawa00000000000000package Film; use strict; use File::Temp qw(tempdir tempfile); use base qw(Class::DBI::SQLite); BEGIN { my $dir = tempdir( CLEANUP => 1 ); my($fh, $filename) = tempfile( DIR => $dir ); __PACKAGE__->set_db('Main', "dbi:SQLite:dbname=$filename", '', '', { AutoCommit => 0 }); } __PACKAGE__->table('Movies'); __PACKAGE__->columns(Primary => qw(id)); __PACKAGE__->columns(All => qw(id title director)); sub CONSTRUCT { my $class = shift; $class->db_Main->do(<<'SQL'); CREATE TABLE Movies ( id INTEGER NOT NULL PRIMARY KEY, title VARCHAR(32) NOT NULL, director VARCHAR(64) NOT NULL ) SQL ; } Class-DBI-SQLite-0.11/t/02_table.t0000644000175000017500000000160610321110024017656 0ustar miyagawamiyagawa00000000000000use strict; use Test::More tests => 5; use Class::DBI::SQLite; use DBI; unlink './t/table.db' if -e './t/table.db'; my $dbh = DBI->connect( 'dbi:SQLite:dbname=./t/table.db', '', '', { RaiseError => 1, PrintError => 1, AutoCommit => 1 } ); $dbh->do('CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, foo INTEGER, bar TEXT)'); package Foo; use base qw(Class::DBI::SQLite); __PACKAGE__->set_db(Main => 'dbi:SQLite:dbname=./t/table.db', '', ''); __PACKAGE__->set_up_table('foo'); package main; is(Foo->table, 'foo'); is(Foo->columns, 3); my @columns = sort Foo->columns('All'); is_deeply(\@columns, [sort qw(id foo bar)]); for my $i(1 .. 10) { Foo->create({ foo => $i, bar => 'bar'. $i }); } my $obj = Foo->retrieve(3); is($obj->bar, 'bar3'); my $new_obj = Foo->create({ foo => 100, bar => 'barbar' }); is($new_obj->id, 11); END { unlink './t/table.db'; } Class-DBI-SQLite-0.11/t/00_compile.t0000644000175000017500000000011610303520431020217 0ustar miyagawamiyagawa00000000000000use strict; use Test::More tests => 1; BEGIN { use_ok 'Class::DBI::SQLite' } Class-DBI-SQLite-0.11/t/01_sqlite.t0000644000175000017500000000112210303520431020067 0ustar miyagawamiyagawa00000000000000use strict; use Test::More tests => 42; use lib 't/lib'; use Class::DBI::SQLite; use Film; Film->CONSTRUCT; for my $i (1..10) { my $film = Film->create({ title => "movie-$i", director => "director-$i", }); isa_ok $film, 'Film'; like $film->id, qr/\d+/, "id is " . $film->id; is $film->title, "movie-$i"; is $film->director, "director-$i"; } Film->dbi_commit; Film->db_Main->disconnect; my @movies = Film->retrieve_all; is @movies, 10, '10 movies out there'; my %seen; my @uniq = grep { !$seen{$_}++ } map $_->id, @movies; is @uniq, 10, "10 unique ids - @uniq"; Class-DBI-SQLite-0.11/t/03_multi_pk.t0000644000175000017500000000161710321110052020417 0ustar miyagawamiyagawa00000000000000use strict; use Test::More tests => 2; use Class::DBI::SQLite; use DBI; use Carp qw( confess ); unlink './t/multi_pk.db' if -e './t/multi_pk.db'; my $dbh = DBI->connect( 'dbi:SQLite:dbname=./t/multi_pk.db', '', '', { RaiseError => 1, PrintError => 1, AutoCommit => 1 } ); $dbh->do('CREATE TABLE multi_pk (revision INTEGER, version INTEGER, msg TEXT, PRIMARY KEY (revision,version) )'); package MultiPK; use base qw(Class::DBI::SQLite); __PACKAGE__->connection('dbi:SQLite:dbname=./t/multi_pk.db', '', ''); __PACKAGE__->set_up_table('multi_pk'); package main; my @pks = sort MultiPK->primary_columns; is_deeply( \@pks, [qw(revision version)] ); for (1..10) { MultiPK->create({ revision => $_, version => $_, msg => "version $_", }); } my $obj = MultiPK->retrieve( revision => 3, version => 3 ); is($obj->msg, 'version 3'); END { unlink './t/multi_pk.db'; } Class-DBI-SQLite-0.11/Changes0000644000175000017500000000265210321110122017132 0ustar miyagawamiyagawa00000000000000Revision history for Perl extension Class::DBI::SQLite 0.11 Thu Oct 6 02:47:28 UTC 2005 - Fixed test suite for Windows [cpan #14939] 0.10 Tue Aug 23 21:57:46 UTC 2005 - Fixed warnings when there's no PK found (Thanks to William ) 0.09 Sat Apr 16 05:35:45 JST 2005 - Fixed some bugs in Multi PK support (Thanks to David Naughton) 0.08 Thu Mar 17 18:17:34 JST 2005 - Kiss SQL::Parser goodbye (Markus Ramberg) 0.07 Fri Jan 28 03:02:10 JST 2005 - Skip REFERENCES sql clause to bypass SQL::Parser's limitation (Sebastian Riedel) 0.06 Tue Oct 19 16:44:39 JST 2004 - Removed debugging statement from the code. 0.05 Tue Oct 19 16:44:39 JST 2004 - Fixed error in PRAGMA table_info(?) with newer DBD::SQLite http://rt.cpan.org/NoAuth/Bug.html?id=7794 Thanks to Seth Gordon and Marcus Ramberg 0.04 Mon Mar 15 20:56:38 JST 2004 - Added t/02_table.t in MANIFEST (Thanks to Tony Bowden) - Added SQL::Dialects::AnyData to PREREQ_PM 0.03 Thu Feb 5 03:38:20 JST 2004 * Fixed bug that SQL::Parser barfs with TIMESTAMP column (Thanks to Aaron Straup Cope) - Fixed test failure that columns() no longer preserves its order. 0.02 Fri Aug 9 15:59:44 JST 2002 - Added tests to see commit() really works (needs Ima::DBI >= 0.27) * Added set_up_table() method (Thanks to Tomohiro Ikebe ) 0.01 Sat Feb 23 22:49:15 2002 - original version Class-DBI-SQLite-0.11/lib/0000755000175000017500000000000010321110135016404 5ustar miyagawamiyagawa00000000000000Class-DBI-SQLite-0.11/lib/Class/0000755000175000017500000000000010321110135017451 5ustar miyagawamiyagawa00000000000000Class-DBI-SQLite-0.11/lib/Class/DBI/0000755000175000017500000000000010321110135020047 5ustar miyagawamiyagawa00000000000000Class-DBI-SQLite-0.11/lib/Class/DBI/SQLite.pm0000644000175000017500000000433510321110072021553 0ustar miyagawamiyagawa00000000000000package Class::DBI::SQLite; use strict; use vars qw($VERSION); $VERSION = "0.11"; require Class::DBI; use base qw(Class::DBI); sub _auto_increment_value { my $self = shift; return $self->db_Main->func("last_insert_rowid"); } sub set_up_table { my($class, $table) = @_; # find all columns. my $sth = $class->db_Main->prepare("PRAGMA table_info('$table')"); $sth->execute(); my @columns; while (my $row = $sth->fetchrow_hashref) { push @columns, $row->{name}; } $sth->finish; # find primary key. so complex ;-( $sth = $class->db_Main->prepare(<<'SQL'); SELECT sql FROM sqlite_master WHERE tbl_name = ? SQL $sth->execute($table); my($sql) = $sth->fetchrow_array; $sth->finish; my ($primary) = $sql =~ m/ (?:\(|\,) # either a ( to start the definition or a , for next \s* # maybe some whitespace (\w+) # the col name [^,]* # anything but the end or a ',' for next column PRIMARY\sKEY/sxi; my @pks; if ($primary) { @pks = ($primary); } else { my ($pks)= $sql =~ m/PRIMARY\s+KEY\s*\(\s*([^)]+)\s*\)/; @pks = split(m/\s*\,\s*/, $pks) if $pks; } $class->table($table); $class->columns(Primary => @pks); $class->columns(All => @columns); } 1; __END__ =head1 NAME Class::DBI::SQLite - Extension to Class::DBI for sqlite =head1 SYNOPSIS package Film; use base qw(Class::DBI::SQLite); __PACKAGE__->set_db('Main', 'dbi:SQLite:dbname=dbfile', '', ''); __PACKAGE__->set_up_table('Movies'); package main; my $film = Film->create({ name => 'Bad Taste', title => 'Peter Jackson', }); my $id = $film->id; # auto-incremented =head1 DESCRIPTION Class::DBI::SQLite is an extension to Class::DBI for DBD::SQLite. It allows you to populate an auto-incremented row id after insert. The C method automates the setup of columns and primary key(s) via the SQLite PRAGMA statement. =head1 AUTHOR Tatsuhiko Miyagawa Emiyagawa@bulknews.netE C implementation by Tomohiro Ikebe Eikebe@cpan.orgE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L =cut Class-DBI-SQLite-0.11/MANIFEST0000644000175000017500000000034110321110135016765 0ustar miyagawamiyagawa00000000000000Changes lib/Class/DBI/SQLite.pm Makefile.PL MANIFEST This list of files t/00_compile.t t/01_sqlite.t t/02_table.t t/03_multi_pk.t t/lib/Film.pm META.yml Module meta-data (added by MakeMaker) Class-DBI-SQLite-0.11/Makefile.PL0000644000175000017500000000041710303520431017616 0ustar miyagawamiyagawa00000000000000use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'Class::DBI::SQLite', 'VERSION_FROM' => 'lib/Class/DBI/SQLite.pm', # finds $VERSION 'PREREQ_PM' => { 'Test::More' => 0.32, 'Class::DBI' => 0.85, 'Ima::DBI' => 0.27, 'DBD::SQLite' => 0.07, }, ); Class-DBI-SQLite-0.11/META.yml0000644000175000017500000000073410321110135017113 0ustar miyagawamiyagawa00000000000000# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Class-DBI-SQLite version: 0.11 version_from: lib/Class/DBI/SQLite.pm installdirs: site requires: Class::DBI: 0.85 DBD::SQLite: 0.07 Ima::DBI: 0.27 Test::More: 0.32 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.27