Skip to content

Commit

Permalink
fix: handle transaction sql with comments at the beginning and set tr…
Browse files Browse the repository at this point in the history
…ansaction status in setAutoCommit
  • Loading branch information
karenc-bq committed Sep 26, 2022
1 parent 861e93c commit a50fdc4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void notifyNodeListChanged(Map<String, EnumSet<NodeChangeOptions>> change

public boolean doesOpenTransaction(String statement) {
statement = statement.toUpperCase();
statement = statement.replaceAll("START(?:\\s*/\\*(.*?)\\*/\\s*)TRANSACTION", "START TRANSACTION");
statement = statement.replaceAll("\\s*/\\*(.*?)\\*/\\s*", " ").trim();
return statement.startsWith("BEGIN") || statement.startsWith("START TRANSACTION");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,10 @@ public void setAutoCommit(boolean autoCommit) throws SQLException {
this.pluginManager,
this.pluginService.getCurrentConnection(),
"Connection.setAutoCommit",
() -> this.pluginService.getCurrentConnection().setAutoCommit(autoCommit),
() -> {
this.pluginService.getCurrentConnection().setAutoCommit(autoCommit);
this.pluginManagerService.setInTransaction(true);
},
autoCommit);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ private static Stream<Arguments> openTransactionQueries() {
Arguments.of("START/* COMMENT */TRANSACTION;", true),
Arguments.of("START /* COMMENT */ TRANSACTION;", true),
Arguments.of("START /*COMMENT*/TRANSACTION;", true),
Arguments.of("/*COMMENT*/START /*COMMENT*/TRANSACTION;", true),
Arguments.of(" /*COMMENT*/ START /*COMMENT*/TRANSACTION;", true),
Arguments.of(" /*COMMENT*/ begin", true),
Arguments.of("commit", false)
);
}
Expand Down

0 comments on commit a50fdc4

Please sign in to comment.