Add SQL DML and cursor statement support#2838
Closed
allieseb wants to merge 2 commits intoTypeCobolTeam:developfrom
Closed
Add SQL DML and cursor statement support#2838allieseb wants to merge 2 commits intoTypeCobolTeam:developfrom
allieseb wants to merge 2 commits intoTypeCobolTeam:developfrom
Conversation
Extend the EXEC SQL parser with support for 7 new statement types that were previously scanned as raw ExecText tokens: - INSERT INTO ... VALUES / INSERT INTO ... SELECT - UPDATE ... SET ... WHERE - DELETE FROM ... WHERE - DECLARE CURSOR ... FOR fullselect - OPEN cursor - CLOSE cursor - FETCH cursor INTO :host-var These are the most common DB2 embedded SQL statements found in COBOL production programs and were missing from the parsed SQL subset. For each statement the full pipeline is wired: 1. ANTLR grammar rules (CobolCodeElements.g4) 2. CodeElementType + StatementType enums 3. IsSqlStatementStartingKeyword() for error recovery 4. Typed CodeElement classes (Sql/CodeElements/Statements/) 5. AST Node classes (Sql/Nodes/) 6. SqlCodeElementBuilder.Create*() extraction methods 7. CobolCodeElementBuilder.Enter*() ANTLR callbacks 8. IASTVisitor Visit() overloads + AbstractAstVisitor defaults 9. IProgramClassBuilder / ProgramClassBuilder / Dispatcher / Listener 10. CUP terminals and sqlStatement alternatives (both .cup files) Naming: DELETE, OPEN and CLOSE are prefixed Sql* (SqlDeleteStatement, SqlOpenStatement, SqlCloseStatement, SqlDelete node) to avoid collision with the existing COBOL-native statements of the same name. A minimal searchCondition rule (expr = expr) is introduced for the WHERE clause; it is intentionally simple and marked TODO for future expansion (AND/OR/BETWEEN/IN/LIKE). Requires EnableSqlParsing = true in TypeCobolOptions (defaults to false) for the scanner to tokenize SQL keywords inside EXEC SQL blocks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tement classes - Rename SqlCloseStatement → CloseCursorStatement - Rename SqlOpenStatement → OpenCursorStatement - Rename SqlDeleteStatement → DeleteSqlStatement - Rename SqlDelete node → DeleteSql - Consolidate SqlCodeElementBuilder with improved parsing logic - Align naming conventions across SQL statement/node hierarchy Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
fm-117
requested changes
Mar 19, 2026
Contributor
There was a problem hiding this comment.
Some general remarks:
- granularity of the PR makes it hard to review as you add 7 new statements in one go. We usually work on one statement at a time as this help to focus on a single syntax diagram. See for example #2284.
- the grammar definitions are incomplete, some optional clauses are not defined here. This is fine but adding a TODO in CobolCodeElements.g4 could help identify the missing parts for each statement
TODO (but you already identified some of these tasks)
- Create at least one unit test for each statement using the
rdzSQLformat- You'll need to update the Comparator for that purpose to account for new statements
- Update existing unit tests affected by the change
| @@ -678,14 +685,14 @@ sourceComputerParagraph: | |||
| // The PROGRAM COLLATING SEQUENCE clause does not apply to DBCS | |||
| // data items or data items of usage NATIONAL. | |||
| // If the PROGRAM COLLATING SEQUENCE clause is omitted, the EBCDIC | |||
| // collating sequence is used. (See Appendix C, �EBCDIC and ASCII collating | |||
| // sequences,� on page 569.) | |||
| // collating sequence is used. (See Appendix C, �EBCDIC and ASCII collating | |||
Contributor
There was a problem hiding this comment.
Unwanted file encoding change ?
| // --- INSERT --- | ||
| insertStatement: SQL_INSERT SQL_INTO tableOrViewOrCorrelationName insertColumnList? (SQL_VALUES LeftParenthesisSeparator insertValueList RightParenthesisSeparator | fullselect); | ||
| insertColumnList: LeftParenthesisSeparator column_name (SQL_CommaSeparator column_name)* RightParenthesisSeparator; | ||
| insertValueList: sqlExpression (SQL_CommaSeparator sqlExpression)*; |
Contributor
There was a problem hiding this comment.
Can be deleted, use repeatedSourceValue instead
|
|
||
| // --- UPDATE --- | ||
| updateStatement: SQL_UPDATE tableOrViewOrCorrelationName SQL_SET updateAssignmentClause (SQL_CommaSeparator updateAssignmentClause)* updateWhereClause?; | ||
| updateAssignmentClause: column_name EqualOperator sqlExpression; |
Contributor
There was a problem hiding this comment.
This is incomplete but ok for simple assignment clauses
allieseb
added a commit
to allieseb/TypeCobol
that referenced
this pull request
Mar 22, 2026
- Fix file encoding: preserve original Windows-1252 bytes in grammar comments (no more UTF-8 replacement characters in diff) - Remove redundant insertValueList rule, reuse repeatedSourceValue as suggested by reviewer - Add TODO comments in CobolCodeElements.g4 for all incomplete optional clauses (INSERT, UPDATE, DELETE, DECLARE CURSOR) - Update SqlCodeElementBuilder to navigate sourceValue tree for host variable extraction (FindHostVariable helper) - Add Comparator Visit methods for all new SQL statement types (InsertStatement, UpdateStatement, SqlDeleteStatement, DeclareCursorStatement, UnsupportedSqlStatement) - Create dedicated rdzSQL unit tests (one per statement type): ExecSqlWithInsertStatement, ExecSqlWithUpdateStatement, ExecSqlWithDeleteStatement, ExecSqlWithDeclareCursorStatement - Update ExecSqlWithUnsupportedStatement test: remove now-supported statements, keep only OPEN/FETCH/CLOSE - Build verified: 0 errors (885 pre-existing warnings) Addresses review from fm-117 on PR TypeCobolTeam#2838. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Will be recreated separately. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
INSERT,UPDATE,DELETE,DECLARE CURSOR,OPEN CURSOR,CLOSE CURSOR,FETCHSqlCloseStatement→CloseCursorStatement,SqlOpenStatement→OpenCursorStatement,SqlDeleteStatement→DeleteSqlStatementSqlCodeElementBuilderwith improved parsing logicChanges
CloseCursorStatement,OpenCursorStatement,DeleteSqlStatement; updateDeclareCursorStatement,FetchStatement,InsertStatement,UpdateStatementDeleteSqlnode; updateCloseCursor,OpenCursor,DeclareCursor,Fetch,Insert,UpdateProgramClassBuilder, dispatcher, and listenerTest plan