summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sql/models/qsqlrelationaltablemodel.cpp7
-rw-r--r--src/sql/models/qsqltablemodel.cpp6
2 files changed, 7 insertions, 6 deletions
diff --git a/src/sql/models/qsqlrelationaltablemodel.cpp b/src/sql/models/qsqlrelationaltablemodel.cpp
index df7cf1eb3b..a21c051dd5 100644
--- a/src/sql/models/qsqlrelationaltablemodel.cpp
+++ b/src/sql/models/qsqlrelationaltablemodel.cpp
@@ -303,7 +303,12 @@ int QSqlRelationalTableModelPrivate::nameToIndex(const QString &name) const
QString fieldname = name;
if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName))
fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName);
- return baseRec.indexOf(fieldname);
+ int idx = baseRec.indexOf(fieldname);
+ if (idx == -1) {
+ // If the name is an alias we can find it here.
+ idx = QSqlTableModelPrivate::nameToIndex(name);
+ }
+ return idx;
}
void QSqlRelationalTableModelPrivate::clearEditBuffer()
diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp
index e44c315701..226f2c7286 100644
--- a/src/sql/models/qsqltablemodel.cpp
+++ b/src/sql/models/qsqltablemodel.cpp
@@ -1344,12 +1344,8 @@ bool QSqlTableModel::setRecord(int row, const QSqlRecord &record)
QSqlTableModelPrivate::clearGenerated(mrow.rec);
mrow.primaryValues = d->primaryValues(indexInQuery(createIndex(row, 0)).row());
}
- QString fieldName;
for (int i = 0; i < record.count(); ++i) {
- fieldName = record.fieldName(i);
- if (d->db.driver()->isIdentifierEscaped(fieldName, QSqlDriver::FieldName))
- fieldName = d->db.driver()->stripDelimiters(fieldName, QSqlDriver::FieldName);
- int idx = mrow.rec.indexOf(fieldName);
+ int idx = d->nameToIndex(record.fieldName(i));
if (idx == -1) {
isOk = false;
} else {