libdballe
9.11
|
Database connection. More...
#include <postgresql.h>
Public Member Functions | |
PostgreSQLConnection (const PostgreSQLConnection &)=delete | |
PostgreSQLConnection (const PostgreSQLConnection &&)=delete | |
PostgreSQLConnection & | operator= (const PostgreSQLConnection &)=delete |
operator PGconn * () | |
void | open_url (const std::string &connection_string) |
Connect to PostgreSQL using a connection URI. More... | |
void | open_test () |
std::unique_ptr< Transaction > | transaction (bool readonly=false) override |
Begin a transaction. More... | |
void | prepare (const std::string &name, const std::string &query) |
Precompile a query. | |
postgresql::Result | exec_unchecked (const char *query) |
postgresql::Result | exec_unchecked (const std::string &query) |
template<typename STRING > | |
void | exec_no_data (STRING query) |
template<typename STRING > | |
postgresql::Result | exec (STRING query) |
template<typename STRING > | |
postgresql::Result | exec_one_row (STRING query) |
template<typename ... ARGS> | |
postgresql::Result | exec_unchecked (const char *query, ARGS... args) |
template<typename ... ARGS> | |
postgresql::Result | exec_unchecked (const std::string &query, ARGS... args) |
template<typename STRING , typename ... ARGS> | |
void | exec_no_data (STRING query, ARGS... args) |
template<typename STRING , typename ... ARGS> | |
postgresql::Result | exec (STRING query, ARGS... args) |
template<typename STRING , typename ... ARGS> | |
postgresql::Result | exec_one_row (STRING query, ARGS... args) |
postgresql::Result | exec_prepared_unchecked (const char *name) |
postgresql::Result | exec_prepared_unchecked (const std::string &name) |
template<typename STRING > | |
void | exec_prepared_no_data (STRING name) |
template<typename STRING > | |
postgresql::Result | exec_prepared (STRING name) |
template<typename STRING > | |
postgresql::Result | exec_prepared_one_row (STRING name) |
template<typename ... ARGS> | |
postgresql::Result | exec_prepared_unchecked (const char *name, ARGS... args) |
template<typename ... ARGS> | |
postgresql::Result | exec_prepared_unchecked (const std::string &name, ARGS... args) |
template<typename STRING , typename ... ARGS> | |
void | exec_prepared_no_data (STRING name, ARGS... args) |
template<typename STRING , typename ... ARGS> | |
postgresql::Result | exec_prepared (STRING name, ARGS... args) |
template<typename STRING , typename ... ARGS> | |
postgresql::Result | exec_prepared_one_row (STRING name, ARGS... args) |
void | cancel_running_query_nothrow () noexcept |
Send a cancellation command to the server. | |
void | discard_all_input_nothrow () noexcept |
Discard all input from an asynchronous request. | |
bool | has_table (const std::string &name) override |
Check if the database contains a table. | |
std::string | get_setting (const std::string &key) override |
Get a value from the settings table. More... | |
void | set_setting (const std::string &key, const std::string &value) override |
Set a value in the settings table. More... | |
void | drop_settings () override |
Drop the settings table. | |
void | execute (const std::string &query) override |
Execute a query without reading its results. | |
void | explain (const std::string &query, FILE *out) override |
Format and print the EXPLAIN output for the query to the given file. | |
void | drop_table_if_exists (const char *name) |
Delete a table in the database if it exists, otherwise do nothing. | |
int | changes () |
Count the number of rows modified by the last query that was run. | |
void | pqexec (const std::string &query) |
Wrap PQexec. | |
void | pqexec_nothrow (const std::string &query) noexcept |
Wrap PQexec but do not throw an exception in case of errors. More... | |
void | run_single_row_mode (const std::string &query_desc, std::function< void(const postgresql::Result &)> dest) |
Retrieve query results in single row mode. | |
void | append_escaped (Querybuf &qb, const char *str) |
Escape the string as a literal value and append it to qb. | |
void | append_escaped (Querybuf &qb, const std::string &str) |
Escape the string as a literal value and append it to qb. | |
void | append_escaped (Querybuf &qb, const std::vector< uint8_t > &buf) |
Escape the buffer as bytea literal and append it to qb. | |
![]() | |
const std::string & | get_url () const |
virtual void | add_datetime (Querybuf &qb, const Datetime &dt) const |
Format a datetime and add it to the querybuf. | |
Static Public Member Functions | |
static std::shared_ptr< PostgreSQLConnection > | create () |
![]() | |
static std::shared_ptr< Connection > | create (const DBConnectOptions &options) |
Create a new connection from a URL. | |
Protected Member Functions | |
void | init_after_connect () |
void | fork_prepare () override |
void | fork_parent () override |
void | fork_child () override |
void | check_connection () |
![]() | |
void | register_atfork () |
Register this connection to be notified in case of fork()-ing. | |
Protected Attributes | |
PGconn * | db = nullptr |
Database connection. | |
std::unordered_set< std::string > | prepared_names |
bool | forked = false |
Marker to catch attempts to reuse connections in forked processes. | |
![]() | |
std::string | url |
Additional Inherited Members | |
![]() | |
ServerType | server_type |
Type of SQL server we are connected to. More... | |
Database connection.
|
overridevirtual |
Get a value from the settings table.
Returns the empty string if the table does not exist.
Implements dballe::sql::Connection.
void dballe::sql::PostgreSQLConnection::open_url | ( | const std::string & | connection_string | ) |
Connect to PostgreSQL using a connection URI.
The syntax is described at: http://www.postgresql.org/docs/9.4/static/libpq-connect.html#AEN41094
|
noexcept |
Wrap PQexec but do not throw an exception in case of errors.
This is useful to be called in destructors. Errors will be printed to stderr.
|
overridevirtual |
Set a value in the settings table.
The table is created if it does not exist.
Implements dballe::sql::Connection.
|
overridevirtual |
Begin a transaction.
The transaction will be controller by the returned Transaction object, and will end when its destuctor is called.
Implements dballe::sql::Connection.