mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[12023] Enable SQL-Storage to work with entries of value zero
This commit is contained in:
parent
a309de2e6d
commit
314c448a3d
2 changed files with 24 additions and 26 deletions
|
|
@ -28,22 +28,20 @@ class SQLStorage
|
||||||
friend struct SQLStorageLoaderBase;
|
friend struct SQLStorageLoaderBase;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
SQLStorage(const char* fmt, const char* _entry_field, const char* sqlname)
|
||||||
SQLStorage(const char* fmt, const char * _entry_field, const char * sqlname)
|
|
||||||
{
|
{
|
||||||
src_format = fmt;
|
src_format = fmt;
|
||||||
dst_format = fmt;
|
dst_format = fmt;
|
||||||
init(_entry_field, sqlname);
|
init(_entry_field, sqlname);
|
||||||
}
|
}
|
||||||
|
|
||||||
SQLStorage(const char* src_fmt, const char* dst_fmt, const char * _entry_field, const char * sqlname)
|
SQLStorage(const char* src_fmt, const char* dst_fmt, const char* _entry_field, const char* sqlname)
|
||||||
{
|
{
|
||||||
src_format = src_fmt;
|
src_format = src_fmt;
|
||||||
dst_format = dst_fmt;
|
dst_format = dst_fmt;
|
||||||
init(_entry_field, sqlname);
|
init(_entry_field, sqlname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
~SQLStorage()
|
~SQLStorage()
|
||||||
{
|
{
|
||||||
Free();
|
Free();
|
||||||
|
|
@ -52,9 +50,7 @@ class SQLStorage
|
||||||
template<class T>
|
template<class T>
|
||||||
T const* LookupEntry(uint32 id) const
|
T const* LookupEntry(uint32 id) const
|
||||||
{
|
{
|
||||||
if( id == 0 )
|
if (id >= MaxEntry)
|
||||||
return NULL;
|
|
||||||
if(id >= MaxEntry)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
return reinterpret_cast<T const*>(pIndex[id]);
|
return reinterpret_cast<T const*>(pIndex[id]);
|
||||||
}
|
}
|
||||||
|
|
@ -70,13 +66,14 @@ class SQLStorage
|
||||||
void Free();
|
void Free();
|
||||||
|
|
||||||
void EraseEntry(uint32 id);
|
void EraseEntry(uint32 id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init(const char * _entry_field, const char * sqlname)
|
void init(const char* _entry_field, const char* sqlname)
|
||||||
{
|
{
|
||||||
entry_field = _entry_field;
|
entry_field = _entry_field;
|
||||||
table=sqlname;
|
table=sqlname;
|
||||||
data=NULL;
|
data = NULL;
|
||||||
pIndex=NULL;
|
pIndex = NULL;
|
||||||
iNumFields = strlen(src_format);
|
iNumFields = strlen(src_format);
|
||||||
oNumFields = strlen(dst_format);
|
oNumFields = strlen(dst_format);
|
||||||
MaxEntry = 0;
|
MaxEntry = 0;
|
||||||
|
|
@ -84,11 +81,11 @@ class SQLStorage
|
||||||
|
|
||||||
char** pIndex;
|
char** pIndex;
|
||||||
|
|
||||||
char *data;
|
char* data;
|
||||||
const char *src_format;
|
const char* src_format;
|
||||||
const char *dst_format;
|
const char* dst_format;
|
||||||
const char *table;
|
const char* table;
|
||||||
const char *entry_field;
|
const char* entry_field;
|
||||||
//bool HasString;
|
//bool HasString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -96,30 +93,31 @@ template <class T>
|
||||||
struct SQLStorageLoaderBase
|
struct SQLStorageLoaderBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Load(SQLStorage &storage, bool error_at_empty = true);
|
void Load(SQLStorage& storage, bool error_at_empty = true);
|
||||||
|
|
||||||
template<class S, class D>
|
template<class S, class D>
|
||||||
void convert(uint32 field_pos, S src, D &dst);
|
void convert(uint32 field_pos, S src, D& dst);
|
||||||
template<class S>
|
template<class S>
|
||||||
void convert_to_str(uint32 field_pos, S src, char * & dst);
|
void convert_to_str(uint32 field_pos, S src, char*& dst);
|
||||||
template<class D>
|
template<class D>
|
||||||
void convert_from_str(uint32 field_pos, char const* src, D& dst);
|
void convert_from_str(uint32 field_pos, char const* src, D& dst);
|
||||||
void convert_str_to_str(uint32 field_pos, char const* src, char *&dst);
|
void convert_str_to_str(uint32 field_pos, char const* src, char*& dst);
|
||||||
template<class S, class D>
|
template<class S, class D>
|
||||||
void default_fill(uint32 field_pos, S src, D &dst);
|
void default_fill(uint32 field_pos, S src, D& dst);
|
||||||
void default_fill_to_str(uint32 field_pos, char const* src, char * & dst);
|
void default_fill_to_str(uint32 field_pos, char const* src, char*& dst);
|
||||||
|
|
||||||
// trap, no body
|
// trap, no body
|
||||||
template<class D>
|
template<class D>
|
||||||
void convert_from_str(uint32 field_pos, char* src, D& dst);
|
void convert_from_str(uint32 field_pos, char* src, D& dst);
|
||||||
void convert_str_to_str(uint32 field_pos, char* src, char *&dst);
|
void convert_str_to_str(uint32 field_pos, char* src, char*& dst);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template<class V>
|
template<class V>
|
||||||
void storeValue(V value, SQLStorage &store, char *p, uint32 x, uint32 &offset);
|
void storeValue(V value, SQLStorage& store, char* p, uint32 x, uint32& offset);
|
||||||
void storeValue(char const* value, SQLStorage &store, char *p, uint32 x, uint32 &offset);
|
void storeValue(char const* value, SQLStorage& store, char* p, uint32 x, uint32& offset);
|
||||||
|
|
||||||
// trap, no body
|
// trap, no body
|
||||||
void storeValue(char * value, SQLStorage &store, char *p, uint32 x, uint32 &offset);
|
void storeValue(char* value, SQLStorage& store, char* p, uint32 x, uint32& offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SQLStorageLoader : public SQLStorageLoaderBase<SQLStorageLoader>
|
struct SQLStorageLoader : public SQLStorageLoaderBase<SQLStorageLoader>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "12022"
|
#define REVISION_NR "12023"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue