List:Commits« Previous MessageNext Message »
From:mmatthews Date:July 19 2006 2:18am
Subject:Connector/J commit: r5532 - in branches/branch_5_1/connector-j/src: com/mysql/jdbc testsuite/regression
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/regression/StatementRegressionTest.java
Log:
Merge from 5.0 - Fixed BUG 20888 - escape of quotes in client-side prepared 
	  statements parsing not respected. Patch covers more than bug report, 
	  including NO_BACKSLASH_ESCAPES being set, and stacked quote characters
	  forms of escaping (i.e. '' or "").

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-07-19 02:17:07 UTC (rev 5531)
+++ branches/branch_5_1/connector-j/src/com/mysql/jdbc/PreparedStatement.java	2006-07-19 02:18:23 UTC (rev 5532)
@@ -174,13 +174,12 @@
 			int lastParmEnd = 0;
 			int i;
 
-			int pre1 = 0;
-			int pre2 = 0;
-
 			int stopLookingForLimitClause = this.statementLength - 5;
 
 			this.foundLimitClause = false;
-
+			
+			boolean noBackslashEscapes = connection.isNoBackslashEscapesSet();
+			
 			for (i = 0; i < this.statementLength; ++i) {
 				char c = sql.charAt(i);
 
@@ -190,32 +189,38 @@
 					this.firstStmtChar = Character.toUpperCase(c);
 				}
 
+				if (!noBackslashEscapes &&
+						c == '\\' && i < (this.statementLength - 1)) {
+					i++;
+					continue; // next character is escaped
+				}
+				
 				// are we in a quoted identifier?
 				// (only valid when the id is not inside a 'string')
 				if (!inQuotes && (quotedIdentifierChar != 0)
 						&& (c == quotedIdentifierChar)) {
 					inQuotedId = !inQuotedId;
-				}
-
-				// only respect quotes when not in a quoted identifier
-				if (!inQuotedId) {
+				} else if (!inQuotedId) {
+					//	only respect quotes when not in a quoted identifier
+					
 					if (inQuotes) {
-						if ((((c == '\'') || (c == '"')) && c == quoteChar)
-								&& (pre1 == '\\') && (pre2 != '\\')) {
+						if (((c == '\'') || (c == '"')) && c == quoteChar) {
+							if (i < (this.statementLength - 1) && sql.charAt(i + 1) == quoteChar) {
+								i++; 
+								continue; // inline quote escape
+							}
+							
 							inQuotes = !inQuotes;
 							quoteChar = 0;
-						} else if ((((c == '\'') || (c == '"')) && c == quoteChar)
-								&& (pre1 != '\\')) {
+						} else if (((c == '\'') || (c == '"')) && c == quoteChar) {
 							inQuotes = !inQuotes;
 							quoteChar = 0;
 						}
 					} else {
-						if (((c == '\'') || (c == '"')) && (pre1 == '\\')
-								&& (pre2 != '\\')) {
+						if ((c == '\'') || (c == '"')) {
 							inQuotes = true;
 							quoteChar = c;
-						} else if (((c == '\'') || (c == '"'))
-								&& (pre1 != '\\')) {
+						} else if ((c == '\'') || (c == '"')) {
 							inQuotes = true;
 							quoteChar = c;
 						}
@@ -248,9 +253,6 @@
 						}
 					}
 				}
-
-				pre2 = pre1;
-				pre1 = c;
 			}
 
 			if (this.firstStmtChar == 'L') {

Modified: branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java
===================================================================
--- branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java	2006-07-19 02:17:07 UTC (rev 5531)
+++ branches/branch_5_1/connector-j/src/testsuite/regression/StatementRegressionTest.java	2006-07-19 02:18:23 UTC (rev 5532)
@@ -3237,4 +3237,25 @@
 		}
 	}
 
+	/**
+	 * Tests fix for BUG#20888 - escape of quotes in client-side prepared 
+	 * statements parsing not respected.
+	 * 
+	 * @throws Exception if the test fails.
+	 */
+	public void testBug20888() throws Exception {
+		
+		try {
+			String s = "SELECT 'What do you think about D\\'Artanian''?', \"What do you think about D\\\"Artanian\"\"?\"";
+			this.pstmt = ((com.mysql.jdbc.Connection)this.conn).clientPrepareStatement(s);
+
+			this.rs = this.pstmt.executeQuery();
+			this.rs.next();
+			assertEquals(this.rs.getString(1), "What do you think about D'Artanian'?");
+			assertEquals(this.rs.getString(2), "What do you think about D\"Artanian\"?");
+		} finally {
+			closeMemberJDBCResources();
+		}
+	}
+
 }

Thread
Connector/J commit: r5532 - in branches/branch_5_1/connector-j/src: com/mysql/jdbc testsuite/regressionmmatthews19 Jul