summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorGerhard Häring <gh@ghaering.de>2006-06-14 22:28:37 (GMT)
committerGerhard Häring <gh@ghaering.de>2006-06-14 22:28:37 (GMT)
commitb2e881640377945716a5f4b147f8438f9e4738de (patch)
treee4a52a0b9356e3c53248723e7f65565de694d6ce /Modules/_sqlite
parent69f6168b766d3fb8fbd0dec8cbeaf97ce564e2c4 (diff)
downloadcpython-b2e881640377945716a5f4b147f8438f9e4738de.zip
cpython-b2e881640377945716a5f4b147f8438f9e4738de.tar.gz
cpython-b2e881640377945716a5f4b147f8438f9e4738de.tar.bz2
- Added version checks in C code to make sure we don't trigger bugs in older
SQLite versions. - Added version checks in test suite so that we don't execute tests that we know will fail with older (buggy) SQLite versions. Now, all tests should run against all SQLite versions from 3.0.8 until 3.3.6 (latest one now). The sqlite3 module can be built against all these SQLite versions and the sqlite3 module does its best to not trigger bugs in SQLite, but using SQLite 3.3.3 or later is recommended.
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/connection.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index bf74710..f63d88c 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -34,6 +34,17 @@
static int connection_set_isolation_level(Connection* self, PyObject* isolation_level);
+
+void _sqlite3_result_error(sqlite3_context* ctx, const char* errmsg, int len)
+{
+ /* in older SQLite versions, calling sqlite3_result_error in callbacks
+ * triggers a bug in SQLite that leads either to irritating results or
+ * segfaults, depending on the SQLite version */
+#if SQLITE_VERSION_NUMBER >= 3003003
+ sqlite3_result_error(ctx, errmsg, len);
+#endif
+}
+
int connection_init(Connection* self, PyObject* args, PyObject* kwargs)
{
static char *kwlist[] = {"database", "timeout", "detect_types", "isolation_level", "check_same_thread", "factory", "cached_statements", NULL, NULL};
@@ -526,7 +537,7 @@ void _func_callback(sqlite3_context* context, int argc, sqlite3_value** argv)
} else {
PyErr_Clear();
}
- sqlite3_result_error(context, "user-defined function raised exception", -1);
+ _sqlite3_result_error(context, "user-defined function raised exception", -1);
}
PyGILState_Release(threadstate);
@@ -558,7 +569,7 @@ static void _step_callback(sqlite3_context *context, int argc, sqlite3_value** p
} else {
PyErr_Clear();
}
- sqlite3_result_error(context, "user-defined aggregate's '__init__' method raised error", -1);
+ _sqlite3_result_error(context, "user-defined aggregate's '__init__' method raised error", -1);
goto error;
}
}
@@ -582,7 +593,7 @@ static void _step_callback(sqlite3_context *context, int argc, sqlite3_value** p
} else {
PyErr_Clear();
}
- sqlite3_result_error(context, "user-defined aggregate's 'step' method raised error", -1);
+ _sqlite3_result_error(context, "user-defined aggregate's 'step' method raised error", -1);
}
error:
@@ -619,7 +630,7 @@ void _final_callback(sqlite3_context* context)
} else {
PyErr_Clear();
}
- sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1);
+ _sqlite3_result_error(context, "user-defined aggregate's 'finalize' method raised error", -1);
} else {
_set_result(context, function_result);
}