Re: Wrong column names in ResultSetMetaData

From: Kris Jurka <books(at)ejurka(dot)com>
To: Mike Martin <mmartin(at)vieo(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Wrong column names in ResultSetMetaData
Date: 2004-07-29 03:20:46
Message-ID: Pine.BSO.4.56.0407282213330.155@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Wed, 28 Jul 2004, Mike Martin wrote:

> I wrote:
> > [new driver returns a column alias as the label, not name]
>
> I'm almost certain this is wrong from a JDBC standpoint.
>
> rsmd.getColumnName() is supposed to return the given name of
> the *result* column, which SQL has rules to define.
> rsmd.getColumnLabel() is "for use in printouts and displays"
> and will often equate to the column name unless the DBMS has
> some "prettier" column title for display purposes.
>
> For programmatic purposes the column name concept is pretty
> well defined by the docs on ResultSet. They're supposed to
> behave such that:
>
> String colname = rsmd.getColumnName(col);
> return rs.getXXX(colname);
>
> is equivalent to:
>
> return rs.getXXX(col);
>

I am not sure I see where it states that. Your logic makes some sense,
but I don't see anywhere it says the above explicity. The problem is how
to return both pieces of information (the alias and the underlying column
name) within the JDBC API. Certainly the alias makes more sense as the
label when you have to pick between the two of them.

Would you expect the results of getTableName() to return the underlying
table or the table's alias in the query? To be consistent with your
argument you'd have to claim the alias name which is useless here.

Further code doesn't make a whole lot of sense doing:

rs.getString(rsmd.getColumnName(1));

Why wouldn't it just do:

rs.getString(1);

Kris Jurka

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2004-07-29 03:23:29 Re: SSL Connection Problems
Previous Message Mike Martin 2004-07-29 01:24:00 Re: Wrong column names in ResultSetMetaData