QSqlTableModel UNIQUE constraint
Unsolved
General and Desktop
-
I have the following table in SQLite3 database:
CREATE TABLE m_units ( id INTEGER PRIMARY KEY NOT NULL, m_unit TEXT UNIQUE NOT NULL )
It is mapped to QSqlTableModel. I use the following code to insert new records:
void ModelsContainer::addRegistryRecord(RegistryType type, const QSqlRecord &record) { if(tableModels->value((*registryMap)[type])->insertRecord(-1, record)) { tableModels->value((*registryMap)[type])->submitAll(); } else { QMessageBox::critical(nullptr,"Error!","Violation of the UNIQUE constraint in the table!"); } }
I supposed that
insertRecord()
must returnfalse
if record's contents conflict with the table's constrains, but it isn't like I thought.
What approach should I use on tablemodels' editing to check constraint's violations in the underlying db tables?