[CONJ-668] Prepared Statement parser incorrectly handles consecutive ESCAPE Created: 2018-12-21  Updated: 2019-03-13  Resolved: 2019-03-13

Status: Closed
Project: MariaDB Connector/J
Component/s: JDBC 4.2 compatibility
Affects Version/s: 2.3.0
Fix Version/s: 2.4.0

Type: Bug Priority: Blocker
Reporter: Alex Mukha Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to CONJ-664 SQLException when backslash (\), whic... Closed

 Description   

If the prepared statement has two or more consecutive clauses with ESCAPE, the parsed statement will be only split into two parts instead of three in ClientPrepareResult#parameterParts.
An example Java code to reproduce the issue:

        
try (PreparedStatement preparedStatement = connection.prepareStatement("select * from my_db.my_table where my_db.my_table.id = ? and (my_db.my_table.username like lower(?) escape '\\\\' or my_db.my_table.firstname like lower(?) escape '\\\\');"))
        {
            preparedStatement.setString(1, "1");
            preparedStatement.setString(2, "user%");
            preparedStatement.setString(3, "user%");
            ResultSet rs = preparedStatement.executeQuery();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }

Results with an exception:

java.sql.SQLException: Could not set parameter at position 3 (values was 'user%')
Query - conn:125(M)  - "select * from my_db.my_table where my_db.my_table.id = ? and (my_db.my_table.username like lower(?) escape '\\' or my_db.my_table.firstname like lower(?) escape '\\');"
	at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getSqlException(ExceptionMapper.java:271)
	at org.mariadb.jdbc.MariaDbPreparedStatementClient.setParameter(MariaDbPreparedStatementClient.java:480)
	at org.mariadb.jdbc.BasePrepareStatement.setString(BasePrepareStatement.java:1533)

This is not reproduced on 2.0.1 version of the driver.


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