#include <db/database.h>
Производные классы:nitro::MySQLDatabase и nitro::PGDatabase.
Открытые члены | |
| 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 () |
См. определение в файле database.h строка 47
| nitro::Database::~Database | ( | ) | [virtual] |
| virtual void nitro::Database::ClearResult | ( | void | ) | [pure virtual] |
Функция очистки результата.
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещается в nitro::MySQLDatabase и nitro::PGDatabase.
Используется в FetchAssociativeArrays(), FetchCommonArrays() и Select().
| void nitro::Database::Connect | ( | const std::string & | theConnectionString | ) | [virtual] |
Подключение к базе данных.
| theConnectionString | - Параметры подключения. |
| nitro::exception | Кидает исключение с описанием ошибки. |
Переопределяется в nitro::MySQLDatabase и nitro::PGDatabase.
См. определение в файле database.cpp строка 8
Перекрестные ссылки nitro::exception::code() и 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 ) );
}
}

| void nitro::Database::Delete | ( | const std::string & | Table, | |
| const std::string & | Condition = "1 = 1" | |||
| ) | [virtual] |
Функция удаления записи.
| Table | - Таблица, в которой осуществляем удаление. | |
| Condition | - Условие отбора записей. |
| nitro::exception | Кидает исключение с описанием ошибки. |
См. определение в файле database.cpp строка 74
Перекрестные ссылки nitro::exception::code(), Query() и 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 ) );
}
}

| virtual void nitro::Database::Disconnect | ( | void | ) | [pure virtual] |
Отключение от базы данных.
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещается в nitro::MySQLDatabase и nitro::PGDatabase.
| void nitro::Database::FetchAssociativeArrays | ( | iter & | InsertIterator | ) |
Функция выборки данных в виде ассоциативных массивов.
| InsertIterator | - Итератор вставки. |
| nitro::exception | Кидает исключение с описанием ошибки. |
См. определение в файле database.h строка 414
Перекрестные ссылки ClearResult(), nitro::exception::code(), FieldCount(), GetFieldName(), GetRecordField(), RecordCount() и 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 ) );
}
}

| void nitro::Database::FetchCommonArrays | ( | iter & | InsertIterator | ) |
Функция выборки данных в виде массивов.
| InsertIterator | - Итератор вставки. |
| nitro::exception | Кидает исключение с описанием ошибки. |
См. определение в файле database.h строка 381
Перекрестные ссылки ClearResult(), nitro::exception::code(), FieldCount(), GetRecordField(), RecordCount() и 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 ) );
}
}

| virtual std::size_t nitro::Database::FieldCount | ( | void | ) | [pure virtual] |
Функция получения количества полей.
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещается в nitro::MySQLDatabase и nitro::PGDatabase.
Используется в FetchAssociativeArrays() и FetchCommonArrays().
| virtual const char* nitro::Database::GetFieldName | ( | std::size_t | j | ) | [pure virtual] |
Функция получения названия поля.
| j | - номер поля. |
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещается в nitro::MySQLDatabase и nitro::PGDatabase.
Используется в FetchAssociativeArrays().
| virtual const char* nitro::Database::GetRecordField | ( | std::size_t | i, | |
| std::size_t | j | |||
| ) | [pure virtual] |
Функция получения значения поля.
| i | - номер записи. | |
| j | - номер поля. |
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещается в nitro::MySQLDatabase и nitro::PGDatabase.
Используется в FetchAssociativeArrays() и FetchCommonArrays().
| void nitro::Database::Insert | ( | const std::string & | Table, | |
| const std::string & | Fields, | |||
| const std::string & | Values | |||
| ) | [virtual] |
Функция вставки записи.
| Table | - Таблица, в которую осуществляем вставку. | |
| Fields | - Список полей в записи. | |
| Values | - Вставляемые значения. |
| nitro::exception | Кидает исключение с описанием ошибки. |
См. определение в файле database.cpp строка 58
Перекрестные ссылки nitro::exception::code(), Query() и 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 ) );
}
}

| void nitro::Database::Query | ( | const std::string & | theQueryString | ) | [virtual] |
Выполнение запроса.
| theQueryString | - Запрос. |
| nitro::exception | Кидает исключение с описанием ошибки. |
Переопределяется в nitro::MySQLDatabase и nitro::PGDatabase.
См. определение в файле database.cpp строка 24
Перекрестные ссылки nitro::exception::code() и nitro::exception::what().
Используется в Delete(), Insert(), Select() и 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 ) );
}
}

| virtual std::size_t nitro::Database::RecordCount | ( | void | ) | [pure virtual] |
Функция получения количества записей.
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещается в nitro::MySQLDatabase и nitro::PGDatabase.
Используется в FetchAssociativeArrays() и FetchCommonArrays().
| void nitro::Database::Select | ( | const std::string & | What, | |
| const std::string & | Tables, | |||
| const std::string & | Condition = "1 = 1" | |||
| ) |
Функция выполнения select запроса.
| What | - Список полей в выбираемых записях. | |
| Tables | - Список таблиц. | |
| Condition | - Условие отбора записей. |
| nitro::exception | Кидает исключение с описанием ошибки. |
См. определение в файле database.cpp строка 40
Перекрестные ссылки ClearResult(), nitro::exception::code(), Query() и 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 ) );
}
}

| void nitro::Database::Update | ( | const std::string & | Table, | |
| const cont1 & | Fields, | |||
| const cont2 & | Values, | |||
| const std::string & | Condition = "1 = 1" | |||
| ) |
Функция обновления записи.
| Table | - Обновляемая таблица. | |
| Fields | - Список полей. | |
| Values | - Изменяемые значения. | |
| Condition | - Условие отбора записей. |
| nitro::exception | Кидает исключение с описанием ошибки. |
См. определение в файле database.h строка 447
Перекрестные ссылки nitro::exception::code(), Query() и 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 ) );
}
}

1.6.1