1 | /* |
---|
2 | * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> |
---|
3 | * |
---|
4 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
19 | */ |
---|
20 | |
---|
21 | #include "SQLStorage.h" |
---|
22 | #include "SQLStorageImpl.h" |
---|
23 | |
---|
24 | #ifdef DO_POSTGRESQL |
---|
25 | extern DatabasePostgre WorldDatabase; |
---|
26 | #else |
---|
27 | extern DatabaseMysql WorldDatabase; |
---|
28 | #endif |
---|
29 | |
---|
30 | const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis"; |
---|
31 | const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiii"; |
---|
32 | const char CreatureDataAddonInfofmt[]="iiiiiiis"; |
---|
33 | const char CreatureModelfmt[]="iffbi"; |
---|
34 | const char CreatureInfoAddonInfofmt[]="iiiiiiis"; |
---|
35 | const char EquipmentInfofmt[]="iiiiiiiiii"; |
---|
36 | const char GameObjectInfosrcfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis"; |
---|
37 | const char GameObjectInfodstfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiii"; |
---|
38 | const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii"; |
---|
39 | const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiii"; |
---|
40 | const char PageTextfmt[]="isi"; |
---|
41 | const char SpellThreatfmt[]="ii"; |
---|
42 | const char InstanceTemplatesrcfmt[]="iiiiiiffffs"; |
---|
43 | const char InstanceTemplatedstfmt[]="iiiiiiffffi"; |
---|
44 | |
---|
45 | SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template"); |
---|
46 | SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon"); |
---|
47 | SQLStorage sCreatureModelStorage(CreatureModelfmt,"modelid","creature_model_info"); |
---|
48 | SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt,"entry","creature_template_addon"); |
---|
49 | SQLStorage sEquipmentStorage(EquipmentInfofmt,"entry","creature_equip_template"); |
---|
50 | SQLStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry","gameobject_template"); |
---|
51 | SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "entry","item_template"); |
---|
52 | SQLStorage sPageTextStore(PageTextfmt,"entry","page_text"); |
---|
53 | SQLStorage sSpellThreatStore(SpellThreatfmt,"entry","spell_threat"); |
---|
54 | SQLStorage sInstanceTemplate(InstanceTemplatesrcfmt, InstanceTemplatedstfmt, "map","instance_template"); |
---|
55 | |
---|
56 | void SQLStorage::Free () |
---|
57 | { |
---|
58 | uint32 offset=0; |
---|
59 | for(uint32 x=0;x<iNumFields;x++) |
---|
60 | if (dst_format[x]==FT_STRING) |
---|
61 | { |
---|
62 | for(uint32 y=0;y<MaxEntry;y++) |
---|
63 | if(pIndex[y]) |
---|
64 | delete [] *(char**)((char*)(pIndex[y])+offset); |
---|
65 | |
---|
66 | offset += sizeof(char*); |
---|
67 | } |
---|
68 | else if (dst_format[x]==FT_LOGIC) |
---|
69 | offset += sizeof(bool); |
---|
70 | else if (dst_format[x]==FT_BYTE) |
---|
71 | offset += sizeof(char); |
---|
72 | else |
---|
73 | offset += 4; |
---|
74 | |
---|
75 | delete [] pIndex; |
---|
76 | delete [] data; |
---|
77 | } |
---|
78 | |
---|
79 | void SQLStorage::Load() |
---|
80 | { |
---|
81 | SQLStorageLoader loader; |
---|
82 | loader.Load(*this); |
---|
83 | } |
---|