unix-ffi/sqlite3: Add optional parameter for URI support.

This commit adds the ability to enable URI on the connect, as can be done
in the cpython sqlite3 module. URI allows, among other things, to create
a shared named in-memory database, which non URI filenames cannot create.

Signed-off-by: Robert Klink <rhermanklink@ripe.net>
pull/905/head
Robert Klink 2024-07-31 14:38:25 +02:00 zatwierdzone przez Damien George
rodzic 0a65c3d34a
commit ab9c5a01b0
1 zmienionych plików z 7 dodań i 1 usunięć

Wyświetl plik

@ -6,6 +6,8 @@ import uctypes
sq3 = ffilib.open("libsqlite3")
sqlite3_open = sq3.func("i", "sqlite3_open", "sp")
# int sqlite3_config(int, ...);
sqlite3_config = sq3.func("i", "sqlite3_config", "ii")
# int sqlite3_close(sqlite3*);
sqlite3_close = sq3.func("i", "sqlite3_close", "p")
# int sqlite3_prepare(
@ -52,6 +54,8 @@ SQLITE_TEXT = 3
SQLITE_BLOB = 4
SQLITE_NULL = 5
SQLITE_CONFIG_URI = 17
class Error(Exception):
pass
@ -136,7 +140,9 @@ class Cursor:
check_error(self.h, res)
def connect(fname):
def connect(fname, uri=False):
sqlite3_config(SQLITE_CONFIG_URI, int(uri))
sqlite_ptr = bytes(get_ptr_size())
sqlite3_open(fname, sqlite_ptr)
return Connections(int.from_bytes(sqlite_ptr, sys.byteorder))