Skip to content

Commit c81032a

Browse files
authored
HCK-14467: Error when applying DDL statements containing comments (#82)
<!--do not remove this marker, its needed to replace info when ticket title is updated --> <!--jira-description-action-hidden-marker-start--> <table> <td> <a href="https://hackolade.atlassian.net/browse/HCK-14467" title="HCK-14467" target="_blank"><img alt="Sub-bug" src="https://hackolade.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10303?size=medium" />HCK-14467</a> [DB2][Apply to instance]: error is thrown on apply ddl with comments </td></table> <br /> <!--jira-description-action-hidden-marker-end--> ## Technical details Added a method to remove multiline `/**/ `and inline `--` comments when executing the query. The root cause: Statements with comments only were being executed as SQL, which Db2 saw as having no tokens
1 parent 1ee9b26 commit c81032a

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

shared/Db2Client/src/main/java/org/db2/Db2Service.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public JSONArray executeQuery(String query) throws SQLException {
3232
}
3333

3434
public int applyScript(String script) throws SQLException {
35-
String[] statements = splitStatements(script);
35+
String cleanedScript = removeComments(script);
36+
String[] statements = splitStatements(cleanedScript);
3637
int totalUpdateCount = 0;
3738

3839
for (String statement : statements) {
@@ -72,6 +73,10 @@ public int applyScript(String script) throws SQLException {
7273
return totalUpdateCount;
7374
}
7475

76+
private String removeComments(String script) {
77+
return script.replaceAll("(?s)(?m)(?<=\\n)(?:/\\*.*?\\*/|--.*?$)(?=\\n)", "");
78+
}
79+
7580
private String[] splitStatements(String query) {
7681
String[] parts = query.trim().split(";\\s+", -1);
7782
java.util.ArrayList<String> statements = new java.util.ArrayList<>();

shared/addons/Db2Client.jar

107 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)