Skip to content

Commit

Permalink
rowid host variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ilidio-lopes committed Jul 24, 2024
1 parent e8331a7 commit 13c05ce
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ binary_host_variable_varbinary_size: T=dbs_integerliteral_expanded {validateInte
host_variable_usage: (USAGE IS?)? SQL TYPE IS;

sql_host_variables: result_set_locator_variable | lob_host_variables | lob_xml_host_variables
| tableLocators_variable ;
| tableLocators_variable | rowid_host_variables;

result_set_locator_variable: dbs_level_01 entry_name host_variable_usage result_set_locator;

Expand All @@ -47,6 +47,8 @@ lob_xml_host_variables: dbs_host_var_levels entry_name host_variable_usage xml_

lob_host_variables: dbs_integer entry_name host_variable_usage (lobWithSize | lobNoSize);

rowid_host_variables: dbs_host_var_levels entry_name host_variable_usage ROWID;

dbs_host_var_levels: dbs_level_01 | T=dbs_integer {validateIntegerRange($T.text, 2, 48);};

result_set_locator: RESULT_SET_LOCATOR VARYING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public List<Node> visitTableLocators_variable(Db2SqlParser.TableLocators_variabl
return createHostVariableDefinitionNode(ctx, ctx.dbs_host_var_levels(), ctx.entry_name());
}

@Override
public List<Node> visitRowid_host_variables(Db2SqlParser.Rowid_host_variablesContext ctx) {
return createHostVariableDefinitionNode(ctx, ctx.dbs_host_var_levels(), ctx.entry_name());
}
@Override
public List<Node> visitLob_xml_host_variables(Db2SqlParser.Lob_xml_host_variablesContext ctx) {
List<Node> hostVariableDefinitionNode = createHostVariableDefinitionNode(ctx, ctx.dbs_host_var_levels(), ctx.entry_name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ public class TestSqlHostVariable {
+ " 49 {$*VAR|1} USAGE IS SQL TYPE IS XML AS CHARACTER LARGE OBJECT (10).\n"
+ " PROCEDURE DIVISION.\n"
+ " DISPLAY {$var-name1}.";

public static final String ROWID_TEXT1 =
" Identification Division.\n"
+ " Program-Id. 'TEST1'.\n"
+ " Data Division.\n"
+ " Working-Storage Section.\n"
+ " 01 {$*VAR}.\n"
+ " 02 {$*VAR1} USAGE IS SQL TYPE IS ROWID.\n"
+ " PROCEDURE DIVISION.\n";

public static final String ROWID_TEXT2 =
" Identification Division.\n"
+ " Program-Id. 'TEST1'.\n"
+ " Data Division.\n"
+ " Working-Storage Section.\n"
+ " 01 {$*VAR}.\n"
+ " 52 {$*VAR1|1} USAGE IS SQL TYPE IS ROWID.\n"
+ " PROCEDURE DIVISION.\n";

@Test
void testSupportForResultSetLocator() {
UseCaseEngine.runTest(TEXT, ImmutableList.of(), ImmutableMap.of());
Expand Down Expand Up @@ -294,4 +313,22 @@ void testLobXMLVariables_levelError() {
)
));
}

@Test
void testRowidVariables() {
UseCaseEngine.runTest(ROWID_TEXT1, ImmutableList.of(), ImmutableMap.of());
}

@Test
void testRowidVariables_levelError() {
UseCaseEngine.runTest(ROWID_TEXT2, ImmutableList.of(), ImmutableMap.of(
"1",
new Diagnostic(
new Range(),
"Allowed range is 2 to 48",
DiagnosticSeverity.Error,
ErrorSource.PARSING.getText()
)
));
}
}

0 comments on commit 13c05ce

Please sign in to comment.