[CONJ-950] Wrong text type names in result set metadata Created: 2022-03-29  Updated: 2022-05-16  Resolved: 2022-05-16

Status: Closed
Project: MariaDB Connector/J
Component/s: metadata
Affects Version/s: None
Fix Version/s: 3.0.5

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

driver 3.0.4



 Description   

How to reproduce:

connection.createStatement().execute("drop table if exists text_types_text");
            connection.createStatement().execute(
                    "create table text_types_text (varchar100           varchar(100),\n" +
                            "  varchar255           varchar(255),\n" +
                            "  text                 text,\n" +
                            "  `tinytext`           tinytext,\n" +
                            "  `mediumtext`         mediumtext,\n" +
                            "  `longtext`           longtext)"
            );
            try (ResultSet resultSet = connection.createStatement().executeQuery("select * from text_types_text")) {
                ResultSetMetaData metaData = resultSet.getMetaData();
                System.out.println("name | type | type name | precision");
                for (int i = 0; i < metaData.getColumnCount(); i++) {
                    String columnName = metaData.getColumnName(i + 1);
                    int columnType = metaData.getColumnType(i + 1);
                    String columnTypeName = metaData.getColumnTypeName(i + 1);
                    int precision = metaData.getPrecision(i + 1);
                    System.out.println(columnName + " | " + columnType + " | " + columnTypeName + " | " + precision);
                }
            }
            connection.createStatement().execute("drop table text_types_text");

Expected:

name       | type | type name  | precision
varchar100 | 12   | VARCHAR    | 100
varchar255 | 12   | VARCHAR    | 255
text       | 12   | TEXT       | 65535
tinytext   | 12   | TINYTEXT   | 255
mediumtext | 12   | MEDIUMTEXT | 16777215
longtext   | 12   | LONGTEXT   | 4294967295

Actual:

name       | type | type name  | precision
varchar100 | 12   | VARCHAR    | 100
varchar255 | 12   | VARCHAR    | 255
text       | 12   | MEDIUMTEXT | 262140
tinytext   | 12   | VARCHAR    | 1020
mediumtext | 12   | LONGTEXT   | 67108860
longtext   | 12   | LONGTEXT   | -1

As you can see type names are pretty random.
And they change from driver version to driver version!
Also precision of all types except VARCHAR is now multiplied by 4 in new version of driver. Why?

I'm a developer from JetBrains, I'm working on MariaDB support in JetBrains IDEs (see https://www.jetbrains.com/datagrip/). This type names issue makes it really complicated for me to support MariaDB properly



 Comments   
Comment by Diego Dupin [ 2022-05-16 ]

Thanks for reporting this metadata difference. This is a regression

  • precision correction :
    • The 4 lmultiplicator, will be corrected, this is a bug intruced by connector rewrite. This will be corrected.
    • another correction is huge/unknown precision will return 0, not -1 as java doc expect.
  • the columnType value for LONGBLOB/LONGTEXT will return correct Type value. (example LONGTEXT data will have Types.LONGVARCHAR, not Types.VARCHAR).

This will make driver 3.0 version behave like previous 2.x driver.

Just a remark . With correction, for your example, this will return a different value compare to your expectation for longtext : "longtext | -1 | LONGTEXT | 0"
(-1 for Types.LONGVARCHAR in place of Types.VARCHAR, and length of 0 (4294967295 > Integer.MAX_INTEGER) javadoc state that "0 is returned for data types where the column size is not applicable."

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