PDA

View Full Version : How to find the ROWID after an insert into an SQLite table?



feraudyh
31st January 2014, 15:55
OK, I know I should probably be using a QSQLTableModel or something like that, but I have a quick demo to do, not much time to learn these models until later.
I'm trying to insert data with query.exec("insert....")and would like to know what ROWID was in fact inserted.
Any suggestions?


But maybe you can convince me that QSQLTableModel is so easy to learn I can get it running in an hour...

sakya
31st January 2014, 16:08
You can use the SQLite function last_insert_rowid() (https://www.sqlite.org/lang_corefunc.html#last_insert_rowid)

feraudyh
31st January 2014, 21:03
thank you, but at first view using a SQLite function seems to leave the Qt Framework. What header files will I be using? Do I need to download anything?

feraudyh
1st February 2014, 11:37
OK I can use "SELECT last_insert_rowid();" as an SQL Query
I put this up to help the readers.

ChrisW67
1st February 2014, 21:13
QSqlQuery::lastInsertId()