Re: [JDBC] JDBC: 2 bugs: Getting a smallint array actually gets an integer array and return type of a boolean array is bit.

From: dmp <danap(at)ttc-cmc(dot)net>
To: Saneesh Apte <san(at)calccit(dot)org>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: [JDBC] JDBC: 2 bugs: Getting a smallint array actually gets an integer array and return type of a boolean array is bit.
Date: 2010-06-29 19:03:26
Message-ID: 4C2A437E.80103@ttc-cmc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-jdbc

> Hi,
>
> I think I found two bugs (and I hope I am not wasting everyone's
> time).
> One is minor: the base type of a boolean[] is java.sql.Types.BIT
> instead or java.sql.Types.BOOLEAN. At the very least shouldn't these
> be aliases for the same type?
>
> And secondly the returned type from a smallint[] is an Integer[]
> instead of a Short[].
>
>
>
> So running this code:

The running of the supplied code also gives the same results with
PostgreSQL 8.3.3

results:
========================================
sun(dot)jdbc(dot)odbc(dot)JdbcOdbcDriver(at)fc9944: 2.1
org(dot)postgresql(dot)Driver(at)8b819f: 8.4
PostgreSQL 8.3.3 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.6
Integer[]
1 2
int4: 4 4
END Integer[]
Boolean[]
false true
bool: 16 -7 -7
END Boolean[]
Short[]
java.lang.ClassCastException: [Ljava.lang.Integer; cannot be cast to
[Ljava.lang.Short;
========================================

The 8.4 JDBC Driver though does gives a consistent result as past
versions via the
tableMetaData.getColumnClassName() & tableMetaData.getColumnTypeName()
for the base types, integer, smallint, and boolean.

System.out.println(i + " " + colNameString + " " +
columnClass + " " + columnType + " " +
columnSize);

3 int_type java.lang.Integer int4 11
2 smallint_type java.lang.Integer int2 6
21 boolean_type java.lang.Boolean bool 1

1 ia java.sql.Array _int4 11
2 sa java.sql.Array _int2 6
3 ba java.sql.Array _bool 1

Attached slight modification to NewClass to correctly compile and drop
table if run
more than once.

danap.

Attachment Content-Type Size
NewClass2.java text/plain 3.3 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Baegle 2010-06-29 19:48:07 BUG #5530: Default cost of crypt causes poor decisions
Previous Message Marcel Asio 2010-06-29 19:00:21 Re: Function works in 8.4 but not in 9.0 beta2 "ERROR: structure of query does not match function result type"

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2010-06-30 01:10:33 Re: [JDBC] JDBC: 2 bugs: Getting a smallint array actually gets an integer array and return type of a boolean array is bit.
Previous Message Kevin Grittner 2010-06-29 18:16:44 Re: Source code for postgress 7.4?