Show
Ignore:
Timestamp:
11/21/08 08:47:55 (17 years ago)
Author:
yumileroy
Message:

*DB script table stucture change. Source Mangos. Also fix some bugs. Hopefully this rev will make program usable again.

Original author: megamage
Date: 2008-11-20 10:43:20-06:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/shared/Database/SQLStorage.h

    r102 r260  
    1111 * This program is distributed in the hope that it will be useful, 
    1212 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
     13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1414 * GNU General Public License for more details. 
    1515 * 
    1616 * You should have received a copy of the GNU General Public License 
    1717 * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
     18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
    1919 */ 
    2020 
     
    2727class SQLStorage 
    2828{ 
     29    template<class T> 
     30    friend struct SQLStorageLoaderBase; 
     31 
    2932    public: 
    3033 
    31         SQLStorage(const char*fmt,const char * _entry_field,const char * sqlname) 
     34        SQLStorage(const char* fmt, const char * _entry_field, const char * sqlname) 
    3235        { 
    33             format=fmt; 
    34             entry_field = _entry_field; 
    35             table=sqlname; 
    36             data=NULL; 
    37             pIndex=NULL; 
    38             iNumFields =strlen(fmt); 
    39             MaxEntry = 0; 
     36            src_format = fmt; 
     37            dst_format = fmt; 
     38            init(_entry_field, sqlname); 
    4039        } 
     40 
     41        SQLStorage(const char* src_fmt, const char* dst_fmt, const char * _entry_field, const char * sqlname) 
     42        { 
     43            src_format = src_fmt; 
     44            dst_format = dst_fmt; 
     45            init(_entry_field, sqlname); 
     46        } 
     47 
     48 
    4149        ~SQLStorage() 
    4250        { 
     
    5765        uint32 MaxEntry; 
    5866        uint32 iNumFields; 
     67 
    5968        void Load(); 
    6069        void Free(); 
     70 
    6171    private: 
     72        void init(const char * _entry_field, const char * sqlname) 
     73        { 
     74            entry_field = _entry_field; 
     75            table=sqlname; 
     76            data=NULL; 
     77            pIndex=NULL; 
     78            iNumFields = strlen(src_format); 
     79            MaxEntry = 0; 
     80        } 
     81 
    6282        char** pIndex; 
    6383 
    6484        char *data; 
    65         const char *format; 
     85        const char *src_format; 
     86        const char *dst_format; 
    6687        const char *table; 
    6788        const char *entry_field; 
    6889        //bool HasString; 
    6990}; 
     91 
     92template <class T> 
     93struct SQLStorageLoaderBase 
     94{ 
     95    public: 
     96        void Load(SQLStorage &storage); 
     97 
     98        template<class S, class D> 
     99            void convert(uint32 field_pos, S src, D &dst); 
     100        template<class S> 
     101            void convert_to_str(uint32 field_pos, S src, char * & dst); 
     102        template<class D> 
     103            void convert_from_str(uint32 field_pos, char * src, D& dst); 
     104        void convert_str_to_str(uint32 field_pos, char *src, char *&dst); 
     105 
     106    private: 
     107        template<class V> 
     108            void storeValue(V value, SQLStorage &store, char *p, int x, uint32 &offset); 
     109        void storeValue(char * value, SQLStorage &store, char *p, int x, uint32 &offset); 
     110}; 
     111 
     112struct SQLStorageLoader : public SQLStorageLoaderBase<SQLStorageLoader> 
     113{ 
     114}; 
     115 
    70116#endif