Skip to content

feat: parse INSERT OR ABORT, FAIL, IGNORE and ROLLBACK (SQLite) - #2853

Merged
manticore-projects merged 3 commits into
JSQLParser:masterfrom
ItsDeadlyProgrammer:feat/sqlite-insert-or-conflict
Oct 26, 2026
Merged

manticore-projects merged 3 commits into
JSQLParser:masterfrom
ItsDeadlyProgrammer:feat/sqlite-insert-or-conflict

Conversation

@ItsDeadlyProgrammer

Copy link
Copy Markdown

Part of #2852 (the INSERT OR half; UPDATE OR ..., WITHOUT ROWID and STRICT are not in this PR).

UpsertType already has INSERT_OR_ABORT, INSERT_OR_FAIL, INSERT_OR_IGNORE and INSERT_OR_ROLLBACK, and Upsert and UpsertDeParser print them, but the grammar only accepted INSERT OR REPLACE. This adds the other four to the Upsert production. ABORT and FAIL are not keywords of the parser, so they are read as identifiers and checked by name; any other word after INSERT OR is a parse error.

SQLiteTest covers all five algorithms with column list and SELECT source, a lower case variant, and an unknown word. The four new cases fail without the grammar change. The full ./gradlew test run has 35 failures (StatementDeParserTest, ExpressionDeParserTest, WithFunctionDeclarationTest and others); they fail the same way on an unmodified master here (JDK 25), none involve INSERT OR.

(
<K_INSERT> <K_OR> <K_REPLACE> { upsert.setUpsertType(UpsertType.INSERT_OR_REPLACE); }
<K_INSERT> <K_OR>
(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do understand that this is SQLite specific syntax. If my understanding is correct, then please guard this block by the SQLite Dialect.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done in 8805d37. There was no SQLite value in Dialect, so I added Dialect.SQLITE and listed it in the dialect table in usage.rst.

INSERT OR IGNORE, ROLLBACK, ABORT and FAIL now parse only with Dialect.SQLITE; other dialects get a ParseException saying so. INSERT OR REPLACE still parses everywhere, because it did before this PR. The tests cover both cases, and the checks are green.

@ItsDeadlyProgrammer
ItsDeadlyProgrammer force-pushed the feat/sqlite-insert-or-conflict branch from 589893e to 8805d37 Compare October 23, 2026 10:57
@manticore-projects

Copy link
Copy Markdown
Contributor

Please fix the failing QA/CI tests.

UpsertType and the deparsers already had these values, but the grammar
only accepted INSERT OR REPLACE.

Part of JSQLParser#2852
Add Dialect.SQLITE. INSERT OR ABORT, FAIL, IGNORE and ROLLBACK need it.
INSERT OR REPLACE keeps parsing in every dialect.
@ItsDeadlyProgrammer
ItsDeadlyProgrammer force-pushed the feat/sqlite-insert-or-conflict branch from fe5d183 to 7eb65c8 Compare October 24, 2026 17:16
The extra INSERT OR alternatives pushed the constant pool of CCJSqlParser
past 65535 entries once JaCoCo instrumented it, so the class was silently
left without coverage data and the coverage check failed. Parse the
algorithm with RelObjectName and decide in AbstractJSqlParser instead.
@ItsDeadlyProgrammer

Copy link
Copy Markdown
Author

The CI failure was a JaCoCo issue, not a test failure. CCJSqlParser is close to the 65535 constant-pool limit, and the extra alternatives pushed it over once JaCoCo added its probes, so the class was left uninstrumented and the coverage check dropped to 21%. I reproduced this locally (ClassTooLargeException from JaCoCo's instrumenter).

7ffb392 parses the algorithm with RelObjectName() and decides in AbstractJSqlParser.insertOrType, which keeps the parser class below the limit. The syntax and the SQLite-dialect guard are unchanged. The workflow needs approval to run on the new commit.

@manticore-projects
manticore-projects merged commit 9663289 into JSQLParser:master Oct 26, 2026
10 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants