Fix for getXXX (numbers)

Поиск
Список
Период
Сортировка
Искать

Fix for getXXX (numbers)

От:
Kim Ho <kho@redhat.com>
Дата:
Fixes the way the jdbc driver handles numbers when it gets them from
backend. Courtesy of Fujitsu.

Cheers,

Kim

Re: Fix for getXXX (numbers)

От:
Kim Ho <kho@redhat.com>
Дата:
Вложения:
Would help if I attach it.

On Tue, 2003-07-22 at 14:23, Kim Ho wrote:
> Fixes the way the jdbc driver handles numbers when it gets them from
> backend. Courtesy of Fujitsu.
> 
> Cheers,
> 
> Kim
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faqs/FAQ.html

Re: Fix for getXXX (numbers)

От:
Kim Ho <kho@redhat.com>
Дата:
This patch was written by Yoshihiro Yasuoka of Fujitsu.

Thanks,

Kim

On Tue, 2003-07-22 at 15:06, Kim Ho wrote:
> Would help if I attach it.
> 
> On Tue, 2003-07-22 at 14:23, Kim Ho wrote:
> > Fixes the way the jdbc driver handles numbers when it gets them from
> > backend. Courtesy of Fujitsu.
> > 
> > Cheers,
> > 
> > Kim
> > 
> > 
> > ---------------------------(end of broadcast)---------------------------
> > TIP 5: Have you checked our extensive FAQ?
> > 
> >                http://www.postgresql.org/docs/faqs/FAQ.html
> ----
> 

> Index: org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
> ===================================================================
> RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java,v
> retrieving revision 1.13
> diff -c -p -r1.13 AbstractJdbc1ResultSet.java
> *** org/postgresql/jdbc1/AbstractJdbc1ResultSet.java	30 Jun 2003 21:10:55 -0000	1.13
> --- org/postgresql/jdbc1/AbstractJdbc1ResultSet.java	22 Jul 2003 18:20:57 -0000
> *************** public abstract class AbstractJdbc1Resul
> *** 805,811 ****
>   			try
>   			{
>   				s = s.trim();
> ! 				return Integer.parseInt(s);
>   			}
>   			catch (NumberFormatException e)
>   			{
> --- 805,811 ----
>   			try
>   			{
>   				s = s.trim();
> ! 				return Float.valueOf(s).intValue();
>   			}
>   			catch (NumberFormatException e)
>   			{
> *************** public abstract class AbstractJdbc1Resul
> *** 822,828 ****
>   			try
>   			{
>   				s = s.trim();		
> ! 				return Long.parseLong(s);
>   			}
>   			catch (NumberFormatException e)
>   			{
> --- 822,828 ----
>   			try
>   			{
>   				s = s.trim();		
> ! 				return Double.valueOf(s).longValue();
>   			}
>   			catch (NumberFormatException e)
>   			{
> ----
> 

> 
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings


Re: Fix for getXXX (numbers)

От:
Barry Lind <blind@xythos.com>
Дата:
Kim,

Can you explain the problem this patch is trying to solve?  On the face 
of it I don't see what is wrong with the existing code.

thanks,
--Barry


Kim Ho wrote:
> This patch was written by Yoshihiro Yasuoka of Fujitsu.
> 
> Thanks,
> 
> Kim
> 
> On Tue, 2003-07-22 at 15:06, Kim Ho wrote:
> 
>>Would help if I attach it.
>>
>>On Tue, 2003-07-22 at 14:23, Kim Ho wrote:
>>
>>>Fixes the way the jdbc driver handles numbers when it gets them from
>>>backend. Courtesy of Fujitsu.
>>>
>>>Cheers,
>>>
>>>Kim
>>>
>>>
>>>---------------------------(end of broadcast)---------------------------
>>>TIP 5: Have you checked our extensive FAQ?
>>>
>>>               http://www.postgresql.org/docs/faqs/FAQ.html
>>
>>----
>>
> 
> 
>>Index: org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
>>===================================================================
>>RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java,v
>>retrieving revision 1.13
>>diff -c -p -r1.13 AbstractJdbc1ResultSet.java
>>*** org/postgresql/jdbc1/AbstractJdbc1ResultSet.java	30 Jun 2003 21:10:55 -0000	1.13
>>--- org/postgresql/jdbc1/AbstractJdbc1ResultSet.java	22 Jul 2003 18:20:57 -0000
>>*************** public abstract class AbstractJdbc1Resul
>>*** 805,811 ****
>>  			try
>>  			{
>>  				s = s.trim();
>>! 				return Integer.parseInt(s);
>>  			}
>>  			catch (NumberFormatException e)
>>  			{
>>--- 805,811 ----
>>  			try
>>  			{
>>  				s = s.trim();
>>! 				return Float.valueOf(s).intValue();
>>  			}
>>  			catch (NumberFormatException e)
>>  			{
>>*************** public abstract class AbstractJdbc1Resul
>>*** 822,828 ****
>>  			try
>>  			{
>>  				s = s.trim();		
>>! 				return Long.parseLong(s);
>>  			}
>>  			catch (NumberFormatException e)
>>  			{
>>--- 822,828 ----
>>  			try
>>  			{
>>  				s = s.trim();		
>>! 				return Double.valueOf(s).longValue();
>>  			}
>>  			catch (NumberFormatException e)
>>  			{
>>----
>>
> 
> 
>>---------------------------(end of broadcast)---------------------------
>>TIP 7: don't forget to increase your free space map settings
> 
> 
> 
> 



Re: Fix for getXXX (numbers)

От:
Kim Ho <kho@redhat.com>
Дата:
It solves this (which CTS is checking for):

In psql:

create table real_tab (a numeric);

In java:

PreparedStatement pstmt = conn.prepareStatement("insert into real_tab
values (?)");
pstmt.setFloat(1, Float.parseFloat(String.valueOf(Integer.MIN_VALUE)));
pstmt.executeUpdate();
ResultSet rs = conn.createStatement().executeQuery("select * from
real_tab");
rs.next();
System.out.println(rs.getInt(1));

Without the patch, you get:
Exception in thread "main" Bad Integer -2147483650
        at
org.postgresql.jdbc1.AbstractJdbc1ResultSet.toInt(AbstractJdbc1ResultSet.java:812)
        at
org.postgresql.jdbc1.AbstractJdbc1ResultSet.getInt(AbstractJdbc1ResultSet.java:248)

With the patch, you get:
-2147483648

Hope that helps,

Kim

On Thu, 2003-07-24 at 11:52, Barry Lind wrote:
> Kim,
> 
> Can you explain the problem this patch is trying to solve?  On the face 
> of it I don't see what is wrong with the existing code.
> 
> thanks,
> --Barry
> 
> 
> Kim Ho wrote:
> > This patch was written by Yoshihiro Yasuoka of Fujitsu.
> > 
> > Thanks,
> > 
> > Kim
> > 
> > On Tue, 2003-07-22 at 15:06, Kim Ho wrote:
> > 
> >>Would help if I attach it.
> >>
> >>On Tue, 2003-07-22 at 14:23, Kim Ho wrote:
> >>
> >>>Fixes the way the jdbc driver handles numbers when it gets them from
> >>>backend. Courtesy of Fujitsu.
> >>>
> >>>Cheers,
> >>>
> >>>Kim
> >>>
> >>>
> >>>---------------------------(end of broadcast)---------------------------
> >>>TIP 5: Have you checked our extensive FAQ?
> >>>
> >>>               http://www.postgresql.org/docs/faqs/FAQ.html
> >>
> >>----
> >>
> > 
> > 
> >>Index: org/postgresql/jdbc1/AbstractJdbc1ResultSet.java
> >>===================================================================
> >>RCS file: /projects/cvsroot/pgsql-server/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java,v
> >>retrieving revision 1.13
> >>diff -c -p -r1.13 AbstractJdbc1ResultSet.java
> >>*** org/postgresql/jdbc1/AbstractJdbc1ResultSet.java	30 Jun 2003 21:10:55 -0000	1.13
> >>--- org/postgresql/jdbc1/AbstractJdbc1ResultSet.java	22 Jul 2003 18:20:57 -0000
> >>*************** public abstract class AbstractJdbc1Resul
> >>*** 805,811 ****
> >>  			try
> >>  			{
> >>  				s = s.trim();
> >>! 				return Integer.parseInt(s);
> >>  			}
> >>  			catch (NumberFormatException e)
> >>  			{
> >>--- 805,811 ----
> >>  			try
> >>  			{
> >>  				s = s.trim();
> >>! 				return Float.valueOf(s).intValue();
> >>  			}
> >>  			catch (NumberFormatException e)
> >>  			{
> >>*************** public abstract class AbstractJdbc1Resul
> >>*** 822,828 ****
> >>  			try
> >>  			{
> >>  				s = s.trim();		
> >>! 				return Long.parseLong(s);
> >>  			}
> >>  			catch (NumberFormatException e)
> >>  			{
> >>--- 822,828 ----
> >>  			try
> >>  			{
> >>  				s = s.trim();		
> >>! 				return Double.valueOf(s).longValue();
> >>  			}
> >>  			catch (NumberFormatException e)
> >>  			{
> >>----
> >>
> > 
> > 
> >>---------------------------(end of broadcast)---------------------------
> >>TIP 7: don't forget to increase your free space map settings
> > 
> > 
> > 
> > 
> 
> 
> 


FAQ