Fix rows_where() crash when offset is given without limit

SQLite requires LIMIT before OFFSET; omitting it raised OperationalError.
When offset is set and limit is not, emit LIMIT -1 first so the SQL is valid.
Same fix applied to search_sql(). Adds regression test.
This commit is contained in:
ikatyal21 2026-07-26 14:37:29 +00:00
commit 72b7d469a4
No known key found for this signature in database
2 changed files with 11 additions and 0 deletions

View file

@ -2003,6 +2003,8 @@ class Queryable:
if limit is not None:
sql += f" limit {limit}"
if offset is not None:
if limit is None:
sql += " limit -1"
sql += f" offset {offset}"
cursor = self.db.execute(sql, where_args or [])
columns = dedupe_keys(c[0] for c in cursor.description)
@ -3594,6 +3596,8 @@ class Table(Queryable):
if limit is not None:
limit_offset += f" limit {limit}"
if offset is not None:
if limit is None:
limit_offset += " limit -1"
limit_offset += f" offset {offset}"
return sql.format(
dbtable=quote_identifier(self.name),