pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Dave Cramer <pg@fastcrypt.com>
To: Oliver Jowett <oliver@opencloud.com>
Cc: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: Re: patch for getXXX methods
Date: Fri, 09 Jul 2004 19:47:29 -0400
Message-ID: <1089416849.1515.298.camel@localhost.localdomain> (raw )
In-Reply-To: <40EF1D5D.2050509@opencloud.com >
References: <1089407362.1508.292.camel@localhost.localdomain >
<40EF1D5D.2050509@opencloud.com >
Attached, with -cb this time
On Fri, 2004-07-09 at 18:34, Oliver Jowett wrote:
> Dave Cramer wrote:
> > this patch addresses the issue of using getXXX recommended and secondary
> > methods
> >
> > Please review and comment.
>
> There are lots of whitespace-only changes which makes it harder to see
> the real changes.
>
> -O
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>
>
>
> !DSPAM:40ef1f6e143178639810363!
>
>
--
Dave Cramer
519 939 0336
ICQ # 14675561
Attachments:
getxxx.patch (text/x-patch, 17.7K) download
Index: org/postgresql/test/jdbc2/ResultSetTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/ResultSetTest.java,v
retrieving revision 1.18
diff -c -b -r1.18 ResultSetTest.java
*** org/postgresql/test/jdbc2/ResultSetTest.java 29 Jun 2004 06:43:28 -0000 1.18
--- org/postgresql/test/jdbc2/ResultSetTest.java 9 Jul 2004 23:44:48 -0000
***************
*** 61,72 ****
stmt.executeUpdate("INSERT INTO testnumeric VALUES('0.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-1.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('1.2')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('99999.2')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('99999')");
- stmt.executeUpdate("INSERT INTO testnumeric VALUES('-2.5')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-99999.2')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-99999')");
stmt.close();
--- 61,90 ----
stmt.executeUpdate("INSERT INTO testnumeric VALUES('0.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-1.0')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('1.2')");
+ stmt.executeUpdate("INSERT INTO testnumeric VALUES('-2.5')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('99999.2')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('99999')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-99999.2')");
stmt.executeUpdate("INSERT INTO testnumeric VALUES('-99999')");
+ // Integer.MaxValue
+ stmt.execute("INSERT INTO testnumeric VALUES('2147483647')");
+
+ // Integer.MinValue
+ stmt.execute("INSERT INTO testnumeric VALUES('-2147483648')");
+
+ stmt.executeUpdate("INSERT INTO testnumeric VALUES('2147483648')");
+ stmt.executeUpdate("INSERT INTO testnumeric VALUES('-2147483649')");
+
+ // Long.MaxValue
+ stmt.executeUpdate("INSERT INTO testnumeric VALUES('9223372036854775807')");
+
+ // Long.MinValue
+ stmt.executeUpdate("INSERT INTO testnumeric VALUES('-9223372036854775808')");
+
+ stmt.executeUpdate("INSERT INTO testnumeric VALUES('9223372036854775808')");
+ stmt.executeUpdate("INSERT INTO testnumeric VALUES('-9223372036854775809')");
+
stmt.close();
***************
*** 225,241 ****
public void testgetByte() throws SQLException
{
! ResultSet rs = con.createStatement().executeQuery("select * from testnumeric");
boolean thrown = false;
assertTrue(rs.next());
! assertEquals(1,rs.getByte(1));
assertTrue(rs.next());
! assertEquals(0,rs.getByte(1));
assertTrue(rs.next());
! assertEquals(-1,rs.getByte(1));
while (rs.next())
{
--- 243,266 ----
public void testgetByte() throws SQLException
{
! ResultSet rs = con.createStatement().executeQuery(
! "select * from testnumeric");
boolean thrown = false;
assertTrue(rs.next());
! assertEquals(1, rs.getByte(1));
!
! assertTrue(rs.next());
! assertEquals(0, rs.getByte(1));
assertTrue(rs.next());
! assertEquals( -1, rs.getByte(1));
assertTrue(rs.next());
! assertEquals(1, rs.getByte(1));
!
! assertTrue(rs.next());
! assertEquals(-2, rs.getByte(1));
while (rs.next())
{
***************
*** 251,271 ****
if (!thrown)
fail("Exception expected.");
}
}
public void testgetShort() throws SQLException
{
! ResultSet rs = con.createStatement().executeQuery("select * from testnumeric");
boolean thrown = false;
assertTrue(rs.next());
! assertEquals(1,rs.getShort(1));
assertTrue(rs.next());
! assertEquals(0,rs.getShort(1));
assertTrue(rs.next());
! assertEquals(-1,rs.getShort(1));
while (rs.next())
{
--- 276,304 ----
if (!thrown)
fail("Exception expected.");
}
+ rs.close();
}
public void testgetShort() throws SQLException
{
! ResultSet rs = con.createStatement().executeQuery(
! "select * from testnumeric");
boolean thrown = false;
assertTrue(rs.next());
! assertEquals(1, rs.getShort(1));
assertTrue(rs.next());
! assertEquals(0, rs.getShort(1));
assertTrue(rs.next());
! assertEquals( -1, rs.getShort(1));
!
! assertTrue(rs.next());
! assertEquals(1, rs.getShort(1));
!
! assertTrue(rs.next());
! assertEquals(-2, rs.getShort(1));
while (rs.next())
{
***************
*** 281,286 ****
--- 314,444 ----
if (!thrown)
fail("Exception expected.");
}
+ rs.close();
+ }
+
+ public void testgetInt() throws SQLException
+ {
+ ResultSet rs = con.createStatement().executeQuery(
+ "select * from testnumeric");
+ boolean thrown = false;
+
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals(0, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals( -1, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals( -2, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals(99999, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals(99999, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals(-99999, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals(-99999, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals(Integer.MAX_VALUE, rs.getInt(1));
+
+ assertTrue(rs.next());
+ assertEquals(Integer.MIN_VALUE, rs.getInt(1));
+
+ while (rs.next())
+ {
+ thrown = false;
+ try
+ {
+ rs.getInt(1);
+ }
+ catch (Exception e)
+ {
+ thrown = true;
+ }
+ if (!thrown)
+ fail("Exception expected." + rs.getString(1));
+ }
+ rs.close();
+ }
+
+ public void testgetLong() throws SQLException
+ {
+ ResultSet rs = con.createStatement().executeQuery(
+ "select * from testnumeric");
+ boolean thrown = false;
+
+ assertTrue(rs.next());
+ assertEquals(1, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals(0, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals( -1, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals(1, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals( -2, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals(99999, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals(99999, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals(-99999, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals(-99999, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals( ((long)Integer.MAX_VALUE), rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals( ((long)Integer.MIN_VALUE), rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals( ((long)Integer.MAX_VALUE)+1, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals( ((long)Integer.MIN_VALUE)-1, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals( Long.MAX_VALUE, rs.getLong(1));
+
+ assertTrue(rs.next());
+ assertEquals( Long.MIN_VALUE, rs.getLong(1));
+
+ while (rs.next())
+ {
+ thrown = false;
+ try
+ {
+ rs.getLong(1);
+ }
+ catch (Exception e)
+ {
+ thrown = true;
+ }
+ if (!thrown)
+ fail("Exception expected." + rs.getString(1) );
+ }
+ rs.close();
}
public void testParameters() throws SQLException
Index: org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java,v
retrieving revision 1.35
diff -c -b -r1.35 AbstractJdbc1ResultSet.java
*** org/postgresql/jdbc1/AbstractJdbc1ResultSet.java 29 Jun 2004 06:43:26 -0000 1.35
--- org/postgresql/jdbc1/AbstractJdbc1ResultSet.java 9 Jul 2004 23:44:49 -0000
***************
*** 28,33 ****
--- 28,34 ----
import org.postgresql.util.PGtokenizer;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
+ import java.math.BigInteger;
public abstract class AbstractJdbc1ResultSet implements BaseResultSet, org.postgresql.PGRefCursorResultSet
{
***************
*** 231,261 ****
if (s != null )
{
try
{
! switch(getSQLType(columnIndex))
{
! case Types.NUMERIC:
! case Types.REAL:
! case Types.DOUBLE:
! case Types.FLOAT:
! case Types.DECIMAL:
! int loc = s.indexOf(".");
! if (loc!=-1 && Integer.parseInt(s.substring(loc+1,s.length()))==0)
{
! s = s.substring(0,loc);
}
! break;
! case Types.CHAR:
! s = s.trim();
! break;
}
- if ( s.length() == 0 ) return 0;
- return Byte.parseByte(s);
}
! catch (NumberFormatException e)
{
! throw new PSQLException("postgresql.res.badbyte", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return 0; // SQL NULL
--- 232,268 ----
if (s != null )
{
+ s= s.trim();
+ if ( s.length() == 0 ) return 0;
try
{
! // try the optimal parse
! return Byte.parseByte(s);
! }
! catch (NumberFormatException e)
{
! // didn't work, assume the column is not a byte
! try
! {
! double d = Double.parseDouble(s);
! // check the size
! if (d > Byte.MAX_VALUE || d < Byte.MIN_VALUE)
{
! throw new PSQLException("postgresql.res.badbyte",
! PSQLState.
! NUMERIC_VALUE_OUT_OF_RANGE, s);
}
! else
! {
! return (byte)d;
}
}
! catch( NumberFormatException ex )
{
! throw new PSQLException("postgresql.res.badbyte",
! PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,
! s);
! }
}
}
return 0; // SQL NULL
***************
*** 267,296 ****
if (s != null)
{
try
{
! switch(getSQLType(columnIndex))
{
! case Types.NUMERIC:
! case Types.REAL:
! case Types.DOUBLE:
! case Types.FLOAT:
! case Types.DECIMAL:
! int loc = s.indexOf(".");
! if (loc!=-1 && Integer.parseInt(s.substring(loc+1,s.length()))==0)
{
! s = s.substring(0,loc);
}
! break;
! case Types.CHAR:
! s = s.trim();
! break;
}
! return Short.parseShort(s);
}
! catch (NumberFormatException e)
{
! throw new PSQLException("postgresql.res.badshort", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return 0; // SQL NULL
--- 274,308 ----
if (s != null)
{
+ s = s.trim();
try
{
! return Short.parseShort(s);
! }
! catch (NumberFormatException e)
{
! try
{
! double d = Double.parseDouble(s);
! // check the size
! if (d > Short.MAX_VALUE || d < Short.MIN_VALUE)
! {
! throw new PSQLException("postgresql.res.badshort",
! PSQLState.
! NUMERIC_VALUE_OUT_OF_RANGE, s);
}
! else
! {
! return (short)d;
}
!
}
! catch ( NumberFormatException ne )
{
! throw new PSQLException("postgresql.res.badshort",
! PSQLState.
! NUMERIC_VALUE_OUT_OF_RANGE, s);
! }
}
}
return 0; // SQL NULL
***************
*** 811,821 ****
}
catch (NumberFormatException e)
{
! throw new PSQLException ("postgresql.res.badint", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return 0; // SQL NULL
}
public static long toLong(String s) throws SQLException
{
--- 823,854 ----
}
catch (NumberFormatException e)
{
! try
! {
! double d = Double.parseDouble(s);
! if( d > Integer.MAX_VALUE || d < Integer.MIN_VALUE )
! {
! throw new PSQLException("postgresql.res.badint",
! PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,
! s);
! }
! else
! {
! return (int)d;
! }
! }
! catch( NumberFormatException ne )
! {
! throw new PSQLException("postgresql.res.badint",
! PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,
! s);
! }
}
}
return 0; // SQL NULL
}
+ private static BigInteger LONGMAX = new BigInteger(Long.toString(Long.MAX_VALUE));
+ private static BigInteger LONGMIN = new BigInteger(Long.toString(Long.MIN_VALUE));
public static long toLong(String s) throws SQLException
{
***************
*** 828,834 ****
}
catch (NumberFormatException e)
{
! throw new PSQLException ("postgresql.res.badlong", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return 0; // SQL NULL
--- 861,888 ----
}
catch (NumberFormatException e)
{
! try
! {
! BigDecimal n = new BigDecimal(s);
! BigInteger i = n.toBigInteger();
! int gt = i.compareTo(LONGMAX);
! int lt = i.compareTo(LONGMIN);
!
! if ( gt > 0 || lt < 0 )
! {
! throw new PSQLException("postgresql.res.badint",
! PSQLState.
! NUMERIC_VALUE_OUT_OF_RANGE,
! s);
! }
! return i.longValue();
! }
! catch( NumberFormatException ne )
! {
! throw new PSQLException("postgresql.res.badint",
! PSQLState.NUMERIC_VALUE_OUT_OF_RANGE,
! s);
! }
}
}
return 0; // SQL NULL
***************
*** 846,852 ****
}
catch (NumberFormatException e)
{
! throw new PSQLException ("postgresql.res.badbigdec", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
if (scale == -1)
return val;
--- 900,907 ----
}
catch (NumberFormatException e)
{
! throw new PSQLException("postgresql.res.badbigdec",
! PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
if (scale == -1)
return val;
***************
*** 856,862 ****
}
catch (ArithmeticException e)
{
! throw new PSQLException ("postgresql.res.badbigdec", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return null; // SQL NULL
--- 911,918 ----
}
catch (ArithmeticException e)
{
! throw new PSQLException("postgresql.res.badbigdec",
! PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return null; // SQL NULL
***************
*** 873,879 ****
}
catch (NumberFormatException e)
{
! throw new PSQLException ("postgresql.res.badfloat", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return 0; // SQL NULL
--- 929,936 ----
}
catch (NumberFormatException e)
{
! throw new PSQLException("postgresql.res.badfloat",
! PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return 0; // SQL NULL
***************
*** 890,896 ****
}
catch (NumberFormatException e)
{
! throw new PSQLException ("postgresql.res.baddouble", PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return 0; // SQL NULL
--- 947,954 ----
}
catch (NumberFormatException e)
{
! throw new PSQLException("postgresql.res.baddouble",
! PSQLState.NUMERIC_VALUE_OUT_OF_RANGE, s);
}
}
return 0; // SQL NULL
view thread (11+ messages) latest in thread
Message-ID: <1089416849.1515.298.camel@localhost.localdomain>
Permalink: ../1089416849.1515.298.camel@localhost.localdomain/
Also on: postgresql.org/message-id/1089416849.1515.298.camel@localhost.localdomain
copy link · copy postgr.es · copy git am
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: pg@fastcrypt.com, oliver@opencloud.com
Subject: Re: patch for getXXX methods
In-Reply-To: <1089416849.1515.298.camel@localhost.localdomain>
References: <1089407362.1508.292.camel@localhost.localdomain> <40EF1D5D.2050509@opencloud.com> <1089416849.1515.298.camel@localhost.localdomain>
* 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