summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite
diff options
context:
space:
mode:
authorSergey Fedoseev <fedoseev.sergey@gmail.com>2018-07-08 07:09:20 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2018-07-08 07:09:20 (GMT)
commit0830858aeedecc9ece60349f8c31c2690d1a99f8 (patch)
tree8cd32ec3cb898edd3631df2378662aa13e8b761a /Modules/_sqlite
parent8d41278045ee4e8bf1cadb58a7db58d70ad55237 (diff)
downloadcpython-0830858aeedecc9ece60349f8c31c2690d1a99f8.zip
cpython-0830858aeedecc9ece60349f8c31c2690d1a99f8.tar.gz
cpython-0830858aeedecc9ece60349f8c31c2690d1a99f8.tar.bz2
bpo-34041: Allow creating deterministic functions in Connection.create_function() (GH-8086)
Diffstat (limited to 'Modules/_sqlite')
-rw-r--r--Modules/_sqlite/connection.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index ef2daeb..b8470df 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -810,24 +810,48 @@ static void _pysqlite_drop_unused_cursor_references(pysqlite_Connection* self)
PyObject* pysqlite_connection_create_function(pysqlite_Connection* self, PyObject* args, PyObject* kwargs)
{
- static char *kwlist[] = {"name", "narg", "func", NULL, NULL};
+ static char *kwlist[] = {"name", "narg", "func", "deterministic", NULL};
PyObject* func;
char* name;
int narg;
int rc;
+ int deterministic = 0;
+ int flags = SQLITE_UTF8;
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
}
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO", kwlist,
- &name, &narg, &func))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO|$p", kwlist,
+ &name, &narg, &func, &deterministic))
{
return NULL;
}
- rc = sqlite3_create_function(self->db, name, narg, SQLITE_UTF8, (void*)func, _pysqlite_func_callback, NULL, NULL);
+ if (deterministic) {
+#if SQLITE_VERSION_NUMBER < 3008003
+ PyErr_SetString(pysqlite_NotSupportedError,
+ "deterministic=True requires SQLite 3.8.3 or higher");
+ return NULL;
+#else
+ if (sqlite3_libversion_number() < 3008003) {
+ PyErr_SetString(pysqlite_NotSupportedError,
+ "deterministic=True requires SQLite 3.8.3 or higher");
+ return NULL;
+ }
+ flags |= SQLITE_DETERMINISTIC;
+#endif
+ }
+
+ rc = sqlite3_create_function(self->db,
+ name,
+ narg,
+ flags,
+ (void*)func,
+ _pysqlite_func_callback,
+ NULL,
+ NULL);
if (rc != SQLITE_OK) {
/* Workaround for SQLite bug: no error code or string is available here */