[CONJ-618] Client preparestatement parsing error on escaped ' / " in query Created: 2018-06-14  Updated: 2019-02-08  Resolved: 2018-06-14

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: None
Fix Version/s: 2.2.6, 1.8.0

Type: Task Priority: Major
Reporter: Diego Dupin Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
is blocked by CONJ-664 SQLException when backslash (\), whic... Closed

 Description   

Client prepared statement has a parsing error on escaped ' / " in string.

example to reproduce :

            try (PreparedStatement preparedStatement = connection.prepareStatement("select '\\'' as a, ? as b, \"\\\"\" as c, ? as d")) {
                preparedStatement.setString(1, "val");
                preparedStatement.setString(2, "val2");
                ResultSet rs = preparedStatement.executeQuery();
            }



 Comments   
Comment by Leonid M. [ 2018-11-30 ]

In the following comment it is not possible to write two backslashes after each other. That's why I wrote '\ \' with space between in meaning two following backslashes without space.

Commit https://github.com/MariaDB/mariadb-connector-j/commit/e9e8acc400d5935082b9d4d5255d5e735eae7a8f
causes problems if SELECT or WHERE contains backspace(s) without following ' or "
Simple Select doesn't work any more without ...?sessionVariables=sql_mode=NO_BACKSLASH_ESCAPES
getSession().createSQLQuery("SELECT CONCAT('\\\\', '') FROM (SELECT '') AS a WHERE :q = 1").setParameter("q", 1).list();

Caused by: java.sql.SQLException: Could not set parameter at position 1 (values was 1)
Query - conn:1180011(M) - "SELECT CONCAT('\ \', '') FROM (SELECT '') AS a WHERE ? = 1"
at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getSqlException(ExceptionMapper.java:211)
at org.mariadb.jdbc.MariaDbPreparedStatementClient.setParameter(MariaDbPreparedStatementClient.java:438)
at org.mariadb.jdbc.BasePrepareStatement.setInt(BasePrepareStatement.java:1436)
...

Generated at Thu Feb 08 03:17:04 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.