pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Bug in org.postgresql.jdbc2.AbstractJdbc2ResultSet?
4+ messages / 4 participants
[nested] [flat]

* Bug in org.postgresql.jdbc2.AbstractJdbc2ResultSet?
@ 2007-04-30 21:45  David Clark <davidclark@tx.rr.com>
  0 siblings, 1 reply; 4+ messages in thread

From: David Clark @ 2007-04-30 21:45 UTC (permalink / raw)
  To: pgsql-jdbc

There seems to be a bug in internalGetObject(int, Field) in 
org.postgresql.jdbc2.AbstractJdbc2ResultSet.  I am using the 
postgresql-jdbc-8.0-319.src sources.  I am placing the patch file inline 
below in case the mailing list does not accept attachments.  The bug (?) is 
that for TINYINT and SMALLINT columns a java.lang.Short should be returned 
from internalGetObject, but an Integer is returned instead.

Patch:

inline patch 1: AbstractJdbc2ResultSet.java.patched (+1/-0 lines) download inline-1.patch--- AbstractJdbc2ResultSet.java 2007-04-16 11:37:04.000000000 -0500 +++ AbstractJdbc2ResultSet.java.patched 2007-04-30 15:52:51.000000000 -0500 @@ -117,6 +117,7 @@ return getBoolean(columnIndex) ? Boolean.TRUE : Boolean.FALSE; case Types.TINYINT: case Types.SMALLINT: + return new Short(getShort(columnIndex)); case Types.INTEGER: return new Integer(getInt(columnIndex)); case Types.BIGINT:
David Clark ^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Bug in org.postgresql.jdbc2.AbstractJdbc2ResultSet?
@ 2007-04-30 22:34  Kris Jurka <books@ejurka.com>
  parent: David Clark <davidclark@tx.rr.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Kris Jurka @ 2007-04-30 22:34 UTC (permalink / raw)
  To: David Clark <davidclark@tx.rr.com>; +Cc: pgsql-jdbc



On Mon, 30 Apr 2007, David Clark wrote:

> There seems to be a bug in internalGetObject(int, Field) in
> org.postgresql.jdbc2.AbstractJdbc2ResultSet.  I am using the
> postgresql-jdbc-8.0-319.src sources.  I am placing the patch file inline
> below in case the mailing list does not accept attachments.  The bug (?) is
> that for TINYINT and SMALLINT columns a java.lang.Short should be returned
> from internalGetObject, but an Integer is returned instead.
>

Actually this behavior is correct according to the JDBC spec.  If you see 
Appendix B [1] it says:

Note - The JDBC 1.0 specification defined the Java object mapping for the 
SMALLINT and TINYINT JDBC types to be Integer.  The Java language did not 
include the Byte and Short data types when the JDBC 1.0 specification was 
finalized.  The mapping of SMALLINT and TINYINT to Integer is maintained 
to preserve backwards compatibility.

Kris Jurka

http://jcp.org/aboutJava/communityprocess/final/jsr221/index.html



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Bug in org.postgresql.jdbc2.AbstractJdbc2Array
@ 2007-07-05 15:05  Alessandro Di Bella <aldibella@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Alessandro Di Bella @ 2007-07-05 15:05 UTC (permalink / raw)
  To: pgsql-jdbc

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
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Bug in org.postgresql.jdbc2.AbstractJdbc2Array
@ 2007-07-05 17:47  Heikki Linnakangas <heikki@enterprisedb.com>
  parent: Alessandro Di Bella <aldibella@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Heikki Linnakangas @ 2007-07-05 17:47 UTC (permalink / raw)
  To: Alessandro Di Bella <aldibella@gmail.com>; +Cc: pgsql-jdbc

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2007-07-05 17:47 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-04-30 21:45 Bug in org.postgresql.jdbc2.AbstractJdbc2ResultSet? David Clark <davidclark@tx.rr.com>
2007-04-30 22:34 ` Kris Jurka <books@ejurka.com>
2007-07-05 15:05 Bug in org.postgresql.jdbc2.AbstractJdbc2Array Alessandro Di Bella <aldibella@gmail.com>
2007-07-05 17:47 ` Re: Bug in org.postgresql.jdbc2.AbstractJdbc2Array Heikki Linnakangas <heikki@enterprisedb.com>

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