-
Notifications
You must be signed in to change notification settings - Fork 62
feat: Db2 binary host variable support #2337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Db2 binary host variable support #2337
Conversation
Adds support for binary host variable declarations for DB2 within COBOL conforming to the IBM standard for their preprocessor.
Added bounds check per IBM's documentation for BINARY and VARBINARY types for their DB2 preprocessor.
Simplified the errors given to the end user. No need to tell them twice that negatives are not allowed.
…ost-Variable-Support
Add unit tests and changed the range check to an easier to read and understand function.
Remove unused message that was previously added as a commit to this PR.
Added a check for the offending token such that it properly denotes where the issue is rather than the one after it. Updated unit tests to reflect these changes.
After your comment on #2338 I came to check your implementation and it looks like in your case it cannot be 01 for level. |
@@ -1783,6 +1794,8 @@ dbs_sql_identifier: NONNUMERICLITERAL | IDENTIFIER | FILENAME | FILENAME (DOT_FS | |||
dbs_comma_separator: (COMMASEPARATORDB2 | COMMACHAR); | |||
dbs_semicolon_end: SEMICOLON_FS | SEMICOLONSEPARATORSQL; | |||
|
|||
dbs_integerliteral_expanded: MINUSCHAR? (INTEGERLITERAL|SINGLEDIGITLITERAL|SINGLEDIGIT_1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if -ve length should be allowed at grammar level. This would always be +ve integer as per doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct, but if the user types a minus sign by accident we can now catch that. See the screenshot at the bottom of the initial comment/post in the PR as an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense 👍
@@ -112,6 +112,33 @@ public List<Node> visitResult_set_locator_host_variable( | |||
return ImmutableList.of(variableDefinitionNode); | |||
} | |||
|
|||
@Override | |||
public List<Node> visitBinary_host_variable(Db2SqlParser.Binary_host_variableContext ctx) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we would need to add test, for usage of generated variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IBM DB2 preprocessor converts the DB2 variable types to those supported by COBOL. These generated variables should already be taken care of.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is that below program with db2 pre/co-processor would compile fine. But cobol-ls would start to throw error variable not defined.
Identification Division.
Program-Id. 'TEST1'.
Data Division.
Working-Storage Section.
LINKAGE SECTION.
01 VBIN-VAR USAGE IS SQL TYPE IS BINARY VARYING(10).
PROCEDURE division.
display VBIN-VAR-LEN.
display VBIN-VAR-TEXT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll take it from here. Let's merge this PR if everything else is fine.
|
||
result_set_locator_host_variable: dbs_level_01 entry_name (USAGE IS?)? SQL TYPE IS RESULT_SET_LOCATOR VARYING; | ||
|
||
binary_host_variable: dbs_level_01 entry_name host_variable_usage binary_host_variable_type; | ||
binary_host_variable_type: BINARY LPARENCHAR binary_host_variable_binary_size RPARENCHAR | VARBINARY LPARENCHAR binary_host_variable_varbinary_size RPARENCHAR | BINARY VARYING; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
( BINARY | VARBINARY | BINARY VARYING) LPARENCHAR binary_host_variable_varbinary_size RPARENCHAR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like 01 VBIN-VAR USAGE IS SQL TYPE IS BINARY VARYING(10).
is a valid syntax
Also, this introduces
7 1 VBIN-VAR. . . . . . . . . . . . . . . . . . . BLL=00001 000000000 DS 0CL12 Group
0 2 VBIN-VAR-LEN. . . . . . . . . . . . . . . . BLL=00001 000000000 DS 2C Binary
0 2 VBIN-VAR-TEXT . . . . . . . . . . . . . . . BLL=00001 000000002 DS 10C Display
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we know the max length when using BINARY VARYING? I've kept the sizes separate in order to allow for bounds/range checking as BINARY and VARBINARY have different max sizes. (255 and 32704 respectively)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well theoretically, these are semantics check and not a syntax issue. But I don't mind it either ways. As a general rule I like to consolidate sub rules to avoid look ahead burden. This is explained at improving-the-performance-of-an-antlr-parse ( check section - Consolidating sub rules)
Since this is a small rule, it doesn't matter a lot here.
For the semantics check, we can always do these in Visitor as the binary_host_variable parser rule context would have all the appropriate value within it.
...er/engine/src/main/java/org/eclipse/lsp/cobol/implicitDialects/sql/MessageServiceParser.java
Outdated
Show resolved
Hide resolved
…ects/sql/MessageServiceParser.java Co-authored-by: Aman Prashant <[email protected]>
That is for the arrays, not this PR which is for the non-array variable(s). Here is IBM's documentation on this one: https://www.ibm.com/docs/en/db2-for-zos/13?topic=cobol-host-variables-in#db2z_hostvariablecobol__title__16 |
Add size requirement for BINARY VARYING.
How Has This Been Tested?
VS Code Extension
Tested the new grammar locally and using the following small COBOL program with valid/invalid/negative values:
Was given the intended results matching what is in IBM's documentation:

Unit Tests
Wrote four new unit tests checking the bounds of the size for both BINARY and VARBINARY types.
Checklist: