[CONJ-314] Prepare Statement doesn't remove { } characters Created: 2016-06-14  Updated: 2016-06-22  Resolved: 2016-06-22

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: None
Fix Version/s: 1.5.0-RC

Type: Bug Priority: Major
Reporter: Leonid Kogan Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

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() }

 Comments   
Comment by Vladislav Vaintroub [ 2016-06-14 ]

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

Comment by Diego Dupin [ 2016-06-15 ]

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 ?

Comment by Diego Dupin [ 2016-06-16 ]

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 ?

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