Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

[solved] A little problem using qsql (qsqlite)

$
0
0
I am trying to fetch the key id from a record I’ve just inserted:         QSqlQuery qri(connection);         qri.prepare("INSERT INTO posts (stamp, date) VALUES (:stamp, :date)");         qri.bindValue(":stamp", postID);         qri.bindValue(":date",time);         if (!qri.exec() && !error) {             errorCode = 501;             error = true;             errorMessage = qri.lastError().text()+" "+postID;         } With:         QString SQL = "SELECT id FROM posts WHERE stamp = ':thestamp'";         QSqlQuery qriL(connection);         qriL.prepare(SQL);         qriL.bindValue(":thestamp", postID);         if (!qriL.exec() && !error) {             errorCode = 502;             error = true;             errorMessage = qri.lastError().text();         }         qriL.nextResult();         int stamp = qriL.value(0).toInt(); But the value ‘stamp’ is always 0. What am I doing wrong? For the record, instead of nextResult() I have also tried next() and seek(0) without result. Interesting enough using a while loop to loop with while (qriL.next()) gives me an integer with a completly different value than wanted/expected …

Viewing all articles
Browse latest Browse all 18427

Trending Articles