mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-05 04:30:43 -06:00
Const connection config (#494)
- The postgres connection does not change the connection_config thus passing it as const. - Implies 'thread safety' when using the same config for multiple connections Co-authored-by: Carel Combrink <carel.combrink@vastech.co.za>
This commit is contained in:
@@ -182,7 +182,7 @@ namespace sqlpp
|
||||
|
||||
// ctor / dtor
|
||||
connection();
|
||||
connection(const std::shared_ptr<connection_config>& config);
|
||||
connection(const std::shared_ptr<const connection_config>& config);
|
||||
~connection();
|
||||
connection(const connection&) = delete;
|
||||
connection(connection&&);
|
||||
@@ -190,7 +190,7 @@ namespace sqlpp
|
||||
connection& operator=(connection&&);
|
||||
|
||||
// creates a connection handle and connects to database
|
||||
void connectUsing(const std::shared_ptr<connection_config>& config) noexcept(false);
|
||||
void connectUsing(const std::shared_ptr<const connection_config>& config) noexcept(false);
|
||||
|
||||
// Select stmt (returns a result)
|
||||
template <typename Select>
|
||||
@@ -391,7 +391,7 @@ namespace sqlpp
|
||||
{
|
||||
}
|
||||
|
||||
inline connection::connection(const std::shared_ptr<connection_config>& config)
|
||||
inline connection::connection(const std::shared_ptr<const connection_config>& config)
|
||||
: _handle(new detail::connection_handle(config))
|
||||
{
|
||||
}
|
||||
@@ -417,7 +417,7 @@ namespace sqlpp
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline void connection::connectUsing(const std::shared_ptr<connection_config>& config) noexcept(false)
|
||||
inline void connection::connectUsing(const std::shared_ptr<const connection_config>& config) noexcept(false)
|
||||
{
|
||||
this->_handle.reset(new detail::connection_handle(config));
|
||||
}
|
||||
|
||||
@@ -60,11 +60,11 @@ namespace sqlpp
|
||||
|
||||
struct DLL_LOCAL connection_handle
|
||||
{
|
||||
std::shared_ptr<connection_config> config;
|
||||
std::shared_ptr<const connection_config> config;
|
||||
std::unique_ptr<PGconn, void(*)(PGconn*)> postgres;
|
||||
std::set<std::string> prepared_statement_names;
|
||||
|
||||
connection_handle(const std::shared_ptr<connection_config>& config);
|
||||
connection_handle(const std::shared_ptr<const connection_config>& config);
|
||||
connection_handle(const connection_handle&) = delete;
|
||||
connection_handle(connection_handle&&) = default;
|
||||
connection_handle& operator=(const connection_handle&) = delete;
|
||||
@@ -79,7 +79,7 @@ namespace sqlpp
|
||||
void deallocate_prepared_statement(const std::string& name);
|
||||
};
|
||||
|
||||
inline connection_handle::connection_handle(const std::shared_ptr<connection_config>& conf)
|
||||
inline connection_handle::connection_handle(const std::shared_ptr<const connection_config>& conf)
|
||||
: config(conf), postgres{nullptr, handle_cleanup}
|
||||
{
|
||||
#ifdef SQLPP_DYNAMIC_LOADING
|
||||
|
||||
Reference in New Issue
Block a user