You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ka...@apache.org on 2014/02/25 09:47:24 UTC
svn commit: r1571615 - in /db/derby/code/trunk/java:
client/org/apache/derby/client/am/SqlException.java
engine/org/apache/derby/iapi/error/StandardException.java
testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java
Author: kahatlen
Date: Tue Feb 25 08:47:23 2014
New Revision: 1571615
URL: http://svn.apache.org/r1571615
Log:
DERBY-6484: Include SQLState in client exception messages
Modified:
db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java
Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java?rev=1571615&r1=1571614&r2=1571615&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/SqlException.java Tue Feb 25 08:47:23 2014
@@ -346,6 +346,13 @@ public class SqlException extends Except
return sqlca_;
}
+ @Override
+ public String toString() {
+ // Match what the embedded driver does in StandardException.toString().
+ return "ERROR " + getSQLState() + ": " + getMessage();
+ }
+
+ @Override
public String getMessage() {
if ( wrappedException_ != null )
{
Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java?rev=1571615&r1=1571614&r2=1571615&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/error/StandardException.java Tue Feb 25 08:47:23 2014
@@ -581,8 +581,9 @@ public class StandardException extends E
Don't print the class name in the toString() method.
*/
public String toString() {
+ // Add the SQLState to the message. This should be kept consistent
+ // with SqlException.toString() in the client driver.
String msg = getMessage();
-
return "ERROR " + getSQLState() + ": " + msg;
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java?rev=1571615&r1=1571614&r2=1571615&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/SqlExceptionTest.java Tue Feb 25 08:47:23 2014
@@ -32,6 +32,7 @@ import org.apache.derby.shared.common.re
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
+import java.sql.SQLDataException;
import java.sql.SQLException;
import java.io.IOException;
import java.io.ByteArrayInputStream;
@@ -102,6 +103,29 @@ public class SqlExceptionTest extends Ba
assertEquals(internalException, javae.getCause().getCause());
}
+ public void testSQLStateInRootException() throws SQLException {
+ String expectedSQLState = "22018";
+ Statement s = createStatement();
+ try {
+ s.execute("values cast('hello' as int)");
+ fail();
+ } catch (SQLDataException sqle) {
+ assertSQLState(expectedSQLState, sqle);
+
+ // Check message of the root cause (a StandardException on embedded
+ // and an SqlException on the client). Client didn't include
+ // the SQLState before DERBY-6484.
+ Throwable cause = sqle;
+ while (cause instanceof SQLException) {
+ cause = cause.getCause();
+ }
+ String toString = cause.toString();
+ assertTrue("Message should start with the SQLState, found: "
+ + toString,
+ toString.startsWith("ERROR " + expectedSQLState + ":"));
+ }
+ }
+
/**
* Verify that a SQLException generated by the derby network client
* driver can be serialized (DERBY-790).