Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 555B2632FAB for ; Wed, 25 Nov 2009 08:16:39 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 73979-07 for ; Wed, 25 Nov 2009 12:16:04 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from tremor.opencloud.co.nz (tremor.opencloud.co.nz [131.203.101.230]) by mail.postgresql.org (Postfix) with ESMTP id 7F9D863299C for ; Wed, 25 Nov 2009 08:16:26 -0400 (AST) Received: from 222-154-85-191.jetstream.xtra.co.nz ([222.154.85.191] helo=[192.168.1.3]) by tremor.opencloud.co.nz with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NDGnF-0006UT-63; Thu, 26 Nov 2009 01:16:21 +1300 Message-ID: <4B0D2014.3060703@opencloud.com> Date: Thu, 26 Nov 2009 01:16:20 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Thomas Kellerer CC: pgsql-jdbc@postgresql.org Subject: Re: getUdateCount() vs. RETURNING clause References: <4B0C7CFE.50106@opencloud.com> <4B0D1164.1060006@opencloud.com> In-Reply-To: X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.855 tagged_above=-10 required=5 tests=AWL=-0.745, BAYES_05=-1.11 X-Spam-Level: X-Archive-Number: 200911/27 X-Sequence-Number: 20074 Thomas Kellerer wrote: > Oliver Jowett, 25.11.2009 12:13: >> >> You've done some selective editing there. The javadoc I referred to is >> this (from the Java 6 javadoc): >> >> getResultSet(): >> >> Retrieves the current result as a ResultSet object. This method should >> be called only once per result. > > Correct, once per *result* not per statement. If the statement returns > more than one result, I should be allowed to call it multiple time. That's right, but you need a call to getMoreResults() to step through the results between calls, as I suggested in my original response. > I think the base of my (mis)understanding is that the term "current" > lead me to believe that the "stack" of results a statement can hold, > could look like this: > > resultSet > update count = 3 > update count = 2 > resultSet > reslutSet Yes, you can have that. You step through the results by calling getMoreResults(). At any particular point, the current result is either a resultset or an update count, but never both. > So if I create a loop using the condition stated in the Javadocs the > program flow would be as follows: > > 1) stmt.execute() returns true, so I call getResultSet() > 2) getMoreResults() returns false, but getUpdateCount() returns 3 ==> go on > 3) getMoreResults() returns false, but getUpdateCount() returns 2 ==> go on > 4) getMoreResults() returns true, so getResultSet() returns a result set > ==> go on > 5) getMoreResults() returns true, so getResultSet() returns a result set > ==> go on > 6) getMoreResults() returns false, getUpdateCount() returns -1 ==> > everything was processed. Yes, this is correct. It will look something like this: boolean hasResultSet = stmt.execute(); int updateCount = stmt.getUpdateCount(); while (hasResultSet || updateCount != -1) { if (hasResultSet) { ResultSet rs = stmt.getResultSet(); // This result is a resultset, process rs. } else { // This result is an update count, process updateCount. } hasResultSet = stmt.getMoreResults(); updateCount = stmt.getUpdateCount(); } -O