Skip to content
Open
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: 2 additions & 3 deletions sqlite_utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -2205,15 +2205,14 @@ def pks_and_rows_where(
key=lambda column: column.is_pk,
)
pks = [column.name for column in pk_columns]
select_parts = [quote_identifier(column.name) for column in self.columns]
select = "*"
if not pks:
# rowid is left unquoted: it is not a real column, and SQLite
# turns a double-quoted identifier that does not resolve into a
# string literal - on a view that would silently select the
# string 'rowid' instead of raising an error
select_parts.insert(0, "rowid")
select = "rowid, *"
pks = ["rowid"]
select = ",".join(select_parts)
for row in self.rows_where(
select=select,
where=where,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,15 @@ def test_pks_and_rows_where_compound_pk_declaration_order(fresh_db):
fresh_db.table("t").insert({"a": "A", "b": "B"})
pks_and_rows = list(fresh_db.table("t").pks_and_rows_where())
assert pks_and_rows == [(("A", "B"), {"b": "B", "a": "A"})]


def test_pks_and_rows_where_includes_generated_columns(fresh_db):
fresh_db.execute(
"create table scores (id integer primary key, points integer, "
"double_points integer generated always as (points * 2))"
)
table = fresh_db["scores"]
table.insert({"id": 1, "points": 7})
assert list(table.pks_and_rows_where()) == [
(1, {"id": 1, "points": 7, "double_points": 14})
]
Loading