PDA

View Full Version : MySQL and transaction problem in Qt 4.6.2 on Windows XP SP3



nuntawat
11th March 2010, 16:51
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:



// 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 (?, ?)";

QSqlQuery query;

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!

Lesiok
11th March 2010, 17:42
Try to look after query.exec() what happened :
qDebug() << QSqlDatabase::database().lastError() << endl << query.executedQuery() << endl << query.lastError();