From: <le...@us...> - 2008-07-10 19:51:41
|
Revision: 4883 http://jython.svn.sourceforge.net/jython/?rev=4883&view=rev Author: leosoto Date: 2008-07-10 12:51:37 -0700 (Thu, 10 Jul 2008) Log Message: ----------- zxJDBC: Map SQLExceptions to zxJDBC.IntegrityError if the sqlState says the exception was caused by a integrity violation Modified Paths: -------------- branches/asm/src/com/ziclix/python/sql/zxJDBC.java Modified: branches/asm/src/com/ziclix/python/sql/zxJDBC.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/zxJDBC.java 2008-07-10 05:12:05 UTC (rev 4882) +++ branches/asm/src/com/ziclix/python/sql/zxJDBC.java 2008-07-10 19:51:37 UTC (rev 4883) @@ -331,7 +331,22 @@ * @return PyException */ public static PyException makeException(Throwable throwable) { - return makeException(Error, throwable); + PyObject type = Error; + if (throwable instanceof SQLException) { + String state = ((SQLException)throwable).getSQLState(); + // The SQL standard is not freely available, but + // http://www.postgresql.org/docs/current/static/errcodes-appendix.html + // contains most of the SQLSTATES codes + if (state.length() == 5) { // Otherwise, the state is not following the standard. + if (state.startsWith("23")) { //Class 23 => Integrity Constraint Violation + type = IntegrityError; + } else if (state.equals("40002")) { + // 40002 => TRANSACTION INTEGRITY CONSTRAINT VIOLATION + type = IntegrityError; + } + } + } + return makeException(type, throwable); } /** @@ -342,15 +357,15 @@ * @return PyException */ public static PyException makeException(PyObject type, Throwable t) { - return makeException(type, t, -1); + return makeException(type, t, -1); } - + /** * Return a newly instantiated PyException of the given type. * * @param type * @param t - * @param rowIndex Row index where the error has happened. Useful for diagnosing. + * @param rowIndex Row index where the error has happened. Useful for diagnosing. * @return PyException */ public static PyException makeException(PyObject type, Throwable t, int rowIndex) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |