From 3370ab9119df09ca14f7d4641c555e60c1b3f478 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Mon, 22 Aug 2016 14:32:05 +0200 Subject: 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 --- src/sql/drivers/mysql/qsql_mysql.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') 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(f.type) == QMetaType::UChar) + return variant.toUInt(); + else if (static_cast(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); -- cgit v1.2.3