Modified:
branches/branch_5_0/connector-j/src/com/mysql/jdbc/EscapeProcessor.java
branches/branch_5_0/connector-j/src/testsuite/regression/CallableStatementRegressionTest.java
trunk/connector-j/src/com/mysql/jdbc/EscapeProcessor.java
trunk/connector-j/src/testsuite/regression/CallableStatementRegressionTest.java
Log:
Driver now supports {call sp} (without "()" if procedure has no arguments).
Modified: branches/branch_5_0/connector-j/src/com/mysql/jdbc/EscapeProcessor.java
===================================================================
--- branches/branch_5_0/connector-j/src/com/mysql/jdbc/EscapeProcessor.java 2006-09-13
00:01:02 UTC (rev 5724)
+++ branches/branch_5_0/connector-j/src/com/mysql/jdbc/EscapeProcessor.java 2006-09-13
14:28:38 UTC (rev 5725)
@@ -443,17 +443,32 @@
int startPos = StringUtils.indexOfIgnoreCase(token,
"CALL") + 5;
int endPos = token.length() - 1;
-
+
if (StringUtils.startsWithIgnoreCase(collapsedToken,
"{?=call")) {
callingStoredFunction = true;
newSql.append("SELECT ");
- newSql.append(token.substring(startPos, endPos));
+ newSql.append(token, startPos, endPos);
} else {
callingStoredFunction = false;
newSql.append("CALL ");
- newSql.append(token.substring(startPos, endPos));
+ newSql.append(token, startPos, endPos);
}
+
+ for (int i = endPos - 1; i >= startPos; i--) {
+ char c = token.charAt(i);
+
+ if (Character.isWhitespace(c)) {
+ continue;
+ }
+
+ if (c != ')') {
+ newSql.append("()"); // handle no-parenthesis no-arg call not supported
+ // by MySQL parser
+ }
+
+ break;
+ }
} else if (StringUtils.startsWithIgnoreCase(collapsedToken,
"{oj")) {
// MySQL already handles this escape sequence
Modified:
branches/branch_5_0/connector-j/src/testsuite/regression/CallableStatementRegressionTest.java
===================================================================
---
branches/branch_5_0/connector-j/src/testsuite/regression/CallableStatementRegressionTest.java 2006-09-13
00:01:02 UTC (rev 5724)
+++
branches/branch_5_0/connector-j/src/testsuite/regression/CallableStatementRegressionTest.java 2006-09-13
14:28:38 UTC (rev 5725)
@@ -657,6 +657,61 @@
}
}
+ /**
+ * Tests fix for BUG#21462 - JDBC (and ODBC) specifications allow no-parenthesis
+ * CALL statements for procedures with no arguments, MySQL server does not.
+ *
+ * @throws Exception if the test fails.
+ */
+ public void testBug21462() throws Exception {
+ if (versionMeetsMinimum(5, 0)) {
+ CallableStatement cstmt = null;
+
+ try {
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug21462");
+ this.stmt.executeUpdate("CREATE PROCEDURE testBug21462() BEGIN SELECT 1; END");
+ cstmt = this.conn.prepareCall("{CALL testBug21462}");
+ cstmt.execute();
+ } finally {
+ if (cstmt != null) {
+ cstmt.close();
+ }
+
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug21462");
+ }
+ }
+ }
+
+ /**
+ * Tests fix for BUG#22024 - Newlines causing whitespace to span confuse
+ * procedure parser when getting parameter metadata for stored procedures.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug22024() throws Exception {
+ if (versionMeetsMinimum(5, 0)) {
+ CallableStatement cstmt = null;
+
+ try {
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug22024");
+ this.stmt.executeUpdate("CREATE PROCEDURE testBug22024(\r\n)\r\n BEGIN SELECT 1;
END");
+ cstmt = this.conn.prepareCall("{CALL testBug22024()}");
+ cstmt.execute();
+
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug22024");
+ this.stmt.executeUpdate("CREATE PROCEDURE testBug22024(\r\na INT)\r\n BEGIN SELECT 1;
END");
+ cstmt = this.conn.prepareCall("{CALL testBug22024(?)}");
+ cstmt.setInt(1, 1);
+ cstmt.execute();
+ } finally {
+ if (cstmt != null) {
+ cstmt.close();
+ }
+
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug22024");
+ }
+ }
+ }
public void testHugeNumberOfParameters() throws Exception {
if (versionMeetsMinimum(5, 0)) {
this.stmt
Modified: trunk/connector-j/src/com/mysql/jdbc/EscapeProcessor.java
===================================================================
--- trunk/connector-j/src/com/mysql/jdbc/EscapeProcessor.java 2006-09-13 00:01:02 UTC (rev
5724)
+++ trunk/connector-j/src/com/mysql/jdbc/EscapeProcessor.java 2006-09-13 14:28:38 UTC (rev
5725)
@@ -436,26 +436,41 @@
+ argument + "'", "42000");
}
} else if (StringUtils.startsWithIgnoreCase(collapsedToken,
- "{call")
- || StringUtils.startsWithIgnoreCase(collapsedToken,
- "{?=call")) {
+ "{call")
+ || StringUtils.startsWithIgnoreCase(collapsedToken,
+ "{?=call")) {
int startPos = StringUtils.indexOfIgnoreCase(token,
- "CALL") + 5;
+ "CALL") + 5;
int endPos = token.length() - 1;
if (StringUtils.startsWithIgnoreCase(collapsedToken,
- "{?=call")) {
+ "{?=call")) {
callingStoredFunction = true;
newSql.append("SELECT ");
- newSql.append(token.substring(startPos, endPos));
+ newSql.append(token, startPos, endPos);
} else {
callingStoredFunction = false;
newSql.append("CALL ");
- newSql.append(token.substring(startPos, endPos));
+ newSql.append(token, startPos, endPos);
}
+
+ for (int i = endPos - 1; i >= startPos; i--) {
+ char c = token.charAt(i);
+
+ if (Character.isWhitespace(c)) {
+ continue;
+ }
+
+ if (c != ')') {
+ newSql.append("()"); // handle no-parenthesis no-arg call not supported
+ // by MySQL parser
+ }
+
+ break;
+ }
} else if (StringUtils.startsWithIgnoreCase(collapsedToken,
- "{oj")) {
+ "{oj")) {
// MySQL already handles this escape sequence
// because of ODBC. Cool.
newSql.append(token);
Modified: trunk/connector-j/src/testsuite/regression/CallableStatementRegressionTest.java
===================================================================
---
trunk/connector-j/src/testsuite/regression/CallableStatementRegressionTest.java 2006-09-13
00:01:02 UTC (rev 5724)
+++
trunk/connector-j/src/testsuite/regression/CallableStatementRegressionTest.java 2006-09-13
14:28:38 UTC (rev 5725)
@@ -731,4 +731,60 @@
}
}
}
+
+ /**
+ * Tests fix for BUG#21462 - JDBC (and ODBC) specifications allow no-parenthesis
+ * CALL statements for procedures with no arguments, MySQL server does not.
+ *
+ * @throws Exception if the test fails.
+ */
+ public void testBug21462() throws Exception {
+ if (versionMeetsMinimum(5, 0)) {
+ CallableStatement cstmt = null;
+
+ try {
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug21462");
+ this.stmt.executeUpdate("CREATE PROCEDURE testBug21462() BEGIN SELECT 1; END");
+ cstmt = this.conn.prepareCall("{CALL testBug21462}");
+ cstmt.execute();
+ } finally {
+ if (cstmt != null) {
+ cstmt.close();
+ }
+
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug21462");
+ }
+ }
+ }
+
+ /**
+ * Tests fix for BUG#22024 - Newlines causing whitespace to span confuse
+ * procedure parser when getting parameter metadata for stored procedures.
+ *
+ * @throws Exception if the test fails
+ */
+ public void testBug22024() throws Exception {
+ if (versionMeetsMinimum(5, 0)) {
+ CallableStatement cstmt = null;
+
+ try {
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug22024");
+ this.stmt.executeUpdate("CREATE PROCEDURE testBug22024(\r\n)\r\n BEGIN SELECT 1;
END");
+ cstmt = this.conn.prepareCall("{CALL testBug22024()}");
+ cstmt.execute();
+
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug22024");
+ this.stmt.executeUpdate("CREATE PROCEDURE testBug22024(\r\na INT)\r\n BEGIN SELECT 1;
END");
+ cstmt = this.conn.prepareCall("{CALL testBug22024(?)}");
+ cstmt.setInt(1, 1);
+ cstmt.execute();
+ } finally {
+ if (cstmt != null) {
+ cstmt.close();
+ }
+
+ this.stmt.executeUpdate("DROP PROCEDURE IF EXISTS testBug22024");
+ }
+ }
+ }
}
| Thread |
|---|
| • Connector/J commit: r5725 - branches/branch_5_0/connector-j/src/com/mysql/jdbc branches/branch_5_0/connector-j/src/testsuite/regression trunk/connecto... | mmatthews | 13 Sep |