Skip to content
Permalink
Browse files

[CONJ-621] escaping when having curly bracket in table field name (ba…

…cktick)

(cherry picked from commit 7873643)
  • Loading branch information...
rusher committed Jun 27, 2018
1 parent bedc9a5 commit 1043417b55131a480cb0f471cf4fc19bbb1b88cc
@@ -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) {
@@ -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[]{
@@ -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[]{
@@ -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.
You can’t perform that action at this time.