Класс для работы с MySQL. Подробнее...
#include <db/mysql_database.h>
Базовые классы:nitro::Database.
Открытые члены | |
| MySQLDatabase (void) | |
| MySQLDatabase (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 | ~MySQLDatabase () |
Закрытые члены | |
| MySQLDatabase (const MySQLDatabase &DBObject) | |
| MySQLDatabase | operator= (const MySQLDatabase &DBObject) |
Закрытые данные | |
| void * | Connection |
| void * | Result |
| void * | Row |
| std::size_t | RowId |
Класс для работы с MySQL.
См. определение в файле mysql_database.h строка 50
| nitro::MySQLDatabase::MySQLDatabase | ( | void | ) |
Конструктор.
| nitro::exception | Кидает исключение с описанием ошибки. |
См. определение в файле mysql_database.cpp строка 19
Перекрестные ссылки nitro::exception::code(), Connection, Result, Row, RowId и nitro::exception::what().
{
try
{
Connection = NULL;
Result = NULL;
Row = NULL;
RowId = std::numeric_limits< std::size_t >::max();
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::MySQLDatabase( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::MySQLDatabase( void )::An error occured" ) , 0 ) );
}
}

| nitro::MySQLDatabase::MySQLDatabase | ( | const std::string & | theConnectionString | ) |
Конструктор.
| theConnectionString | - Параметры подключения. |
| nitro::exception | Кидает исключение с описанием ошибки. |
См. определение в файле mysql_database.cpp строка 38
Перекрестные ссылки nitro::exception::code(), Connect(), Connection, Result, Row, RowId и nitro::exception::what().
{
try
{
Connection = NULL;
Result = NULL;
Row = NULL;
RowId = std::numeric_limits< std::size_t >::max();
Connect( theConnectionString );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::MySQLDatabase( const std::string & theConnectionString )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::MySQLDatabase( const std::string & theConnectionString )::An error occured" ) , 0 ) );
}
}

| nitro::MySQLDatabase::~MySQLDatabase | ( | ) | [virtual] |
Деструктор.
См. определение в файле mysql_database.cpp строка 147
Перекрестные ссылки Disconnect().
{
try
{
Disconnect();
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::~MySQLDatabase()::An error occured" ) , 0 ) );
}
}

| nitro::MySQLDatabase::MySQLDatabase | ( | const MySQLDatabase & | DBObject | ) | [inline, private] |
Закрытый конструктор копирования.
| DBObject | - объект базы данных. |
См. определение в файле mysql_database.h строка 282
{}
| void nitro::MySQLDatabase::ClearResult | ( | void | ) | [virtual] |
Функция очистки результата.
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещает nitro::Database.
См. определение в файле mysql_database.cpp строка 243
Перекрестные ссылки nitro::exception::code(), Result и nitro::exception::what().
Используется в Disconnect() и Query().
{
try
{
mysql_free_result( ( MYSQL_RES * ) Result );
Result = NULL;
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::ClearResult( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::ClearResult( void )::An error occured" ) , 0 ) );
}
}

| void nitro::MySQLDatabase::Connect | ( | const std::string & | theConnectionString | ) | [virtual] |
Подключение к базе данных.
| theConnectionString | - Параметры подключения. |
| nitro::exception | Кидает исключение с описанием ошибки. |
Переопределяет метод предка nitro::Database.
См. определение в файле mysql_database.cpp строка 59
Перекрестные ссылки nitro::Converters::atoi(), nitro::exception::code(), Connection, Disconnect(), nitro::Parsers::GetCommandLineParameter(), Query() и nitro::exception::what().
Используется в MySQLDatabase().
{
try
{
if( Connection != NULL )
{
Disconnect();
}
Connection = ( void * )mysql_init( NULL );
std::string Host( nitro::Parsers::GetCommandLineParameter( theConnectionString , std::string( "host" ) , std::string( "localhost" ) ) );
std::string Port( nitro::Parsers::GetCommandLineParameter( theConnectionString , std::string( "port" ) , std::string( "3306" ) ) );
std::string User( nitro::Parsers::GetCommandLineParameter( theConnectionString , std::string( "user" ) , std::string( "root" ) ) );
std::string Password( nitro::Parsers::GetCommandLineParameter( theConnectionString , std::string( "password" ) , std::string( "" ) ) );
std::string DatabaseName( nitro::Parsers::GetCommandLineParameter( theConnectionString , std::string( "dbname" ) , std::string( "mysql" ) ) );
std::string CharacterSet( nitro::Parsers::GetCommandLineParameter( theConnectionString , std::string( "character_set" ) , std::string( "" ) ) );
if( !mysql_real_connect( ( MYSQL * ) Connection , Host.c_str() , User.c_str() , Password.c_str() , DatabaseName.c_str() , nitro::Converters::atoi( Port ) , NULL , 0 ) )
{
throw( nitro::exception( std::string( "An error occured while connecting to the server. Connection string : " ) + theConnectionString , 1 ) );
}
if( !CharacterSet.empty() )
{
Query( std::string( "SET NAMES " ) + CharacterSet );
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::Connect( const std::string & theConnectionString )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::Connect( const std::string & theConnectionString )::An error occured" ) , 0 ) );
}
}

| void nitro::MySQLDatabase::Disconnect | ( | void | ) | [virtual] |
Отключение от базы данных.
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещает nitro::Database.
См. определение в файле mysql_database.cpp строка 127
Перекрестные ссылки ClearResult(), nitro::exception::code(), Connection, Row и nitro::exception::what().
Используется в Connect() и ~MySQLDatabase().
{
try
{
delete ( MYSQL_ROW * )Row;
ClearResult();
mysql_close( ( MYSQL * ) Connection );
Connection = NULL;
mysql_library_end();
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::Disconnect( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::Disconnect( void )::An error occured" ) , 0 ) );
}
}

| std::size_t nitro::MySQLDatabase::FieldCount | ( | void | ) | [virtual] |
Функция получения количества полей.
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещает nitro::Database.
См. определение в файле mysql_database.cpp строка 180
Перекрестные ссылки nitro::exception::code(), Connection, Result и nitro::exception::what().
{
try
{
if( Result == NULL )
{
return( 0 );
}
return( mysql_field_count( ( MYSQL * ) Connection ) );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::FieldCount( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::FieldCount( void )::An error occured" ) , 0 ) );
}
}

| const char * nitro::MySQLDatabase::GetFieldName | ( | std::size_t | j | ) | [virtual] |
Функция получения названия поля.
| j | - номер поля. |
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещает nitro::Database.
См. определение в файле mysql_database.cpp строка 223
Перекрестные ссылки nitro::exception::code(), Result и nitro::exception::what().
{
try
{
mysql_field_seek( ( MYSQL_RES * ) Result , ( MYSQL_FIELD_OFFSET )j );
MYSQL_FIELD * Field;
Field = mysql_fetch_field( ( MYSQL_RES * ) Result );
return( Field->name );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::GetFieldName( std::size_t j )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::GetFieldName( std::size_t j )::An error occured" ) , 0 ) );
}
}

| const char * nitro::MySQLDatabase::GetRecordField | ( | std::size_t | i, | |
| std::size_t | j | |||
| ) | [virtual] |
Функция получения значения поля.
| i | - номер записи. | |
| j | - номер поля. |
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещает nitro::Database.
См. определение в файле mysql_database.cpp строка 201
Перекрестные ссылки nitro::exception::code(), Result, Row, RowId и nitro::exception::what().
{
try
{
if( RowId == std::numeric_limits< std::size_t >::max() || RowId != i )
{
mysql_data_seek( ( MYSQL_RES * ) Result , i );
*( ( MYSQL_ROW * )this->Row ) = mysql_fetch_row( ( MYSQL_RES * ) Result );
RowId = i;
}
return( ( * ( ( MYSQL_ROW * )this->Row ) )[ j ] ? ( * ( ( MYSQL_ROW * )this->Row ) )[ j ] : "" );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::GetRecordField( std::size_t i , std::size_t j )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::GetRecordField( std::size_t i , std::size_t j )::An error occured" ) , 0 ) );
}
}

| MySQLDatabase nitro::MySQLDatabase::operator= | ( | const MySQLDatabase & | DBObject | ) | [inline, private] |
Закрытый оператор присваивания.
| DBObject | - объект базы данных. |
См. определение в файле mysql_database.h строка 298
{return( *this );}
| void nitro::MySQLDatabase::Query | ( | const std::string & | theQueryString | ) | [virtual] |
Выполнение запроса.
| theQueryString | - Запрос. |
| nitro::exception | Кидает исключение с описанием ошибки. |
Переопределяет метод предка nitro::Database.
См. определение в файле mysql_database.cpp строка 97
Перекрестные ссылки ClearResult(), nitro::exception::code(), Connection, Result, Row, RowId и nitro::exception::what().
Используется в Connect().
{
try
{
ClearResult();
if( Row == NULL )
{
Row = ( void * ) new MYSQL_ROW;
}
RowId = std::numeric_limits< std::size_t >::max();
if( mysql_query( ( MYSQL * ) Connection , theQueryString.c_str() ) )
{
throw( nitro::exception( std::string( "An error occured while query execution. Query string : " ) + theQueryString + " Error message : " + mysql_error( ( MYSQL * )Connection ) , 1 ) );
}
Result = ( void * )mysql_store_result( ( MYSQL * ) Connection );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::Query( const std::string & theQueryString )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::Query( const std::string & theQueryString )::An error occured" ) , 0 ) );
}
}

| std::size_t nitro::MySQLDatabase::RecordCount | ( | void | ) | [virtual] |
Функция получения количества записей.
| nitro::exception | Кидает исключение с описанием ошибки. |
Замещает nitro::Database.
См. определение в файле mysql_database.cpp строка 159
Перекрестные ссылки nitro::exception::code(), Result и nitro::exception::what().
{
try
{
if( Result == NULL )
{
return( 0 );
}
return( ( std::size_t )mysql_num_rows( ( MYSQL_RES * ) Result ) );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "MySQLDatabase::RecordCount( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "MySQLDatabase::RecordCount( void )::An error occured" ) , 0 ) );
}
}

void* nitro::MySQLDatabase::Connection [private] |
Соединение.
См. определение в файле mysql_database.h строка 310
Используется в Connect(), Disconnect(), FieldCount(), MySQLDatabase() и Query().
void* nitro::MySQLDatabase::Result [private] |
Результат запроса.
См. определение в файле mysql_database.h строка 322
Используется в ClearResult(), FieldCount(), GetFieldName(), GetRecordField(), MySQLDatabase(), Query() и RecordCount().
void* nitro::MySQLDatabase::Row [private] |
Запись из выборки.
См. определение в файле mysql_database.h строка 334
Используется в Disconnect(), GetRecordField(), MySQLDatabase() и Query().
std::size_t nitro::MySQLDatabase::RowId [private] |
Номер записи.
См. определение в файле mysql_database.h строка 346
Используется в GetRecordField(), MySQLDatabase() и Query().
1.6.1