Modified:
branches/v_3_1_10-utf8-clob-fix/connector-j/.project
branches/v_3_1_10-utf8-clob-fix/connector-j/CHANGES
branches/v_3_1_10-utf8-clob-fix/connector-j/src/com/mysql/jdbc/SingleByteCharsetConverter.java
branches/v_3_1_10-utf8-clob-fix/connector-j/src/com/mysql/jdbc/StringUtils.java
branches/v_3_1_10-utf8-clob-fix/connector-j/src/testsuite/regression/StringRegressionTest.java
Log:
Backport of fix for BUG#11614.
Modified: branches/v_3_1_10-utf8-clob-fix/connector-j/.project
===================================================================
(Binary files differ)
Modified: branches/v_3_1_10-utf8-clob-fix/connector-j/CHANGES
===================================================================
--- branches/v_3_1_10-utf8-clob-fix/connector-j/CHANGES 2005-09-01 15:35:12 UTC (rev 4187)
+++ branches/v_3_1_10-utf8-clob-fix/connector-j/CHANGES 2005-09-01 16:12:43 UTC (rev 4188)
@@ -1,6 +1,12 @@
# Changelog
# $Id$
+09-01-05 - Version 3.1.10-stable-utf8-clob-fixes
+
+ - Backport of fix for 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/v_3_1_10-utf8-clob-fix/connector-j/src/com/mysql/jdbc/SingleByteCharsetConverter.java
===================================================================
--- branches/v_3_1_10-utf8-clob-fix/connector-j/src/com/mysql/jdbc/SingleByteCharsetConverter.java 2005-09-01 15:35:12 UTC (rev 4187)
+++ branches/v_3_1_10-utf8-clob-fix/connector-j/src/com/mysql/jdbc/SingleByteCharsetConverter.java 2005-09-01 16:12:43 UTC (rev 4188)
@@ -102,10 +102,6 @@
public static SingleByteCharsetConverter initCharset(String javaEncodingName)
throws UnsupportedEncodingException, SQLException {
- if ("utf8".equals(javaEncodingName)) {
- System.out.println("!");
- }
-
if (CharsetMapping.isMultibyteCharset(javaEncodingName)) {
return null;
}
Modified: branches/v_3_1_10-utf8-clob-fix/connector-j/src/com/mysql/jdbc/StringUtils.java
===================================================================
--- branches/v_3_1_10-utf8-clob-fix/connector-j/src/com/mysql/jdbc/StringUtils.java 2005-09-01 15:35:12 UTC (rev 4187)
+++ branches/v_3_1_10-utf8-clob-fix/connector-j/src/com/mysql/jdbc/StringUtils.java 2005-09-01 16:12:43 UTC (rev 4188)
@@ -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/v_3_1_10-utf8-clob-fix/connector-j/src/testsuite/regression/StringRegressionTest.java
===================================================================
--- branches/v_3_1_10-utf8-clob-fix/connector-j/src/testsuite/regression/StringRegressionTest.java 2005-09-01 15:35:12 UTC (rev 4187)
+++ branches/v_3_1_10-utf8-clob-fix/connector-j/src/testsuite/regression/StringRegressionTest.java 2005-09-01 16:12:43 UTC (rev 4188)
@@ -29,6 +29,7 @@
import testsuite.BaseTestCase;
import testsuite.simple.BlobTest;
+import java.sql.Clob;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
@@ -677,4 +678,69 @@
assertTrue("1.5E-7".equals(StringUtils.fixDecimalExponent("1.5E-7")));
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();
+ }
+ }
+ }
+ }
}
| Thread |
|---|
| • Connector/J commit: r4188 - in branches/v_3_1_10-utf8-clob-fix/connector-j: . src/com/mysql/jdbc src/testsuite/regression | mmatthews | 1 Sep |