pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Oliver Jowett <oliver@opencloud.com>
Cc: Gianvito Pio <pio.gianvito@gmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Get a table name
Date: Tue, 29 Dec 2009 07:20:04 -0500 (EST)
Message-ID: <alpine.BSO.2.00.0912290703590.24198@leary.csoft.net> (raw)
In-Reply-To: <4B3809D7.9090407@opencloud.com>
References: <4B3737DA.4070408@gmail.com>
	<4B3809D7.9090407@opencloud.com>



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



view thread (8+ messages)

Message-ID: <alpine.BSO.2.00.0912290703590.24198@leary.csoft.net>
Permalink:  ../alpine.BSO.2.00.0912290703590.24198@leary.csoft.net/
Also on:    postgresql.org/message-id/alpine.BSO.2.00.0912290703590.24198@leary.csoft.net

 · 

reply

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: books@ejurka.com, oliver@opencloud.com, pio.gianvito@gmail.com
  Subject: Re: Get a table name
  In-Reply-To: <alpine.BSO.2.00.0912290703590.24198@leary.csoft.net>
  References: <4B3737DA.4070408@gmail.com> <4B3809D7.9090407@opencloud.com> <alpine.BSO.2.00.0912290703590.24198@leary.csoft.net>

* 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