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>
This commit is contained in:
Andy Shaw 2017-11-30 17:16:06 +01:00
parent 33b03d99cd
commit c4ba2b1c70
2 changed files with 35 additions and 0 deletions

View File

@ -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()

View File

@ -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"