MySQL and transaction problem in Qt 4.6.2 on Windows XP SP3
Hello. I have a problem about controlling a transaction with MySQL database in Qt 4.6.2 for VS2008 on Windows XP SP3.
When calling transaction functions including transaction, commit, it'll always return 'true,' but the database isn't updated. Here is my code:
Code:
// Assume that the connection was open by db.open(), where db is an instance of QSqlDatabase.
QString insertCmd
= "INSERT INTO image (img_desc, img_filename) VALUE (?, ?)";
db.transaction();
query.prepare(insertCmd);
// Assume that imgDesc and imgFileName are QString got from QPlainTextEdit.
query.addBindValue(imgDesc);
query.addBindValue(imgFileName);
query.exec();
db.commit();
But there is no new record in table image in MySQL. So what should I do? Thanks a lot!
Re: MySQL and transaction problem in Qt 4.6.2 on Windows XP SP3
Try to look after query.exec() what happened :
Code:
qDebug
() <<
QSqlDatabase::database().
lastError() << endl << query.
executedQuery() << endl << query.
lastError();