List:Commits« Previous MessageNext Message »
From:tikeda Date:January 25 2006 8:18pm
Subject:Connector/J commit: r4845 - 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/Connection.java
   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.setNString(int,String)

Modified: branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java
===================================================================
--- branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java	2006-01-25 19:45:33 UTC (rev 4844)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/Connection.java	2006-01-25 20:18:50 UTC (rev 4845)
@@ -3557,7 +3557,8 @@
 
 		String nativeSql = getProcessEscapeCodesForPrepStmts() ? nativeSQL(sql)
 				: sql;
-
+System.out.println("prepareStatement: sql=" + sql);
+System.out.println("prepareStatement: nativeSql=" + nativeSql);
 		if (getEmulateUnsupportedPstmts()) {
 			canServerPrepare = canHandleAsServerPreparedStatement(nativeSql);
 		}
@@ -3576,6 +3577,7 @@
 
 			if (pStmt == null) {
 				try {
+System.out.println("Connection.java trying to create ServerPreparedStatement");
 					pStmt = new com.mysql.jdbc.ServerPreparedStatement(this,
 							nativeSql, this.database);
 					if (this.getCachePreparedStatements()
@@ -3583,6 +3585,8 @@
 						((com.mysql.jdbc.ServerPreparedStatement) pStmt).isCached = true;
 					}
 				} catch (SQLException sqlEx) {
+System.out.println("Connection.java catching SQLException during creating ServerPreparedStatement");
+sqlEx.printStackTrace();
 					// Punt, if necessary
 					if (getEmulateUnsupportedPstmts()) {
 						pStmt = clientPrepareStatement(nativeSql);

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 19:45:33 UTC (rev 4844)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java	2006-01-25 20:18:50 UTC (rev 4845)
@@ -83,6 +83,11 @@
  */
 public class PreparedStatement extends com.mysql.jdbc.Statement implements
 		java.sql.PreparedStatement {
+    
+    static {
+        System.out.println("5.1 PreparedStatement is loaded");
+    }
+    
 	class BatchParams {
 		boolean[] isNull = null;
 
@@ -300,6 +305,9 @@
 					}
 				}
 			}
+            for (int j = 0; j < staticSql.length; j++) {
+                System.out.println("staticSql[" + j + "]=" + new String(staticSql[j]));
+            }
 		}
 	}
 
@@ -692,6 +700,8 @@
 	 *                if a database access error occurs
 	 */
 	public boolean execute() throws SQLException {
+try{
+System.out.println("execute() invoked");
 		if (this.connection.isReadOnly() && (this.firstCharOfStmt != 'S')) {
 			throw SQLError.createSQLException(Messages
 					.getString("PreparedStatement.20") //$NON-NLS-1$
@@ -794,6 +804,10 @@
 		}
 
 		return ((rs != null) && rs.reallyResult());
+} catch (SQLException ex) {
+    ex.printStackTrace();
+    throw ex;
+}
 	}
 
 	/**
@@ -2410,11 +2424,118 @@
 		throw new ToBeImplementedException();
 	}
 
-	public void setNString(int parameterIndex, String value)
+    /**
+     * Set a parameter to a Java String value. The driver converts this to a SQL
+     * VARCHAR or LONGVARCHAR value with character set utf8 (depending on the 
+     * arguments size relative to the driver's limits on VARCHARs) when it 
+     * sends it to the database.
+     * 
+     * @param parameterIndex
+     *            the first parameter is 1...
+     * @param x
+     *            the parameter value
+     * 
+     * @exception SQLException
+     *                if a database access error occurs
+     */
+	public void setNString(int parameterIndex, String x)
 			throws SQLException {
-		throw new ToBeImplementedException();
-	}
+        if (this.charEncoding.equalsIgnoreCase("UTF-8")
+                || this.charEncoding.equalsIgnoreCase("utf8")) {
+            setString(parameterIndex, x);
+            return;
+        }
+        // if the passed string is null, then set this column to null
+        if (x != null) {
+            int stringLength = x.length();
+            StringBuffer buf = new StringBuffer((int) (x.length() * 1.1 + 4));
+            // Add introducer _utf8 for NATIONAL CHARACTER
+            buf.append("_utf8");
+            buf.append('\'');
 
+            //
+            // Note: buf.append(char) is _faster_ than
+            // appending in blocks, because the block
+            // append requires a System.arraycopy()....
+            // go figure...
+            //
+
+            for (int i = 0; i < stringLength; ++i) {
+                char c = x.charAt(i);
+
+                switch (c) {
+                case 0: /* Must be escaped for 'mysql' */
+                    buf.append('\\');
+                    buf.append('0');
+
+                    break;
+
+                case '\n': /* Must be escaped for logs */
+                    buf.append('\\');
+                    buf.append('n');
+
+                    break;
+
+                case '\r':
+                    buf.append('\\');
+                    buf.append('r');
+
+                    break;
+
+                case '\\':
+                    buf.append('\\');
+                    buf.append('\\');
+
+                    break;
+
+                case '\'':
+                    buf.append('\\');
+                    buf.append('\'');
+
+                    break;
+
+                case '"': /* Better safe than sorry */
+                    if (this.usingAnsiMode) {
+                        buf.append('\\');
+                    }
+
+                    buf.append('"');
+
+                    break;
+
+                case '\032': /* This gives problems on Win32 */
+                    buf.append('\\');
+                    buf.append('Z');
+
+                    break;
+
+                default:
+                    buf.append(c);
+                }
+            }
+
+            buf.append('\'');
+
+            String parameterAsString = buf.toString();
+
+            byte[] parameterAsBytes = null;
+            System.out.println("buf= " + buf.toString());
+            if (!this.isLoadDataQuery) {
+                // Use "UTF-8" for NATIONAL CHARACTER
+                parameterAsBytes = StringUtils.getBytes(parameterAsString,
+                        this.connection.getCharsetConverter("UTF-8"), "UTF-8", this.connection
+                                .getServerCharacterEncoding(), this.connection
+                                .parserKnowsUnicode());
+            } else {
+                // Send with platform character encoding
+                parameterAsBytes = parameterAsString.getBytes();
+            }
+            setInternal(parameterIndex, parameterAsBytes);
+        } else {
+            setNull(parameterIndex, Types.CHAR);
+        }
+    }
+
 	/**
 	 * Set a parameter to SQL NULL
 	 * 
@@ -2991,13 +3112,13 @@
 	 *                if a database access error occurs
 	 */
 	public void setString(int parameterIndex, String x) throws SQLException {
+System.out.println("setString invoked");
 		// if the passed string is null, then set this column to null
-		if (x == null) {
-			setNull(parameterIndex, Types.CHAR);
-		} else {
+		if (x != null) {
 			int stringLength = x.length();
-
+System.out.println("this.connection.isNoBackslashEscapesSet() = " + this.connection.isNoBackslashEscapesSet());
 			if (this.connection.isNoBackslashEscapesSet()) {
+            //if (false) {
 				// Scan for any nasty chars
 
 				boolean needsHexEscape = false;
@@ -3093,7 +3214,10 @@
 			// append requires a System.arraycopy()....
 			// go figure...
 			//
-
+/*
+String y = x; x = "";
+buf.append(y);
+System.out.println("hiya");stringLength = x.length();*/
 			for (int i = 0; i < stringLength; ++i) {
 				char c = x.charAt(i);
 
@@ -3153,7 +3277,7 @@
 			String parameterAsString = buf.toString();
 
 			byte[] parameterAsBytes = null;
-
+            System.out.println("buf= " + buf.toString());
 			if (!this.isLoadDataQuery) {
 				parameterAsBytes = StringUtils.getBytes(parameterAsString,
 						this.charConverter, this.charEncoding, this.connection
@@ -3163,8 +3287,10 @@
 				// Send with platform character encoding
 				parameterAsBytes = parameterAsString.getBytes();
 			}
-
+System.out.println("buf= " + buf.toString());
 			setInternal(parameterIndex, parameterAsBytes);
+		} else {
+			setNull(parameterIndex, Types.CHAR);
 		}
 	}
 

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-25 19:45:33 UTC (rev 4844)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/ServerPreparedStatement.java	2006-01-25 20:18:50 UTC (rev 4845)
@@ -1851,17 +1851,16 @@
 	 */
 	public void setString(int parameterIndex, String x) throws SQLException {
 		checkClosed();
-
+System.out.println("ServerPreparedStatement.setString(int,String) is invoked");
 		if (x == null) {
 			setNull(parameterIndex, java.sql.Types.CHAR);
 		} else {
 			BindValue binding = getBinding(parameterIndex, false);
-
 			setType(binding, this.stringTypeCode);
-
 			binding.value = x;
 			binding.isNull = false;
 			binding.isLongData = false;
+System.out.println("binding.toString() = " + binding.toString());
 		}
 	}
 

Thread
Connector/J commit: r4845 - branches/branch_5_1/connector-j/src/com/mysql/jdbctikeda25 Jan