Skip to content

Commit 69a76b0

Browse files
committed
fix: handle transaction sql with comments at the beginning
1 parent 774e9e5 commit 69a76b0

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

wrapper/src/main/java/software/amazon/jdbc/plugin/DefaultConnectionPlugin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void notifyNodeListChanged(Map<String, EnumSet<NodeChangeOptions>> change
158158

159159
public boolean doesOpenTransaction(String statement) {
160160
statement = statement.toUpperCase();
161-
statement = statement.replaceAll("START(?:\\s*/\\*(.*?)\\*/\\s*)TRANSACTION", "START TRANSACTION");
161+
statement = statement.replaceAll("\\s*/\\*(.*?)\\*/\\s*", " ").trim();
162162
return statement.startsWith("BEGIN") || statement.startsWith("START TRANSACTION");
163163
}
164164

wrapper/src/test/java/software/amazon/jdbc/plugin/DefaultConnectionPluginTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ private static Stream<Arguments> openTransactionQueries() {
8484
Arguments.of("START/* COMMENT */TRANSACTION;", true),
8585
Arguments.of("START /* COMMENT */ TRANSACTION;", true),
8686
Arguments.of("START /*COMMENT*/TRANSACTION;", true),
87+
Arguments.of("/*COMMENT*/START /*COMMENT*/TRANSACTION;", true),
88+
Arguments.of(" /*COMMENT*/ START /*COMMENT*/TRANSACTION;", true),
89+
Arguments.of(" /*COMMENT*/ begin", true),
8790
Arguments.of("commit", false)
8891
);
8992
}

0 commit comments

Comments
 (0)