Public Member Functions | Private Member Functions | Private Attributes

nitro::PGDatabase Class Reference

Class provides PostgreSQL routine. More...

#include <db/pg_database.h>

Inherits nitro::Database.

Collaboration diagram for nitro::PGDatabase:
Collaboration graph
[legend]

List of all members.

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

Detailed Description

Class provides PostgreSQL routine.

Author:
Dodonov A.A.

Definition at line 50 of file pg_database.h.


Constructor & Destructor Documentation

nitro::PGDatabase::PGDatabase ( void   ) 

Constructor.

Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

nitro::PGDatabase::PGDatabase ( const std::string &  theConnectionString  ) 

Constructor.

Parameters:
theConnectionString - Connection settings.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

nitro::PGDatabase::~PGDatabase (  )  [virtual]

Destructor.

Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

nitro::PGDatabase::PGDatabase ( const PGDatabase DBObject  )  [inline, private]

Private copy-constructor.

Parameters:
DBObject - database object.
Author:
Dodonov A.A.

Definition at line 282 of file pg_database.h.

{}


Member Function Documentation

void nitro::PGDatabase::ClearResult ( void   )  [virtual]

Function clears results.

Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::PGDatabase::Connect ( const std::string &  theConnectionString  )  [virtual]

Function provide database connection routine.

Parameters:
theConnectionString - Connection settings.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

void nitro::PGDatabase::Disconnect ( void   )  [virtual]

Function closes connection.

Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

std::size_t nitro::PGDatabase::FieldCount ( void   )  [virtual]

Function returns count of fields.

Returns:
Count of fields.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

const char * nitro::PGDatabase::GetFieldName ( std::size_t  j  )  [virtual]

Function returns name of the field.

Parameters:
j - number of the field.
Returns:
Name of the field.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

const char * nitro::PGDatabase::GetRecordField ( std::size_t  i,
std::size_t  j 
) [virtual]

Function returns value of the field.

Parameters:
i - number of the record.
j - number of the field.
Returns:
Count of fields.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

PGDatabase nitro::PGDatabase::operator= ( const PGDatabase DBObject  )  [inline, private]

Private assign operator.

Parameters:
DBObject - database object.
Author:
Dodonov A.A.

Definition at line 298 of file pg_database.h.

{return( *this );}

void nitro::PGDatabase::Query ( const std::string &  theQueryString  )  [virtual]

Executing query.

Parameters:
theQueryString - Query.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:

std::size_t nitro::PGDatabase::RecordCount ( void   )  [virtual]

Function returns count of selected records.

Returns:
Count of records.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

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 ) );
                }
        }

Here is the call graph for this function:


Member Data Documentation

Connection.

Author:
Dodonov A.A.

Definition at line 310 of file pg_database.h.

Referenced by Connect(), Disconnect(), and Query().

void* nitro::PGDatabase::Result [private]

Query result.

Author:
Dodonov A.A.

Definition at line 322 of file pg_database.h.

Referenced by ClearResult(), FieldCount(), GetFieldName(), GetRecordField(), Query(), and RecordCount().


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

Generated by  doxygen 1.6.1