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>
This commit is contained in:
Jesus Fernandez 2016-06-13 19:09:15 +02:00
parent e5e93345c5
commit 8e88937811
2 changed files with 40 additions and 0 deletions

View File

@ -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;

View File

@ -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 );