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>
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);
}
/*!
}
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()
{