0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

A couple of minor cleanups in the PostgreSQL connector (#518)

* Replace ()-init with {}-init

* Move the method definitions for sqlpp::postgresql::detail::connection_handle inside the class.
This commit is contained in:
MeanSquaredError 2023-08-23 08:19:06 +03:00 committed by GitHub
parent d0dc081625
commit 348511d078
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,20 +58,8 @@ namespace sqlpp
std::unique_ptr<PGconn, void(*)(PGconn*)> postgres; std::unique_ptr<PGconn, void(*)(PGconn*)> postgres;
std::set<std::string> prepared_statement_names; std::set<std::string> prepared_statement_names;
connection_handle(const std::shared_ptr<const connection_config>& config); connection_handle(const std::shared_ptr<const connection_config>& conf)
connection_handle(const connection_handle&) = delete; : config{conf}, postgres{nullptr, PQfinish}
connection_handle(connection_handle&&) = default;
~connection_handle();
connection_handle& operator=(const connection_handle&) = delete;
connection_handle& operator=(connection_handle&&) = default;
void deallocate_prepared_statement(const std::string& name);
PGconn* native_handle() const;
bool check_connection() const;
};
inline connection_handle::connection_handle(const std::shared_ptr<const connection_config>& conf)
: config(conf), postgres{nullptr, PQfinish}
{ {
#ifdef SQLPP_DYNAMIC_LOADING #ifdef SQLPP_DYNAMIC_LOADING
init_pg(""); init_pg("");
@ -204,7 +192,10 @@ namespace sqlpp
} }
} }
inline connection_handle::~connection_handle() connection_handle(const connection_handle&) = delete;
connection_handle(connection_handle&&) = default;
~connection_handle()
{ {
// Debug // Debug
if (config->debug) if (config->debug)
@ -213,7 +204,10 @@ namespace sqlpp
} }
} }
inline void connection_handle::deallocate_prepared_statement(const std::string& name) connection_handle& operator=(const connection_handle&) = delete;
connection_handle& operator=(connection_handle&&) = default;
void deallocate_prepared_statement(const std::string& name)
{ {
std::string cmd = "DEALLOCATE \"" + name + "\""; std::string cmd = "DEALLOCATE \"" + name + "\"";
PGresult* result = PQexec(native_handle(), cmd.c_str()); PGresult* result = PQexec(native_handle(), cmd.c_str());
@ -221,16 +215,17 @@ namespace sqlpp
prepared_statement_names.erase(name); prepared_statement_names.erase(name);
} }
inline PGconn* connection_handle::native_handle() const PGconn* native_handle() const
{ {
return postgres.get(); return postgres.get();
} }
inline bool connection_handle::check_connection() const bool check_connection() const
{ {
auto nh = native_handle(); auto nh = native_handle();
return nh && (PQstatus(nh) == CONNECTION_OK); return nh && (PQstatus(nh) == CONNECTION_OK);
} }
};
} }
} }
} }