diff options
author | Andy Shaw <andy.shaw@qt.io> | 2017-11-30 17:16:06 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2017-12-01 10:52:44 +0000 |
commit | c4ba2b1c70218f76366575ee7e6d90eb99efbb08 (patch) | |
tree | 0314859f575d4e76847dd21748fe68418b3ec179 /tests/auto/sql/kernel | |
parent | 33b03d99cdaff3e8292b31bc166d97b8f5775640 (diff) |
Copy the numericalPrecisionPolicy when copying the QSqlDatabase
As the numercialPrecisionPolicy can be set and subsequently retrieved
from the QSqlDatabase's driver, then when copying the QSqlDatabase, we
need to set that appropriately too.
Task-number: QTBUG-10452
Change-Id: I2c63748365ab4e9fbc29d8d460d80d2e2a0ee385
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/sql/kernel')
-rw-r--r-- | tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp index 210b6311a9..ec5afd2b5c 100644 --- a/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/sql/kernel/qsqldatabase/tst_qsqldatabase.cpp @@ -75,6 +75,8 @@ private slots: void addDatabase(); void errorReporting_data(); void errorReporting(); + void cloneDatabase_data() { generic_data(); } + void cloneDatabase(); //database specific tests void recordMySQL_data() { generic_data("QMYSQL"); } @@ -2286,5 +2288,34 @@ void tst_QSqlDatabase::sqlite_enableRegexp() QFAIL_SQL(q, next()); } +void tst_QSqlDatabase::cloneDatabase() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + { + QSqlDatabase clonedDatabase = QSqlDatabase::cloneDatabase(db, "clonedDatabase"); + QCOMPARE(clonedDatabase.databaseName(), db.databaseName()); + QCOMPARE(clonedDatabase.userName(), db.userName()); + QCOMPARE(clonedDatabase.password(), db.password()); + QCOMPARE(clonedDatabase.hostName(), db.hostName()); + QCOMPARE(clonedDatabase.driverName(), db.driverName()); + QCOMPARE(clonedDatabase.port(), db.port()); + QCOMPARE(clonedDatabase.connectOptions(), db.connectOptions()); + QCOMPARE(clonedDatabase.numericalPrecisionPolicy(), db.numericalPrecisionPolicy()); + } + { + // Now double check numericalPrecisionPolicy after changing it since it + // is a special case, as changing it can set it on the driver as well as + // the database object. When retrieving the numerical precision policy + // it may just get it from the driver so we have to check that the + // clone has also ensured the copied driver has the correct precision + // policy too. + db.setNumericalPrecisionPolicy(QSql::LowPrecisionDouble); + QSqlDatabase clonedDatabase = QSqlDatabase::cloneDatabase(db, "clonedDatabaseCopy"); + QCOMPARE(clonedDatabase.numericalPrecisionPolicy(), db.numericalPrecisionPolicy()); + } +} + QTEST_MAIN(tst_QSqlDatabase) #include "tst_qsqldatabase.moc" |