Skip to content
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
6 changes: 6 additions & 0 deletions .github/actions/setup-sqlite-version/setup-sqlite-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ case "$version_spec" in
amalgamation_id="3460000"
builtin_fallback_urls="https://static.simonwillison.net/static/2026/sqlite-amalgamation-3460000.zip"
;;
3.25.3)
sqlite_version="3.25.3"
sqlite_year="2018"
amalgamation_id="3250300"
builtin_fallback_urls=""
;;
3.23.1)
sqlite_version="3.23.1"
sqlite_year="2018"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-sqlite-support.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
python-version: ["3.10"]
sqlite-version: [
"3.46",
"3.25.3", # 2018-11-05, UPSERT but requires a conflict target
"3.23.1", # 2018-04-10, before UPSERT
]
steps:
Expand Down
4 changes: 3 additions & 1 deletion sqlite_utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,8 @@ def supports_strict(self) -> bool:
@property
def supports_on_conflict(self) -> bool:
# SQLite's upsert is implemented as INSERT INTO ... ON CONFLICT DO ...
# SQLite 3.24 to 3.34 require an explicit conflict target, so the
# probe includes one: https://github.com/simonw/sqlite-utils/issues/976
if not hasattr(self, "_supports_on_conflict"):
table_name = f"t{secrets.token_hex(16)}"
try:
Expand All @@ -1180,7 +1182,7 @@ def supports_on_conflict(self) -> bool:
)
self.conn.execute(
f"insert into {table_name} (id, name) values (1, 'two') "
"on conflict do update set name = 'two'"
"on conflict(id) do update set name = 'two'"
)
self._supports_on_conflict = True
except sqlite3.OperationalError:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_fts.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ def test_enable_fts_with_triggers(fresh_db):
@pytest.mark.parametrize("fts_version", ["FTS4", "FTS5"])
def test_fts_triggers_keep_updates_and_deletes_in_sync(fresh_db, fts_version):
table_name = "notes '100%'"
if fts_version == "FTS5" and fresh_db.sqlite_version < (3, 24, 0):
# SQLite 3.23.1 does not quote the table name when it builds the
if fts_version == "FTS5" and fresh_db.sqlite_version < (3, 30, 0):
# SQLite before 3.30.0 does not quote the table name when it builds the
# query for "order by rank", so FTS5 search fails with a syntax
# error for any table name that needs quoting
table_name = "notes"
Expand Down
8 changes: 8 additions & 0 deletions tests/test_upsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ def test_upsert_existing_row_omitting_not_null_column(use_old_upsert):
assert dogs.last_pk == 1


def test_supports_on_conflict_matches_sqlite_version(fresh_db):
# Upsert arrived in SQLite 3.24.0, but versions before 3.35.0 require an
# explicit conflict target - the probe must still detect support there
# https://github.com/simonw/sqlite-utils/issues/976
version = tuple(int(part) for part in sqlite3.sqlite_version.split("."))
assert fresh_db.supports_on_conflict == (version >= (3, 24, 0))


def test_upsert_new_row_omitting_not_null_column_errors(fresh_db):
# A partial upsert that would create a new row must not invent a value
# for a NOT NULL column - it should fail the constraint
Expand Down
Loading