libdballe  7.6
Public Member Functions | Protected Member Functions | Protected Attributes
dballe::db::PostgreSQLConnection Class Reference

Database connection. More...

#include <internals.h>

Inheritance diagram for dballe::db::PostgreSQLConnection:
dballe::db::Connection

Public Member Functions

 PostgreSQLConnection (const PostgreSQLConnection &)=delete
 
 PostgreSQLConnection (const PostgreSQLConnection &&)=delete
 
PostgreSQLConnectionoperator= (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< Transactiontransaction () 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 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...
 
- Public Member Functions inherited from dballe::db::Connection
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.
 

Protected Member Functions

void init_after_connect ()
 

Protected Attributes

PGconn * db = nullptr
 Database connection.
 
- Protected Attributes inherited from dballe::db::Connection
std::string url
 

Additional Inherited Members

- Static Public Member Functions inherited from dballe::db::Connection
static std::unique_ptr< Connectioncreate_from_url (const char *url)
 Create a new connection from a URL.
 
static std::unique_ptr< Connectioncreate_from_url (const std::string &url)
 Create a new connection from a URL.
 
- Data Fields inherited from dballe::db::Connection
ServerType server_type
 Type of SQL server we are connected to. More...
 

Detailed Description

Database connection.

Member Function Documentation

std::string dballe::db::PostgreSQLConnection::get_setting ( const std::string &  key)
overridevirtual

Get a value from the settings table.

Returns the empty string if the table does not exist.

Implements dballe::db::Connection.

void dballe::db::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

void dballe::db::PostgreSQLConnection::pqexec_nothrow ( const std::string &  query)
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.

void dballe::db::PostgreSQLConnection::set_setting ( const std::string &  key,
const std::string &  value 
)
overridevirtual

Set a value in the settings table.

The table is created if it does not exist.

Implements dballe::db::Connection.

std::unique_ptr<Transaction> dballe::db::PostgreSQLConnection::transaction ( )
overridevirtual

Begin a transaction.

The transaction will be controller by the returned Transaction object, and will end when its destuctor is called.

Implements dballe::db::Connection.


The documentation for this class was generated from the following file: