Skip to content

Commit

Permalink
fix: Fix support for EXEC SQL node for CCF
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurkambay committed Jul 8, 2024
1 parent 832dd5e commit 044586d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,25 @@ public Range constructRange(ParserRuleContext ctx) {
public List<Node> visitSqlCode(Db2SqlParser.SqlCodeContext ctx) {
// String intervalText = VisitorHelper.getIntervalText(ctx);
String sqlCode = preProcessSqlComment(ctx);

List<Node> nodes = this.visitStartSqlRule(parseSQL(sqlCode, ctx));
Db2SqlVisitorHelper.adjustNodeLocations(ctx, context, nodes);

Locality locality =
VisitorHelper.buildNameRangeLocality(
ctx.getParent(), VisitorHelper.getName(ctx.getParent()), context.getProgramDocumentUri());
Location location = context.getExtendedDocument().mapLocation(locality.getRange());
locality = Locality.builder().range(location.getRange()).uri(location.getUri()).build();

boolean isWhenever = nodes.stream().anyMatch(n ->
n.getDepthFirstStream().anyMatch(nd -> nd instanceof ExecSqlWheneverNode));

if (!isWhenever) {
Node sqlNode = new ExecSqlNode(locality);
nodes = new LinkedList<>(nodes);
nodes.add(0, sqlNode);
}

return nodes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@
EXEC SQL WHENEVER SQLERROR GO TO HANDLER END-EXEC.
EXEC SQL WHENEVER SQLERROR CONTINUE END-EXEC.

EXEC SQL
SELECT ABC FROM XYZ;
END-EXEC.

HANDLER.
DISPLAY "HANDLER".
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"character": 9
},
"end": {
"line": 21,
"line": 25,
"character": 31
}
},
Expand Down Expand Up @@ -106,18 +106,46 @@
}
}
},
{
"type": "execsql",
"location": {
"uri": "fake/path",
"start": {
"line": 20,
"character": 12
},
"end": {
"line": 22,
"character": 45
}
}
},
{
"type": "endexec",
"location": {
"uri": "fake/path",
"start": {
"line": 20,
"character": 12
},
"end": {
"line": 22,
"character": 45
}
}
},
{
"snippet": "HANDLER.\r\n DISPLAY \"HANDLER\".",
"name": "HANDLER",
"type": "paragraph",
"location": {
"uri": "fake/path",
"start": {
"line": 20,
"line": 24,
"character": 9
},
"end": {
"line": 21,
"line": 25,
"character": 31
}
}
Expand Down

0 comments on commit 044586d

Please sign in to comment.