Skip to content

Commit b207c42

Browse files
author
gerhard.haering
committed
Forward-port of commit 59184.
- 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 git-svn-id: http://svn.python.org/projects/python/trunk@59471 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 5e23f36 commit b207c42

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Modules/_sqlite/statement.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
237237
*/
238238
#ifdef SQLITE_VERSION_NUMBER
239239
#if SQLITE_VERSION_NUMBER >= 3002002
240-
(void)sqlite3_transfer_bindings(self->st, new_st);
240+
/* The check for the number of parameters is necessary to not trigger a
241+
* bug in certain SQLite versions (experienced in 3.2.8 and 3.3.4). */
242+
if (sqlite3_bind_parameter_count(self->st) > 0) {
243+
(void)sqlite3_transfer_bindings(self->st, new_st);
244+
}
241245
#endif
242246
#else
243247
statement_bind_parameters(self, params);

Modules/_sqlite/util.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, pysqlite_Connection*
2828
{
2929
int rc;
3030

31-
Py_BEGIN_ALLOW_THREADS
32-
rc = sqlite3_step(statement);
33-
Py_END_ALLOW_THREADS
31+
if (statement == NULL) {
32+
/* this is a workaround for SQLite 3.5 and later. it now apparently
33+
* returns NULL for "no-operation" statements */
34+
rc = SQLITE_OK;
35+
} else {
36+
Py_BEGIN_ALLOW_THREADS
37+
rc = sqlite3_step(statement);
38+
Py_END_ALLOW_THREADS
39+
}
3440

3541
return rc;
3642
}

0 commit comments

Comments
 (0)