1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
From 8e889378115c69508b050a511621ac8e30ec4158 Mon Sep 17 00:00:00 2001
From: Jesus Fernandez <jesus.fernandez@theqtcompany.com>
Date: Mon, 13 Jun 2016 19:09:15 +0200
Subject: [PATCH] Fix UNSIGNED values in QMYSQL
The unsigned flag in columns was ignored when creating the list of
bound values in a mysql table. So the result iteration with
QSqlQuery::next stops after the first wrong truncated value.
[ChangeLog][QtSql] Fixed QSqlQuery::prepare value truncation error when
using UNSIGNED values in a MySQL database.
Task-number: QTBUG-53969
Task-number: QTBUG-53237
Change-Id: I10d977993445f2794f1dd8c88b2e83517ef524f3
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
---
src/sql/drivers/mysql/qsql_mysql.cpp | 1 +
tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 39 +++++++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/src/sql/drivers/mysql/qsql_mysql.cpp b/src/sql/drivers/mysql/qsql_mysql.cpp
index 96bdcc4..55bf499 100644
--- a/src/sql/drivers/mysql/qsql_mysql.cpp
+++ b/src/sql/drivers/mysql/qsql_mysql.cpp
@@ -387,6 +387,7 @@ bool QMYSQLResultPrivate::bindInValues()
bind->buffer_length = f.bufLength = fieldInfo->length + 1;
bind->is_null = &f.nullIndicator;
bind->length = &f.bufLength;
+ bind->is_unsigned = fieldInfo->flags & UNSIGNED_FLAG ? 1 : 0;
f.outField=field;
++i;
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index bd553d5..f1c4333 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -233,6 +233,9 @@ private slots:
void QTBUG_36211_data() { generic_data("QPSQL"); }
void QTBUG_36211();
+ void QTBUG_53969_data() { generic_data("QMYSQL"); }
+ void QTBUG_53969();
+
void sqlite_constraint_data() { generic_data("QSQLITE"); }
void sqlite_constraint();
@@ -3652,6 +3655,42 @@ void tst_QSqlQuery::QTBUG_36211()
}
}
+void tst_QSqlQuery::QTBUG_53969()
+{
+ QFETCH( QString, dbName );
+ QVector<int> values = QVector<int>() << 10 << 20 << 127 << 128 << 1, tableValues;
+ QSqlDatabase db = QSqlDatabase::database( dbName );
+ CHECK_DATABASE( db );
+ tableValues.reserve(values.size());
+ if (tst_Databases::getDatabaseType(db) == QSqlDriver::MySqlServer) {
+ const QString tableName(qTableName("bug53969", __FILE__, db));
+ tst_Databases::safeDropTable( db, tableName );
+
+ QSqlQuery q(db);
+ QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id INT AUTO_INCREMENT PRIMARY KEY, "
+ "test_number TINYINT(3) UNSIGNED)")
+ .arg(tableName)));
+
+ QVERIFY_SQL(q, prepare("INSERT INTO " + tableName + " (test_number) VALUES (:value)"));
+
+ QVector<int>::iterator begin = values.begin(), end = values.end(), it;
+ for (it = begin; it != end; ++it) {
+ q.bindValue(":value", *it);
+ QVERIFY_SQL(q, exec());
+ }
+
+ QVERIFY_SQL(q, prepare("SELECT test_number FROM " + tableName));
+ QVERIFY_SQL(q, exec());
+
+ while (q.next()) {
+ bool ok;
+ tableValues.push_back(q.value(0).toUInt(&ok));
+ QVERIFY(ok);
+ }
+ QCOMPARE(values, tableValues);
+ }
+}
+
void tst_QSqlQuery::oraOCINumber()
{
QFETCH( QString, dbName );
|