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:
parent
00b0cb9f00
commit
f3dcf2cf74
2 changed files with 74 additions and 11 deletions
20
dbdimp.c
20
dbdimp.c
|
@ -144,6 +144,7 @@ sqlite_is_number(pTHX_ const char *v)
|
|||
if (!isdigit(*z)) return 0;
|
||||
z++;
|
||||
while (isdigit(*z)) { digit++; z++; }
|
||||
#if defined(USE_64_BIT_INT)
|
||||
if (digit > 19) return 0; /* too large for i64 */
|
||||
if (digit == 19) {
|
||||
int c;
|
||||
|
@ -153,8 +154,21 @@ sqlite_is_number(pTHX_ const char *v)
|
|||
if (c == 0) {
|
||||
c = tmp[18] - '8';
|
||||
}
|
||||
if (c >= neg) return 0;
|
||||
if (c < neg) return 0;
|
||||
}
|
||||
#else
|
||||
if (digit > 11) return 0; /* too large for i32 */
|
||||
if (digit == 10) {
|
||||
int c;
|
||||
char tmp[19];
|
||||
strncpy(tmp, v, z - v + 1);
|
||||
c = memcmp(tmp, "2147483648", 10) * 10;
|
||||
if (c == 0) {
|
||||
c = tmp[10] - '8';
|
||||
}
|
||||
if (c < neg) return 0;
|
||||
}
|
||||
#endif
|
||||
if (*z == '.') {
|
||||
z++;
|
||||
if (!isdigit(*z)) return 0;
|
||||
|
@ -762,6 +776,7 @@ sqlite_st_fetch(SV *sth, imp_sth_t *imp_sth)
|
|||
}
|
||||
switch(col_type) {
|
||||
case SQLITE_INTEGER:
|
||||
#if 0
|
||||
sqlite_trace(sth, imp_sth, 5, form("fetch column %d as integer", i));
|
||||
#if defined(USE_64_BIT_INT)
|
||||
sv_setiv(AvARRAY(av)[i], sqlite3_column_int64(imp_sth->stmt, i));
|
||||
|
@ -769,8 +784,9 @@ sqlite_st_fetch(SV *sth, imp_sth_t *imp_sth)
|
|||
sv_setnv(AvARRAY(av)[i], (double)sqlite3_column_int64(imp_sth->stmt, i));
|
||||
#endif
|
||||
break;
|
||||
#endif
|
||||
case SQLITE_FLOAT:
|
||||
#if 01
|
||||
#if 0
|
||||
/* 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));
|
||||
|
|
|
@ -35,9 +35,10 @@ my @values = qw/
|
|||
+ -
|
||||
/;
|
||||
|
||||
my @types = ('', 'text', 'integer', 'float');
|
||||
my @types = ('', 'text', 'integer', 'real');
|
||||
|
||||
my %prior_DBD_SQLITE_1_30_behaviors = prior_DBD_SQLITE_1_30_behaviors();
|
||||
my %sqlite3_bin_behaviors = sqlite3_bin_behaviors();
|
||||
|
||||
my $has_sqlite;
|
||||
my $sqlite3_bin;
|
||||
|
@ -67,25 +68,35 @@ for my $type (@types) {
|
|||
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";
|
||||
my $sqlite3_behavior = $sqlite3_bin_behaviors{$type}{$value};
|
||||
$sqlite3_behavior = '' unless defined $sqlite3_behavior;
|
||||
if ($sqlite3_behavior eq $got) {
|
||||
pass "same as the sqlite3 bin: type: $typename got: $got expected: $value sqlite3_behavior: $sqlite3_behavior";
|
||||
}
|
||||
else {
|
||||
fail "type: $typename got: $got expected: $value old_behavior $old_behavior";
|
||||
if ($old_behavior eq $got) {
|
||||
TODO: {
|
||||
local $TODO = "same as the old behavior";
|
||||
fail "same as the old behavior: type: $typename got: $got expected: $value";
|
||||
}
|
||||
}
|
||||
else {
|
||||
fail "type: $typename got: $got expected: $value old_behavior: $old_behavior sqlite3_behavior: $sqlite3_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) {
|
||||
my $got_from_bin = `$sqlite3_bin -list ':memory:' '$cmd'`;
|
||||
chomp $got_from_bin;
|
||||
if ($got_from_bin eq $got) {
|
||||
pass "sqlite3: type: $typename got: $got expected: $value";
|
||||
}
|
||||
else {
|
||||
TODO: {
|
||||
local $TODO = "sqlite3 shell behaves differently";
|
||||
fail "sqlite3: type: $typename got: $got expected: $value";
|
||||
fail "sqlite3: type: $typename got: $got expected: $value got_from_bin: $got_from_bin";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +141,7 @@ sub prior_DBD_SQLITE_1_30_behaviors {(
|
|||
'+2147483648', => '2147483648',
|
||||
'+2147483649', => '2147483649',
|
||||
},
|
||||
float => {
|
||||
real => {
|
||||
'1.0' => 1,
|
||||
'2.0' => 2,
|
||||
'1.0e+001' => 10,
|
||||
|
@ -168,3 +179,39 @@ sub prior_DBD_SQLITE_1_30_behaviors {(
|
|||
'+2147483649', => '2147483649',
|
||||
},
|
||||
)}
|
||||
|
||||
sub sqlite3_bin_behaviors {(
|
||||
integer => {
|
||||
'0000001e00000517' => 'Inf', # previously 'inf'
|
||||
'+9223372036854775806' => '9223372036854775806', # previously 9.22337203685478e+18
|
||||
'+9223372036854775807' => '9223372036854775807', # previously 9.22337203685478e+18
|
||||
},
|
||||
real => {
|
||||
'0' => '0.0', # previously 0
|
||||
'1' => '1.0', # previously 1
|
||||
'1.0e+001' => '10.0', # previously 10
|
||||
'0000' => '0.0', # previously 0
|
||||
'01010101' => '1010101.0', # previously 1010101
|
||||
'10010101' => '10010101.0', # previously 10010101
|
||||
'0000002100000517' => '2100000517.0', # previously 2100000517
|
||||
'0000002200000517' => '2200000517.0', # previously 2200000517
|
||||
'0000001e00000517' => 'Inf', # previously 'inf'
|
||||
'00002.000' => '2.0', # previously 2
|
||||
'-1' => '-1.0', # previously -1
|
||||
'-0000' => '0.0', # previously 0
|
||||
'-0101' => '-101.0', # previously -101
|
||||
'-002.00' => '-2.0', # previously -2
|
||||
'+1' => '1.0', # previously 1
|
||||
'+1.0' => '1.0', # previously 1
|
||||
'+2.0' => '2.0', # previously 2
|
||||
'+0000' => '0.0', # previously 0
|
||||
'+0101' => '101.0', # previously 101
|
||||
'+002.00' => '2.0', # previously 2
|
||||
'-2147483646' => '-2147483646.0', # previously -2147483646
|
||||
'+2147483647' => '2147483647.0', # previously 2147483647
|
||||
'-2147483647' => '-2147483647.0', # previously -2147483647
|
||||
'+2147483648' => '2147483648.0', # previously 2147483648
|
||||
'-2147483648' => '-2147483648.0', # previously -2147483648
|
||||
'+2147483649' => '2147483649.0', # previously 2147483649
|
||||
},
|
||||
)}
|
||||
|
|
Loading…
Add table
Reference in a new issue