@@ -28,9 +28,10 @@ class SqliteDb:
2828 etc(a, b)
2929
3030 """
31- def __init__ (self , filename : str , debug : TDebugCtl ) -> None :
31+ def __init__ (self , filename : str , debug : TDebugCtl , no_disk : bool = False ) -> None :
3232 self .debug = debug
3333 self .filename = filename
34+ self .no_disk = no_disk
3435 self .nest = 0
3536 self .con : sqlite3 .Connection | None = None
3637
@@ -49,7 +50,11 @@ def _connect(self) -> None:
4950 if self .debug .should ("sql" ):
5051 self .debug .write (f"Connecting to { self .filename !r} " )
5152 try :
52- self .con = sqlite3 .connect (self .filename , check_same_thread = False )
53+ # Use uri=True when connecting to memory URIs
54+ if self .filename .startswith ("file:" ):
55+ self .con = sqlite3 .connect (self .filename , check_same_thread = False , uri = True )
56+ else :
57+ self .con = sqlite3 .connect (self .filename , check_same_thread = False )
5358 except sqlite3 .Error as exc :
5459 raise DataError (f"Couldn't use data file { self .filename !r} : { exc } " ) from exc
5560
@@ -78,7 +83,7 @@ def _connect(self) -> None:
7883 def close (self , force : bool = False ) -> None :
7984 """If needed, close the connection."""
8085 if self .con is not None :
81- if force or self .filename != ":memory:" :
86+ if force or not self .no_disk :
8287 if self .debug .should ("sql" ):
8388 self .debug .write (f"Closing { self .con !r} on { self .filename !r} " )
8489 self .con .close ()
@@ -120,7 +125,7 @@ def _execute(self, sql: str, parameters: Iterable[Any]) -> sqlite3.Cursor:
120125 return self .con .execute (sql , parameters ) # type: ignore[arg-type]
121126 except sqlite3 .Error as exc :
122127 msg = str (exc )
123- if self .filename != ":memory:" :
128+ if not self .no_disk :
124129 try :
125130 # `execute` is the first thing we do with the database, so try
126131 # hard to provide useful hints if something goes wrong now.
0 commit comments