List:Commits« Previous MessageNext Message »
From:tikeda Date:February 22 2006 12:30am
Subject:Connector/J commit: r4966 - in branches/branch_5_1/connector-j/src: com/mysql/jdbc testsuite/simple
View as plain text  
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:
added PreparedStatement.setNClob() and a testcase

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-02-21 21:34:42 UTC (rev 4965)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java	2006-02-22 00:30:16 UTC (rev 4966)
@@ -2436,14 +2436,46 @@
                     SQLError.SQL_STATE_GENERAL_ERROR);
         }
     }
-
+    
+    /**
+     * JDBC 4.0 Set a NCLOB parameter.
+     * 
+     * @param i
+     *            the first parameter is 1, the second is 2, ...
+     * @param x
+     *            an object representing a NCLOB
+     * 
+     * @throws SQLException
+     *             if a database error occurs
+     */
 	public void setNClob(int parameterIndex, NClob value) throws SQLException {
-		throw new ToBeImplementedException();
+		if (value == null) {
+            setNull(parameterIndex, java.sql.Types.NCLOB);
+        } else {
+            setNCharacterStream(parameterIndex, value.getCharacterStream(), value.length());
+        }
 	}
 
+    /**
+     * JDBC 4.0 Set a NCLOB parameter.
+     * 
+     * @param parameterIndex
+     *            the first parameter is 1, the second is 2, ...
+     * @param reader
+     *            the java reader which contains the UNICODE data
+     * @param length
+     *            the number of characters in the stream
+     * 
+     * @throws SQLException
+     *             if a database error occurs
+     */
 	public void setNClob(int parameterIndex, Reader reader, long length)
 			throws SQLException {
-		throw new ToBeImplementedException();
+        if (reader == null) {
+            setNull(parameterIndex, java.sql.Types.NCLOB);
+        } else {
+            setNCharacterStream(parameterIndex, reader, length);
+        }
 	}
 
     /**

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-21 21:34:42 UTC (rev 4965)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java	2006-02-22 00:30:16 UTC (rev 4966)
@@ -26,12 +26,11 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.CharArrayReader;
-import java.io.File;
-import java.io.FileWriter;
 import java.io.Reader;
 import java.io.StringReader;
 import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.NClob;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -1627,4 +1626,65 @@
         pstmt2.close();
         conn2.close();
     }
+    
+    /**
+     * Tests for PreparedStatement.setNClob()
+     * 
+     * @throws Exception
+     */
+    public void testSetNClob() throws Exception {
+        // suppose sql_mode don't include "NO_BACKSLASH_ESCAPES"
+        
+        createTable("testSetNClob", "(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 testSetNClob (c1, c2, c3) VALUES (?, ?, ?)");
+        pstmt1.setNClob(1, null);
+        NClob nclob2 = conn1.createNClob();
+        nclob2.setString(1, "aaa");
+        pstmt1.setNClob(2, nclob2);
+        NClob nclob3 = conn1.createNClob();
+        nclob3.setString(1, "\'aaa\'");
+        pstmt1.setNClob(3, nclob3);
+        pstmt1.execute();
+        ResultSet rs1 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNClob");
+        rs1.next();
+        assertEquals(null, rs1.getString(1));
+        assertEquals("aaa", rs1.getString(2));
+        assertEquals("\'aaa\'", rs1.getString(3));
+        rs1.close();
+        pstmt1.close();
+        conn1.close();
+        
+        createTable("testSetNClob", "(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 testSetNClob (c1, c2, c3) VALUES (?, ?, ?)");
+        pstmt2.setNClob(1, null);
+        nclob2 = conn2.createNClob();
+        nclob2.setString(1, "aaa");
+        pstmt2.setNClob(2, nclob2);
+        nclob3 = conn2.createNClob();
+        nclob3.setString(1, "\'aaa\'");
+        pstmt2.setNClob(3, nclob3);
+        pstmt2.execute();
+        ResultSet rs2 = this.stmt.executeQuery("SELECT c1, c2, c3 FROM testSetNClob");
+        rs2.next();
+        assertEquals(null, rs2.getString(1));
+        assertEquals("aaa", rs2.getString(2));
+        assertEquals("\'aaa\'", rs2.getString(3));
+        rs2.close();
+        pstmt2.close();
+        conn2.close();
+    }
 }

Thread
Connector/J commit: r4966 - in branches/branch_5_1/connector-j/src: com/mysql/jdbc testsuite/simpletikeda22 Feb