Re: Prepared Statements

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Dmitry Tkach <dmitry(at)openratings(dot)com>
Cc: Kim Ho <kho(at)redhat(dot)com>, Fernando Nasser <fnasser(at)redhat(dot)com>, Barry Lind <blind(at)xythos(dot)com>, pgsql-jdbc-list <pgsql-jdbc(at)postgresql(dot)org>, Dave Cramer <Dave(at)micro-automation(dot)net>
Subject: Re: Prepared Statements
Date: 2003-07-19 01:25:55
Message-ID: 20030719012555.GA20158@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Fri, Jul 18, 2003 at 02:22:24PM -0400, Dmitry Tkach wrote:

> What I am concerned about is the "in" thing -
>
> select * from sometable where x in ?;
> setObject (1, "(1,2,3,4,5)");
>
> that works just fine right now, and will be irreperably broken by this
> patch...

How about:

+ create an org.postgresql.InSet class that wraps an Object[] array and java.sql.Types value
+ use setObject(N, new InSet(myArray, Types.INTEGER));

The Javadoc for PreparedStatement.setObject() says:

Note that this method may be used to pass datatabase- specific abstract data
types, by using a driver-specific Java type.

so presumably this is the right way to do it. setObject() would handle an
InSet by individually escaping the components of the array it wraps as if
they had been passed to setObject() and turning them into an IN-like clause.

For arrays we just need to fix setArray() so that it does the same sort of
thing as described above, using the java.sql.Array methods to get the
component objects. And maybe provide a simple implementation of Array that
wraps a Java array (users can always provide their own, anyway).

Any thoughts? I can try to sort out patches, but I'm a bit short on time
right now so no promises.

-O

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2003-07-19 06:06:24 Re: Prepared Statements
Previous Message Fernando Nasser 2003-07-19 00:47:18 Re: Prepared Statements