Modified:
branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java
branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java
Log:
upgraded PreparedStatement.setNString and test
Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-01-25 23:33:08 UTC (rev 4853)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java 2006-01-26 00:03:23 UTC (rev 4854)
@@ -2430,16 +2430,11 @@
setString(parameterIndex, x);
return;
}
-
+
// if the passed string is null, then set this column to null
if (x == null) {
- //setNull(parameterIndex, Types.NCHAR);
- x = "null";
- this.isNull[parameterIndex - 1] = true;
- }
-
-
- //} else {
+ setNull(parameterIndex, -8); // -8 is the value of Types.NCHAR
+ } else {
int stringLength = x.length();
// Ignore sql_mode=NO_BACKSLASH_ESCAPES in current implementation.
@@ -2526,7 +2521,7 @@
}
setInternal(parameterIndex, parameterAsBytes);
- //}
+ }
}
/**
Modified: branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java
===================================================================
--- branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java 2006-01-25 23:33:08 UTC (rev 4853)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java 2006-01-26 00:03:23 UTC (rev 4854)
@@ -1425,44 +1425,46 @@
public void testSetNString() throws Exception {
// suppose sql_mode don't include "NO_BACKSLASH_ESCAPES"
- createTable("testSetNString", "(c1 NATIONAL CHARACTER(10))");
+ createTable("testSetNString", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
+ "c3 NATIONAL CHARACTER(10))");
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
Connection conn1 = getConnectionWithProps(props1);
com.mysql.jdbc.PreparedStatement pstmt1 = (com.mysql.jdbc.PreparedStatement)
- conn1.prepareStatement("INSERT INTO testSetNString (c1) VALUES (?)");
+ conn1.prepareStatement("INSERT INTO testSetNString (c1, c2, c3) VALUES (?, ?, ?)");
pstmt1.setNString(1, null);
+ pstmt1.setNString(2, "aaa");
+ pstmt1.setNString(3, "\'aaa\'");
pstmt1.execute();
- pstmt1.setNString(1, "aaa");
- pstmt1.execute();
- pstmt1.setNString(1, "\'aaa\'");
- pstmt1.execute();
- ResultSet rs1 = this.stmt.executeQuery("SELECT c1 FROM testSetNString");
+ ResultSet rs1 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNString");
rs1.next();
- assertEquals("null", rs1.getString(1));
- rs1.next();
- assertEquals("aaa", rs1.getString(1));
- rs1.next();
- assertEquals("\'aaa\'", rs1.getString(1));
+ assertEquals(null, rs1.getString(1));
+ assertEquals("aaa", rs1.getString(2));
+ assertEquals("\'aaa\'", rs1.getString(3));
rs1.close();
pstmt1.close();
conn1.close();
- createTable("testSetNString", "(c1 NATIONAL CHARACTER(10))");
+ createTable("testSetNString", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10), " +
+ "c3 NATIONAL CHARACTER(10))");
Properties props2 = new Properties();
props2.put("useServerPrepStmts", "false"); // use client-side prepared statement
props2.put("useUnicode", "true");
props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
Connection conn2 = getConnectionWithProps(props2);
com.mysql.jdbc.PreparedStatement pstmt2 = (com.mysql.jdbc.PreparedStatement)
- conn2.prepareStatement("INSERT INTO testSetNString (c1) VALUES (?)");
- pstmt2.setNString(1, "\'aaa\'");
+ conn2.prepareStatement("INSERT INTO testSetNString (c1, c2, c3) VALUES (?, ?, ?)");
+ pstmt2.setNString(1, null);
+ pstmt2.setNString(2, "aaa");
+ pstmt2.setNString(3, "\'aaa\'");
pstmt2.execute();
- ResultSet rs2 = this.stmt.executeQuery("SELECT c1 FROM testSetNString");
+ ResultSet rs2 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNString");
rs2.next();
- assertEquals("\'aaa\'", rs2.getString(1));
+ assertEquals(null, rs2.getString(1));
+ assertEquals("aaa", rs2.getString(2));
+ assertEquals("\'aaa\'", rs2.getString(3));
rs2.close();
pstmt2.close();
conn2.close();
@@ -1501,14 +1503,10 @@
Connection conn2 = getConnectionWithProps(props2);
com.mysql.jdbc.ServerPreparedStatement pstmt2 = (com.mysql.jdbc.ServerPreparedStatement)
conn2.prepareStatement("INSERT INTO testSetNStringServer (c1) VALUES (?)");
- pstmt2.setNString(1, "aaa");
- pstmt2.execute();
pstmt2.setNString(1, "\'aaa\'");
pstmt2.execute();
ResultSet rs2 = this.stmt.executeQuery("SELECT c1 FROM testSetNStringServer");
rs2.next();
- assertEquals("aaa", rs2.getString(1));
- rs2.next();
assertEquals("\'aaa\'", rs2.getString(1));
rs2.close();
pstmt2.close();
| Thread |
|---|
| • Connector/J commit: r4854 - in branches/branch_5_1/connector-j/src: com/mysql/jdbc testsuite/simple | tikeda | 26 Jan |