Bug #35115 | yearIsDateType=false has no effect on result's column type and class | ||
---|---|---|---|
Submitted: | 6 Mar 2008 15:02 | Modified: | 21 Nov 2013 17:46 |
Reporter: | Gilles Rayrat | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / J | Severity: | S3 (Non-critical) |
Version: | 5.0.6 | OS: | Any |
Assigned to: | Filipe Silva | CPU Architecture: | Any |
Tags: | date, ResultSet metadata, short, year, yearIsDateType |
[6 Mar 2008 15:02]
Gilles Rayrat
[6 Mar 2008 15:17]
Tonci Grgin
Hi Gilles and thanks for your report. Verified like described using latest c/J 5.0 sources.
[6 Mar 2008 15:20]
Gilles Rayrat
Java class showing the different types and names for yearIsDateType=false and true
Attachment: TestBug35115.java (text/plain), 2.15 KiB.
[6 Mar 2008 15:24]
Tonci Grgin
Test case
Attachment: TestBug35115.java (text/x-java), 975 bytes.
[21 Nov 2013 17:46]
Daniel So
Added the following entry into the Connector/J 5.1.27 changelog: "After setting the connection property yearIsDateType=false, the method ResultSet.getMetaData().getColumnType() still returned the data type of a YEAR column as DATE. This fix corrected the metadata for a YEAR column under this situation, so that the correct data type of SHORT is returned."
[25 Jul 2014 19:24]
Jack Beckman
Fails for me using driver 5.1.31 on OS X with Java 1.7.0_6. Simple test case: CREATE TABLE Seasons ( season_id bigint NOT NULL AUTO_INCREMENT, season_name VARCHAR(100), season_year YEAR, PRIMARY KEY (season_id), INDEX Seasons_ix1 (season_name, season_year) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Year always returns a DATE even if yearIsDateType=false.
[28 Jul 2014 11:56]
Filipe Silva
Hi Jack, Thank you for pointing this out. Actually, in spite of the value of the property 'yearIsDateType', both methods ResultSetMetaData.getColumnType() and ResultSetMetaData.getColumnTypeName() will return the same values, i.e., 91 (java.sql.Types.DATE) and "YEAR" respectively, as it was determined by the fix for Bug#10485. The actual difference is how this values are treated internally, which is either as java.sql.Date or java.lang.Short. This patch fixes the identification of the SQL type to Java type mapping that can be obtained from ResultSetMetaData.getColumnClassName(). Now it returns the correct value, java.sql.Date for 'yearIsDateType=true' and java.lang.Short for 'yearIsDateType=false'. The best way of seeing these differences is by using the method ResultSet.getObject(). The description in the change log is not correct however, but we should fix it as soon as possible.
[28 Jul 2014 17:16]
Daniel So
Corrected the changelog entry for this bug in Connector/J 5.1.27 to: "After setting the connection property yearIsDateType=false, the method ResultSet.getMetaData().getColumnClassName() still returned the Java type of a YEAR column as as java.sql.Date although internally it was being treated as java.sql.Short. This fix corrects the metadata for a YEAR column under this situation, so that the correct Java type of java.sql.Short is returned. Please note that the method ResultSet.getMetaData().getColumnType(), however, returns java.sql.Types.DATE irrespective of the yearIsDateType setting.