Subject Re: getXXX(colname) doesn't work with calculated columns and aliases
Author ft@cluedup.com
--- In IB-Java@y..., Dietrich Schulten <ibo@s...> wrote:
> Hi Fred,
>
>
> ft@c... schrieb:
>
> > The above will work with any JDBC complient driver. If a driver
does
> > not return all the ResultSet values with getXXXX(index), it
> > is not JDBC complient.
>
> Well, then Interclient isn't JDBC compliant, for the same holds
true for
> getXXX(name). I wouldn't go as far as calling a driver non-
compliant
> because of such a problem.
>

Interclient is JDBC complient. The same does not hold for getXXX
(name). A driver that does not support getXXX(index) is non-complient
because this is the primary means of retrieving ResultSet values.

There is a fundamental difference between getXXX(index) and
getXXX(name). Any result set has a finite set of columns numbered
from 1 onwards. Each of these columns can hold a value or null. Thus
getObject(index) is always unambiguous in what it refers to and must
return the appropriate result. A column may or may not have a label
or name. getXXX(name) should work only if there is a name or label
for the column and it can be ambiguous in what it refers to.


> > > A JDBC driver must guarantee that findColumn(colname) always
works
>
> > Depends what "colname" is. If it's the name of the column in the
> > table, it must. If it's a user-defined column I agree that it
should
> > (interclient doesn't and could be improved though I'm not sure it
is
> > required by the JDBC spec). Certainly, the driver should not add
> > anything to the method arguments. Whether it should
> > interpret "colname" values in the "tablename.label" format
instead of
> > returning a null depends on whether this is allowed by the spec
and
> > if (and how) other JDBC implementations use it.
>
> For getXXX(colname) it would be the only way, at least I see no
other.

Actually I've now got the answer to the "tablename.label" hypothesis
and it is NO.

Paragraph below is quoted varbatim from Java Docs for
java.sql.ResultSet:

Column names used as input to getXXX methods are case insensitive.
When a getXXX method is called with a column name and several columns
have the same name, the value of the first matching column will be
returned. The column name option is designed to be used when column
names are used in the SQL query that generated the result set. For
columns that are NOT explicitly named in the query, it is best to use
column numbers. If column names are used, there is no way for the
programmer to guarantee that they actually refer to the intended
columns.


> > It's a good idea to follow the crowd, so to speak, to make the
> > product useful to more people. However, inventing column labels
where
> > there was none is not part of JDBC or SQL and cannot serve a
useful
> > purpose.
>
> So would you be against something like column4 as column name seen
from
> the outside, while the JDBC Driver maps this to ordinal numbers
> internally?

Absolutely, if "column4" is not a column name in the table or a label
provided in the query. This is the third post in which I've said the
same thing and that's just about enough.


Fred