wxPg::Database Class Reference

Class for connecting to database and executing SQL statements. More...

Inherited by Database.

List of all members.

Classes

struct  client_

Public Member Functions

 Database ()
 Create new database object.
 Database (const wxString &coninfo)
 Creates new object and initializes it with specified connection info.
virtual ~Database ()
 Destroys object.
void connection_info (const wxString &coninfo)
 Sets connection info for this object.
const wxString & connection_info () const
 Return current connection info.
bool connect (bool connect=true)
 Connect to or disconnect from database.
bool connected () const
 Is this object connected to database.
PGconn * handle ()
 Return connection handle.
void attach (DB_client *cli, int level)
 Attach new client to this connection.
void detach (DB_client *cli, int level)
 Detach client.
void detach_all (int level)
 Detach all clients.
bool begin_transaction ()
 Begin new transaction.
bool enter_transaction ()
 Ensure, that database is in transaction.
bool commit ()
 Commit current transaction.
void rollback ()
 Rollbacks current transaction.
bool in_transaction ()
 Is database in transaction.
bool run (const wxString &sql)
 Run SQL statement.
bool run (Cached_result &result, const wxString &sql)
 Run SQL query.
const wxString & last_err () const
 Get last error.
virtual void sql_monitor (const wxString &sql)
 Monitor SQL for this database object.
const wxString char_to_str (const char *s) const
 Convert C-string to wxString.

Static Public Attributes

static const int ATTACH_CONNECTION = 10
 Attach DB_client to connection.
static const int ATTACH_TRANSACTION = 20
 Attach DB_client to transaction.

Friends

class wxPg::Query
class wxPg::Updatable_row


Detailed Description

Class for connecting to database and executing SQL statements.


Constructor & Destructor Documentation

wxPg::Database::Database (  ) 

Create new database object.

Call connection_info() to complete initialization.

wxPg::Database::Database ( const wxString &  coninfo  )  [explicit]

Creates new object and initializes it with specified connection info.

Parameters:
coninfo - see PQconnectdb() in PostgreSQL documentation for description.

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

Destroys object.


Member Function Documentation

void wxPg::Database::attach ( DB_client cli,
int  level 
)

Attach new client to this connection.

When database is disconnected or transaction is ended, detach() method is called for each client.

Parameters:
cli - a client to attach.
level - level of attach, use one of ATTACH_* constants.

bool wxPg::Database::begin_transaction (  ) 

Begin new transaction.

If a transaction is already started, rollbacks old and starts new. Call last_err() to get error message.

Returns:
true on success, and false on error.

const wxString wxPg::Database::char_to_str ( const char *  s  )  const

Convert C-string to wxString.

Used internally for converting data, received from database, to wxString.

Parameters:
s - zero terminated char array.
Returns:
s, converted to wxString.

bool wxPg::Database::commit (  ) 

Commit current transaction.

If return value is false, call last_err() to get error message.

Returns:
true on success and false on error or if not in transaction.

bool wxPg::Database::connect ( bool  connect = true  ) 

Connect to or disconnect from database.

Parameters:
connect - if is true, than connect, else - disconnect.
Returns:
true on success and false on error.

bool wxPg::Database::connected (  )  const

Is this object connected to database.

Returns:
true, if connected, else otherwise.

const wxString& wxPg::Database::connection_info (  )  const

Return current connection info.

See PQconnectdb() in PostgreSQL documentation for returned string description.

void wxPg::Database::connection_info ( const wxString &  coninfo  ) 

Sets connection info for this object.

Parameters:
coninfo - see PQconnectdb() in PostgreSQL documentation for description.

void wxPg::Database::detach ( DB_client cli,
int  level 
)

Detach client.

Note, that this method does not call detach() on a client.

Parameters:
cli - a client to detach.
level - level of detach, same as attach level for attach().

void wxPg::Database::detach_all ( int  level  ) 

Detach all clients.

Note, that this method does not call detach() on the clients.

Parameters:
level - level of detach, same as attach level for attach().

bool wxPg::Database::enter_transaction (  ) 

Ensure, that database is in transaction.

If database is not in transaction, starts new transaction, simply returns true otherwise.

Returns:
false on error, true if database is now in transaction.

PGconn* wxPg::Database::handle (  ) 

Return connection handle.

bool wxPg::Database::in_transaction (  ) 

Is database in transaction.

Returns:
true if transaction is started and false otherwise.

const wxString& wxPg::Database::last_err (  )  const

Get last error.

Returns:
message for last error.

void wxPg::Database::rollback (  ) 

Rollbacks current transaction.

Does nothing if not in transaction.

bool wxPg::Database::run ( Cached_result result,
const wxString &  sql 
)

Run SQL query.

If returns false, call last_err() to get error message.

Parameters:
result - Cached_result object, where result is stored.
sql - SQL statement to execute.
Returns:
true on success and false on failure.

bool wxPg::Database::run ( const wxString &  sql  ) 

Run SQL statement.

If returns false, call last_err() to get error message. Don't use it for SQL statements, that return data, as there is no way to get it.

Parameters:
sql - SQL statement to execute.
Returns:
true on success and false on failure.

virtual void wxPg::Database::sql_monitor ( const wxString &  sql  )  [virtual]

Monitor SQL for this database object.

This method does nothing. Override it in derived class to get ability to monitor any SQL statement, executed by this object.

Parameters:
sql - SQL statement, executed by this object.


Member Data Documentation

const int wxPg::Database::ATTACH_CONNECTION = 10 [static]

Attach DB_client to connection.

Client is detached when database is disconnected.

const int wxPg::Database::ATTACH_TRANSACTION = 20 [static]

Attach DB_client to transaction.

Client is detached when transaction is committed or rollbacked.


Generated on Sat Sep 5 23:00:41 2009 for wxPostgres by  doxygen 1.5.8