Reduce the scope of variables in exec() and fetchNext()

The scope of the variable 'currBind' can be reduced if the variable 'r'
is not 0. So declare the variable when the variable 'r' is 0. The local
variable 'i' shadows outer variable in fetchNext(), so move it to the
front of switch.

Don't declare 'res' until we need and initialize it.

Change-Id: Idfb220b96cfbcd4088fd7858ed9392d0a3e10aea
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Zou Ya 2020-11-24 19:54:09 +08:00 committed by Volker Hilsheimer
parent 6cb36d825d
commit 5b93f6cae6
2 changed files with 3 additions and 7 deletions

View File

@ -872,7 +872,6 @@ bool QMYSQLResult::exec()
return false;
int r = 0;
MYSQL_BIND* currBind;
QList<MYSQL_TIME *> timeVector;
QList<QByteArray> stringVector;
QList<my_bool> nullVector;
@ -894,7 +893,7 @@ bool QMYSQLResult::exec()
const QVariant &val = boundValues().at(i);
void *data = const_cast<void *>(val.constData());
currBind = &d->outBinds[i];
MYSQL_BIND* currBind = &d->outBinds[i];
nullVector[i] = static_cast<my_bool>(val.isNull());
currBind->is_null = &nullVector[i];

View File

@ -249,8 +249,6 @@ void QSQLiteResultPrivate::initColumns(bool emptyResultset)
bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int idx, bool initialFetch)
{
Q_Q(QSQLiteResult);
int res;
int i;
if (skipRow) {
// already fetched
@ -273,8 +271,7 @@ bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int i
q->setAt(QSql::AfterLastRow);
return false;
}
res = sqlite3_step(stmt);
int res = sqlite3_step(stmt);
switch(res) {
case SQLITE_ROW:
// check to see if should fill out columns
@ -283,7 +280,7 @@ bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int i
initColumns(false);
if (idx < 0 && !initialFetch)
return true;
for (i = 0; i < rInf.count(); ++i) {
for (int i = 0; i < rInf.count(); ++i) {
switch (sqlite3_column_type(stmt, i)) {
case SQLITE_BLOB:
values[i + idx] = QByteArray(static_cast<const char *>(