Bug #4880 connectorJ ResultSetMetaData returns wrong length on varchar fields
Submitted: 3 Aug 2004 20:18 Modified: 4 Aug 2004 2:38
Reporter: Jim Mason Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:3.0.10 OS:Windows (Windows XP)
Assigned to: Mark Matthews CPU Architecture:Any

[3 Aug 2004 20:18] Jim Mason
Description:
connecting to a table in Mysql 4.0.18 that has varchar fields, the jdbc connector resultsetMetaData shows a 0 length and precision for varchar fields.  This is incorrect.

This is a critical show stopper for MySQL.  Is there something wrong with the combination of mysql 4.0.18 and ConnectorJ 3.0.10 that causes it not to get the right metadata?

The same request against any other database works fine.

How to repeat:
Running a describe mytable; at command line correctly shows the length of varchar fields.  For instance, customer table company field has varchar(150).

Using ConnectorJ v3.0.10 to retrieve the ResultSetMetaData shows a length and precision of 0 for the same column.  This is incorrect.

The ResultSetMetaData is generated normally after running a select query.  The select query returns the correct data from the correct columns.

int len = rsmd.getLength(3)  // 3 is the company column in the database

Suggested fix:
correct the Driver to return correct lengths for varchar fields for length and precision attributes

also IF there is an undocumented dependency between the connectJ version and the MySQL version needed, please document that

Let Me know how to get a hold of this fix asap..

Thanks,

Jim Mason

jmason900@yahoo.com
[4 Aug 2004 1:49] Matthew Lord
Dear User,

Have you also experienced this when using 3.0.14,the latest production releast for connectorj?
[4 Aug 2004 2:16] Matthew Lord
I was able to repeat this by using the attached Tester.java file.  I was connecting from a RH 9 
box using connector/j 3.0.14 and 3.1.3 to a windows 2k box running 4.0.20 and 4.1.3.
[4 Aug 2004 2:19] Mark Matthews
Turns out this is defined in the _tutorial_ for JDBC, but not in the spec itself. Will be fixed for 3.0.15.
[4 Aug 2004 2:23] Matthew Lord
Dear Sir,

I apologize, I was calling getPrecision instead of getColumnDisplaySize().

getColumnDisplaySize() works correctly using 3.0.14 and 4.0.20.  I do not see getLength() in 
ResultSetMetaData.

Best Regards
[4 Aug 2004 2:35] Mark Matthews
The JDBC compliance testsuite actually makes the following comment about RSMD.getPrecision(), which is why we are fixing this:

     * The getPrecision(int colindex) method returns an integer value
     * representing the number of decimal digits for number types,maximum
     * length in characters for character types,maximum length in bytes
     * for JDBC binary datatypes.
     * 
     * (See Section 27.3 of JDBC 2.0 API Reference & Tutorial 2nd edition)

The issue stems from the fact that this behavior is _not_ documented in the JDBC specification or the javadocs for java.sql.ResultSetMetaData, unfortunately.
[4 Aug 2004 2:38] Mark Matthews
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

This is now fixed in the source repository. A snapshot build of 3.0.15 with this fix will be available after 00:00 GMT on 04-Aug-04 at http://downloads.mysql.com/snapshots.php