Bug 1135281 - Correctly bind null parameters in SQLiteBridge.cpp. r=sebastian
authorRichard Newman <rnewman@mozilla.com>
Fri, 07 Aug 2015 21:43:47 -0700
changeset 288593 7bbb28b68b0dbd8d067ed71c8c4017cd50b5dbaa
parent 288592 bd1474381abd27e9a47549d9001c1bc9bd2c24c6
child 288594 c56e7866445c15389b4a54c805b252345f22ced3
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1135281
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1135281 - Correctly bind null parameters in SQLiteBridge.cpp. r=sebastian
mozglue/android/SQLiteBridge.cpp
mozglue/android/SQLiteBridge.h
--- a/mozglue/android/SQLiteBridge.cpp
+++ b/mozglue/android/SQLiteBridge.cpp
@@ -18,16 +18,17 @@
 #endif
 
 #define SQLITE_WRAPPER_INT(name) name ## _t f_ ## name;
 
 SQLITE_WRAPPER_INT(sqlite3_open)
 SQLITE_WRAPPER_INT(sqlite3_errmsg)
 SQLITE_WRAPPER_INT(sqlite3_prepare_v2)
 SQLITE_WRAPPER_INT(sqlite3_bind_parameter_count)
+SQLITE_WRAPPER_INT(sqlite3_bind_null)
 SQLITE_WRAPPER_INT(sqlite3_bind_text)
 SQLITE_WRAPPER_INT(sqlite3_step)
 SQLITE_WRAPPER_INT(sqlite3_column_count)
 SQLITE_WRAPPER_INT(sqlite3_finalize)
 SQLITE_WRAPPER_INT(sqlite3_close)
 SQLITE_WRAPPER_INT(sqlite3_column_name)
 SQLITE_WRAPPER_INT(sqlite3_column_type)
 SQLITE_WRAPPER_INT(sqlite3_column_blob)
@@ -38,16 +39,17 @@ SQLITE_WRAPPER_INT(sqlite3_last_insert_r
 
 void setup_sqlite_functions(void *sqlite_handle)
 {
 #define GETFUNC(name) f_ ## name = (name ## _t) (uintptr_t) __wrap_dlsym(sqlite_handle, #name)
   GETFUNC(sqlite3_open);
   GETFUNC(sqlite3_errmsg);
   GETFUNC(sqlite3_prepare_v2);
   GETFUNC(sqlite3_bind_parameter_count);
+  GETFUNC(sqlite3_bind_null);
   GETFUNC(sqlite3_bind_text);
   GETFUNC(sqlite3_step);
   GETFUNC(sqlite3_column_count);
   GETFUNC(sqlite3_finalize);
   GETFUNC(sqlite3_close);
   GETFUNC(sqlite3_column_name);
   GETFUNC(sqlite3_column_type);
   GETFUNC(sqlite3_column_blob);
@@ -258,21 +260,27 @@ sqliteInternalCall(JNIEnv* jenv,
                 // IsInstanceOf or isAssignableFrom? String is final, so IsInstanceOf
                 // should be OK.
                 jboolean isString = jenv->IsInstanceOf(jObjectParam, stringClass);
                 if (isString != JNI_TRUE) {
                     throwSqliteException(jenv,
                         "Parameter is not of String type");
                     return nullptr;
                 }
-                jstring jStringParam = (jstring)jObjectParam;
-                const char* paramStr = jenv->GetStringUTFChars(jStringParam, nullptr);
+
                 // SQLite parameters index from 1.
-                rc = f_sqlite3_bind_text(ppStmt, i + 1, paramStr, -1, SQLITE_TRANSIENT);
-                jenv->ReleaseStringUTFChars(jStringParam, paramStr);
+                if (jObjectParam == nullptr) {
+                  rc = f_sqlite3_bind_null(ppStmt, i + 1);
+                } else {
+                  jstring jStringParam = (jstring) jObjectParam;
+                  const char* paramStr = jenv->GetStringUTFChars(jStringParam, nullptr);
+                  rc = f_sqlite3_bind_text(ppStmt, i + 1, paramStr, -1, SQLITE_TRANSIENT);
+                  jenv->ReleaseStringUTFChars(jStringParam, paramStr);
+                }
+
                 if (rc != SQLITE_OK) {
                     throwSqliteException(jenv, "Error binding query parameter");
                     return nullptr;
                 }
             }
         }
     }
 
--- a/mozglue/android/SQLiteBridge.h
+++ b/mozglue/android/SQLiteBridge.h
@@ -13,16 +13,17 @@ void setup_sqlite_functions(void *sqlite
 typedef return_type (*name ## _t)(args);  \
 extern name ## _t f_ ## name;
 
 SQLITE_WRAPPER(sqlite3_open, int, const char*, sqlite3**)
 SQLITE_WRAPPER(sqlite3_errmsg, const char*, sqlite3*)
 SQLITE_WRAPPER(sqlite3_prepare_v2, int, sqlite3*, const char*, int, sqlite3_stmt**, const char**)
 SQLITE_WRAPPER(sqlite3_bind_parameter_count, int, sqlite3_stmt*)
 SQLITE_WRAPPER(sqlite3_bind_text, int, sqlite3_stmt*, int, const char*, int, void(*)(void*))
+SQLITE_WRAPPER(sqlite3_bind_null, int, sqlite3_stmt*, int)
 SQLITE_WRAPPER(sqlite3_step, int, sqlite3_stmt*)
 SQLITE_WRAPPER(sqlite3_column_count, int, sqlite3_stmt*)
 SQLITE_WRAPPER(sqlite3_finalize, int, sqlite3_stmt*)
 SQLITE_WRAPPER(sqlite3_close, int, sqlite3*)
 SQLITE_WRAPPER(sqlite3_column_name, const char*, sqlite3_stmt*, int)
 SQLITE_WRAPPER(sqlite3_column_type, int, sqlite3_stmt*, int)
 SQLITE_WRAPPER(sqlite3_column_blob, const void*, sqlite3_stmt*, int)
 SQLITE_WRAPPER(sqlite3_column_bytes, int, sqlite3_stmt*, int)