diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2016-08-22 14:32:05 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2016-09-12 12:47:08 +0000 |
commit | 3370ab9119df09ca14f7d4641c555e60c1b3f478 (patch) | |
tree | d3710534e5bf8235ab7f2e81b37ad542b8e7df71 /src/sql/drivers/mysql | |
parent | 3b8df0ea44b048b8fcc4317ffdfd074e2547a95e (diff) |
Never return char variants when reading prepared MySQL statements
This has undesired effects when converting a QSqlRecord to JSON.
A char(0) e.g. has special semantics that are undesired when
reading a Tinyint column.
I don't think that returning bool for the special case of a
Tinyint(1) is required. This also did not happen before, and
is also not happening when not using a prepared statement.
Instead, a plain int/uint QVariant is returned.
This patch extends tst_QSqlQuery::integralTypesMysql to also
cover reading and writing booleans from/to a MySQL table column
of type Tinyint(1). Additionally, the reading is now also done
with a prepared statement and we also check the raw variant
value.
The broken behavior fixed by this patch was introduced by me in
commit 194403a3483b7317cc9511bc8b2ab307775643c5.
Change-Id: I028a3abd83fdd2b42d98d478950d205e5b6bbeb5
Task-number: QTBUG-53397
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/sql/drivers/mysql')
-rw-r--r-- | src/sql/drivers/mysql/qsql_mysql.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index 99472542bf..c26c03ad07 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -596,8 +596,15 @@ QVariant QMYSQLResult::data(int field) if (f.nullIndicator) return QVariant(f.type); - if (qIsInteger(f.type)) - return QVariant(f.type, f.outField); + if (qIsInteger(f.type)) { + QVariant variant(f.type, f.outField); + // we never want to return char variants here, see QTBUG-53397 + if (static_cast<int>(f.type) == QMetaType::UChar) + return variant.toUInt(); + else if (static_cast<int>(f.type) == QMetaType::Char) + return variant.toInt(); + return variant; + } if (f.type != QVariant::ByteArray) val = toUnicode(d->driver->d_func()->tc, f.outField, f.bufLength); |