Bug in getImportedExportedKeys(), DatabaseMetaData class

From: Todd Cornett <tcornett(at)mitre(dot)org>
To: pgsql-jdbc(at)postgresql(dot)org
Cc: "Hoyt,Jeffrey C(dot)" <jchoyt(at)mitre(dot)org>, "Smith,Kenneth P(dot)" <kps(at)mitre(dot)org>, "Carley,Monica P(dot)" <mcarley(at)mitre(dot)org>, "Cornett,Todd C(dot)" <tcornett(at)mitre(dot)org>
Subject: Bug in getImportedExportedKeys(), DatabaseMetaData class
Date: 2003-04-08 17:17:02
Message-ID: 3E93040E.B57AFE@mitre.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

All:

In our work with PostgreSQL 7.3.2 and the JDBC drivers, we have
discovered a bug in the DatabaseMetaData class, or more specifically the
AbstractJdbc1DatabaseMetaData class in the getImportedExportedKeys()
(about line number 3100) . We found that the current use of the
StringTokenizer to parse out the response from the database acheieves
the desired result only when the returning column and table names do not
contain either '\' or '0'. We believe that the intent was to treat the
string parameter as a literal string and not as a collection of
characters, as Java interprets it.

To fix this, we used the split function, available in JDK1.4, to split
the string. The sample of the code is attached below. Unfortunately,
this fix only works in JDK1.4 but hopefully this will fix someone's
problem if they come across it or at least bring it to the attention of
the development team.

Thank you for your time,

Todd Cornett
The MITRE Corporation

/***********************************************/

// args look like this
//<unnamed>\000ww\000vv\000UNSPECIFIED\000m\000a\000n\000b\000
// we are primarily interested in the column names which are the last
items in the string

// StringTokenizer st = new StringTokenizer(targs, "\\000");

String[] str_array = targs.split( "\\\\000" );

int advance = 4 + (keySequence - 1) * 2;
/*

for ( int i = 0; st.hasMoreTokens() && i < advance ; i++ ) {
st.nextToken(); // advance to the key column of interest
}
if ( st.hasMoreTokens() )
{
fkeyColumn = st.nextToken();
}
if ( st.hasMoreTokens() )
{
pkeyColumn = st.nextToken();
}
*/
if( str_array.length >= advance ) {

fkeyColumn = str_array[ advance ];

if( str_array.length >= ( advance + 1 ) ) {

pkeyColumn = str_array[ advance + 1 ];

}
}

tuple[3] = pkeyColumn.getBytes(); //PKCOLUMN_NAME
tuple[7] = fkeyColumn.getBytes(); //FKCOLUMN_NAME

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message . 2003-04-08 17:23:00 Problem asking columns allowing NULL values
Previous Message Dave Cramer 2003-04-08 16:43:48 Re: Problem asking columns allowing NULL values