Re: IN clauses via setObject(Collection) [Was: Re: Prepared - Mailing list pgsql-jdbc

From Fernando Nasser
Subject Re: IN clauses via setObject(Collection) [Was: Re: Prepared
Date
Msg-id 3F1C282D.6040702@redhat.com
Whole thread Raw
In response to Re: Prepared Statements  (Dmitry Tkach <dmitry@openratings.com>)
Responses Re: IN clauses via setObject(Collection) [Was: Re: Prepared  (Dmitry Tkach <dmitry@openratings.com>)
Re: IN clauses via setObject(Collection) [Was: Re: Prepared Statements]  (Oliver Jowett <oliver@opencloud.com>)
Re: IN clauses via setObject(Collection) [Was: Re: Prepared  (Paul Thomas <paul@tmsl.demon.co.uk>)
List pgsql-jdbc
Oliver Jowett wrote:> On Tue, Jul 22, 2003 at 03:47:49AM +1200, Oliver Jowett wrote:
>
>>On Mon, Jul 21, 2003 at 11:26:11AM -0400, Fernando Nasser wrote:
>>
>>
>>>I think Dima is arguing that Collection could be treated as an special case
>>>where it indicates a list of something instead of a single something.
>>>
>>>So, we would iterate through this Collection using its iterator and, for
>>>each Object obtained, act like a setObject has been used with that Object
>>>and the JAVA TYPE as an argument.
>>>
>>>The Types.OTHER is used for database specific SQL types or for Dynamic Data
>>>Access support.  As the Collection class is not a data type there is no
>>>chance of confusion.
>>
>>Ya, I understand. My main objection is that setObject(n, object,
>>Types.INTEGER), in all other cases, means "interpret object as an integer,
>>or fail if it can't be cast in that way".
>
>
> Also.. what would we do with this object?
>
> public class AnnoyingObject implements java.util.Collection, java.sql.Array {
>   // ...
> }
>
> then setObject(n, new AnnoyingObject(), Types.ARRAY);
>
> Is that an Array, or an IN clause of Arrays? :)
>
> (Array is the obvious candidate for also being a Collection, but potentially
> you could do it with other types too)
>

I am not sure if this is an useful or usual Java class at all, but if you want
to pass a list of this AnnoyingObject you can always create a Collection of such
objects (like an ArrayList).

With setObject, if the specified type is Array and the passed type is an Array
of some sort we have to honor that.  So, in the obscure case where someone wants
to set a list of Arrays they will have to add the Arrays to a Collection (that
is not an Array itself).

But you are right, to my pseudo code we do have to check the Array to ARRAY case
before assuming that the list is what the programmer wants.

Also, we may limit this behavior with Collections to the IN clause only.  Where
else could we need lists to replace the '?' ?

--
Fernando Nasser
Red Hat - Toronto                       E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9


pgsql-jdbc by date:

Previous
From: "David Wall"
Date:
Subject: Detecting 'socket errors' - closing the Connection object
Next
From: Dmitry Tkach
Date:
Subject: Re: Detecting 'socket errors' - closing the Connection object