Bug #51904 getProcedureColumns() always returns PROCEDURE_CAT result column as NULL
Submitted: 10 Mar 2010 9:28 Modified: 24 Mar 2010 7:11
Reporter: Bogdan Degtyariov Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.12 OS:Any
Assigned to: CPU Architecture:Any
Tags: getProcedureColumns, PROCEDURE_CAT

[10 Mar 2010 9:28] Bogdan Degtyariov
Description:
This bug is connected to bug#51712, but it goes further.

The PROCEDURE_CAT column in the resultset is always NULL.
This is so because the NULL value for the result is hard-coded in the driver:

DatabaseMetadata.java:843:

		row[0] = null; // PROCEDURE_CAT

How to repeat:
Run the testcase uploaded below.
It displays something like:
---------------------------------------------------
Calling getProcedureColumns(null, null, "%", null)

Outputting procedure columns info:

PROCEDURE_CAT is: null
PROCEDURE_NAME  is: proc_bug_procedure_columns
COLUMN_NAME     is: p1_in
COLUMN_TYPE     is: 1
DATA_TYPE       is: 4

PROCEDURE_CAT is: null
PROCEDURE_NAME  is: proc_bug_procedure_columns
COLUMN_NAME     is: p2_in
COLUMN_TYPE     is: 1
DATA_TYPE       is: 1

PROCEDURE_CAT is: null
PROCEDURE_NAME  is: proc_bug_procedure_columns
COLUMN_NAME     is: p3_out
COLUMN_TYPE     is: 4
DATA_TYPE       is: 4

PROCEDURE_CAT is: null
PROCEDURE_NAME  is: proc_bug_procedure_columns
COLUMN_NAME     is: p4_out
COLUMN_TYPE     is: 4
DATA_TYPE       is: 1
---------------------------------------------------

Suggested fix:
see the diff below. I know it is awkward, but I just wanted to show the idea. Surely Mark will do it nicer.
[10 Mar 2010 9:28] Bogdan Degtyariov
Test case

Attachment: bug_procedure_columns.java (text/x-java), 1.97 KiB.

[10 Mar 2010 9:30] Bogdan Degtyariov
Idea of the bug fix

Attachment: procedure_cat.diff (text/x-diff), 4.76 KiB.

[10 Mar 2010 10:51] Tonci Grgin
Same problem observed using I__S... The symptom is described in Bug#51022. I should have been more careful fixing that bug and replace all occurrences of faulty code... Primary fix for I__S, will see if additional ones are needed:

=== modified file 'src/com/mysql/jdbc/DatabaseMetaDataUsingInfoSchema.java'
--- src/com/mysql/jdbc/DatabaseMetaDataUsingInfoSchema.java
+++ src/com/mysql/jdbc/DatabaseMetaDataUsingInfoSchema.java
@@ -1325,6 +1325,8 @@
                        if (this.conn.getNullCatalogMeansCurrent()) {
                                db = this.database;
                        }
+               }  else {
+                       db = catalog;
                }
[10 Mar 2010 12:38] Tonci Grgin
Looking further into code shows this will get hit only for MySQL server version 5.4+ and for the rest, DatabaseMetaData code is executed. Moving to new bug report.
[10 Mar 2010 13:40] Tonci Grgin
Added bugs Bug#51908 and Bug#51912.
[18 Mar 2010 9:44] Tonci Grgin
This will be fixed in comprehensive patch for Bug#51912
[18 Mar 2010 12:04] Tonci Grgin
New code works just fine with Bogdan's test case:
PROCEDURE_CAT   is: test
PROCEDURE_NAME  is: proc_bug_procedure_columns
COLUMN_NAME     is: p1_in
COLUMN_TYPE     is: 1
DATA_TYPE       is: 4
PRECISSION      is: 10
LENGTH          is: 10

PROCEDURE_CAT   is: test
PROCEDURE_NAME  is: proc_bug_procedure_columns
COLUMN_NAME     is: p2_in
COLUMN_TYPE     is: 1
DATA_TYPE       is: 1
PRECISSION      is: 20
LENGTH          is: 20

PROCEDURE_CAT   is: test
PROCEDURE_NAME  is: proc_bug_procedure_columns
COLUMN_NAME     is: p3_out
COLUMN_TYPE     is: 4
DATA_TYPE       is: 4
PRECISSION      is: 10
LENGTH          is: 10

PROCEDURE_CAT   is: test
PROCEDURE_NAME  is: proc_bug_procedure_columns
COLUMN_NAME     is: p4_out
COLUMN_TYPE     is: 4
DATA_TYPE       is: 1
PRECISSION      is: 11
LENGTH          is: 11
[24 Mar 2010 7:11] Tonci Grgin
This is fixed as a part of Bug#51912.