My Project
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ParaInfoCenter::DBEntity Class Reference

a single database file. More...

#include <ICDBManager.h>

Public Member Functions

PE_CORE_DECL void Release ()
 
void addref ()
 add reference count of the asset. More...
 
bool delref ()
 decrease reference count of the asset. More...
 
int GetRefCount ()
 get the reference count
 
PE_CORE_DECL int ExecuteSqlStringFormated (const char *sql,...)
 execute a sql script. More...
 
PE_CORE_DECL int ExecuteSqlStringFormated (const char16_t *sql,...)
 
PE_CORE_DECL int ExecuteSqlScript (const char *sql, bool bBreakOnError=false)
 execute a sql script. More...
 
PE_CORE_DECL int sql_prepare (const char *sql,...)
 prepare a sql statement, and return the statement object. More...
 
PE_CORE_DECL int sql_prepare (const char16_t *sql,...)
 
PE_CORE_DECL int sql_step ()
 step through the current sql statement. More...
 
PE_CORE_DECL int sql_finalize ()
 finalize the current statement if it has not been finalized. More...
 
sqlite3_stmt * GetStatement ()
 get the current statement
 
PE_CORE_DECL void OpenDB ()
 ensure that the database is opened. More...
 
PE_CORE_DECL void CloseDB ()
 ensure that the database is closed. More...
 
PE_CORE_DECL bool IsValid () const
 return true if database is now successfully opened. More...
 
PE_CORE_DECL const string & GetConnectionString ()
 get the connection string. More...
 
sqlite3 * GetDBHandle ()
 get sqlite3 object More...
 
PE_CORE_DECL CICRecordSetCreateRecordSet (const char *sql,...)
 Create a managed sql statement(procedure). More...
 
PE_CORE_DECL CICRecordSetCreateRecordSet (const char16_t *sql,...)
 
PE_CORE_DECL CICRecordSetCreateRecordSet1 (const char *sql)
 similar to CreateRecordSet(const char* sql,...), except that there is no limit to input length
 
PE_CORE_DECL CICRecordSetCreateRecordSet1 (const char16_t *sql)
 
PE_CORE_DECL CICRecordSetCreateRecordSet ()
 
PE_CORE_DECL void DeleteRecordSet (CICRecordSet *recordset)
 explicitly release a record set. More...
 
PE_CORE_DECL int64 GetLastInsertRowID ()
 
PE_CORE_DECL bool IsCreateFile ()
 get if database file is opened by creating a new database file. More...
 
PE_CORE_DECL void SetCreateFile (bool bCreateFile)
 set if database file is opened by creating a new database file. More...
 

Protected Member Functions

void exec_sql16 (const char16_t *sql)
 execute the command until it is completed. More...
 
void exec_sql (const char *sql)
 
void prepare_sql (const char16_t *sql,...)
 it is always used with exec_sql16(). More...
 
void prepare_sql (const char *sql,...)
 
void exec_sql ()
 
void exec_sql16 ()
 
sqlite3_stmt * exec_sql_prepare ()
 
sqlite3_stmt * exec_sql_prepare16 ()
 
int exec_sql_finish ()
 
int exec_sql_finish (sqlite3_stmt *stmt)
 
int exec_sql_step ()
 
int exec_sql_step (sqlite3_stmt *stmt)
 
void OpenDB16 (const char16_t *dbname)
 open database file More...
 
void OpenDB (const char *dbname)
 
string PrepareDatabaseFile (const string &filename)
 prepare the database file before open it. More...
 
void init ()
 

Protected Attributes

sqlite3 * m_db
 database handle
 
vector< RSpair > m_RSpool
 a pool of sql statements created by the user. More...
 
u16string m_name
 alias name of the db
 
string m_filepath
 db file path
 
bool m_isValid
 whether db is opened. More...
 
bool m_bEncodingUTF8
 whether the database use UTF-8 encoding; if false it will be UTF-16 unicode encoding. More...
 
bool m_bIsCreateFile
 this is true if database file is opened by creating a new database file. More...
 
int m_nSQLite_OpenFlags
 the opening flags for sqlite3_open_v2(). More...
 
std::u16string m_wsql
 
std::string m_sql
 
void * m_trail
 
sqlite3_stmt * m_stmt
 
ParaEngine::mutex m_mutex
 this makes all db query thread-safe
 
int m_refcount
 reference count of the asset. More...
 

Friends

class CICMapTrace
 
class CICRoot
 
class CICGenManager
 
class CICDBManager
 

Detailed Description

a single database file.

Member Function Documentation

§ addref()

void ParaInfoCenter::DBEntity::addref ( )
inline

add reference count of the asset.

One may later order the asset manager to remove all asset whose reference count has dropped to 0

§ CloseDB()

void DBEntity::CloseDB ( )

ensure that the database is closed.

§ CreateRecordSet()

CICRecordSet * DBEntity::CreateRecordSet ( const char *  sql,
  ... 
)

Create a managed sql statement(procedure).

One can bind data field and execute it through the CICRecordSet,class

Parameters
sqlsql commands
...
Returns
sql statement object is returned.

§ DeleteRecordSet()

void DBEntity::DeleteRecordSet ( CICRecordSet recordset)

explicitly release a record set.

Parameters
recordset

§ delref()

bool ParaInfoCenter::DBEntity::delref ( )
inline

decrease reference count of the asset.

One may later order the asset manager to remove all asset whose reference count has dropped to 0

Returns
: return true if the the reference count is zero after decreasing it

§ exec_sql16()

void DBEntity::exec_sql16 ( const char16_t *  sql)
protected

execute the command until it is completed.

Parameters
*sql

§ ExecuteSqlScript()

int DBEntity::ExecuteSqlScript ( const char *  sql,
bool  bBreakOnError = false 
)

execute a sql script.

similar to ExecuteSqlStringFormated(), except that there is no length limit to sql string.

Parameters
*sqlthis string is usually read from resource file
bBreakOnErrordefault to false. if true, the script will break on any error; otherwise, it will continue execute the following commands even when there are previous errors.
Returns
the most recent error code is returned.

sqlite3_complete((const char*)m_trail)

sqlite3_complete((const char*)m_trail)

§ ExecuteSqlStringFormated()

int DBEntity::ExecuteSqlStringFormated ( const char *  sql,
  ... 
)

execute a sql script.

It is equivalent to calling sql_prepare(), sql_step(), sql_finalize() in that order until all commands are completed. this function will handle error messages and will not throw exception.

Parameters
sqlsql must be less than 2048 in length.

§ GetConnectionString()

PE_CORE_DECL const string& ParaInfoCenter::DBEntity::GetConnectionString ( )
inline

get the connection string.

It is currently the file path.

Returns

§ GetDBHandle()

sqlite3* ParaInfoCenter::DBEntity::GetDBHandle ( )
inline

get sqlite3 object

Returns

§ IsCreateFile()

bool DBEntity::IsCreateFile ( )

get if database file is opened by creating a new database file.

one may want to install all tables and initial data if a database file is newly created.

§ IsValid()

PE_CORE_DECL bool ParaInfoCenter::DBEntity::IsValid ( ) const
inline

return true if database is now successfully opened.

Returns

§ OpenDB()

void DBEntity::OpenDB ( )

ensure that the database is opened.

§ OpenDB16()

void DBEntity::OpenDB16 ( const char16_t *  dbname)
protected

open database file

Parameters
dbname

§ prepare_sql()

void DBEntity::prepare_sql ( const char16_t *  sql,
  ... 
)
protected

it is always used with exec_sql16().

e.g. prepare_sql(...); exec_sql();

Parameters
*sql
...

§ PrepareDatabaseFile()

string DBEntity::PrepareDatabaseFile ( const string &  filename)
protected

prepare the database file before open it.

Some database files are in archives, we will first copy them to a temporary disk location and then load the disk file instead.

Parameters
filenamethe file to be prepared. it can be ":memory:", a disk file or a file in a zip file.
Returns
always returns the disk file path or ":memory:", it is "", if the file is not valid.

§ Release()

void DBEntity::Release ( )

because some of DBEntity is not reference counted. we shall do a (GetRefCount()==0) check

§ SetCreateFile()

void DBEntity::SetCreateFile ( bool  bCreateFile)

set if database file is opened by creating a new database file.

one may want to install all tables and initial data if a database file is newly created.

§ sql_finalize()

int DBEntity::sql_finalize ( )

finalize the current statement if it has not been finalized.

§ sql_prepare()

int DBEntity::sql_prepare ( const char *  sql,
  ... 
)

prepare a sql statement, and return the statement object.

CICSQLException exception may be thrown.

§ sql_step()

int DBEntity::sql_step ( )

step through the current sql statement.

Returns
If the return code is SQLITE_ERROR, CICSQLException exception will be thrown, the current sql statement will be automatically finalized.

Member Data Documentation

§ m_bEncodingUTF8

bool ParaInfoCenter::DBEntity::m_bEncodingUTF8
protected

whether the database use UTF-8 encoding; if false it will be UTF-16 unicode encoding.

§ m_bIsCreateFile

bool ParaInfoCenter::DBEntity::m_bIsCreateFile
protected

this is true if database file is opened by creating a new database file.

§ m_isValid

bool ParaInfoCenter::DBEntity::m_isValid
protected

whether db is opened.

§ m_nSQLite_OpenFlags

int ParaInfoCenter::DBEntity::m_nSQLite_OpenFlags
protected

the opening flags for sqlite3_open_v2().

default to SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE .

§ m_refcount

int ParaInfoCenter::DBEntity::m_refcount
protected

reference count of the asset.

Asset may be referenced by scene objects. Once the reference count drops to 0, the asset may be unloaded, due to asset garbage collection. however, the asset is not completed removed. Pointers to this object will still be valid. only resources (such as texture, mesh data, etc) are unloaded.

§ m_RSpool

vector<RSpair> ParaInfoCenter::DBEntity::m_RSpool
protected

a pool of sql statements created by the user.


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