Skip to content

Commit 7a44338

Browse files
committed
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 <[email protected]>
1 parent d6b6e03 commit 7a44338

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

unix-ffi/sqlite3/sqlite3.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
sq3 = ffilib.open("libsqlite3")
77

88
sqlite3_open = sq3.func("i", "sqlite3_open", "sp")
9+
# int sqlite3_config(int, ...);
10+
sqlite3_config = sq3.func("i", "sqlite3_config", "ii")
911
# int sqlite3_close(sqlite3*);
1012
sqlite3_close = sq3.func("i", "sqlite3_close", "p")
1113
# int sqlite3_prepare(
@@ -52,6 +54,8 @@
5254
SQLITE_BLOB = 4
5355
SQLITE_NULL = 5
5456

57+
SQLITE_CONFIG_URI = 17
58+
5559

5660
class Error(Exception):
5761
pass
@@ -136,7 +140,9 @@ def fetchone(self):
136140
check_error(self.h, res)
137141

138142

139-
def connect(fname):
143+
def connect(fname, uri=False):
144+
sqlite3_config(SQLITE_CONFIG_URI, int(uri))
145+
140146
sqlite_ptr = bytes(get_ptr_size())
141147
sqlite3_open(fname, sqlite_ptr)
142148
return Connections(int.from_bytes(sqlite_ptr, sys.byteorder))

0 commit comments

Comments
 (0)