I am trying to obtain the ID (primary key with auto increment) of the last inserted data. But my query seems to be empty after using SCOPE_IDENTITY()
, while the entries are inserted correctly into the database. What is causing the problem? Thank you!
QSqlQuery query;
query.prepare("INSERT INTO list (file) VALUES (?); SELECT SCOPE_IDENTITY()");
query.addBindValue(file);
qDebug() << query.exec();
qDebug() << query.first();
query.value(0).toInt();
Console Output:
true
false
QSqlQuery::value: not positioned on a valid record