[R-sig-DB] RSQLite and SQLite 3.3.x

Ashish Kulkarni @@h|@h@ku|k@rn| @end|ng |rom k@|yptor|@k@com
Fri Sep 29 16:28:10 CEST 2006


Hello,

I found the reason why RSQLite does not work with SQLite 3.3.x -- one of the SQLite APIs was being used incorrectly. The patch is simple:

diff -ur ./src/RS-SQLite.c ../RSQLite/src/RS-SQLite.c
--- ./src/RS-SQLite.c	2006-09-01 04:34:11.000000000 +0530
+++ ../RSQLite/src/RS-SQLite.c	2006-09-29 19:44:05.851964900 +0530
@@ -1029,7 +1029,7 @@
     zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable);
     if( zSql==0 ) return 0;
     nByte = strlen(zSql);
-    rc = sqlite3_prepare(db, zSql, 0, &pStmt, 0);
+    rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
     sqlite3_free(zSql);
     if( rc ){
       char errMsg[512];
@@ -1051,7 +1051,7 @@
     }
     zSql[j++] = ')';
     zSql[j] = 0;
-    rc = sqlite3_prepare(db, zSql, 0, &pStmt, 0);
+    rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0);
     free(zSql);
     if( rc ){
       char errMsg[512];

According to http://sqlite.org/capi3ref.html#sqlite3_prepare
"If the next argument, "nBytes", is less than zero, then zSql 
is read up to the first nul terminator. If "nBytes" is not 
less than zero, then it is the length of the string zSql in 
Bytes."

In this case, nBytes was zero -- effectively a zero-length 
query. Also, the error handling did not work -- a zero was
returned from the function RS_sqlite_import() but the coercion 
to a logical always returned TRUE -- that really confused me :-)

Hope this is integrated in the official CRAN uploads.

Regards,
ashish




More information about the R-sig-DB mailing list