1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-23 18:17:46 +00:00

What can i say but... more refactoring of db stuff

This commit is contained in:
Mordred 2017-09-01 23:21:35 +02:00
parent 63346359c7
commit 224ecadef1
2 changed files with 165 additions and 155 deletions

View file

@ -49,6 +49,21 @@ bool QueryResult::nextRow()
return true;
}
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;
@ -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;
}
}
}

View file

@ -12,55 +12,18 @@
namespace Core {
namespace Db {
// CField is used to access db-query resultsets
class Field
{
public:
// set value
__inline void setValue( char* value )
{
m_pValue = value;
}
void setValue( char* value );
void setLength( uint32_t value );
// set value
__inline void setLength( uint32_t value )
{
m_size = value;
}
// 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;
}
std::string getString() const;
void getBinary( char* dstBuf, uint16_t size ) const;
float getFloat() const;
bool getBool() const;
template< class T >
__inline T get() const
@ -71,11 +34,7 @@ namespace Core {
return static_cast< T >( atol( m_pValue ) );
}
__inline uint32_t getLength() const
{
return m_size;
}
uint32_t getLength() const;
private:
char *m_pValue;
@ -91,18 +50,9 @@ namespace Core {
bool nextRow();
__inline Field* fetch()
{
return m_currentRow;
}
__inline uint32_t getFieldCount() const
{
return m_fieldCount;
}
__inline uint32_t getRowCount() const
{
return m_rowCount;
}
Field* fetch();
uint32_t getFieldCount() const;
uint32_t getRowCount() const;
protected:
uint32_t m_fieldCount;
@ -134,9 +84,6 @@ namespace Core {
Database();
virtual ~Database();
/************************************************************************/
/* Virtual Functions */
/************************************************************************/
bool initialize( const DatabaseParams& params );
void shutdown();
@ -146,15 +93,9 @@ namespace Core {
bool execute( const char* QueryString, ... );
bool execute( const std::string& QueryString );
__inline const std::string& getHostName()
{
return m_hostname;
}
const std::string& getHostName();
__inline const std::string& getDatabaseName()
{
return m_databaseName;
}
const std::string& getDatabaseName();
std::string escapeString( std::string Escape );
void escapeLongString( const char * str, uint32_t len, std::stringstream& out );