⚡ Sangsakala Proxy 🏠 Home
Skip to content

fix: end block comments at the first */ for dialects that do not nest - #2892

Closed
tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:block-comment-nesting-by-dialect
Closed

tanjiroK-coder wants to merge 1 commit into
JSQLParser:masterfrom
tanjiroK-coder:block-comment-nesting-by-dialect

Conversation

@tanjiroK-coder

Copy link
Copy Markdown
Contributor

The token manager's consumeBlockCommentBody honours nested block comments under every dialect, so a /* inside a comment opens another level and the comment runs on to a later /. MySQL, MariaDB, SQLite, Oracle, BigQuery and Spanner document that block comments do not nest: their servers end the comment at the first / and run what follows it. With Dialect.MYSQL the parser therefore returned SELECT 1 for SELECT 1 / a / b */ + 2 -- */, which MySQL evaluates as SELECT 1 + 2, so TablesNamesFinder, the validators and a rewriter all work on a different statement from the one the server executes. H2 returns 1 for the same text, so it keeps nesting together with PostgreSQL, SQL Server, ANSI_SQL and a parser without a dialect. Dialect gains isNestedBlockComments(), and the token manager nests only when the configured dialect does; the remaining dialects keep nesting until their behaviour is documented. The new NestedCommentTest cases fail on master for the six dialects and pass after, and ./gradlew check is green.

consumeBlockCommentBody honoured nested block comments under every
dialect, so a /* inside a comment opened another level and the comment
ran on to a later */. MySQL, MariaDB, SQLite, Oracle, BigQuery and
Spanner end a block comment at the first */ and run what follows it,
so with Dialect.MYSQL the parser returned SELECT 1 for
SELECT 1 /* a /* b */ + 2 -- */, which the server evaluates as
SELECT 1 + 2.

Dialect gains isNestedBlockComments(), false for those six dialects,
and the token manager nests only when the configured dialect does.
Without a dialect, and for PostgreSQL, SQL Server, H2 and the other
dialects, nesting is unchanged.
@manticore-projects

manticore-projects commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

SELECT 1 / a / b */ + 2 -- */

Please, we need to stop here.

@tanjiroK-coder

Copy link
Copy Markdown
Contributor Author

Understood. The nesting in consumeBlockCommentBody was a deliberate choice and that input is contrived, so I won't push dialect-specific lexing for it. Fine to close this.

@manticore-projects

Copy link
Copy Markdown
Contributor

Please do not feel offended, I do appreciate your work and support.
But our goal is to write the most general purpose and best performance SQL parser -- not to support any crazy mess the RDBMS have introduced over the decades. Please bear in mind: someone has to maintain all of this in the future.

@tanjiroK-coder

Copy link
Copy Markdown
Contributor Author

No offence taken. The maintenance point is fair, one lexer path for every dialect is easier to keep right than per-dialect comment rules. Closing this.

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