mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-24 02:27:46 +00:00
What can i say but... more refactoring of db stuff
This commit is contained in:
parent
63346359c7
commit
224ecadef1
2 changed files with 165 additions and 155 deletions
|
@ -49,7 +49,22 @@ bool QueryResult::nextRow()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Database::Database()
|
Field *QueryResult::fetch()
|
||||||
|
{
|
||||||
|
return m_currentRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t QueryResult::getFieldCount() const
|
||||||
|
{
|
||||||
|
return m_fieldCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t QueryResult::getRowCount() const
|
||||||
|
{
|
||||||
|
return m_rowCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
Database::Database()
|
||||||
{
|
{
|
||||||
m_port = 0;
|
m_port = 0;
|
||||||
m_counter = 0;
|
m_counter = 0;
|
||||||
|
@ -339,5 +354,59 @@ void Database::shutdown()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string &Database::getHostName()
|
||||||
|
{
|
||||||
|
return m_hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Database::getDatabaseName()
|
||||||
|
{
|
||||||
|
return m_databaseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Field::setValue( char *value )
|
||||||
|
{
|
||||||
|
m_pValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Field::setLength( uint32_t value )
|
||||||
|
{
|
||||||
|
m_size = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Field::getString() const
|
||||||
|
{
|
||||||
|
if( !m_pValue )
|
||||||
|
return "";
|
||||||
|
return std::string( m_pValue );
|
||||||
|
}
|
||||||
|
|
||||||
|
void Field::getBinary( char *dstBuf, uint16_t size ) const
|
||||||
|
{
|
||||||
|
if( m_pValue )
|
||||||
|
{
|
||||||
|
memcpy( dstBuf, m_pValue, size );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dstBuf = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float Field::getFloat() const
|
||||||
|
{
|
||||||
|
return m_pValue ? static_cast< float >( atof( m_pValue ) ) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Field::getBool() const
|
||||||
|
{
|
||||||
|
return m_pValue ? atoi( m_pValue ) > 0 : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Field::getLength() const
|
||||||
|
{
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,57 +10,20 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Db {
|
namespace Db {
|
||||||
|
|
||||||
// CField is used to access db-query resultsets
|
|
||||||
class Field
|
class Field
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// set value
|
// set value
|
||||||
__inline void setValue( char* value )
|
void setValue( char* value );
|
||||||
{
|
void setLength( uint32_t value );
|
||||||
m_pValue = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// set value
|
std::string getString() const;
|
||||||
__inline void setLength( uint32_t value )
|
void getBinary( char* dstBuf, uint16_t size ) const;
|
||||||
{
|
float getFloat() const;
|
||||||
m_size = value;
|
bool getBool() const;
|
||||||
}
|
|
||||||
|
|
||||||
// return as string
|
|
||||||
__inline std::string getString() const
|
|
||||||
{
|
|
||||||
if( !m_pValue )
|
|
||||||
return "";
|
|
||||||
return std::string( m_pValue );
|
|
||||||
}
|
|
||||||
|
|
||||||
// return as string
|
|
||||||
__inline void getBinary( char* dstBuf, uint16_t size ) const
|
|
||||||
{
|
|
||||||
if( m_pValue )
|
|
||||||
{
|
|
||||||
memcpy( dstBuf, m_pValue, size );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dstBuf = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// return as float
|
|
||||||
__inline float getFloat() const
|
|
||||||
{
|
|
||||||
return m_pValue ? static_cast< float >( atof( m_pValue ) ) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// return as bool
|
|
||||||
__inline bool getBool() const
|
|
||||||
{
|
|
||||||
return m_pValue ? atoi( m_pValue ) > 0 : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< class T >
|
template< class T >
|
||||||
__inline T get() const
|
__inline T get() const
|
||||||
|
@ -71,11 +34,7 @@ namespace Core {
|
||||||
return static_cast< T >( atol( m_pValue ) );
|
return static_cast< T >( atol( m_pValue ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
__inline uint32_t getLength() const
|
uint32_t getLength() const;
|
||||||
{
|
|
||||||
return m_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *m_pValue;
|
char *m_pValue;
|
||||||
|
@ -91,18 +50,9 @@ namespace Core {
|
||||||
|
|
||||||
bool nextRow();
|
bool nextRow();
|
||||||
|
|
||||||
__inline Field* fetch()
|
Field* fetch();
|
||||||
{
|
uint32_t getFieldCount() const;
|
||||||
return m_currentRow;
|
uint32_t getRowCount() const;
|
||||||
}
|
|
||||||
__inline uint32_t getFieldCount() const
|
|
||||||
{
|
|
||||||
return m_fieldCount;
|
|
||||||
}
|
|
||||||
__inline uint32_t getRowCount() const
|
|
||||||
{
|
|
||||||
return m_rowCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32_t m_fieldCount;
|
uint32_t m_fieldCount;
|
||||||
|
@ -134,27 +84,18 @@ namespace Core {
|
||||||
Database();
|
Database();
|
||||||
virtual ~Database();
|
virtual ~Database();
|
||||||
|
|
||||||
/************************************************************************/
|
|
||||||
/* Virtual Functions */
|
|
||||||
/************************************************************************/
|
|
||||||
bool initialize( const DatabaseParams& params );
|
bool initialize( const DatabaseParams& params );
|
||||||
|
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
boost::shared_ptr<QueryResult> query( const std::string& QueryString );
|
boost::shared_ptr< QueryResult > query( const std::string& QueryString );
|
||||||
bool waitExecuteNA( const char* QueryString );//Wait For Request Completion
|
bool waitExecuteNA( const char* QueryString );//Wait For Request Completion
|
||||||
bool execute( const char* QueryString, ... );
|
bool execute( const char* QueryString, ... );
|
||||||
bool execute( const std::string& QueryString );
|
bool execute( const std::string& QueryString );
|
||||||
|
|
||||||
__inline const std::string& getHostName()
|
const std::string& getHostName();
|
||||||
{
|
|
||||||
return m_hostname;
|
|
||||||
}
|
|
||||||
|
|
||||||
__inline const std::string& getDatabaseName()
|
const std::string& getDatabaseName();
|
||||||
{
|
|
||||||
return m_databaseName;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string escapeString( std::string Escape );
|
std::string escapeString( std::string Escape );
|
||||||
void escapeLongString( const char * str, uint32_t len, std::stringstream& out );
|
void escapeLongString( const char * str, uint32_t len, std::stringstream& out );
|
||||||
|
@ -195,6 +136,6 @@ namespace Core {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue