List:Commits« Previous MessageNext Message »
From:tikeda Date:February 24 2006 12:57am
Subject:Connector/J commit: r4977 - 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/ResultSet.java
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/UpdatableResultSet.java
   branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java
Log:
Added ResultSet.updateNXXX()

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ResultSet.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ResultSet.java	2006-02-23 01:02:35 UTC (rev 4976)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ResultSet.java	2006-02-24 00:57:48 UTC (rev 4977)
@@ -7903,30 +7903,30 @@
 
 	public void updateNCharacterStream(int columnIndex, Reader x, int length)
 			throws SQLException {
-		throw new ToBeImplementedException();
+        throw new NotUpdatable();
 	}
 
 	public void updateNCharacterStream(String columnName, Reader reader,
 			int length) throws SQLException {
-		throw new ToBeImplementedException();
+		updateNCharacterStream(findColumn(columnName), reader, length);
 	}
 
 	public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
-		throw new ToBeImplementedException();
+        throw new NotUpdatable();
 	}
 
 	public void updateNClob(String columnName, NClob nClob) throws SQLException {
-		throw new ToBeImplementedException();
+		updateNClob(findColumn(columnName), nClob);
 	}
 
 	public void updateNString(int columnIndex, String nString)
 			throws SQLException {
-		throw new ToBeImplementedException();
+        throw new NotUpdatable();
 	}
 
 	public void updateNString(String columnName, String nString)
 			throws SQLException {
-		throw new ToBeImplementedException();
+		updateNString(findColumn(columnName), nString);
 	}
 
 	/**

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-23 01:02:35 UTC (rev 4976)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/UpdatableResultSet.java	2006-02-24 00:57:48 UTC (rev 4977)
@@ -1781,7 +1781,66 @@
 			java.io.Reader reader, int length) throws SQLException {
 		updateCharacterStream(findColumn(columnName), reader, length);
 	}
+    
+    /**
+     * JDBC 4.0 Update a column with a character stream value. The updateXXX()
+     * methods are used to update column values in the current row, or the
+     * insert row. The updateXXX() methods do not update the underlying
+     * database, instead the updateRow() or insertRow() methods are called to
+     * update the database.
+     * 
+     * @param columnIndex
+     *            the first column is 1, the second is 2, ...
+     * @param x
+     *            the new column value
+     * @param length
+     *            the length of the stream
+     * 
+     * @exception SQLException
+     *                if a database-access error occurs
+     */
+    public synchronized void updateNCharacterStream(int columnIndex,
+            java.io.Reader x, int length) throws SQLException {
+        if (!this.onInsertRow) {
+            if (!this.doingUpdates) {
+                this.doingUpdates = true;
+                syncUpdate();
+            }
 
+            this.updater.setNCharacterStream(columnIndex, x, length);
+        } else {
+            this.inserter.setNCharacterStream(columnIndex, x, length);
+
+            if (x == null) {
+                this.thisRow[columnIndex - 1] = null;
+            } else {
+                this.thisRow[columnIndex - 1] = STREAM_DATA_MARKER;
+            }
+        }
+    }
+    
+    /**
+     * JDBC 4.0 Update a column with a character stream value. The updateXXX()
+     * methods are used to update column values in the current row, or the
+     * insert row. The updateXXX() methods do not update the underlying
+     * database, instead the updateRow() or insertRow() methods are called to
+     * update the database.
+     * 
+     * @param columnName
+     *            the name of the column
+     * @param reader
+     *            the new column value
+     * @param length
+     *            of the stream
+     * 
+     * @exception SQLException
+     *                if a database-access error occurs
+     */
+    public synchronized void updateNCharacterStream(String columnName,
+            java.io.Reader reader, int length) throws SQLException {
+        updateNCharacterStream(findColumn(columnName), reader, length);
+    }
+
 	/**
 	 * @see ResultSet#updateClob(int, Clob)
 	 */
@@ -1794,6 +1853,35 @@
 					(int) clob.length());
 		}
 	}
+    
+    /**
+     * @see ResultSet#updateClob(int, Clob)
+     */
+    public void updateClob(String columnName, java.sql.Clob clob)
+            throws SQLException {
+        updateClob(findColumn(columnName), clob);
+    }
+    
+    /**
+     * @see ResultSet#updateClob(int, Clob)
+     */
+    public void updateNClob(int columnIndex, java.sql.NClob nClob)
+            throws SQLException {
+        if (nClob == null) {
+            updateNull(columnIndex);
+        } else {
+            updateNCharacterStream(columnIndex, nClob.getCharacterStream(),
+                    (int) nClob.length());
+        }
+    }
+    
+    /**
+     * @see ResultSet#updateClob(int, Clob)
+     */
+    public void updateNClob(String columnName, java.sql.NClob nClob)
+            throws SQLException {
+        updateNClob(findColumn(columnName), nClob);
+    }
 
 	/**
 	 * JDBC 2.0 Update a column with a Date value. The updateXXX() methods are
@@ -2332,7 +2420,60 @@
 			throws SQLException {
 		updateString(findColumn(columnName), x);
 	}
+    
+    /**
+     * JDBC 4.0 Update a column with NATIONAL CHARACTER. The updateXXX() methods are
+     * used to update column values in the current row, or the insert row. The
+     * updateXXX() methods do not update the underlying database, instead the
+     * updateRow() or insertRow() methods are called to update the database.
+     * 
+     * @param columnIndex
+     *            the first column is 1, the second is 2, ...
+     * @param x
+     *            the new column value
+     * 
+     * @exception SQLException
+     *                if a database-access error occurs
+     */
+    public synchronized void updateNString(int columnIndex, String x)
+            throws SQLException {
+        if (!this.onInsertRow) {
+            if (!this.doingUpdates) {
+                this.doingUpdates = true;
+                syncUpdate();
+            }
 
+            this.updater.setNString(columnIndex, x);
+        } else {
+            this.inserter.setNString(columnIndex, x);
+
+            if (x == null) {
+                this.thisRow[columnIndex - 1] = null;
+            } else {
+                this.thisRow[columnIndex - 1] = x.getBytes();
+            }
+        }
+    }
+    
+    /**
+     * JDBC 4.0 Update a column with NATIONAL CHARACTER. The updateXXX() methods are
+     * used to update column values in the current row, or the insert row. The
+     * updateXXX() methods do not update the underlying database, instead the
+     * updateRow() or insertRow() methods are called to update the database.
+     * 
+     * @param columnName
+     *            the name of the column
+     * @param x
+     *            the new column value
+     * 
+     * @exception SQLException
+     *                if a database-access error occurs
+     */
+    public synchronized void updateNString(String columnName, String x)
+            throws SQLException {
+        updateNString(findColumn(columnName), x);
+    }
+
 	/**
 	 * JDBC 2.0 Update a column with a Time value. The updateXXX() methods are
 	 * used to update column values in the current row, or the insert row. The

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-23 01:02:35 UTC (rev 4976)
+++ branches/branch_5_1/connector-j/src/testsuite/simple/StatementsTest.java	2006-02-24 00:57:48 UTC (rev 4977)
@@ -1799,7 +1799,7 @@
         assertEquals("bbb", new String(c2));
         this.rs.close();
         
-        // for isBinaryEncoded = true
+        // for isBinaryEncoded = true, using PreparedStatement
         createTable("testGetNClob", "(c1 NATIONAL CHARACTER(10), c2 NATIONAL CHARACTER(10))");
         this.stmt.executeUpdate("INSERT INTO testGetNClob (c1, c2) VALUES (_utf8 'aaa', _utf8 'bbb')");
         this.pstmt = this.conn.prepareStatement("SELECT c1, c2 FROM testGetNClob");
@@ -1813,4 +1813,124 @@
         assertEquals("bbb", new String(c2));
         this.rs.close();
     }
+    
+    /**
+     * Tests for ResultSet.updateNString()
+     * 
+     * @throws Exception
+     */
+    public void testUpdateNString() throws Exception {
+        createTable("testUpdateNString", 
+                "(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
+        Connection conn1 = getConnectionWithProps(props1);
+        PreparedStatement pstmt1 = conn1.prepareStatement(
+                "INSERT INTO testUpdateNString (c1, c2) VALUES (?, ?)");
+        pstmt1.setString(1, "1");
+        pstmt1.setNString(2, "aaa");
+        pstmt1.execute();
+        Statement stmt1 = conn1.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs1 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNString");
+        rs1.next();
+        rs1.updateNString("c2", "bbb");
+        rs1.updateRow();
+        rs1.moveToInsertRow();
+        rs1.updateString("c1", "2");
+        rs1.updateNString("c2", "ccc");
+        rs1.insertRow();
+        ResultSet rs2 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNString");
+        rs2.next();
+        assertEquals("1", rs2.getString("c1"));
+        assertEquals("bbb", rs2.getNString("c2"));
+        rs2.next();
+        assertEquals("2", rs2.getString("c1"));
+        assertEquals("ccc", rs2.getNString("c2"));
+        pstmt1.close();
+        stmt1.close();
+        conn1.close();
+    }
+    
+    /**
+     * Tests for ResultSet.updateNCharacterStream()
+     * 
+     * @throws Exception
+     */
+    public void testUpdateNCharacterStream() throws Exception {
+        createTable("testUpdateNCharacterStream", 
+                "(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
+        Connection conn1 = getConnectionWithProps(props1);
+        PreparedStatement pstmt1 = conn1.prepareStatement(
+                "INSERT INTO testUpdateNCharacterStream (c1, c2) VALUES (?, ?)");
+        pstmt1.setString(1, "1");
+        pstmt1.setNCharacterStream(2, new StringReader("aaa"), 3);
+        pstmt1.execute();
+        Statement stmt1 = conn1.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs1 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNCharacterStream");
+        rs1.next();
+        rs1.updateNCharacterStream("c2", new StringReader("bbb"), 3);
+        rs1.updateRow();
+        rs1.moveToInsertRow();
+        rs1.updateString("c1", "2");
+        rs1.updateNCharacterStream("c2", new StringReader("ccc"), 3);
+        rs1.insertRow();
+        ResultSet rs2 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNCharacterStream");
+        rs2.next();
+        assertEquals("1", rs2.getString("c1"));
+        assertEquals("bbb", rs2.getNString("c2"));
+        rs2.next();
+        assertEquals("2", rs2.getString("c1"));
+        assertEquals("ccc", rs2.getNString("c2"));
+        pstmt1.close();
+        stmt1.close();
+        conn1.close();
+    }
+    
+    /**
+     * Tests for ResultSet.updateNClob()
+     * 
+     * @throws Exception
+     */
+    public void testUpdateNChlob() throws Exception {
+        createTable("testUpdateNChlob", 
+                "(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
+        Connection conn1 = getConnectionWithProps(props1);
+        PreparedStatement pstmt1 = conn1.prepareStatement(
+                "INSERT INTO testUpdateNChlob (c1, c2) VALUES (?, ?)");
+        pstmt1.setString(1, "1");
+        NClob nClob1 = conn1.createNClob();
+        nClob1.setString(1, "aaa");
+        pstmt1.setNClob(2, nClob1);
+        pstmt1.execute();
+        Statement stmt1 = conn1.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
+        ResultSet rs1 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNChlob");
+        rs1.next();
+        NClob nClob2 = conn1.createNClob();
+        nClob2.setString(1, "bbb");
+        rs1.updateNClob("c2", nClob2);
+        rs1.updateRow();
+        rs1.moveToInsertRow();
+        rs1.updateString("c1", "2");
+        NClob nClob3 = conn1.createNClob();
+        nClob3.setString(1, "ccc");
+        rs1.updateNClob("c2", nClob3);
+        rs1.insertRow();
+        ResultSet rs2 = stmt1.executeQuery("SELECT c1, c2 FROM testUpdateNChlob");
+        rs2.next();
+        assertEquals("1", rs2.getString("c1"));
+        assertEquals("bbb", rs2.getNString("c2"));
+        rs2.next();
+        assertEquals("2", rs2.getString("c1"));
+        assertEquals("ccc", rs2.getNString("c2"));
+        pstmt1.close();
+        stmt1.close();
+        conn1.close();
+    }
 }

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