fix: auto-commit delete_where()

This commit is contained in:
cloudyun888 2026-04-22 15:14:25 +08:00
commit fcbab3649d
No known key found for this signature in database
2 changed files with 18 additions and 3 deletions

View file

@ -2905,9 +2905,10 @@ class Table(Queryable):
sql = "delete from {}".format(quote_identifier(self.name))
if where is not None:
sql += " where " + where
self.db.execute(sql, where_args or [])
if analyze:
self.analyze()
with self.db.conn:
self.db.execute(sql, where_args or [])
if analyze:
self.analyze()
return self
def update(

View file

@ -1,3 +1,4 @@
from sqlite_utils import Database
def test_delete_rowid_table(fresh_db):
table = fresh_db["table"]
table.insert({"foo": 1}).last_pk
@ -32,6 +33,19 @@ def test_delete_where_all(fresh_db):
assert table.count == 0
def test_delete_where_all_auto_commits(db_path):
db = Database(db_path)
table = db["table"]
table.insert_all(({"id": i} for i in range(1, 6)), pk="id")
assert table.count == 5
table.delete_where()
assert table.count == 0
reopened = Database(db_path)
assert reopened["table"].count == 0
def test_delete_where_analyze(fresh_db):
table = fresh_db["table"]
table.insert_all(({"id": i, "i": i} for i in range(10)), pk="id")