]> granicus.if.org Git - python/commitdiff
Forward-port of commit 59184.
authorGerhard Häring <gh@ghaering.de>
Tue, 11 Dec 2007 21:07:40 +0000 (21:07 +0000)
committerGerhard Häring <gh@ghaering.de>
Tue, 11 Dec 2007 21:07:40 +0000 (21:07 +0000)
- Backported a workaround for a bug in SQLite 3.2.x/3.3.x versions where a
  statement recompilation with no bound parameters lead to a segfault
- Backported a fix necessary because of an SQLite API change in version
  3.5.
  This prevents segfaults when executing empty queries, like our test suite
  does

Modules/_sqlite/statement.c
Modules/_sqlite/util.c

index 20c1aac324f85527199a286f43c6f04abb1019bc..97d2e2a360b39b3f8fd18551c135d1486ce67032 100644 (file)
@@ -237,7 +237,11 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
          */
         #ifdef SQLITE_VERSION_NUMBER
         #if SQLITE_VERSION_NUMBER >= 3002002
-        (void)sqlite3_transfer_bindings(self->st, new_st);
+        /* The check for the number of parameters is necessary to not trigger a
+         * bug in certain SQLite versions (experienced in 3.2.8 and 3.3.4). */
+        if (sqlite3_bind_parameter_count(self->st) > 0) {
+            (void)sqlite3_transfer_bindings(self->st, new_st);
+        }
         #endif
         #else
         statement_bind_parameters(self, params);
index b70297b9277b18af8473d19cc3bd56fcda8f8ce5..5e78d588460bfb14e4e1792d1a8956c26fe82f31 100644 (file)
@@ -28,9 +28,15 @@ int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, pysqlite_Connection*
 {
     int rc;
 
-    Py_BEGIN_ALLOW_THREADS
-    rc = sqlite3_step(statement);
-    Py_END_ALLOW_THREADS
+    if (statement == NULL) {
+        /* this is a workaround for SQLite 3.5 and later. it now apparently
+         * returns NULL for "no-operation" statements */
+        rc = SQLITE_OK;
+    } else {
+        Py_BEGIN_ALLOW_THREADS
+        rc = sqlite3_step(statement);
+        Py_END_ALLOW_THREADS
+    }
 
     return rc;
 }