Re: Get a table name

From: Kris Jurka <books(at)ejurka(dot)com>
To: Oliver Jowett <oliver(at)opencloud(dot)com>
Cc: Gianvito Pio <pio(dot)gianvito(at)gmail(dot)com>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Get a table name
Date: 2009-12-29 12:20:04
Message-ID: alpine.BSO.2.00.0912290703590.24198@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Mon, 28 Dec 2009, Oliver Jowett wrote:

> We concluded a while back that getTableName() is meant to return the
> aliased table name in the query, not the underlying table name. It's not
> easy for the driver to find the aliased name, so it always returns an
> empty string, as you found.
>

Just recently I was reading the Mysql JDBC driver's documentation [1] and
came across the "useColumnNamesInFindColumn" config option that comes with
this description:

Prior to JDBC-4.0, the JDBC specification had a bug related to what
could be given as a "column name" to ResultSet methods like
findColumn(), or getters that took a String property. JDBC-4.0
clarified "column name" to mean the label, as given in an "AS"
clause and returned by ResultSetMetaData.getColumnLabel(), and if
no AS clause, the column name. Setting this property to "true" will
give behavior that is congruent to JDBC-3.0 and earlier versions of
the JDBC specification, but which because of the specification bug
could give unexpected results. This property is preferred over
"useOldAliasMetadataBehavior" unless you need the specific
behavior that it provides with respect to ResultSetMetadata.

This claims that we've got things backwards now despite our extensive
previous discussion because the spec was misleading. I gave the JDBC 4
spec another read and didn't find anything particularly revealing, but
taking a look at the Javadoc for getColumnLabel [2] does clear things up:

Gets the designated column's suggested title for use in printouts
and displays. The suggested title is usually specified by the SQL
AS clause. If a SQL AS is not specified, the value returned from
getColumnLabel will be the same as the value returned by the
getColumnName method.

For reference the previous discussion started at [3] and continued to [4].
So it looks like we should fix this up and ensure there's a way of
getting to old mode as well.

Kris Jurka

[1] http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html
[2] http://java.sun.com/javase/6/docs/api/java/sql/ResultSetMetaData.html#getColumnLabel(int)
[3] http://archives.postgresql.org/pgsql-jdbc/2004-07/threads.php#00314
[4] http://archives.postgresql.org/pgsql-jdbc/2004-08/threads.php#00008

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message mesued 2009-12-29 20:35:36 metadata as XML
Previous Message Kris Jurka 2009-12-28 22:15:43 Re: Bulgarian translation for the PostgreSQL JDBC driver