Public Member Functions

nitro::Database Class Reference

#include <db/database.h>

Inherited by nitro::MySQLDatabase, and nitro::PGDatabase.

List of all members.

Public Member Functions

virtual void Connect (const std::string &theConnectionString)
virtual void Disconnect (void)=0
virtual void Query (const std::string &theQueryString)
void Select (const std::string &What, const std::string &Tables, const std::string &Condition="1 = 1")
template<class iter >
void FetchCommonArrays (iter &InsertIterator)
template<class iter >
void FetchAssociativeArrays (iter &InsertIterator)
virtual void Insert (const std::string &Table, const std::string &Fields, const std::string &Values)
template<class cont1 , class cont2 >
void Update (const std::string &Table, const cont1 &Fields, const cont2 &Values, const std::string &Condition="1 = 1")
virtual void Delete (const std::string &Table, const std::string &Condition="1 = 1")
virtual std::size_t RecordCount (void)=0
virtual std::size_t FieldCount (void)=0
virtual const char * GetRecordField (std::size_t i, std::size_t j)=0
virtual const char * GetFieldName (std::size_t j)=0
virtual void ClearResult (void)=0
virtual ~Database ()

Detailed Description

Definition at line 47 of file database.h.


Constructor & Destructor Documentation

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

Destructor.

Author:
Dodonov A.A.

Definition at line 90 of file database.cpp.

        {
                try
                {
                }
                catch( ... )
                {
                }
        }


Member Function Documentation

virtual void nitro::Database::ClearResult ( void   )  [pure virtual]

Function clears results.

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

Implemented in nitro::MySQLDatabase, and nitro::PGDatabase.

Referenced by FetchAssociativeArrays(), FetchCommonArrays(), and Select().

void nitro::Database::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 in nitro::MySQLDatabase, and nitro::PGDatabase.

Definition at line 8 of file database.cpp.

References nitro::exception::code(), and nitro::exception::what().

        {
                try
                {
                        Connect( theConnectionString.c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Database::Connect( const std::string & theConnectionString )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Database::Connect( const std::string & theConnectionString )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::Database::Delete ( const std::string &  Table,
const std::string &  Condition = "1 = 1" 
) [virtual]

Function deletes record.

Parameters:
Table - Table to delete from.
Condition - Records selection condition.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

Definition at line 74 of file database.cpp.

References nitro::exception::code(), Query(), and nitro::exception::what().

        {
                try
                {
                        Query( ( std::string( "DELETE FROM " ) + Table + " WHERE " + Condition ).c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Database::Delete( const std::string & Table , const std::string & Condition )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Database::Delete( const std::string & Table , const std::string & Condition )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

virtual void nitro::Database::Disconnect ( void   )  [pure virtual]

Function closes connection.

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

Implemented in nitro::MySQLDatabase, and nitro::PGDatabase.

template<class iter >
void nitro::Database::FetchAssociativeArrays ( iter &  InsertIterator  ) 

Function returns data as associative arrays.

Parameters:
InsertIterator - Insert iterator.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

Definition at line 414 of file database.h.

References ClearResult(), nitro::exception::code(), FieldCount(), GetFieldName(), GetRecordField(), RecordCount(), and nitro::exception::what().

        {
                try
                {
                        std::size_t                                             RecCount( RecordCount() );
                        std::size_t                                             FldCount( FieldCount() );

                        typedef typename iter::container_type::value_type       RecordType;
                        
                        for( std::size_t i( 0 ) ; i < RecCount ; i++ )
                        {
                                RecordType                                      Record;

                                for( std::size_t j( 0 ) ; j < FldCount ; j++ )
                                {
                                        Record.insert( std::pair< std::string , std::string >( std::string( GetFieldName( j ) ) , std::string( GetRecordField( i , j ) ) ) );
                                }

                                ( * InsertIterator ) = Record;
                        }

                        ClearResult();
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Database::FetchAssociativeArrays( iter & InsertIterator )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Database::FetchAssociativeArrays( iter & InsertIterator )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

template<class iter >
void nitro::Database::FetchCommonArrays ( iter &  InsertIterator  ) 

Function returns data as common arrays.

Parameters:
InsertIterator - Insert iterator.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

Definition at line 381 of file database.h.

References ClearResult(), nitro::exception::code(), FieldCount(), GetRecordField(), RecordCount(), and nitro::exception::what().

        {
                try
                {
                        std::size_t                                             RecCount( RecordCount() );
                        std::size_t                                             FldCount( FieldCount() );

                        typedef typename iter::container_type::value_type       RecordType;
                        
                        for( std::size_t i( 0 ) ; i < RecCount ; i++ )
                        {
                                RecordType                                      Record;

                                for( std::size_t j( 0 ) ; j < FldCount ; j++ )
                                {
                                        Record.push_back( std::string( GetRecordField( i , j ) ) );
                                }

                                ( * InsertIterator ) = Record;
                        }

                        ClearResult();
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Database::FetchCommonArrays( iter & InsertIterator )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Database::FetchCommonArrays( iter & InsertIterator )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

virtual std::size_t nitro::Database::FieldCount ( void   )  [pure virtual]

Function returns count of fields.

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

Implemented in nitro::MySQLDatabase, and nitro::PGDatabase.

Referenced by FetchAssociativeArrays(), and FetchCommonArrays().

virtual const char* nitro::Database::GetFieldName ( std::size_t  j  )  [pure 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.

Implemented in nitro::MySQLDatabase, and nitro::PGDatabase.

Referenced by FetchAssociativeArrays().

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

Function returns value of the field.

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

Implemented in nitro::MySQLDatabase, and nitro::PGDatabase.

Referenced by FetchAssociativeArrays(), and FetchCommonArrays().

void nitro::Database::Insert ( const std::string &  Table,
const std::string &  Fields,
const std::string &  Values 
) [virtual]

Function inserts record.

Parameters:
Table - Table to insert in.
Fields - List of fields.
Values - Inserting values.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

Definition at line 58 of file database.cpp.

References nitro::exception::code(), Query(), and nitro::exception::what().

        {
                try
                {
                        Query( ( std::string( "INSERT INTO " ) + Table + " ( " + Fields + " ) VALUES ( " + Values + " )" ).c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Database::Insert( const std::string & Table , const std::string & Fields , const std::string & Values )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Database::Insert( const std::string & Table , const std::string & Fields , const std::string & Values )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

void nitro::Database::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 in nitro::MySQLDatabase, and nitro::PGDatabase.

Definition at line 24 of file database.cpp.

References nitro::exception::code(), and nitro::exception::what().

Referenced by Delete(), Insert(), Select(), and Update().

        {
                try
                {
                        Query( theQueryString.c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Database::Query( const std::string & theQueryString )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Database::Query( const std::string & theQueryString )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

virtual std::size_t nitro::Database::RecordCount ( void   )  [pure 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.

Implemented in nitro::MySQLDatabase, and nitro::PGDatabase.

Referenced by FetchAssociativeArrays(), and FetchCommonArrays().

void nitro::Database::Select ( const std::string &  What,
const std::string &  Tables,
const std::string &  Condition = "1 = 1" 
)

Function executes "select" query.

Parameters:
What - List of fields.
Tables - List of tables.
Condition - Query selecting condition.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

Definition at line 40 of file database.cpp.

References ClearResult(), nitro::exception::code(), Query(), and nitro::exception::what().

        {
                try
                {
                        ClearResult();

                        Query( ( std::string( "SELECT " ) + What + " FROM " + Tables + " WHERE " + Condition ).c_str() );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Database::Select( const std::string & What , const std::string & Tables , const std::string & Condition /* = 1 = 1 */ )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Database::Select( const std::string & What , const std::string & Tables , const std::string & Condition /* = 1 = 1 */ )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:

template<class cont1 , class cont2 >
void nitro::Database::Update ( const std::string &  Table,
const cont1 &  Fields,
const cont2 &  Values,
const std::string &  Condition = "1 = 1" 
)

Function updates record.

Parameters:
Table - Table to update.
Fields - List of fields.
Values - Changing values.
Condition - Query selecting condition.
Exceptions:
nitro::exception Throws exception with the description of error.
Author:
Dodonov A.A.

Definition at line 447 of file database.h.

References nitro::exception::code(), Query(), and nitro::exception::what().

        {
                try
                {
                        std::string                                             UpdateString( "" );

                        typename cont1::const_iterator  i( Fields.begin() );
                        typename cont2::const_iterator  j( Values.begin() );

                        for( ; i != Fields.end() && j != Values.end() ; i++ , j++ )
                        {
                                if( i + 1 != Fields.end() && j + 1 != Values.end() )
                                {
                                        UpdateString += *i + " = '" + *j + "' , ";
                                }
                                else
                                {
                                        UpdateString += *i + " = '" + *j + "'";
                                }
                        }

                        Query( std::string( "UPDATE " ) + Table + " SET " + UpdateString + " WHERE " + Condition );
                }
                catch( nitro::exception e )
                {
                        throw( nitro::exception( std::string( "Database::Update( const std::string & Table , const cont1 & Fields , const cont2 & Values , const std::string & Condition /* = 1 = 1 */ )::" ) + e.what() , e.code() ) );
                }
                catch( ... )
                {
                        throw( nitro::exception( std::string( "Database::Update( const std::string & Table , const cont1 & Fields , const cont2 & Values , const std::string & Condition /* = 1 = 1 */ )::An error occured" ) , 0 ) );
                }
        }

Here is the call graph for this function:


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

Generated by  doxygen 1.6.1