Skip to content
Open
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
12 changes: 2 additions & 10 deletions src/main/java/org/mariadb/jdbc/util/ClientParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public static ClientParser rewritableParts(String queryString, boolean noBacksla
boolean isInsertDuplicate = false;
boolean afterValues = false;
int isInParenthesis = 0;
int lastParenthesisPosition = 0;
int multiQueryIdx = -1;
byte[] query = queryString.getBytes(StandardCharsets.UTF_8);
int queryLength = query.length;
Expand Down Expand Up @@ -430,7 +429,6 @@ public static ClientParser rewritableParts(String queryString, boolean noBacksla
if (state == LexState.Normal) {
isInParenthesis++;
if (afterValues == true && valuesBracketPositions.isEmpty()) {
;
valuesBracketPositions.add(i);
}
}
Expand All @@ -444,17 +442,15 @@ public static ClientParser rewritableParts(String queryString, boolean noBacksla
if (state == LexState.Normal) {
isInParenthesis--;
if (isInParenthesis == 0 && valuesBracketPositions.size() == 1) {
lastParenthesisPosition = i;
valuesBracketPositions.add(i);
}
}
break;
case (byte) '?':
if (state == LexState.Normal) {
paramPositions.add(i);
// have parameter outside values parenthesis
if (valuesBracketPositions.size() == 1
&& lastParenthesisPosition > 0
&& isInParenthesis == 0) {
if (valuesBracketPositions.size() == 2) {
reWritablePrepare = false;
}
}
Expand Down Expand Up @@ -485,10 +481,6 @@ public static ClientParser rewritableParts(String queryString, boolean noBacksla
isMulti = hasAdditionalPart;
}

if (valuesBracketPositions.size() == 1 && lastParenthesisPosition > 0) {
valuesBracketPositions.add(lastParenthesisPosition);
}

if (isMulti || !isInsert || !reWritablePrepare || valuesBracketPositions.size() != 2) {
valuesBracketPositions = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public void rewritableThatContainSelectQuery() {
assertTrue(checkRewritable("INSERT INTO TABLE VALUES ('\\\\test', ?) /*test* #/ ;`*/", 25, 37));
assertTrue(checkRewritable("INSERT INTO TABLE VALUES ('\\\\test', ?) # EOL ", 25, 37));
assertTrue(checkRewritable("INSERT INTO TABLE VALUES ('\\\\test', ?) -- EOL ", 25, 37));
assertTrue(checkRewritable("INSERT INTO TABLE VALUES ('\\\\test', ?) -- EOL ()", 25, 37));
}

private boolean checkRewritable(String query, int pos1, int pos2) {
Expand Down Expand Up @@ -94,7 +95,17 @@ static Stream<Arguments> rewriteTestData() {
"INSERT INTO b VALUES (?,?), (?,?)",
4,
new int[] {22, 24, 29, 31},
new int[] {21, 32}));
null),
Arguments.of(
"INSERT INTO b VALUES (?,?) AS v ON DUPLICATE KEY UPDATE b.a=v.a",
2,
new int[] {22, 24},
new int[] {21, 25}),
Arguments.of(
"INSERT INTO b VALUES (?,?) AS v ON DUPLICATE KEY UPDATE b.a=(v.a)",
2,
new int[] {22, 24},
new int[] {21, 25}));
}

@ParameterizedTest()
Expand Down
Loading