Re: Accepting Object[] as an acceptable input to setObject with Types.ARRAY?

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Steven Schlansker <stevenschlansker(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Accepting Object[] as an acceptable input to setObject with Types.ARRAY?
Date: 2011-06-04 02:58:38
Message-ID: BANLkTin9UDRNKV8Pfp_T4x5kqxBcPBKL_Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 4 June 2011 10:42, Steven Schlansker <stevenschlansker(at)gmail(dot)com> wrote:

> +    private String determineSQLType(Object[] array) {
> +        Class<?> componentType = array.getClass().getComponentType();
> +        if (componentType.equals(byte.class) || componentType.equals(Byte.class))
> +            return "tinyint";

Note that the test vs. byte, int, etc will never fire, because arrays
of primitive types are not instanceof Object[]

Can we do anything better when given, say, an Object[] (not Integer[])
that contains only Integer instances?
Not sure if you can do anything sensible here, since an Object[] could
also contain a heterogeneous mix of types.

There seems to be some duplication between determineSQLType() and the
switch in setObject().

Oliver

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Michal Politowski 2011-06-06 08:13:23 Re: [GENERAL] Mixed up protocol packets in server response?
Previous Message Steven Schlansker 2011-06-03 23:05:45 Re: Accepting Object[] as an acceptable input to setObject with Types.ARRAY?