Re: Bug with callable statement and output parameters

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: List <pgsql-jdbc(at)postgresql(dot)org>
Cc: Luis Londono <somakani(at)gmail(dot)com>, Kris Jurka <books(at)ejurka(dot)com>
Subject: Re: Bug with callable statement and output parameters
Date: 2006-04-27 16:01:53
Message-ID: B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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);
}
}

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message J. 2006-04-28 00:02:09 connection pooling with servlets
Previous Message Dave Cramer 2006-04-27 13:56:50 Re: java.sql.SQLException: No suitable driver