mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-05-02 06:29:54 -05:00
changed DM::m_configuration to unordered_map
I have discovered very bad bug that caused crashes because of
invalidated references to the configurations caused by QHash after
insertion using DB::addConnection().
std::unordered_map doesn't invalidates references after insertion or
remove 🙌.
This commit is contained in:
@@ -7,6 +7,8 @@ TINY_SYSTEM_HEADER
|
||||
|
||||
#include <QVariantHash>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "orm/macros/commonnamespace.hpp"
|
||||
#include "orm/macros/threadlocal.hpp"
|
||||
|
||||
@@ -22,7 +24,7 @@ namespace Orm::Support
|
||||
|
||||
public:
|
||||
/*! Type used for Database Connections map. */
|
||||
using ConfigurationsType = QHash<QString, QVariantHash>;
|
||||
using ConfigurationsType = std::unordered_map<QString, QVariantHash>;
|
||||
|
||||
/*! Default constructor. */
|
||||
inline DatabaseConfiguration() = default;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "orm/databasemanager.hpp"
|
||||
|
||||
#include <range/v3/view/map.hpp>
|
||||
|
||||
#include "orm/concerns/hasconnectionresolver.hpp"
|
||||
#include "orm/exceptions/invalidargumenterror.hpp"
|
||||
#include "orm/schema.hpp"
|
||||
@@ -260,7 +262,7 @@ DatabaseManager::addConnection(const QVariantHash &config, const QString &name)
|
||||
QStringLiteral("The database connection '%1' already exists.")
|
||||
.arg(name));
|
||||
|
||||
(*m_configuration).insert(name, config);
|
||||
(*m_configuration).emplace(name, config);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -269,7 +271,7 @@ DatabaseManager &
|
||||
DatabaseManager::addConnections(const ConfigurationsType &configs)
|
||||
{
|
||||
for (auto itConfig = configs.cbegin(); itConfig != configs.cend(); ++itConfig)
|
||||
addConnection(itConfig.value(), itConfig.key());
|
||||
addConnection(itConfig->second, itConfig->first);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@@ -303,7 +305,7 @@ bool DatabaseManager::removeConnection(const QString &name)
|
||||
|
||||
// Not connected
|
||||
if (!(*m_connections).contains(name_)) {
|
||||
(*m_configuration).remove(name_);
|
||||
(*m_configuration).erase(name_);
|
||||
resetDefaultConnection_();
|
||||
return true;
|
||||
}
|
||||
@@ -321,7 +323,7 @@ bool DatabaseManager::removeConnection(const QString &name)
|
||||
Schema::m_schemaBuildersCache.erase(name_);
|
||||
|
||||
// Remove TinyORM configuration
|
||||
(*m_configuration).remove(name_);
|
||||
(*m_configuration).erase(name_);
|
||||
// Remove Qt's database connection
|
||||
QSqlDatabase::removeDatabase(name_);
|
||||
|
||||
@@ -364,7 +366,7 @@ QSqlDatabase DatabaseManager::connectEagerly(const QString &name)
|
||||
|
||||
QStringList DatabaseManager::connectionNames() const
|
||||
{
|
||||
return (*m_configuration).keys();
|
||||
return (*m_configuration) | ranges::views::keys | ranges::to<QStringList>();
|
||||
}
|
||||
|
||||
QStringList DatabaseManager::openedConnectionNames() const
|
||||
|
||||
Reference in New Issue
Block a user