Re: Prepared Statements - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: Prepared Statements
Date
Msg-id 20030719012555.GA20158@opencloud.com
Whole thread Raw
In response to Re: Prepared Statements  (Dmitry Tkach <dmitry@openratings.com>)
Responses Re: Prepared Statements  (Aaron Mulder <ammulder@alumni.princeton.edu>)
Re: Prepared Statements  (Dima Tkach <dmitry@openratings.com>)
List 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

pgsql-jdbc by date:

Previous
From: Fernando Nasser
Date:
Subject: Re: Prepared Statements
Next
From: Aaron Mulder
Date:
Subject: Re: Prepared Statements