drivers removed driverWeakInternal()

This is possible after the std::enable_shared_from_this<MySqlDriver> was
added.
This commit is contained in:
silverqx
2024-07-28 00:30:06 +02:00
parent 5651efcac2
commit 88b8286e35
2 changed files with 2 additions and 20 deletions

View File

@@ -178,9 +178,6 @@ namespace MySql
private: private:
/* Getters / Setters */ /* Getters / Setters */
/*! Get the SQL database driver used to access the database connection. */
std::weak_ptr<SqlDriver> driverWeakInternal() noexcept;
/*! Get the current connection name. */ /*! Get the current connection name. */
QString connectionName() const noexcept; QString connectionName() const noexcept;

View File

@@ -444,11 +444,8 @@ QVariant SqlQuery::lastInsertId() const
void SqlQuery::clear() void SqlQuery::clear()
{ {
// Ownership of a weak_ptr()
const auto driver = driverWeakInternal();
// Get a new empty SqlResult instance // Get a new empty SqlResult instance
*this = SqlQuery(driver.lock()->createResult(driver)); *this = SqlQuery(driverWeak().lock()->createResult());
} }
void SqlQuery::finish() noexcept void SqlQuery::finish() noexcept
@@ -466,18 +463,6 @@ void SqlQuery::finish() noexcept
/* Getters / Setters */ /* Getters / Setters */
/* Leave the non-const driverWeak() private, it's correct, it's not needed anywhere and
is for special cases only. */
std::weak_ptr<SqlDriver> SqlQuery::driverWeakInternal() noexcept
{
/* This must be the std::weak_ptr() because when the connection is removed from
the SqlDatabaseManager using the SqlDatabase::removeDatabase() then the SqlDriver
is invalidated (using the std::shared_ptr::reset()).
This means we don't want to keep the SqlDriver alive after removeDatabase(). */
return m_sqlResult->driver();
}
QString SqlQuery::connectionName() const noexcept QString SqlQuery::connectionName() const noexcept
{ {
return m_sqlResult->connectionName(); return m_sqlResult->connectionName();
@@ -488,7 +473,7 @@ QString SqlQuery::connectionName() const noexcept
void SqlQuery::throwIfNoDatabaseConnection() void SqlQuery::throwIfNoDatabaseConnection()
{ {
// Nothing to do // Nothing to do
if (this->driverWeakInternal().lock()->isOpen()) if (driverWeak().lock()->isOpen())
return; return;
throw Exceptions::LogicError( throw Exceptions::LogicError(