Re: Wrong column names in ResultSetMetaData - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: Wrong column names in ResultSetMetaData
Date
Msg-id Pine.BSO.4.56.0407282213330.155@leary.csoft.net
Whole thread Raw
In response to Re: Wrong column names in ResultSetMetaData  ("Mike Martin" <mmartin@vieo.com>)
List 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


pgsql-jdbc by date:

Previous
From: "Mike Martin"
Date:
Subject: Wrong column names in ResultSetMetaData
Next
From: Kris Jurka
Date:
Subject: Re: SSL Connection Problems