Skip to content

Commit

Permalink
Fixes issue krummas#45
Browse files Browse the repository at this point in the history
Now handling backquotes the same way single and double quotes are handled
  • Loading branch information
Stephane GIRON authored and Stephane GIRON committed Apr 13, 2018
1 parent b2ca26e commit 9ec434f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<artifactId>drizzle-jdbc</artifactId>
<packaging>jar</packaging>
<name>Drizzle-JDBC</name>
<version>1.5-SNAPSHOT</version>
<version>1.5.1-SNAPSHOT</version>
<description>BSD Licensed JDBC driver for Drizzle and MySQL</description>
<url>https://github.com/krummas/DrizzleJDBC</url>
<properties>
Expand Down
21 changes: 15 additions & 6 deletions src/main/java/org/drizzle/jdbc/internal/common/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,35 @@ public static int countChars(final String str, final char chr) {
public static List<String> createQueryParts(String query) {
boolean isWithinDoubleQuotes = false;
boolean isWithinQuotes = false;
boolean isWithinBackquotes = false;

int queryPos = 0;
int lastQueryPos = 0;
List<String> queryParts = new LinkedList<String>();

for (int i = 0; i < query.length(); i++) {
final char c = query.charAt(i);

if (c == '"' && !isWithinQuotes && !isWithinDoubleQuotes) {
if (c == '"' && !isWithinQuotes && !isWithinDoubleQuotes && !isWithinBackquotes) {
isWithinDoubleQuotes = true;
} else if (c == '"' && !isWithinQuotes) {
} else if (c == '"' && !isWithinQuotes && !isWithinBackquotes) {
isWithinDoubleQuotes = false;
}

if (c == '\'' && !isWithinQuotes && !isWithinDoubleQuotes) {
if (c == '\'' && !isWithinQuotes && !isWithinDoubleQuotes && !isWithinBackquotes) {
isWithinQuotes = true;
} else if (c == '\'' && !isWithinDoubleQuotes) {
} else if (c == '\'' && !isWithinDoubleQuotes && !isWithinBackquotes) {
isWithinQuotes = false;
}

if (!isWithinDoubleQuotes && !isWithinQuotes) {
if (c == '`' && !isWithinQuotes && !isWithinDoubleQuotes && !isWithinBackquotes) {
isWithinBackquotes = true;
} else if (c == '`' && !isWithinDoubleQuotes && !isWithinQuotes) {
isWithinBackquotes = false;
}


if (!isWithinDoubleQuotes && !isWithinQuotes && !isWithinBackquotes) {
if (c == '?') {
queryParts.add(query.substring(lastQueryPos, queryPos));
lastQueryPos = queryPos + 1;
Expand Down Expand Up @@ -498,4 +507,4 @@ public static long byteArrayToLong(byte [] b) {
return isPositive?-sum:sum;
//return Integer.MAX_VALUE;
}
}
}

0 comments on commit 9ec434f

Please sign in to comment.