Description:
Users with basic permissions (SELECT, INSERT, DELETE) cannot run a stored procedure because the DatabaseMetaData.getCallStmtParameterTypes method throws the following exception:
Caused by: java.sql.SQLException: Driver requires declaration of procedure to either contain a '\nbegin' or '\n' to follow argument declaration, or SELECT privilege on mysql.proc to parse column types.
at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1323)
at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3640)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:560)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:450)
(...)
What's happening is that when that method runs this code:
try {
paramRetrievalRs = paramRetrievalStmt
.executeQuery("SHOW CREATE PROCEDURE "
+ procNameBuf.toString());
parsingFunction = false;
} catch (SQLException sqlEx) {
try {
paramRetrievalRs = paramRetrievalStmt
.executeQuery("SHOW CREATE FUNCTION "
+ procNameBuf.toString());
parsingFunction = true;
} catch (SQLException ex) {
throw sqlEx; // the original exception which made us try this in the first place...
}
}
if (paramRetrievalRs.next()) {
String procedureDef = parsingFunction ? paramRetrievalRs
.getString("Create Function") : paramRetrievalRs
.getString("Create Procedure");
paramRetrievalRs.next() returns an empty result.
It is related to that bug somehow where the command succeeds to retrieve an empty declaration of SP (see http://bugs.mysql.com/bug.php?id=14564)
How to repeat:
Create a SP, create a user with minimum permissions, use JDBC to call the SP with that minimal user it throws:
Caused by: java.sql.SQLException: Driver requires declaration of procedure to either contain a '\nbegin' or '\n' to follow argument declaration, or SELECT privilege on mysql.proc to parse column types.
at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1323)
at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3640)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:560)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:450)
(...)
Suggested fix:
see suggested fix for bug <a href="http://bugs.mysql.com/bug.php?id=14564">14564</a>