List:Commits« Previous MessageNext Message »
From:tikeda Date:January 27 2006 1:13am
Subject:Connector/J commit: r4862 - branches/branch_5_1/connector-j/src/com/mysql/jdbc
View as plain text  
Modified:
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java
   branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
Log:
implemented PreparedStatement.setNCharacterStream(), ServerPreparedStatement.setNCharacterStream() and those test methods

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-27 01:03:42 UTC (rev 4861)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java	2006-01-27 01:13:13 UTC (rev 4862)
@@ -2396,11 +2396,70 @@
 		setInternal(parameterIndex, String.valueOf(x));
 	}
 
-	public void setNCharacterStream(int parameterIndex, Reader value,
+    /**
+     * JDBC 2.0 When a very large UNICODE value is input to a LONGVARCHAR
+     * parameter, it may be more practical to send it via a java.io.Reader. JDBC
+     * will read the data from the stream as needed, until it reaches
+     * end-of-file. The JDBC driver will do any necessary conversion from
+     * UNICODE to the database char format.
+     * 
+     * <P>
+     * <B>Note:</B> This stream object can either be a standard Java stream
+     * object or your own subclass that implements the standard interface.
+     * </p>
+     * 
+     * @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
+     * 
+     * @exception SQLException
+     *                if a database-access error occurs.
+     */
+	public void setNCharacterStream(int parameterIndex, Reader reader,
 			long length) throws SQLException {
-		throw new ToBeImplementedException();
-	}
+        try {
+            if (reader == null) {
+                setNull(parameterIndex, -10 /* Types.LONGNVARCHAR */);
+                
+            } else {
+                char[] c = null;
+                int len = 0;
 
+                boolean useLength = this.connection
+                        .getUseStreamLengthsInPrepStmts();
+                
+                // Ignore "clobCharacterEncoding" because utf8 should be used this time.
+
+                if (useLength && (length != -1)) {
+                    c = new char[(int) length];
+
+                    int numCharsRead = readFully(reader, c, (int) length); // blocks
+                    // until
+                    // all
+                    // read
+                    setNString(parameterIndex, new String(c, 0, numCharsRead));
+
+                } else {
+                    c = new char[4096];
+
+                    StringBuffer buf = new StringBuffer();
+
+                    while ((len = reader.read(c)) != -1) {
+                        buf.append(c, 0, len);
+                    }
+
+                    setNString(parameterIndex, buf.toString());
+                }
+            }
+        } catch (java.io.IOException ioEx) {
+            throw SQLError.createSQLException(ioEx.toString(),
+                    SQLError.SQL_STATE_GENERAL_ERROR);
+        }
+    }
+
 	public void setNClob(int parameterIndex, NClob value) throws SQLException {
 		throw new ToBeImplementedException();
 	}

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2006-01-27 01:03:42 UTC (rev 4861)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2006-01-27 01:13:13 UTC (rev 4862)
@@ -1643,6 +1643,21 @@
 			}
 		}
 	}
+    
+    /**
+     * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader,
+     *      long)
+     */
+    public void setNCharacterStream(int parameterIndex, Reader reader, long length)
+            throws SQLException {
+        if (this.charEncoding.equalsIgnoreCase("UTF-8")
+                || this.charEncoding.equalsIgnoreCase("utf8")) {
+            setCharacterStream(parameterIndex, reader, (int) length);
+        } else {
+            throw SQLError.createSQLException(
+                "Can not call setNCharacterStream() when connection character set isn't UTF-8");
+        }
+    }
 
 	/**
 	 * @see java.sql.PreparedStatement#setClob(int, java.sql.Clob)

Thread
Connector/J commit: r4862 - branches/branch_5_1/connector-j/src/com/mysql/jdbctikeda27 Jan