Skip to content

Commit

Permalink
rowid variable arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
ilidio-lopes committed Jul 24, 2024
1 parent e8331a7 commit 0e1cc73
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ NULTERM : N U L T E R M;
NUMBER : N U M B E R;
NUMERIC : N U M E R I C;
NUMPARTS: N U M P A R T S;
OCCURS : O C C U R S;
OBID: O B I D;
OBJECT : O B J E C T;
OF : O F;
Expand Down Expand Up @@ -727,6 +728,7 @@ TEMPORAL: T E M P O R A L;
TEMPORARY : T E M P O R A R Y;
THEN : T H E N;
TIME : T I M E;
TIMES : T I M E S;
TIMESTAMP : T I M E S T A M P;
TIMEZONE : T I M E Z O N E;
TO : T O;
Expand Down
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_arrays;

result_set_locator_variable: dbs_level_01 entry_name host_variable_usage result_set_locator;

Expand All @@ -47,8 +47,12 @@ 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_arrays: dbs_host_var_levels_arrays entry_name host_variable_usage rowid occurs_clause;

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

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

result_set_locator: RESULT_SET_LOCATOR VARYING;

tableLocators: TABLE LIKE entry_name AS LOCATOR;
Expand All @@ -64,6 +68,10 @@ xml_lobNO_size: BLOB_FILE | CLOB_FILE | DBCLOB_FILE;

xml_as: XML AS;

rowid: ROWID;

occurs_clause: OCCURS T=dbs_integer {validateIntegerRange($T.text, 1, 32767);} TIMES?;

entry_name : (FILLER |dbs_host_names);
sqlCode
: ~END_EXEC*?
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_arrays(Db2SqlParser.Rowid_host_variables_arraysContext ctx) {
return createHostVariableDefinitionNode(ctx, ctx.dbs_host_var_levels_arrays(), 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,36 @@ 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_ARRAYS_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 OCCURS 10 TIMES.\n"
+ " PROCEDURE DIVISION.\n";

public static final String ROWID_ARRAYS_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 OCCURS 10 TIMES.\n"
+ " PROCEDURE DIVISION.\n";

public static final String ROWID_ARRAYS_TEXT3 =
" Identification Division.\n"
+ " Program-Id. 'TEST1'.\n"
+ " Data Division.\n"
+ " Working-Storage Section.\n"
+ " 01 {$*GREET}.\n"
+ " 40 {$*VAR} USAGE IS SQL TYPE IS ROWID OCCURS 100000 {TIMES|1}.\n"
+ " PROCEDURE DIVISION.\n"
+ " DISPLAY {$VAR}.";


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

@Test
void testRowidVariablesArrays() {
UseCaseEngine.runTest(ROWID_ARRAYS_TEXT1, ImmutableList.of(), ImmutableMap.of());
}

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

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

0 comments on commit 0e1cc73

Please sign in to comment.