Changeset: f78aa88aafe7 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f78aa88aafe7
Modified Files:
        java/src/nl/cwi/monetdb/jdbc/MonetConnection.java
        java/src/nl/cwi/monetdb/mcl/net/MapiSocket.java
Branch: Dec2011
Log Message:

Connection: properly handle login errors

Make sure we don't return SQLSTATEs in exception messages.  MCL doesn't
know about SQLSTATEs, so it won't ever be sensical for it to return
them.  Hence, like for IOExceptions and MCLParseExceptions, make sure we
don't have to skip the SQLSTATE ever.


diffs (40 lines):

diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java 
b/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java
--- a/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java
+++ b/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java
@@ -30,6 +30,7 @@ import java.net.SocketTimeoutException;
 import nl.cwi.monetdb.mcl.io.*;
 import nl.cwi.monetdb.mcl.net.*;
 import nl.cwi.monetdb.mcl.parser.*;
+import nl.cwi.monetdb.mcl.MCLException;
 
 /**
  * A Connection suitable for the MonetDB database.
@@ -216,8 +217,15 @@ public class MonetConnection extends Mon
                                throw new SQLException(error.substring(6), 
"08001");
                } catch (IOException e) {
                        throw new SQLException("Unable to connect (" + hostname 
+ ":" + port + "): " + e.getMessage(), "08006");
-               } catch (Exception e) {
+               } catch (MCLParseException e) {
                        throw new SQLException(e.getMessage(), "08001");
+               } catch (MCLException e) {
+                       String[] connex = e.getMessage().split("\n");
+                       SQLException sqle = new SQLException(connex[0], 
"08001", e);
+                       for (int i = 1; i < connex.length; i++) {
+                               sqle.setNextException(new 
SQLException(connex[1], "08001"));
+                       }
+                       throw sqle;
                }
 
                // we seem to have managed to log in, let's store the
diff --git a/java/src/nl/cwi/monetdb/mcl/net/MapiSocket.java 
b/java/src/nl/cwi/monetdb/mcl/net/MapiSocket.java
--- a/java/src/nl/cwi/monetdb/mcl/net/MapiSocket.java
+++ b/java/src/nl/cwi/monetdb/mcl/net/MapiSocket.java
@@ -284,7 +284,7 @@ public final class MapiSocket {
                                                
con.getInetAddress().getHostName() + ":" +
                                                con.getPort() + ": End of 
stream reached");
                        if ((lineType = reader.getLineType()) == 
BufferedMCLReader.ERROR) {
-                               err += "\n" + tmp.substring(1);
+                               err += "\n" + tmp.substring(7);
                        } else if (lineType == BufferedMCLReader.INFO) {
                                warns.add(tmp.substring(1));
                        } else if (lineType == BufferedMCLReader.REDIRECT) {
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to