Get values from SQLite row using last_insert_rowid()
-
Hi,
I need to get the values from a query using the row id I tell the query to use, however, I can't seem to know how to call the row id in said query.
Is this a syntax problem?
Here's an example of my code:QSqlQuery query; query.exec("SELECT last_insert_rowid()"); QString sLastId = query.lastInsertId().toString(); query.exec("SELECT fPrecioUnit, fLitros, fImporte, rowid WHERE rowid=\'" + sLastId + "\'");
-
HI and welcome to devnet,
usually a SELECT statement is in the form
SELECT <field_list> FROM <table_name> WHERE <conditions>
; in your queries there's noFROM <tablename>
.BTW,
QSqlQuery::exec()
returns a boolean and you can check the errors withQSqlQuery::lastError()
bool result = query.exec(...); if (!result) { qDebug() << "Error: " << query.lastError().text(); }