diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-12-22 15:09:23 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-01-12 17:41:07 +0100 |
commit | 999d856bc8569455c21850dc524a595e6b6f52b6 (patch) | |
tree | 8ed959c57f0fcbf527324204df1b00e0b76d6074 /src/plugins | |
parent | 66f0149693c810a512001d9d4df89b6f9d7a9327 (diff) |
Adapt SQL drivers to Qt 6 change of QVariant::isNull
In Qt 5, QVariant::isNull returned true if either the variant didn't
contain a value, or if the value was of a nullable type where the type's
isNull member function returned true.
In Qt 6, QVariant::isNull only returns true for variants that don't
contain a value; if the value contained is e.g. a null-QString or
QDateTime, then QVariant::isNull returns false.
This change requires a follow up in the SQL drivers, which must
still treat null-values the same as null-variants, lest they write data
into the data base.
Add a static helper to QSqlResultPrivate that implements isNull-checking
of variants that contain a nullable type relevant for Sql, and add a
test case to the QSqlQuery test that exercises that code.
Pick-to: 6.2 6.3
Fixes: QTBUG-99408
Fixes: QTBUG-98471
Change-Id: I08b74a33aa3235c37d974f182da1f2bdcfd8217e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/sqldrivers/db2/qsql_db2.cpp | 2 | ||||
-rw-r--r-- | src/plugins/sqldrivers/ibase/qsql_ibase.cpp | 4 | ||||
-rw-r--r-- | src/plugins/sqldrivers/mysql/qsql_mysql.cpp | 2 | ||||
-rw-r--r-- | src/plugins/sqldrivers/oci/qsql_oci.cpp | 6 | ||||
-rw-r--r-- | src/plugins/sqldrivers/odbc/qsql_odbc.cpp | 2 | ||||
-rw-r--r-- | src/plugins/sqldrivers/psql/qsql_psql.cpp | 2 | ||||
-rw-r--r-- | src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp | 2 |
7 files changed, 10 insertions, 10 deletions
diff --git a/src/plugins/sqldrivers/db2/qsql_db2.cpp b/src/plugins/sqldrivers/db2/qsql_db2.cpp index e605ac91a2..00bcc1cc4a 100644 --- a/src/plugins/sqldrivers/db2/qsql_db2.cpp +++ b/src/plugins/sqldrivers/db2/qsql_db2.cpp @@ -697,7 +697,7 @@ bool QDB2Result::exec() for (i = 0; i < values.count(); ++i) { // bind parameters - only positional binding allowed SQLLEN *ind = &indicators[i]; - if (values.at(i).isNull()) + if (QSqlResultPrivate::isVariantNull(values.at(i))) *ind = SQL_NULL_DATA; if (bindValueType(i) & QSql::Out) values[i].detach(); diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp index ba820a4416..d8cb3ae5f3 100644 --- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp +++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp @@ -968,7 +968,7 @@ bool QIBaseResult::exec() setAt(QSql::BeforeFirstRow); if (d->inda) { - QList<QVariant>& values = boundValues(); + const QList<QVariant> &values = boundValues(); int i; if (values.count() > d->inda->sqld) { qWarning() << QLatin1String("QIBaseResult::exec: Parameter mismatch, expected") << @@ -984,7 +984,7 @@ bool QIBaseResult::exec() continue; const QVariant val(values[i]); if (d->inda->sqlvar[para].sqltype & 1) { - if (val.isNull()) { + if (QSqlResultPrivate::isVariantNull(val)) { // set null indicator *(d->inda->sqlvar[para].sqlind) = -1; // and set the value to 0, otherwise it would count as empty string. diff --git a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp index caf406da46..837805cc46 100644 --- a/src/plugins/sqldrivers/mysql/qsql_mysql.cpp +++ b/src/plugins/sqldrivers/mysql/qsql_mysql.cpp @@ -929,7 +929,7 @@ bool QMYSQLResult::exec() MYSQL_BIND* currBind = &d->outBinds[i]; - nullVector[i] = static_cast<my_bool>(val.isNull()); + nullVector[i] = static_cast<my_bool>(QSqlResultPrivate::isVariantNull(val)); currBind->is_null = &nullVector[i]; currBind->length = 0; currBind->is_unsigned = 0; diff --git a/src/plugins/sqldrivers/oci/qsql_oci.cpp b/src/plugins/sqldrivers/oci/qsql_oci.cpp index 5ba862f430..324e502f8c 100644 --- a/src/plugins/sqldrivers/oci/qsql_oci.cpp +++ b/src/plugins/sqldrivers/oci/qsql_oci.cpp @@ -515,7 +515,7 @@ int QOCIResultPrivate::bindValues(QVariantList &values, IndicatorArray &indicato OCIBind * hbnd = nullptr; // Oracle handles these automatically sb2 *indPtr = &indicators[i]; - *indPtr = val.isNull() ? -1 : 0; + *indPtr = QSqlResultPrivate::isVariantNull(val) ? -1 : 0; bindValue(sql, &hbnd, err, i, val, indPtr, &tmpSizes[i], tmpStorage); } @@ -1372,7 +1372,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a // not a list - create a deep-copy of the single value QOCIBatchColumn &singleCol = columns[i]; singleCol.indicators = new sb2[1]; - *singleCol.indicators = boundValues.at(i).isNull() ? -1 : 0; + *singleCol.indicators = QSqlResultPrivate::isVariantNull(boundValues.at(i)) ? -1 : 0; r = d->bindValue(d->sql, &singleCol.bindh, d->err, i, boundValues.at(i), singleCol.indicators, &tmpSizes[i], tmpStorage); @@ -1469,7 +1469,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a for (uint row = 0; row < col.recordCount; ++row) { const QVariant &val = boundValues.at(i).toList().at(row); - if (val.isNull() && !d->isOutValue(i)) { + if (QSqlResultPrivate::isVariantNull(val) && !d->isOutValue(i)) { columns[i].indicators[row] = -1; columns[i].lengths[row] = 0; } else { diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index 1b3a55d096..dbbf984fa9 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -1419,7 +1419,7 @@ bool QODBCResult::exec() values[i].detach(); const QVariant &val = values.at(i); SQLLEN *ind = &indicators[i]; - if (val.isNull()) + if (QSqlResultPrivate::isVariantNull(val)) *ind = SQL_NULL_DATA; switch (val.typeId()) { case QMetaType::QDate: { diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index 4c3d6ca13f..07cc29d78c 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -856,7 +856,7 @@ static QString qCreateParamString(const QList<QVariant> &boundValues, const QSql QSqlField f; for (const QVariant &val : boundValues) { f.setMetaType(val.metaType()); - if (val.isNull()) + if (QSqlResultPrivate::isVariantNull(val)) f.clear(); else f.setValue(val); diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp index d13fb1787c..9f90d91e82 100644 --- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp +++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp @@ -501,7 +501,7 @@ bool QSQLiteResult::exec() res = SQLITE_OK; const QVariant &value = values.at(i); - if (value.isNull()) { + if (QSqlResultPrivate::isVariantNull(value)) { res = sqlite3_bind_null(d->stmt, i + 1); } else { switch (value.userType()) { |