I'm now using Qt SQL in my application, and I'm able to execute the following script (aka UPSERT) by using QSqlQuery:
INSERT INTO table_1(col_1,col_2,col_3) VALUES(val_1,val_2,val_3)
ON CONFLICT(col_1) DO UPDATE SET col_1=val_1,col_2=val_2,col_3=val_3
Is it possible to implement this under model/view framework, i.e. using QSqlTableModel?
No,
UPSERTis not implemented inQtbecause it has different syntax on different database systems. But you can implement it this way:QSqlTableModel::insertRowIntoTableQSqlTableModelPrivate::execfrom qt sources or pointer-hack into it.Here's how it can be done for mysql:
Full source