This commit is contained in:
fry69 2026-06-24 21:18:23 +00:00 committed by GitHub
commit 654636ad74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 308 additions and 48 deletions

View file

@ -383,7 +383,10 @@ class Database:
self.conn = sqlite3.connect(":memory:")
self.memory = True
elif isinstance(filename_or_conn, (str, pathlib.Path)):
if recreate and os.path.exists(filename_or_conn):
filename_str = str(filename_or_conn)
# Check if this is a URI filename (starts with "file:")
is_uri = filename_str.startswith("file:")
if recreate and not is_uri and os.path.exists(filename_or_conn):
try:
os.remove(filename_or_conn)
except OSError:
@ -391,7 +394,11 @@ class Database:
# https://github.com/simonw/sqlite-utils/issues/503
self.conn = sqlite3.connect(":memory:")
raise
self.conn = sqlite3.connect(str(filename_or_conn))
if is_uri:
# URI filenames need uri=True parameter
self.conn = sqlite3.connect(filename_str, uri=True)
else:
self.conn = sqlite3.connect(filename_str)
else:
assert not recreate, "recreate cannot be used with connections, only paths"
self.conn = cast(sqlite3.Connection, filename_or_conn)