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

tweaked code and tests for older SQLite libraries (re: RT 101573)

This commit is contained in:
Kenichi Ishigaki 2015-02-10 17:07:32 +09:00
parent 6ebf627ffd
commit eb10c7ce6f
19 changed files with 171 additions and 61 deletions

View file

@ -586,7 +586,7 @@ SAVEPOINT()
#if SQLITE_VERSION_NUMBER >= 3006011
RETVAL = SQLITE_SAVEPOINT;
#else
RETVAL = -1;
RETVAL = -1;
#endif
OUTPUT:
RETVAL
@ -622,28 +622,44 @@ OPEN_NOMUTEX()
static int
OPEN_FULLMUTEX()
CODE:
#if SQLITE_VERSION_NUMBER >= 3006006
RETVAL = SQLITE_OPEN_FULLMUTEX;
#else
RETVAL = -1;
#endif
OUTPUT:
RETVAL
static int
OPEN_SHAREDCACHE()
CODE:
#if SQLITE_VERSION_NUMBER >= 3006018
RETVAL = SQLITE_OPEN_SHAREDCACHE;
#else
RETVAL = -1;
#endif
OUTPUT:
RETVAL
static int
OPEN_PRIVATECACHE()
CODE:
#if SQLITE_VERSION_NUMBER >= 3006018
RETVAL = SQLITE_OPEN_PRIVATECACHE;
#else
RETVAL = -1;
#endif
OUTPUT:
RETVAL
static int
OPEN_URI()
CODE:
#if SQLITE_VERSION_NUMBER >= 3007007
RETVAL = SQLITE_OPEN_URI;
#else
RETVAL = -1;
#endif
OUTPUT:
RETVAL

View file

@ -1439,7 +1439,9 @@ _sqlite_status(int reset)
_stores_status(SQLITE_STATUS_PARSER_STACK, "parser_stack");
_stores_status(SQLITE_STATUS_PAGECACHE_SIZE, "pagecache_size");
_stores_status(SQLITE_STATUS_SCRATCH_SIZE, "scratch_size");
#if SQLITE_VERSION_NUMBER >= 3007001
_stores_status(SQLITE_STATUS_MALLOC_COUNT, "malloc_count");
#endif
_stores_status(SQLITE_STATUS_SCRATCH_OVERFLOW, "scratch_overflow");
return hv;
@ -1454,15 +1456,25 @@ _sqlite_db_status(pTHX_ SV* dbh, int reset)
HV *anon;
_stores_dbstatus(SQLITE_DBSTATUS_LOOKASIDE_USED, "lookaside_used");
#if SQLITE_VERSION_NUMBER >= 3007000
_stores_dbstatus(SQLITE_DBSTATUS_CACHE_USED, "cache_used");
#endif
#if SQLITE_VERSION_NUMBER >= 3007001
_stores_dbstatus(SQLITE_DBSTATUS_SCHEMA_USED, "schema_used");
_stores_dbstatus(SQLITE_DBSTATUS_STMT_USED, "stmt_used");
#endif
#if SQLITE_VERSION_NUMBER >= 3007005
_stores_dbstatus(SQLITE_DBSTATUS_LOOKASIDE_HIT, "lookaside_hit");
_stores_dbstatus(SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, "lookaside_miss_size");
_stores_dbstatus(SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, "lookaside_miss_full");
#endif
#if SQLITE_VERSION_NUMBER >= 3007009
_stores_dbstatus(SQLITE_DBSTATUS_CACHE_HIT, "cache_hit");
_stores_dbstatus(SQLITE_DBSTATUS_CACHE_MISS, "cache_miss");
#endif
#if SQLITE_VERSION_NUMBER >= 3007012
_stores_dbstatus(SQLITE_DBSTATUS_CACHE_WRITE, "cache_write");
#endif
return hv;
}
@ -1473,9 +1485,13 @@ _sqlite_st_status(pTHX_ SV* sth, int reset)
D_imp_sth(sth);
HV *hv = newHV();
#if SQLITE_VERSION_NUMBER >= 3006004
_stores_ststatus(SQLITE_STMTSTATUS_FULLSCAN_STEP, "fullscan_step");
_stores_ststatus(SQLITE_STMTSTATUS_SORT, "sort");
#endif
#if SQLITE_VERSION_NUMBER >= 3007000
_stores_ststatus(SQLITE_STMTSTATUS_AUTOINDEX, "autoindex");
#endif
return hv;
}
@ -1492,7 +1508,9 @@ sqlite_db_filename(pTHX_ SV *dbh)
croak_if_db_is_null();
#if SQLITE_VERSION_NUMBER >= 3007010
filename = sqlite3_db_filename(imp_dbh->db, "main");
#endif
return filename ? newSVpv(filename, 0) : &PL_sv_undef;
}
@ -2828,7 +2846,6 @@ int sqlite_db_register_fts3_perl_tokenizer(pTHX_ SV *dbh)
** (i.e support for virtual tables written in Perl)
************************************************************************/
typedef struct perl_vtab {
sqlite3_vtab base;
SV *perl_vtab_obj;
@ -3087,8 +3104,10 @@ static int perl_vt_BestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pIdxInfo){
pIdxInfo->orderByConsumed = (val && SvTRUE(*val)) ? 1 : 0;
val = hv_fetch(hv, "estimatedCost", 13, FALSE);
pIdxInfo->estimatedCost = (val && SvOK(*val)) ? SvNV(*val) : 0;
#if SQLITE_VERSION_NUMBER >= 3008002
val = hv_fetch(hv, "estimatedRows", 13, FALSE);
pIdxInfo->estimatedRows = (val && SvOK(*val)) ? SvIV(*val) : 0;
#endif
/* loop over constraints to get back the "argvIndex" and "omit" keys
that shoud have been added by the best_index() method call */
@ -3543,9 +3562,11 @@ static sqlite3_module perl_vt_Module = {
perl_vt_Rollback, /* xRollback (optional) */
perl_vt_FindFunction, /* xFindFunction (optional) */
perl_vt_Rename, /* xRename */
#if SQLITE_VERSION_NUMBER >= 3007007
perl_vt_Savepoint, /* xSavepoint (optional) */
perl_vt_Release, /* xRelease (optional) */
perl_vt_RollbackTo /* xRollbackTo (optional) */
#endif
};

View file

@ -4,15 +4,9 @@ use strict;
use warnings;
use Test::More;
use t::lib::Test qw/connect_ok dbfile @CALL_FUNCS/;
use t::lib::Test qw/connect_ok dbfile @CALL_FUNCS requires_sqlite/;
BEGIN {
use DBD::SQLite;
unless ($DBD::SQLite::sqlite_version_number && $DBD::SQLite::sqlite_version_number >= 3006011) {
plan skip_all => "this test requires SQLite 3.6.11 and newer";
exit;
}
}
BEGIN { requires_sqlite('3.6.11') }
use Test::NoWarnings;
use DBI;

View file

@ -9,13 +9,7 @@ BEGIN {
use t::lib::Test;
use Test::More;
BEGIN {
use DBD::SQLite;
unless ($DBD::SQLite::sqlite_version_number && $DBD::SQLite::sqlite_version_number >= 3006019) {
plan skip_all => "this test requires SQLite 3.6.19 and newer";
exit;
}
}
BEGIN { requires_sqlite('3.6.19') }
use Test::NoWarnings;

View file

@ -5,7 +5,7 @@ BEGIN {
$^W = 1;
}
use t::lib::Test qw/connect_ok/;
use t::lib::Test qw/connect_ok has_sqlite/;
use Test::More;
use DBD::SQLite;
@ -36,7 +36,9 @@ BEGIN {
}
use Test::NoWarnings;
plan tests => 4 * @tests # each test with unicode y/n and with fts3/fts4
my $num = has_sqlite('3.7.4') ? 4 : 2;
plan tests => $num * @tests # each test with unicode y/n and with fts3/fts4
+ 2 # connect_ok with unicode y/n
+ 1; # Test::NoWarnings
@ -80,6 +82,7 @@ for my $use_unicode (0, 1) {
my $dbh = connect_ok( RaiseError => 1, sqlite_unicode => $use_unicode );
for my $fts (qw/fts3 fts4/) {
next if $fts eq 'fts4' && !has_sqlite('3.7.4');
# create fts table
$dbh->do(<<"") or die DBI::errstr;
CREATE VIRTUAL TABLE try_$fts

View file

@ -7,7 +7,11 @@ BEGIN {
}
use t::lib::Test;
use Test::More tests => 5;
use Test::More;
BEGIN { requires_sqlite('3.6.8') }
plan tests => 5;
use Test::NoWarnings;
my $dbh = connect_ok(

View file

@ -6,8 +6,11 @@ BEGIN {
$^W = 1;
}
use t::lib::Test qw/connect_ok @CALL_FUNCS/;
use t::lib::Test qw/connect_ok @CALL_FUNCS requires_sqlite/;
use Test::More;
BEGIN { requires_sqlite('3.6.21') }
use Test::NoWarnings;
plan tests => 12 * @CALL_FUNCS + 1;

View file

@ -6,8 +6,11 @@ BEGIN {
$^W = 1;
}
use t::lib::Test qw/connect_ok @CALL_FUNCS/;
use t::lib::Test qw/connect_ok @CALL_FUNCS requires_sqlite/;
use Test::More;
BEGIN { requires_sqlite('3.7.10') }
use Test::NoWarnings;
plan tests => 6 * @CALL_FUNCS + 1;

View file

@ -6,11 +6,15 @@ BEGIN {
$^W = 1;
}
use t::lib::Test qw/connect_ok @CALL_FUNCS/;
use t::lib::Test qw/connect_ok @CALL_FUNCS has_sqlite/;
use Test::More;
use Test::NoWarnings;
plan tests => 8 * @CALL_FUNCS + 1;
my $tests = 5;
$tests += 2 if has_sqlite('3.6.4');
$tests += 1 if has_sqlite('3.7.0');
plan tests => $tests * @CALL_FUNCS + 1;
my $dbh = connect_ok();
{
@ -34,8 +38,10 @@ for my $func (@CALL_FUNCS) {
ok $db_status && ref $db_status eq ref {}, "db status is a hashref";
my $num_of_keys = scalar keys %$db_status;
ok $num_of_keys, "db status: $num_of_keys indicators";
my $used_cache = $db_status->{cache_used}{current};
ok defined $used_cache && $used_cache, "current used cache: $used_cache";
if (has_sqlite('3.7.0')) {
my $used_cache = $db_status->{cache_used}{current};
ok defined $used_cache && $used_cache, "current used cache: $used_cache";
}
}
{
@ -43,9 +49,11 @@ for my $func (@CALL_FUNCS) {
$sth->execute("text1");
my $st_status = $sth->$func('st_status');
ok $st_status && ref $st_status eq ref {}, "st status is a hashref";
my $num_of_keys = scalar keys %$st_status;
ok $num_of_keys, "st status: $num_of_keys indicators";
my $sort = $st_status->{sort};
ok defined $sort, "num of sort: $sort";
if (has_sqlite('3.6.4')) {
my $num_of_keys = scalar keys %$st_status;
ok $num_of_keys, "st status: $num_of_keys indicators";
my $sort = $st_status->{sort};
ok defined $sort, "num of sort: $sort";
}
}
}

View file

@ -7,7 +7,12 @@ BEGIN {
}
use t::lib::Test;
use Test::More tests => 8;
use Test::More;
my $tests = 7;
$tests += 1 if has_sqlite('3.7.7');
plan tests => $tests;
use DBI;
use DBD::SQLite;
@ -51,7 +56,7 @@ unlink $dbfile if -f $dbfile;
unlink $dbfile if -f $dbfile;
}
{
if (has_sqlite('3.7.7')) {
my $dbh = eval {
DBI->connect("dbi:SQLite:$dbfile", undef, undef, {
PrintError => 0,

View file

@ -7,7 +7,11 @@ BEGIN {
}
use t::lib::Test;
use Test::More tests => 17;
use Test::More;
BEGIN { requires_sqlite('3.7.7') }
plan tests => 17;
use DBI;
use DBD::SQLite;

View file

@ -9,7 +9,7 @@ use Test::More ();
our $VERSION = '1.46';
our @ISA = 'Exporter';
our @EXPORT = qw/connect_ok dies dbfile @CALL_FUNCS $sqlite_call/;
our @EXPORT = qw/connect_ok dies dbfile @CALL_FUNCS $sqlite_call has_sqlite requires_sqlite/;
our @CALL_FUNCS;
our $sqlite_call;
@ -147,5 +147,37 @@ $sqlite_call = sub {
$CALL_FUNCS[-1]->($dbh, @_, $func_to_call);
};
=head2 has_sqlite
has_sqlite('3.6.11');
returns true if DBD::SQLite is built with a version of SQLite equal to or higher than the specified version.
=cut
sub has_sqlite {
my $version = shift;
my @version_parts = split /\./, $version;
my $format = '%d%03d%03d';
my $version_number = sprintf $format, @version_parts[0..2];
use DBD::SQLite;
return ($DBD::SQLite::sqlite_version_number && $DBD::SQLite::sqlite_version_number >= $version_number) ? 1 : 0;
}
=head2 requires_sqlite
BEGIN { requires_sqlite('3.6.11'); }
skips all the tests if DBD::SQLite is not built with a version of SQLite equal to or higher than the specified version.
=cut
sub requires_sqlite {
my $version = shift;
unless (has_sqlite($version)) {
Test::More::plan skip_all => "this test requires SQLite $version and newer";
exit;
}
}
1;

View file

@ -2,7 +2,12 @@
use strict;
use warnings;
use DBI;
use Test::More tests => 22;
use Test::More;
use t::lib::Test;
BEGIN { requires_sqlite('3.6.3') }
plan tests => 22;
use_ok('DBD::SQLite');

View file

@ -8,9 +8,12 @@ BEGIN {
use t::lib::Test;
use Test::More;
BEGIN {
if ( $] >= 5.008005 ) {
plan( tests => 29 * 2 + 1 );
my $tests = 27;
$tests += 2 if has_sqlite('3.6.14');
plan( tests => $tests * 2 + 1 );
} else {
plan( skip_all => 'Unicode is not supported before 5.8.5' );
}
@ -83,7 +86,7 @@ sub unicode_test {
is $primary_key_info->{COLUMN_NAME} => $unicode_encoded, "primary_key_info returns the correctly encoded primary key name";
}
{
if (has_sqlite('3.6.14')) {
my $sth = $dbh->foreign_key_info(undef, undef, $unicode_encoded, undef, undef, 'bar');
my $foreign_key_info = $sth->fetchrow_hashref;
is $foreign_key_info->{PKCOLUMN_NAME} => $unicode_encoded, "foreign_key_info returns the correctly encoded foreign key name";
@ -151,7 +154,7 @@ sub unicode_test {
is $primary_key_info->{COLUMN_NAME} => $unicode, "primary_key_info returns the correctly decoded primary key name";
}
{
if (has_sqlite('3.6.14')) {
my $sth = $dbh->foreign_key_info(undef, undef, $unicode, undef, undef, 'bar');
my $foreign_key_info = $sth->fetchrow_hashref;
is $foreign_key_info->{PKCOLUMN_NAME} => $unicode, "foreign_key_info returns the correctly decoded foreign key name";

View file

@ -6,12 +6,6 @@
# constraint on the 'docid' column. So we have to explicitly type that
# column, using a CAST expression or a call to bind_param().
# TMP HACK
use lib "..";
use lib "../blib/arch";
use lib "../lib";
use strict;
BEGIN {
$| = 1;
@ -20,6 +14,9 @@ BEGIN {
use t::lib::Test;
use Test::More;
BEGIN { requires_sqlite('3.7.9') }
use DBI qw/SQL_INTEGER/;
plan tests => 8;
use Test::NoWarnings;

View file

@ -7,7 +7,11 @@ BEGIN {
}
use t::lib::Test;
use Test::More tests => 3;
use Test::More;
BEGIN { requires_sqlite('3.7.7') }
plan tests => 3;
use Test::NoWarnings;
my $dbh = connect_ok(AutoCommit => 0);

View file

@ -5,8 +5,11 @@ BEGIN {
$^W = 1;
}
use t::lib::Test qw/connect_ok $sqlite_call/;
use t::lib::Test qw/connect_ok $sqlite_call requires_sqlite/;
use Test::More;
BEGIN { requires_sqlite('3.7.12') }
use Test::NoWarnings;
use FindBin;

View file

@ -6,8 +6,11 @@ BEGIN {
}
use t::lib::Test qw/connect_ok $sqlite_call/;
use t::lib::Test qw/connect_ok $sqlite_call requires_sqlite has_sqlite/;
use Test::More;
BEGIN { requires_sqlite('3.7.4') }
use Test::NoWarnings;
use FindBin;
@ -17,7 +20,9 @@ our $perl_rows = [
[7, 8, 'nine' ],
];
plan tests => 29;
my $tests = 25;
$tests += 2 * 2 if has_sqlite('3.7.11');
plan tests => $tests;
my $dbh = connect_ok( RaiseError => 1, AutoCommit => 1 );
@ -92,11 +97,11 @@ $sql = "SELECT i FROM intarray WHERE i BETWEEN 0 AND 5";
$res = $dbh->selectcol_arrayref($sql);
is_deeply $res, [1 .. 5], $sql;
$sql = "INSERT INTO intarray VALUES (98), (99)";
ok $dbh->do($sql), $sql;
is_deeply $integers, [1 .. 10, 98, 99], "added 2 ints";
if (has_sqlite('3.7.10')) {
$sql = "INSERT INTO intarray VALUES (98), (99)";
ok $dbh->do($sql), $sql;
is_deeply $integers, [1 .. 10, 98, 99], "added 2 ints";
}
# test below inspired by sqlite "test_intarray.{h,c})
$integers = [ 1, 7 ];
@ -110,9 +115,11 @@ our $strings = [qw/one two three/];
ok $dbh->do(<<""), "create vtable strarray";
CREATE VIRTUAL TABLE strarray USING perl(str TEXT, colref="main::strings")
$sql = "INSERT INTO strarray VALUES ('aa'), ('bb')";
ok $dbh->do($sql), $sql;
is_deeply $strings, [qw/one two three aa bb/], "added 2 strings";
if (has_sqlite('3.7.10')) {
$sql = "INSERT INTO strarray VALUES ('aa'), ('bb')";
ok $dbh->do($sql), $sql;
is_deeply $strings, [qw/one two three aa bb/], "added 2 strings";
}
$sql = "SELECT a FROM vtb WHERE c IN strarray";
$res = $dbh->selectcol_arrayref($sql);

View file

@ -5,7 +5,7 @@ BEGIN {
$^W = 1;
}
use t::lib::Test qw/connect_ok $sqlite_call/;
use t::lib::Test qw/connect_ok $sqlite_call has_sqlite/;
use Test::More;
use Test::NoWarnings;
@ -33,7 +33,9 @@ our $perl_rows = [
[12, undef, "data\nhas\tspaces"],
];
plan tests => 4 + 2 * 15 + @interpolation_attempts + 9;
my $tests = 14;
$tests += 1 if has_sqlite('3.6.10');
plan tests => 4 + 2 * $tests + @interpolation_attempts + 9;
my $dbh = connect_ok( RaiseError => 1, AutoCommit => 1 );
@ -106,9 +108,11 @@ sub test_table {
$res = $dbh->selectcol_arrayref($sql, {}, undef);
is_deeply $res, [], $sql;
$sql = "SELECT a FROM $table WHERE c IS ?";
$res = $dbh->selectcol_arrayref($sql, {}, undef);
is_deeply $res, [7], $sql;
if (has_sqlite('3.6.10')) {
$sql = "SELECT a FROM $table WHERE c IS ?";
$res = $dbh->selectcol_arrayref($sql, {}, undef);
is_deeply $res, [7], $sql;
}
}
sub test_match_operator {