diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 84e9643e773..8deb5ddf8ff 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -3995,35 +3995,29 @@ void tst_QSqlQuery::aggregateFunctionTypes() } template -void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName, const QString &type, const bool withPreparedStatement, - const T min = std::numeric_limits::min(), const T max = std::numeric_limits::max()) +void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName, + const QString &type, bool withPreparedStatement, + const QVector &values) { + QVector variantValues; + variantValues.reserve(values.size()); + QSqlQuery q(db); QVERIFY_SQL(q, exec("DROP TABLE IF EXISTS " + tableName)); QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id " + type + ')')); - const int steps = (max == min + 1) ? 2 : 20; - const T increment = (max == min + 1) ? 1 : (max / steps - min / steps); - - // insert some values - QVector values; - QVector variantValues; - values.resize(steps); - variantValues.resize(steps); - T v = min; if (withPreparedStatement) { QVERIFY_SQL(q, prepare("INSERT INTO " + tableName + " (id) VALUES (?)")); } for (int i = 0; i < values.size(); ++i) { + const T v = values.at(i); if (withPreparedStatement) { q.bindValue(0, v); QVERIFY_SQL(q, exec()); } else { QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (" + QString::number(v) + QLatin1Char(')'))); } - values[i] = v; - variantValues[i] = QVariant::fromValue(v); - v += increment; + variantValues.append(QVariant::fromValue(v)); } // ensure we can read them back properly @@ -4048,16 +4042,34 @@ void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName, const QCOMPARE(actualVariantValues, variantValues); } +template +void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName, + const QString &type, const bool withPreparedStatement, + const T min = std::numeric_limits::min(), + const T max = std::numeric_limits::max()) +{ + // insert some values + const int steps = 20; + const T increment = (max / steps - min / steps); + QVector values; + values.reserve(steps); + T v = min; + for (int i = 0; i < steps; ++i, v += increment) + values.append(v); + runIntegralTypesMysqlTest(db, tableName, type, withPreparedStatement, values); +} + void tst_QSqlQuery::integralTypesMysql() { QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + const QVector boolValues = QVector() << false << true; for (int i = 0; i < 2; ++i) { const bool withPreparedStatement = (i == 1); - runIntegralTypesMysqlTest(db, "tinyInt1Test", "TINYINT(1)", withPreparedStatement); - runIntegralTypesMysqlTest(db, "unsignedTinyInt1Test", "TINYINT(1) UNSIGNED", withPreparedStatement); + runIntegralTypesMysqlTest(db, "tinyInt1Test", "TINYINT(1)", withPreparedStatement, boolValues); + runIntegralTypesMysqlTest(db, "unsignedTinyInt1Test", "TINYINT(1) UNSIGNED", withPreparedStatement, boolValues); runIntegralTypesMysqlTest(db, "tinyIntTest", "TINYINT", withPreparedStatement); runIntegralTypesMysqlTest(db, "unsignedTinyIntTest", "TINYINT UNSIGNED", withPreparedStatement); runIntegralTypesMysqlTest(db, "smallIntTest", "SMALLINT", withPreparedStatement);