Skip to content

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

Open
ItsDeadlyProgrammer wants to merge 2 commits into
JSQLParser:masterfrom
ItsDeadlyProgrammer:feat/sqlite-insert-or-conflict
Open

ItsDeadlyProgrammer wants to merge 2 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.

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 589893e to 8805d37 Compare October 23, 2026 10:57

This branch has not been deployed

No deployments
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