summaryrefslogtreecommitdiffstats
path: root/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-09-16 23:16:25 +0200
committerLiang Qi <liang.qi@qt.io>2016-09-16 23:16:25 +0200
commitd148019f16e3c95916731e59e0324e7c470cc1fc (patch)
treed9c0640c9055f24379468b8f55b3419f30a37c47 /tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
parent8ceab12814a7437a01d917c83ec28fd6e81c459e (diff)
parent6b9c57f8cd3df65702db327616913fa9d8172237 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp Change-Id: I0af32ee55936d523cbd259b6fe82eb9c409f9074
Diffstat (limited to 'tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp')
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp45
1 files changed, 31 insertions, 14 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index 078a629df5..84e9643e77 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -4002,12 +4002,14 @@ void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName, const
QVERIFY_SQL(q, exec("DROP TABLE IF EXISTS " + tableName));
QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id " + type + ')'));
- const int steps = 20;
- const T increment = max / steps - min / steps;
+ const int steps = (max == min + 1) ? 2 : 20;
+ const T increment = (max == min + 1) ? 1 : (max / steps - min / steps);
// insert some values
QVector<T> values;
+ QVector<QVariant> variantValues;
values.resize(steps);
+ variantValues.resize(steps);
T v = min;
if (withPreparedStatement) {
QVERIFY_SQL(q, prepare("INSERT INTO " + tableName + " (id) VALUES (?)"));
@@ -4020,17 +4022,30 @@ void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName, const
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (" + QString::number(v) + QLatin1Char(')')));
}
values[i] = v;
+ variantValues[i] = QVariant::fromValue(v);
v += increment;
}
// ensure we can read them back properly
- QVERIFY_SQL(q, exec("SELECT id FROM " + tableName));
+ if (withPreparedStatement) {
+ QVERIFY_SQL(q, prepare("SELECT id FROM " + tableName));
+ QVERIFY_SQL(q, exec());
+ } else {
+ QVERIFY_SQL(q, exec("SELECT id FROM " + tableName));
+ }
QVector<T> actualValues;
+ QVector<QVariant> actualVariantValues;
actualValues.reserve(values.size());
while (q.next()) {
- actualValues << q.value(0).value<T>();
+ QVariant value = q.value(0);
+ actualVariantValues << value;
+ actualValues << value.value<T>();
+ QVERIFY(actualVariantValues.last().userType() != qMetaTypeId<char>());
+ QVERIFY(actualVariantValues.last().userType() != qMetaTypeId<signed char>());
+ QVERIFY(actualVariantValues.last().userType() != qMetaTypeId<unsigned char>());
}
QCOMPARE(actualValues, values);
+ QCOMPARE(actualVariantValues, variantValues);
}
void tst_QSqlQuery::integralTypesMysql()
@@ -4041,16 +4056,18 @@ void tst_QSqlQuery::integralTypesMysql()
for (int i = 0; i < 2; ++i) {
const bool withPreparedStatement = (i == 1);
- runIntegralTypesMysqlTest<char>(db, "tinyIntTest", "TINYINT", withPreparedStatement);
- runIntegralTypesMysqlTest<unsigned char>(db, "unsignedTinyIntTest", "TINYINT UNSIGNED", withPreparedStatement);
- runIntegralTypesMysqlTest<char>(db, "smallIntTest", "SMALLINT", withPreparedStatement);
- runIntegralTypesMysqlTest<unsigned char>(db, "unsignedSmallIntTest", "SMALLINT UNSIGNED", withPreparedStatement);
- runIntegralTypesMysqlTest<int>(db, "mediumIntTest", "MEDIUMINT", withPreparedStatement, -(1 << 23), (1 << 23) - 1);
- runIntegralTypesMysqlTest<unsigned int>(db, "unsignedMediumIntTest", "MEDIUMINT UNSIGNED", withPreparedStatement, 0, (1 << 24) - 1);
- runIntegralTypesMysqlTest<int>(db, "intTest", "INT", withPreparedStatement);
- runIntegralTypesMysqlTest<unsigned int>(db, "unsignedIntTest", "INT UNSIGNED", withPreparedStatement);
- runIntegralTypesMysqlTest<long long>(db, "bigIntTest", "BIGINT", withPreparedStatement);
- runIntegralTypesMysqlTest<unsigned long long>(db, "unsignedBigIntTest", "BIGINT UNSIGNED", withPreparedStatement);
+ runIntegralTypesMysqlTest<bool>(db, "tinyInt1Test", "TINYINT(1)", withPreparedStatement);
+ runIntegralTypesMysqlTest<bool>(db, "unsignedTinyInt1Test", "TINYINT(1) UNSIGNED", withPreparedStatement);
+ runIntegralTypesMysqlTest<qint8>(db, "tinyIntTest", "TINYINT", withPreparedStatement);
+ runIntegralTypesMysqlTest<quint8>(db, "unsignedTinyIntTest", "TINYINT UNSIGNED", withPreparedStatement);
+ runIntegralTypesMysqlTest<qint16>(db, "smallIntTest", "SMALLINT", withPreparedStatement);
+ runIntegralTypesMysqlTest<quint16>(db, "unsignedSmallIntTest", "SMALLINT UNSIGNED", withPreparedStatement);
+ runIntegralTypesMysqlTest<qint32>(db, "mediumIntTest", "MEDIUMINT", withPreparedStatement, -(1 << 23), (1 << 23) - 1);
+ runIntegralTypesMysqlTest<quint32>(db, "unsignedMediumIntTest", "MEDIUMINT UNSIGNED", withPreparedStatement, 0, (1 << 24) - 1);
+ runIntegralTypesMysqlTest<qint32>(db, "intTest", "INT", withPreparedStatement);
+ runIntegralTypesMysqlTest<quint32>(db, "unsignedIntTest", "INT UNSIGNED", withPreparedStatement);
+ runIntegralTypesMysqlTest<qint64>(db, "bigIntTest", "BIGINT", withPreparedStatement);
+ runIntegralTypesMysqlTest<quint64>(db, "unsignedBigIntTest", "BIGINT UNSIGNED", withPreparedStatement);
}
}