Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

pqxx::Connection Class Reference

Connection class; represents a connection to a database. More...

#include <connection.h>

List of all members.

Public Methods

 Connection (const PGSTD::string &ConnInfo, bool Immediate=true)
 Constructor. Sets up connection based on PostgreSQL connection string.

 ~Connection ()
 Destructor. Implicitly closes the connection.

void Disconnect () const throw ()
 Explicitly close connection.

bool IsOpen () const
 Is this connection open?

template<typename TRANSACTOR> void Perform (const TRANSACTOR &, int Attempts=3)
 Perform the transaction defined by a Transactor-based object.

NoticeProcessor SetNoticeProcessor (NoticeProcessor, void *arg)
 Set callback method for postgresql status output.

void ProcessNotice (const char[]) throw ()
 Invoke notice processor function. The message should end in newline.

void ProcessNotice (PGSTD::string msg) throw ()
 Invoke notice processor function. The message should end in newline.

void Trace (FILE *)
 Enable tracing to a given output stream, or NULL to disable.

void Untrace ()
 Disable tracing. OBSOLETE. Use Trace(0).

void GetNotifs ()
 Check for pending trigger notifications and take appropriate action.

const char * DbName () const throw ()
 Name of database we're connected to, if any.

const char * UserName () const throw ()
 Database user ID we're connected under, if any.

const char * HostName () const throw ()
 Address of server (NULL for local connections).

const char * Port () const throw ()
 Server port number we're connected to.

const char * Options () const throw ()
 Full connection string as used to set up this connection.

int BackendPID () const
 Process ID for backend process.

void Activate () const
 Explicitly activate deferred or deactivated connection.

void Deactivate () const
 Explicitly deactivate connection.


Friends

class TransactionItf
class Trigger


Detailed Description

Connection class; represents a connection to a database.

This is the first class to look at when you wish to work with a database through libpqxx. It is automatically opened by its constructor, and automatically closed upon destruction, if it hasn't already been closed manually. To query or manipulate the database once connected, use one of the Transaction classes (see pqxx/transactionitf.h) or preferably the Transactor framework (see pqxx/transactor.h).


Constructor & Destructor Documentation

pqxx::Connection::Connection const PGSTD::string &    ConnInfo,
bool    Immediate = true
[explicit]
 

Constructor. Sets up connection based on PostgreSQL connection string.

Parameters:
ConnInfo a PostgreSQL connection string specifying any required parameters, such as server, port, database, and password.
Immediate if set, makes the connection immediately. This is the default. If not set, the creation of the underlying database connection is deferred until necessitated by actual use, and the Connection remains in a deactivated state. It will be activated transparently when calls to its member functions make it necessary to do so. This regime is referred to as a "lazy" connection.

pqxx::Connection::~Connection  
 

Destructor. Implicitly closes the connection.


Member Function Documentation

void pqxx::Connection::Activate   const
 

Explicitly activate deferred or deactivated connection.

Use of this method is entirely optional. Whenever a Connection is used while in a deferred or deactivated state, it will transparently try to bring itself into an actiaveted state. This function is best viewed as an explicit hint to the Connection that "if you're not in an active state, now would be a good time to get into one." Whether a Connection is currently in an active state or not makes no real difference to its functionality. There is also no particular need to match calls to Activate() with calls to Deactivate(). A good time to call Activate() might be just before you first open a transaction on a lazy connection.

int pqxx::Connection::BackendPID   const
 

Process ID for backend process.

Use with care: connections may be lost and automatically re-established without your knowledge, in which case this process ID may no longer be correct. You may, however, assume that this number remains constant and reliable within the span of a successful backend transaction. If the transaction fails, which may be due to a lost connection, then this number will have become invalid at some point within the transaction.

const char* pqxx::Connection::DbName   const throw ()
 

Name of database we're connected to, if any.

void pqxx::Connection::Deactivate   const
 

Explicitly deactivate connection.

Like its counterpart Activate(), this method is entirely optional. Calling this function really only makes sense if you won't be using this Connection for a while and want to reduce the number of open connections on the database server. There is no particular need to match or pair calls to Deactivate() with calls to Activate(), but calling Deactivate() during a transaction is an error.

void pqxx::Connection::Disconnect   const throw ()
 

Explicitly close connection.

void pqxx::Connection::GetNotifs  
 

Check for pending trigger notifications and take appropriate action.

const char* pqxx::Connection::HostName   const throw ()
 

Address of server (NULL for local connections).

bool pqxx::Connection::IsOpen   const
 

Is this connection open?

const char* pqxx::Connection::Options   const throw ()
 

Full connection string as used to set up this connection.

template<typename TRANSACTOR>
void pqxx::Connection::Perform const TRANSACTOR &    T,
int    Attempts = 3
 

Perform the transaction defined by a Transactor-based object.

Invoke a Transactor, making at most Attempts attempts to perform the encapsulated code on the database. If the code throws any exception other than broken_connection, it will be aborted right away. Take care: neither OnAbort() nor OnCommit() will be invoked on the original transactor you pass into the function. It only serves as a prototype for the transaction to be performed. In fact, this function may copy-construct any number of Transactors from the one you passed in, calling either OnCommit() or OnAbort() only on those that actually have their operator() invoked.

const char* pqxx::Connection::Port   const throw ()
 

Server port number we're connected to.

void pqxx::Connection::ProcessNotice PGSTD::string    msg throw ()
 

Invoke notice processor function. The message should end in newline.

void pqxx::Connection::ProcessNotice const    char[] throw ()
 

Invoke notice processor function. The message should end in newline.

pqxx::NoticeProcessor pqxx::Connection::SetNoticeProcessor NoticeProcessor   ,
void *    arg
 

Set callback method for postgresql status output.

return value is the previous handler. Passing a NULL callback pointer simply returns the existing callback. The callback must have C linkage.

void pqxx::Connection::Trace FILE *   
 

Enable tracing to a given output stream, or NULL to disable.

void pqxx::Connection::Untrace  
 

Disable tracing. OBSOLETE. Use Trace(0).

const char* pqxx::Connection::UserName   const throw ()
 

Database user ID we're connected under, if any.


Friends And Related Function Documentation

friend class TransactionItf [friend]
 

friend class Trigger [friend]
 


The documentation for this class was generated from the following files:
Generated on Tue Dec 3 01:37:35 2002 for libpqxx by doxygen1.3-rc1