Modified:
branches/branch_5_0/connector-j/CHANGES
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/DatabaseMetaData.java
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java
branches/branch_5_0/connector-j/src/testsuite/regression/MetaDataRegressionTest.java
Log:
Fixed BUG#27916 - UNSIGNED types not reported via DBMD.getTypeInfo(), and
capitalization of type names is not consistent between DBMD.getColumns(),
RSMD.getColumnTypeName() and DBMD.getTypeInfo().
This fix also ensures that the precision of UNSIGNED MEDIUMINT
and UNSIGNED BIGINT is reported correctly via DBMD.getColumns().
Modified: branches/branch_5_0/connector-j/CHANGES
===================================================================
--- branches/branch_5_0/connector-j/CHANGES 2007-10-02 22:35:59 UTC (rev 6600)
+++ branches/branch_5_0/connector-j/CHANGES 2007-10-03 14:24:12 UTC (rev 6601)
@@ -73,7 +73,14 @@
- Driver will now fall back to sane defaults for max_allowed_packet and
net_buffer_length if the server reports them incorrectly (and will log
this situation at WARN level, since it's actually an error condition).
-
+
+ - Fixed BUG#27916 - UNSIGNED types not reported via DBMD.getTypeInfo(), and
+ capitalization of type names is not consistent between DBMD.getColumns(),
+ RSMD.getColumnTypeName() and DBMD.getTypeInfo().
+
+ This fix also ensures that the precision of UNSIGNED MEDIUMINT
+ and UNSIGNED BIGINT is reported correctly via DBMD.getColumns().
+
07-19-07 - Version 5.0.7
- Setting the configuration parameter "useCursorFetch" to "true" for
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java
===================================================================
---
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java 2007-10-02
22:35:59 UTC (rev 6600)
+++
branches/branch_5_0/connector-j/src/com/mysql/jdbc/ConnectionProperties.java 2007-10-03
14:24:12 UTC (rev 6601)
@@ -812,7 +812,7 @@
private BooleanConnectionProperty capitalizeTypeNames = new BooleanConnectionProperty(
"capitalizeTypeNames",
- false,
+ true,
"Capitalize type names in DatabaseMetaData? (usually only useful when using
WebObjects, true/false, defaults to 'false')",
"2.0.7", MISC_CATEGORY, Integer.MIN_VALUE);
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/DatabaseMetaData.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/DatabaseMetaData.java 2007-10-02
22:35:59 UTC (rev 6600)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/DatabaseMetaData.java 2007-10-03
14:24:12 UTC (rev 6601)
@@ -204,8 +204,11 @@
// Add unsigned to typename reported to enduser as 'native type', if
// present
+ boolean isUnsigned = false;
+
if (StringUtils.indexOfIgnoreCase(typeInfo, "unsigned") != -1) {
fullMysqlType = mysqlType + " unsigned";
+ isUnsigned = true;
} else {
fullMysqlType = mysqlType;
}
@@ -315,7 +318,7 @@
this.decimalDigits = new Integer(0);
} else if (StringUtils.startsWithIgnoreCaseAndWs(typeInfo,
"mediumint")) {
- this.columnSize = new Integer(7);
+ this.columnSize = new Integer(isUnsigned ? 8 : 7);
this.decimalDigits = new Integer(0);
} else if (StringUtils.startsWithIgnoreCaseAndWs(typeInfo,
"int")) {
@@ -327,7 +330,7 @@
this.decimalDigits = new Integer(0);
} else if (StringUtils.startsWithIgnoreCaseAndWs(typeInfo,
"bigint")) {
- this.columnSize = new Integer(19);
+ this.columnSize = new Integer(isUnsigned ? 20 : 19);
this.decimalDigits = new Integer(0);
} else if (StringUtils.startsWithIgnoreCaseAndWs(typeInfo,
"int24")) {
@@ -5173,7 +5176,36 @@
rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
tuples.add(rowVal);
+
+ rowVal = new byte[18][];
+ rowVal[0] = s2b("TINYINT UNSIGNED");
+ rowVal[1] = Integer.toString(java.sql.Types.TINYINT).getBytes();
+ // JDBC Data type
+ rowVal[2] = s2b("3"); // Precision
+ rowVal[3] = s2b(""); // Literal Prefix
+ rowVal[4] = s2b(""); // Literal Suffix
+ rowVal[5] = s2b("[(M)] [UNSIGNED] [ZEROFILL]"); // Create Params
+ rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable)
+ .getBytes();
+
+ // Nullable
+ rowVal[7] = s2b("false"); // Case Sensitive
+ rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable)
+ .getBytes();
+
+ // Searchable
+ rowVal[9] = s2b("true"); // Unsignable
+ rowVal[10] = s2b("false"); // Fixed Prec Scale
+ rowVal[11] = s2b("true"); // Auto Increment
+ rowVal[12] = s2b("TINYINT UNSIGNED"); // Locale Type Name
+ rowVal[13] = s2b("0"); // Minimum Scale
+ rowVal[14] = s2b("0"); // Maximum Scale
+ rowVal[15] = s2b("0"); // SQL Data Type (not used)
+ rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
+ rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
+ tuples.add(rowVal);
+
/*
* MySQL Type: BIGINT JDBC Type: BIGINT
*/
@@ -5205,7 +5237,36 @@
rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
tuples.add(rowVal);
+
+ rowVal = new byte[18][];
+ rowVal[0] = s2b("BIGINT UNSIGNED");
+ rowVal[1] = Integer.toString(java.sql.Types.BIGINT).getBytes();
+ // JDBC Data type
+ rowVal[2] = s2b("20"); // Precision
+ rowVal[3] = s2b(""); // Literal Prefix
+ rowVal[4] = s2b(""); // Literal Suffix
+ rowVal[5] = s2b("[(M)] [ZEROFILL]"); // Create Params
+ rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable)
+ .getBytes();
+
+ // Nullable
+ rowVal[7] = s2b("false"); // Case Sensitive
+ rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable)
+ .getBytes();
+
+ // Searchable
+ rowVal[9] = s2b("true"); // Unsignable
+ rowVal[10] = s2b("false"); // Fixed Prec Scale
+ rowVal[11] = s2b("true"); // Auto Increment
+ rowVal[12] = s2b("BIGINT UNSIGNED"); // Locale Type Name
+ rowVal[13] = s2b("0"); // Minimum Scale
+ rowVal[14] = s2b("0"); // Maximum Scale
+ rowVal[15] = s2b("0"); // SQL Data Type (not used)
+ rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
+ rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
+ tuples.add(rowVal);
+
/*
* MySQL Type: LONG VARBINARY JDBC Type: LONGVARBINARY
*/
@@ -5736,7 +5797,36 @@
rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
tuples.add(rowVal);
+
+ rowVal = new byte[18][];
+ rowVal[0] = s2b("INTEGER UNSIGNED");
+ rowVal[1] = Integer.toString(java.sql.Types.INTEGER).getBytes();
+ // JDBC Data type
+ rowVal[2] = s2b("10"); // Precision
+ rowVal[3] = s2b(""); // Literal Prefix
+ rowVal[4] = s2b(""); // Literal Suffix
+ rowVal[5] = s2b("[(M)] [ZEROFILL]"); // Create Params
+ rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable)
+ .getBytes();
+
+ // Nullable
+ rowVal[7] = s2b("false"); // Case Sensitive
+ rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable)
+ .getBytes();
+
+ // Searchable
+ rowVal[9] = s2b("true"); // Unsignable
+ rowVal[10] = s2b("false"); // Fixed Prec Scale
+ rowVal[11] = s2b("true"); // Auto Increment
+ rowVal[12] = s2b("INTEGER UNSIGNED"); // Locale Type Name
+ rowVal[13] = s2b("0"); // Minimum Scale
+ rowVal[14] = s2b("0"); // Maximum Scale
+ rowVal[15] = s2b("0"); // SQL Data Type (not used)
+ rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
+ rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
+ tuples.add(rowVal);
+
/*
* MySQL Type: INT JDBC Type: INTEGER
*/
@@ -5768,7 +5858,36 @@
rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
tuples.add(rowVal);
+
+ rowVal = new byte[18][];
+ rowVal[0] = s2b("INT UNSIGNED");
+ rowVal[1] = Integer.toString(java.sql.Types.INTEGER).getBytes();
+ // JDBC Data type
+ rowVal[2] = s2b("10"); // Precision
+ rowVal[3] = s2b(""); // Literal Prefix
+ rowVal[4] = s2b(""); // Literal Suffix
+ rowVal[5] = s2b("[(M)] [ZEROFILL]"); // Create Params
+ rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable)
+ .getBytes();
+
+ // Nullable
+ rowVal[7] = s2b("false"); // Case Sensitive
+ rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable)
+ .getBytes();
+
+ // Searchable
+ rowVal[9] = s2b("true"); // Unsignable
+ rowVal[10] = s2b("false"); // Fixed Prec Scale
+ rowVal[11] = s2b("true"); // Auto Increment
+ rowVal[12] = s2b("INT UNSIGNED"); // Locale Type Name
+ rowVal[13] = s2b("0"); // Minimum Scale
+ rowVal[14] = s2b("0"); // Maximum Scale
+ rowVal[15] = s2b("0"); // SQL Data Type (not used)
+ rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
+ rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
+ tuples.add(rowVal);
+
/*
* MySQL Type: MEDIUMINT JDBC Type: INTEGER
*/
@@ -5801,6 +5920,35 @@
rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
tuples.add(rowVal);
+ rowVal = new byte[18][];
+ rowVal[0] = s2b("MEDIUMINT UNSIGNED");
+ rowVal[1] = Integer.toString(java.sql.Types.INTEGER).getBytes();
+
+ // JDBC Data type
+ rowVal[2] = s2b("8"); // Precision
+ rowVal[3] = s2b(""); // Literal Prefix
+ rowVal[4] = s2b(""); // Literal Suffix
+ rowVal[5] = s2b("[(M)] [ZEROFILL]"); // Create Params
+ rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable)
+ .getBytes();
+
+ // Nullable
+ rowVal[7] = s2b("false"); // Case Sensitive
+ rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable)
+ .getBytes();
+
+ // Searchable
+ rowVal[9] = s2b("true"); // Unsignable
+ rowVal[10] = s2b("false"); // Fixed Prec Scale
+ rowVal[11] = s2b("true"); // Auto Increment
+ rowVal[12] = s2b("MEDIUMINT UNSIGNED"); // Locale Type Name
+ rowVal[13] = s2b("0"); // Minimum Scale
+ rowVal[14] = s2b("0"); // Maximum Scale
+ rowVal[15] = s2b("0"); // SQL Data Type (not used)
+ rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
+ rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
+ tuples.add(rowVal);
+
/*
* MySQL Type: SMALLINT JDBC Type: SMALLINT
*/
@@ -5832,7 +5980,36 @@
rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
tuples.add(rowVal);
+
+ rowVal = new byte[18][];
+ rowVal[0] = s2b("SMALLINT UNSIGNED");
+ rowVal[1] = Integer.toString(java.sql.Types.SMALLINT).getBytes();
+ // JDBC Data type
+ rowVal[2] = s2b("5"); // Precision
+ rowVal[3] = s2b(""); // Literal Prefix
+ rowVal[4] = s2b(""); // Literal Suffix
+ rowVal[5] = s2b("[(M)] [ZEROFILL]"); // Create Params
+ rowVal[6] = Integer.toString(java.sql.DatabaseMetaData.typeNullable)
+ .getBytes();
+
+ // Nullable
+ rowVal[7] = s2b("false"); // Case Sensitive
+ rowVal[8] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable)
+ .getBytes();
+
+ // Searchable
+ rowVal[9] = s2b("true"); // Unsignable
+ rowVal[10] = s2b("false"); // Fixed Prec Scale
+ rowVal[11] = s2b("true"); // Auto Increment
+ rowVal[12] = s2b("SMALLINT UNSIGNED"); // Locale Type Name
+ rowVal[13] = s2b("0"); // Minimum Scale
+ rowVal[14] = s2b("0"); // Maximum Scale
+ rowVal[15] = s2b("0"); // SQL Data Type (not used)
+ rowVal[16] = s2b("0"); // SQL DATETIME SUB (not used)
+ rowVal[17] = s2b("10"); // NUM_PREC_RADIX (2 or 10)
+ tuples.add(rowVal);
+
/*
* MySQL Type: FLOAT JDBC Type: REAL (this is the SINGLE PERCISION
* floating point type)
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java 2007-10-02
22:35:59 UTC (rev 6600)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/ResultSetMetaData.java 2007-10-03
14:24:12 UTC (rev 6601)
@@ -306,7 +306,7 @@
return field.isUnsigned() ? "SMALLINT UNSIGNED" : "SMALLINT";
case MysqlDefs.FIELD_TYPE_LONG:
- return field.isUnsigned() ? "INTEGER UNSIGNED" : "INTEGER";
+ return field.isUnsigned() ? "INT UNSIGNED" : "INT";
case MysqlDefs.FIELD_TYPE_FLOAT:
return field.isUnsigned() ? "FLOAT UNSIGNED" : "FLOAT";
Modified:
branches/branch_5_0/connector-j/src/testsuite/regression/MetaDataRegressionTest.java
===================================================================
---
branches/branch_5_0/connector-j/src/testsuite/regression/MetaDataRegressionTest.java 2007-10-02
22:35:59 UTC (rev 6600)
+++
branches/branch_5_0/connector-j/src/testsuite/regression/MetaDataRegressionTest.java 2007-10-03
14:24:12 UTC (rev 6601)
@@ -2024,4 +2024,46 @@
assertNull(this.rs.getString("SOURCE_DATA_TYPE"));
assertEquals("NO", this.rs.getString("IS_AUTOINCREMENT"));
}
+
+ /**
+ * Tests fix for BUG#27916 - UNSIGNED types not reported
+ * via DBMD.getTypeInfo(), and capitalization of types is
+ * not consistent between DBMD.getColumns(), RSMD.getColumnTypeName()
+ * and DBMD.getTypeInfo().
+ *
+ * This fix also ensures that the precision of UNSIGNED MEDIUMINT
+ * and UNSIGNED BIGINT is reported correctly via DBMD.getColumns().
+ *
+ * @throws Exception
+ */
+ public void testBug27916() throws Exception {
+ createTable(
+ "testBug27916",
+ "(field1 TINYINT UNSIGNED, field2 SMALLINT UNSIGNED, field3 INT UNSIGNED, field4
INTEGER UNSIGNED, field5 MEDIUMINT UNSIGNED, field6 BIGINT UNSIGNED)");
+
+ ResultSetMetaData rsmd = this.stmt.executeQuery(
+ "SELECT * FROM testBug27916").getMetaData();
+
+ HashMap typeNameToPrecision = new HashMap();
+ this.rs = this.conn.getMetaData().getTypeInfo();
+
+ while (this.rs.next()) {
+ typeNameToPrecision.put(this.rs.getString("TYPE_NAME"), this.rs
+ .getObject("PRECISION"));
+ }
+
+ this.rs = this.conn.getMetaData().getColumns(this.conn.getCatalog(),
+ null, "testBug27916", "%");
+
+ for (int i = 0; i < rsmd.getColumnCount(); i++) {
+ this.rs.next();
+ String typeName = this.rs.getString("TYPE_NAME");
+
+ assertEquals(typeName, rsmd.getColumnTypeName(i + 1));
+ assertEquals(typeName, this.rs.getInt("COLUMN_SIZE"), rsmd
+ .getPrecision(i + 1));
+ assertEquals(typeName, new Integer(rsmd.getPrecision(i + 1)),
+ typeNameToPrecision.get(typeName));
+ }
+ }
}
| Thread |
|---|
| • Connector/J commit: r6601 - in branches/branch_5_0/connector-j: . src/com/mysql/jdbc src/testsuite/regression | mmatthews | 3 Oct |