Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 059F19FB6AE for ; Tue, 6 Mar 2007 12:49:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 37587-01-4 for ; Tue, 6 Mar 2007 12:49:15 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail63.csoft.net (leary.csoft.net [205.205.214.5]) by postgresql.org (Postfix) with SMTP id 25CCE9FB8AF for ; Tue, 6 Mar 2007 12:49:14 -0400 (AST) Received: (qmail 17134 invoked by uid 1112); 6 Mar 2007 16:49:05 -0000 Date: Tue, 6 Mar 2007 11:49:05 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Valery Meshkov cc: pgsql-bugs@postgresql.org, pgsql-jdbc@postgresql.org Subject: Re: BUG #3106: A problem with escaping table name pattern for DatabaseMetaData.getColumns() In-Reply-To: <200703041900.l24J08aR034467@wwwmaster.postgresql.org> Message-ID: References: <200703041900.l24J08aR034467@wwwmaster.postgresql.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.029 tagged_above=0 required=5 tests=AWL, BAYES_50 X-Spam-Level: X-Archive-Number: 200703/36 X-Sequence-Number: 17050 On Sun, 4 Mar 2007, Valery Meshkov wrote: > The following bug has been logged online: > > Bug reference: 3106 > PostgreSQL version: 8.2.3 > Description: A problem with escaping table name pattern for > DatabaseMetaData.getColumns() > Details: > > I am seeing a problem in the JDBC driver postgresql-8.2-504.jdbc3.jar with > getting columns of the table 'A_B'. I am escaping '_' with the escape > value returned by DatabaseMetaData.getSearchStringEscape(), which in my case > is "\\\\" (standard_conforming_strings is off). When I pass the resulting > table name 'A\\_B' to DatabaseMetaData.getColumns() the number of > backslashes doubles again, resulting in 4 backslashes in the select > statement: > The problem is that there is a different search string escape depending on whether you plan to interpolate it into a query or pass it as a parameter to a PreparedStatement. The getSearchStringEscape method is assuming you're going to interpolate it into a query and returns the doubled version. getColumns is assuming you're passing a parameter that it then interpolates and must escape itself. The fact that the javadoc for getColumns has a see also for getSearchStringEscape implies to me that our implementation is wrong and it shouldn't return the doubled version and anyone interpolating text into a query must escape it appropriately including the search string escape. I'll put a fix for this into the next release. Kris Jurka