cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Torsten Curdt <tcu...@dff.st>
Subject Re: esql v1.22 multiple returned update counts and ResultSets
Date Fri, 17 May 2002 08:01:49 GMT
On Friday 17 May 2002 03:48, neil wrote:
> Hi,
> it seems that a few cocoon users like me, are hacking about with esql to
> get it to do what we need. I'm working on the change shown below and am
> happy to share it if anyone wants it.
>
> JDBC can handle a sequence of values returned from a stored procedure,
> where the values can be update counts and ResultSets in any order. It looks
> to me like esql v1.22 will only handle a sequence with all the ResultSets
> before the first update count and at most one update count. e.g.
> ResultSet*updateCount? (where * and ? are as in a RE).
>
> MS SqlServer stored procs return an update count for every
> insert/update/delete performed and a ResultSet for every query (whose
> results aren't consumed in the procedure) in the order that they are
> performed. So its important to handle update counts and ResultSets in any
> order.

Let's assume you expect:

resultset
update count
resultset
update count

How do you iterate through the update counts? AFAIK the JDBC API provides only 
information about the update count in the Statement. This is why current esql 
is like it is.

> int resultCount = 0;
> for ( boolean nextResultIsResultSet = cs.execute(); true;
> nextResultIsResultSet = cs.getMoreResults() ) {
>     if (nextResultIsResultSet) {
> 	java.sql.ResultSet rs = cs.getResultSet();
> 	++resultCount;
> 	// handle ResultSet
> 	rs.close();
>     } else {
> 	// either the next result is an update count or there are no more results
> 	int updateCount = cs.getUpdateCount();
> 	if ( updateCount == -1 ) {
> 	    break; // no more results
> 	    // only finished when cs.getMoreResults() == false &&
> cs.getUpdateCount() == -1
> 	    // awful bit of API but it works
> 	}
> 	++resultCount;
> 	// handle updateCount
>     }
>     // there may still be more ResultSets and/or update counts
> }
> if (resultCount == 0) {
>     // no returned results
> }

note that you are always calling getUpdateCount on the same statement. will 
it's state be changed?!? That would be indeed a ugly behaviour...
--
Torsten

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail: <cocoon-users-help@xml.apache.org>


Mime
View raw message