Skip to content

Commit

Permalink
Fix for Bug#109807 (Bug#35021014), DatabaseMetaData#getTypeInfo shoul…
Browse files Browse the repository at this point in the history
…d ordered by DATA_TYPE.

Change-Id: I50d4934f4ac37dc9d5cbebc590b90c614f7dfdfb
  • Loading branch information
fjssilva committed Feb 8, 2023
1 parent f0f802b commit ab7b4e9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 8.0.33

- Fix for Bug#109807 (Bug#35021014), DatabaseMetaData#getTypeInfo should ordered by DATA_TYPE.

- Fix for Bug#77368 (Bug#21321849), "LOAD DATA LOCAL INFILE" doesn't work properly with relative paths.

- Fix for Bug#109243 (Bug#34852047), Judge whether the returned result set of the sql statement is incorrect.
Expand Down
88 changes: 56 additions & 32 deletions src/main/user-impl/java/com/mysql/cj/jdbc/DatabaseMetaData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates.
* Copyright (c) 2002, 2023, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -4060,49 +4060,73 @@ public java.sql.ResultSet getTypeInfo() throws SQLException {

ArrayList<Row> tuples = new ArrayList<>();

// Ordered by DATA_TYPE and then by how closely the data type maps to the corresponding JDBC SQL type.
// java.sql.Types.BIT = -7
tuples.add(new ByteArrayRow(getTypeInfo("BIT"), getExceptionInterceptor()));
// java.sql.Types.TINYINT = -6
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT UNSIGNED"), getExceptionInterceptor()));
// java.sql.Types.BIGINT = -5
tuples.add(new ByteArrayRow(getTypeInfo("BIGINT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BIGINT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BINARY"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BIT"), getExceptionInterceptor()));
// java.sql.Types.LONGVARBINARY = -4
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARBINARY"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMBLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONGBLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("BOOL"), getExceptionInterceptor()));
// java.sql.Types.VARBINARY = -3
tuples.add(new ByteArrayRow(getTypeInfo("VARBINARY"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYBLOB"), getExceptionInterceptor()));
// java.sql.Types.BINARY = -2
tuples.add(new ByteArrayRow(getTypeInfo("BINARY"), getExceptionInterceptor()));
// java.sql.Types.LONGVARCHAR = -1
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARCHAR"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMTEXT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONGTEXT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TEXT"), getExceptionInterceptor()));
// java.sql.Types.CHAR = 1
tuples.add(new ByteArrayRow(getTypeInfo("CHAR"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DATE"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DATETIME"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DECIMAL"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE PRECISION"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE PRECISION UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("ENUM"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("FLOAT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("SET"), getExceptionInterceptor()));
// java.sql.Types.DECIMAL = 3
tuples.add(new ByteArrayRow(getTypeInfo("DECIMAL"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("NUMERIC"), getExceptionInterceptor()));
// java.sql.Types.INTEGER = 4
tuples.add(new ByteArrayRow(getTypeInfo("INTEGER"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INTEGER UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARBINARY"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARCHAR"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONGBLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("LONGTEXT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMBLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMINT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INTEGER UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("INT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMINT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMTEXT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("NUMERIC"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("REAL"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("SET"), getExceptionInterceptor()));
// java.sql.Types.SMALLINT = 5
tuples.add(new ByteArrayRow(getTypeInfo("SMALLINT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("SMALLINT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TEXT"), getExceptionInterceptor()));
if (!this.yearIsDateType) {
tuples.add(new ByteArrayRow(getTypeInfo("YEAR"), getExceptionInterceptor()));
}
// java.sql.Types.REAL = 7
tuples.add(new ByteArrayRow(getTypeInfo("FLOAT"), getExceptionInterceptor()));
// java.sql.Types.DOUBLE = 8
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE PRECISION"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("REAL"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE PRECISION UNSIGNED"), getExceptionInterceptor()));
// java.sql.Types.VARCHAR = 12
tuples.add(new ByteArrayRow(getTypeInfo("VARCHAR"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYTEXT"), getExceptionInterceptor()));
// java.sql.Types.BOOLEAN = 16
tuples.add(new ByteArrayRow(getTypeInfo("BOOL"), getExceptionInterceptor()));
// java.sql.Types.DATE = 91
tuples.add(new ByteArrayRow(getTypeInfo("DATE"), getExceptionInterceptor()));
if (this.yearIsDateType) {
tuples.add(new ByteArrayRow(getTypeInfo("YEAR"), getExceptionInterceptor()));
}
// java.sql.Types.TIME = 92
tuples.add(new ByteArrayRow(getTypeInfo("TIME"), getExceptionInterceptor()));
// java.sql.Types.TIMESTAMP = 93
tuples.add(new ByteArrayRow(getTypeInfo("DATETIME"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TIMESTAMP"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYBLOB"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT UNSIGNED"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("TINYTEXT"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("VARBINARY"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("VARCHAR"), getExceptionInterceptor()));
tuples.add(new ByteArrayRow(getTypeInfo("YEAR"), getExceptionInterceptor()));

// TODO add missed types (aliases)

Expand Down
25 changes: 25 additions & 0 deletions src/test/java/testsuite/regression/MetaDataRegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5493,4 +5493,29 @@ public void testBug106758() throws Exception {
}
}
}

/**
* Tests fix for Bug#109807 (Bug#35021014), DatabaseMetaData#getTypeInfo should ordered by DATA_TYPE.
*
* @throws Exception
*/
@Test
void testBug109807() throws Exception {
boolean useIS = false;
boolean yearDT = false;
do {
Properties props = new Properties();
props.setProperty(PropertyKey.useInformationSchema.getKeyName(), Boolean.toString(useIS));
props.setProperty(PropertyKey.yearIsDateType.getKeyName(), Boolean.toString(yearDT));
Connection testConn = getConnectionWithProps(props);
DatabaseMetaData testDbMD = testConn.getMetaData();
this.rs = testDbMD.getTypeInfo();
int prevDataType = Integer.MIN_VALUE;
while (this.rs.next()) {
assertTrue(prevDataType <= this.rs.getInt("DATA_TYPE"), "DatabaseMetaData#getTypeInfo must be ordered ascending by DATA_TYPE");
prevDataType = this.rs.getInt("DATA_TYPE");
}
testConn.close();
} while ((useIS = !useIS) || (yearDT = !yearDT));
}
}

0 comments on commit ab7b4e9

Please sign in to comment.