Subject Re: [Firebird-Architect] Update WHERE CURRENT OF vs. ResultSet.isLast()
Author Jim Starkey
Roman Rokytskyy wrote:

>Hi All,
>
>I've got a request about implementing Statement.setCursorName(String)
>and using positioned updates. While implementing this stuff I
>discovered that with positioned updates we cannot have
>ResultSet.isLast() working.
>
>Reason for this is that server does not tell us anything whether we
>fetched the last record or not. This happens only during additional
>fetch() (we get reply "sorry, no more records"). Till now we
>prefetched one record, but this moves cursor position too. So, when
>using positioned update we would update next records, not current.
>Fixing this prefetching breaks ResultSet.isLast().
>
>Usually people use while(rs.next()) {...} construct, so broken
>rs.isLast() would not affect them. However if you use do {rs.next()}
>while(!rs.isLast()), you will get endless loop.
>
>So, the question now is: what do you prefer - positioned updates or
>correct work of ResultSet.isLast()? Should I create a poll in the group?
>
Roman, this isn't at all the wrong group. You have raised a difficult
architectural
problem. The JDBC 2.0 spec requires the method ResultSet.isLast(), which is
essentially unimplementable in Firebird. It could, in theory, be
implemented with
a layer that prefetched the next record then emulated positional updates
with a
refetch by dbkey, but this would require analyzing and rewriting all
"select" statement,
which is expensive in both code and cycles. Alternatively the engine
could be modified,
but not without a significant extension to BLR.

I'm inclinded to blame the JDBC guys, but that's pointless since the
deed is done.

I'm not going to presume to offer advice on how Firebird should handle
the problem.
Netfrastructure, however, handles the ResultSet.isLast() method in
approximately
to following manner:

throw new SQLException ("Not Yet Implemented")

A more complete implementation would be:

throw new SQLException ("Not Yet Implemented and Unlikely to
be Be So")

My reasoning is that positional updates have been part of SQL from day 0
and are
semantically significant while ResultSet.isLast() is recent,
semantically unnecessary,
and absurdly expensive to implement.