Subject Re: getXXX(colname) doesn't work with calculated columns and aliases
--- In IB-Java@y..., Dietrich Schulten <ibo@s...> wrote:
> Hi,
> > In my opinion it would to silly to be able to refer to calculated
> > function fields by name if you have not given them a name.
> What about an application that takes user defined queries and shows
> result to the user? It is at least no friendly behavior to skip
> calculated columns in the display as long as the user doesn't give
> an alias. Using an expression without alias is perfectly legal.

I did not say skip calculated columns. Sure, the user can choose to
use labels or not but she knows SQL and decides what she wants. The
application designer displays the result using getObject(index) and
the labels using getColumnLabel(index). The results appear in the
right order. If there is no label for a value, the label is blank.
The use of getXXXX(name) serves no purpose in these circumstances
because the app designer does not know the queries in advance.

> > As for
> > user-defined labels it should be simple enough to implement this
> > feature.
> > For now, you can do something like:
> > PreparedStatement ps = ....;
> > ResultSet rs = ps.executeQuery();
> > int count = rs.getMetaData().getColumnCount();
> > Map hm = new HashMap ();
> > for ( int i = 1; i <= count ; i++ )
> > hm.put(rs.getMetaData().getColumnLabel(i), new Integer(i));
> > // Later you can:
> > int index = ((Integer) hm.get(label)).intValue();
> > Object object = rs.getObject(i);
> I'm not sure whether you are talking about the driver or about an
> application that uses the driver. In a java application this would
> to specialize on Interclient's behavior that getXXX(colname)
> always work. Who guarantees that the next driver will work with
> numbers?

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.

> As to ambiguous column names, that is a good point. A JDBC driver
> guarantee that findColumn(colname) always works, therefore it
should try
> to make column names unique by adding the table name.

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.

> I'd say, this is an implicit requirement of the JDBC API. I'm not
sure if
> it isn't thought out well, after all it is about standardized data
> retrieval. If Interbase has special ways, the driver must try to
> that. At least that's what I think at the moment. Any Interbase
> driver should try to do it that way, otherwise it will hamper the
use of
> Interbase, compared with other databases that always work with
> getXXX(colname).

JDBC is about standardization to a degree. It does not attempt to
standardize many differences between databases. For instance,
interclient accepts and returns an Integer for SMALLINT fields
whereas some other JDBC drivers use a Short instead.

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

A lot of work has to be done on new and existing JDBC drivers. Look
at the sources and see if you can improve upon this one.