diff options
Diffstat (limited to 'src/sql/kernel/qsqldatabase.cpp')
-rw-r--r-- | src/sql/kernel/qsqldatabase.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/sql/kernel/qsqldatabase.cpp b/src/sql/kernel/qsqldatabase.cpp index 2c7b4b83db..12ab9671b5 100644 --- a/src/sql/kernel/qsqldatabase.cpp +++ b/src/sql/kernel/qsqldatabase.cpp @@ -1380,6 +1380,40 @@ QSqlDatabase QSqlDatabase::cloneDatabase(const QSqlDatabase &other, const QStrin } /*! + \since 5.13 + \overload + + Clones the database connection \a other and stores it as \a + connectionName. All the settings from the original database, e.g. + databaseName(), hostName(), etc., are copied across. Does nothing + if \a other is an invalid database. Returns the newly created + database connection. + + \note The new connection has not been opened. Before using the new + connection, you must call open(). + + This overload is useful when cloning the database in another thread to the + one that is used by the database represented by \a other. +*/ + +QSqlDatabase QSqlDatabase::cloneDatabase(const QString &other, const QString &connectionName) +{ + const QConnectionDict *dict = dbDict(); + Q_ASSERT(dict); + + dict->lock.lockForRead(); + QSqlDatabase otherDb = dict->value(other); + dict->lock.unlock(); + if (!otherDb.isValid()) + return QSqlDatabase(); + + QSqlDatabase db(otherDb.driverName()); + db.d->copy(otherDb.d); + QSqlDatabasePrivate::addDatabase(db, connectionName); + return db; +} + +/*! \since 4.4 Returns the connection name, which may be empty. \note The |