|
37 | 37 | import java.sql.RowIdLifetime; |
38 | 38 | import java.sql.SQLException; |
39 | 39 | import java.sql.Statement; |
| 40 | +import java.sql.Types; |
40 | 41 | import java.util.ArrayList; |
41 | 42 | import java.util.Arrays; |
42 | 43 | import java.util.Collections; |
@@ -752,6 +753,7 @@ protected enum ProcedureType { |
752 | 753 | protected boolean tinyInt1isBit; |
753 | 754 | protected boolean transformedBitIsBoolean; |
754 | 755 | protected boolean useHostsInPrivileges; |
| 756 | + protected boolean yearIsDateType; |
755 | 757 |
|
756 | 758 | protected RuntimeProperty<DatabaseTerm> databaseTerm; |
757 | 759 | protected RuntimeProperty<Boolean> nullDatabaseMeansCurrent; |
@@ -792,6 +794,7 @@ protected DatabaseMetaData(JdbcConnection connToSet, String databaseToSet, Resul |
792 | 794 | this.tinyInt1isBit = this.conn.getPropertySet().getBooleanProperty(PropertyKey.tinyInt1isBit).getValue(); |
793 | 795 | this.transformedBitIsBoolean = this.conn.getPropertySet().getBooleanProperty(PropertyKey.transformedBitIsBoolean).getValue(); |
794 | 796 | this.useHostsInPrivileges = this.conn.getPropertySet().getBooleanProperty(PropertyKey.useHostsInPrivileges).getValue(); |
| 797 | + this.yearIsDateType = this.conn.getPropertySet().getBooleanProperty(PropertyKey.yearIsDateType).getValue(); |
795 | 798 | this.quotedId = this.session.getIdentifierQuoteString(); |
796 | 799 | } |
797 | 800 |
|
@@ -873,7 +876,8 @@ private Row convertTypeDescriptorToProcedureRow(byte[] procNameAsBytes, byte[] p |
873 | 876 | row[2] = procNameAsBytes; // PROCEDURE/NAME |
874 | 877 | row[3] = s2b(paramName); // COLUMN_NAME |
875 | 878 | row[4] = s2b(String.valueOf(getColumnType(isOutParam, isInParam, isReturnParam, forGetFunctionColumns))); // COLUMN_TYPE |
876 | | - row[5] = s2b(Short.toString((short) typeDesc.mysqlType.getJdbcType())); // DATA_TYPE |
| 879 | + row[5] = Short.toString(typeDesc.mysqlType == MysqlType.YEAR && !DatabaseMetaData.this.yearIsDateType ? // |
| 880 | + Types.SMALLINT : (short) typeDesc.mysqlType.getJdbcType()).getBytes(); // DATA_TYPE (jdbc) |
877 | 881 | row[6] = s2b(typeDesc.mysqlType.getName()); // TYPE_NAME |
878 | 882 | row[7] = typeDesc.datetimePrecision == null ? s2b(typeDesc.columnSize.toString()) : s2b(typeDesc.datetimePrecision.toString()); // PRECISION |
879 | 883 | row[8] = typeDesc.columnSize == null ? null : s2b(typeDesc.columnSize.toString()); // LENGTH |
@@ -1346,7 +1350,8 @@ void forEach(String dbStr) throws SQLException { |
1346 | 1350 | } |
1347 | 1351 |
|
1348 | 1352 | MysqlType ft = MysqlType.getByName(type.toUpperCase()); |
1349 | | - rowVal[2] = s2b(String.valueOf(ft.getJdbcType())); |
| 1353 | + rowVal[2] = s2b( |
| 1354 | + String.valueOf(ft == MysqlType.YEAR && !DatabaseMetaData.this.yearIsDateType ? Types.SMALLINT : ft.getJdbcType())); |
1350 | 1355 | rowVal[3] = s2b(type); |
1351 | 1356 | rowVal[4] = hasLength ? Integer.toString(size + decimals).getBytes() : Long.toString(ft.getPrecision()).getBytes(); |
1352 | 1357 | rowVal[5] = Integer.toString(maxBufferSize).getBytes(); |
@@ -2171,7 +2176,8 @@ void forEach(String dbStr) throws SQLException { |
2171 | 2176 | rowVal[1] = DatabaseMetaData.this.databaseTerm.getValue() == DatabaseTerm.SCHEMA ? s2b(dbStr) : null; // TABLE_SCHEM |
2172 | 2177 | rowVal[2] = s2b(tableName); // TABLE_NAME |
2173 | 2178 | rowVal[3] = results.getBytes("Field"); |
2174 | | - rowVal[4] = Short.toString((short) typeDesc.mysqlType.getJdbcType()).getBytes();// DATA_TYPE (jdbc) |
| 2179 | + rowVal[4] = Short.toString(typeDesc.mysqlType == MysqlType.YEAR && !DatabaseMetaData.this.yearIsDateType ? Types.SMALLINT |
| 2180 | + : (short) typeDesc.mysqlType.getJdbcType()).getBytes(); // DATA_TYPE (jdbc) |
2175 | 2181 | rowVal[5] = s2b(typeDesc.mysqlType.getName()); // TYPE_NAME (native) |
2176 | 2182 | if (typeDesc.columnSize == null) { // COLUMN_SIZE |
2177 | 2183 | rowVal[6] = null; |
@@ -3943,7 +3949,7 @@ private byte[][] getTypeInfo(String mysqlTypeName) throws SQLException { |
3943 | 3949 | byte[][] rowVal = new byte[18][]; |
3944 | 3950 |
|
3945 | 3951 | rowVal[0] = s2b(mysqlTypeName); // Type name |
3946 | | - rowVal[1] = Integer.toString(mt.getJdbcType()).getBytes(); // JDBC Data type |
| 3952 | + rowVal[1] = Integer.toString(mt == MysqlType.YEAR && !DatabaseMetaData.this.yearIsDateType ? Types.SMALLINT : mt.getJdbcType()).getBytes(); // JDBC Data type |
3947 | 3953 | // JDBC spec reserved only 'int' type for precision, thus we need to cut longer values |
3948 | 3954 | rowVal[2] = Integer.toString(mt.getPrecision() > Integer.MAX_VALUE ? Integer.MAX_VALUE : mt.getPrecision().intValue()).getBytes(); // Precision |
3949 | 3955 | switch (mt) { |
@@ -4208,7 +4214,8 @@ void forEach(String dbStr) throws SQLException { |
4208 | 4214 | byte[][] rowVal = new byte[8][]; |
4209 | 4215 | rowVal[0] = null; // SCOPE is not used |
4210 | 4216 | rowVal[1] = results.getBytes("Field"); // COLUMN_NAME |
4211 | | - rowVal[2] = Short.toString((short) typeDesc.mysqlType.getJdbcType()).getBytes(); // DATA_TYPE |
| 4217 | + rowVal[2] = Short.toString(typeDesc.mysqlType == MysqlType.YEAR && !DatabaseMetaData.this.yearIsDateType ? Types.SMALLINT |
| 4218 | + : (short) typeDesc.mysqlType.getJdbcType()).getBytes(); // DATA_TYPE (jdbc) |
4212 | 4219 | rowVal[3] = s2b(typeDesc.mysqlType.getName()); // TYPE_NAME |
4213 | 4220 | rowVal[4] = typeDesc.columnSize == null ? null : s2b(typeDesc.columnSize.toString()); // COLUMN_SIZE |
4214 | 4221 | rowVal[5] = s2b(Integer.toString(typeDesc.bufferLength)); // BUFFER_LENGTH |
|
0 commit comments