[CONJ-935] Connection.getMetaData() returns MariaDbClob instead of String Created: 2022-02-24  Updated: 2022-03-03  Resolved: 2022-03-03

Status: Closed
Project: MariaDB Connector/J
Component/s: metadata
Affects Version/s: 3.0.3
Fix Version/s: 3.0.4

Type: Bug Priority: Major
Reporter: Andreas Dangel Assignee: Diego Dupin
Resolution: Fixed Votes: 1
Labels: None

Attachments: Java Source File TestCase.java    

 Description   

There's a difference between 2.7.5 and 3.0.3 / 3.0.4-SNAPSHOT, which leads to the error "ClassCastException: class [B cannot be cast to class java.lang.String" in Liquibase (see https://github.com/liquibase/liquibase/issues/2431).

Connection.getMetaData().getColumns() returned in 2.7.5 a ResultSet, where the column type of "TYPE_NAME" was a java.lang.String. But 3.0.4 returns a org.mariadb.jdbc.MariaDbClob, which is then converted by Liquibase into a byte[] (See https://github.com/liquibase/liquibase/blob/79c0e38fe8987bdc7f4200cc05efa1b7c8276248/liquibase-core/src/main/java/liquibase/util/JdbcUtil.java#L89-L90) because MariaDbClob implements java.sql.Blob.

Is this an error on MariaDB side or is this something, that Liquibase would need to fix?

Please see the attached TestCase.java. If I run it with different version, I'll get the following results:

$ java --class-path=mariadb-java-client-2.7.5.jar TestCase.java 
Metadata: class java.lang.String
VARCHAR col: class java.lang.String
 
$ java --class-path=mariadb-java-client-3.0.3.jar TestCase.java 
Metadata: class org.mariadb.jdbc.MariaDbClob
VARCHAR col: class java.lang.String
 
$ java --class-path=mariadb-java-client-3.0.4-SNAPSHOT.jar TestCase.java 
Metadata: class org.mariadb.jdbc.MariaDbClob
VARCHAR col: class java.lang.String 

Real queries seem to behave the correctly and return a String for VARCHAR columns.

This currently prevents Liquibase / Liquibase-Percona from Upgrading to MariaDB Connector 3.x (https://github.com/liquibase/liquibase-percona/pull/180).



 Comments   
Comment by Diego Dupin [ 2022-03-02 ]

javadoc about metadata.getColumn() expect return type :

  • TABLE_CAT String => table catalog (may be null)
  • TABLE_SCHEM String => table schema (may be null)
  • TABLE_NAME String => table name
  • COLUMN_NAME String => column name
  • DATA_TYPE int => SQL type from java.sql.Types
  • TYPE_NAME String => Data source dependent type name, for a UDT the type name is fully qualified

So string type is expected here. This is a bug in driver

Comment by Andreas Dangel [ 2022-03-03 ]

Hi diego dupin,

thanks for working on this! I've run my integration test against the new driver 3.0.4-SNAPSHOT (built locally from branch develop) and there are no problems anymore. So my problem is solved.
There are some failed unit tests now in the driver - they expect Clob where now String is returned. Not sure if the tests are wrong or whether this change would impact other queries as well.

Regards,
Andreas Dangel

Comment by Diego Dupin [ 2022-03-03 ]

this is now corrected (test correction included with an additional task CONJ-937 that have been created after investigation for this task)

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