Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4470E632750 for ; Wed, 25 Nov 2009 07:13:56 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 57593-10 for ; Wed, 25 Nov 2009 11:13:48 +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 6D70663251B for ; Wed, 25 Nov 2009 07:13:48 -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 1NDFoc-00061Q-B1; Thu, 26 Nov 2009 00:13:42 +1300 Message-ID: <4B0D1164.1060006@opencloud.com> Date: Thu, 26 Nov 2009 00:13:40 +1300 From: Oliver Jowett User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: Thomas Kellerer CC: pgsql-jdbc@postgresql.org Subject: Re: getUdateCount() vs. RETURNING clause References: <4B0C7CFE.50106@opencloud.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200911/25 X-Sequence-Number: 20072 Thomas Kellerer wrote: > Hmm, my understand was a bit different. > The Javadocs simply say > > There are no more results when the following is true: > ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1)) > > It doesn't state that they are mutually exclusive. And for me it seemed > to imply that I can call getMoreResults() and getUpdateCount() in a loop > in order to process everything that is returned. > > Additionally the Javadocs for getUpdateCount() says: > > "Gets the *current* result as an update count" and ".. if there are no > more results it returns -1" 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. Returns: the current result as a ResultSet object or null if the result is an update count or there are no more results --- getUpdateCount(): Retrieves the current result as an update count; if the result is a ResultSet object or there are no more results, -1 is returned. This method should be called only once per result. Returns: the current result as an update count; -1 if the current result is a ResultSet object or there are no more results --- I think that's fairly clear: the "current result" is either a ResultSet, or an update count, but it can't be both. getUpdateCount() explicitly says that it returns "-1 [...] if the current result is a ResultSet object", and getResultSet() explicitly says that it returns "null if the [current] result is an update count." > The word "current" here also let me to believe I can call those methods > multiple times. From memory the postgresql driver doesn't care if you call them multiple times, but FWIW the javadoc says that you should only call them once per result. -O