pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: List <pgsql-jdbc@postgresql.org>
Cc: Luis Londono <somakani@gmail.com>
Cc: Kris Jurka <books@ejurka.com>
Subject: Re: Bug with callable statement and output parameters
Date: Thu, 27 Apr 2006 12:01:53 -0400
Message-ID: <B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com> (raw)
In-Reply-To: <Pine.BSO.4.63.0604261827560.30145@leary2.csoft.net>
References: <3f205b320604201502o112f68abhafbc0a2e0a845218@mail.gmail.com>
	<A29BE1BD-7BA2-49F9-BCEC-829A63B11874@fastcrypt.com>
	<3f205b320604201703x2d5a52c7s214a039e36539a8a@mail.gmail.com>
	<DB439E45-9AF2-4EC9-8215-4A83DFE31A52@fastcrypt.com>
	<Pine.BSO.4.63.0604261551120.31984@leary2.csoft.net>
	<D65A5222-DACA-4BBC-97E0-C3D4BAAB2525@fastcrypt.com>
	<Pine.BSO.4.63.0604261827560.30145@leary2.csoft.net>

Patch attached for review and test

Index: org/postgresql/jdbc2/AbstractJdbc2Statement.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/ 
AbstractJdbc2Statement.java,v
retrieving revision 1.88
diff -c -r1.88 AbstractJdbc2Statement.java
*** org/postgresql/jdbc2/AbstractJdbc2Statement.java    1 Feb 2006  
18:52:13 -0000       1.88
--- org/postgresql/jdbc2/AbstractJdbc2Statement.java    27 Apr 2006  
16:00:50 -0000
***************
*** 366,392 ****

               // figure out how many columns
               int cols = rs.getMetaData().getColumnCount();
!             callResult = new Object[cols];

               // move them into the result set
!             for ( int i=0; i < cols; i++)
               {
!                 callResult[i] = rs.getObject(i+1);
!                 int columnType = rs.getMetaData().getColumnType(1);
!                 if (columnType != functionReturnType[i])
                   {
                       // this is here for the sole purpose of  
passing the cts
!                     if ( columnType == Types.DOUBLE &&  
functionReturnType[i] == Types.REAL )
                       {
                           // return it as a float
!                         if ( callResult[i] != null)
!                             callResult[i] = new Float(((Double) 
callResult[i]).floatValue());
                       }
                       else
                       {
!                           throw new PSQLException (GT.tr("A  
CallableStatement function was executed and the return was of type  
{0} however type {1} was registered.",
!                                   new Object[]{
!                                       "java.sql.Types=" +  
columnType, "java.sql.Types=" + functionReturnType[i] }),
                               PSQLState.DATA_TYPE_MISMATCH);
                       }
                   }
--- 366,401 ----

               // figure out how many columns
               int cols = rs.getMetaData().getColumnCount();
!
!             // allocate enough space for all possible parameters  
without regard to in/out
!             callResult = new Object 
[preparedParameters.getParameterCount()+1];

               // move them into the result set
!             for ( int i=0,j=0; i < cols; i++,j++)
               {
!                 // find the next out parameter, the assumption is  
that the functionReturnType
!                 // array will be initialized with 0 and only out  
parameters will have values
!                 // other than 0. 0 is the value for  
java.sql.Types.NULL, which should not
!                 // conflict
!                 while( j< functionReturnType.length &&  
functionReturnType[j]==0) j++;
!
!                 callResult[j] = rs.getObject(i+1);
!                 int columnType = rs.getMetaData().getColumnType(i+1);
!
!                 if (columnType != functionReturnType[j])
                   {
                       // this is here for the sole purpose of  
passing the cts
!                     if ( columnType == Types.DOUBLE &&  
functionReturnType[j] == Types.REAL )
                       {
                           // return it as a float
!                         if ( callResult[j] != null)
!                             callResult[j] = new Float(((Double) 
callResult[j]).floatValue());
                       }
                       else
                       {
!                           throw new PSQLException (GT.tr("A  
CallableStatement function was executed and the out parameter {0} was  
of type {1} however type {2} was registered.",
!                                   new Object[]{""+i+1,
!                                       "java.sql.Types=" +  
columnType, "java.sql.Types=" + functionReturnType[j] }),
                               PSQLState.DATA_TYPE_MISMATCH);
                       }
                   }




view thread (21+ messages)  latest in thread

Message-ID: <B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com>
Permalink:  ../B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com/
Also on:    postgresql.org/message-id/B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com

 · 

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, somakani@gmail.com, books@ejurka.com
  Subject: Re: Bug with callable statement and output parameters
  In-Reply-To: <B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com>
  References: <3f205b320604201502o112f68abhafbc0a2e0a845218@mail.gmail.com> <A29BE1BD-7BA2-49F9-BCEC-829A63B11874@fastcrypt.com> <3f205b320604201703x2d5a52c7s214a039e36539a8a@mail.gmail.com> <DB439E45-9AF2-4EC9-8215-4A83DFE31A52@fastcrypt.com> <Pine.BSO.4.63.0604261551120.31984@leary2.csoft.net> <D65A5222-DACA-4BBC-97E0-C3D4BAAB2525@fastcrypt.com> <Pine.BSO.4.63.0604261827560.30145@leary2.csoft.net> <B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com>

* 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