Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
1.1.5
-
None
-
None
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);
|