[CONJ-82] data type LONGVARCHAR not supported in setObject() Created: 2014-02-11  Updated: 2014-12-09  Resolved: 2014-12-09

Status: Closed
Project: MariaDB Connector/J
Component/s: None
Affects Version/s: 1.1.5
Fix Version/s: 1.1.8

Type: Bug Priority: Major
Reporter: Daniel Kessel Assignee: Massimo Siani (Inactive)
Resolution: Fixed Votes: 2
Labels: None

Attachments: File CONJ82.patch    

 Description   

The MariaDB Connector fails to handle Strings correctly when the datatype LONGVARCHAR is used. The MySQL connector handles CHAR, VARCHAR and LONGVARCHAR identically. The MariaDB connector should do the same.
This harms portability of MySQL Connector based projects.

To reproduce:

public class Test {
    public static void main(String[] args) throws Exception {
        final Connection jdbcConnection = DriverManager.getConnection("jdbc:mariadb://localhost:3306/testdb", "root", null);
        final Statement stmt = jdbcConnection.createStatement();
 
        stmt.execute("CREATE TABLE exception (column1 TEXT NULL)");
        stmt.close();
 
        final PreparedStatement preparedStmt = jdbcConnection.prepareStatement("INSERT INTO `exception` (`column1`) VALUES ( ? )");
        
        preparedStmt.setObject(1, "This is a test!" , Types.LONGVARCHAR);
        preparedStmt.executeUpdate();
    }
}

Expected: Statement gets executed without errors
But got: Exception below

Exception in thread "main" java.sql.SQLException: Could not convert [This is a test!] to -1
at org.mariadb.jdbc.internal.SQLExceptionMapper.getSQLException(SQLExceptionMapper.java:161)
at org.mariadb.jdbc.MySQLPreparedStatement.setObject(MySQLPreparedStatement.java:1320)
at aaa.Test.main(Test.java:45)

Proposed patch:
Change MySQLPreparedStatement#setObject(int, Object, int) to handle the character based SQL types identically:

                case Types.CHAR:
                case Types.VARCHAR:
+               case Types.LONGVARCHAR: 
                case Types.TIMESTAMP: 
                case Types.TIME:
                    setString(parameterIndex, s);



 Comments   
Comment by Patrice Scheidt [ 2014-02-11 ]

Ok, shouldn't the statement be "INSERT INTO `exception` (`column1`) VALUES ( ? )"
Besides that, the setObject() doesn't work anyway.

Comment by Jochen Wiedmann [ 2014-02-20 ]

Confirming the issue, and the solution. Attaching a proposed patch, which includes a test case.

Comment by Jochen Wiedmann [ 2014-02-20 ]

Attaching proposed patch, including a test case.

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