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 4CC5B11F66F1 for ; Thu, 20 Apr 2006 19:02:07 -0300 (ADT) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Score: -1.248 X-Spam-Level: X-Spam-Status: No, score=-1.248 required=5 tests=[BAYES_00=-2.599, HTML_10_20=1.351, 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 HJCRzEiS4JpD for ; Thu, 20 Apr 2006 19:02:02 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from nz-out-0102.google.com (nz-out-0102.google.com [64.233.162.204]) by postgresql.org (Postfix) with ESMTP id 2730911F625D for ; Thu, 20 Apr 2006 19:02:00 -0300 (ADT) Received: by nz-out-0102.google.com with SMTP id o1so216061nzf for ; Thu, 20 Apr 2006 15:02:00 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=jauqZVj4o4UyAt6gz/noas3LYT+W7AfvACSOlptShG/3Fy97vZyDKwnWKWae/HA12LeRcrdmc149TEmj5HTgLrOSXolSHdWPMNYgmIWgLGN4WAUXvmIEWAROPjs7HS70p+bBAVEBgPs6v/7NaUGorxYfxinI778OPwAMUKFuzbM= Received: by 10.37.13.76 with SMTP id q76mr1367696nzi; Thu, 20 Apr 2006 15:02:00 -0700 (PDT) Received: by 10.36.128.5 with HTTP; Thu, 20 Apr 2006 15:02:00 -0700 (PDT) Message-ID: <3f205b320604201502o112f68abhafbc0a2e0a845218@mail.gmail.com> Date: Thu, 20 Apr 2006 16:02:00 -0600 From: "Luis Londono" To: pgsql-jdbc@postgresql.org Subject: Bug with callable statement and output parameters MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_3275_23936993.1145570520741" X-Archive-Number: 200604/138 X-Sequence-Number: 15072 ------=_Part_3275_23936993.1145570520741 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I kept getting the following error when using a callable statement with multiple output parameters: 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=3D4was 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.sqlExecuteQue= ry (ProcedureStatement.java:34) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWit= hCallback (GeneralStatement.java:173) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryFor= Object (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.getDataAndRenew2( 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-405source tree reads: int columnType =3D rs.getMetaData().getColumnType(1); <<<<<< number one and I believe it should be: int columnType =3D rs.getMetaData().getColumnType(i+1); <<<<< letter i pl= us 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_3275_23936993.1145570520741 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline I kept getting the following error when using a callable statement with mul= tiple output parameters:

org.postgresql.util.PSQLException: A Callab= leStatement function was executed and the return was of type java.sql.Types= =3D12 however type java.sql.Types=3D4 was registered.
    at o= rg.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2St= atement.java:387)
    at org.postgresql.jdbc2.AbstractJdb= c2Statement.execute(AbstractJdbc2Statement.java :346)
    at org.apache.commons.dbcp.DelegatingPreparedSt= atement.execute(DelegatingPreparedStatement.java:168)
   = at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 &n= bsp;  at sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source)
    at sun.reflect.DelegatingMethodAcces= sorImpl.invoke(Unknown Source)
    at java.lang.reflect.M= ethod.invoke(Unknown Source)
    at com.ibatis.common.jdb= c.logging.PreparedStatementLogProxy.invoke (PreparedStatementLogProxy.java:62)
    at $Proxy8.execut= e(Unknown Source)
    at com.ibatis.sqlmap.engine.executi= on.SqlExecutor.executeQueryProcedure(SqlExecutor.java:287)
  &= nbsp; at com.ibatis.sqlmap.engine.mapping.statement.ProcedureStatement.sqlE= xecuteQuery (ProcedureStatement.java:34)
    at com.ibatis.sqlmap.eng= ine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStat= ement.java:173)
    at com.ibatis.sqlmap.engine.mapping.s= tatement.GeneralStatement.executeQueryForObject (GeneralStatement.java:104)
    at com.ibatis.sqlmap.engi= ne.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:5= 61)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDe= legate.queryForObject(SqlMapExecutorDelegate.java :536)
    at com.ibatis.sqlmap.engine.impl.SqlMapSessionI= mpl.queryForObject(SqlMapSessionImpl.java:93)
    at com.= ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.= java:70)
    at org.springframework.orm.ibatis.SqlMapClie= ntTemplate$1.doInSqlMapClient (SqlMapClientTemplate.java:224)
    at org.springframewor= k.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.Sessio= nDataDaoImpl.getDataAndRenew2(SessionDataDaoImpl.java:133)
  &= nbsp; at test.sms.app.shared.web.session.TestSessionData.testStoredProc(Tes= tSessionData.java:155)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native M= ethod)
    at sun.reflect.NativeMethodAccessorImpl.invoke= (Unknown Source)
    at sun.reflect.DelegatingMethodAcces= sorImpl.invoke(Unknown Source)
    at=20 java.lang.reflect.Method.invoke(Unknown Source)
    at ju= nit.framework.TestCase.runTest(TestCase.java:154)
    at = junit.framework.TestCase.runBare(TestCase.java:127)
    a= t junit.framework.TestResult$1.protect(TestResult.java :106)
    at junit.framework.TestResult.runProtected(Test= Result.java:124)
    at junit.framework.TestResult.run(Te= stResult.java:109)
    at junit.framework.TestCase.run(Te= stCase.java:118)
    at org.eclipse.jdt.internal.junit.ru= nner.RemoteTestRunner.runTests (RemoteTestRunner.java:478)
    at org.eclipse.jdt.intern= al.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
 &n= bsp;  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(R= emoteTestRunner.java:196)


after much hair pulling, I am certain there are a couple of bugs wi= th 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 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 registerOutParamet= er is called as:
        cs.registerOutParameter(2, Types.INTEGER)  - this will eventually call the registerOutParameter method in Abs= tractJdbc2Statement.java
  - this will store in functionReturnType[= 1] the value of Types.INTEGER
  - the call is made to the db and the resultset containing the ou= tput parameters will be retrieved
  - in the same place as the prev= ious error, the types are checked,
  - The problem arises now.&nbs= p; The first output parameter is column 0 of the result set, but index 1 in= the functionReturnType array. =20
  - 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_3275_23936993.1145570520741--