rigglemania / pysqlcipher3

Python 3 bindings for SQLCipher
zlib License
138 stars 42 forks source link

create_function no support for flag deterministic #33

Open msftcangoblowm opened 1 year ago

msftcangoblowm commented 1 year ago

From py383, sqlite3 create_function supports deterministic flag

py383 release log

Added SQLITE_DETERMINISTIC as an optional bit in the 4th argument to the sqlite3_create_function() and related interfaces, providing applications with the ability to create new functions that can be factored out of inner loops when they have constant arguments

pysqlcipher3 return NULL (aka error occurred) when the kwarg/flag deterministic is provided

This breaks sqlalchemy sqlite+pysqlcipher driver. Forcing sqlalchemy dev to recommend using python3 -m pip install sqlcipher3-binary wheel instead of pysqlcipher3. Reasoning being pysqlcipher3 is not in compliance with the sqlite3 docs.

In discussion thread issue 9430; tracked down the bug to connection.c

pysqlcipher3 python3/connection.c:835

static char *kwlist[] = {"name", "narg", "func", NULL, NULL};

Should look like

https://github.com/coleifer/sqlcipher3/blob/master/src/connection.c#L997

static char *kwlist[] = {"name", "narg", "func", "deterministic", NULL};

triggers failure when checking kwargs


if (!PyArg_ParseTupleAndKeywords(args, kwargs, "siO", kwlist,
                                     &name, &narg, &func))
    {
        return NULL;
    }

So the keywords check return NULL when kwargs deterministic is provided, even if it would be later ignored.

Please confirm the issue. Then in create_function, add deterministic flag as an acceptable kwarg in pysqlite_connection_create_function