List:Commits« Previous MessageNext Message »
From:tikeda Date:January 25 2006 10:33pm
Subject:Connector/J commit: r4849 - branches/branch_5_1/connector-j/src/testsuite/simple
View as plain text  
Modified:
   branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java
Log:
added test method to StatementTest for PreparedStatement.setNString method

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 21:53:57 UTC (rev 4848)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java	2006-01-25 22:33:08 UTC (rev 4849)
@@ -1423,13 +1423,49 @@
      * @throws Exception
      */
     public void testSetNString() throws Exception {
-        this.stmt.executeUpdate("DROP TABLE IF EXISTS testSetNString");
-        this.stmt.executeUpdate("CREATE TABLE testSetNString (c1 NATIONAL CHARACTER(10))");
+        // suppose sql_mode don't include "NO_BACKSLASH_ESCAPES"
         
-        Properties props = new Properties();
-        props.put("useServerPrepStmts", "false");
-        Connection conn = getConnectionWithProps(props);
+        createTable("testSetNString", "(c1 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 (?)");
+        pstmt1.setNString(1, "aaa");
+        pstmt1.execute();
+        pstmt1.setNString(1, "\'aaa");
+        pstmt1.execute();
+        ResultSet rs1 = this.stmt.executeQuery("SELECT c1 FROM testSetNString");
+        rs1.next();
+        assertEquals("aaa", rs1.getString(1));
+        rs1.next();
+        assertEquals("\'aaa", rs1.getString(1));
+        rs1.close();
+        pstmt1.close();
+        conn1.close();
         
+        createTable("testSetNString", "(c1 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");
+        pstmt2.execute();
+        pstmt2.setNString(1, "\'aaa");
+        pstmt2.execute();
+        ResultSet rs2 = this.stmt.executeQuery("SELECT c1 FROM testSetNString");
+        rs2.next();
+        assertEquals("aaa", rs2.getString(1));
+        rs2.next();
+        assertEquals("\'aaa", rs2.getString(1));
+        rs2.close();
+        pstmt2.close();
+        conn2.close();
     }
     
     /**
@@ -1437,7 +1473,43 @@
      * 
      * @throws Exception
      */
-    public void testSetNStringServer() {
+    public void testSetNStringServer() throws Exception {
+        createTable("testSetNStringServer", "(c1 NATIONAL CHARACTER(10))");
+        Properties props1 = new Properties();
+        props1.put("useServerPrepStmts", "true"); // use server-side prepared statement
+        props1.put("useUnicode", "true");
+        props1.put("characterEncoding", "latin1"); // ensure charset isn't utf8 here
+        Connection conn1 = getConnectionWithProps(props1);
+        com.mysql.jdbc.ServerPreparedStatement pstmt1 = (com.mysql.jdbc.ServerPreparedStatement)
+            conn1.prepareStatement("INSERT INTO testSetNStringServer (c1) VALUES (?)");
+        try {
+            pstmt1.setNString(1, "aaa");
+            fail();
+        } catch (SQLException e) {
+            // ok
+        }
+        pstmt1.close();
+        conn1.close();
         
+        createTable("testSetNStringServer", "(c1 NATIONAL CHARACTER(10))");
+        Properties props2 = new Properties();
+        props2.put("useServerPrepStmts", "true"); // use server-side prepared statement
+        props2.put("useUnicode", "true");
+        props2.put("characterEncoding", "UTF-8"); // ensure charset is utf8 here
+        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();
+        conn2.close();
     }
 }

Thread
Connector/J commit: r4849 - branches/branch_5_1/connector-j/src/testsuite/simpletikeda25 Jan