diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp index 14374c7ca9..b129499fe6 100644 --- a/src/sql/kernel/qsqldatabase.cpp +++ b/src/sql/kernel/qsqldatabase.cpp @@ -135,6 +135,8 @@ QSqlDatabasePrivate::QSqlDatabasePrivate(const QSqlDatabasePrivate &other) : ref connOptions = other.connOptions; driver = other.driver; precisionPolicy = other.precisionPolicy; + if (driver) + driver->setNumericalPrecisionPolicy(other.driver->numericalPrecisionPolicy()); } QSqlDatabasePrivate::~QSqlDatabasePrivate() @@ -253,6 +255,8 @@ void QSqlDatabasePrivate::copy(const QSqlDatabasePrivate *other) port = other->port; connOptions = other->connOptions; precisionPolicy = other->precisionPolicy; + if (driver) + driver->setNumericalPrecisionPolicy(other->driver->numericalPrecisionPolicy()); } void QSqlDatabasePrivate::disable() 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"