Thread: BigDecimal Bugs
Hi, I've found 2 bugs related with BigDecimal in the JDBC driver. The first bug occurs when you call Array.toArray on a column containing an array of NUMERIC. The returned java array is wrong with all BigDecimal stored in the first element. The second bug is in PreparedStatement.setBigDecimal. If you pass a null object as argument, the method raises a NullPointerException. Attached are the 2 diff files to correct those bugs. Kudos to all postgresql developers for their great job! Florian
Attachment
Florian, Can you resubmit these patches as context diff's ? cvs -c diff ... Thanks, Dave > -----Original Message----- > From: pgsql-jdbc-owner@postgresql.org > [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of > mailing-list@urbanet.ch > Sent: Sunday, March 24, 2002 11:02 AM > To: pgsql-jdbc@postgresql.org > Subject: [JDBC] BigDecimal Bugs > > > Hi, > > I've found 2 bugs related with BigDecimal in the JDBC driver. > > The first bug occurs when you call Array.toArray on a column > containing an > array of NUMERIC. The returned java array is wrong with all > BigDecimal > stored in the first element. > > The second bug is in PreparedStatement.setBigDecimal. If you > pass a null > object as argument, the method raises a NullPointerException. > > Attached are the 2 diff files to correct those bugs. > > Kudos to all postgresql developers for their great job! > > Florian >
Sure! Here it is. Index: Array.java =================================================================== RCS file: /projects/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java,v retrieving revision 1.9 diff -c -r1.9 Array.java *** Array.java 2002/03/05 03:46:03 1.9 --- Array.java 2002/03/25 20:41:19 *************** *** 140,146 **** case Types.NUMERIC: retVal = new BigDecimal[ count ]; for ( ; count > 0; count-- ) ! ((BigDecimal[])retVal)[i] = ResultSet.toBigDecimal( arrayContents[(int)index++],0 ); break; case Types.REAL: retVal = new float[ count ]; --- 140,146 ---- case Types.NUMERIC: retVal = new BigDecimal[ count ]; for ( ; count > 0; count-- ) ! ((BigDecimal[])retVal)[i++] = ResultSet.toBigDecimal( arrayContents[(int)index++],0 ); break; case Types.REAL: retVal = new float[ count ]; Index: PreparedStatement.java =================================================================== RCS file: /projects/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java,v retrieving revision 1.24 diff -c -r1.24 PreparedStatement.java *** PreparedStatement.java 2002/01/15 07:37:33 1.24 --- PreparedStatement.java 2002/03/25 20:41:20 *************** *** 251,257 **** */ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { ! set(parameterIndex, x.toString()); } /* --- 251,260 ---- */ public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { ! if (x == null) ! setNull(parameterIndex, Types.OTHER); ! else ! set(parameterIndex, x.toString()); } /* On Monday 25 March 2002 02:50, Dave Cramer wrote: > Florian, > > Can you resubmit these patches as context diff's ? > > cvs -c diff ... > > Thanks, > > Dave > > > -----Original Message----- > > From: pgsql-jdbc-owner@postgresql.org > > [mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of > > mailing-list@urbanet.ch > > Sent: Sunday, March 24, 2002 11:02 AM > > To: pgsql-jdbc@postgresql.org > > Subject: [JDBC] BigDecimal Bugs > > > > > > Hi, > > > > I've found 2 bugs related with BigDecimal in the JDBC driver. > > > > The first bug occurs when you call Array.toArray on a column > > containing an > > array of NUMERIC. The returned java array is wrong with all > > BigDecimal > > stored in the first element. > > > > The second bug is in PreparedStatement.setBigDecimal. If you > > pass a null > > object as argument, the method raises a NullPointerException. > > > > Attached are the 2 diff files to correct those bugs. > > > > Kudos to all postgresql developers for their great job! > > > > Florian
Patch applied. (also fixed jdbc1/PreparedStatement.java) thanks, --Barry mailing-list@urbanet.ch wrote: > Sure! Here it is. > > Index: Array.java > =================================================================== > RCS file: /projects/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Array.java,v > retrieving revision 1.9 > diff -c -r1.9 Array.java > *** Array.java 2002/03/05 03:46:03 1.9 > --- Array.java 2002/03/25 20:41:19 > *************** > *** 140,146 **** > case Types.NUMERIC: > retVal = new BigDecimal[ count ]; > for ( ; count > 0; count-- ) > ! ((BigDecimal[])retVal)[i] = ResultSet.toBigDecimal( arrayContents[(int)index++],0 ); > break; > case Types.REAL: > retVal = new float[ count ]; > --- 140,146 ---- > case Types.NUMERIC: > retVal = new BigDecimal[ count ]; > for ( ; count > 0; count-- ) > ! ((BigDecimal[])retVal)[i++] = ResultSet.toBigDecimal( arrayContents[(int)index++],0 ); > break; > case Types.REAL: > retVal = new float[ count ]; > Index: PreparedStatement.java > =================================================================== > RCS file: /projects/cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/PreparedStatement.java,v > retrieving revision 1.24 > diff -c -r1.24 PreparedStatement.java > *** PreparedStatement.java 2002/01/15 07:37:33 1.24 > --- PreparedStatement.java 2002/03/25 20:41:20 > *************** > *** 251,257 **** > */ > public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException > { > ! set(parameterIndex, x.toString()); > } > > /* > --- 251,260 ---- > */ > public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException > { > ! if (x == null) > ! setNull(parameterIndex, Types.OTHER); > ! else > ! set(parameterIndex, x.toString()); > } > > /* > > > On Monday 25 March 2002 02:50, Dave Cramer wrote: > >>Florian, >> >>Can you resubmit these patches as context diff's ? >> >>cvs -c diff ... >> >>Thanks, >> >>Dave >> >> >>>-----Original Message----- >>>From: pgsql-jdbc-owner@postgresql.org >>>[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of >>>mailing-list@urbanet.ch >>>Sent: Sunday, March 24, 2002 11:02 AM >>>To: pgsql-jdbc@postgresql.org >>>Subject: [JDBC] BigDecimal Bugs >>> >>> >>>Hi, >>> >>>I've found 2 bugs related with BigDecimal in the JDBC driver. >>> >>>The first bug occurs when you call Array.toArray on a column >>>containing an >>>array of NUMERIC. The returned java array is wrong with all >>>BigDecimal >>>stored in the first element. >>> >>>The second bug is in PreparedStatement.setBigDecimal. If you >>>pass a null >>>object as argument, the method raises a NullPointerException. >>> >>>Attached are the 2 diff files to correct those bugs. >>> >>>Kudos to all postgresql developers for their great job! >>> >>>Florian >> > > ---------------------------(end of broadcast)--------------------------- > TIP 5: Have you checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html >