Skip to content

Commit

Permalink
[CONJ-621] escaping when having curly bracket in table field name (ba…
Browse files Browse the repository at this point in the history
…cktick)

(cherry picked from commit 7873643)
  • Loading branch information
rusher committed Feb 4, 2019
1 parent bedc9a5 commit 1043417
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/org/mariadb/jdbc/internal/util/Utils.java
Expand Up @@ -366,6 +366,7 @@ public static String nativeSql(String sql, boolean noBackslashEscapes) throws SQ
switch (car) {
case '\'':
case '"':
case '`':
if (!inComment) {
if (inQuote) {
if (quoteChar == car) {
Expand Down
14 changes: 13 additions & 1 deletion src/test/java/org/mariadb/jdbc/UtilTest.java
Expand Up @@ -55,12 +55,14 @@
import org.junit.Test;
import org.mariadb.jdbc.internal.util.Utils;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import static org.junit.Assert.assertEquals;


public class UtilTest {
public class UtilTest extends BaseTest {
@Test
public void escape() throws SQLException {
String[] inputs = new String[]{
Expand All @@ -76,6 +78,7 @@ public void escape() throws SQLException {
"{ts '1997-05-24 10:30:29.123'}",
"{ts'1997-05-24 10:30:29.123'}",
"'{string data with { or } will not be altered'",
"`{string data with { or } will not be altered`",
"-- Also note that you can safely include { and } in comments"
};
String[] outputs = new String[]{
Expand All @@ -91,10 +94,19 @@ public void escape() throws SQLException {
"'1997-05-24 10:30:29.123'",
"'1997-05-24 10:30:29.123'",
"'{string data with { or } will not be altered'",
"`{string data with { or } will not be altered`",
"-- Also note that you can safely include { and } in comments"
};
for (int i = 0; i < inputs.length; i++) {
assertEquals(Utils.nativeSql(inputs[i], false), outputs[i]);
}
}

@Test
public void backTickQuote() throws SQLException {
try (Connection conn = setConnection()) {
Statement stmt = conn.createStatement();
stmt.execute("CREATE TEMPORARY TABLE `{tt1}`(`{Document id}` int, tt text)");
}
}
}

0 comments on commit 1043417

Please sign in to comment.