Changeset: 7965adb04c49 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7965adb04c49 Modified Files: java/ChangeLog.Dec2011 java/SQLSTATEs java/src/nl/cwi/monetdb/client/JdbcClient.java java/src/nl/cwi/monetdb/jdbc/MonetBlob.java java/src/nl/cwi/monetdb/jdbc/MonetClob.java java/src/nl/cwi/monetdb/jdbc/MonetConnection.java java/src/nl/cwi/monetdb/jdbc/MonetDatabaseMetaData.java java/src/nl/cwi/monetdb/jdbc/MonetDriver.java.in java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java java/src/nl/cwi/monetdb/jdbc/MonetSavepoint.java java/src/nl/cwi/monetdb/jdbc/MonetStatement.java java/src/nl/cwi/monetdb/jdbc/MonetWrapper.java java/src/nl/cwi/monetdb/mcl/io/BufferedMCLReader.java Branch: Dec2011 Log Message:
JDBC: set SQLSTATE for SQLExceptions thrown Since the server doesn't provide us with any SQLSTATE information, the usefulness is limited to exceptions generated by the JDBC driver itself. The set of vendor-specific exceptions and their descriptions that are used in the implementation is listed in the SQLSTATEs file. For all server originated exceptions the generic data exception state (22000) is reported. diffs (truncated from 2161 to 300 lines): diff --git a/java/ChangeLog.Dec2011 b/java/ChangeLog.Dec2011 --- a/java/ChangeLog.Dec2011 +++ b/java/ChangeLog.Dec2011 @@ -1,6 +1,11 @@ # ChangeLog file for java # This file is updated with Maddlog +* Sun Dec 11 2011 Fabian Groffen <[email protected]> +- SQLExceptions thrown now carry a SQLSTATE. Until the server starts + sending correct SQLSTATEs for errors, all server originated errors + are considered generic data exceptions (22000). + * Sat Dec 10 2011 Fabian Groffen <[email protected]> - Fixed a bug where closing ResultSets and PreparedStatements could lead to errors on concurrent running queries using the same Connection due diff --git a/java/SQLSTATEs b/java/SQLSTATEs new file mode 100644 --- /dev/null +++ b/java/SQLSTATEs @@ -0,0 +1,29 @@ +08M01 opening logfile failed +01M02 redirect warning +M0M03 illegal arguments (invalid call of internal function) +01M03 illegal arguments (invalid call of internal function) +M0M04 only supported in SQL mode +M1M05 invalid argument (to JDBC method) +M0M06 savepoint is not MonetSavepoint +01M07 unrecognised clientinfo property +01M08 read-only conection mode not supported +01M09 transaction mode not supported +M0M10 protocol violation/unexpected server response +01M10 unexpected server output +01M11 server-client autocommit state mismatch +M0M12 matching client handle referenced by server not found +01M13 concurrency mode not supported +01M14 scrolling mode not supported +01M15 holdability mode not supported +M1M16 multistatements not supported in batches +M1M17 result set not expected for DML or DDL-statement +01M18 generated keys for columns not supported +M1M19 response is not a result set +M1M20 object closed +01M21 cursors not supported +0AM21 cursors not supported +01M22 JDBC escape syntax not supported +01M23 field size limitation not supported +01M24 query time out not supported +M1M25 failed reading from/writing to object stream +08M26 invalid URI diff --git a/java/src/nl/cwi/monetdb/client/JdbcClient.java b/java/src/nl/cwi/monetdb/client/JdbcClient.java --- a/java/src/nl/cwi/monetdb/client/JdbcClient.java +++ b/java/src/nl/cwi/monetdb/client/JdbcClient.java @@ -554,15 +554,14 @@ copts.produceHelpMessage() executeQuery(query, stmt, out); } catch (SQLException e) { out.flush(); - if (hasFile) { - System.err.println("Error on line " + i + ": " + e.getMessage()); - } else { - System.err.println("Error: " + e.getMessage()); - } - // print all error messages in the chain (if any) - while ((e = e.getNextException()) != null) { - System.err.println(e.getMessage()); - } + do { + if (hasFile) { + System.err.println("Error on line " + i + ": [" + e.getSQLState() + "] " + e.getMessage()); + } else { + System.err.println("Error: [" + e.getSQLState() + "] " + e.getMessage()); + } + // print all error messages in the chain (if any) + } while ((e = e.getNextException()) != null); } query = ""; wasComplete = true; @@ -672,7 +671,10 @@ copts.produceHelpMessage() } } catch (SQLException e) { out.flush(); - System.err.println("Error: " + e.getMessage()); + do { + System.err.println("Error: [" + e.getSQLState() + "] " + e.getMessage()); + // print all error messages in the chain (if any) + } while ((e = e.getNextException()) != null); } } else if (qp.getQuery().startsWith("\\l") || qp.getQuery().startsWith("\\i")) @@ -716,11 +718,14 @@ copts.produceHelpMessage() executeQuery(query, stmt, out); } catch (SQLException e) { out.flush(); - if (hasFile) { - System.err.println("Error on line " + i + ": " + e.getMessage()); - } else { - System.err.println("Error: " + e.getMessage()); - } + do { + if (hasFile) { + System.err.println("Error on line " + i + ": [" + e.getSQLState() + "] " + e.getMessage()); + } else { + System.err.println("Error: [" + e.getSQLState() + "] " + e.getMessage()); + } + // print all error messages in the chain (if any) + } while ((e = e.getNextException()) != null); } query = ""; wasComplete = true; @@ -862,11 +867,11 @@ copts.produceHelpMessage() stmt.executeBatch(); stmt.clearBatch(); } catch (SQLException e) { - System.err.println("Error at line " + i + ": " + e.getMessage()); - // print all error messages in the chain (if any) - while ((e = e.getNextException()) != null) { - System.err.println(e.getMessage()); - } + do { + System.err.println("Error at line " + i + ": [" + + e.getSQLState() + "] " + e.getMessage()); + // print all error messages in the chain (if any) + } while ((e = e.getNextException()) != null); } } diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetBlob.java b/java/src/nl/cwi/monetdb/jdbc/MonetBlob.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetBlob.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetBlob.java @@ -73,7 +73,7 @@ public class MonetBlob implements Blob { */ public InputStream getBinaryStream() throws SQLException { if (buf == null) - throw new SQLException("This Blob object has been freed"); + throw new SQLException("This Blob object has been freed", "M1M20"); return(new ByteArrayInputStream(buf)); } @@ -98,13 +98,13 @@ public class MonetBlob implements Blob { throws SQLException { if (buf == null) - throw new SQLException("This Blob object has been freed"); + throw new SQLException("This Blob object has been freed", "M1M20"); if (pos < 1) - throw new SQLException("pos is less than 1"); + throw new SQLException("pos is less than 1", "M1M05"); if (pos - 1 > buf.length) - throw new SQLException("pos is greater than the number of bytes in the Blob"); + throw new SQLException("pos is greater than the number of bytes in the Blob", "M1M05"); if (pos - 1 + length > buf.length) - throw new SQLException("pos + length is greater than the number of bytes in the Blob"); + throw new SQLException("pos + length is greater than the number of bytes in the Blob", "M1M05"); return(new ByteArrayInputStream(buf, (int)(pos - 1), (int)length)); } @@ -124,14 +124,14 @@ public class MonetBlob implements Blob { */ public byte[] getBytes(long pos, int length) throws SQLException { if (buf == null) - throw new SQLException("This Blob object has been freed"); + throw new SQLException("This Blob object has been freed", "M1M20"); try { byte[] r = new byte[length]; for (int i = 0; i < length; i++) r[i] = buf[(int)pos - 1 + i]; return(r); } catch (IndexOutOfBoundsException e) { - throw new SQLException(e.getMessage()); + throw new SQLException(e.getMessage(), "M0M10"); } } @@ -145,7 +145,7 @@ public class MonetBlob implements Blob { */ public long length() throws SQLException { if (buf == null) - throw new SQLException("This Blob object has been freed"); + throw new SQLException("This Blob object has been freed", "M1M20"); return((long)buf.length); } @@ -180,7 +180,7 @@ public class MonetBlob implements Blob { */ public long position(byte[] pattern, long start) throws SQLException { if (buf == null) - throw new SQLException("This Blob object has been freed"); + throw new SQLException("This Blob object has been freed", "M1M20"); try { for (int i = (int)(start - 1); i < buf.length - pattern.length; i++) { int j; @@ -192,7 +192,7 @@ public class MonetBlob implements Blob { return(i); } } catch (IndexOutOfBoundsException e) { - throw new SQLException(e.getMessage()); + throw new SQLException(e.getMessage(), "M0M10"); } return(-1); } @@ -217,10 +217,10 @@ public class MonetBlob implements Blob { */ public OutputStream setBinaryStream(long pos) throws SQLException { if (buf == null) - throw new SQLException("This Blob object has been freed"); + throw new SQLException("This Blob object has been freed", "M1M20"); if (pos < 1) - throw new SQLException("pos is less than 1"); - throw new SQLFeatureNotSupportedException("Operation setBinaryStream(long pos) currently not supported"); + throw new SQLException("pos is less than 1", "M1M05"); + throw new SQLFeatureNotSupportedException("Operation setBinaryStream(long pos) currently not supported", "0A000"); } /** @@ -262,13 +262,13 @@ public class MonetBlob implements Blob { throws SQLException { if (buf == null) - throw new SQLException("This Blob object has been freed"); + throw new SQLException("This Blob object has been freed", "M1M20"); try { /* transactions? what are you talking about? */ for (int i = (int)pos; i < len; i++) buf[i] = bytes[offset - 1 + i]; } catch (IndexOutOfBoundsException e) { - throw new SQLException(e.getMessage()); + throw new SQLException(e.getMessage(), "M0M10"); } return(len); } @@ -284,7 +284,7 @@ public class MonetBlob implements Blob { */ public void truncate(long len) throws SQLException { if (buf == null) - throw new SQLException("This Blob object has been freed"); + throw new SQLException("This Blob object has been freed", "M1M20"); if (buf.length > len) { byte[] newbuf = new byte[(int)len]; for (int i = 0; i < len; i++) diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetClob.java b/java/src/nl/cwi/monetdb/jdbc/MonetClob.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetClob.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetClob.java @@ -65,7 +65,7 @@ public class MonetClob implements Clob { * not support this method */ public InputStream getAsciiStream() throws SQLException { - throw new SQLFeatureNotSupportedException("Operation getAsciiStream() currently not supported"); + throw new SQLFeatureNotSupportedException("Operation getAsciiStream() currently not supported", "0A000"); } /** @@ -77,7 +77,7 @@ public class MonetClob implements Clob { * not support this method */ public Reader getCharacterStream() throws SQLException { - throw new SQLFeatureNotSupportedException("Operation getCharacterStream() currently not supported"); + throw new SQLFeatureNotSupportedException("Operation getCharacterStream() currently not supported", "0A000"); } /** @@ -95,7 +95,7 @@ public class MonetClob implements Clob { * not support this method */ public Reader getCharacterStream(long pos, long length) throws SQLException { - throw new SQLFeatureNotSupportedException("Operation getCharacterStream(long, long) currently not supported"); + throw new SQLFeatureNotSupportedException("Operation getCharacterStream(long, long) currently not supported", "0A000"); } /** @@ -113,7 +113,7 @@ public class MonetClob implements Clob { */ public String getSubString(long pos, int length) throws SQLException { if (buf == null) - throw new SQLException("This Clob has been freed"); + throw new SQLException("This Clob has been freed", "M1M20"); try { return(buf.substring((int)(pos - 1), (int)(pos - 1 + length))); } catch (IndexOutOfBoundsException e) { @@ -131,7 +131,7 @@ public class MonetClob implements Clob { */ public long length() throws SQLException { if (buf == null) - throw new SQLException("This Clob has been freed"); + throw new SQLException("This Clob has been freed", "M1M20"); return((long)buf.length()); } @@ -167,20 +167,20 @@ public class MonetClob implements Clob { */ public long position(String searchstr, long start) throws SQLException { if (buf == null) - throw new SQLException("This Clob has been freed"); + throw new SQLException("This Clob has been freed", "M1M20"); return((long)(buf.indexOf(searchstr, (int)(start - 1)))); } public OutputStream setAsciiStream(long pos) throws SQLException { if (buf == null) - throw new SQLException("This Clob has been freed"); - throw new SQLException("Operation setAsciiStream(long pos) currently not supported"); + throw new SQLException("This Clob has been freed", "M1M20"); _______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
