Otclient  14/8/2020
Database Class Reference

#include <database.h>

Inheritance diagram for Database:
Collaboration diagram for Database:

Public Member Functions

 Database ()
 
virtual ~Database ()
 
virtual void connect (const std::string &host, const std::string &user, const std::string &pass, const std::string &db, uint16 port, const std::string &unix_socket="")
 
virtual bool beginTransaction ()
 
virtual bool rollback ()
 
virtual bool commit ()
 
virtual bool executeQuery (const std::string &query)
 
virtual DBResultPtr storeQuery (const std::string &query)
 
virtual std::string escapeString (const std::string &)
 
virtual std::string escapeBlob (const char *, uint32)
 
virtual uint64 getLastInsertedRowID ()
 
virtual std::string getStringComparer ()
 
virtual std::string getUpdateLimiter ()
 
virtual Fw::DatabaseEngine getDatabaseEngine ()
 
bool isConnected ()
 
- Public Member Functions inherited from LuaObject
 LuaObject ()
 
virtual ~LuaObject ()
 
template<typename T >
void connectLuaField (const std::string &field, const std::function< T > &f, bool pushFront=false)
 
template<typename... T>
int luaCallLuaField (const std::string &field, const T &... args)
 
template<typename R , typename... T>
callLuaField (const std::string &field, const T &... args)
 
template<typename... T>
void callLuaField (const std::string &field, const T &... args)
 
bool hasLuaField (const std::string &field)
 Returns true if the lua field exists. More...
 
template<typename T >
void setLuaField (const std::string &key, const T &value)
 Sets a field in this lua object. More...
 
template<typename T >
getLuaField (const std::string &key)
 Gets a field from this lua object. More...
 
void releaseLuaFieldsTable ()
 Release fields table reference. More...
 
void luaSetField (const std::string &key)
 Sets a field from this lua object, the value must be on the stack. More...
 
void luaGetField (const std::string &key)
 Gets a field from this lua object, the result is pushed onto the stack. More...
 
void luaGetMetatable ()
 Get object's metatable. More...
 
void luaGetFieldsTable ()
 Gets the table containing all stored fields of this lua object, the result is pushed onto the stack. More...
 
int getUseCount ()
 
std::string getClassName ()
 Returns the derived class name, its the same name used in Lua. More...
 
LuaObjectPtr asLuaObject ()
 
void operator= (const LuaObject &)
 
- Public Member Functions inherited from stdext::shared_object
 shared_object ()
 
virtual ~shared_object ()
 
void add_ref ()
 
void dec_ref ()
 
refcount_t ref_count ()
 
template<typename T >
stdext::shared_object_ptr< T > static_self_cast ()
 
template<typename T >
stdext::shared_object_ptr< T > dynamic_self_cast ()
 
template<typename T >
stdext::shared_object_ptr< T > const_self_cast ()
 

Protected Member Functions

void setConnected (bool connected)
 
virtual bool handleError ()
 
virtual bool internalExecuteQuery (const std::string &query)
 
DBResultPtr verifyResult (DBResultPtr result)
 

Protected Attributes

ticks_t m_use
 
bool m_connected
 

Friends

class DBTransaction
 

Detailed Description

Definition at line 31 of file database.h.

Constructor & Destructor Documentation

◆ Database()

Database::Database ( )
inline

Definition at line 36 of file database.h.

◆ ~Database()

virtual Database::~Database ( )
inlinevirtual

Definition at line 37 of file database.h.

Member Function Documentation

◆ beginTransaction()

virtual bool Database::beginTransaction ( )
inlinevirtual

Transaction related methods.

Methods for starting, commiting and rolling back transaction. Each of the returns boolean value.

Returns
true on success, false on error
Note
#include <ctime> If your database system doesn't support transactions you should return true - it's not feature test, code should work without transaction, just will lack integrity.

Reimplemented in DatabaseMySQL.

Definition at line 57 of file database.h.

Here is the caller graph for this function:

◆ commit()

virtual bool Database::commit ( )
inlinevirtual

Reimplemented in DatabaseMySQL.

Definition at line 59 of file database.h.

Here is the caller graph for this function:

◆ connect()

virtual void Database::connect ( const std::string &  host,
const std::string &  user,
const std::string &  pass,
const std::string &  db,
uint16  port,
const std::string &  unix_socket = "" 
)
inlinevirtual

Database connector.

Connects the database to the source host.

Reimplemented in DatabaseMySQL.

Definition at line 44 of file database.h.

◆ escapeBlob()

virtual std::string Database::escapeBlob ( const char *  ,
uint32   
)
inlinevirtual

Escapes binary stream for query.

Prepares binary stream to fit SQL queries.

Parameters
char*binary stream
longstream length
Returns
quoted string

Reimplemented in DatabaseMySQL.

Definition at line 100 of file database.h.

◆ escapeString()

virtual std::string Database::escapeString ( const std::string &  )
inlinevirtual

Escapes string for query.

Prepares string to fit SQL queries including quoting it.

Parameters
std::stringstring to be escaped
Returns
quoted string

Reimplemented in DatabaseMySQL.

Definition at line 89 of file database.h.

Here is the caller graph for this function:

◆ executeQuery()

virtual bool Database::executeQuery ( const std::string &  query)
inlinevirtual

Executes command.

Executes query which doesn't generates results (eg. INSERT, UPDATE, DELETE...).

Parameters
std::stringquery command
Returns
true on success, false on error

Reimplemented in DatabaseMySQL.

Definition at line 69 of file database.h.

Here is the caller graph for this function:

◆ getDatabaseEngine()

virtual Fw::DatabaseEngine Database::getDatabaseEngine ( )
inlinevirtual

Get database engine

Returns
the database engine type

Reimplemented in DatabaseMySQL.

Definition at line 122 of file database.h.

Here is the caller graph for this function:

◆ getLastInsertedRowID()

virtual uint64 Database::getLastInsertedRowID ( )
inlinevirtual

Retrieve id of last inserted row

Returns
id on success, 0 if last query did not result on any rows with auto_increment keys

Reimplemented in DatabaseMySQL.

Definition at line 107 of file database.h.

Here is the caller graph for this function:

◆ getStringComparer()

virtual std::string Database::getStringComparer ( )
inlinevirtual

Get case insensitive string comparison operator

Returns
the case insensitive operator

Definition at line 114 of file database.h.

Here is the caller graph for this function:

◆ getUpdateLimiter()

virtual std::string Database::getUpdateLimiter ( )
inlinevirtual

Definition at line 115 of file database.h.

Here is the caller graph for this function:

◆ handleError()

virtual bool Database::handleError ( )
inlineprotectedvirtual

Reimplemented in DatabaseMySQL.

Definition at line 141 of file database.h.

◆ internalExecuteQuery()

virtual bool Database::internalExecuteQuery ( const std::string &  query)
inlineprotectedvirtual

Reimplemented in DatabaseMySQL.

Definition at line 142 of file database.h.

◆ isConnected()

bool Database::isConnected ( )
inline

Database connected.

Returns whether or not the database is connected.

Returns
whether or not the database is connected.

Definition at line 131 of file database.h.

Here is the caller graph for this function:

◆ rollback()

virtual bool Database::rollback ( )
inlinevirtual

Reimplemented in DatabaseMySQL.

Definition at line 58 of file database.h.

Here is the caller graph for this function:

◆ setConnected()

void Database::setConnected ( bool  connected)
inlineprotected

Database set connected.

Sets the database to know that it is connected.

Definition at line 139 of file database.h.

Here is the caller graph for this function:

◆ storeQuery()

virtual DBResultPtr Database::storeQuery ( const std::string &  query)
inlinevirtual

Queries database.

Executes query which generates results (mostly SELECT).

Parameters
std::stringquery
Returns
results object (null on error)

Reimplemented in DatabaseMySQL.

Definition at line 79 of file database.h.

◆ verifyResult()

DBResultPtr Database::verifyResult ( DBResultPtr  result)
protected

Definition at line 27 of file database.cpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ DBTransaction

friend class DBTransaction
friend

Definition at line 34 of file database.h.

Member Data Documentation

◆ m_connected

bool Database::m_connected
protected

Definition at line 147 of file database.h.

◆ m_use

ticks_t Database::m_use
protected

Definition at line 146 of file database.h.


The documentation for this class was generated from the following files: