X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A7DBC52F39 for ; Mon, 8 Aug 2005 15:15:59 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72372-02 for ; Mon, 8 Aug 2005 18:15:50 +0000 (GMT) Received: from vsmtp14.tin.it (vsmtp14.tin.it [212.216.176.118]) by svr1.postgresql.org (Postfix) with ESMTP id 44A6252E36 for ; Mon, 8 Aug 2005 15:15:49 -0300 (ADT) Received: from casa (80.117.82.223) by vsmtp14.tin.it (7.2.060.1) (authenticated as giuseppe.sacco17@tin.it) id 42E2842D005EFED1 for pgsql-jdbc@postgresql.org; Mon, 8 Aug 2005 20:15:46 +0200 Received: from eppesuig3wifi ([192.168.2.51]) by casa with esmtpsa (TLS-1.0:RSA_ARCFOUR_MD5:16) (Exim 4.50) id 1E2C4Q-0002iC-Ix; Mon, 08 Aug 2005 20:09:54 +0200 Subject: [PATCH] problem with DatabaseMetaData and mixed case table names From: Giuseppe Sacco To: pgsql-jdbc@postgresql.org Content-Type: multipart/mixed; boundary="=-VL8vBwsIfG6gQ77peVZk" Organization: Giuseppe Sacco Consulting Date: Mon, 08 Aug 2005 18:20:43 +0200 Message-Id: <1123518043.6487.4.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.2.3 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.173 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200508/37 X-Sequence-Number: 13606 --=-VL8vBwsIfG6gQ77peVZk Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Hi pgsql developers, today I found a problem using the latest version of the driver, from CVS. This is an example that shows the problem: --------------------------------------------------------- Connection c =3D ...; Statement s =3D c.createStatement(); s.execute("create table MyTable ( PK numeric(10), primary key(pk))"); DatabaseMetaData md =3D c.getMetaData(); ResultSet rs =3D md.getPrimaryKeys(null,null, "MyTable") while (rs.next()) System.out.println("table: \"" + rs.getString("TABLE_NAME") +=20 "\", column: \"" + rs.getString("COLUMN_NAME") + "\"."); rs.close(); s.close(); c.close(); --------------------------------------------------------- The resultset is empty, while it should contain a line for the "PK" field. If I lowercase the table name in =ABgetPrimaryKeys=BB call than everything works. My question is: how do I know that postgresql changed my table name? The solution I propose is, since it seems that postgresql always store relation names in lowercase letters, to change the jdbc implementation of all methods like =ABgetPrimaryKeys=BB in order to pass lowercase relatio= n names to the backend. The proposed patch change =ABescapeQuotes=BB method that is used for table names, column names, schema names, type names, table name patters, column name patterns, schema name patters and type name patterns. The changed method return a lowercase string, that is thereafter used in sql statements with '=3D' and 'like' operators. Is this the right way to solve the problem? Thanks, Giuseppe --=-VL8vBwsIfG6gQ77peVZk Content-Disposition: attachment; filename=pgsql-lowercase.diff Content-Type: text/x-patch; name=pgsql-lowercase.diff; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit --- org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java.orig 2005-07-22 09:14:23.000000000 +0200 +++ org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 2005-08-08 18:00:31.000000000 +0200 @@ -1757,7 +1757,7 @@ prevPrevChar = prevChar; prevChar = c; } - return sb.toString(); + return sb.toString().toLowerCase(); } /* --=-VL8vBwsIfG6gQ77peVZk--