db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject svn commit: r1002115 - in /db/derby/code/trunk/java: drda/org/apache/derby/impl/drda/DDMWriter.java drda/org/apache/derby/impl/drda/DRDAConnThread.java testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java
Date Tue, 28 Sep 2010 11:06:41 GMT
Author: tiago
Date: Tue Sep 28 11:06:40 2010
New Revision: 1002115

URL: http://svn.apache.org/viewvc?rev=1002115&view=rev
Log:
DERBY-4746 (Server) Implement UTF8 support on DRDA

Patch DERBY-4746_p3.diff

Changes the way the lengths are obtained for Strings in the DRDA protocol.

Also changes the way the server encodes the RDBNAM parameter when being sent back to the client.

Modified:
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java
    db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java?rev=1002115&r1=1002114&r2=1002115&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DDMWriter.java Tue Sep 28 11:06:40
2010
@@ -919,7 +919,7 @@ class DDMWriter
 	 */
 	void writeScalarPaddedString (int codePoint, String string, int paddedLength)
 	{
-		int stringLength = string.length();
+		int stringLength = ccsidManager.getByteLength(string);
 		int fillLength = paddedLength - stringLength;
 		ensureLength (paddedLength + 4);
 		buffer.putShort((short) (paddedLength + 4));
@@ -937,7 +937,7 @@ class DDMWriter
 	 */
 	protected void writeScalarPaddedString (String string, int paddedLength)
 	{
-		int stringLength = string.length();
+		int stringLength = ccsidManager.getByteLength(string);
 
 		int fillLength = paddedLength -stringLength;
 		ensureLength (paddedLength);
@@ -954,6 +954,7 @@ class DDMWriter
 	 */
 	protected void writeScalarPaddedString (DRDAString drdaString, int paddedLength)
 	{
+	    /* This .length() call is valid as this is a DRDAString */
 		int stringLength = drdaString.length();
 		int fillLength = paddedLength - stringLength;
 		ensureLength(paddedLength);

Modified: db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java?rev=1002115&r1=1002114&r2=1002115&view=diff
==============================================================================
--- db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java (original)
+++ db/derby/code/trunk/java/drda/org/apache/derby/impl/drda/DRDAConnThread.java Tue Sep 28
11:06:40 2010
@@ -575,19 +575,14 @@ class DRDAConnThread extends Thread {
 	protected void writeRDBNAM(String rdbnam)
 		throws DRDAProtocolException
 	{
-		int len = rdbnam.length();
-		if (len < CodePoint.RDBNAM_LEN)
-			len = CodePoint.RDBNAM_LEN;
-		writer.writeScalarHeader(CodePoint.RDBNAM, len);
-		try {
-			writer.writeScalarPaddedBytes(rdbnam.getBytes(server.DEFAULT_ENCODING),
-				len, server.SPACE_CHAR);
-		}
-		catch (UnsupportedEncodingException e)
-		{
-			agentError("Unsupported coding exception for server encoding "
-				+ server.DEFAULT_ENCODING);
-		}
+        CcsidManager currentManager = writer.getCurrentCcsidManager();
+        
+        int len = currentManager.getByteLength(rdbnam);
+        if (len < CodePoint.RDBNAM_LEN)
+        	len = CodePoint.RDBNAM_LEN;
+
+        /* Write the string padded */
+        writer.writeScalarPaddedString(CodePoint.RDBNAM, rdbnam, len);
 	}
 	/***************************************************************************
 	 *                   Private methods
@@ -635,6 +630,9 @@ class DRDAConnThread extends Thread {
 		if (session.state == Session.ATTEXC)
 			sqlamLevel = appRequester.getManagerLevel(CodePoint.SQLAM);
 
+        /* All sessions MUST start as EBCDIC */
+        reader.setEbcdicCcsid();
+        writer.setEbcdicCcsid();
 	}
 	/**      
 	 * In initial state for a session, 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java?rev=1002115&r1=1002114&r2=1002115&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/InternationalConnectTest.java
Tue Sep 28 11:06:40 2010
@@ -224,7 +224,31 @@ public class InternationalConnectTest ex
                 assertSQLState("22005",se);
         } 
     }
-    
+
+    /**
+     * Regression test case for DERBY-4799. Attempting to connect to a
+     * database that doesn't exist used to cause a protocol error between
+     * the network server and the client. This only happened if the
+     * database name was at least 18 characters and the name contained at
+     * least one non-ascii character.
+     */
+    public void testFailureOnNonExistentDatabase() throws SQLException {
+        String url = TestConfiguration.getCurrent().getJDBCUrl(
+                "abcdefghijklmnopq\u00E5");
+        try {
+            // This call used to fail with a protocol error with the
+            // client driver. Check that it fails gracefully now.
+            DriverManager.getConnection(url);
+            fail(url + " should not exist");
+        } catch (SQLException sqle) {
+            // Embedded responds with XJ004 - database not found.
+            // Client responds with 08004 - connection refused because
+            // the database was not found.
+            String expected = usingEmbedded() ? "XJ004" : "08004";
+            assertSQLState(expected, sqle);
+        }
+    }
+
     public void tearDown() throws SQLException {
         String shutdownUrl = TestConfiguration.getCurrent().getJDBCUrl("\u4e10;shutdown=true");
         try {



Mime
View raw message