mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 07:37:01 +00:00
[6827] Added an interface for defining custom SQLStorage loaders.
This commit is contained in:
parent
b195eb87a9
commit
074bd3a08f
8 changed files with 294 additions and 136 deletions
|
|
@ -24,18 +24,26 @@
|
|||
|
||||
class SQLStorage
|
||||
{
|
||||
template<class T>
|
||||
friend struct SQLStorageLoaderBase;
|
||||
|
||||
public:
|
||||
|
||||
SQLStorage(const char*fmt,const char * _entry_field,const char * sqlname)
|
||||
SQLStorage(const char* fmt, const char * _entry_field, const char * sqlname)
|
||||
{
|
||||
format=fmt;
|
||||
entry_field = _entry_field;
|
||||
table=sqlname;
|
||||
data=NULL;
|
||||
pIndex=NULL;
|
||||
iNumFields =strlen(fmt);
|
||||
MaxEntry = 0;
|
||||
src_format = fmt;
|
||||
dst_format = fmt;
|
||||
init(_entry_field, sqlname);
|
||||
}
|
||||
|
||||
SQLStorage(const char* src_fmt, const char* dst_fmt, const char * _entry_field, const char * sqlname)
|
||||
{
|
||||
src_format = src_fmt;
|
||||
dst_format = dst_fmt;
|
||||
init(_entry_field, sqlname);
|
||||
}
|
||||
|
||||
|
||||
~SQLStorage()
|
||||
{
|
||||
Free();
|
||||
|
|
@ -54,15 +62,53 @@ class SQLStorage
|
|||
uint32 RecordCount;
|
||||
uint32 MaxEntry;
|
||||
uint32 iNumFields;
|
||||
|
||||
void Load();
|
||||
void Free();
|
||||
|
||||
private:
|
||||
void init(const char * _entry_field, const char * sqlname)
|
||||
{
|
||||
entry_field = _entry_field;
|
||||
table=sqlname;
|
||||
data=NULL;
|
||||
pIndex=NULL;
|
||||
iNumFields = strlen(src_format);
|
||||
MaxEntry = 0;
|
||||
}
|
||||
|
||||
char** pIndex;
|
||||
|
||||
char *data;
|
||||
const char *format;
|
||||
const char *src_format;
|
||||
const char *dst_format;
|
||||
const char *table;
|
||||
const char *entry_field;
|
||||
//bool HasString;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct SQLStorageLoaderBase
|
||||
{
|
||||
public:
|
||||
void Load(SQLStorage &storage);
|
||||
|
||||
template<class S, class D>
|
||||
void convert(uint32 field_pos, S src, D &dst);
|
||||
template<class S>
|
||||
void convert_to_str(uint32 field_pos, S src, char * & dst);
|
||||
template<class D>
|
||||
void convert_from_str(uint32 field_pos, char * src, D& dst);
|
||||
void convert_str_to_str(uint32 field_pos, char *src, char *&dst);
|
||||
|
||||
private:
|
||||
template<class V>
|
||||
void storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset);
|
||||
void storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset);
|
||||
};
|
||||
|
||||
struct SQLStorageLoader : public SQLStorageLoaderBase<SQLStorageLoader>
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue