summaryrefslogtreecommitdiffstats
path: root/tests/auto/sql
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@digia.com>2012-12-20 19:20:27 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-12-22 14:43:28 +0100
commit69627730eaf3a024186e2f2dad1842aa32d9ccb8 (patch)
tree4237cc0e225e89b4d65d5743fe122bb32948e603 /tests/auto/sql
parent2ebb71468642b7ba3360d5169c0a7e5b3178c4dc (diff)
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 <mabrand@mabrand.nl>
Diffstat (limited to 'tests/auto/sql')
-rw-r--r--tests/auto/sql/kernel/qsqldatabase/tst_databases.h7
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp35
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__));