There are two issues I can see:
- QSqlQuery::exec() executes a single SQL statement and you are trying to pass two (DROP and CREATE PROCEDURE BEGIN ... END)
- The DELIMITER lines are not SQL, they are directives to the mysql commandline tool to ensure it passes the whole procedure in one block rather than stopping at the first semicolon. The Mysql command line tool is not involved here.
You should be able to execute the DROP in one exec() call, and the CREATE PROCEDURE (with the internal semicolons as-is) in a second. If you are trying to handle a user-provided script with Mysql command line tool syntax then:
- you need to write a simple parser to split the script into statement and send them one at at time
- you need to really trust your user not to bork your database
Bookmarks