From: Kris Jurka <books@ejurka.com>
To: Yi Lin <ylin30@cs.mcgill.ca>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: FastPath blocked when ERROR is thrown
Date: Tue, 11 Apr 2006 17:59:33 -0500 (EST)
Message-ID: <Pine.BSO.4.63.0604111756500.2028@leary2.csoft.net> (raw)
In-Reply-To: <59619.132.206.52.74.1144793175.squirrel@mail.cs.mcgill.ca>
References: <59619.132.206.52.74.1144793175.squirrel@mail.cs.mcgill.ca>
On Tue, 11 Apr 2006, Yi Lin wrote:
> I used java API FastPath.fastpath(fid, ...) to call a C function
> PGfn(conn, fid,...) in the kernal. But if there is an exception (i.e.,
> ERROR messages is thrown in the backend due to elog(ERROR, ...)), the
> FastPath.fastpath(fid, ..) is blocked and never returns.
The attached code runs fine with the cvs jdbc driver and a 8.0.7 server.
You haven't mentioned your versions, but this code hasn't changed recently
so anything relatively new should be fine.
How do you know the function is erroring out? What does the server log
say?
Kris Jurka
Attachments:FP.java (text/plain, 1.2K) download
import java.sql.*;
import org.postgresql.*;
import org.postgresql.fastpath.*;
public class FP {
public static void main(String margs[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/jurka","jurka","");
Statement stmt = conn.createStatement();
// Create a function to call via fastpath that will
// throw an exception.
//
stmt.execute("CREATE OR REPLACE FUNCTION myfpfunc() RETURNS int AS 'BEGIN RAISE EXCEPTION ''ex''; RETURN 1; END;' LANGUAGE plpgsql");
// Lookup oid of function we just created.
ResultSet rs = stmt.executeQuery("SELECT oid FROM pg_proc WHERE proname='myfpfunc'");
rs.next();
int fnid = rs.getInt(1);
rs.close();
// Call the function catching any error.
Fastpath fp = ((PGConnection)conn).getFastpathAPI();
FastpathArg[] args = new FastpathArg[0];
try {
fp.fastpath(fnid, true, args);
} catch (SQLException sqle) {
sqle.printStackTrace();
}
// Check that the connection still works by executing
// something else.
rs = stmt.executeQuery("SELECT 1");
rs.next();
System.out.println(rs.getInt(1));
rs.close();
stmt.close();
conn.close();
}
}
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, ylin30@cs.mcgill.ca
Subject: Re: FastPath blocked when ERROR is thrown
In-Reply-To: <Pine.BSO.4.63.0604111756500.2028@leary2.csoft.net>
References: <59619.132.206.52.74.1144793175.squirrel@mail.cs.mcgill.ca> <Pine.BSO.4.63.0604111756500.2028@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