SQLite: max_rows breaks LIMIT -1 OFFSET n with a syntax error

Aperta Adatta ai principianti
#544 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@goranai ci sta già lavorando.

Dal 24/11/2026.

  • #545 di @goranai — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
sqlite, typescript
Ambito
database

Direzione di ricerca

Il bug si trova in findTopLevelLimit in src/utils/sql-row-limiter.ts, che non riconosce un conteggio negativo come -1 dopo LIMIT, quindi applyMaxRowsWithTruncationProbe aggiunge un secondo LIMIT. Inizia riproducendo il problema con executeSQL del connettore SQLite e maxRows impostato a 100, usando la tabella e la query della issue. È completato quando LIMIT -1 OFFSET 2 restituisce gli id da 3 a 6 con max_rows impostato, la query segue lo stesso percorso di wrap delle forme parametrizzate e i test unitari e di integrazione SQLite lo coprono.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

LIMIT -1 OFFSET n fails with a syntax error on SQLite when max_rows is set on the tool. The same query works without max_rows.

SQLite has no OFFSET without a LIMIT. Its docs say a negative LIMIT means no upper bound, so LIMIT -1 OFFSET n is the way to skip rows without capping them (https://www.sqlite.org/lang_select.html). Agents, hand-written SQL and literal-compiled SQL use this form. ORMs such as SQLAlchemy emit the same shape for offset-only selects, usually with -1 bound as a parameter.

Config:

[[sources]]
id = "lite"
dsn = "sqlite:///:memory:"

[[tools]]
name = "execute_sql"
source = "lite"
max_rows = 100

Table t(id) with ids 1 to 6, on main (b814ad3):

query sqlite3 dbhub with max_rows
SELECT id FROM t ORDER BY id LIMIT -1 OFFSET 2 3, 4, 5, 6 near "LIMIT": syntax error

I ran it through the real SQLiteConnector.executeSQL with maxRows: 100. SQLRowLimiter.applyMaxRowsWithTruncationProbe returns:

SELECT id FROM t ORDER BY id LIMIT -1 OFFSET 2
LIMIT 101

findTopLevelLimit in src/utils/sql-row-limiter.ts only knows digits, $n, ? and @pn as a count after LIMIT. It does not see -1 as a count, so it treats the statement as having no LIMIT and appends a second one. LIMIT 5, -1 has the same problem.

The parameterized forms (LIMIT ?, LIMIT 5, :n) already take the wrap path SELECT * FROM (...) AS subq LIMIT n. A negative number can take the same path.

I have a small fix with unit and SQLite integration tests and will send it as a PR.

Validated with Claude Opus 5.5.

Lingua principale
TypeScript
Stelle
4k
Fork
370
Merge medio
6h 28m
PR unite (30g)
41

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bytebase/dbhub

Tutte le issue di bytebase/dbhub

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.