Commit graph

12 commits

Author SHA1 Message Date
Simon Willison
c2a1774409 Fix two tests that assumed modern SQLite behavior
SQLite 3.23.1 rejects a UTF-8 byte order mark before the first token,
so the BOM variant of the execute()-prefixed-BEGIN test now skips when
the SQLite version does not accept a leading BOM. And versions before
3.36 allowed selecting rowid from a view, returning NULL, rather than
raising an error - the pks_and_rows_where() view test now accepts
either behavior.

Refs https://github.com/simonw/sqlite-utils/issues/769#issuecomment-4900034150

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 22:02:41 -07:00
Simon Willison
1ed95e4ad2 Fix pks_and_rows_where() on views
The previous compound-pk-ordering commit switched pks_and_rows_where()
to Table-only properties, but the method is defined on Queryable and
views exposed it too - calling it on a View raised AttributeError.

Restored Queryable-safe logic, and stopped double-quoting the
synthesized rowid column: SQLite turns a double-quoted identifier that
does not resolve into a string literal, so on a view the generated
select "rowid" silently produced the string 'rowid' and a confusing
KeyError, where 3.x's [rowid] quoting raised OperationalError cleanly.

Refs https://github.com/simonw/sqlite-utils/issues/769#issuecomment-4900034150

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-06 21:42:02 -07:00
Simon Willison
07b603e562
Preserve duplicate column names in query results
Queries returning duplicate column names - e.g. joins between tables
sharing column names - silently lost values because rows were built
with dict(zip(keys, row)), where the last duplicate wins.

Later occurrences are now renamed with a numeric suffix: id, id
becomes id, id_2 - skipping any suffix that would collide with a
real column in the same query.

The new utils.dedupe_keys() helper transforms the key list once per
query, so the per-row dict construction is unchanged and there is no
measurable performance impact.

Applied in Database.query() (including the PRAGMA and RETURNING
paths), Table.rows_where(), Table.search() and the CLI's JSON output.
CSV, TSV and table output keep the original duplicate headers.

Closes #624
2026-07-05 21:20:39 -07:00
Simon Willison
90e211e3e2 Now complies with flake8, refs #291 2021-06-22 18:22:08 -07:00
Simon Willison
2dad4f583c Improved .rows_where() documentation, added test for :named parameters 2021-06-02 11:57:11 -07:00
Simon Willison
16987bd56e Removed rogue assert False, refs #240 2021-02-25 08:35:24 -08:00
Simon Willison
38e688fb8b table.pks_and_rows_where() method, closes #240 2021-02-25 08:28:17 -08:00
Simon Willison
320f3ac33a offset= and limit= parameters, closes #231 2021-02-14 12:02:41 -08:00
Simon Willison
2db6c5b2d5 table.extract() now works with rowid tables, refs #42 2020-09-22 16:11:28 -07:00
Simon Willison
71782311ce New .rows_where(select=) argument 2020-09-22 16:10:14 -07:00
Simon Willison
125c625fbc .rows_where(..., order_by=) argument, closes #76 2020-04-15 20:12:55 -07:00
Simon Willison
fc38868bd4 Refactored tests into new test_rows.py, refs #76 2020-04-15 18:04:55 -07:00