pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Thomas Kellerer <spam_eater@gmx.net>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: getUdateCount() vs. RETURNING clause
Date: Thu, 26 Nov 2009 00:13:40 +1300
Message-ID: <4B0D1164.1060006@opencloud.com> (raw)
In-Reply-To: <heimgq$sdo$1@ger.gmane.org>
References: <hegh0m$j0f$1@ger.gmane.org>
	<4B0C7CFE.50106@opencloud.com>
	<heimgq$sdo$1@ger.gmane.org>

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



view thread (10+ messages)  latest in thread

Message-ID: <4B0D1164.1060006@opencloud.com>
Permalink:  ../4B0D1164.1060006@opencloud.com/
Also on:    postgresql.org/message-id/4B0D1164.1060006@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com, spam_eater@gmx.net
  Subject: Re: getUdateCount() vs. RETURNING clause
  In-Reply-To: <4B0D1164.1060006@opencloud.com>
  References: <hegh0m$j0f$1@ger.gmane.org> <4B0C7CFE.50106@opencloud.com> <heimgq$sdo$1@ger.gmane.org> <4B0D1164.1060006@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox