Hello there,
i have some mysql qt problems i dont understand. First some speccs: mysql 5.6, qt 5.1, windows7 and ubuntu 12.04. Inno db table.
this simple snippet starts a transaction, inserted data into table1 and commit the data. But the problem is the data will be inserted twice - i cant figure it out why this happens.
qDebug() << db.transaction(); // returns true
QSqlQuery qry
("SET autocommit = 0",db
);
// test purpose QSqlQuery qry2
("INSERT INTO table1(col1) VALUES(1)",db
);
if (!qry.exec()){ // returns true
qDebug() << qry.lastError();
}else{
qDebug() << qry2.exec();//returns true
qDebug() << db.commit() << db.lastError().text(); // commit returns true and last error string is empty, But the Data is inserted twice, why?
}
QSqlDatabase db = QSqlDatabase::database("dbOne"); //is already opened and all works fine...
qDebug() << db.transaction(); // returns true
QSqlQuery qry("SET autocommit = 0",db); // test purpose
QSqlQuery qry2("INSERT INTO table1(col1) VALUES(1)",db);
if (!qry.exec()){ // returns true
qDebug() << qry.lastError();
}else{
qDebug() << qry2.exec();//returns true
qDebug() << db.commit() << db.lastError().text(); // commit returns true and last error string is empty, But the Data is inserted twice, why?
}
To copy to clipboard, switch view to plain text mode
If I try the same thing with a store_procedure and wrap it with the code above (instead of exec query, call storeProc) - the data will be inserted twice. If I remove the qry.exec() line the data is only inserted once.
Another problem when I use a storeProcedure with many inserts on different tables and in a loop in c++ qt the commit() (outside the loop - transaction starts before the loop and commit after the loop) returns an error after i try to commit the data: "commands out of sync you can't run this command now".
I Dont get the point what happens here. A Simple insert, a simple transaction and two behaviour i didnt get...
Thanks for any kind of help!
best regards
ane
Added after 11 minutes:
If I ry this in mysql workbench all is fine...
start transaction;
INSERT INTO table1(col1) VALUES(1)
commit; # or rollback all works fine
Bookmarks