Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/UpdatableResultSet.java
branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java
Log:
modified(added) testcases StatementTest.testUpdateNString()/testUpdateNCharacterStream()/testUpdateNClob(), modified UpdatableResultSet.updateNString(int, String)/updateString(int, String)
Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/UpdatableResultSet.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/UpdatableResultSet.java 2006-02-25 01:01:50 UTC (rev 4988)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/UpdatableResultSet.java 2006-02-25 01:52:22 UTC (rev 4989)
@@ -1801,6 +1801,12 @@
*/
public synchronized void updateNCharacterStream(int columnIndex,
java.io.Reader x, int length) throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException(
+ "Can not call updateNCharacterStream() when field's character set isn't UTF-8");
+ }
+
if (!this.onInsertRow) {
if (!this.doingUpdates) {
this.doingUpdates = true;
@@ -1867,6 +1873,11 @@
*/
public void updateNClob(int columnIndex, java.sql.NClob nClob)
throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException("Can not call updateNClob() when field's character set isn't UTF-8");
+ }
+
if (nClob == null) {
updateNull(columnIndex);
} else {
@@ -2390,14 +2401,10 @@
if (x == null) {
this.thisRow[columnIndex - 1] = null;
} else {
- if (getCharConverter() != null) {
- this.thisRow[columnIndex - 1] = StringUtils.getBytes(x,
- this.charConverter, this.charEncoding,
- this.connection.getServerCharacterEncoding(),
- this.connection.parserKnowsUnicode());
- } else {
- this.thisRow[columnIndex - 1] = x.getBytes();
- }
+ this.thisRow[columnIndex - 1] = StringUtils.getBytes(x,
+ this.charConverter, this.fields[columnIndex - 1].getCharacterSet(),
+ this.connection.getServerCharacterEncoding(),
+ this.connection.parserKnowsUnicode());
}
}
}
@@ -2437,6 +2444,11 @@
*/
public synchronized void updateNString(int columnIndex, String x)
throws SQLException {
+ String fieldEncoding = this.fields[columnIndex - 1].getCharacterSet();
+ if (fieldEncoding == null || !fieldEncoding.equals("UTF-8")) {
+ throw new SQLException("Can not call updateNString() when field's character set isn't UTF-8");
+ }
+
if (!this.onInsertRow) {
if (!this.doingUpdates) {
this.doingUpdates = true;
@@ -2450,7 +2462,10 @@
if (x == null) {
this.thisRow[columnIndex - 1] = null;
} else {
- this.thisRow[columnIndex - 1] = x.getBytes();
+ this.thisRow[columnIndex - 1] = StringUtils.getBytes(x,
+ this.charConverter, fieldEncoding,
+ this.connection.getServerCharacterEncoding(),
+ this.connection.parserKnowsUnicode());
}
}
}
Modified: branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java
===================================================================
--- branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java 2006-02-25 01:01:50 UTC (rev 4988)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java 2006-02-25 01:52:22 UTC (rev 4989)
@@ -1444,11 +1444,11 @@
// suppose sql_mode don't include "NO_BACKSLASH_ESCAPES"
createTable("testSetNString", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
- "c3 NATIONAL CHARACTER(10))");
+ "c3 NATIONAL CHARACTER(10)) DEFAULT CHARACTER SET cp932");
Properties props1 = new Properties();
props1.put("useServerPrepStmts", "false"); // use client-side prepared statement
props1.put("useUnicode", "true");
- props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
+ props1.put("characterEncoding", "MS932"); // ensure charset isn't utf8 here
Connection conn1 = getConnectionWithProps(props1);
com.mysql.jdbc.PreparedStatement pstmt1 = (com.mysql.jdbc.PreparedStatement)
conn1.prepareStatement("INSERT INTO testSetNString (c1, c2, c3) VALUES (?, ?, ?)");
@@ -1466,7 +1466,7 @@
conn1.close();
createTable("testSetNString", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
- "c3 NATIONAL CHARACTER(10))");
+ "c3 NATIONAL CHARACTER(10)) DEFAULT CHARACTER SET cp932");
Properties props2 = new Properties();
props2.put("useServerPrepStmts", "false"); // use client-side prepared statement
props2.put("useUnicode", "true");
@@ -1824,7 +1824,7 @@
"(c1 CHAR(10) PRIMARY KEY, c2 NATIONAL CHARACTER(10)) default character set sjis");
Properties props1 = new Properties();
props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
- props1.put("characterEncoding", "UTF-8"); // ensure charset isn't utf8 here
+ props1.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
Connection conn1 = getConnectionWithProps(props1);
PreparedStatement pstmt1 = conn1.prepareStatement(
"INSERT INTO testUpdateNString (c1, c2) VALUES (?, ?)");
@@ -1850,6 +1850,32 @@
pstmt1.close();
stmt1.close();
conn1.close();
+
+ createTable("testUpdateNString",
+ "(c1 CHAR(10) PRIMARY KEY, c2 CHAR(10)) default character set sjis"); // sjis field
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props2.put("characterEncoding", "SJIS"); // ensure charset isn't utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 = conn2.prepareStatement(
+ "INSERT INTO testUpdateNString (c1, c2) VALUES (?, ?)");
+ pstmt2.setString(1, "1");
+ pstmt2.setString(2, "aaa");
+ pstmt2.execute();
+ Statement stmt2 = conn2.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs3 = stmt2.executeQuery("SELECT c1, c2 FROM testUpdateNString");
+ rs3.next();
+ try {
+ rs3.updateNString("c2", "bbb"); // field's charset isn't utf8
+ fail();
+ } catch (SQLException ex) {
+ assertEquals("Can not call updateNString() when field's character set isn't UTF-8",
+ ex.getMessage());
+ }
+ rs3.close();
+ pstmt2.close();
+ stmt2.close();
+ conn2.close();
}
/**
@@ -1888,6 +1914,32 @@
pstmt1.close();
stmt1.close();
conn1.close();
+
+ createTable("testUpdateNCharacterStream",
+ "(c1 CHAR(10) PRIMARY KEY, c2 CHAR(10)) default character set sjis"); // sjis field
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props2.put("characterEncoding", "SJIS"); // ensure charset isn't utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 = conn2.prepareStatement(
+ "INSERT INTO testUpdateNCharacterStream (c1, c2) VALUES (?, ?)");
+ pstmt2.setString(1, "1");
+ pstmt2.setString(2, "aaa");
+ pstmt2.execute();
+ Statement stmt2 = conn2.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs3 = stmt2.executeQuery("SELECT c1, c2 FROM testUpdateNCharacterStream");
+ rs3.next();
+ try {
+ rs3.updateNCharacterStream("c2", new StringReader("bbb"), 3); // field's charset isn't utf8
+ fail();
+ } catch (SQLException ex) {
+ assertEquals("Can not call updateNCharacterStream() when field's character set isn't UTF-8",
+ ex.getMessage());
+ }
+ rs3.close();
+ pstmt2.close();
+ stmt2.close();
+ conn2.close();
}
/**
@@ -1932,5 +1984,33 @@
pstmt1.close();
stmt1.close();
conn1.close();
+
+ createTable("testUpdateNChlob",
+ "(c1 CHAR(10) PRIMARY KEY, c2 CHAR(10)) default character set sjis"); // sjis field
+ Properties props2 = new Properties();
+ props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+ props2.put("characterEncoding", "SJIS"); // ensure charset isn't utf8 here
+ Connection conn2 = getConnectionWithProps(props2);
+ PreparedStatement pstmt2 = conn2.prepareStatement(
+ "INSERT INTO testUpdateNChlob (c1, c2) VALUES (?, ?)");
+ pstmt2.setString(1, "1");
+ pstmt2.setString(2, "aaa");
+ pstmt2.execute();
+ Statement stmt2 = conn2.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+ ResultSet rs3 = stmt2.executeQuery("SELECT c1, c2 FROM testUpdateNChlob");
+ rs3.next();
+ NClob nClob4 = conn2.createNClob();
+ nClob4.setString(1, "bbb");
+ try {
+ rs3.updateNClob("c2", nClob4); // field's charset isn't utf8
+ fail();
+ } catch (SQLException ex) {
+ assertEquals("Can not call updateNClob() when field's character set isn't UTF-8",
+ ex.getMessage());
+ }
+ rs3.close();
+ pstmt2.close();
+ stmt2.close();
+ conn2.close();
}
}
| Thread |
|---|
| • Connector/J commit: r4989 - in branches/branch_5_1/connector-j/src: com/mysql/jdbc testsuite/simple | tikeda | 25 Feb |