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:
parent
63346359c7
commit
224ecadef1
2 changed files with 165 additions and 155 deletions
|
@ -49,7 +49,22 @@ bool QueryResult::nextRow()
|
|||
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_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>
|
||||
|
||||
namespace Core {
|
||||
namespace Db {
|
||||
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,27 +84,18 @@ namespace Core {
|
|||
Database();
|
||||
virtual ~Database();
|
||||
|
||||
/************************************************************************/
|
||||
/* Virtual Functions */
|
||||
/************************************************************************/
|
||||
bool initialize( const DatabaseParams& params );
|
||||
|
||||
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 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 );
|
||||
|
@ -195,6 +136,6 @@ namespace Core {
|
|||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue