
Originally Posted by
Lesiok
As you can see, there are several SQL commands run by a single
QSqlQuery::exec.
Fair enough. I have just tried something like your script with MySQL in QT 5.9 for a CREATE TABLE, some INSERTS, and COMMIT: it worked. I was basing my response on what I have seen with the Sqlite interface in the past: it seems the behaviour here has changed also or I was triggering a result like the one below.
The OP's script in this post, and the other, includes directives for the mysql interactive SQL tools. They will not parse as SQL, causing exec() to execute only the steps up to that point. In this case I expect it drops the procedure and terminates without an error.
In my test:
"CREATE TABLE xyzzy (a int); "
"INSERT INTO xyzzy (a) VALUES(1); "
"INSERT INTO xyzzy (a) VALUES(2); "
"INSERT INTO xyzzy (a) VALUES(3); "
"COMMIT; "
);
QString skrypt(
"CREATE TABLE xyzzy (a int); "
"INSERT INTO xyzzy (a) VALUES(1); "
"INSERT INTO xyzzy (a) VALUES(2); "
"INSERT INTO xyzzy (a) VALUES(3); "
"COMMIT; "
);
To copy to clipboard, switch view to plain text mode
created a table of three records, and
"CREATE TABLE xyzzy (a int); "
"DELIMITER $$ "
"INSERT INTO xyzzy (a) VALUES(1); "
"INSERT INTO xyzzy (a) VALUES(2); "
"INSERT INTO xyzzy (a) VALUES(3); "
"COMMIT; "
);
QString skrypt(
"CREATE TABLE xyzzy (a int); "
"DELIMITER $$ "
"INSERT INTO xyzzy (a) VALUES(1); "
"INSERT INTO xyzzy (a) VALUES(2); "
"INSERT INTO xyzzy (a) VALUES(3); "
"COMMIT; "
);
To copy to clipboard, switch view to plain text mode
creates an empty table and reports no error. In the OP's script this would execute only the DROP PROCEDURE.
Bookmarks