Public Member Functions | Data Fields | Friends
psql::Database Class Reference

Represents a connection to PostgreSQL database. More...

#include <Database.h>

Public Member Functions

 Database (Database const &)
Databaseoperator= (Database const &)
 Database (Database &&other)
 Move constructs Database from other Database.
Databaseoperator= (Database &&other)
 Move assigns from other Database.
 Database (std::string const &conninfo, bool synchr=false)
 Connects to database.
void regist (std::string const &name, std::string const &sql, IStatement *st)
 Prepares server side prepared statement.
void unregist (std::string const &name, IStatement *st)
 Deallocates server side prepared statement.
void begin_transaction ()
 Starts a transaction on this connection.
void commit_transaction ()
 Commits a transaction on this connection.
void rollback_transaction ()
 Rollbacks a transaction on this connection.
void savepoint (std::string const &name)
 Creates a savepoint in transaction.
void rollback_to_savepoint (std::string const &name)
 Rollbacks current transaction to given savepoint.
void analyze ()
 Runs ANALYZE on database.
void set_schema (std::string schema)
 Sets search path on this connection.
void create_schema (std::string const &schema)
 Create schema with given name.
bool in_transaction ()
bool in_failed_transaction ()
PGconn * get_db ()
 Retrieve underlying PGconn* from this connection.
void add_cursor (ICursor *curs)
 Adds a cursor to cursor collection.
void remove_cursor (ICursor *curs)
 Removes a cursor from cursor collection.
bool is_cursor (ICursor *curs) const
virtual ~Database ()

Data Fields

boost::signal< void(PGresult
const &)> & 
notice_signal ()

Friends

void noticeReceiver (void *arg, PGresult const *res)

Detailed Description

Represents a connection to PostgreSQL database.

Definition at line 21 of file Database.h.


Constructor & Destructor Documentation

psql::Database::Database ( Database const &  )
psql::Database::Database ( Database &&  other)

Move constructs Database from other Database.

Parameters:
other
psql::Database::Database ( std::string const &  conninfo,
bool  synchr = false 
)

Connects to database.

Parameters:
conninfoconnection info string (see libpq documentation)
synchrwhether connection is synchronous

Definition at line 94 of file Database.cpp.

psql::Database::~Database ( ) [virtual]

Definition at line 169 of file Database.cpp.


Member Function Documentation

void psql::Database::add_cursor ( ICursor curs)

Adds a cursor to cursor collection.

Cursor class does this automatically, so you shouldn't need to call this.

Parameters:
curs

Definition at line 74 of file Database.cpp.

void psql::Database::analyze ( )

Runs ANALYZE on database.

Definition at line 43 of file Database.cpp.

void psql::Database::begin_transaction ( )

Starts a transaction on this connection.

Definition at line 11 of file Database.cpp.

void psql::Database::commit_transaction ( )

Commits a transaction on this connection.

Definition at line 16 of file Database.cpp.

void psql::Database::create_schema ( std::string const &  schema)

Create schema with given name.

Parameters:
schemaname of the schema to create

Definition at line 55 of file Database.cpp.

PGconn * psql::Database::get_db ( )

Retrieve underlying PGconn* from this connection.

Returns:
underlying PGconn*

Definition at line 120 of file Database.cpp.

bool psql::Database::in_failed_transaction ( )
Returns:
wheteher a failed transaction is in progress (and thus rollback needs to be called before anything else)

Definition at line 67 of file Database.cpp.

bool psql::Database::in_transaction ( )
Returns:
whether a non-failed transaction is in progress

Definition at line 60 of file Database.cpp.

bool psql::Database::is_cursor ( ICursor curs) const
Parameters:
curs
Returns:
true if curs is in cursor collection

Definition at line 84 of file Database.cpp.

Database& psql::Database::operator= ( Database const &  )
Database& psql::Database::operator= ( Database &&  other)

Move assigns from other Database.

Parameters:
other
Returns:
*this
void psql::Database::regist ( std::string const &  name,
std::string const &  sql,
IStatement st 
)

Prepares server side prepared statement.

psql::Statement class does this automatically so you probably shouldn't call this.

Parameters:
namestatement name
sqlstatement sql
stpointer to statement

Definition at line 175 of file Database.cpp.

void psql::Database::remove_cursor ( ICursor curs)

Removes a cursor from cursor collection.

Cursor class does this automatically, so you shouldn't need to call this.

Parameters:
curs

Definition at line 79 of file Database.cpp.

void psql::Database::rollback_to_savepoint ( std::string const &  name)

Rollbacks current transaction to given savepoint.

Parameters:
namesavepoint name

Definition at line 38 of file Database.cpp.

void psql::Database::rollback_transaction ( )

Rollbacks a transaction on this connection.

Definition at line 23 of file Database.cpp.

void psql::Database::savepoint ( std::string const &  name)

Creates a savepoint in transaction.

Parameters:
namesavepoint name

Definition at line 30 of file Database.cpp.

void psql::Database::set_schema ( std::string  schema)

Sets search path on this connection.

Parameters:
schemasearch path (can be single schema or comma separated search path)

Definition at line 48 of file Database.cpp.

void psql::Database::unregist ( std::string const &  name,
IStatement st 
)

Deallocates server side prepared statement.

psql::Statement class does this automatically so you probably shouldn't call this.

Parameters:
namestatement name
stpointer to statement

Definition at line 190 of file Database.cpp.


Friends And Related Function Documentation

void noticeReceiver ( void *  arg,
PGresult const *  res 
) [friend]

Definition at line 89 of file Database.cpp.


Field Documentation

boost::signal< void(const PGresult &)> & psql::Database::notice_signal
Returns:
boost::signal to connect to if you want to be informed about notices received from this connection

Definition at line 113 of file Database.h.


The documentation for this class was generated from the following files:
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines