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 km...@apache.org on 2006/04/20 21:54:14 UTC

svn commit: r395687 - in /db/derby/code/branches/10.1/java: drda/org/apache/derby/impl/drda/DRDAConnThread.java engine/org/apache/derby/catalog/SystemProcedures.java

Author: kmarsden
Date: Thu Apr 20 12:54:13 2006
New Revision: 395687

URL: http://svn.apache.org/viewcvs?rev=395687&view=rev
Log:
DERBY-901 Remove use of String(byte[]) constructors in network server leading to non-portable behaviour

Contributed by Sunitha Kambhampati
patch 2

Fix the remaining places that the String(byte[]) constructor is used in Network Server.

remove use of default String(byte[]) constructor in
-- trace method in DRDAConnThread.readAndSetParams to print out the hex string of the bytes .
-- use SQLERRMC_TOKEN_DELIMITER in SQLDIAGCI .

some cleanup
 -- define the SQLERRMC_MESSAGE_DELIMITER in SystemProcedures and use that in DRDAConnThread.

Modified:
    db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/catalog/SystemProcedures.java

Modified: db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=395687&r1=395686&r2=395687&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/branches/10.1/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Thu Apr 20 12:54:13 2006
@@ -44,6 +44,7 @@
 import java.util.Properties;
 import java.util.Vector;
 
+import org.apache.derby.catalog.SystemProcedures;
 import org.apache.derby.iapi.error.ExceptionSeverity;
 import org.apache.derby.iapi.reference.Attribute;
 import org.apache.derby.iapi.reference.JDBC30Translation;
@@ -4122,7 +4123,7 @@
 			{
 				byte[] paramVal = reader.readBytes();
 				if (SanityManager.DEBUG) 
-					trace("fix bytes parameter value is: "+new String(paramVal));
+					trace("fix bytes parameter value is: "+ convertToHexString(paramVal));
 				ps.setBytes(i+1, paramVal);
 				break;
 			}
@@ -5174,14 +5175,7 @@
  	 */
 	private static String SQLERRMC_TOKEN_DELIMITER = new String(new char[] {(char)20});
 	
-    // This token delimiter value is used to separate the tokens for multiple 
-    // error messages.  This is used in SystemProcedures.SQLCAMESSAGE.
-	/**
-	 * <code>SQLERRMC_MESSAGE_DELIMITER</code> When message argument tokes are sent,
-	 * this value separates the tokens for mulitiple error messages 
-	 */
-	private static String SQLERRMC_MESSAGE_DELIMITER = new String(new char[] {(char)20,(char)20,(char)20});
-	
+
 	/**
 	 * <code>SQLERRMC_PREFORMATTED_MESSAGE_DELIMITER</code>, When full message text is 
 	 * sent for severe errors. This value separates the messages. 
@@ -5266,7 +5260,7 @@
 	 * Build Tokenized SQLERRMC to just send the tokenized arguments to the client.
 	 * for a Derby SQLException
 	 * Message argument tokens are separated by SQLERRMC_TOKEN_DELIMITER 
-	 * Multiple messages are separated by SQLERRMC_MESSAGE_DELIMITER
+	 * Multiple messages are separated by SystemProcedures.SQLERRMC_MESSAGE_DELIMITER
 	 * 
 	 *                 ...
 	 * @param se   SQLException to print
@@ -5285,7 +5279,7 @@
 			se = (EmbedSQLException) se.getNextException();
 			if (se != null)
 			{
-				sqlerrmc += SQLERRMC_MESSAGE_DELIMITER + se.getSQLState() + ":";				
+				sqlerrmc += SystemProcedures.SQLERRMC_MESSAGE_DELIMITER + se.getSQLState() + ":";				
 			}
 		} while (se != null);
 		return sqlerrmc;
@@ -5447,13 +5441,10 @@
 			String sqlState = se.getSQLState();
 			int sqlCode = getSqlCode(getExceptionSeverity(se));
 			String sqlerrmc = "";
-			byte[] sep = {20};	// use it as separator of sqlerrmc tokens
-			String separator = new String(sep);
-				
 			// arguments are variable part of a message
 			Object[] args = ((EmbedSQLException)se).getArguments();
 			for (int i = 0; args != null &&  i < args.length; i++)
-				sqlerrmc += args[i].toString() + separator;
+				sqlerrmc += args[i].toString() + SQLERRMC_TOKEN_DELIMITER;
 
 			String dbname = null;
 			if (database != null)

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/catalog/SystemProcedures.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/catalog/SystemProcedures.java?rev=395687&r1=395686&r2=395687&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/catalog/SystemProcedures.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/catalog/SystemProcedures.java Thu Apr 20 12:54:13 2006
@@ -63,6 +63,15 @@
 	private final static int SQL_ROWVER = 2;
 	private final static String DRIVER_TYPE_OPTION = "DATATYPE";
 	private final static String ODBC_DRIVER_OPTION = "'ODBC'";
+    // This token delimiter value is used to separate the tokens for multiple 
+    // error messages.  This is used in DRDAConnThread
+    /**
+     * <code>SQLERRMC_MESSAGE_DELIMITER</code> When message argument tokes are sent,
+     * this value separates the tokens for mulitiple error messages 
+     * Used by Server
+     */
+    public static String SQLERRMC_MESSAGE_DELIMITER = 
+                    new String(new char[] {(char)20,(char)20,(char)20});
 
 	/**
 	  Method used by Cloudscape Network Server to get localized message (original call
@@ -93,18 +102,14 @@
 										String[] msg, int[] rc)
 	{
 		int numMessages = 1;
-        // This corresponds to the DRDAConnThread.SQLERRMC_MESSAGE_DELIMITER
-        // delimiter for multiple messages that are set in sqlerrmc.
-        char[] b = {(char)20, (char)20, (char)20};
-		String errSeparator = new String(b);
 
 		// Figure out if there are multiple exceptions in sqlerrmc. If so get each one
 		// translated and append to make the final result.
 		for (int index=0; ; numMessages++)
 		{
-			if (sqlerrmc.indexOf(errSeparator, index) == -1)
+			if (sqlerrmc.indexOf(SQLERRMC_MESSAGE_DELIMITER, index) == -1)
 				break;
-			index = sqlerrmc.indexOf(errSeparator, index) + errSeparator.length();
+			index = sqlerrmc.indexOf(SQLERRMC_MESSAGE_DELIMITER, index) + SQLERRMC_MESSAGE_DELIMITER.length();
 		}
 
 		// Putting it here instead of prepareCall it directly is because inter-jar reference tool
@@ -120,7 +125,7 @@
 			String[] errMsg = new String[2];
 			for (int i=0; i<numMessages; i++)
 			{
-				endIdx = sqlerrmc.indexOf(errSeparator, startIdx);
+				endIdx = sqlerrmc.indexOf(SQLERRMC_MESSAGE_DELIMITER, startIdx);
 				if (i == numMessages-1)				// last error message
 					sqlError = sqlerrmc.substring(startIdx);
 				else sqlError = sqlerrmc.substring(startIdx, endIdx);
@@ -143,7 +148,7 @@
 						msg[0] = errMsg[0];
 					else msg[0] += errMsg[0];	// append the new message
 				}
-				startIdx = endIdx + errSeparator.length();
+				startIdx = endIdx + SQLERRMC_MESSAGE_DELIMITER.length();
 			}
 		}
 	}