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

more tests

This commit is contained in:
Kenichi Ishigaki 2010-06-17 07:08:01 +00:00
parent a53e2df1cb
commit 00b0cb9f00
2 changed files with 126 additions and 6 deletions

View file

@ -770,7 +770,7 @@ sqlite_st_fetch(SV *sth, imp_sth_t *imp_sth)
#endif
break;
case SQLITE_FLOAT:
#if 0
#if 01
/* fetching as float may lose precision info in the perl world */
sqlite_trace(sth, imp_sth, 5, form("fetch column %d as float", i));
sv_setnv(AvARRAY(av)[i], sqlite3_column_double(imp_sth->stmt, i));

View file

@ -8,10 +8,11 @@ BEGIN {
use t::lib::Test;
use Test::More;
use DBD::SQLite;
use Test::NoWarnings;
my @values = qw/
0 1 1.0 1.0e+001 0000 01010101 10010101
0 1 1.0 1.1 2.0 1.0e+001 0000 01010101 10010101
0000002100000517
0000002200000517
0000001e00000517
@ -19,8 +20,8 @@ my @values = qw/
test 01234test -test +test
0.123e 0.123e+
0. .123 -.123 +.123
-1 -1.0 -1.0e-001 -0000 -0101 -002.00
+1 +1.0 +1.0e-001 +0000 +0101 +002.00
-1 -1.0 -1.1 -2.0 -1.0e-001 -0000 -0101 -002.00
+1 +1.0 +1.1 +2.0 +1.0e-001 +0000 +0101 +002.00
1234567890123456789012345678901234567890
-1234567890123456789012345678901234567890
+1234567890123456789012345678901234567890
@ -36,7 +37,21 @@ my @values = qw/
my @types = ('', 'text', 'integer', 'float');
plan tests => @values * 3 * @types + 1;
my %prior_DBD_SQLITE_1_30_behaviors = prior_DBD_SQLITE_1_30_behaviors();
my $has_sqlite;
my $sqlite3_bin;
eval {
$sqlite3_bin = -f 'sqlite3' ? './sqlite3' : 'sqlite3';
my $sqlite3_version = `$sqlite3_bin --version`;
chomp $sqlite3_version;
$has_sqlite = $sqlite3_version eq $DBD::SQLite::sqlite_version ? 1 : 0;
};
unless ($has_sqlite) {
diag "requires sqlite3 $DBD::SQLite::sqlite_version executable for extra tests";
}
plan tests => @values * (3 + $has_sqlite) * @types + 1;
for my $type (@types) {
my $typename = $type || 'default';
@ -45,6 +60,111 @@ for my $type (@types) {
$dbh->do("create table foo (value $type)");
ok $dbh->do('insert into foo values(?)', undef, $value), "inserting $value into a $typename column";
my ($got) = $dbh->selectrow_array('select value from foo where value = ?', undef, $value);
ok defined $got && $got eq $value, "type: $typename got: $got expected: $value";
$got = '' unless defined $got;
if ($got eq $value) {
pass "type: $typename got: $got expected: $value";
}
else {
my $old_behavior = $prior_DBD_SQLITE_1_30_behaviors{$type}{$value};
$old_behavior = '' unless defined $old_behavior;
if ($old_behavior eq $got) {
pass "same as the old behavior: type: $typename got: $got expected: $value";
}
else {
fail "type: $typename got: $got expected: $value old_behavior $old_behavior";
}
}
if ($has_sqlite) {
my $cmd = "create table f (v $type);insert into f values(\"$value\");select * from f;";
my $got = `$sqlite3_bin -list ':memory:' '$cmd'`;
chomp $got;
if ($got eq $value) {
pass "sqlite3: type: $typename got: $got expected: $value";
}
else {
TODO: {
local $TODO = "sqlite3 shell behaves differently";
fail "sqlite3: type: $typename got: $got expected: $value";
}
}
}
}
}
sub prior_DBD_SQLITE_1_30_behaviors {(
integer => {
'1.0' => 1,
'2.0' => 2,
'1.0e+001' => 10,
'0000' => 0,
'01010101' => 1010101,
'0000002100000517' => 2100000517,
'0000002200000517' => 2200000517,
'0000001e00000517' => 'inf',
'00002.000' => 2,
'-1.0', => -1,
'-2.0', => -2,
'-1.0e-001' => -0.1,
'-0000' => 0,
'-0101' => -101,
'-002.00' => -2,
'+1', => 1,
'+1.0' => 1,
'+1.1' => 1.1,
'+2.0' => 2,
'+1.0e-001' => 0.1,
'+0000' => 0,
'+0101', => 101,
'+002.00' => 2,
'1234567890123456789012345678901234567890' => '1.23456789012346e+39',
'-1234567890123456789012345678901234567890' => '-1.23456789012346e+39',
'+1234567890123456789012345678901234567890' => '1.23456789012346e+39',
'-9223372036854775807' => '-9.22337203685478e+18',
'+9223372036854775806', => '9.22337203685478e+18',
'-9223372036854775808', => '-9.22337203685478e+18',
'+9223372036854775807', => '9.22337203685478e+18',
'-9223372036854775809', => '-9.22337203685478e+18',
'+9223372036854775808', => '9.22337203685478e+18',
'+2147483647', => '2147483647',
'+2147483648', => '2147483648',
'+2147483649', => '2147483649',
},
float => {
'1.0' => 1,
'2.0' => 2,
'1.0e+001' => 10,
'0000' => 0,
'01010101' => 1010101,
'0000002100000517' => 2100000517,
'0000002200000517' => 2200000517,
'0000001e00000517' => 'inf',
'00002.000' => 2,
'-1.0', => -1,
'-2.0', => -2,
'-1.0e-001' => -0.1,
'-0000' => 0,
'-0101' => -101,
'-002.00' => -2,
'+1', => 1,
'+1.0' => 1,
'+1.1' => 1.1,
'+2.0' => 2,
'+1.0e-001' => 0.1,
'+0000' => 0,
'+0101', => 101,
'+002.00' => 2,
'1234567890123456789012345678901234567890' => '1.23456789012346e+39',
'-1234567890123456789012345678901234567890' => '-1.23456789012346e+39',
'+1234567890123456789012345678901234567890' => '1.23456789012346e+39',
'-9223372036854775807' => '',
'+9223372036854775806', => '',
'-9223372036854775808', => '-9.22337203685478e+18',
'+9223372036854775807', => '',
'-9223372036854775809', => '-9.22337203685478e+18',
'+9223372036854775808', => '9.22337203685478e+18',
'+2147483647', => '2147483647',
'+2147483648', => '2147483648',
'+2147483649', => '2147483649',
},
)}