diff options
Diffstat (limited to 'src/shared/Database/SQLStorageImpl.h')
-rw-r--r-- | src/shared/Database/SQLStorageImpl.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/shared/Database/SQLStorageImpl.h b/src/shared/Database/SQLStorageImpl.h index c229327a0ec..b511bdad68c 100644 --- a/src/shared/Database/SQLStorageImpl.h +++ b/src/shared/Database/SQLStorageImpl.h @@ -15,15 +15,18 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #include "ProgressBar.h" #include "Log.h" #include "DBCFileLoader.h" + template<class T> template<class S, class D> void SQLStorageLoaderBase<T>::convert(uint32 /*field_pos*/, S src, D &dst) { dst = D(src); } + template<class T> void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char *src, char *&dst) { @@ -39,6 +42,7 @@ void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char *src memcpy(dst, src, l); } } + template<class T> template<class S> void SQLStorageLoaderBase<T>::convert_to_str(uint32 /*field_pos*/, S /*src*/, char * & dst) @@ -46,12 +50,14 @@ void SQLStorageLoaderBase<T>::convert_to_str(uint32 /*field_pos*/, S /*src*/, ch dst = new char[1]; *dst = 0; } + template<class T> template<class D> void SQLStorageLoaderBase<T>::convert_from_str(uint32 /*field_pos*/, char * /*src*/, D& dst) { dst = 0; } + template<class T> template<class V> void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset) @@ -81,6 +87,7 @@ void SQLStorageLoaderBase<T>::storeValue(V value, SQLStorage &store, char *p, in break; } } + template<class T> void SQLStorageLoaderBase<T>::storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset) { @@ -109,6 +116,7 @@ void SQLStorageLoaderBase<T>::storeValue(char * value, SQLStorage &store, char * break; } } + template<class T> void SQLStorageLoaderBase<T>::Load(SQLStorage &store) { @@ -120,8 +128,10 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) sLog.outError("Error loading %s table (not exist?)\n", store.table); exit(1); // Stop server at loading non exited table or not accessable table } + maxi = (*result)[0].GetUInt32()+1; delete result; + result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.table); if(result) { @@ -131,15 +141,19 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) } else store.RecordCount = 0; + result = WorldDatabase.PQuery("SELECT * FROM %s", store.table); + if(!result) { sLog.outError("%s table is empty!\n", store.table); store.RecordCount = 0; return; } + uint32 recordsize = 0; uint32 offset = 0; + if(store.iNumFields != result->GetFieldCount()) { store.RecordCount = 0; @@ -147,6 +161,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) delete result; exit(1); // Stop server at loading broken or non-compatible table. } + //get struct size uint32 sc=0; uint32 bo=0; @@ -159,8 +174,10 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) else if (store.dst_format[x]==FT_BYTE) ++bb; recordsize=(store.iNumFields-sc-bo-bb)*4+sc*sizeof(char*)+bo*sizeof(bool)+bb*sizeof(char); + char** newIndex=new char*[maxi]; memset(newIndex,0,maxi*sizeof(char*)); + char * _data= new char[store.RecordCount *recordsize]; uint32 count=0; barGoLink bar( store.RecordCount ); @@ -170,6 +187,7 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) bar.step(); char *p=(char*)&_data[recordsize*count]; newIndex[fields[0].GetUInt32()]=p; + offset=0; for(uint32 x = 0; x < store.iNumFields; x++) switch(store.src_format[x]) @@ -187,7 +205,9 @@ void SQLStorageLoaderBase<T>::Load(SQLStorage &store) } ++count; }while( result->NextRow() ); + delete result; + store.pIndex = newIndex; store.MaxEntry = maxi; store.data = _data; |