pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alessandro Di Bella <aldibella@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Bug in org.postgresql.jdbc2.AbstractJdbc2Array
Date: Thu, 05 Jul 2007 16:05:31 +0100
Message-ID: <468D08BB.701@google.com> (raw)

Hi,
I found a bug in the org.postgresql.jdbc2.AbstractJdbc2Array class that 
causes the following exception when an array contains a null value:

Caused by: org.postgresql.util.PSQLException: Bad value for type date : NULL
    at 
org.postgresql.jdbc2.TimestampUtils.loadCalendar(TimestampUtils.java:246)
    at org.postgresql.jdbc2.TimestampUtils.toDate(TimestampUtils.java:402)
    at 
org.postgresql.jdbc2.AbstractJdbc2Array.getArrayImpl(AbstractJdbc2Array.java:210)

I attached a patch that fixes the problem. If you are happy with it, 
please merge it with the HEAD stream.


Thanks


Alessandro

Attachments:

pgjdbc-sqlarray-patch.patch (text/plain, 3.1K) download Index: org/postgresql/jdbc2/AbstractJdbc2Array.java =================================================================== RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Array.java,v retrieving revision 1.18 diff -u -p -r1.18 AbstractJdbc2Array.java --- org/postgresql/jdbc2/AbstractJdbc2Array.java 4 Dec 2005 21:40:33 -0000 1.18 +++ org/postgresql/jdbc2/AbstractJdbc2Array.java 5 Jul 2007 14:56:50 -0000 @@ -185,8 +185,10 @@ public class AbstractJdbc2Array break; case Types.NUMERIC: retVal = new BigDecimal[ count ]; - for ( ; count > 0; count-- ) - ((BigDecimal[])retVal)[i++] = AbstractJdbc2ResultSet.toBigDecimal( arrayContents[(int)index++], -1 ); + for ( ; count > 0; count-- ){ + String content = arrayContents[(int)index++]; + ((BigDecimal[])retVal)[i++] = ("NULL".equals(content)) ? null : AbstractJdbc2ResultSet.toBigDecimal( content, -1 ); + } break; case Types.REAL: retVal = new float[ count ]; @@ -201,23 +203,31 @@ public class AbstractJdbc2Array case Types.CHAR: case Types.VARCHAR: retVal = new String[ count ]; - for ( ; count > 0; count-- ) - ((String[])retVal)[i++] = arrayContents[(int)index++]; + for ( ; count > 0; count-- ){ + String content = arrayContents[(int)index++]; + ((String[])retVal)[i++] = ("NULL".equals(content)) ? null : content; + } break; case Types.DATE: retVal = new java.sql.Date[ count ]; - for ( ; count > 0; count-- ) - ((java.sql.Date[])retVal)[i++] = conn.getTimestampUtils().toDate(null, arrayContents[(int)index++] ); + for ( ; count > 0; count-- ){ + String content = arrayContents[(int)index++]; + ((java.sql.Date[])retVal)[i++] = ("NULL".equals(content)) ? null : conn.getTimestampUtils().toDate(null, content ); + } break; case Types.TIME: retVal = new java.sql.Time[ count ]; - for ( ; count > 0; count-- ) - ((java.sql.Time[])retVal)[i++] = conn.getTimestampUtils().toTime(null, arrayContents[(int)index++] ); + for ( ; count > 0; count-- ){ + String content = arrayContents[(int)index++]; + ((java.sql.Time[])retVal)[i++] = ("NULL".equals(content)) ? null : conn.getTimestampUtils().toTime(null, content ); + } break; case Types.TIMESTAMP: retVal = new Timestamp[ count ]; - for ( ; count > 0; count-- ) - ((java.sql.Timestamp[])retVal)[i++] = conn.getTimestampUtils().toTimestamp(null, arrayContents[(int)index++] ); + for ( ; count > 0; count-- ){ + String content = arrayContents[(int)index++]; + ((java.sql.Timestamp[])retVal)[i++] = ("NULL".equals(content)) ? null : conn.getTimestampUtils().toTimestamp(null, content ); + } break; // Other datatypes not currently supported. If you are really using other types ask

view thread (4+ messages)  latest in thread

Message-ID: <468D08BB.701@google.com>
Permalink:  ../468D08BB.701@google.com/
Also on:    postgresql.org/message-id/468D08BB.701@google.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: aldibella@gmail.com
  Subject: Re: Bug in org.postgresql.jdbc2.AbstractJdbc2Array
  In-Reply-To: <468D08BB.701@google.com>
  References: <468D08BB.701@google.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox