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

Prepare Statement doesn't remove { } characters

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • 1.5.0-RC
    • Other
    • None
    • Linux

    Description

      This is issue shows up when MariaDB connector is used with EclipseLink.
      EclipseLink is a JPA 2.0 implementation and allows calling a stored procedure. It works fine with MySQL connector, where it creates correctly sp call based on provided class. However, when MariaDB connector is used all calls to SP fails, this happens due to the fact that EclipseLink (platform->MySQLPlatform) sends a prepare request with a text like

      { CALL sp() }. prepareCall method correctly removes {} brackets from a provided text and produces a correct query, however, and prepareStatement method doesn't call escape on a text provided and as the result call DB with a text { CALL sp() }

      .
      The request fails with an error:
      Internal Exception: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '

      { CALL sp_list() }' at line 1
      Query is : { CALL sp_list() }

      Error Code: 1064
      Call:

      { CALL sp_list() }

      Attachments

        Activity

          leonidkogan Leonid Kogan created issue -
          leonidkogan Leonid Kogan made changes -
          Field Original Value New Value
          Summary Prepare Statement doesn't escape { } characters Prepare Statement doesn't remove { } characters
          wlad Vladislav Vaintroub added a comment - - edited

          https://docs.oracle.com/javase/7/docs/api/java/sql/CallableStatement.html does not have spaces after the curly bracket before CALL. I have not seen any mentioning of spaces in escape sequences (moreover, standard uses lowercase everywhere).

          https://docs.oracle.com/cd/E13157_01/wlevs/docs30/jdbc_drivers/sqlescape.html

          wlad Vladislav Vaintroub added a comment - - edited https://docs.oracle.com/javase/7/docs/api/java/sql/CallableStatement.html does not have spaces after the curly bracket before CALL. I have not seen any mentioning of spaces in escape sequences (moreover, standard uses lowercase everywhere). https://docs.oracle.com/cd/E13157_01/wlevs/docs30/jdbc_drivers/sqlescape.html
          diego dupin Diego Dupin made changes -
          diego dupin Diego Dupin made changes -
          Comment [ Hi, this correspond to jira issue CONJ-298.
          problem is when stored procedure hasn't any parameter, if there isn't a space before parenthesis, query parsing doesn't work.

          {CALL sp_list () } will work.

          This will be corrected in the 1.5.0 version (release in 15 days). ]
          diego dupin Diego Dupin made changes -
          diego dupin Diego Dupin added a comment -

          i don't understand this escaping problem :

          some existing tests :

              @Test
              public void testCallExecuteErrorBatch() throws SQLException {
                  createProcedure("TEST_SP1", "() BEGIN\n"
                          + "SELECT 1;\n"
                          + "END");
                  CallableStatement callableStatement = sharedConnection.prepareCall("{call TEST_SP1()}");
                  callableStatement.execute();
                  ResultSet rs = callableStatement.getResultSet();
                  assertTrue(rs.next());
                  assertEquals(1, rs.getInt(1));
                  assertFalse(rs.next());
              }
          

          server will have the query "call TEST_SP1()".

          Can you provide a small snippet of code so i can understand to problem, and indicate the driver version you're using ?

          diego dupin Diego Dupin added a comment - i don't understand this escaping problem : some existing tests : @Test public void testCallExecuteErrorBatch() throws SQLException { createProcedure( "TEST_SP1" , "() BEGIN\n" + "SELECT 1;\n" + "END" ); CallableStatement callableStatement = sharedConnection.prepareCall( "{call TEST_SP1()}" ); callableStatement.execute(); ResultSet rs = callableStatement.getResultSet(); assertTrue(rs.next()); assertEquals( 1 , rs.getInt( 1 )); assertFalse(rs.next()); } server will have the query "call TEST_SP1()". Can you provide a small snippet of code so i can understand to problem, and indicate the driver version you're using ?
          diego dupin Diego Dupin made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          diego dupin Diego Dupin made changes -
          Fix Version/s 1.5.0 [ 19607 ]
          diego dupin Diego Dupin added a comment -

          Hi leonid.

          As you have say in another email problem is on statement and PrepareStatement, not callableStatement.

          Correction done and available by snapshot :

          <repositories>
              <repository>
                  <id>sonatype-nexus-snapshots</id>
                  <name>Sonatype Nexus Snapshots</name>
                  <url>https://oss.sonatype.org/content/repositories/snapshots</url>
              </repository>
          </repositories>
           
          <dependencies>
              <dependency>
                  <groupId>org.mariadb.jdbc</groupId>
                  <artifactId>mariadb-java-client</artifactId>
                  <version>1.5.0-SNAPSHOT</version>
              </dependency>
          </dependencies>
          

          Can you confirm that solves your problem ?

          diego dupin Diego Dupin added a comment - Hi leonid. As you have say in another email problem is on statement and PrepareStatement, not callableStatement. Correction done and available by snapshot : <repositories> <repository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https: //oss.sonatype.org/content/repositories/snapshots</url> </repository> </repositories>   <dependencies> <dependency> <groupId>org.mariadb.jdbc</groupId> <artifactId>mariadb-java-client</artifactId> <version> 1.5 . 0 -SNAPSHOT</version> </dependency> </dependencies> Can you confirm that solves your problem ?
          diego dupin Diego Dupin made changes -
          Component/s Other [ 12201 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 76014 ] MariaDB v4 [ 134883 ]

          People

            diego dupin Diego Dupin
            leonidkogan Leonid Kogan
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.