diff --git a/src/servers/Server_Common/Database/Connection.cpp b/src/servers/Server_Common/Database/Connection.cpp index c8a799df..32d15e6f 100644 --- a/src/servers/Server_Common/Database/Connection.cpp +++ b/src/servers/Server_Common/Database/Connection.cpp @@ -8,13 +8,14 @@ Core::Db::Connection::Connection( MySqlBase * pBase, const std::string& hostName, const std::string& userName, - const std::string& password ) : + const std::string& password, + uint16_t port ) : m_pBase( pBase ), m_bConnected( false ) { m_pRawCon = mysql_init( nullptr ); if( mysql_real_connect( m_pRawCon, hostName.c_str(), userName.c_str(), password.c_str(), - nullptr, 3306, nullptr, 0) == nullptr ) + nullptr, port, nullptr, 0) == nullptr ) throw std::runtime_error( mysql_error( m_pRawCon ) ); m_bConnected = true; @@ -24,7 +25,8 @@ Core::Db::Connection::Connection( MySqlBase * pBase, const std::string& hostName, const std::string& userName, const std::string& password, - const optionMap& options ) : + const optionMap& options, + uint16_t port ) : m_pBase( pBase ) { m_pRawCon = mysql_init( nullptr ); @@ -100,7 +102,7 @@ Core::Db::Connection::Connection( MySqlBase * pBase, if( mysql_real_connect( m_pRawCon, hostName.c_str(), userName.c_str(), password.c_str(), - nullptr, 3306, nullptr, 0) == nullptr ) + nullptr, port, nullptr, 0) == nullptr ) throw std::runtime_error( mysql_error( m_pRawCon ) ); } diff --git a/src/servers/Server_Common/Database/Connection.h b/src/servers/Server_Common/Database/Connection.h index 1e7abfb7..4f78476c 100644 --- a/src/servers/Server_Common/Database/Connection.h +++ b/src/servers/Server_Common/Database/Connection.h @@ -18,20 +18,19 @@ namespace Db class Connection { - //Statement * createServiceStmt(); - - public: - + public: Connection( MySqlBase * pBase, const std::string& hostName, const std::string& userName, - const std::string& password ); + const std::string& password, + uint16_t port = 3306); Connection( MySqlBase * pBase, const std::string& hostName, const std::string& userName, const std::string& password, - const optionMap& options ); + const optionMap& options, + uint16_t port = 3306 ); virtual ~Connection(); @@ -53,20 +52,14 @@ namespace Db Statement * createStatement(); - //// implemented up to this point - void beginTransaction(); void commitTransaction(); void rollbackTransaction(); - - std::string getSchema(); //DatabaseMetaData * getMetaData(); - //enum_transaction_isolation getTransactionIsolation(); - std::string getError(); bool isReadOnly(); @@ -90,11 +83,11 @@ namespace Db std::string getLastStatementInfo(); - MYSQL * getRawCon(); + MYSQL* getRawCon(); private: - MySqlBase * m_pBase; - MYSQL * m_pRawCon; + MySqlBase* m_pBase; + MYSQL* m_pRawCon; bool m_bConnected; Connection( const Connection& ); diff --git a/src/servers/Server_Common/Database/ResultSet.cpp b/src/servers/Server_Common/Database/ResultSet.cpp index 8d2c4b62..c09a6b26 100644 --- a/src/servers/Server_Common/Database/ResultSet.cpp +++ b/src/servers/Server_Common/Database/ResultSet.cpp @@ -5,6 +5,7 @@ #include #include #include +#include Core::Db::ResultSet::ResultSet( MYSQL_RES *res, Core::Db::Statement *par ) { @@ -272,3 +273,25 @@ std::istream* Core::Db::ResultSet::getBlob( const std::string& columnLabel ) con return new std::istringstream( getString( columnLabel ) ); } +std::vector< char > Core::Db::ResultSet::getBlobVector( uint32_t columnIndex ) const +{ + if( columnIndex == 0 || columnIndex > m_numFields ) + throw std::runtime_error( "ResultSet::getBlobVector: invalid value of 'columnIndex'" ); + + boost::scoped_ptr< std::istream > inStr( getBlob( columnIndex ) ); + char buff[4196]; + std::string s; + std::vector< char > data; + inStr->read( buff, sizeof( buff ) ); + if( inStr->gcount() ) + { + data.resize( inStr->gcount() ); + memcpy( data.data(), buff, inStr->gcount() ); + } + return data; +} + +std::vector< char > Core::Db::ResultSet::getBlobVector( const std::string& columnLabel ) const +{ + return getBlobVector( findColumn( columnLabel ) ); +} \ No newline at end of file diff --git a/src/servers/Server_Common/Database/ResultSet.h b/src/servers/Server_Common/Database/ResultSet.h index f4cd339f..d167d976 100644 --- a/src/servers/Server_Common/Database/ResultSet.h +++ b/src/servers/Server_Common/Database/ResultSet.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "ResultSetBase.h" #include @@ -52,6 +53,9 @@ namespace Core std::istream * getBlob( uint32_t columnIndex ) const; std::istream * getBlob( const std::string& columnLabel ) const; + std::vector< char > getBlobVector( uint32_t columnIndex ) const; + std::vector< char > getBlobVector( const std::string& columnLabel ) const; + bool getBoolean( uint32_t columnIndex ) const; bool getBoolean( const std::string& columnLabel ) const; diff --git a/src/servers/Server_Zone/ServerZone.cpp b/src/servers/Server_Zone/ServerZone.cpp index 132c142c..978fe4a6 100644 --- a/src/servers/Server_Zone/ServerZone.cpp +++ b/src/servers/Server_Zone/ServerZone.cpp @@ -213,6 +213,15 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] ) } + boost::scoped_ptr< Core::Db::Statement > stmt3( con->createStatement() ); + boost::scoped_ptr< Core::Db::ResultSet > res1( stmt3->executeQuery( "SELECT * FROM charabase" ) ); + + while( res1->next() ) + { + auto blob = res1->getBlobVector( "Customize" ); + } + + } catch( std::runtime_error e ) {