I use SQLite 3.x, Qt 5.7, C++, QSqlTableModel
, QTableView
classes. The table sites
contains unique url
column. I'd like to avoid redundant selects and minimize/exclude full resets of my model in the case of small data modifications. So, I prefer using read-only raw SQL queries and writing via QSqlRecord
in this project. I update the row in the model through changing the corresponding QSqlRecord
instance. But I have to make linear search of the record to update (see pseudocode below):
for (int i = 0; i < rowCount(); ++i)
{
QSqlRecord current_record = record(i);
QString current_url = current_record.value("url").toString();
if (current_url == url)
{
//updates...
break;
}
}
I'd like to use SQLite internal means for quicker search. How can I find correct identifier (let's name it found_id
) in SQLite in order to call QSqlRecord record = row(found_id);
? Note that inserts and removals will be used too.
Here is simplified DDL:
CREATE TABLE sites (
id INTEGER PRIMARY KEY,
url VARCHAR UNIQUE NOT NULL
);