|
My Project
|
Attribute fields data provider: it is a group of attribute stored in {name, value} value pair fasion in a single database table. More...
#include <AttributeProvider.h>
Public Member Functions | |
| AttributeProvider (void) | |
| perform test cases when reseting db. More... | |
| bool | IsValid () |
| whether db is opened. More... | |
| void | Cleanup () |
| delete the database and set everything to NULL | |
| DBEntity * | GetDBEntity () |
| get the database object associated with this provider | |
| void | SetDBEntity (const string &sConnectionstring) |
| replace the current database with current one. More... | |
| void | ValidateDatabase () |
| ensure that the database has been set up properly. More... | |
| bool | SaveAttributeObject (const char *sTableName, IAttributeFields *pAttributeObject) |
| save the attribute object to the given table More... | |
| bool | LoadAttributeObject (const char *sTableName, IAttributeFields *pAttributeObject) |
| load the attribute object from a given table. More... | |
| void | SetTableName (const char *sName) |
| current attribute table name, if the table does not exists it will be created. More... | |
| const string & | GetTableName () |
| current attribute table name More... | |
| bool | ResetTable (const char *sName) |
| reset a given table to blank. More... | |
| bool | DoesAttributeExists (const char *sName) |
| current object name . More... | |
| bool | GetAttribute (const char *sName, string &sOut) |
| get the attribute of the current attribute instance in the current table More... | |
| bool | GetAttribute (CAttributeDbItem &inout) |
| get the complete attribute information in the current table More... | |
| bool | InsertAttribute (CAttributeDbItem &sIn) |
| insert a new attribute field in the current table More... | |
| bool | InsertAttribute (const char *sName, const char *sValue) |
| insert by simple name value pair More... | |
| bool | UpdateAttribute (const char *sName, const char *sIn) |
| update the attribute of the current attribute instance in the current table insert the attribute if it is not created before. More... | |
| bool | DeleteAttribute (const char *sName) |
| delete the attribute of the current attribute instance in the current table More... | |
| bool | CreateTableIfNotExists () |
| create the current table, if it does not exists. More... | |
Attribute fields data provider: it is a group of attribute stored in {name, value} value pair fasion in a single database table.
The db table does not define the name, hence a table in the database is very similar to an intance of Iattributefields in ParaEngine. To be extensible, the table record has the following format: {name(prim key), InstanceName(indexed), value, type, description, schematics} in other word, the database table provides a serialization of IAttributeField (all fields are persistent except get/set function address). All instances sharing the same ClassName are usually stored in the same db table. In case of a singleton, we can default InstanceName field to NULL. e.g. game world class may store global information for a game in the database, such as the spawn points, last player position, etc. Besides serializing IAttributeField class, the data provider should also expose methods to add and remove dynamic fields.
| AttributeProvider::AttributeProvider | ( | void | ) |
perform test cases when reseting db.
| bool AttributeProvider::CreateTableIfNotExists | ( | ) |
create the current table, if it does not exists.
This function is mostly called automatically when the SetTableName() function is called.
| bool AttributeProvider::DeleteAttribute | ( | const char * | sName | ) |
delete the attribute of the current attribute instance in the current table
| sName | : name of the attribute field |
| bool AttributeProvider::DoesAttributeExists | ( | const char * | sName | ) |
current object name .
a table may save attribute for multiple objects. this may be empty string, in which case the table is assumed to be storing a singleton object.
| sName | whether a given attribute exists. This function is usually used internally. One common use of this function is to test if a field exists, so that we know if a object has been saved before or not. |
| sName | : name of the attribute field |
| bool AttributeProvider::GetAttribute | ( | const char * | sName, |
| string & | sOut | ||
| ) |
get the attribute of the current attribute instance in the current table
| sName | : name of the attribute field |
| sOut | : value of the field as a string. |
| bool AttributeProvider::GetAttribute | ( | CAttributeDbItem & | inout | ) |
get the complete attribute information in the current table
| inout | : [in|out] get the complete database information. CAttributeDbItem::m_sName and CAttributeDbItem::m_sInstanceName must be filled first. the rest of CAttributeDbItem will be filled when the function returns. Please note that if CAttributeDbItem::m_sInstanceName is empty then the current object name will used instead. |
|
inline |
current attribute table name
| bool AttributeProvider::InsertAttribute | ( | CAttributeDbItem & | sIn | ) |
insert a new attribute field in the current table
| sIn | : [in] CAttributeDbItem::m_sName is always ignored. |
| bool AttributeProvider::InsertAttribute | ( | const char * | sName, |
| const char * | sValue | ||
| ) |
insert by simple name value pair
| sName | |
| sValue |
|
inline |
whether db is opened.
| bool AttributeProvider::LoadAttributeObject | ( | const char * | sTableName, |
| IAttributeFields * | pAttributeObject | ||
| ) |
load the attribute object from a given table.
| sTableName | if table name is empty, the current table is used. |
| pAttributeObject | [out] |
| bool AttributeProvider::ResetTable | ( | const char * | sName | ) |
reset a given table to blank.
if the table does not exists a blank one will be created.
| sName | table name |
| bool AttributeProvider::SaveAttributeObject | ( | const char * | sTableName, |
| IAttributeFields * | pAttributeObject | ||
| ) |
save the attribute object to the given table
| sTableName | if table name is empty, the current table is used. |
| pAttributeObject | [in] |
| void AttributeProvider::SetDBEntity | ( | const string & | sConnectionstring | ) |
replace the current database with current one.
the old one is closed and the new once will be opened.
| sConnectionstring | the file path |
| void AttributeProvider::SetTableName | ( | const char * | sName | ) |
current attribute table name, if the table does not exists it will be created.
| sName |
| bool AttributeProvider::UpdateAttribute | ( | const char * | sName, |
| const char * | sIn | ||
| ) |
update the attribute of the current attribute instance in the current table insert the attribute if it is not created before.
| sName | : name of the attribute field |
| sIn | value of the attribute field |
| void AttributeProvider::ValidateDatabase | ( | ) |
ensure that the database has been set up properly.
If not, ResetDatabase() is called to reset the database to blank
1.8.12