From: | Barry Lind <blind(at)xythos(dot)com> |
---|---|
To: | Kris Jurka <books(at)ejurka(dot)com> |
Cc: | Todd Cornett <tcornett(at)mitre(dot)org>, pgsql-jdbc(at)postgresql(dot)org, "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> |
Subject: | Re: Bug in getImportedExportedKeys(), DatabaseMetaData class |
Date: | 2003-04-17 04:38:00 |
Message-ID: | 3E9E2FA8.4000806@xythos.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Patch applied to both head and 7.3 branch.
--Barry
Kris Jurka wrote:
>
> On Tue, 8 Apr 2003, Todd Cornett wrote:
>
>
>>All:
>>
>>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'.
>
>
> The attached patch fixes this for all JDK versions by using its own
> tokenizing routine.
>
> Kris Jurka
>
>
>
> ------------------------------------------------------------------------
>
> Index: src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java,v
> retrieving revision 1.20
> diff -c -r1.20 AbstractJdbc1DatabaseMetaData.java
> *** src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java 2003/03/25 02:28:45 1.20
> --- src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java 2003/04/16 07:17:29
> ***************
> *** 3143,3168 ****
> //<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");
> ! if (st.hasMoreTokens()) {
> ! fkName = st.nextToken();
> }
>
> if (fkName.startsWith("<unnamed>")) {
> fkName = targs;
> }
>
> ! int advance = 4 + (keySequence - 1) * 2;
> ! for ( int i = 1; 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();
> }
>
> tuple[3] = pkeyColumn.getBytes(); //PKCOLUMN_NAME
> --- 3143,3165 ----
> //<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
>
> ! Vector tokens = tokenize(targs, "\\000");
> ! if (tokens.size() > 0) {
> ! fkName = (String)tokens.elementAt(0);
> }
>
> if (fkName.startsWith("<unnamed>")) {
> fkName = targs;
> }
>
> ! int element = 4 + (keySequence - 1) * 2;
> ! if (tokens.size() > element) {
> ! fkeyColumn = (String)tokens.elementAt(element);
> }
> !
> ! element++;
> ! if (tokens.size() > element) {
> ! pkeyColumn = (String)tokens.elementAt(element);
> }
>
> tuple[3] = pkeyColumn.getBytes(); //PKCOLUMN_NAME
> ***************
> *** 3571,3575 ****
> --- 3568,3597 ----
> sql += " ORDER BY NON_UNIQUE, TYPE, INDEX_NAME ";
> return connection.createStatement().executeQuery(sql);
> }
> +
> + /**
> + * Tokenize based on words not on single characters.
> + */
> + private static Vector tokenize(String input, String delimiter) {
> + Vector result = new Vector();
> + int start = 0;
> + int end = input.length();
> + int delimiterSize = delimiter.length();
> +
> + while (start < end) {
> + int delimiterIndex = input.indexOf(delimiter,start);
> + if (delimiterIndex < 0) {
> + result.addElement(input.substring(start));
> + break;
> + } else {
> + String token = input.substring(start,delimiterIndex);
> + result.addElement(token);
> + start = delimiterIndex + delimiterSize;
> + }
> + }
> + return result;
> + }
> +
> +
>
> }
>
>
> ------------------------------------------------------------------------
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
From | Date | Subject | |
---|---|---|---|
Next Message | Barry Lind | 2003-04-17 04:38:25 | Re: Index metadata not sorted by ORDINAL_POSITION |
Previous Message | Justin Clift | 2003-04-17 01:52:44 | Website giving wrong mime type for the .jar files? |