1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 14:19:10 -04:00

DBD-SQLite: made sure if private methods/functions return true after successful calls (#44871)

This commit is contained in:
Kenichi Ishigaki 2009-05-06 12:18:37 +00:00
parent b78c888711
commit 1c06ff021e
16 changed files with 63 additions and 58 deletions

View file

@ -34,7 +34,7 @@ last_insert_rowid(dbh)
OUTPUT:
RETVAL
void
static int
create_function(dbh, name, argc, func)
SV *dbh
char *name
@ -44,8 +44,10 @@ create_function(dbh, name, argc, func)
DBD::SQLite::db::sqlite_create_function = 1
CODE:
{
sqlite3_db_create_function(aTHX_ dbh, name, argc, func );
RETVAL = sqlite3_db_create_function(aTHX_ dbh, name, argc, func );
}
OUTPUT:
RETVAL
static int
enable_load_extension(dbh, onoff)

View file

@ -1288,7 +1288,10 @@ sqlite3_db_create_collation(pTHX_ SV *dbh, const char *name, SV *func )
if ( rv != SQLITE_OK )
{
char* const errmsg = form("sqlite_create_collation failed with error %s", sqlite3_errmsg(imp_dbh->db));
sqlite_error(dbh, (imp_xxh_t*)imp_dbh, rv, errmsg);
return FALSE;
}
return TRUE;
}
static int

View file

@ -16,7 +16,7 @@ BEGIN {
plan skip_all => 'requires DBI v1.608' if $DBI::VERSION < 1.608;
}
plan tests => 11;
plan tests => 12;
my $dbh = connect_ok(
RaiseError => 1,
@ -77,7 +77,7 @@ if (!defined($pid)) {
my $line = <READER>;
chomp($line);
ok($line, "Ready");
$dbh->sqlite_busy_timeout(10000);
ok($dbh->sqlite_busy_timeout(10000));
ok($dbh->do("INSERT INTO Blah VALUES (4, 'Test4' )"));
$dbh->commit;
wait;

View file

@ -9,7 +9,7 @@ BEGIN {
}
use t::lib::Test;
use Test::More tests => 11;
use Test::More tests => 12;
use Test::NoWarnings;
my $dbh = connect_ok(
@ -71,7 +71,7 @@ if (!defined($pid)) {
my $line = <READER>;
chomp($line);
ok($line, "Ready");
$dbh->func(10000, 'busy_timeout');
ok($dbh->func(10000, 'busy_timeout'));
ok($dbh->do("INSERT INTO Blah VALUES (4, 'Test4' )"));
$dbh->commit;
wait;

View file

@ -15,7 +15,7 @@ BEGIN {
plan skip_all => 'requires DBI v1.608' if $DBI::VERSION < 1.608;
}
plan tests => 19;
plan tests => 28;
sub now {
return time();
@ -59,7 +59,7 @@ sub noop {
my $dbh = connect_ok( PrintError => 0 );
$dbh->sqlite_create_function( "now", 0, \&now );
ok($dbh->sqlite_create_function( "now", 0, \&now ));
my $result = $dbh->selectrow_arrayref( "SELECT now()" );
ok( $result->[0], 'Got a result' );
@ -68,35 +68,35 @@ $dbh->do( 'CREATE TEMP TABLE func_test ( a, b )' );
$dbh->do( 'INSERT INTO func_test VALUES ( 1, 3 )' );
$dbh->do( 'INSERT INTO func_test VALUES ( 0, 4 )' );
$dbh->sqlite_create_function( "add2", 2, \&add2 );
ok($dbh->sqlite_create_function( "add2", 2, \&add2 ));
$result = $dbh->selectrow_arrayref( "SELECT add2(1,3)" );
is($result->[0], 4, "SELECT add2(1,3)" );
$result = $dbh->selectall_arrayref( "SELECT add2(a,b) FROM func_test" );
is_deeply( $result, [ [4], [4] ], "SELECT add2(a,b) FROM func_test" );
$dbh->sqlite_create_function( "my_sum", -1, \&my_sum );
ok($dbh->sqlite_create_function( "my_sum", -1, \&my_sum ));
$result = $dbh->selectrow_arrayref( "SELECT my_sum( '2', 3, 4, '5')" );
is( $result->[0], 14, "SELECT my_sum( '2', 3, 4, '5')" );
$dbh->sqlite_create_function( "error", -1, \&error );
ok($dbh->sqlite_create_function( "error", -1, \&error ));
$result = $dbh->selectrow_arrayref( "SELECT error( 'I died' )" );
ok( !$result );
like( $DBI::errstr, qr/function is dying: I died/ );
$dbh->sqlite_create_function( "void_return", -1, \&void_return );
ok($dbh->sqlite_create_function( "void_return", -1, \&void_return ));
$result = $dbh->selectrow_arrayref( "SELECT void_return( 'I died' )" );
is_deeply( $result, [ undef ], "SELECT void_return( 'I died' )" );
$dbh->sqlite_create_function( "return_null", -1, \&return_null );
ok($dbh->sqlite_create_function( "return_null", -1, \&return_null ));
$result = $dbh->selectrow_arrayref( "SELECT return_null()" );
is_deeply( $result, [ undef ], "SELECT return_null()" );
$dbh->sqlite_create_function( "return2", -1, \&return2 );
ok($dbh->sqlite_create_function( "return2", -1, \&return2 ));
$result = $dbh->selectrow_arrayref( "SELECT return2()" );
is_deeply( $result, [ 2 ], "SELECT return2()" );
$dbh->sqlite_create_function( "my_defined", 1, \&my_defined );
ok($dbh->sqlite_create_function( "my_defined", 1, \&my_defined ));
$result = $dbh->selectrow_arrayref( "SELECT my_defined(1)" );
is_deeply( $result, [ 1 ], "SELECT my_defined(1)" );
@ -109,7 +109,7 @@ is_deeply( $result, [ 1 ], "SELECT my_defined('abc')" );
$result = $dbh->selectrow_arrayref( "SELECT my_defined(NULL)" );
is_deeply( $result, [ '0' ], "SELECT my_defined(NULL)" );
$dbh->sqlite_create_function( "noop", 1, \&noop );
ok($dbh->sqlite_create_function( "noop", 1, \&noop ));
$result = $dbh->selectrow_arrayref( "SELECT noop(NULL)" );
is_deeply( $result, [ undef ], "SELECT noop(NULL)" );

View file

@ -8,7 +8,7 @@ BEGIN {
}
use t::lib::Test;
use Test::More tests => 19;
use Test::More tests => 28;
use Test::NoWarnings;
sub now {
@ -53,7 +53,7 @@ sub noop {
my $dbh = connect_ok( PrintError => 0 );
$dbh->func( "now", 0, \&now, "create_function" );
ok($dbh->func( "now", 0, \&now, "create_function" ));
my $result = $dbh->selectrow_arrayref( "SELECT now()" );
ok( $result->[0], 'Got a result' );
@ -62,35 +62,35 @@ $dbh->do( 'CREATE TEMP TABLE func_test ( a, b )' );
$dbh->do( 'INSERT INTO func_test VALUES ( 1, 3 )' );
$dbh->do( 'INSERT INTO func_test VALUES ( 0, 4 )' );
$dbh->func( "add2", 2, \&add2, "create_function" );
ok($dbh->func( "add2", 2, \&add2, "create_function" ));
$result = $dbh->selectrow_arrayref( "SELECT add2(1,3)" );
is($result->[0], 4, "SELECT add2(1,3)" );
$result = $dbh->selectall_arrayref( "SELECT add2(a,b) FROM func_test" );
is_deeply( $result, [ [4], [4] ], "SELECT add2(a,b) FROM func_test" );
$dbh->func( "my_sum", -1, \&my_sum, "create_function" );
ok($dbh->func( "my_sum", -1, \&my_sum, "create_function" ));
$result = $dbh->selectrow_arrayref( "SELECT my_sum( '2', 3, 4, '5')" );
is( $result->[0], 14, "SELECT my_sum( '2', 3, 4, '5')" );
$dbh->func( "error", -1, \&error, "create_function" );
ok($dbh->func( "error", -1, \&error, "create_function" ));
$result = $dbh->selectrow_arrayref( "SELECT error( 'I died' )" );
ok( !$result );
like( $DBI::errstr, qr/function is dying: I died/ );
$dbh->func( "void_return", -1, \&void_return, "create_function" );
ok($dbh->func( "void_return", -1, \&void_return, "create_function" ));
$result = $dbh->selectrow_arrayref( "SELECT void_return( 'I died' )" );
is_deeply( $result, [ undef ], "SELECT void_return( 'I died' )" );
$dbh->func( "return_null", -1, \&return_null, "create_function" );
ok($dbh->func( "return_null", -1, \&return_null, "create_function" ));
$result = $dbh->selectrow_arrayref( "SELECT return_null()" );
is_deeply( $result, [ undef ], "SELECT return_null()" );
$dbh->func( "return2", -1, \&return2, "create_function" );
ok($dbh->func( "return2", -1, \&return2, "create_function" ));
$result = $dbh->selectrow_arrayref( "SELECT return2()" );
is_deeply( $result, [ 2 ], "SELECT return2()" );
$dbh->func( "my_defined", 1, \&my_defined, "create_function" );
ok($dbh->func( "my_defined", 1, \&my_defined, "create_function" ));
$result = $dbh->selectrow_arrayref( "SELECT my_defined(1)" );
is_deeply( $result, [ 1 ], "SELECT my_defined(1)" );
@ -103,7 +103,7 @@ is_deeply( $result, [ 1 ], "SELECT my_defined('abc')" );
$result = $dbh->selectrow_arrayref( "SELECT my_defined(NULL)" );
is_deeply( $result, [ '0' ], "SELECT my_defined(NULL)" );
$dbh->func( "noop", 1, \&noop, "create_function" );
ok($dbh->func( "noop", 1, \&noop, "create_function" ));
$result = $dbh->selectrow_arrayref( "SELECT noop(NULL)" );
is_deeply( $result, [ undef ], "SELECT noop(NULL)" );

View file

@ -14,7 +14,7 @@ BEGIN {
plan skip_all => 'requires DBI v1.608' if $DBI::VERSION < 1.608;
}
plan tests => 16;
plan tests => 22;
# Create the aggregate test packages
SCOPE: {
@ -81,7 +81,7 @@ foreach my $val ( qw/NULL 1 'test'/ ) {
$dbh->do( "INSERT INTO aggr_test VALUES ( $val )" );
}
$dbh->sqlite_create_aggregate( "newcount", 0, "count_aggr" );
ok($dbh->sqlite_create_aggregate( "newcount", 0, "count_aggr" ));
my $result = $dbh->selectrow_arrayref( "SELECT newcount() FROM aggr_test" );
ok( $result && $result->[0] == 3 );
@ -99,7 +99,7 @@ ok( $result && !$result->[0] );
$result = $dbh->selectrow_arrayref( "SELECT newcount() FROM aggr_empty_test" );
ok( $result && !$result->[0] );
$dbh->sqlite_create_aggregate( "defined", 1, 'obj_aggregate' );
ok($dbh->sqlite_create_aggregate( "defined", 1, 'obj_aggregate' ));
$result = $dbh->selectrow_arrayref( "SELECT defined(field) FROM aggr_test" );
ok( $result && $result->[0] == 2 );
$result = $dbh->selectrow_arrayref( "SELECT defined(field) FROM aggr_test" );
@ -114,7 +114,7 @@ local $SIG{__WARN__} = sub { $last_warn = join "", @_ };
foreach my $fail ( qw/ new step finalize/ ) {
$last_warn = '';
my $aggr = new fail_aggregate( $fail );
$dbh->sqlite_create_aggregate( "fail_$fail", -1, $aggr );
ok($dbh->sqlite_create_aggregate( "fail_$fail", -1, $aggr ));
$result = $dbh->selectrow_arrayref( "SELECT fail_$fail() FROM aggr_test" );
# ok( !$result && $DBI::errstr =~ /$fail\(\) failed on request/ );
ok( !defined $result->[0] && $last_warn =~ /$fail\(\) failed on request/ );
@ -129,7 +129,7 @@ foreach my $fail ( qw/ new step finalize/ ) {
my $aggr = new fail_aggregate( 'undef' );
$last_warn = '';
$dbh->sqlite_create_aggregate( "fail_undef", -1, $aggr );
ok($dbh->sqlite_create_aggregate( "fail_undef", -1, $aggr ));
$result = $dbh->selectrow_arrayref( "SELECT fail_undef() FROM aggr_test" );
# ok( !$result && $DBI::errstr =~ /new\(\) should return a blessed reference/ );
ok( !defined $result->[0] && $last_warn =~ /new\(\) should return a blessed reference/ );

View file

@ -7,7 +7,7 @@ BEGIN {
}
use t::lib::Test;
use Test::More tests => 16;
use Test::More tests => 22;
use Test::NoWarnings;
# Create the aggregate test packages
@ -75,7 +75,7 @@ foreach my $val ( qw/NULL 1 'test'/ ) {
$dbh->do( "INSERT INTO aggr_test VALUES ( $val )" );
}
$dbh->func( "newcount", 0, "count_aggr", "create_aggregate" );
ok($dbh->func( "newcount", 0, "count_aggr", "create_aggregate" ));
my $result = $dbh->selectrow_arrayref( "SELECT newcount() FROM aggr_test" );
ok( $result && $result->[0] == 3 );
@ -93,7 +93,7 @@ ok( $result && !$result->[0] );
$result = $dbh->selectrow_arrayref( "SELECT newcount() FROM aggr_empty_test" );
ok( $result && !$result->[0] );
$dbh->func( "defined", 1, 'obj_aggregate', "create_aggregate" );
ok($dbh->func( "defined", 1, 'obj_aggregate', "create_aggregate" ));
$result = $dbh->selectrow_arrayref( "SELECT defined(field) FROM aggr_test" );
ok( $result && $result->[0] == 2 );
$result = $dbh->selectrow_arrayref( "SELECT defined(field) FROM aggr_test" );
@ -108,7 +108,7 @@ local $SIG{__WARN__} = sub { $last_warn = join "", @_ };
foreach my $fail ( qw/ new step finalize/ ) {
$last_warn = '';
my $aggr = new fail_aggregate( $fail );
$dbh->func( "fail_$fail", -1, $aggr, 'create_aggregate' );
ok($dbh->func( "fail_$fail", -1, $aggr, 'create_aggregate' ));
$result = $dbh->selectrow_arrayref( "SELECT fail_$fail() FROM aggr_test" );
# ok( !$result && $DBI::errstr =~ /$fail\(\) failed on request/ );
ok( !defined $result->[0] && $last_warn =~ /$fail\(\) failed on request/ );
@ -123,7 +123,7 @@ foreach my $fail ( qw/ new step finalize/ ) {
my $aggr = new fail_aggregate( 'undef' );
$last_warn = '';
$dbh->func( "fail_undef", -1, $aggr, 'create_aggregate' );
ok($dbh->func( "fail_undef", -1, $aggr, 'create_aggregate' ));
$result = $dbh->selectrow_arrayref( "SELECT fail_undef() FROM aggr_test" );
# ok( !$result && $DBI::errstr =~ /new\(\) should return a blessed reference/ );
ok( !defined $result->[0] && $last_warn =~ /new\(\) should return a blessed reference/ );

View file

@ -12,7 +12,7 @@ BEGIN {
plan skip_all => 'requires DBI v1.608' if $DBI::VERSION < 1.608;
if ( $] >= 5.008005 ) {
plan( tests => 9 );
plan( tests => 11 );
} else {
plan( skip_all => 'Unicode is not supported before 5.8.5' );
}
@ -57,7 +57,7 @@ sub no_accents ($$) {
$dbh = connect_ok( RaiseError => 1 );
$dbh->sqlite_create_collation( "no_accents", \&no_accents );
ok($dbh->sqlite_create_collation( "no_accents", \&no_accents ));
$dbh->do( 'CREATE TEMP TABLE collate_test ( txt )' );
$dbh->do( "INSERT INTO collate_test VALUES ( '$_' )" ) foreach @words;
@ -79,7 +79,7 @@ is_deeply(\@sorted, $db_sorted, "collate no_accents (@sorted // @$db_sorted)");
$dbh->disconnect;
$dbh = connect_ok( RaiseError => 1, unicode => 1 );
$dbh->sqlite_create_collation( "no_accents", \&no_accents );
ok($dbh->sqlite_create_collation( "no_accents", \&no_accents ));
$dbh->do( 'CREATE TEMP TABLE collate_test ( txt )' );
$dbh->do( "INSERT INTO collate_test VALUES ( '$_' )" ) foreach @words_utf8;

View file

@ -10,7 +10,7 @@ use t::lib::Test;
use Test::More;
BEGIN {
if ( $] >= 5.008005 ) {
plan( tests => 9 );
plan( tests => 11 );
} else {
plan( skip_all => 'Unicode is not supported before 5.8.5' );
}
@ -55,7 +55,7 @@ sub no_accents ($$) {
$dbh = connect_ok( RaiseError => 1 );
$dbh->func( "no_accents", \&no_accents, "create_collation" );
ok($dbh->func( "no_accents", \&no_accents, "create_collation" ));
$dbh->do( 'CREATE TEMP TABLE collate_test ( txt )' );
$dbh->do( "INSERT INTO collate_test VALUES ( '$_' )" ) foreach @words;
@ -77,7 +77,7 @@ is_deeply(\@sorted, $db_sorted, "collate no_accents (@sorted // @$db_sorted)");
$dbh->disconnect;
$dbh = connect_ok( RaiseError => 1, unicode => 1 );
$dbh->func( "no_accents", \&no_accents, "create_collation" );
ok($dbh->func( "no_accents", \&no_accents, "create_collation" ));
$dbh->do( 'CREATE TEMP TABLE collate_test ( txt )' );
$dbh->do( "INSERT INTO collate_test VALUES ( '$_' )" ) foreach @words_utf8;

View file

@ -14,7 +14,7 @@ BEGIN {
plan skip_all => 'requires DBI v1.608' if $DBI::VERSION < 1.608;
}
plan tests => 4;
plan tests => 6;
my $N_OPCODES = 50; # how many opcodes before calling the progress handler
@ -27,7 +27,7 @@ sub progress_handler {
# connect and register the progress handler
my $dbh = connect_ok( RaiseError => 1 );
$dbh->sqlite_progress_handler( $N_OPCODES, \&progress_handler );
ok($dbh->sqlite_progress_handler( $N_OPCODES, \&progress_handler ));
# populate a temporary table with random numbers
$dbh->do( 'CREATE TEMP TABLE progress_test ( foo )' );
@ -46,7 +46,7 @@ ok($n_callback);
# unregister the progress handler, set counter back to zero, do more work
$dbh->sqlite_progress_handler( $N_OPCODES, undef );
ok($dbh->sqlite_progress_handler( $N_OPCODES, undef ));
$n_callback = 0;
$result = $dbh->do( "SELECT * from progress_test ORDER BY foo DESC " );

View file

@ -7,7 +7,7 @@ BEGIN {
}
use t::lib::Test;
use Test::More tests => 4;
use Test::More tests => 6;
use Test::NoWarnings;
my $N_OPCODES = 50; # how many opcodes before calling the progress handler
@ -21,7 +21,7 @@ sub progress_handler {
# connect and register the progress handler
my $dbh = connect_ok( RaiseError => 1 );
$dbh->func( $N_OPCODES, \&progress_handler, "progress_handler" );
ok($dbh->func( $N_OPCODES, \&progress_handler, "progress_handler" ));
# populate a temporary table with random numbers
$dbh->do( 'CREATE TEMP TABLE progress_test ( foo )' );
@ -40,7 +40,7 @@ ok($n_callback);
# unregister the progress handler, set counter back to zero, do more work
$dbh->func( $N_OPCODES, undef, "progress_handler" );
ok($dbh->func( $N_OPCODES, undef, "progress_handler" ));
$n_callback = 0;
$result = $dbh->do( "SELECT * from progress_test ORDER BY foo DESC " );

View file

@ -11,7 +11,7 @@ BEGIN {
plan skip_all => 'requires DBI v1.608' if $DBI::VERSION < 1.608;
}
plan tests => 4;
plan tests => 6;
# Connect to the test db and add some stuff:
my $foo = connect_ok( RaiseError => 1 );
@ -31,7 +31,7 @@ my $dbh = DBI->connect(
{ RaiseError => 1 }
);
$dbh->sqlite_backup_from_file('foo');
ok($dbh->sqlite_backup_from_file('foo'));
{
my ($count) = $dbh->selectrow_array(
@ -47,7 +47,7 @@ $dbh->do(
$dbh->do("INSERT INTO online_backup_test2 (foo) VALUES ($$)");
# backup to file (foo):
$dbh->sqlite_backup_to_file('foo');
ok($dbh->sqlite_backup_to_file('foo'));
$dbh->disconnect;

View file

@ -3,7 +3,7 @@
use strict;
use warnings;
use Test::More tests => 4;
use Test::More tests => 6;
use t::lib::Test;
use DBI;
@ -25,7 +25,7 @@ my $dbh = DBI->connect(
{ RaiseError => 1 }
);
$dbh->func('foo', 'backup_from_file');
ok($dbh->func('foo', 'backup_from_file'));
{
my ($count) = $dbh->selectrow_array(
@ -41,7 +41,7 @@ $dbh->do(
$dbh->do("INSERT INTO online_backup_test2 (foo) VALUES ($$)");
# backup to file (foo):
$dbh->func('foo', 'backup_to_file');
ok($dbh->func('foo', 'backup_to_file'));
$dbh->disconnect;

View file

@ -12,7 +12,7 @@ BEGIN {
plan skip_all => 'requires DBI v1.608' if $DBI::VERSION < 1.608;
if ( $] >= 5.008005 ) {
plan( tests => 15 );
plan( tests => 16 );
} else {
plan( skip_all => 'Unicode is not supported before 5.8.5' );
}
@ -23,7 +23,7 @@ eval "require utf8";
die $@ if $@;
my $dbh = connect_ok( unicode => 1 );
$dbh->sqlite_create_function( "perl_uc", 1, \&perl_uc );
ok($dbh->sqlite_create_function( "perl_uc", 1, \&perl_uc ));
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
CREATE TABLE foo (

View file

@ -10,7 +10,7 @@ use t::lib::Test;
use Test::More;
BEGIN {
if ( $] >= 5.008005 ) {
plan( tests => 15 );
plan( tests => 16 );
} else {
plan( skip_all => 'Unicode is not supported before 5.8.5' );
}
@ -21,7 +21,7 @@ eval "require utf8";
die $@ if $@;
my $dbh = connect_ok( unicode => 1 );
$dbh->func( "perl_uc", 1, \&perl_uc, "create_function" );
ok($dbh->func( "perl_uc", 1, \&perl_uc, "create_function" ));
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
CREATE TABLE foo (