X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (mx2.hub.org [200.46.204.254]) by postgresql.org (Postfix) with ESMTP id C928211F6761 for ; Thu, 20 Apr 2006 21:03:43 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: -1.923 X-Spam-Level: X-Spam-Status: No, score=-1.923 required=5 tests=[AWL=0.676, BAYES_00=-2.599, HTML_MESSAGE=0.001, SPF_PASS=-0.001] Received: from postgresql.org ([200.46.204.71]) by localhost (mx2.hub.org [200.46.204.254]) (amavisd-new, port 10024) with ESMTP id Aqt3Rl2RTxc0 for ; Thu, 20 Apr 2006 21:03:38 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nz-out-0102.google.com (nz-out-0102.google.com [64.233.162.200]) by postgresql.org (Postfix) with ESMTP id A4F7F11F6770 for ; Thu, 20 Apr 2006 21:03:36 -0300 (ADT) Received: by nz-out-0102.google.com with SMTP id o1so231109nzf for ; Thu, 20 Apr 2006 17:03:37 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=p02d76IdbUKpDBGjxuAAgq5OcwZFO8VxI19Q1nsPj542QRaXJbu/JcFHVmcOgdl9qA1vA3Ai6prv2ltyN9c8L4x7NqBqJIO7Bu6xecmieLy25E6Tkhy1FEgZZkei1JvTn6aa+pi765ek4KYVlJcnf8MrznMIhO7+AzSj4ILpjSA= Received: by 10.36.38.7 with SMTP id l7mr1459211nzl; Thu, 20 Apr 2006 17:03:37 -0700 (PDT) Received: by 10.36.128.5 with HTTP; Thu, 20 Apr 2006 17:03:37 -0700 (PDT) Message-ID: <3f205b320604201703x2d5a52c7s214a039e36539a8a@mail.gmail.com> Date: Thu, 20 Apr 2006 18:03:37 -0600 From: "Luis Londono" To: "Dave Cramer" Subject: Re: Bug with callable statement and output parameters Cc: pgsql-jdbc@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_4248_4657546.1145577817044" References: <3f205b320604201502o112f68abhafbc0a2e0a845218@mail.gmail.com> X-Archive-Number: 200604/140 X-Sequence-Number: 15074 ------=_Part_4248_4657546.1145577817044 Content-Type: multipart/alternative; boundary="----=_Part_4249_30447062.1145577817044" ------=_Part_4249_30447062.1145577817044 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I am attaching a java file that goes against the following functions: CREATE OR REPLACE FUNCTION test_somein_someout( pa IN int4, pb OUT varchar, pc OUT int8) AS $BODY$ begin pb :=3D 'pb out'; pc :=3D pa + 1; end; $BODY$ LANGUAGE 'plpgsql' VOLATILE; CREATE OR REPLACE FUNCTION test_allinout( pa INOUT int4, pb INOUT varchar, pc INOUT int8) AS $BODY$ begin pa :=3D pa + 1; pb :=3D 'pb out'; pc :=3D pa + 1; end; $BODY$ LANGUAGE 'plpgsql' VOLATILE; I used postgresql-8.1-405.jdbc3.jar against 8.1.0 version of the db. Here are the results: org.postgresql.util.PSQLException: A CallableStatement function was execute= d and the return was of type java.sql.Types=3D12 however type java.sql.Types=3D0was registered. at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags( AbstractJdbc2Statement.java:387) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery( AbstractJdbc2Statement.java:257) at TestDriver.testSomeInSomeOut(TestDriver.java:20) at TestDriver.main(TestDriver.java:54) org.postgresql.util.PSQLException: A CallableStatement function was execute= d and the return was of type java.sql.Types=3D4 however type java.sql.Types=3D12was registered. at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags( AbstractJdbc2Statement.java:387) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery( AbstractJdbc2Statement.java:257) at TestDriver.testAllInOut(TestDriver.java:40) at TestDriver.main(TestDriver.java:60) On 4/20/06, Dave Cramer wrote: > > Luis, > > Can you send us a test case that fails. There are a number of test > cases in the driver source code that do pass. > > Dave > On 20-Apr-06, at 6:02 PM, Luis Londono wrote: > > > I kept getting the following error when using a callable statement > > with multiple output parameters: > > > > org.postgresql.util.PSQLException: A CallableStatement function was > > executed and the return was of type java.sql.Types=3D12 however type > > java.sql.Types=3D4 was registered. > > at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags > > (AbstractJdbc2Statement.java:387) > > at org.postgresql.jdbc2.AbstractJdbc2Statement.execute > > (AbstractJdbc2Statement.java :346) > > at org.apache.commons.dbcp.DelegatingPreparedStatement.execute > > (DelegatingPreparedStatement.java:168) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source) > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > at java.lang.reflect.Method.invoke(Unknown Source) > > at > > com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.invoke > > (PreparedStatementLogProxy.java:62) > > at $Proxy8.execute(Unknown Source) > > at > > com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQueryProcedure > > (SqlExecutor.java:287) > > at > > com.ibatis.sqlmap.engine.mapping.statement.ProcedureStatement.sqlExecu > > teQuery (ProcedureStatement.java:34) > > at > > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQue > > ryWithCallback(GeneralStatement.java:173) > > at > > com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQue > > ryForObject (GeneralStatement.java:104) > > at > > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject > > (SqlMapExecutorDelegate.java:561) > > at > > com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject > > (SqlMapExecutorDelegate.java :536) > > at > > com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject > > (SqlMapSessionImpl.java:93) > > at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject > > (SqlMapClientImpl.java:70) > > at org.springframework.orm.ibatis.SqlMapClientTemplate > > $1.doInSqlMapClient (SqlMapClientTemplate.java:224) > > at org.springframework.orm.ibatis.SqlMapClientTemplate.execute > > (SqlMapClientTemplate.java:165) > > at > > org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject > > (SqlMapClientTemplate.java :222) > > at > > sms.app.shared.web.session.dao.ibatis.SessionDataDaoImpl.getDataAndRen > > ew2(SessionDataDaoImpl.java:133) > > at > > test.sms.app.shared.web.session.TestSessionData.testStoredProc > > (TestSessionData.java:155) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > at java.lang.reflect.Method.invoke(Unknown Source) > > at junit.framework.TestCase.runTest(TestCase.java:154) > > at junit.framework.TestCase.runBare(TestCase.java:127) > > at junit.framework.TestResult$1.protect(TestResult.java :106) > > at junit.framework.TestResult.runProtected(TestResult.java:124) > > at junit.framework.TestResult.run(TestResult.java:109) > > at junit.framework.TestCase.run(TestCase.java:118) > > at > > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests > > (RemoteTestRunner.java:478) > > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run > > (RemoteTestRunner.java:344) > > at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main > > (RemoteTestRunner.java:196) > > > > > > after much hair pulling, I am certain there are a couple of bugs > > with the jdbc driver. The first bug is relatively clear. Line 375 > > of org/postgresql/jdbc2/AbstractJdbc2Statement.java, in the latest > > 8.1-405 source tree reads: > > > > int columnType =3D rs.getMetaData().getColumnType(1); <<<<<< number on= e > > > > and I believe it should be: > > > > int columnType =3D rs.getMetaData().getColumnType(i+1); <<<<< > > letter i plus one > > > > There is a second problem with output parameter checking, but it is > > harder to explain: > > - call a function such as: myfunc(p1 IN varchar, p2 OUT int4, p3 > > OUT timestamp) > > - The registerOutParameter is called as: > > cs.registerOutParameter(2, Types.INTEGER) > > - this will eventually call the registerOutParameter method in > > AbstractJdbc2Statement.java > > - this will store in functionReturnType[1] the value of > > Types.INTEGER > > - the call is made to the db and the resultset containing the > > output parameters will be retrieved > > - in the same place as the previous error, the types are checked, > > - The problem arises now. The first output parameter is column 0 > > of the result set, but index 1 in the functionReturnType array. > > - The types do not match and an error is thrown. > > > > I am not sure what the right fix is for this latter error. > > > > -Luis > > ------=_Part_4249_30447062.1145577817044 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I am attaching a java file that goes against the following functions:
CREATE OR REPLACE FUNCTION test_somein_someout(
   &nbs= p;  pa IN int4,
      pb OUT varchar, = ;
      pc OUT int8)
 AS
$BODY$
= begin
   pb :=3D 'pb out';
   pc :=3D pa + 1;
end;
$= BODY$
  LANGUAGE 'plpgsql' VOLATILE;

CREATE OR REPLACE FUNCT= ION test_allinout(
      pa INOUT int4,
&nbs= p;     pb INOUT varchar,
    &n= bsp; pc INOUT int8)
 AS
$BODY$
begin
   pa :=3D pa + 1;
   pb :=3D= 'pb out';
   pc :=3D pa + 1;
end;
$BODY$
  LANG= UAGE 'plpgsql' VOLATILE;
 
I used postgresql-8.1-405.jdbc3.jar = against 8.1.0 version of the db.   Here are the results:

org.postgresql.util.PSQLException: A CallableStatement function was= executed and the return was of type java.sql.Types=3D12 however type java.= sql.Types=3D0 was registered.
    at org.postgresql.jdbc2= .AbstractJdbc2Statement.executeWithFlags (AbstractJdbc2Statement.java:387)
    at org.postgresql.j= dbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:257)    at TestDriver.testSomeInSomeOut(TestDriver.java:20)    at TestDriver.main(TestDriver.java :54)
org.postgresql.util.PSQLException: A CallableStatement function was= executed and the return was of type java.sql.Types=3D4 however type java.s= ql.Types=3D12 was registered.
    at org.postgresql.jdbc2= .AbstractJdbc2Statement.executeWithFlags (AbstractJdbc2Statement.java:387)
    at org.postgresql.j= dbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:257)    at TestDriver.testAllInOut(TestDriver.java:40)
&nbs= p;   at TestDriver.main(TestDriver.java :60)


On 4/20/06, Dave Cramer <pg@= fastcrypt.com> wrote:
Luis,

Can you send us a test case that fails. There are a number of = test
cases in the driver source code that do pass.

Dave
On 20-= Apr-06, at 6:02 PM, Luis Londono wrote:

> I kept getting the foll= owing error when using a callable statement
> with multiple output parameters:
>
> org.postgresql.ut= il.PSQLException: A CallableStatement function was
> executed and the= return was of type java.sql.Types=3D12 however type
> java.sql.Types= =3D4 was registered.
>     at org.postgresql.jdbc2.Ab= stractJdbc2Statement.executeWithFlags
> (AbstractJdbc2Statement.java:= 387)
>     at org.postgresql.jdbc2.AbstractJdbc2S= tatement.execute
> (AbstractJdbc2Statement.java :346)
>     at org.apache.commons.dbcp.Delegatin= gPreparedStatement.execute
> (DelegatingPreparedStatement.java:168)>     at sun.reflect.NativeMethodAccessorImpl.invo= ke0(Native Method)
>     at sun.reflect.NativeMet= hodAccessorImpl.invoke (Unknown Source)
>     at sun.reflect.Delegating= MethodAccessorImpl.invoke(Unknown Source)
>     a= t java.lang.reflect.Method.invoke(Unknown Source)
>   =   at
> com.ibatis.common.jdbc.logging.PreparedStatementLogProxy.= invoke
> (PreparedStatementLogProxy.java:62)
>    = ; at $Proxy8.execute(Unknown Source)
>     at
= > com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQueryProcedure> (SqlExecutor.java:287)
>     at
> com.ibatis.sqlmap.engine.mapping.statement.ProcedureStatement.sqlE= xecu
> teQuery (ProcedureStatement.java:34)
>   =   at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStateme= nt.executeQue
> ryWithCallback(GeneralStatement.java:173)
>   &nb= sp; at
> com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.= executeQue
> ryForObject (GeneralStatement.java:104)
> &nb= sp;   at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDele= gate.queryForObject
> (SqlMapExecutorDelegate.java:561)
>     = at
> com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObj= ect
> (SqlMapExecutorDelegate.java :536)
>   &nb= sp; at
> com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObje= ct
> (SqlMapSessionImpl.java:93)
>     at com= .ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject
> (SqlMapC= lientImpl.java:70)
>     at org.springframework.o= rm.ibatis.SqlMapClientTemplate
> $1.doInSqlMapClient ( SqlMapClientTemplate.java:224)
>     at org.sprin= gframework.orm.ibatis.SqlMapClientTemplate.execute
> (SqlMapClientTem= plate.java:165)
>     at
> org.springframew= ork.orm.ibatis.SqlMapClientTemplate.queryForObject
> (SqlMapClientTemplate.java :222)
>     a= t
> sms.app.shared.web.session.dao.ibatis.SessionDataDaoImpl.getDataA= ndRen
> ew2(SessionDataDaoImpl.java:133)
>   &nb= sp; at
> test.sms.app.shared.web.session.TestSessionData.testStoredPr= oc
> (TestSessionData.java:155)
>     at sun.= reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>  =    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)=
>     at sun.reflect.DelegatingMethodAccessorImp= l.invoke (Unknown Source)
>     at java.lang.reflect.Metho= d.invoke(Unknown Source)
>     at junit.framework= .TestCase.runTest(TestCase.java:154)
>     at jun= it.framework.TestCase.runBare(TestCase.java:127)
>   &= nbsp; at=20 junit.framework.TestResult$1.protect(TestResult.java :106)
> &nb= sp;   at junit.framework.TestResult.runProtected(TestResult.java:= 124)
>     at junit.framework.TestResult.run(Test= Result.java:109)
>     at junit.framework.TestCas= e.run (TestCase.java:118)
>     at
> org.eclipse.= jdt.internal.junit.runner.RemoteTestRunner.runTests
> (RemoteTestRunn= er.java:478)
>     at org.eclipse.jdt.internal.ju= nit.runner.RemoteTestRunner.run
> ( RemoteTestRunner.java:344)
>     at org.eclipse.j= dt.internal.junit.runner.RemoteTestRunner.main
> (RemoteTestRunner.ja= va:196)
>
>
> after much hair pulling, I am certain there= are a couple of bugs
> with the jdbc driver.  The first bug is relatively clear= .  Line 375
> of org/postgresql/jdbc2/AbstractJdbc2Statemen= t.java, in the latest
> 8.1-405 source tree reads:
>
> in= t columnType =3D rs.getMetaData ().getColumnType(1);  <<<<<< number one
>=
> and I believe it should be:
>
> int columnType =3D rs.= getMetaData().getColumnType(i+1);   <<<<<
> = letter i plus one
>
> There is a second problem with output parameter checking, but = it is
> harder to explain:
>   - call a function such= as:  myfunc(p1 IN varchar, p2 OUT int4, p3
> OUT timestamp= )
>   - The registerOutParameter is called as:
>         cs.registerOutPara= meter(2, Types.INTEGER)
>   - this will eventually call the= registerOutParameter method in
> AbstractJdbc2Statement.java
>=    - this will store in functionReturnType[1] the value of
> Types.INTEGER
>   - the call is made to the db and= the resultset containing the
> output parameters will be retrieved>   - in the same place as the previous error, the types are= checked,
>   - The problem arises now.  The firs= t output parameter is column 0
> of the result set, but index 1 in the functionReturnType array.>   - The types do not match and an error is thrown.
><= br>> I am not sure what the right fix is for this latter error.
><= br>> -Luis


------=_Part_4249_30447062.1145577817044-- ------=_Part_4248_4657546.1145577817044 Content-Type: application/octet-stream; name=TestDriver.java Content-Transfer-Encoding: 7bit X-Attachment-Id: f_em9rfkk5 Content-Disposition: attachment; filename="TestDriver.java" import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Types; /** * */ public class TestDriver { private static void testSomeInSomeOut() throws Exception { String url = "jdbc:postgresql://localhost/db"; Connection con = DriverManager.getConnection(url, "user", "pwd"); CallableStatement cstmt = con.prepareCall("{call test_somein_someout(?,?,?)}"); cstmt.registerOutParameter(2, Types.VARCHAR); cstmt.registerOutParameter(3, Types.BIGINT); cstmt.setInt(1,20); cstmt.executeQuery(); String out1 = cstmt.getString(1); long out2 = cstmt.getLong(2); System.out.println("out1=[" + out1 + "] out2=" + out2); cstmt.close(); con.close(); } private static void testAllInOut() throws Exception { String url = "jdbc:postgresql://localhost/db"; Connection con = DriverManager.getConnection(url, "user", "pwd"); CallableStatement cstmt = con.prepareCall("{call test_allinout(?,?,?)}"); cstmt.registerOutParameter(1, Types.INTEGER); cstmt.registerOutParameter(2, Types.VARCHAR); cstmt.registerOutParameter(3, Types.BIGINT); cstmt.setInt(1,20); cstmt.setString(2,"hi"); cstmt.setLong(3,123); cstmt.executeQuery(); int out1 = cstmt.getInt(1); String out2 = cstmt.getString(2); long out3 = cstmt.getLong(3); System.out.println("out1=" + out1 + " out2=[" + out2 + "] out3=" + out3); cstmt.close(); con.close(); } public static void main(String[] str) throws Exception { Class.forName("org.postgresql.Driver"); try { testSomeInSomeOut(); } catch (Exception e) { e.printStackTrace(); } try { testAllInOut(); } catch (Exception e) { e.printStackTrace(); } } } ------=_Part_4248_4657546.1145577817044--