Description:
When JDBC is given a string literal that contains an open brace that follows an escaped backslash and an escaped single quote, the open brace is incorrectly processed as an escape code.
How to repeat:
Here is test code:
package com.cbfiddle.test;
import java.sql.*;
import com.mysql.jdbc.util.BaseBugReport;
public class TestMySQLBug1
extends BaseBugReport
{
public void setUp()
throws SQLException
{
Connection c = getConnection();
Statement stmt = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate("CREATE TABLE TESTBUG (DATA MEDIUMTEXT)");
stmt.executeUpdate("INSERT INTO TESTBUG SET DATA = 'abc'");
}
public void tearDown()
throws SQLException
{
Connection c = getConnection();
Statement stmt = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate("DROP TABLE TESTBUG");
}
public void runTest()
throws SQLException
{
Connection c = getConnection();
Statement stmt = c.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
// stmt.setEscapeProcessing(false); // a workaround
stmt.executeUpdate("UPDATE TESTBUG SET DATA = '\\\\\\' {d}'");
// This should create a string value whose characters are:
// backslash, single-quote, space, open-brace, d, close-brace
// The above statement gets the error: Syntax error for DATE escape sequence '{d}'
ResultSet rs = stmt.executeQuery("SELECT DATA FROM TESTBUG");
while (rs.next()) {
String s = rs.getString(1);
System.err.println("Result: " + s);
}
}
public static void main(String[] args)
throws Exception
{
new TestMySQLBug1().run();
}
}