pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Kris Jurka <books@ejurka.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: patch: streaming of bytea parameter values
Date: Sun, 23 May 2004 12:25:24 +1200
Message-ID: <40AFEF74.6080904@opencloud.com> (raw)
In-Reply-To: <Pine.BSO.4.56.0405221233190.20327@leary.csoft.net>
References: <4085F25A.8060009@opencloud.com>
	<Pine.BSO.4.56.0405220222030.20695@leary.csoft.net>
	<40AF1DDE.90206@opencloud.com>
	<Pine.BSO.4.56.0405221233190.20327@leary.csoft.net>

Kris Jurka wrote:
> 
> On Sat, 22 May 2004, Oliver Jowett wrote:

>>My V3 patches handle these cases by closing the connection entirely & 
>>throwing an exception (i.e. providing a short stream or throwing 
>>IOException is a fatal error). This seemed better than silently padding 
>>with bogus data.
>>
>>I don't see that either case is a "normal" case we should be supporting 
>>-- we just need to be sure we clean up properly.
>>
> 
> 
> I don't consider abandoning the connection "cleaning up properly."

I don't see what isn't cleaned up by closing the connection. It seems 
the simplest and safest way of handling this sort of error.

> With
> the V3 protocol we have a reasonable recovery method because we will
> detect this error at Bind time and simply not issue the Execute.  In the
> current code's case it seems the only way to do it is to deliberately
> introduce a syntax error to make the query fail.

We'd have to insert an artificial syntax error (another Parse after the 
Bind that failed) anyway to force transaction rollback.

I'm reluctant to allow the txn to continue as a) it's inconsistent with 
how other errors are handled and b) the distinction between Bind and 
Execute is a bit fuzzy. There is some portal setup work run on Bind, and 
I'm not sure if we can assume that a Bind immediately followed by a 
ClosePortal does not modify the DB in any way.

Really, this is an *application error*, so I'm happy with anything that 
preserves data integrity in the DB, even if it toasts the application's 
current connection. If the application doesn't want this behaviour, it 
shouldn't give the driver bad streams!

> Another issue that just came to me is what is the desired behavior for
> 
> ByteArrayInputStream bais = new ByteArrayInputStream(new byte[1000]));
> PreparedStatement ps = conn.prepareStatement("INSERT INTO t VALUES (?)");
> ps.setBinaryStream(1, bais, 100);
> ps.execute();
> ps.execute();
> ps.execute();
> 
> Should each inserted row have the same values?  Should the second row get 
> the second 100 bytes and the third row get the third 100?

I'm sure that there is something somewhere in the spec that says that 
the client has to keep the stream in an appropriate state until 
execution (but now I can't find it anywhere!). So I'd expect in this 
case to get bytes 0-99, 100-199, 200-299 inserted into the three rows 
respectively.

More fun is what happens if you do the above with addBatch() / 
executeBatch(); should that be equivalent to treating addBatch() as a 
"query execution"? What if we want to delay reading the data until the 
real batch execution?

-O



view thread (15+ messages)  latest in thread

Message-ID: <40AFEF74.6080904@opencloud.com>
Permalink:  ../40AFEF74.6080904@opencloud.com/
Also on:    postgresql.org/message-id/40AFEF74.6080904@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, books@ejurka.com
  Subject: Re: patch: streaming of bytea parameter values
  In-Reply-To: <40AFEF74.6080904@opencloud.com>
  References: <4085F25A.8060009@opencloud.com> <Pine.BSO.4.56.0405220222030.20695@leary.csoft.net> <40AF1DDE.90206@opencloud.com> <Pine.BSO.4.56.0405221233190.20327@leary.csoft.net> <40AFEF74.6080904@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