SourceMod SDK  1.7
SourceMod::IDatabase Class Referenceabstract

Encapsulates a database connection. More...

#include <public/IDBDriver.h>

Public Member Functions

virtual bool Close ()=0
 Disconnects the database and frees its associated memory. Note that the actual object will not be freed until all open references have been closed. More...
 
virtual const char * GetError (int *errorCode=NULL)=0
 Error code and string returned by the last operation on this connection. More...
 
virtual bool DoSimpleQuery (const char *query)=0
 Prepares and executes a query in one step, and discards any return data. More...
 
virtual IQueryDoQuery (const char *query)=0
 Prepares and executes a query in one step, and returns the resultant data set. More...
 
virtual IPreparedQueryPrepareQuery (const char *query, char *error, size_t maxlength, int *errCode=NULL)=0
 Prepares a query statement for multiple executions and/or binding marked parameters (? in MySQL/sqLite, $n in PostgreSQL). More...
 
virtual bool QuoteString (const char *str, char buffer[], size_t maxlen, size_t *newSize)=0
 
virtual unsigned int GetAffectedRows ()=0
 Number of rows affected by the last execute. More...
 
virtual unsigned int GetInsertID ()=0
 Retrieves the last insert ID on this database connection. More...
 
virtual bool LockForFullAtomicOperation ()=0
 Locks the database for an atomic query+retrieval operation. More...
 
virtual void UnlockFromFullAtomicOperation ()=0
 Unlocks a locked atomic fetch.
 
virtual void IncReferenceCount ()=0
 Increases the reference count on the database. More...
 
virtual IDBDriverGetDriver ()=0
 Returns the parent driver. More...
 
virtual bool DoSimpleQueryEx (const char *query, size_t len)=0
 Prepares and executes a binary query in one step, and discards any return data. More...
 
virtual IQueryDoQueryEx (const char *query, size_t len)=0
 Prepares and executes a binary query in one step, and returns the resultant data set. More...
 
virtual unsigned int GetAffectedRowsForQuery (IQuery *query)=0
 Retrieves the number of affected rows from the last execute of the given query. More...
 
virtual unsigned int GetInsertIDForQuery (IQuery *query)=0
 Retrieves the last insert id of the given query. More...
 
virtual bool SetCharacterSet (const char *characterset)=0
 Sets the character set of the current connection. More...
 
void AddRef ()
 Wrapper around IncReferenceCount(), for ke::Ref.
 
void Release ()
 Wrapper around Close(), for ke::Ref.
 

Detailed Description

Encapsulates a database connection.

Member Function Documentation

virtual bool SourceMod::IDatabase::Close ( )
pure virtual

Disconnects the database and frees its associated memory. Note that the actual object will not be freed until all open references have been closed.

It is guaranteed that an IDatabase pointer won't be destroyed until all open IQuery or IPreparedQuery pointers are closed.

This function is thread safe.

Returns
True if object was destroyed, false if references are remaining.
virtual IQuery* SourceMod::IDatabase::DoQuery ( const char *  query)
pure virtual

Prepares and executes a query in one step, and returns the resultant data set.

Note: If a query contains more than one result set, each result set must be processed before a new query is started.

This function is not thread safe and must be included in any locks.

Parameters
queryQuery string.
Returns
IQuery pointer on success, NULL otherwise.
virtual IQuery* SourceMod::IDatabase::DoQueryEx ( const char *  query,
size_t  len 
)
pure virtual

Prepares and executes a binary query in one step, and returns the resultant data set.

Note: If a query contains more than one result set, each result set must be processed before a new query is started.

This function is not thread safe and must be included in any locks.

Parameters
queryQuery string.
Returns
IQuery pointer on success, NULL otherwise.
virtual bool SourceMod::IDatabase::DoSimpleQuery ( const char *  query)
pure virtual

Prepares and executes a query in one step, and discards any return data.

This function is not thread safe and must be included in any locks.

Parameters
queryQuery string.
Returns
True on success, false otherwise.
virtual bool SourceMod::IDatabase::DoSimpleQueryEx ( const char *  query,
size_t  len 
)
pure virtual

Prepares and executes a binary query in one step, and discards any return data.

This function is not thread safe and must be included in any locks.

Parameters
queryQuery string.
lengthLength of query string.
Returns
True on success, false otherwise.
virtual unsigned int SourceMod::IDatabase::GetAffectedRows ( )
pure virtual

Number of rows affected by the last execute.

This function is not thread safe and must be included in any locks.

Returns
Number of rows affected by the last execute.
virtual unsigned int SourceMod::IDatabase::GetAffectedRowsForQuery ( IQuery query)
pure virtual

Retrieves the number of affected rows from the last execute of the given query.

Note: This can only accept queries from this driver.

This function is not thread safe and must be included in any locks.

Parameters
queryIQuery object from this driver
Returns
Rows affected from last execution of this query, if applicable.
virtual IDBDriver* SourceMod::IDatabase::GetDriver ( )
pure virtual

Returns the parent driver.

This function is thread safe.

virtual const char* SourceMod::IDatabase::GetError ( int *  errorCode = NULL)
pure virtual

Error code and string returned by the last operation on this connection.

This function is not thread safe and must be included in any locks.

Parameters
errorCodeOptional pointer to retrieve an error code.
Returns
Error string pointer (empty if none).
virtual unsigned int SourceMod::IDatabase::GetInsertID ( )
pure virtual

Retrieves the last insert ID on this database connection.

This function is not thread safe and must be included in any locks.

Returns
Row insertion ID of the last execute, if any.
virtual unsigned int SourceMod::IDatabase::GetInsertIDForQuery ( IQuery query)
pure virtual

Retrieves the last insert id of the given query.

Note: This can only accept queries from this driver.

This function is not thread safe and must be included in any locks.

Parameters
queryIQuery object from this driver
Returns
Insert Id from the last execution of this query, if applicable.
virtual void SourceMod::IDatabase::IncReferenceCount ( )
pure virtual

Increases the reference count on the database.

This function is thread safe.

virtual bool SourceMod::IDatabase::LockForFullAtomicOperation ( )
pure virtual

Locks the database for an atomic query+retrieval operation.

Returns
True on success, false if not supported.
virtual IPreparedQuery* SourceMod::IDatabase::PrepareQuery ( const char *  query,
char *  error,
size_t  maxlength,
int *  errCode = NULL 
)
pure virtual

Prepares a query statement for multiple executions and/or binding marked parameters (? in MySQL/sqLite, $n in PostgreSQL).

This function is not thread safe and must be included in any locks.

Parameters
queryQuery string.
errorError buffer.
maxlengthMaximum length of the error buffer.
errCodeOptional pointer to store a driver-specific error code.
Returns
IPreparedQuery pointer on success, NULL otherwise.
virtual bool SourceMod::IDatabase::QuoteString ( const char *  str,
char  buffer[],
size_t  maxlen,
size_t *  newSize 
)
pure virtual

Quotes a string for insertion into a query.

Parameters
strSource string.
bufferBuffer to store new string (should not overlap source string).
maxlenMaximum length of the output buffer.
newSizePointer to store the output size.
Returns
True on success, false if the output buffer is not big enough. If not big enough, the required buffer size is passed through newSize.
virtual bool SourceMod::IDatabase::SetCharacterSet ( const char *  characterset)
pure virtual

Sets the character set of the current connection.

Parameters
charactersetThe characterset to switch to. e.g. "utf8".

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