Repository navigation
refactor(jdbc): route statement SQL checks through SqlTokenizer - #165
Conversation
Cover INSERT OR REPLACE, comments, quoted identifiers, PRAGMA assignment, and malformed input.
|
PASS+NOTES Verified revisions
Static and unit level (at head)
User-level probe (at head)Real sqld container (
Parent against headChecked out base
The other 7 probes pass at base. The worktree was returned to head Note 2: the owner's claim that exactly the two comment probes fail at base is off by one. The CTE-plus-comment probe fails at base as well, so the change fixes three comment cases, not two. This does not weaken the change; it only corrects the stated base delta. Notes
|
Why
The statement and the prepared statement each carried their own SQL scanner, so the driver kept three copies of the same SQLite lexical rules.
SqlTokenizeralready owns those rules for result metadata. This change routes the last two call sites through it and deletes the copies.What changed
LibsqlStatement.isInsertSqlreads the first depth-0 statement keyword fromSqlTokenizer. Generated keys now treat comments and quoted identifiers the same way the metadata parsers do.LibsqlPreparedStatementdecidesexecuteQueryagainstexecuteUpdatefrom the same tokens. Its privateTokenrecord and scanner are gone.=, WITH...INSERT RETURNING, and malformed input.Scope
The old scanners ignored a comment before INSERT and a comment between a WITH clause and its INSERT, so those statements reported no generated keys. The shared tokenizer fixes both, and the new tests pin them. Malformed SQL now classifies as an update. That changes the local error for
executeQuery, but no statement that executes changes behavior.Tradeoffs
I sampled four reusable tokenizers and parsers. JSqlParser lexed all 38 SQLite samples but parsed only 26, so it would still need this fallback. The ANTLR SQLite grammar is the best external lexer, but the in-repo tokenizer has no dependency and already matches SQLite's rules.
Blast Radius
Every
getGeneratedKeyscall and every prepared-statementexecuteQueryandexecuteUpdatedecision now usesSqlTokenizer. The module suite and the xerial conformance suite cover both paths.Verification
./mvnw -pl libsql-jdbc test: 351 tests, 0 failures. The 336 tests green at HEAD stayed green after the source change alone../mvnw -pl libsql-conformance -am verify: 268 tests, 0 failures, 7 skipped.