summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorIsrael Lins <israel@proabakus.com.br>2014-11-01 11:29:14 -0300
committerMark Brand <mabrand@mabrand.nl>2014-12-30 23:56:13 +0100
commit5fefec9136fb2aac73f9e54037d2f6809021f011 (patch)
tree1988ac38ad8f0de8cc5bfd718ac7f84ef7e07544 /tests
parentb60773934dc0231b53e1fde3e5927d969bbf6298 (diff)
Added ROUND test for PostgreSQL
The ROUND function for PostgreSQL only accept NUMERIC field as argument Change-Id: I0c3753bfe4167cd47158e21b407cca8771816104 Reviewed-by: Mark Brand <mabrand@mabrand.nl>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
index 1943b6ec92..a862ce2094 100644
--- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp
@@ -3864,21 +3864,25 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QCOMPARE(q.value(0).toDouble(), 2.5);
QCOMPARE(q.record().field(0).type(), QVariant::Double);
- // PSQL does not have support for the round() function
- if (dbType != QSqlDriver::PostgreSQL) {
- 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);
+ QString field = "id";
- QVERIFY_SQL(q, exec("SELECT ROUND(id, 0) FROM " + tableName + " WHERE id=2.5"));
- QVERIFY(q.next());
- if (dbType == QSqlDriver::MySqlServer)
- QCOMPARE(q.value(0).toDouble(), 2.0);
- else
- QCOMPARE(q.value(0).toDouble(), 3.0);
- QCOMPARE(q.record().field(0).type(), QVariant::Double);
+ // PSQL does not have the round() function with real type
+ if (dbType == QSqlDriver::PostgreSQL) {
+ field += "::NUMERIC";
}
+
+ QVERIFY_SQL(q, exec("SELECT ROUND(" + field + ", 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(" + field + ", 0) FROM " + tableName + " WHERE id=2.5"));
+ QVERIFY(q.next());
+ if (dbType == QSqlDriver::MySqlServer)
+ QCOMPARE(q.value(0).toDouble(), 2.0);
+ else
+ QCOMPARE(q.value(0).toDouble(), 3.0);
+ QCOMPARE(q.record().field(0).type(), QVariant::Double);
}
{
const QString tableName(qTableName("stringFunctions", __FILE__, db));