diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index 55923e785fa..dee811f53f7 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -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); diff --git a/Modules/_sqlite/util.c b/Modules/_sqlite/util.c index f5a7233a9f3..cbaee92cce1 100644 --- a/Modules/_sqlite/util.c +++ b/Modules/_sqlite/util.c @@ -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; }