List:Internals« Previous MessageNext Message »
From:mmatthews Date:August 2 2005 8:01pm
Subject:Connector/J commit: r4009 - in branches/branch_3_1/connector-j: . src/com/mysql/jdbc src/testsuite/regression
View as plain text  
Modified:
   branches/branch_3_1/connector-j/CHANGES
   branches/branch_3_1/connector-j/src/com/mysql/jdbc/StringUtils.java
   branches/branch_3_1/connector-j/src/testsuite/regression/StringRegressionTest.java
Log:
Fix for BUG#11614 - StringUtils.getBytes() doesn't work
when using multibyte character encodings and a length in 
_characters_ is specified.

Modified: branches/branch_3_1/connector-j/CHANGES
===================================================================
--- branches/branch_3_1/connector-j/CHANGES	2005-08-02 00:07:33 UTC (rev 4008)
+++ branches/branch_3_1/connector-j/CHANGES	2005-08-02 18:01:20 UTC (rev 4009)
@@ -20,7 +20,27 @@
     
     - Fixed BUG#11797 - Escape tokenizer doesn't respect stacked single quotes
 	  for escapes.
+	  
+	- GEOMETRY type not recognized when using server-side prepared statements.
+    
+    - Fixed BUG#11879 -- ReplicationConnection won't switch to slave, throws 
+      "Catalog can't be null" exception.
       
+    - Fixed BUG#12218, properties shared between master and slave with 
+      replication connection.
+      
+    - Fixed BUG#10630, Statement.getWarnings() fails with NPE if statement 
+      has been closed.
+      
+    - Only get char[] from SQL in PreparedStatement.ParseInfo() when needed.
+    
+    - Fixed BUG#12104 - Geometry types not handled with server-side prepared 
+      statements.
+      
+    - Fixed BUG#11614 - StringUtils.getBytes() doesn't work when using 
+      multibyte character encodings and a length in  _characters_ is 
+      specified.
+      
 06-23-05 - Version 3.1.10-stable
 
 	- Fixed connecting without a database specified raised an exception

Modified: branches/branch_3_1/connector-j/src/com/mysql/jdbc/StringUtils.java
===================================================================
--- branches/branch_3_1/connector-j/src/com/mysql/jdbc/StringUtils.java	2005-08-02
00:07:33 UTC (rev 4008)
+++ branches/branch_3_1/connector-j/src/com/mysql/jdbc/StringUtils.java	2005-08-02
18:01:20 UTC (rev 4009)
@@ -408,17 +408,21 @@
 			if (converter != null) {
 				b = converter.toBytes(c, offset, length);
 			} else if (encoding == null) {
-				byte[] temp = new String(c).getBytes();
+				byte[] temp = new String(c, offset, length).getBytes();
 
+				length = temp.length;
+				
 				b = new byte[length];
-				System.arraycopy(temp, offset, b, 0, length);
+				System.arraycopy(temp, 0, b, 0, length);
 			} else {
-				String s = new String(c);
+				String s = new String(c, offset, length);
 
 				byte[] temp = s.getBytes(encoding);
 
+				length = temp.length;
+				
 				b = new byte[length];
-				System.arraycopy(temp, offset, b, 0, length);
+				System.arraycopy(temp, 0, b, 0, length);
 
 				if (!parserKnowsUnicode && (encoding.equalsIgnoreCase("SJIS") //$NON-NLS-1$
 						|| encoding.equalsIgnoreCase("BIG5") //$NON-NLS-1$
@@ -539,16 +543,22 @@
 			if (converter != null) {
 				b = converter.toBytes(s, offset, length);
 			} else if (encoding == null) {
-				byte[] temp = s.getBytes();
+				byte[] temp = s.substring(offset, offset + length).getBytes();
 
+				length = temp.length;
+				
 				b = new byte[length];
-				System.arraycopy(temp, offset, b, 0, length);
+				System.arraycopy(temp, 0, b, 0, length);
 			} else {
-				byte[] temp = s.getBytes(encoding);
 
+				byte[] temp = s.substring(offset, offset + length)
+					.getBytes(encoding);
+
+				length = temp.length;
+				
 				b = new byte[length];
-				System.arraycopy(temp, offset, b, 0, length);
-
+				System.arraycopy(temp, 0, b, 0, length);
+				
 				if (!parserKnowsUnicode && (encoding.equalsIgnoreCase("SJIS") //$NON-NLS-1$
 						|| encoding.equalsIgnoreCase("BIG5") //$NON-NLS-1$
 				|| encoding.equalsIgnoreCase("GBK"))) { //$NON-NLS-1$

Modified:
branches/branch_3_1/connector-j/src/testsuite/regression/StringRegressionTest.java
===================================================================
---
branches/branch_3_1/connector-j/src/testsuite/regression/StringRegressionTest.java	2005-08-02
00:07:33 UTC (rev 4008)
+++
branches/branch_3_1/connector-j/src/testsuite/regression/StringRegressionTest.java	2005-08-02
18:01:20 UTC (rev 4009)
@@ -32,6 +32,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.sql.Clob;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
@@ -681,6 +682,71 @@
 		assertTrue("1.5E+7".equals(StringUtils.fixDecimalExponent("1.5E7")));
 	}
 	
+	/**
+	 * Tests fix for BUG#11614 - StringUtils.getBytes() doesn't work
+	 * when using multibyte character encodings and a length in 
+	 * _characters_ is specified.
+	 * 
+	 * @throws Exception if the test fails.
+	 */
+	public void testBug11614() throws Exception {
+		if (versionMeetsMinimum(4, 1)) {
+			createTable("testBug11614", "(`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,"
+					+ "`text` TEXT NOT NULL,"
+					+ "PRIMARY KEY(`id`)) CHARACTER SET utf8 COLLATE utf8_general_ci");
+			
+			Properties props = new Properties();
+			props.setProperty("characterEncoding", "utf8");
+			
+			Connection utf8Conn = null;
+			
+			try {
+				utf8Conn = getConnectionWithProps(props);
+	
+				utf8Conn.createStatement().executeUpdate("INSERT INTO testBug11614  (`id`,`text`)
values (1,'')");
+				this.rs = utf8Conn.createStatement().executeQuery("SELECT `text` FROM testBug11614
WHERE id=1");
+				assertTrue(this.rs.next());
+				
+				Clob c = this.rs.getClob(1);
+				c.truncate(0);
+				int blockSize = 8192;
+				int sizeToTest = blockSize + 100;
+				
+				StringBuffer blockBuf = new StringBuffer(sizeToTest);
+				
+				for (int i = 0; i < sizeToTest; i++) {
+					blockBuf.append('\u00f6');
+				}
+				
+				String valueToTest = blockBuf.toString();
+				
+				c.setString(1, valueToTest);
+				this.pstmt = utf8Conn.prepareStatement ("UPDATE testBug11614 SET `text` = ? WHERE
id=1");
+				this.pstmt.setClob ( 1, c );
+				this.pstmt.executeUpdate();
+				this.pstmt.close();
+				
+				String fromDatabase = getSingleIndexedValueWithQuery(utf8Conn, 1, "SELECT `text` FROM
testBug11614").toString();
+				assertEquals(valueToTest, fromDatabase);
+			} finally {
+				if (this.rs != null) {
+					this.rs.close();
+					this.rs = null;
+				}
+				
+				if (this.pstmt != null) {
+					this.pstmt.close();
+					
+					this.pstmt = null;
+				}
+				
+				if (utf8Conn != null) {
+					utf8Conn.close();
+				}
+			}
+		}
+	}
+	
 	public void testBug11629() throws Exception {
 		PrintStream oldOut = System.out;
 		PrintStream oldError = System.err;

Thread
Connector/J commit: r4009 - in branches/branch_3_1/connector-j: . src/com/mysql/jdbc src/testsuite/regressionmmatthews2 Aug