mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-29 07:37:45 +00:00
Blob fields can now be returned as vector.
This commit is contained in:
parent
6f62b2f13b
commit
271c857d40
5 changed files with 50 additions and 19 deletions
|
@ -8,13 +8,14 @@
|
||||||
Core::Db::Connection::Connection( MySqlBase * pBase,
|
Core::Db::Connection::Connection( MySqlBase * pBase,
|
||||||
const std::string& hostName,
|
const std::string& hostName,
|
||||||
const std::string& userName,
|
const std::string& userName,
|
||||||
const std::string& password ) :
|
const std::string& password,
|
||||||
|
uint16_t port ) :
|
||||||
m_pBase( pBase ),
|
m_pBase( pBase ),
|
||||||
m_bConnected( false )
|
m_bConnected( false )
|
||||||
{
|
{
|
||||||
m_pRawCon = mysql_init( nullptr );
|
m_pRawCon = mysql_init( nullptr );
|
||||||
if( mysql_real_connect( m_pRawCon, hostName.c_str(), userName.c_str(), password.c_str(),
|
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 ) );
|
throw std::runtime_error( mysql_error( m_pRawCon ) );
|
||||||
m_bConnected = true;
|
m_bConnected = true;
|
||||||
|
|
||||||
|
@ -24,7 +25,8 @@ Core::Db::Connection::Connection( MySqlBase * pBase,
|
||||||
const std::string& hostName,
|
const std::string& hostName,
|
||||||
const std::string& userName,
|
const std::string& userName,
|
||||||
const std::string& password,
|
const std::string& password,
|
||||||
const optionMap& options ) :
|
const optionMap& options,
|
||||||
|
uint16_t port ) :
|
||||||
m_pBase( pBase )
|
m_pBase( pBase )
|
||||||
{
|
{
|
||||||
m_pRawCon = mysql_init( nullptr );
|
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(),
|
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 ) );
|
throw std::runtime_error( mysql_error( m_pRawCon ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,20 +18,19 @@ namespace Db
|
||||||
|
|
||||||
class Connection
|
class Connection
|
||||||
{
|
{
|
||||||
//Statement * createServiceStmt();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Connection( MySqlBase * pBase,
|
Connection( MySqlBase * pBase,
|
||||||
const std::string& hostName,
|
const std::string& hostName,
|
||||||
const std::string& userName,
|
const std::string& userName,
|
||||||
const std::string& password );
|
const std::string& password,
|
||||||
|
uint16_t port = 3306);
|
||||||
|
|
||||||
Connection( MySqlBase * pBase,
|
Connection( MySqlBase * pBase,
|
||||||
const std::string& hostName,
|
const std::string& hostName,
|
||||||
const std::string& userName,
|
const std::string& userName,
|
||||||
const std::string& password,
|
const std::string& password,
|
||||||
const optionMap& options );
|
const optionMap& options,
|
||||||
|
uint16_t port = 3306 );
|
||||||
|
|
||||||
virtual ~Connection();
|
virtual ~Connection();
|
||||||
|
|
||||||
|
@ -53,20 +52,14 @@ namespace Db
|
||||||
|
|
||||||
Statement * createStatement();
|
Statement * createStatement();
|
||||||
|
|
||||||
//// implemented up to this point
|
|
||||||
|
|
||||||
void beginTransaction();
|
void beginTransaction();
|
||||||
void commitTransaction();
|
void commitTransaction();
|
||||||
void rollbackTransaction();
|
void rollbackTransaction();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string getSchema();
|
std::string getSchema();
|
||||||
|
|
||||||
//DatabaseMetaData * getMetaData();
|
//DatabaseMetaData * getMetaData();
|
||||||
|
|
||||||
//enum_transaction_isolation getTransactionIsolation();
|
|
||||||
|
|
||||||
std::string getError();
|
std::string getError();
|
||||||
|
|
||||||
bool isReadOnly();
|
bool isReadOnly();
|
||||||
|
@ -90,11 +83,11 @@ namespace Db
|
||||||
|
|
||||||
std::string getLastStatementInfo();
|
std::string getLastStatementInfo();
|
||||||
|
|
||||||
MYSQL * getRawCon();
|
MYSQL* getRawCon();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MySqlBase * m_pBase;
|
MySqlBase* m_pBase;
|
||||||
MYSQL * m_pRawCon;
|
MYSQL* m_pRawCon;
|
||||||
bool m_bConnected;
|
bool m_bConnected;
|
||||||
|
|
||||||
Connection( const Connection& );
|
Connection( const Connection& );
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <clocale>
|
#include <clocale>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <boost/scoped_ptr.hpp>
|
||||||
|
|
||||||
Core::Db::ResultSet::ResultSet( MYSQL_RES *res, Core::Db::Statement *par )
|
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 ) );
|
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 ) );
|
||||||
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/scoped_ptr.hpp>
|
#include <boost/scoped_ptr.hpp>
|
||||||
#include <boost/weak_ptr.hpp>
|
#include <boost/weak_ptr.hpp>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "ResultSetBase.h"
|
#include "ResultSetBase.h"
|
||||||
#include <mysql.h>
|
#include <mysql.h>
|
||||||
|
@ -52,6 +53,9 @@ namespace Core
|
||||||
std::istream * getBlob( uint32_t columnIndex ) const;
|
std::istream * getBlob( uint32_t columnIndex ) const;
|
||||||
std::istream * getBlob( const std::string& columnLabel ) 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( uint32_t columnIndex ) const;
|
||||||
bool getBoolean( const std::string& columnLabel ) const;
|
bool getBoolean( const std::string& columnLabel ) const;
|
||||||
|
|
||||||
|
|
|
@ -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 )
|
catch( std::runtime_error e )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue