Re: Bug in getImportedExportedKeys(), DatabaseMetaData class - Mailing list pgsql-jdbc

From Barry Lind
Subject Re: Bug in getImportedExportedKeys(), DatabaseMetaData class
Date
Msg-id 3E9E2FA8.4000806@xythos.com
Whole thread Raw
In response to Re: Bug in getImportedExportedKeys(), DatabaseMetaData class  (Kris Jurka <books@ejurka.com>)
List 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


pgsql-jdbc by date:

Previous
From: Barry Lind
Date:
Subject: Re: [PATCHES] the build
Next
From: Barry Lind
Date:
Subject: Re: Index metadata not sorted by ORDINAL_POSITION