]> granicus.if.org Git - python/commitdiff
- Backported a workaround for a bug in SQLite 3.2.x/3.3.x versions where a
authorGerhard Häring <gh@ghaering.de>
Sun, 25 Nov 2007 17:40:35 +0000 (17:40 +0000)
committerGerhard Häring <gh@ghaering.de>
Sun, 25 Nov 2007 17:40:35 +0000 (17:40 +0000)
  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 55923e785fa096805b97f9ef27ffa1ea99432b29..dee811f53f7ea239d82a5c979328685fd5582f07 100644 (file)
@@ -237,7 +237,11 @@ int statement_recompile(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 f5a7233a9f333e2b827ea545ea3cba57053cfd36..cbaee92cce12ed35805da9efad76cd96ed9825c6 100644 (file)
@@ -29,9 +29,15 @@ int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, Connection* connectio
 {
     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;
 }