Passing offset to rows_where() (or pks_and_rows_where()) without also passing limit generates invalid SQL and raises OperationalError.
Repro:
import sqlite_utils
db = sqlite_utils.Database(":memory:")
db["t"].insert_all([{"id": i} for i in range(5)])
list(db["t"].rows_where(offset=2))
# OperationalError: near "2": syntax error
Root cause: In db.py rows_where() appends OFFSET N to the SQL only when limit is not None is False, but SQLite requires LIMIT to appear before OFFSET. The generated SQL is SELECT * FROM "t" OFFSET 2, which is invalid syntax.
The same issue affects search_sql() when offset is given without limit.
Fix: When offset is set but limit is not, emit LIMIT -1 before the OFFSET clause. SQLite treats a negative limit as "no upper bound", so LIMIT -1 OFFSET N correctly returns all rows starting from position N.
Passing
offsettorows_where()(orpks_and_rows_where()) without also passinglimitgenerates invalid SQL and raisesOperationalError.Repro:
Root cause: In
db.pyrows_where()appendsOFFSET Nto the SQL only whenlimit is not Noneis False, but SQLite requiresLIMITto appear beforeOFFSET. The generated SQL isSELECT * FROM "t" OFFSET 2, which is invalid syntax.The same issue affects
search_sql()whenoffsetis given withoutlimit.Fix: When
offsetis set butlimitis not, emitLIMIT -1before theOFFSETclause. SQLite treats a negative limit as "no upper bound", soLIMIT -1 OFFSET Ncorrectly returns all rows starting from position N.