Thread: getColumns() is not table name case insensitive

getColumns() is not table name case insensitive

From
Michał Niklas
Date:
Hello,

I'm working with PostgreSQL from both Delphi and Java.
In Java I use JDBC driver.
In Delphi I use PgLib or Zeos components.
Zeos components can be found at:
http://sourceforge.net/projects/zeoslib

My program can show tables and columns.
I use metainformation to get it.
Unfortunatelly getColumns() works fine only
if name of table is identical in case
with table name in PostgreSQL system tables.

If in my db is table 'test' I can do:
a) SELECT fld FROM test
b) SELECT fld FROM Test
c) SELECT fld FROM TEST
etc
But getColumns() works only with "test".

In Zeos there are functions that get meta information
about table columns just like JDBC getColumns().
They use lower() SQL function and Lowercase()
Pascal function.
Example from ZDirPgSql.pas:

   Sql := 'SELECT pg_attribute.attnum AS index, attname AS field,'
...
     +' AND atthasdef=''f'' AND
lower(relname)='''+LowerCase(TableName)+'''';
   if FieldName <> '' then
     Sql := Sql + ' AND lower(attname) LIKE '''+LowerCase(FieldName)+'''';

In JDBC AbstractJdbc1DatabaseMetaData.java
where getColumns() is implemented
I have found no lower() function:
if (tableNamePattern != null && !"".equals(tableNamePattern)) {
sql += " AND c.relname LIKE '"+escapeQuotes(tableNamePattern)+"' ";
}
if (columnNamePattern != null && !"".equals(columnNamePattern)) {
sql += " AND a.attname LIKE '"+escapeQuotes(columnNamePattern)+"' ";
...

I think both relname and attname should be compared
without case sensitivity.

Best regards,
Michal Niklas
http://republika.pl/michalniklas/mn.html


Re: getColumns() is not table name case insensitive

From
Kris Jurka
Date:

On Wed, 19 Feb 2003, [ISO-8859-2] Micha� Niklas wrote:

> Hello,
> My program can show tables and columns.
> I use metainformation to get it.
> Unfortunatelly getColumns() works fine only
> if name of table is identical in case
> with table name in PostgreSQL system tables.
>
> I think both relname and attname should be compared
> without case sensitivity.
>

What if you have two tables named "tableone" and "TableOne" then you
cannot retrieve the information for just one of the tables.

You can determine the Postgres case folding rules from the various
DatabaseMetaData.storesXXXXXCaseIdentifiers methods.  What this won't tell
you is wether your original table was created with quotes or not.  If your
getColumns call is generated from the results of getTables then your fine
because it will give you the correct case.  What is your table name source
for this application?

Kris Jurka