From: Giuseppe Sacco <giuseppe@eppesuigoccas.homedns.org>
To: pgsql-jdbc@postgresql.org
Subject: [PATCH] problem with DatabaseMetaData and mixed case table names
Date: Mon, 08 Aug 2005 18:20:43 +0200
Message-ID: <1123518043.6487.4.camel@localhost> (raw)
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 = ...;
Statement s = c.createStatement();
s.execute("create table MyTable ( PK numeric(10), primary key(pk))");
DatabaseMetaData md = c.getMetaData();
ResultSet rs = md.getPrimaryKeys(null,null, "MyTable")
while (rs.next())
System.out.println("table: \"" + rs.getString("TABLE_NAME") +
"\", 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 «getPrimaryKeys» 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 «getPrimaryKeys» in order to pass lowercase relation
names to the backend.
The proposed patch change «escapeQuotes» 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 '=' and 'like' operators.
Is this the right way to solve the problem?
Thanks,
Giuseppe
Attachments:pgsql-lowercase.diff (text/x-patch, 387B) download--- 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();
}
/*
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: giuseppe@eppesuigoccas.homedns.org
Subject: Re: [PATCH] problem with DatabaseMetaData and mixed case table names
In-Reply-To: <1123518043.6487.4.camel@localhost>
References: <1123518043.6487.4.camel@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox