mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-27 04:14:30 +02:00
Merge 5c6eb9a4ec into 85b1be10c8
This commit is contained in:
commit
6b726b1cfb
3 changed files with 15 additions and 2 deletions
|
|
@ -2160,7 +2160,7 @@ class Queryable:
|
||||||
:param offset: Integer for SQL offset
|
:param offset: Integer for SQL offset
|
||||||
"""
|
"""
|
||||||
if not self.exists():
|
if not self.exists():
|
||||||
return
|
raise NoTable(f"Table {self.name} does not exist")
|
||||||
sql = f"select {select} from {quote_identifier(self.name)}"
|
sql = f"select {select} from {quote_identifier(self.name)}"
|
||||||
if where is not None:
|
if where is not None:
|
||||||
sql += " where " + where
|
sql += " where " + where
|
||||||
|
|
@ -4105,7 +4105,7 @@ class Table(Queryable):
|
||||||
:param analyze: Set to ``True`` to run ``ANALYZE`` after the rows have been deleted.
|
:param analyze: Set to ``True`` to run ``ANALYZE`` after the rows have been deleted.
|
||||||
"""
|
"""
|
||||||
if not self.exists():
|
if not self.exists():
|
||||||
return self
|
raise NoTable(f"Table {self.name} does not exist")
|
||||||
sql = f"delete from {quote_identifier(self.name)}"
|
sql = f"delete from {quote_identifier(self.name)}"
|
||||||
if where is not None:
|
if where is not None:
|
||||||
sql += " where " + where
|
sql += " where " + where
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
|
import pytest
|
||||||
import sqlite_utils
|
import sqlite_utils
|
||||||
|
from sqlite_utils.db import NoTable
|
||||||
|
|
||||||
|
|
||||||
def test_delete_rowid_table(fresh_db):
|
def test_delete_rowid_table(fresh_db):
|
||||||
|
|
@ -62,3 +64,8 @@ def test_delete_where_analyze(fresh_db):
|
||||||
assert list(fresh_db.table("sqlite_stat1").rows) == [
|
assert list(fresh_db.table("sqlite_stat1").rows) == [
|
||||||
{"tbl": "table", "idx": "idx_table_i", "stat": "6 1"}
|
{"tbl": "table", "idx": "idx_table_i", "stat": "6 1"}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def test_delete_where_nonexistent_table(fresh_db):
|
||||||
|
with pytest.raises(NoTable):
|
||||||
|
fresh_db.table("does_not_exist").delete_where()
|
||||||
|
|
|
||||||
|
|
@ -147,3 +147,9 @@ def test_pks_and_rows_where_compound_pk_declaration_order(fresh_db):
|
||||||
fresh_db.table("t").insert({"a": "A", "b": "B"})
|
fresh_db.table("t").insert({"a": "A", "b": "B"})
|
||||||
pks_and_rows = list(fresh_db.table("t").pks_and_rows_where())
|
pks_and_rows = list(fresh_db.table("t").pks_and_rows_where())
|
||||||
assert pks_and_rows == [(("A", "B"), {"b": "B", "a": "A"})]
|
assert pks_and_rows == [(("A", "B"), {"b": "B", "a": "A"})]
|
||||||
|
|
||||||
|
|
||||||
|
def test_rows_where_nonexistent_table_raises(fresh_db):
|
||||||
|
from sqlite_utils.db import NoTable
|
||||||
|
with pytest.raises(NoTable):
|
||||||
|
list(fresh_db.table("does_not_exist").rows_where())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue