diff --git a/Changes b/Changes index 47dacd5..8964577 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Changes for Perl extension DBD-SQLite. +1.22_05 Sat 11 Apr 2009 + - Setting svn:eol-style to native to prevent EOL issues (ADAMK) + 1.22_04 Sat 11 Apr 2009 - Adding support parsing attributes out of the DSN (ADAMK) - Inserted pTHX_/aTHX_ for better efficiency (suggested in #44884 by TIMB) (ISHIGAKI) diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index dd44047..850570f 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -8,7 +8,7 @@ use DynaLoader (); use vars qw($VERSION @ISA); use vars qw{$err $errstr $drh $sqlite_version}; BEGIN { - $VERSION = '1.22_04'; + $VERSION = '1.22_05'; @ISA = ('DynaLoader'); # Driver singleton diff --git a/t/28_schemachange.t b/t/28_schemachange.t index f7464fe..4c440d9 100644 --- a/t/28_schemachange.t +++ b/t/28_schemachange.t @@ -1,59 +1,59 @@ -#!/usr/bin/perl - -# This test works, but as far as I can tell this doesn't actually test -# the thing that the test was originally meant to test. - -use strict; -BEGIN { - $| = 1; - $^W = 1; -} - -use Test::More tests => 9; -use t::lib::Test; - -my $create1 = 'CREATE TABLE table1 (id INTEGER NOT NULL, name CHAR (64) NOT NULL)'; -my $create2 = 'CREATE TABLE table2 (id INTEGER NOT NULL, name CHAR (64) NOT NULL)'; -my $drop1 = 'DROP TABLE table1'; -my $drop2 = 'DROP TABLE table2'; - -# diag("Parent connecting... ($$)\n"); -SCOPE: { - my $dbh = connect_ok(); - ok( $dbh->do($create1), $create1 ); - ok( $dbh->do($create2), $create2 ); - ok( $dbh->disconnect, '->disconnect ok' ); -} - -my $pid; -# diag("Forking... ($$)"); -if ( not defined( $pid = fork() ) ) { - die("fork: $!"); - -} elsif ( $pid == 0 ) { - # Pause to let the parent connect - sleep(2); - - # diag("Child starting... ($$)"); - my $dbh = DBI->connect( - 'dbi:SQLite:dbname=foo', '', '' - ) or die 'connect failed'; - $dbh->do($drop2) or die "DROP ok"; - $dbh->disconnect or die "disconnect ok"; - # diag("Child exiting... ($$)"); - - exit(0); - -} - -SCOPE: { - # Parent process - my $dbh = connect_ok(); - # diag("Waiting for child... ($$)"); - ok( waitpid($pid, 0) != -1, "waitpid" ); - - # Make sure the child actually deleted table2 - ok( $dbh->do($drop1), $drop1 ) or diag("Error: '$DBI::errstr'"); - ok( $dbh->do($create2), $create2 ) or diag("Error: '$DBI::errstr'"); - ok( $dbh->disconnect, '->disconnect ok' ); -} +#!/usr/bin/perl + +# This test works, but as far as I can tell this doesn't actually test +# the thing that the test was originally meant to test. + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use Test::More tests => 9; +use t::lib::Test; + +my $create1 = 'CREATE TABLE table1 (id INTEGER NOT NULL, name CHAR (64) NOT NULL)'; +my $create2 = 'CREATE TABLE table2 (id INTEGER NOT NULL, name CHAR (64) NOT NULL)'; +my $drop1 = 'DROP TABLE table1'; +my $drop2 = 'DROP TABLE table2'; + +# diag("Parent connecting... ($$)\n"); +SCOPE: { + my $dbh = connect_ok(); + ok( $dbh->do($create1), $create1 ); + ok( $dbh->do($create2), $create2 ); + ok( $dbh->disconnect, '->disconnect ok' ); +} + +my $pid; +# diag("Forking... ($$)"); +if ( not defined( $pid = fork() ) ) { + die("fork: $!"); + +} elsif ( $pid == 0 ) { + # Pause to let the parent connect + sleep(2); + + # diag("Child starting... ($$)"); + my $dbh = DBI->connect( + 'dbi:SQLite:dbname=foo', '', '' + ) or die 'connect failed'; + $dbh->do($drop2) or die "DROP ok"; + $dbh->disconnect or die "disconnect ok"; + # diag("Child exiting... ($$)"); + + exit(0); + +} + +SCOPE: { + # Parent process + my $dbh = connect_ok(); + # diag("Waiting for child... ($$)"); + ok( waitpid($pid, 0) != -1, "waitpid" ); + + # Make sure the child actually deleted table2 + ok( $dbh->do($drop1), $drop1 ) or diag("Error: '$DBI::errstr'"); + ok( $dbh->do($create2), $create2 ) or diag("Error: '$DBI::errstr'"); + ok( $dbh->disconnect, '->disconnect ok' ); +} diff --git a/t/lib/Test.pm b/t/lib/Test.pm index ddad2ba..f389172 100644 --- a/t/lib/Test.pm +++ b/t/lib/Test.pm @@ -9,7 +9,7 @@ use Test::More (); use vars qw{$VERSION @ISA @EXPORT}; BEGIN { - $VERSION = '1.22_04'; + $VERSION = '1.22_05'; @ISA = qw{ Exporter }; @EXPORT = qw{ connect_ok }; diff --git a/t/rt_25460_numeric_aggregate.t b/t/rt_25460_numeric_aggregate.t index 4a4620f..653bbf4 100644 --- a/t/rt_25460_numeric_aggregate.t +++ b/t/rt_25460_numeric_aggregate.t @@ -1,61 +1,61 @@ -#!/usr/bin/perl - -use strict; -BEGIN { - $| = 1; - $^W = 1; -} - -use Test::More tests => 13; -use t::lib::Test; - -# Create the table -my $dbh = connect_ok(); -ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' ); -create table foo ( - id integer primary key not null, - mygroup varchar(255) not null, - mynumber numeric(20,3) not null -) -END_SQL - -# Fill the table -my @data = qw{ - a -2 - a 1 - b 2 - b 1 - c 3 - c -1 - d 4 - d 5 - e 6 - e 7 -}; -$dbh->begin_work; -while ( @data ) { - ok $dbh->do( - 'insert into foo ( mygroup, mynumber ) values ( ?, ? )', {}, - shift(@data), shift(@data), - ); -} -$dbh->commit; - -# Issue the group/sum/sort/limit query -my $rv = $dbh->selectall_arrayref(<<'END_SQL'); -select mygroup, sum(mynumber) as total -from foo -group by mygroup -order by total -limit 3 -END_SQL - -is_deeply( - $rv, - [ - [ 'a', -1 ], - [ 'c', 2 ], - [ 'b', 3 ], - ], - 'group/sum/sort/limit query ok' -); +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use Test::More tests => 13; +use t::lib::Test; + +# Create the table +my $dbh = connect_ok(); +ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' ); +create table foo ( + id integer primary key not null, + mygroup varchar(255) not null, + mynumber numeric(20,3) not null +) +END_SQL + +# Fill the table +my @data = qw{ + a -2 + a 1 + b 2 + b 1 + c 3 + c -1 + d 4 + d 5 + e 6 + e 7 +}; +$dbh->begin_work; +while ( @data ) { + ok $dbh->do( + 'insert into foo ( mygroup, mynumber ) values ( ?, ? )', {}, + shift(@data), shift(@data), + ); +} +$dbh->commit; + +# Issue the group/sum/sort/limit query +my $rv = $dbh->selectall_arrayref(<<'END_SQL'); +select mygroup, sum(mynumber) as total +from foo +group by mygroup +order by total +limit 3 +END_SQL + +is_deeply( + $rv, + [ + [ 'a', -1 ], + [ 'c', 2 ], + [ 'b', 3 ], + ], + 'group/sum/sort/limit query ok' +); diff --git a/t/rt_32889_prepare_cached_reexecute.t b/t/rt_32889_prepare_cached_reexecute.t index bf2575b..2bb1aa0 100644 --- a/t/rt_32889_prepare_cached_reexecute.t +++ b/t/rt_32889_prepare_cached_reexecute.t @@ -1,177 +1,177 @@ -#!/usr/bin/perl - -# Tests that executing the same prepare_cached twice without a -# finish in between does not prevent it being automatically cleaned -# up and that it does not generate a warning. - -use strict; -BEGIN { - $| = 1; - $^W = 1; -} - -use Test::More tests => 31; -use t::lib::Test; - -# Create the table -SCOPE: { - my $dbh = connect_ok(); - ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' ); - create table foo ( - id integer primary key not null - ) -END_SQL - $dbh->begin_work; - ok( $dbh->do('insert into foo values ( 1 )'), 'insert 1' ); - ok( $dbh->do('insert into foo values ( 2 )'), 'insert 2' ); - $dbh->commit; - $dbh->disconnect; -} - -# Collect the warnings -my $c = 0; -my @w = (); -$SIG{__WARN__} = sub { $c++; push @w, [ @_ ]; return }; - -# Conveniences -my $sql = 'select * from foo order by id'; - -sub fetchrow_1 { - my $row = $_[0]->fetchrow_arrayref; - is_deeply( $row, [ 1 ], 'Got row 1' ); -} - - - - - -###################################################################### -# A well-behaved non-cached statement - -SCOPE: { - my $dbh = connect_ok(); - SCOPE: { - my $sth = $dbh->prepare($sql); - } - $dbh->disconnect; - is( $c, 0, 'No warnings' ); -} - -SCOPE: { - my $dbh = connect_ok(); - SCOPE: { - my $sth = $dbh->prepare($sql); - $sth->execute; - } - $dbh->disconnect; - is( $c, 0, 'No warnings' ); -} - -SCOPE: { - my $dbh = connect_ok(); - SCOPE: { - my $sth = $dbh->prepare($sql); - $sth->execute; - fetchrow_1($sth); - } - $dbh->disconnect; - is( $c, 0, 'No warnings' ); -} - - - - - -###################################################################### -# A badly-behaved regular statement - -# Double execute, no warnings -SCOPE: { - my $dbh = connect_ok(); - SCOPE: { - my $sth = $dbh->prepare($sql); - $sth->execute; - fetchrow_1($sth); - $sth->execute; - fetchrow_1($sth); - } - $dbh->disconnect; - is( $c, 0, 'No warnings' ); -} - -# We expect a warnings from this one -SCOPE: { - my $dbh = connect_ok(); - my $sth = $dbh->prepare($sql); - $sth->execute; - fetchrow_1($sth); - $dbh->disconnect; - is( $c, 1, 'Got a warning' ); -} - - - - - -###################################################################### -# A well-behaved cached statement - -SCOPE: { - my $dbh = connect_ok(); - SCOPE: { - my $sth = $dbh->prepare_cached($sql); - } - $dbh->disconnect; - is( $c, 1, 'No warnings' ); -} - -SCOPE: { - my $dbh = connect_ok(); - SCOPE: { - my $sth = $dbh->prepare_cached($sql); - $sth->execute; - fetchrow_1($sth); - $sth->finish; - } - $dbh->disconnect; - is( $c, 1, 'No warnings' ); -} - -SCOPE: { - my $dbh = connect_ok(); - SCOPE: { - my $sth = $dbh->prepare_cached($sql); - $sth->execute; - fetchrow_1($sth); - $sth->finish; - } - SCOPE: { - my $sth = $dbh->prepare_cached($sql); - $sth->execute; - fetchrow_1($sth); - $sth->finish; - } - $dbh->disconnect; - is( $c, 1, 'No warnings' ); -} - - - - - -##################################################################### -# Badly-behaved prepare_cached (but still acceptable) - -SCOPE: { - my $dbh = connect_ok(); - SCOPE: { - my $sth = $dbh->prepare_cached($sql); - $sth->execute; - fetchrow_1($sth); - $sth->execute; - fetchrow_1($sth); - $sth->finish; - } - $dbh->disconnect; - is( $c, 1, 'No warnings' ); -} +#!/usr/bin/perl + +# Tests that executing the same prepare_cached twice without a +# finish in between does not prevent it being automatically cleaned +# up and that it does not generate a warning. + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use Test::More tests => 31; +use t::lib::Test; + +# Create the table +SCOPE: { + my $dbh = connect_ok(); + ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' ); + create table foo ( + id integer primary key not null + ) +END_SQL + $dbh->begin_work; + ok( $dbh->do('insert into foo values ( 1 )'), 'insert 1' ); + ok( $dbh->do('insert into foo values ( 2 )'), 'insert 2' ); + $dbh->commit; + $dbh->disconnect; +} + +# Collect the warnings +my $c = 0; +my @w = (); +$SIG{__WARN__} = sub { $c++; push @w, [ @_ ]; return }; + +# Conveniences +my $sql = 'select * from foo order by id'; + +sub fetchrow_1 { + my $row = $_[0]->fetchrow_arrayref; + is_deeply( $row, [ 1 ], 'Got row 1' ); +} + + + + + +###################################################################### +# A well-behaved non-cached statement + +SCOPE: { + my $dbh = connect_ok(); + SCOPE: { + my $sth = $dbh->prepare($sql); + } + $dbh->disconnect; + is( $c, 0, 'No warnings' ); +} + +SCOPE: { + my $dbh = connect_ok(); + SCOPE: { + my $sth = $dbh->prepare($sql); + $sth->execute; + } + $dbh->disconnect; + is( $c, 0, 'No warnings' ); +} + +SCOPE: { + my $dbh = connect_ok(); + SCOPE: { + my $sth = $dbh->prepare($sql); + $sth->execute; + fetchrow_1($sth); + } + $dbh->disconnect; + is( $c, 0, 'No warnings' ); +} + + + + + +###################################################################### +# A badly-behaved regular statement + +# Double execute, no warnings +SCOPE: { + my $dbh = connect_ok(); + SCOPE: { + my $sth = $dbh->prepare($sql); + $sth->execute; + fetchrow_1($sth); + $sth->execute; + fetchrow_1($sth); + } + $dbh->disconnect; + is( $c, 0, 'No warnings' ); +} + +# We expect a warnings from this one +SCOPE: { + my $dbh = connect_ok(); + my $sth = $dbh->prepare($sql); + $sth->execute; + fetchrow_1($sth); + $dbh->disconnect; + is( $c, 1, 'Got a warning' ); +} + + + + + +###################################################################### +# A well-behaved cached statement + +SCOPE: { + my $dbh = connect_ok(); + SCOPE: { + my $sth = $dbh->prepare_cached($sql); + } + $dbh->disconnect; + is( $c, 1, 'No warnings' ); +} + +SCOPE: { + my $dbh = connect_ok(); + SCOPE: { + my $sth = $dbh->prepare_cached($sql); + $sth->execute; + fetchrow_1($sth); + $sth->finish; + } + $dbh->disconnect; + is( $c, 1, 'No warnings' ); +} + +SCOPE: { + my $dbh = connect_ok(); + SCOPE: { + my $sth = $dbh->prepare_cached($sql); + $sth->execute; + fetchrow_1($sth); + $sth->finish; + } + SCOPE: { + my $sth = $dbh->prepare_cached($sql); + $sth->execute; + fetchrow_1($sth); + $sth->finish; + } + $dbh->disconnect; + is( $c, 1, 'No warnings' ); +} + + + + + +##################################################################### +# Badly-behaved prepare_cached (but still acceptable) + +SCOPE: { + my $dbh = connect_ok(); + SCOPE: { + my $sth = $dbh->prepare_cached($sql); + $sth->execute; + fetchrow_1($sth); + $sth->execute; + fetchrow_1($sth); + $sth->finish; + } + $dbh->disconnect; + is( $c, 1, 'No warnings' ); +}