From: Kris Jurka <books@ejurka.com>
To: Dave Cramer <pg@fastcrypt.com>
Cc: List <pgsql-jdbc@postgresql.org>
Cc: Luis Londono <somakani@gmail.com>
Subject: Re: Bug with callable statement and output parameters
Date: Thu, 27 Apr 2006 21:15:37 -0500 (EST)
Message-ID: <Pine.BSO.4.63.0604272109340.9036@leary2.csoft.net> (raw)
In-Reply-To: <B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com>
References: <3f205b320604201502o112f68abhafbc0a2e0a845218@mail.gmail.com>
<A29BE1BD-7BA2-49F9-BCEC-829A63B11874@fastcrypt.com>
<3f205b320604201703x2d5a52c7s214a039e36539a8a@mail.gmail.com>
<DB439E45-9AF2-4EC9-8215-4A83DFE31A52@fastcrypt.com>
<Pine.BSO.4.63.0604261551120.31984@leary2.csoft.net>
<D65A5222-DACA-4BBC-97E0-C3D4BAAB2525@fastcrypt.com>
<Pine.BSO.4.63.0604261827560.30145@leary2.csoft.net>
<B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com>
On Thu, 27 Apr 2006, Dave Cramer wrote:
> Patch attached for review and test
>
This patch does not handle the situation where the number of registered
parameters does not match the number of returned parameters as the
attached tests show.
Also the regression tests you sent me separately are no good. They do not
pass because they mix creating and destroying the test function in the
test method and the tearDown method. This should go into setUp and
tearDown. Also you can't call executeQuery on a CallableStatement because
it will complain with "No results were returned by the query."
The whole Jdbc3CallableStatementTest sucks. It should have all of its
function/table creation destruction moved into setUp/tearDown. Also the
coding:
try {
// something
} catch(Exception e) {
fail(e.getMessage();
}
Is a waste of code. Not only does it not do anything, but it also
obscures the source of the exception.
Kris Jurka
Attachments:OutFunc.java (text/plain, 1.5K) download
import java.sql.*;
public class OutFunc {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5820/jurka","jurka","");
try {
testNotEnoughRegisters(conn);
} catch (Exception e) {
e.printStackTrace();
}
try {
testTooManyRegisters(conn);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void testNotEnoughRegisters(Connection conn) throws SQLException {
Statement stmt = conn.createStatement();
stmt.execute("CREATE OR REPLACE FUNCTION myiofunc(a INOUT int, b OUT int) AS 'BEGIN b := a; a := 1; END;' LANGUAGE plpgsql");
CallableStatement cs = conn.prepareCall("{call myiofunc(?,?)}");
cs.setInt(1,2);
cs.registerOutParameter(2,Types.INTEGER);
cs.execute();
System.out.println(cs.getInt(1));
System.out.println(cs.getInt(2));
}
private static void testTooManyRegisters(Connection conn) throws SQLException {
Statement stmt = conn.createStatement();
stmt.execute("CREATE OR REPLACE FUNCTION myif(a INOUT int, b IN int) AS 'BEGIN a := b; END;' LANGUAGE plpgsql");
CallableStatement cs = conn.prepareCall("{call myif(?,?)}");
cs.setInt(1,1);
cs.setInt(2,2);
cs.registerOutParameter(1,Types.INTEGER);
cs.registerOutParameter(2,Types.INTEGER);
cs.execute();
System.out.println(cs.getInt(1));
System.out.println(cs.getInt(2));
}
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, pg@fastcrypt.com, somakani@gmail.com
Subject: Re: Bug with callable statement and output parameters
In-Reply-To: <Pine.BSO.4.63.0604272109340.9036@leary2.csoft.net>
References: <3f205b320604201502o112f68abhafbc0a2e0a845218@mail.gmail.com> <A29BE1BD-7BA2-49F9-BCEC-829A63B11874@fastcrypt.com> <3f205b320604201703x2d5a52c7s214a039e36539a8a@mail.gmail.com> <DB439E45-9AF2-4EC9-8215-4A83DFE31A52@fastcrypt.com> <Pine.BSO.4.63.0604261551120.31984@leary2.csoft.net> <D65A5222-DACA-4BBC-97E0-C3D4BAAB2525@fastcrypt.com> <Pine.BSO.4.63.0604261827560.30145@leary2.csoft.net> <B8BAE173-D49A-4C20-82A9-6DA0950F4CF9@fastcrypt.com> <Pine.BSO.4.63.0604272109340.9036@leary2.csoft.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox