QSqlDriver: return the connection name of the assoicated QSqlDatabase
A QSqlDriver instance is directly bound to a QSqlDatabase object. But there was no way to get the QSqlDatabase out of a QSqlQuery/QSqlDriver. Fix it by storing the connection name also in the driver during creation and add a getter for it. [ChangeLog][QtSql][QSqlDriver] Added connectionName() which returns the connection name of the associated QSqlDatabase instance. Task-number: QTBUG-123603 Change-Id: If78b85413cf6ca965ff6bf9f3600cb54169b5569 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 5b07e3de3fe5335d9338c65ca40cfe656a389167) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ed1032975e
commit
fc29afbe1a
@ -110,8 +110,11 @@ QSqlDatabasePrivate::QSqlDatabasePrivate(const QSqlDatabasePrivate &other) : ref
|
||||
connOptions = other.connOptions;
|
||||
driver = other.driver;
|
||||
precisionPolicy = other.precisionPolicy;
|
||||
if (driver)
|
||||
if (driver) {
|
||||
driver->setNumericalPrecisionPolicy(other.driver->numericalPrecisionPolicy());
|
||||
auto drvPriv = static_cast<QSqlDriverPrivate *>(QObjectPrivate::get(driver));
|
||||
drvPriv->connectionName = connName;
|
||||
}
|
||||
}
|
||||
|
||||
QSqlDatabasePrivate::~QSqlDatabasePrivate()
|
||||
@ -169,6 +172,8 @@ void QSqlDatabasePrivate::addDatabase(const QSqlDatabase &db, const QString &nam
|
||||
}
|
||||
sqlGlobals->connections.insert(name, db);
|
||||
db.d->connName = name;
|
||||
auto drvPriv = static_cast<QSqlDriverPrivate *>(QObjectPrivate::get(db.d->driver));
|
||||
drvPriv->connectionName = name;
|
||||
}
|
||||
|
||||
/*! \internal
|
||||
|
@ -801,6 +801,18 @@ int QSqlDriver::maximumIdentifierLength(QSqlDriver::IdentifierType type) const
|
||||
return INT_MAX;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 6.9
|
||||
|
||||
Returns the database connection name the driver was created by with
|
||||
QSqlDatabase::addDatabase()
|
||||
*/
|
||||
QString QSqlDriver::connectionName() const
|
||||
{
|
||||
Q_D(const QSqlDriver);
|
||||
return d->connectionName;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#include "moc_qsqldriver.cpp"
|
||||
|
@ -25,6 +25,7 @@ class QVariant;
|
||||
class Q_SQL_EXPORT QSqlDriver : public QObject
|
||||
{
|
||||
friend class QSqlDatabase;
|
||||
friend class QSqlDatabasePrivate;
|
||||
friend class QSqlResultPrivate;
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QSql::NumericalPrecisionPolicy numericalPrecisionPolicy READ numericalPrecisionPolicy WRITE setNumericalPrecisionPolicy)
|
||||
@ -98,6 +99,9 @@ public:
|
||||
|
||||
DbmsType dbmsType() const;
|
||||
virtual int maximumIdentifierLength(IdentifierType type) const;
|
||||
|
||||
QString connectionName() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual bool cancelQuery();
|
||||
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
dbmsType(type)
|
||||
{ }
|
||||
|
||||
QString connectionName;
|
||||
QSqlError error;
|
||||
QSql::NumericalPrecisionPolicy precisionPolicy = QSql::LowPrecisionDouble;
|
||||
QSqlDriver::DbmsType dbmsType;
|
||||
|
Loading…
x
Reference in New Issue
Block a user