Skip to content

WI #2837 Handle unsupported SQL statements avoiding parser hang#2845

Open
allieseb wants to merge 10 commits intoTypeCobolTeam:developfrom
allieseb:pr/unsupported-sql-statement
Open

WI #2837 Handle unsupported SQL statements avoiding parser hang#2845
allieseb wants to merge 10 commits intoTypeCobolTeam:developfrom
allieseb:pr/unsupported-sql-statement

Conversation

@allieseb
Copy link
Copy Markdown

@allieseb allieseb commented Apr 8, 2026

Summary

  • Add UnsupportedSqlStatement CodeElement to gracefully handle unrecognized SQL DML/DDL statements (DELETE, DECLARE, OPEN, FETCH, CLOSE, etc.) inside EXEC SQL blocks
  • Replace hardcoded keyword list with a generic catch-all grammar rule that matches any SQL keyword not handled by a specific rule
  • Prevent parser hang on unknown SQL syntax by consuming tokens until END-EXEC

Fixes part of #2837

Test plan

  • New test ExecSqlWithUnsupportedStatement.rdz.cbl with 7 unsupported SQL statements
  • Updated ExecInDataDivision_NoEndExec.Mix.txt expected output
  • All 63 existing tests pass (26 skipped — perf/incremental)

🤖 Generated with Claude Code

allieseb and others added 7 commits April 7, 2026 11:01
…very

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… infrastructure

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- New test file with INSERT, UPDATE, DELETE, DECLARE CURSOR, OPEN, FETCH, CLOSE
- All 7 unsupported statements parse without errors (catch-all rule works)
- Updated expected results for ExecInDataDivision and ExecSqlWithCommit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The unsupportedSqlStatement rule now matches any SQL tokens until END-EXEC
instead of a closed list of 7 keywords. This handles all current and future
SQL statements (GRANT, REVOKE, MERGE, CALL, CREATE INDEX, etc.) without
requiring grammar updates for each new unsupported keyword.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@fm-117 fm-117 self-requested a review April 8, 2026 12:05
@fm-117 fm-117 changed the title fix: handle unsupported SQL statements without parser hang WI #2837 Handle unsupported SQL statements avoiding parser hang Apr 8, 2026
…ent set

Replace the arbitrary SQL keyword list in unsupportedSqlStatement with a
systematic set derived from the DB2 z/OS SQL Reference. The new
unsupportedSqlKeyword rule lists all 26 statement-starting keywords that
don't have a dedicated parser rule, with documentation of which SQL
statements they cover. This eliminates the need to guess which keywords
to add — when a new dedicated rule is created, its keyword is simply
removed from this list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@fm-117 fm-117 left a comment

Choose a reason for hiding this comment

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

@allieseb I need a file to test the initial problem: I'd like to compare between before and after this fix, please email me with a sample illustrating the hang.

Comment thread TypeCobol.Test/Parser/Programs/Cobol85/ExecSql/ExecSqlWithCommit.Tokens.txt Outdated
Comment thread TypeCobol/AntlrGrammar/CobolCodeElements.g4
Comment thread TypeCobol/AntlrGrammar/CobolCodeElements.g4 Outdated
Comment thread TypeCobol/AntlrGrammar/CobolCodeElements.g4
Comment thread TypeCobol/Compiler/Sql/CodeElements/Statements/UnsupportedSqlStatement.cs Outdated
Comment thread TypeCobol/Compiler/Sql/CodeElements/SqlStatementElement.cs Outdated
Comment thread TypeCobol/Compiler/Sql/CodeElements/SqlCodeElementBuilder.cs Outdated
allieseb and others added 2 commits April 10, 2026 11:10
- Revert unwanted encoding change in CobolCodeElements.g4 (preserve cp1252)
- Drop maintenance-prone statement list comment in unsupportedSqlStatement;
  add TODO noting SQL_MERGE (and possibly other SQL keywords) missing from
  the lexer token set
- UnsupportedSqlStatement: drop the per-statement example list in doc and
  add the missing VisitCodeElement override
- SqlCodeElementBuilder.CreateUnsupportedSqlStatement: drop the "UNKNOWN"
  fallback and pass the ANTLR token text directly (null allowed)
- Revert SqlStatementElement.cs changes that were not part of this PR
- Add UnsupportedSqlStatementChecker emitting a syntax error per
  unsupported statement; wire it from CobolCodeElementBuilder
- Comparators.SqlStatements: visit UnsupportedSqlStatement so test outputs
  include them
- Update LSR test EmptyExecStatement.tlsp expecting list to include
  UnsupportedSqlStatement
- Refresh expected outputs (ExecSqlWithCommit.Tokens.txt and
  ExecSqlWithUnsupportedStatement.SQL.txt)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Two related fixes that complete the answer to fm-117's "Where is the
COMMIT statement from the beginning ??" question on PR TypeCobolTeam#2845.

- CommitStatement was missing the VisitCodeElement override, so the
  AST visitor walked Commit nodes without ever calling Visit(CommitStatement).
  As a result, COMMIT statements never appeared in test outputs that
  rely on the SqlStatements comparator. Add the override following the
  same pattern as RollbackStatement.

- SqlObject.DumpProperty matched string values via the IEnumerable case
  (since string implements IEnumerable<char>) and dumped them
  character-by-character. Add a dedicated string case before the
  IEnumerable case so string properties (like UnsupportedSqlStatement.
  SqlKeyword) are written as a single value.

Refresh ExecSqlWithUnsupportedStatement.SQL.txt expected output to
include the now-visited COMMIT at line 10 and the readable SqlKeyword
values.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@fm-117 fm-117 self-requested a review April 10, 2026 09:36
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