mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 14:19:10 -04:00
applied two more patches from Yuriy Kaminskiy to fix 64bit integer handling
This commit is contained in:
parent
6f54dc4aa2
commit
8fc2d566db
2 changed files with 28 additions and 4 deletions
23
dbdimp.c
23
dbdimp.c
|
@ -142,8 +142,12 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV *result, int is_error)
|
|||
if ( !SvOK(result) ) {
|
||||
sqlite3_result_null( context );
|
||||
} else if( SvIOK_UV(result) ) {
|
||||
s = SvPV(result, len);
|
||||
sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
|
||||
if ((UV)(sqlite3_int64)UV_MAX == UV_MAX)
|
||||
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) ) {
|
||||
#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;
|
||||
STRLEN len;
|
||||
int type = sqlite3_value_type(value[i]);
|
||||
sqlite_int64 iv;
|
||||
|
||||
/* warn("func dispatch type: %d, value: %s\n", type, sqlite3_value_text(value[i])); */
|
||||
switch(type) {
|
||||
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;
|
||||
case SQLITE_FLOAT:
|
||||
arg = sv_2mortal(newSVnv(sqlite3_value_double(value[i])));
|
||||
|
|
|
@ -11,7 +11,7 @@ use t::lib::Test qw/connect_ok @CALL_FUNCS/;
|
|||
use Test::More;
|
||||
use Test::NoWarnings;
|
||||
|
||||
plan tests => 27 * @CALL_FUNCS + 1;
|
||||
plan tests => 29 * @CALL_FUNCS + 1;
|
||||
|
||||
sub now {
|
||||
return time();
|
||||
|
@ -119,5 +119,12 @@ foreach my $call_func (@CALL_FUNCS) {
|
|||
$result = $dbh->selectrow_arrayref( "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;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue