QSqlTableModelPrivate: deduplicate field stripping logic

Change-Id: Ic969a192644e84d78558da0f19e588033e4af43d
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
This commit is contained in:
Mark Brand 2012-02-06 23:41:27 +01:00 committed by Qt by Nokia
parent 7e4232f10a
commit 1247683d40
3 changed files with 8 additions and 4 deletions

View File

@ -299,9 +299,7 @@ void QSqlRelationalTableModelPrivate::revertCachedRow(int row)
int QSqlRelationalTableModelPrivate::nameToIndex(const QString &name) const
{
QString fieldname = name;
if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName))
fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName);
QString fieldname = strippedFieldName(name);
int idx = baseRec.indexOf(fieldname);
if (idx == -1) {
// If the name is an alias we can find it here.

View File

@ -67,11 +67,16 @@ QSqlRecord QSqlTableModelPrivate::record(const QVector<QVariant> &values) const
}
int QSqlTableModelPrivate::nameToIndex(const QString &name) const
{
return rec.indexOf(strippedFieldName(name));
}
QString QSqlTableModelPrivate::strippedFieldName(const QString &name) const
{
QString fieldname = name;
if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName))
fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName);
return rec.indexOf(fieldname);
return fieldname;
}
void QSqlTableModelPrivate::initRecordAndPrimaryIndex()

View File

@ -77,6 +77,7 @@ public:
const QSqlRecord &rec, const QSqlRecord &whereValues);
virtual void revertCachedRow(int row);
virtual int nameToIndex(const QString &name) const;
QString strippedFieldName(const QString &name) const;
void initRecordAndPrimaryIndex();
QSqlDatabase db;