X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0503A5E471B for ; Wed, 1 Sep 2004 09:50:00 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47644-07 for ; Wed, 1 Sep 2004 12:49:57 +0000 (GMT) Received: from net2.micro-automation.com (net2.micro-automation.com [64.7.141.29]) by svr1.postgresql.org (Postfix) with SMTP id D83625E4717 for ; Wed, 1 Sep 2004 09:49:54 -0300 (ADT) Received: (qmail 10856 invoked from network); 1 Sep 2004 12:49:58 -0000 Received: from dcdsl.ebox.com (HELO ?192.168.1.36?) (davec@64.7.143.116) by net2.micro-automation.com with SMTP; 1 Sep 2004 12:49:58 -0000 Subject: multiple out parameters implementation From: Dave Cramer Reply-To: pg@fastcrypt.com To: "pgsql-jdbc@postgresql.org" Content-Type: text/plain Organization: Cramer Consulting Message-Id: <1094043108.1554.198.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Wed, 01 Sep 2004 08:51:49 -0400 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests=TO_ADDRESS_EQ_REAL X-Spam-Level: X-Archive-Number: 200409/5 X-Sequence-Number: 10895 I've managed to hack into the jdbc driver the capability for multiple out parameters from a postgresql function. Before you say no it can't be done, read on. Also before anyone gives me credit for the idea, the original work was provided by Fujitsu japan, I can only take credit for implementing it in the current driver. The way this works is: 1) create a composite type eg: create type Numeric_Proc_RetType as(it1 numeric(30,15),it2 numeric(30,15),it3 numeric(30,15)) 2) create a function which returns this type. create function Numeric_Proc(numeric(30,15),numeric(30,15),numeric(30,15)) returns Numeric_Proc_RetType as 'declare work_ret record; begin select * into work_ret from Numeric_Tab; return work_ret; end;' language 'plpgsql' 3)create a table create temp table numeric_tab (MAX_VAL NUMERIC(30,15), MIN_VAL NUMERIC(30,15), NULL_VAL NUMERIC(30,15) ) Then the following code now works: CallableStatement call = con.prepareCall( func + "Numeric_Proc(?,?,?) }" ) ; call.registerOutParameter(1,Types.NUMERIC); call.registerOutParameter(2,Types.NUMERIC); call.registerOutParameter(3,Types.NUMERIC); call.setBigDecimal(2,new java.math.BigDecimal(1)); call.setBigDecimal(3,new java.math.BigDecimal(2)); call.setBigDecimal(4,new java.math.BigDecimal(3)); call.execute(); java.math.BigDecimal ret = call.getBigDecimal(1); ret = call.getBigDecimal(2); ret = call.getBigDecimal(3); There is more work to be done, but I've found it relatively easy to do, thanks largely to Oliver's rewrite of the code (Thanks Oliver!). This is particularly useful to folks that want to port code from other databases which do support multiple out parameters. I would like to query the list as to their thoughts, is this a useful feature for the driver ? Dave -- Dave Cramer 519 939 0336 ICQ # 14675561 www.postgresintl.com