Skip to content

Fix sqlite store in 2.x #2880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Release notes
Unreleased
----------

Fixes
~~~~~
* Fixed ``SQLiteStore`` with the latest version of ``sqlite3``.
By :user:`David Stansby <dstansby>`

Deprecations
~~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ filterwarnings = [
"ignore:The loop argument is deprecated since Python 3.8.*:DeprecationWarning",
"ignore:The .* is deprecated and will be removed in a Zarr-Python version 3*:FutureWarning",
"ignore:The experimental Zarr V3 implementation in this version .*:FutureWarning",
"ignore:unclosed database in <sqlite3.Connection.*:ResourceWarning",
]
doctest_subpackage_requires = [
"zarr/core.py = numpy>=2",
Expand Down
2 changes: 1 addition & 1 deletion zarr/_storage/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def rmdir(self, path=None):
if path:
for base in [meta_root, data_root]:
with self.lock:
self.cursor.execute('DELETE FROM zarr WHERE k LIKE (? || "/%")', (base + path,))
self.cursor.execute("DELETE FROM zarr WHERE k LIKE (? || '/%')", (base + path,))
# remove any associated metadata files
sfx = _get_metadata_suffix(self)
meta_dir = (meta_root + path).rstrip("/")
Expand Down
12 changes: 6 additions & 6 deletions zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2779,9 +2779,9 @@ def listdir(self, path=None):
sep = "_" if path == "" else "/"
keys = self.cursor.execute(
f"""
SELECT DISTINCT SUBSTR(m, 0, INSTR(m, "/")) AS l FROM (
SELECT LTRIM(SUBSTR(k, LENGTH(?) + 1), "/") || "/" AS m
FROM zarr WHERE k LIKE (? || "{sep}%")
SELECT DISTINCT SUBSTR(m, 0, INSTR(m, '/')) AS l FROM (
SELECT LTRIM(SUBSTR(k, LENGTH(?) + 1), '/') || '/' AS m
FROM zarr WHERE k LIKE (? || '{sep}%')
) ORDER BY l ASC
""",
(path, path),
Expand All @@ -2794,8 +2794,8 @@ def getsize(self, path=None):
size = self.cursor.execute(
"""
SELECT COALESCE(SUM(LENGTH(v)), 0) FROM zarr
WHERE k LIKE (? || "%") AND
0 == INSTR(LTRIM(SUBSTR(k, LENGTH(?) + 1), "/"), "/")
WHERE k LIKE (? || '%') AND
0 == INSTR(LTRIM(SUBSTR(k, LENGTH(?) + 1), '/'), '/')
""",
(path, path),
)
Expand All @@ -2806,7 +2806,7 @@ def rmdir(self, path=None):
path = normalize_storage_path(path)
if path:
with self.lock:
self.cursor.execute('DELETE FROM zarr WHERE k LIKE (? || "/%")', (path,))
self.cursor.execute("DELETE FROM zarr WHERE k LIKE (? || '/%')", (path,))
else:
self.clear()

Expand Down
Loading