This cannot be right:

> sqlite_set_result(pTHX_ sqlite3_context *context, SV *result, int is_error)
> {
> ...
>     if ( is_error ) {
>         s = SvPV(result, len);
>         sqlite3_result_error( context, s, len );
>         return;
>     }
> ...
>     else if ( SvIOK(result) ) {
>         sqlite3_result_int( context, SvIV(result));
>     } else if ( !is_error && SvIOK(result) ) {
>         sqlite3_result_double( context, SvNV(result));

1) (!is_error) is always true in this branch
2) SvIOK(result) is already checked above and is always false in this branch

Have no idea what original author had in mind (this code predates
DBD-SQLite-1.14), but please consider one of patches below.
Alternative 1: remove always true condition, replace SvIOK with SvNOK

diff --git a/dbdimp.c b/dbdimp.c
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -147,7 +147,7 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV 
*result, int is_error)
     }
     else if ( SvIOK(result) ) {
         sqlite3_result_int( context, SvIV(result));
-    } else if ( !is_error && SvIOK(result) ) {
+    } else if ( SvNOK(result) ) {
         sqlite3_result_double( context, SvNV(result));
     } else {
         s = SvPV(result, len);
Alternative: same as alternative 1, but with extra paranoia about loosing 
precision

diff --git a/dbdimp.c b/dbdimp.c
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -147,7 +147,7 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV 
*result, int is_error)
     }
     else if ( SvIOK(result) ) {
         sqlite3_result_int( context, SvIV(result));
-    } else if ( !is_error && SvIOK(result) ) {
+    } else if ( SvNOK(result) && ( sizeof(NV) == sizeof(double) || 
SvNVX(result) == (double) SvNVX(result) ) ) {
         sqlite3_result_double( context, SvNVX(result));
     } else {
         s = SvPV(result, len);
Alternative 3: simply remove impossible to execute code.

diff --git a/dbdimp.c b/dbdimp.c
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -147,7 +147,5 @@ sqlite_set_result(pTHX_ sqlite3_context *context, SV 
*result, int is_error)
     }
     else if ( SvIOK(result) ) {
         sqlite3_result_int( context, SvIV(result));
-    } else if ( !is_error && SvIOK(result) ) {
-        sqlite3_result_double( context, SvNV(result));
     } else {
         s = SvPV(result, len);
_______________________________________________
DBD-SQLite mailing list
DBD-SQLite@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbd-sqlite

Reply via email to