From 69627730eaf3a024186e2f2dad1842aa32d9ccb8 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 20 Dec 2012 19:20:27 +0100 Subject: Fix QSqlQuery test in relation to PSQL support Some things needed to be corrected for testing with PSQL, this was checked against the the PostgreSQL documentation to confirm that the exepected behaviour is correct. Change-Id: I45a6b343e9eb920fcae2a62910ecc956abcac0f0 Reviewed-by: Mark Brand --- tests/auto/sql/kernel/qsqldatabase/tst_databases.h | 7 +++++ tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 35 +++++++++++++--------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/tests/auto/sql/kernel/qsqldatabase/tst_databases.h b/tests/auto/sql/kernel/qsqldatabase/tst_databases.h index fee1d006b2..f20b2dae2a 100644 --- a/tests/auto/sql/kernel/qsqldatabase/tst_databases.h +++ b/tests/auto/sql/kernel/qsqldatabase/tst_databases.h @@ -463,6 +463,13 @@ public: return "blob"; } + static QString dateTimeTypeName(QSqlDatabase db) + { + if (db.driverName().startsWith("QPSQL")) + return QLatin1String("timestamp"); + return QLatin1String("datetime"); + } + static QString autoFieldName( QSqlDatabase db ) { if ( db.driverName().startsWith( "QMYSQL" ) ) diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 879396a5bf..d6216ee8f3 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -3406,7 +3406,7 @@ void tst_QSqlQuery::QTBUG_2192() tst_Databases::safeDropTable( db, tableName ); QSqlQuery q(db); - QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (dt DATETIME)")); + QVERIFY_SQL(q, exec(QString("CREATE TABLE " + tableName + " (dt %1)").arg(tst_Databases::dateTimeTypeName(db)))); QVERIFY_SQL(q, prepare("INSERT INTO " + tableName + " (dt) VALUES (?)")); q.bindValue(0, QVariant(QDateTime(QDate(2012, 7, 4), QTime(23, 59, 59, 999)))); @@ -3578,6 +3578,10 @@ void tst_QSqlQuery::aggregateFunctionTypes() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + QVariant::Type intType = QVariant::Int; + // QPSQL uses LongLong for manipulation of integers + if (db.driverName().startsWith("QPSQL")) + intType = QVariant::LongLong; { const QString tableName(qTableName("numericFunctionsWithIntValues", __FILE__)); tst_Databases::safeDropTable( db, tableName ); @@ -3591,7 +3595,7 @@ void tst_QSqlQuery::aggregateFunctionTypes() if (db.driverName().startsWith("QSQLITE")) QCOMPARE(q.record().field(0).type(), QVariant::Invalid); else - QCOMPARE(q.record().field(0).type(), QVariant::Int); + QCOMPARE(q.record().field(0).type(), intType); QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (1)")); QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (2)")); @@ -3599,11 +3603,11 @@ void tst_QSqlQuery::aggregateFunctionTypes() QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName)); QVERIFY(q.next()); QCOMPARE(q.value(0).toInt(), 3); - QCOMPARE(q.record().field(0).type(), QVariant::Int); + QCOMPARE(q.record().field(0).type(), intType); QVERIFY_SQL(q, exec("SELECT AVG(id) FROM " + tableName)); QVERIFY(q.next()); - if (db.driverName().startsWith("QSQLITE")) { + if (db.driverName().startsWith("QSQLITE") || db.driverName().startsWith("QPSQL")) { QCOMPARE(q.value(0).toDouble(), 1.5); QCOMPARE(q.record().field(0).type(), QVariant::Double); } else { @@ -3614,7 +3618,7 @@ void tst_QSqlQuery::aggregateFunctionTypes() QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName)); QVERIFY(q.next()); QCOMPARE(q.value(0).toInt(), 2); - QCOMPARE(q.record().field(0).type(), QVariant::Int); + QCOMPARE(q.record().field(0).type(), intType); QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName)); QVERIFY(q.next()); @@ -3657,7 +3661,7 @@ void tst_QSqlQuery::aggregateFunctionTypes() QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName)); QVERIFY(q.next()); QCOMPARE(q.value(0).toInt(), 2); - QCOMPARE(q.record().field(0).type(), QVariant::Int); + QCOMPARE(q.record().field(0).type(), intType); QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName)); QVERIFY(q.next()); @@ -3669,15 +3673,18 @@ void tst_QSqlQuery::aggregateFunctionTypes() QCOMPARE(q.value(0).toDouble(), 2.5); QCOMPARE(q.record().field(0).type(), QVariant::Double); - QVERIFY_SQL(q, exec("SELECT ROUND(id, 1) FROM " + tableName + " WHERE id=1.5")); - QVERIFY(q.next()); - QCOMPARE(q.value(0).toDouble(), 1.5); - QCOMPARE(q.record().field(0).type(), QVariant::Double); + // PSQL does not have support for the round() function + if (!db.driverName().startsWith("QPSQL")) { + QVERIFY_SQL(q, exec("SELECT ROUND(id, 1) FROM " + tableName + " WHERE id=1.5")); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toDouble(), 1.5); + QCOMPARE(q.record().field(0).type(), QVariant::Double); - QVERIFY_SQL(q, exec("SELECT ROUND(id, 0) FROM " + tableName + " WHERE id=2.5")); - QVERIFY(q.next()); - QCOMPARE(q.value(0).toDouble(), 3.0); - QCOMPARE(q.record().field(0).type(), QVariant::Double); + QVERIFY_SQL(q, exec("SELECT ROUND(id, 0) FROM " + tableName + " WHERE id=2.5")); + QVERIFY(q.next()); + QCOMPARE(q.value(0).toDouble(), 3.0); + QCOMPARE(q.record().field(0).type(), QVariant::Double); + } } { const QString tableName(qTableName("stringFunctions", __FILE__)); -- cgit v1.2.3