mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-34041: Allow creating deterministic functions in Connection.create_function() (GH-8086)
This commit is contained in:
parent
8d41278045
commit
0830858aee
4 changed files with 62 additions and 6 deletions
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue