SQL/IBase: cache return value of record()
Cache the return value of QIBaseResult::record() to avoid the recreation (e.g. when using QSqlQuery::value(QString) instead index-based ones). Change-Id: I88568d99ba96e19ae6b661d058e7709ebc5ef2a2 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 71880c018fe98854948a6c7dd9049e4ba0ddb8e6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b67c748e29
commit
d05985d229
@ -527,6 +527,7 @@ public:
|
||||
XSQLDA *sqlda; // output sqlda
|
||||
XSQLDA *inda; // input parameters
|
||||
int queryType;
|
||||
mutable QSqlRecord cachedRecord;
|
||||
};
|
||||
|
||||
|
||||
@ -558,6 +559,7 @@ void QIBaseResultPrivate::cleanup()
|
||||
delDA(inda);
|
||||
|
||||
queryType = -1;
|
||||
cachedRecord.clear();
|
||||
q->cleanup();
|
||||
}
|
||||
|
||||
@ -1493,13 +1495,14 @@ int QIBaseResult::numRowsAffected()
|
||||
QSqlRecord QIBaseResult::record() const
|
||||
{
|
||||
Q_D(const QIBaseResult);
|
||||
QSqlRecord rec;
|
||||
if (!isActive() || !d->sqlda)
|
||||
return rec;
|
||||
return {};
|
||||
|
||||
if (!d->cachedRecord.isEmpty())
|
||||
return d->cachedRecord;
|
||||
|
||||
XSQLVAR v;
|
||||
for (int i = 0; i < d->sqlda->sqld; ++i) {
|
||||
v = d->sqlda->sqlvar[i];
|
||||
const XSQLVAR &v = d->sqlda->sqlvar[i];
|
||||
QSqlField f(QString::fromLatin1(v.aliasname, v.aliasname_length).simplified(),
|
||||
QMetaType(qIBaseTypeName2(v.sqltype, v.sqlscale < 0)),
|
||||
QString::fromLatin1(v.relname, v.relname_length));
|
||||
@ -1525,9 +1528,9 @@ QSqlRecord QIBaseResult::record() const
|
||||
f.setRequiredStatus(q.value(3).toBool() ? QSqlField::Required : QSqlField::Optional);
|
||||
}
|
||||
}
|
||||
rec.append(f);
|
||||
d->cachedRecord.append(f);
|
||||
}
|
||||
return rec;
|
||||
return d->cachedRecord;
|
||||
}
|
||||
|
||||
QVariant QIBaseResult::handle() const
|
||||
|
Loading…
x
Reference in New Issue
Block a user