[#1011117] seems that try catch is powerless on prepared statements

View Trackers | Bugs | Download .csv | Monitor

Date:
2011-11-13 13:01
Priority:
3
State:
Open
Submitted by:
Christian Meier (cikic)
Assigned to:
Nobody (None)
Category:
Group:
Summary:
seems that try catch is powerless on prepared statements

Detailed description
i am using win 7 64x, postgres 9.0.4 Java 1.6 and pljava 1.4.2

the following code

PreparedStatement ps = DatabaseUtils.getPreparedStatement(sql.toString());
for (int i=0;i<values.length;i++)
ps.setObject(i+1, values[i]); //ps.setObject(i+1, values[i], (Integer) ClassUtils.TYPE_MAPPING.get(values[i].getClass())[1]);

env.print(ps.toString());

try {
ps.execute(); //<--- is causing problems
} catch (SQLException e) {
ps.clearWarnings();
Logger.getAnonymousLogger().warning(StackUtils.getStackTrace(e));
} finally {
ps.close();
}

results in an exception:
"An attempt was made to call a PostgreSQL backend function after an elog(ERROR) had been issued"

this is because the prepared statement is violating a duplicate key. as you can see the try catch is powerless and the exception will allways result in a complete rollback.


Followup

Message
Date: 2011-11-30 13:39
Sender: Christian Meier

NOTE: the issue also on linux 64 bit postgres 9.1 and pljava
1.4.3
kic@ubuntu:~/workspace/stalked/stalked/bin$ psql -Upostgres
psql (9.1.1)
Type "help" for help.

postgres=# create or replace function public.test_catch()
returns void
postgres-# as 'kic.stalked.proebel.TestCatch.test' language
java;
CREATE FUNCTION
postgres=# select public.test_catch();
WARNING: 30 Nov 11 14:38:42 kic.stalked.proebel.TestCatch
exception caught
ERROR: java.sql.SQLException: An attempt was made to call a
PostgreSQL backend function after an elog(ERROR) had been
issued
postgres=#
Date: 2011-11-30 13:09
Sender: Christian Meier

try the attached jar (src and bin) with this sql
create or replace function public.test_catch() returns void
as 'kic.stalked.proebel.TestCatch.test' language java;

select public.test_catch();

you will get a:
D:\>psql -Upostgres
psql (9.0.4)
Warnung: Konsolencodeseite (850) unterscheidet sich von der
Windows-
Codeseite (1252). 8-Bit-Zeichen funktionieren
möglicherweise nicht
richtig. Einzelheiten finden Sie auf der psql-
Handbuchseite unter
»Notes for Windows users«.
Geben Sie »help« für Hilfe ein.

postgres=# select public.test_catch();
WARNUNG: 30 Nov 11 14:09:04 kic.stalked.proebel.TestCatch
exception caught
FEHLER: java.sql.SQLException: An attempt was made to call
a PostgreSQL backend function after an elog(ERROR) had been
issued
postgres=#


Date: 2011-11-30 12:25
Sender: Christian Meier

I am not able to catch any SQLException. Whenever a
SQLException is thrown somebody writes to stderr, so the next
operation will fail with a "elog" exception on the postgres
side.
Date: 2011-11-13 14:49
Sender: Christian Meier

ok, i have found a workaround. put the standard postgres
jdbc driver into your sqlj classpath and open an very new
connection. of course this could be really bad because you
open an new session.
Date: 2011-11-13 14:49
Sender: Johann Oskarsson

I see. I'll investigate further soon.
Date: 2011-11-13 14:41
Sender: Christian Meier

I have found out, this is not only an prepared statements.
every time you ran into a duplicate key, you are not able to
catch this exception in your java code. save points will not
solve my problem because i have to issue an update in case
of a duplicate key violation. but i am not able to catch
duplicate key exceptions. try/catch blockes have excatly no
effect ...
Date: 2011-11-13 14:35
Sender: Johann Oskarsson

You need to use savepoints around the statements for it not to rollback the entire transaction.

I'm not sure this is a bug and will investigate further.

Attached Files:

Attachments:
trycatch.jar
trycatch.jar

Changes:

Field Old Value Date By
File Added706: trycatch.jar2011-11-30 14:36cikic
File Added705: trycatch.jar2011-11-30 13:36cikic
Powered By FusionForge