Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-668

Prepared Statement parser incorrectly handles consecutive ESCAPE

    XMLWordPrintable

Details

    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.

      Attachments

        Issue Links

          Activity

            People

              diego dupin Diego Dupin
              amukha Alex Mukha
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.