Skip to content

Commit 3659ab5

Browse files
committed
Fix for Bug#106758 (33973048), DatabaseMetaData.getTypeInfo returns AUTO_INCREMENT = false for all datatypes.
Change-Id: I3fa914c4a092be95758a3fe70dbcfb47fbfc0f86
1 parent 8fe1660 commit 3659ab5

File tree

3 files changed

+94
-32
lines changed

3 files changed

+94
-32
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 8.0.30
55

6+
- Fix for Bug#106758 (33973048), DatabaseMetaData.getTypeInfo returns AUTO_INCREMENT = false for all datatypes.
7+
68
- Fix for Bug#34090350, Update mappings for utf8mb3 and utf8mb4 collations.
79

810
- Fix for Bug#106880 (34022110), Outdated description in connection property 'rewriteBatchedStatements'.

src/main/user-impl/java/com/mysql/cj/jdbc/DatabaseMetaData.java

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,7 +3987,29 @@ private byte[][] getTypeInfo(String mysqlTypeName) throws SQLException {
39873987
rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable).getBytes(); // Searchable
39883988
rowVal[9] = s2b(mt.isAllowed(MysqlType.FIELD_FLAG_UNSIGNED) ? "true" : "false"); // Unsignable
39893989
rowVal[10] = s2b("false"); // Fixed Prec Scale
3990-
rowVal[11] = s2b("false"); // Auto Increment
3990+
switch (mt) {
3991+
case BIGINT:
3992+
case BIGINT_UNSIGNED:
3993+
case BOOLEAN:
3994+
case DOUBLE:
3995+
case DOUBLE_UNSIGNED:
3996+
case FLOAT:
3997+
case FLOAT_UNSIGNED:
3998+
case INT:
3999+
case INT_UNSIGNED:
4000+
case MEDIUMINT:
4001+
case MEDIUMINT_UNSIGNED:
4002+
case SMALLINT:
4003+
case SMALLINT_UNSIGNED:
4004+
case TINYINT:
4005+
case TINYINT_UNSIGNED:
4006+
rowVal[11] = s2b("true"); // Auto Increment
4007+
break;
4008+
default:
4009+
rowVal[11] = s2b("false"); // Auto Increment
4010+
break;
4011+
4012+
}
39914013
rowVal[12] = s2b(mt.getName()); // Locale Type Name
39924014
switch (mt) {
39934015
case DECIMAL: // TODO is it right? DECIMAL isn't a floating-point number...
@@ -4038,50 +4060,49 @@ public java.sql.ResultSet getTypeInfo() throws SQLException {
40384060

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

4041-
/*
4042-
* The following are ordered by java.sql.Types, and then by how closely the MySQL type matches the JDBC Type (per spec)
4043-
*/
4044-
tuples.add(new ByteArrayRow(getTypeInfo("BIT"), getExceptionInterceptor()));
4045-
tuples.add(new ByteArrayRow(getTypeInfo("BOOL"), getExceptionInterceptor()));
4046-
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT"), getExceptionInterceptor()));
4047-
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT UNSIGNED"), getExceptionInterceptor()));
40484063
tuples.add(new ByteArrayRow(getTypeInfo("BIGINT"), getExceptionInterceptor()));
40494064
tuples.add(new ByteArrayRow(getTypeInfo("BIGINT UNSIGNED"), getExceptionInterceptor()));
4050-
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARBINARY"), getExceptionInterceptor()));
4051-
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMBLOB"), getExceptionInterceptor()));
4052-
tuples.add(new ByteArrayRow(getTypeInfo("LONGBLOB"), getExceptionInterceptor()));
4053-
tuples.add(new ByteArrayRow(getTypeInfo("BLOB"), getExceptionInterceptor()));
4054-
tuples.add(new ByteArrayRow(getTypeInfo("VARBINARY"), getExceptionInterceptor()));
4055-
tuples.add(new ByteArrayRow(getTypeInfo("TINYBLOB"), getExceptionInterceptor()));
40564065
tuples.add(new ByteArrayRow(getTypeInfo("BINARY"), getExceptionInterceptor()));
4057-
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARCHAR"), getExceptionInterceptor()));
4058-
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMTEXT"), getExceptionInterceptor()));
4059-
tuples.add(new ByteArrayRow(getTypeInfo("LONGTEXT"), getExceptionInterceptor()));
4060-
tuples.add(new ByteArrayRow(getTypeInfo("TEXT"), getExceptionInterceptor()));
4066+
tuples.add(new ByteArrayRow(getTypeInfo("BIT"), getExceptionInterceptor()));
4067+
tuples.add(new ByteArrayRow(getTypeInfo("BLOB"), getExceptionInterceptor()));
4068+
tuples.add(new ByteArrayRow(getTypeInfo("BOOL"), getExceptionInterceptor()));
40614069
tuples.add(new ByteArrayRow(getTypeInfo("CHAR"), getExceptionInterceptor()));
4062-
tuples.add(new ByteArrayRow(getTypeInfo("ENUM"), getExceptionInterceptor()));
4063-
tuples.add(new ByteArrayRow(getTypeInfo("SET"), getExceptionInterceptor()));
4070+
tuples.add(new ByteArrayRow(getTypeInfo("DATE"), getExceptionInterceptor()));
4071+
tuples.add(new ByteArrayRow(getTypeInfo("DATETIME"), getExceptionInterceptor()));
40644072
tuples.add(new ByteArrayRow(getTypeInfo("DECIMAL"), getExceptionInterceptor()));
4065-
tuples.add(new ByteArrayRow(getTypeInfo("NUMERIC"), getExceptionInterceptor()));
4066-
tuples.add(new ByteArrayRow(getTypeInfo("INTEGER"), getExceptionInterceptor()));
4067-
tuples.add(new ByteArrayRow(getTypeInfo("INTEGER UNSIGNED"), getExceptionInterceptor()));
4073+
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE PRECISION"), getExceptionInterceptor()));
4074+
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE PRECISION UNSIGNED"), getExceptionInterceptor()));
4075+
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE"), getExceptionInterceptor()));
4076+
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE UNSIGNED"), getExceptionInterceptor()));
4077+
tuples.add(new ByteArrayRow(getTypeInfo("ENUM"), getExceptionInterceptor()));
4078+
tuples.add(new ByteArrayRow(getTypeInfo("FLOAT"), getExceptionInterceptor()));
40684079
tuples.add(new ByteArrayRow(getTypeInfo("INT"), getExceptionInterceptor()));
40694080
tuples.add(new ByteArrayRow(getTypeInfo("INT UNSIGNED"), getExceptionInterceptor()));
4081+
tuples.add(new ByteArrayRow(getTypeInfo("INTEGER"), getExceptionInterceptor()));
4082+
tuples.add(new ByteArrayRow(getTypeInfo("INTEGER UNSIGNED"), getExceptionInterceptor()));
4083+
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARBINARY"), getExceptionInterceptor()));
4084+
tuples.add(new ByteArrayRow(getTypeInfo("LONG VARCHAR"), getExceptionInterceptor()));
4085+
tuples.add(new ByteArrayRow(getTypeInfo("LONGBLOB"), getExceptionInterceptor()));
4086+
tuples.add(new ByteArrayRow(getTypeInfo("LONGTEXT"), getExceptionInterceptor()));
4087+
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMBLOB"), getExceptionInterceptor()));
40704088
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMINT"), getExceptionInterceptor()));
40714089
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMINT UNSIGNED"), getExceptionInterceptor()));
4090+
tuples.add(new ByteArrayRow(getTypeInfo("MEDIUMTEXT"), getExceptionInterceptor()));
4091+
tuples.add(new ByteArrayRow(getTypeInfo("NUMERIC"), getExceptionInterceptor()));
4092+
tuples.add(new ByteArrayRow(getTypeInfo("REAL"), getExceptionInterceptor()));
4093+
tuples.add(new ByteArrayRow(getTypeInfo("SET"), getExceptionInterceptor()));
40724094
tuples.add(new ByteArrayRow(getTypeInfo("SMALLINT"), getExceptionInterceptor()));
40734095
tuples.add(new ByteArrayRow(getTypeInfo("SMALLINT UNSIGNED"), getExceptionInterceptor()));
4074-
tuples.add(new ByteArrayRow(getTypeInfo("FLOAT"), getExceptionInterceptor()));
4075-
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE"), getExceptionInterceptor()));
4076-
tuples.add(new ByteArrayRow(getTypeInfo("DOUBLE PRECISION"), getExceptionInterceptor()));
4077-
tuples.add(new ByteArrayRow(getTypeInfo("REAL"), getExceptionInterceptor()));
4078-
tuples.add(new ByteArrayRow(getTypeInfo("VARCHAR"), getExceptionInterceptor()));
4079-
tuples.add(new ByteArrayRow(getTypeInfo("TINYTEXT"), getExceptionInterceptor()));
4080-
tuples.add(new ByteArrayRow(getTypeInfo("DATE"), getExceptionInterceptor()));
4081-
tuples.add(new ByteArrayRow(getTypeInfo("YEAR"), getExceptionInterceptor()));
4096+
tuples.add(new ByteArrayRow(getTypeInfo("TEXT"), getExceptionInterceptor()));
40824097
tuples.add(new ByteArrayRow(getTypeInfo("TIME"), getExceptionInterceptor()));
4083-
tuples.add(new ByteArrayRow(getTypeInfo("DATETIME"), getExceptionInterceptor()));
40844098
tuples.add(new ByteArrayRow(getTypeInfo("TIMESTAMP"), getExceptionInterceptor()));
4099+
tuples.add(new ByteArrayRow(getTypeInfo("TINYBLOB"), getExceptionInterceptor()));
4100+
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT"), getExceptionInterceptor()));
4101+
tuples.add(new ByteArrayRow(getTypeInfo("TINYINT UNSIGNED"), getExceptionInterceptor()));
4102+
tuples.add(new ByteArrayRow(getTypeInfo("TINYTEXT"), getExceptionInterceptor()));
4103+
tuples.add(new ByteArrayRow(getTypeInfo("VARBINARY"), getExceptionInterceptor()));
4104+
tuples.add(new ByteArrayRow(getTypeInfo("VARCHAR"), getExceptionInterceptor()));
4105+
tuples.add(new ByteArrayRow(getTypeInfo("YEAR"), getExceptionInterceptor()));
40854106

40864107
// TODO add missed types (aliases)
40874108

src/test/java/testsuite/regression/MetaDataRegressionTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5465,4 +5465,43 @@ public void testBug82084() throws Exception {
54655465
}
54665466
}
54675467
}
5468+
5469+
/**
5470+
* Tests fix for Bug#106758 (33973048), DatabaseMetaData.getTypeInfo returns AUTO_INCREMENT = false for all datatypes.
5471+
*
5472+
* @throws Exception
5473+
*/
5474+
@Test
5475+
public void testBug106758() throws Exception {
5476+
DatabaseMetaData dbmd = this.conn.getMetaData();
5477+
5478+
this.rs = dbmd.getTypeInfo();
5479+
while (this.rs.next()) {
5480+
StringBuilder sb = new StringBuilder("CREATE TEMPORARY TABLE testBug106758 (col ");
5481+
sb.append(this.rs.getString("TYPE_NAME"));
5482+
if (this.rs.getString("CREATE_PARAMS").startsWith("(M)")) {
5483+
sb.append("(5)");
5484+
} else if (this.rs.getString("CREATE_PARAMS").startsWith("('value")) {
5485+
sb.append(" ('value')");
5486+
}
5487+
sb.append(" AUTO_INCREMENT PRIMARY KEY)"); // Some types don't support primary keys like this, however, the query fails due to AUTO_INCREMENT first.
5488+
5489+
if (this.rs.getBoolean("AUTO_INCREMENT")) {
5490+
try {
5491+
this.stmt.execute(sb.toString());
5492+
} catch (SQLException e) {
5493+
fail("Type " + this.rs.getString("TYPE_NAME") + " does not support AUTO_INCREMENT.");
5494+
} finally {
5495+
this.stmt.execute("DROP TABLE IF EXISTS testBug106758");
5496+
}
5497+
} else {
5498+
assertThrows("Type " + this.rs.getString("TYPE_NAME") + " supports AUTO_INCREMENT.", SQLException.class,
5499+
"Incorrect column specifier for column 'col'", () -> {
5500+
this.stmt.execute(sb.toString());
5501+
this.stmt.execute("DROP TABLE IF EXISTS testBug106758");
5502+
return null;
5503+
});
5504+
}
5505+
}
5506+
}
54685507
}

0 commit comments

Comments
 (0)