Bug in org.postgresql.jdbc2.AbstractJdbc2Array
Bug in org.postgresql.jdbc2.AbstractJdbc2Array
От:
Alessandro Di Bella <aldibella@gmail.com>
Дата:
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
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
Re: Bug in org.postgresql.jdbc2.AbstractJdbc2Array
От:
Heikki Linnakangas <heikki@enterprisedb.com>
Дата:
Alessandro Di Bella wrote: > 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! There's a little problem with the patch; it will transform a text column with the string "NULL" to a null. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com