QSqlTableModel: derive primary values from database values
Primary values are used to map a row in the model to a row in the database table. It is critically important between submitting a change and the following select (which refreshes the query) to have updated primary values. Otherwise, if the change affected the primary values, additional changes before select will misbehave. Change-Id: I5d08dd70ac5d3f06cd9d3186a439f4c80a037c2d Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
This commit is contained in:
parent
463bd32fe5
commit
698e620aad
@ -201,16 +201,7 @@ bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement,
|
||||
|
||||
QSqlRecord QSqlTableModelPrivate::primaryValues(int row) const
|
||||
{
|
||||
Q_Q(const QSqlTableModel);
|
||||
if (cache.value(row).op() == Insert)
|
||||
return QSqlRecord();
|
||||
|
||||
QSqlRecord values(primaryIndex.isEmpty() ? rec : primaryIndex);
|
||||
|
||||
for (int i = 0; i < values.count(); ++i)
|
||||
values.setValue(i, q->QSqlQueryModel::data(createIndex(row, rec.indexOf(values.fieldName(i))), Qt::EditRole));
|
||||
|
||||
return values;
|
||||
return cache.value(row).primaryValues(primaryIndex.isEmpty() ? rec : primaryIndex);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -113,6 +113,18 @@ public:
|
||||
}
|
||||
inline bool submitted() const { return m_submitted; }
|
||||
inline void setSubmitted() { m_submitted = true; }
|
||||
inline QSqlRecord primaryValues(const QSqlRecord& pi) const
|
||||
{
|
||||
if (m_op == None || m_op == Insert)
|
||||
return QSqlRecord();
|
||||
|
||||
QSqlRecord values(pi);
|
||||
|
||||
for (int i = values.count() - 1; i >= 0; --i)
|
||||
values.setValue(i, m_db_values.value(values.fieldName(i)));
|
||||
|
||||
return values;
|
||||
}
|
||||
private:
|
||||
void init_rec()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user