Class provides PostgreSQL routine. More...
#include <db/pg_database.h>
Inherits nitro::Database.
Public Member Functions | |
PGDatabase (void) | |
PGDatabase (const std::string &theConnectionString) | |
void | Connect (const std::string &theConnectionString) |
void | Disconnect (void) |
void | Query (const std::string &theQueryString) |
virtual std::size_t | RecordCount (void) |
virtual std::size_t | FieldCount (void) |
virtual const char * | GetRecordField (std::size_t i, std::size_t j) |
virtual const char * | GetFieldName (std::size_t j) |
virtual void | ClearResult (void) |
virtual | ~PGDatabase () |
Private Member Functions | |
PGDatabase (const PGDatabase &DBObject) | |
PGDatabase | operator= (const PGDatabase &DBObject) |
Private Attributes | |
void * | Connection |
void * | Result |
Class provides PostgreSQL routine.
Definition at line 50 of file pg_database.h.
nitro::PGDatabase::PGDatabase | ( | void | ) |
Constructor.
nitro::exception | Throws exception with the description of error. |
Definition at line 13 of file pg_database.cpp.
References nitro::exception::code(), and nitro::exception::what().
{ try { } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::PGDatabase( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::PGDatabase( void )::An error occured" ) , 0 ) ); } }
nitro::PGDatabase::PGDatabase | ( | const std::string & | theConnectionString | ) |
Constructor.
theConnectionString | - Connection settings. |
nitro::exception | Throws exception with the description of error. |
Definition at line 28 of file pg_database.cpp.
References nitro::exception::code(), Connect(), and nitro::exception::what().
{ try { Connect( theConnectionString ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::PGDatabase( const std::string & theConnectionString )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::PGDatabase( const std::string & theConnectionString )::An error occured" ) , 0 ) ); } }
nitro::PGDatabase::~PGDatabase | ( | ) | [virtual] |
Destructor.
Definition at line 111 of file pg_database.cpp.
References Disconnect().
{ try { Disconnect(); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::~PGDatabase()::An error occured" ) , 0 ) ); } }
nitro::PGDatabase::PGDatabase | ( | const PGDatabase & | DBObject | ) | [inline, private] |
Private copy-constructor.
DBObject | - database object. |
Definition at line 282 of file pg_database.h.
{}
void nitro::PGDatabase::ClearResult | ( | void | ) | [virtual] |
Function clears results.
nitro::exception | Throws exception with the description of error. |
Implements nitro::Database.
Definition at line 187 of file pg_database.cpp.
References nitro::exception::code(), Result, and nitro::exception::what().
{ try { if( Result != NULL ) { PQclear( ( PGresult * )Result ); Result = NULL; } } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::ClearResult( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::ClearResult( void )::An error occured" ) , 0 ) ); } }
void nitro::PGDatabase::Connect | ( | const std::string & | theConnectionString | ) | [virtual] |
Function provide database connection routine.
theConnectionString | - Connection settings. |
nitro::exception | Throws exception with the description of error. |
Reimplemented from nitro::Database.
Definition at line 44 of file pg_database.cpp.
References nitro::exception::code(), Connection, nitro::Parsers::GetCommandLineParameter(), Query(), and nitro::exception::what().
Referenced by PGDatabase().
{ try { Connection = ( void * )PQconnectdb( theConnectionString.c_str() ); if( PQstatus( ( PGconn * )Connection ) != CONNECTION_OK ) { throw( nitro::exception( std::string( "An error occured while connecting to the server. Connection string : " ) + theConnectionString , 1 ) ); } std::string CharacterSet( nitro::Parsers::GetCommandLineParameter( theConnectionString , std::string( "character_set" ) , std::string( "" ) ) ); if( !CharacterSet.empty() ) { Query( std::string( "SET NAMES " ) + CharacterSet ); } } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::Connect( const std::string & theConnectionString )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::Connect( const std::string & theConnectionString )::An error occured" ) , 0 ) ); } }
void nitro::PGDatabase::Disconnect | ( | void | ) | [virtual] |
Function closes connection.
nitro::exception | Throws exception with the description of error. |
Implements nitro::Database.
Definition at line 95 of file pg_database.cpp.
References nitro::exception::code(), Connection, and nitro::exception::what().
Referenced by ~PGDatabase().
{ try { PQfinish( ( PGconn * )Connection ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::Disconnect( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::Disconnect( void )::An error occured" ) , 0 ) ); } }
std::size_t nitro::PGDatabase::FieldCount | ( | void | ) | [virtual] |
Function returns count of fields.
nitro::exception | Throws exception with the description of error. |
Implements nitro::Database.
Definition at line 139 of file pg_database.cpp.
References nitro::exception::code(), Result, and nitro::exception::what().
{ try { return( PQnfields( ( const PGresult * ) Result ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::FieldCount( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::FieldCount( void )::An error occured" ) , 0 ) ); } }
const char * nitro::PGDatabase::GetFieldName | ( | std::size_t | j | ) | [virtual] |
Function returns name of the field.
j | - number of the field. |
nitro::exception | Throws exception with the description of error. |
Implements nitro::Database.
Definition at line 171 of file pg_database.cpp.
References nitro::exception::code(), Result, and nitro::exception::what().
{ try { return( ( const char * )PQfname( ( const PGresult * ) Result , ( int )j ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::GetFieldName( std::size_t j )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::GetFieldName( std::size_t j )::An error occured" ) , 0 ) ); } }
const char * nitro::PGDatabase::GetRecordField | ( | std::size_t | i, | |
std::size_t | j | |||
) | [virtual] |
Function returns value of the field.
i | - number of the record. | |
j | - number of the field. |
nitro::exception | Throws exception with the description of error. |
Implements nitro::Database.
Definition at line 155 of file pg_database.cpp.
References nitro::exception::code(), Result, and nitro::exception::what().
{ try { return( ( const char * )PQgetvalue( ( const PGresult * ) Result , ( int )i , ( int )j ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::GetRecordField( std::size_t i , std::size_t j )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::GetRecordField( std::size_t i , std::size_t j )::An error occured" ) , 0 ) ); } }
PGDatabase nitro::PGDatabase::operator= | ( | const PGDatabase & | DBObject | ) | [inline, private] |
Private assign operator.
DBObject | - database object. |
Definition at line 298 of file pg_database.h.
{return( *this );}
void nitro::PGDatabase::Query | ( | const std::string & | theQueryString | ) | [virtual] |
Executing query.
theQueryString | - Query. |
nitro::exception | Throws exception with the description of error. |
Reimplemented from nitro::Database.
Definition at line 72 of file pg_database.cpp.
References nitro::exception::code(), Connection, Result, and nitro::exception::what().
Referenced by Connect().
{ try { Result = ( void * )PQexec( ( PGconn * )Connection , theQueryString.c_str() ); ExecStatusType Status( PQresultStatus( ( PGresult * )Result ) ); if( Status == PGRES_BAD_RESPONSE || Status == PGRES_NONFATAL_ERROR || Status == PGRES_FATAL_ERROR ) { throw( nitro::exception( std::string( "An error occured while executing query " ) + theQueryString , 1 ) ); } } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::Query( const std::string & theQueryString )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::Query( const std::string & theQueryString )::An error occured" ) , 0 ) ); } }
std::size_t nitro::PGDatabase::RecordCount | ( | void | ) | [virtual] |
Function returns count of selected records.
nitro::exception | Throws exception with the description of error. |
Implements nitro::Database.
Definition at line 123 of file pg_database.cpp.
References nitro::exception::code(), Result, and nitro::exception::what().
{ try { return( PQntuples( ( const PGresult * ) Result ) ); } catch( nitro::exception e ) { throw( nitro::exception( std::string( "PGDatabase::RecordCount( void )::" ) + e.what() , e.code() ) ); } catch( ... ) { throw( nitro::exception( std::string( "PGDatabase::RecordCount( void )::An error occured" ) , 0 ) ); } }
void* nitro::PGDatabase::Connection [private] |
Connection.
Definition at line 310 of file pg_database.h.
Referenced by Connect(), Disconnect(), and Query().
void* nitro::PGDatabase::Result [private] |
Query result.
Definition at line 322 of file pg_database.h.
Referenced by ClearResult(), FieldCount(), GetFieldName(), GetRecordField(), Query(), and RecordCount().