From f3dcf2cf741f33d3d20f85413643089bc259fa73 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Thu, 17 Jun 2010 08:35:33 +0000 Subject: [PATCH] more tests --- dbdimp.c | 20 +++++++- t/rt_44891_strings_look_like_numbers.t | 65 ++++++++++++++++++++++---- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/dbdimp.c b/dbdimp.c index c16bbc1..c63892a 100644 --- a/dbdimp.c +++ b/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)); diff --git a/t/rt_44891_strings_look_like_numbers.t b/t/rt_44891_strings_look_like_numbers.t index 3bd8f4e..433f1cf 100644 --- a/t/rt_44891_strings_look_like_numbers.t +++ b/t/rt_44891_strings_look_like_numbers.t @@ -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 + }, +)}