Skip to content

fix: Fix support for EXEC SQL node for CCF #2371

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

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading