From 0378a269f3ab3c44e67b14f96414b6ca95263263 Mon Sep 17 00:00:00 2001 From: Barry Lind Date: Mon, 8 Sep 2003 17:30:22 +0000 Subject: This set of changes applies a patch from KHO at redhat to add some SQLState support to the jdbc driver. That patch needed some work: it assumed the sqlcode in a server message was fixed in its position, the patch lost the ability to pass exceptions, and the patch missed a couple of places where server errors where being received. In addition to fixing the above, I also added full support for the V3 protocol error message syntax, I reversed the order of arguments in the PSQLException constructor to more closely follow the constructors for SQLException, I changed the new constructors that take PSQLState to take Object for additional parameters as the old ones did. Still todo are to add SQLState values to all existing exceptions thrown in the driver and add support for parsing the V3 protocol format for notices. Modified Files: jdbc/build.xml jdbc/org/postgresql/Driver.java.in jdbc/org/postgresql/errors.properties jdbc/org/postgresql/core/Encoding.java jdbc/org/postgresql/core/PGStream.java jdbc/org/postgresql/core/QueryExecutor.java jdbc/org/postgresql/fastpath/Fastpath.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java jdbc/org/postgresql/jdbc1/AbstractJdbc1ResultSet.java jdbc/org/postgresql/jdbc1/AbstractJdbc1Statement.java jdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java jdbc/org/postgresql/jdbc2/AbstractJdbc2Statement.java jdbc/org/postgresql/util/MessageTranslator.java jdbc/org/postgresql/util/PSQLException.java --- .../jdbc/org/postgresql/fastpath/Fastpath.java | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/interfaces/jdbc/org/postgresql/fastpath') diff --git a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java index 1b250a2bf70..08015d18dbf 100644 --- a/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java +++ b/src/interfaces/jdbc/org/postgresql/fastpath/Fastpath.java @@ -6,7 +6,7 @@ * Copyright (c) 2003, PostgreSQL Global Development Group * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/Fastpath.java,v 1.14 2003/05/29 04:39:51 barry Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/fastpath/Attic/Fastpath.java,v 1.15 2003/09/08 17:30:22 barry Exp $ * *------------------------------------------------------------------------- */ @@ -20,6 +20,7 @@ import org.postgresql.Driver; import org.postgresql.core.BaseConnection; import org.postgresql.core.PGStream; import org.postgresql.util.PSQLException; +import org.postgresql.util.PSQLState; /* * This class implements the Fastpath api. @@ -100,14 +101,14 @@ public class Fastpath } catch (IOException ioe) { - throw new PSQLException("postgresql.fp.send", new Integer(fnid), ioe); + throw new PSQLException("postgresql.fp.send", PSQLState.COMMUNICATION_ERROR, new Integer(fnid), ioe); } // Now handle the result // Now loop, reading the results Object result = null; // our result - StringBuffer errorMessage = null; + PSQLException error = null; int c; boolean l_endQuery = false; while (!l_endQuery) @@ -124,11 +125,16 @@ public class Fastpath //------------------------------ // Error message returned case 'E': - if ( errorMessage == null ) - errorMessage = new StringBuffer(); - int l_elen = stream.ReceiveIntegerR(4); - errorMessage.append(conn.getEncoding().decode(stream.Receive(l_elen-4))); + String totalMessage = conn.getEncoding().decode(stream.Receive(l_elen-4)); + PSQLException l_error = PSQLException.parseServerError(totalMessage); + + if (error != null) { + error.setNextException(l_error); + } else { + error = l_error; + } + break; //------------------------------ // Notice from backend @@ -165,7 +171,7 @@ public class Fastpath case 'Z': //TODO: use size better - if (stream.ReceiveIntegerR(4) != 5) throw new PSQLException("postgresql.con.setup"); + if (stream.ReceiveIntegerR(4) != 5) throw new PSQLException("postgresql.con.setup", PSQLState.CONNECTION_UNABLE_TO_CONNECT); //TODO: handle transaction status char l_tStatus = (char)stream.ReceiveChar(); l_endQuery = true; @@ -176,8 +182,8 @@ public class Fastpath } } - if ( errorMessage != null ) - throw new PSQLException("postgresql.fp.error", errorMessage.toString()); + if ( error != null ) + throw error; return result; } @@ -208,7 +214,8 @@ public class Fastpath } catch (IOException ioe) { - throw new PSQLException("postgresql.fp.send", new Integer(fnid), ioe); + //Should be sending exception as second arg. + throw new PSQLException("postgresql.fp.send", PSQLState.COMMUNICATION_ERROR, new Integer(fnid), ioe); } // Now handle the result -- cgit v1.2.3