summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qsqldatabase/tst_qsqldatabase.cpp')
-rw-r--r--tests/auto/qsqldatabase/tst_qsqldatabase.cpp52
1 files changed, 34 insertions, 18 deletions
diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
index 21064c3..31a699c 100644
--- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
+++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp
@@ -249,7 +249,7 @@ struct FieldDef {
// excluding the primary key field
static int createFieldTable(const FieldDef fieldDefs[], QSqlDatabase db)
{
- tst_Databases::safeDropTables(db, QStringList() << qTableName("qtestfields"));
+ tst_Databases::safeDropTable(db, qTableName("qtestfields"));
QSqlQuery q(db);
// construct a create table statement consisting of all fieldtypes
QString qs = "create table " + qTableName("qtestfields");
@@ -358,6 +358,7 @@ void tst_QSqlDatabase::dropTestTables(QSqlDatabase db)
tableNames << (qTableName("qtest") + " test");
tst_Databases::safeDropTables(db, tableNames);
+ tst_Databases::safeDropView(db, qTableName("qtest_view"));
}
void tst_QSqlDatabase::populateTestTables(QSqlDatabase db)
@@ -541,11 +542,6 @@ void tst_QSqlDatabase::tables()
QVERIFY(tables.contains(qTableName("temp_tab"), Qt::CaseInsensitive));
QVERIFY(tables.contains(qTableName("qtest"), Qt::CaseInsensitive));
- if (tst_Databases::isMSAccess(db))
- QSqlQuery("drop table " + qTableName("qtest_view"), db);
- else
- QSqlQuery("drop view " + qTableName("qtest_view"), db);
-
if (db.driverName().startsWith("QPSQL")) {
QVERIFY(tables.contains(qTableName("qtest") + " test"));
}
@@ -1082,8 +1078,8 @@ void tst_QSqlDatabase::recordMySQL()
FieldDef("bigint unsigned", QVariant::ULongLong, Q_UINT64_C(18446744073709551615)),
FieldDef("float", QVariant::Double, 1.12345),
FieldDef("double", QVariant::Double, 1.123456789),
- FieldDef("decimal(10, 9)", QVariant::String,1.123456789),
- FieldDef("numeric(5, 2)", QVariant::String, 123.67),
+ FieldDef("decimal(10, 9)", QVariant::Double,1.123456789),
+ FieldDef("numeric(5, 2)", QVariant::Double, 123.67),
FieldDef("date", QVariant::Date, QDate::currentDate()),
FieldDef("datetime", QVariant::DateTime, dt),
FieldDef("timestamp", QVariant::DateTime, dt, false),
@@ -1630,62 +1626,82 @@ void tst_QSqlDatabase::precisionPolicy()
QSKIP("Driver or database doesn't support setting precision policy", SkipSingle);
// Create a test table with some data
- QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id smallint, num numeric(20,0))").arg(tableName)));
+ QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id smallint, num numeric(18,5))").arg(tableName)));
QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?, ?)").arg(tableName)));
q.bindValue(0, 1);
q.bindValue(1, 123);
QVERIFY_SQL(q, exec());
q.bindValue(0, 2);
- q.bindValue(1, QString("18500000000000000000"));
+ q.bindValue(1, 1850000000000.0001);
QVERIFY_SQL(q, exec());
// These are expected to pass
+ q.setNumericalPrecisionPolicy(QSql::HighPrecision);
QString query = QString("SELECT num FROM %1 WHERE id = 1").arg(tableName);
QVERIFY_SQL(q, exec(query));
QVERIFY_SQL(q, next());
+ if(db.driverName().startsWith("QSQLITE"))
+ QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::String);
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64);
QVERIFY_SQL(q, exec(query));
QVERIFY_SQL(q, next());
+ if(q.value(0).type() != QVariant::LongLong)
+ QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::LongLong);
QCOMPARE(q.value(0).toLongLong(), (qlonglong)123);
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt32);
QVERIFY_SQL(q, exec(query));
QVERIFY_SQL(q, next());
+ if(db.driverName().startsWith("QSQLITE"))
+ QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::Int);
QCOMPARE(q.value(0).toInt(), 123);
q.setNumericalPrecisionPolicy(QSql::LowPrecisionDouble);
QVERIFY_SQL(q, exec(query));
QVERIFY_SQL(q, next());
+ if(db.driverName().startsWith("QSQLITE"))
+ QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::Double);
QCOMPARE(q.value(0).toDouble(), (double)123);
query = QString("SELECT num FROM %1 WHERE id = 2").arg(tableName);
QVERIFY_SQL(q, exec(query));
QVERIFY_SQL(q, next());
+ if(db.driverName().startsWith("QSQLITE"))
+ QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::Double);
- QCOMPARE(q.value(0).toDouble(), QString("18500000000000000000").toDouble());
+ QCOMPARE(q.value(0).toDouble(), QString("1850000000000.0001").toDouble());
// Postgres returns invalid QVariants on overflow
q.setNumericalPrecisionPolicy(QSql::HighPrecision);
QVERIFY_SQL(q, exec(query));
QVERIFY_SQL(q, next());
+ if(db.driverName().startsWith("QSQLITE"))
+ QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::String);
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64);
+ QEXPECT_FAIL("QOCI", "Oracle fails here, to retrieve next", Continue);
QVERIFY_SQL(q, exec(query));
QVERIFY_SQL(q, next());
- QCOMPARE(q.value(0).type(), QVariant::Invalid);
+ if(db.driverName().startsWith("QSQLITE"))
+ QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
+ QCOMPARE(q.value(0).type(), QVariant::LongLong);
- q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt32);
- QVERIFY_SQL(q, exec(query));
- if(db.driverName().startsWith("QOCI"))
- QEXPECT_FAIL("", "Oracle fails to move to next when data columns are oversize", Abort);
- QVERIFY_SQL(q, next());
- QCOMPARE(q.value(0).type(), QVariant::Invalid);
+ QSql::NumericalPrecisionPolicy oldPrecision= db.numericalPrecisionPolicy();
+ db.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64);
+ QSqlQuery q2(db);
+ q2.exec(QString("SELECT num FROM %1 WHERE id = 2").arg(tableName));
+ QVERIFY_SQL(q2, exec(query));
+ QVERIFY_SQL(q2, next());
+ if(db.driverName().startsWith("QSQLITE"))
+ QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
+ QCOMPARE(q2.value(0).type(), QVariant::LongLong);
+ db.setNumericalPrecisionPolicy(oldPrecision);
}
// This test needs a ODBC data source containing MYSQL in it's name