1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 22:28:47 -04:00

applied two more patches from Yuriy Kaminskiy to fix 64bit integer handling

This commit is contained in:
Kenichi Ishigaki 2012-03-25 02:37:09 +00:00
parent 6f54dc4aa2
commit 8fc2d566db
2 changed files with 28 additions and 4 deletions

View file

@ -142,8 +142,12 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV *result, int is_error)
if ( !SvOK(result) ) { if ( !SvOK(result) ) {
sqlite3_result_null( context ); sqlite3_result_null( context );
} else if( SvIOK_UV(result) ) { } else if( SvIOK_UV(result) ) {
s = SvPV(result, len); if ((UV)(sqlite3_int64)UV_MAX == UV_MAX)
sqlite3_result_text( context, s, len, SQLITE_TRANSIENT ); sqlite3_result_int64( context, (sqlite3_int64)SvUV(result));
else {
s = SvPV(result, len);
sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
}
} }
else if ( SvIOK(result) ) { else if ( SvIOK(result) ) {
#if defined(USE_64_BIT_INT) #if defined(USE_64_BIT_INT)
@ -1241,11 +1245,24 @@ sqlite_db_func_dispatcher(int is_unicode, sqlite3_context *context, int argc, sq
SV *arg; SV *arg;
STRLEN len; STRLEN len;
int type = sqlite3_value_type(value[i]); int type = sqlite3_value_type(value[i]);
sqlite_int64 iv;
/* warn("func dispatch type: %d, value: %s\n", type, sqlite3_value_text(value[i])); */ /* warn("func dispatch type: %d, value: %s\n", type, sqlite3_value_text(value[i])); */
switch(type) { switch(type) {
case SQLITE_INTEGER: case SQLITE_INTEGER:
arg = sv_2mortal(newSViv(sqlite3_value_int(value[i]))); iv = sqlite3_value_int64(value[i]);
if ( iv >= IV_MIN && iv <= IV_MAX ) {
/* ^^^ compile-time constant (= true) when IV == int64 */
arg = sv_2mortal(newSViv((IV)iv));
}
else if ( iv >= 0 && iv <= UV_MAX ) {
/* warn("integer overflow, cast to UV"); */
arg = sv_2mortal(newSVuv((UV)iv));
}
else {
/* warn("integer overflow, cast to NV"); */
arg = sv_2mortal(newSVnv((NV)iv));
}
break; break;
case SQLITE_FLOAT: case SQLITE_FLOAT:
arg = sv_2mortal(newSVnv(sqlite3_value_double(value[i]))); arg = sv_2mortal(newSVnv(sqlite3_value_double(value[i])));

View file

@ -11,7 +11,7 @@ use t::lib::Test qw/connect_ok @CALL_FUNCS/;
use Test::More; use Test::More;
use Test::NoWarnings; use Test::NoWarnings;
plan tests => 27 * @CALL_FUNCS + 1; plan tests => 29 * @CALL_FUNCS + 1;
sub now { sub now {
return time(); return time();
@ -119,5 +119,12 @@ foreach my $call_func (@CALL_FUNCS) {
$result = $dbh->selectrow_arrayref( "SELECT noop(1.0625)" ); $result = $dbh->selectrow_arrayref( "SELECT noop(1.0625)" );
is_deeply( $result, [ 1.0625 ], "SELECT noop(1.0625)" ); is_deeply( $result, [ 1.0625 ], "SELECT noop(1.0625)" );
# 2147483648 == 1<<31
$result = $dbh->selectrow_arrayref( "SELECT noop(2147483648)" );
is_deeply( $result, [ 2147483648 ], "SELECT noop(2147483648)" );
$result = $dbh->selectrow_arrayref( "SELECT typeof(noop(2147483648))" );
is_deeply( $result, [ 'integer' ], "SELECT typeof(noop(2147483648))" );
$dbh->disconnect; $dbh->disconnect;
} }