From 593b8f7f0b35ddc424d8ccbd5df11fcf2442858e Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Tue, 30 Oct 2012 10:51:25 +0100 Subject: fix binding of bool type in mysql driver MYSQL_TYPE_TINY should be used for binding bool input value. MYSQL_TYPE_LONG might be too big for bool, resulting in bools being saved in the database as int 127. The problem was not specific to the vendor's BOOL column type. http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html http://dev.mysql.com/doc/refman/5.0/en/c-api-prepared-statement-type-codes.html Added generic autotest to make sure that binding bool works. All drivers should pass this test. Task-number: QTBUG-27763 Change-Id: I4e69f8e3b32fffb702ec9fa8a80ff5c50dea954b Reviewed-by: Andy Shaw Reviewed-by: Mark Brand --- src/sql/drivers/mysql/qsql_mysql.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp index 6cc9edffa8..182b0a4dd3 100644 --- a/src/sql/drivers/mysql/qsql_mysql.cpp +++ b/src/sql/drivers/mysql/qsql_mysql.cpp @@ -987,11 +987,16 @@ bool QMYSQLResult::exec() break; } case QVariant::UInt: case QVariant::Int: - case QVariant::Bool: currBind->buffer_type = MYSQL_TYPE_LONG; currBind->buffer = data; currBind->buffer_length = sizeof(int); currBind->is_unsigned = (val.type() != QVariant::Int); + break; + case QVariant::Bool: + currBind->buffer_type = MYSQL_TYPE_TINY; + currBind->buffer = data; + currBind->buffer_length = sizeof(bool); + currBind->is_unsigned = false; break; case QVariant::Double: currBind->buffer_type = MYSQL_TYPE_DOUBLE; -- cgit v1.2.3