X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id D731011F6240 for ; Thu, 27 Apr 2006 13:06:32 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 62137-01 for ; Thu, 27 Apr 2006 13:05:19 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by postgresql.org (Postfix) with SMTP id 96B5A11F6220 for ; Thu, 27 Apr 2006 13:01:55 -0300 (ADT) Received: (qmail 501 invoked from network); 27 Apr 2006 16:01:54 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.2?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 27 Apr 2006 16:01:54 -0000 In-Reply-To: References: <3f205b320604201502o112f68abhafbc0a2e0a845218@mail.gmail.com> <3f205b320604201703x2d5a52c7s214a039e36539a8a@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v749.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: Luis Londono , Kris Jurka Content-Transfer-Encoding: 7bit From: Dave Cramer Subject: Re: Bug with callable statement and output parameters Date: Thu, 27 Apr 2006 12:01:53 -0400 To: List X-Mailer: Apple Mail (2.749.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200604/175 X-Sequence-Number: 15109 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); } }