Index: trunk/src/shared/ProgressBar.h
===================================================================
--- trunk/src/shared/ProgressBar.h (revision 272)
+++ trunk/src/shared/ProgressBar.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #ifndef TRINITYCORE_PROGRESSBAR_H
Index: trunk/src/shared/Database/DatabaseMysql.h
===================================================================
--- trunk/src/shared/Database/DatabaseMysql.h (revision 272)
+++ trunk/src/shared/Database/DatabaseMysql.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/SqlOperations.h
===================================================================
--- trunk/src/shared/Database/SqlOperations.h (revision 272)
+++ trunk/src/shared/Database/SqlOperations.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/DatabaseEnv.h
===================================================================
--- trunk/src/shared/Database/DatabaseEnv.h (revision 272)
+++ trunk/src/shared/Database/DatabaseEnv.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/Field.h
===================================================================
--- trunk/src/shared/Database/Field.h (revision 272)
+++ trunk/src/shared/Database/Field.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/DBCStores.cpp
===================================================================
--- trunk/src/shared/Database/DBCStores.cpp (revision 272)
+++ trunk/src/shared/Database/DBCStores.cpp (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
@@ -122,19 +122,7 @@
 // DBC used only for initialization sTaxiPathSetBySource at startup.
 TaxiPathNodesByPath sTaxiPathNodesByPath;
-struct TaxiPathNodeEntry
-{
-    uint32    path;
-    uint32    index;
-    uint32    mapid;
-    float     x;
-    float     y;
-    float     z;
-    uint32    actionFlag;
-    uint32    delay;
-};
+
 static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt);
-
 DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt);
-
 DBCStorage <WorldMapAreaEntry>  sWorldMapAreaStore(WorldMapAreaEntryfmt);
 DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt);
@@ -236,5 +224,5 @@
         }
     }
-    
+
     LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore,     dbcPath,"FactionTemplate.dbc");
     LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore,       dbcPath,"GemProperties.dbc");
@@ -284,5 +272,5 @@
     {
         SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
-    
+
         if(!skillLine)
             continue;
@@ -291,5 +279,5 @@
 
         if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0)
-        {      
+        {
             for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i)
             {
@@ -298,5 +286,5 @@
                     continue;
 
-                if(skillLine->skillId != cFamily->skillLine && skillLine->skillId != cFamily->skillLine2)
+                if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1])
                     continue;
 
@@ -310,5 +298,4 @@
     LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellFocusObjectStore,    dbcPath,"SpellFocusObject.dbc");
     LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentStore,dbcPath,"SpellItemEnchantment.dbc");
-    
     LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellItemEnchantmentConditionStore,dbcPath,"SpellItemEnchantmentCondition.dbc");
     LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRadiusStore,         dbcPath,"SpellRadius.dbc");
@@ -456,9 +443,9 @@
     // check at up-to-date DBC files (71 is last char title added in 2.4.3)
     // check at up-to-date DBC files (1768 is last area added in 2.4.3)
-    if( !sSpellStore.LookupEntry(53085)            || 
-        !sSkillLineAbilityStore.LookupEntry(17514) || 
+    if( !sSpellStore.LookupEntry(53085)            ||
+        !sSkillLineAbilityStore.LookupEntry(17514) ||
         !sMapStore.LookupEntry(598)                ||
-        !sGemPropertiesStore.LookupEntry(1127)     || 
-        !sItemExtendedCostStore.LookupEntry(2425)  || 
+        !sGemPropertiesStore.LookupEntry(1127)     ||
+        !sItemExtendedCostStore.LookupEntry(2425)  ||
         !sCharTitlesStore.LookupEntry(71)          ||
         !sAreaStore.LookupEntry(1768)              )
Index: trunk/src/shared/Database/SQLStorage.h
===================================================================
--- trunk/src/shared/Database/SQLStorage.h (revision 272)
+++ trunk/src/shared/Database/SQLStorage.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
@@ -27,16 +27,24 @@
 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()
         {
@@ -57,14 +65,52 @@
         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
Index: trunk/src/shared/Database/DatabaseMysql.cpp
===================================================================
--- trunk/src/shared/Database/DatabaseMysql.cpp (revision 272)
+++ trunk/src/shared/Database/DatabaseMysql.cpp (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/dbcfile.h
===================================================================
--- trunk/src/shared/Database/dbcfile.h (revision 272)
+++ trunk/src/shared/Database/dbcfile.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/SqlOperations.cpp
===================================================================
--- trunk/src/shared/Database/SqlOperations.cpp (revision 272)
+++ trunk/src/shared/Database/SqlOperations.cpp (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/QueryResult.h
===================================================================
--- trunk/src/shared/Database/QueryResult.h (revision 272)
+++ trunk/src/shared/Database/QueryResult.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/DBCStructure.h
===================================================================
--- trunk/src/shared/Database/DBCStructure.h (revision 272)
+++ trunk/src/shared/Database/DBCStructure.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
@@ -22,4 +22,5 @@
 #define DBCSTRUCTURE_H
 
+#include "DBCEnums.h"
 #include "Platform/Define.h"
 
@@ -36,40 +37,4 @@
 #pragma pack(push,1)
 #endif
-
-enum AreaTeams
-{
-    AREATEAM_NONE  = 0,
-    AREATEAM_ALLY  = 2,
-    AREATEAM_HORDE = 4
-};
-
-enum AreaFlags
-{
-    AREA_FLAG_SNOW             = 0x00000001,                // snow (only Dun Morogh, Naxxramas, Razorfen Downs and Winterspring)
-    AREA_FLAG_UNK1             = 0x00000002,                // unknown, (only Naxxramas and Razorfen Downs)
-    AREA_FLAG_UNK2             = 0x00000004,                // Only used on development map
-    AREA_FLAG_SLAVE_CAPITAL    = 0x00000008,                // slave capital city flag?
-    AREA_FLAG_UNK3             = 0x00000010,                // unknown
-    AREA_FLAG_SLAVE_CAPITAL2   = 0x00000020,                // slave capital city flag?
-    AREA_FLAG_UNK4             = 0x00000040,                // many zones have this flag
-    AREA_FLAG_ARENA            = 0x00000080,                // arena, both instanced and world arenas
-    AREA_FLAG_CAPITAL          = 0x00000100,                // main capital city flag
-    AREA_FLAG_CITY             = 0x00000200,                // only for one zone named "City" (where it located?)
-    AREA_FLAG_OUTLAND          = 0x00000400,                // outland zones? (only Eye of the Storm not have this flag, but have 0x00004000 flag)
-    AREA_FLAG_SANCTUARY        = 0x00000800,                // sanctuary area (PvP disabled)
-    AREA_FLAG_NEED_FLY         = 0x00001000,                // only Netherwing Ledge, Socrethar's Seat, Tempest Keep, The Arcatraz, The Botanica, The Mechanar, Sorrow Wing Point, Dragonspine Ridge, Netherwing Mines, Dragonmaw Base Camp, Dragonmaw Skyway
-    AREA_FLAG_UNUSED1          = 0x00002000,                // not used now (no area/zones with this flag set in 2.4.2)
-    AREA_FLAG_OUTLAND2         = 0x00004000,                // outland zones? (only Circle of Blood Arena not have this flag, but have 0x00000400 flag)
-    AREA_FLAG_PVP              = 0x00008000,                // pvp objective area? (Death's Door also has this flag although it's no pvp object area)
-    AREA_FLAG_ARENA_INSTANCE   = 0x00010000,                // used by instanced arenas only
-    AREA_FLAG_UNUSED2          = 0x00020000,                // not used now (no area/zones with this flag set in 2.4.2)
-    AREA_FLAG_UNK5             = 0x00040000,                // just used for Amani Pass, Hatchet Hills
-    AREA_FLAG_LOWLEVEL         = 0x00100000                 // used for some starting areas with area_level <=15
-};
-
-enum FactionTemplateFlags
-{
-    FACTION_TEMPLATE_FLAG_CONTESTED_GUARD   =   0x00001000, // faction will attack players that were involved in PvP combats
-};
 
 struct AreaTableEntry
@@ -180,5 +145,5 @@
                                                             // 64 string flags, unused
                                                             // 65-67 unused
-    uint32    addon;                                         // 68 (0 - original race, 1 - tbc addon, ...)
+    uint32      addon;                                      // 68 (0 - original race, 1 - tbc addon, ...)
 };
 
@@ -194,10 +159,9 @@
 {
     uint32    ID;                                           // 0
-    float     minScale;                                     // 1  
-    uint32    minScaleLevel;                                // 2 0/1      
+    float     minScale;                                     // 1
+    uint32    minScaleLevel;                                // 2 0/1
     float     maxScale;                                     // 3
     uint32    maxScaleLevel;                                // 4 0/60
-    uint32    skillLine;                                    // 5
-    uint32    skillLine2;                                   // 6
+    uint32    skillLine[2];                                 // 5-6
     uint32    petFoodMask;                                  // 7
     char*     Name[16];                                     // 8-23
@@ -243,13 +207,4 @@
     //char*     description[16];                            // 36-51 unused
                                                             // 52 string flags, unused
-};
-
-enum FactionMasks
-{
-    FACTION_MASK_PLAYER   = 1,                              // any player
-    FACTION_MASK_ALLIANCE = 2,                              // player or creature from alliance team
-    FACTION_MASK_HORDE    = 4,                              // player or creature from horde team
-    FACTION_MASK_MONSTER  = 8                               // aggressive creature from monster team
-                                                            // if none flags set then non-aggressive creature
 };
 
@@ -302,4 +257,5 @@
 
 #define GT_MAX_LEVEL    100
+
 struct GtCombatRatingsEntry
 {
@@ -430,13 +386,4 @@
                                                             // 17 name flags, unused
     //char*       content[16];                              // 18-33
-};
-
-enum MapTypes
-{
-    MAP_COMMON          = 0,
-    MAP_INSTANCE        = 1,
-    MAP_RAID            = 2,
-    MAP_BATTLEGROUND    = 3,
-    MAP_ARENA           = 4
 };
 
@@ -544,10 +491,4 @@
                                                             // 36 string flags, not used
     uint32    spellIcon;                                    // 37
-};
-
-enum AbilytyLearnType
-{
-    ABILITY_LEARNED_ON_GET_PROFESSION_SKILL     = 1,
-    ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL  = 2
 };
 
@@ -759,15 +700,4 @@
 };
 
-enum ItemEnchantmentType
-{
-    ITEM_ENCHANTMENT_TYPE_NONE         = 0,
-    ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL = 1,
-    ITEM_ENCHANTMENT_TYPE_DAMAGE       = 2,
-    ITEM_ENCHANTMENT_TYPE_EQUIP_SPELL  = 3,
-    ITEM_ENCHANTMENT_TYPE_RESISTANCE   = 4,
-    ITEM_ENCHANTMENT_TYPE_STAT         = 5,
-    ITEM_ENCHANTMENT_TYPE_TOTEM        = 6
-};
-
 struct SpellItemEnchantmentEntry
 {
@@ -827,12 +757,4 @@
 };
 
-struct TaxiPathEntry
-{
-    uint32    ID;
-    uint32    from;
-    uint32    to;
-    uint32    price;
-};
-
 struct TaxiNodesEntry
 {
@@ -848,13 +770,22 @@
 };
 
-enum TotemCategoryType
-{
-    TOTEM_CATEGORY_TYPE_KNIFE   = 1,
-    TOTEM_CATEGORY_TYPE_TOTEM   = 2,
-    TOTEM_CATEGORY_TYPE_ROD     = 3,
-    TOTEM_CATEGORY_TYPE_PICK    = 21,
-    TOTEM_CATEGORY_TYPE_STONE   = 22,
-    TOTEM_CATEGORY_TYPE_HAMMER  = 23,
-    TOTEM_CATEGORY_TYPE_SPANNER = 24
+struct TaxiPathEntry
+{
+    uint32    ID;
+    uint32    from;
+    uint32    to;
+    uint32    price;
+};
+
+struct TaxiPathNodeEntry
+{
+    uint32    path;
+    uint32    index;
+    uint32    mapid;
+    float     x;
+    float     y;
+    float     z;
+    uint32    actionFlag;
+    uint32    delay;
 };
 
Index: trunk/src/shared/Database/Field.cpp
===================================================================
--- trunk/src/shared/Database/Field.cpp (revision 272)
+++ trunk/src/shared/Database/Field.cpp (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/SQLStorage.cpp
===================================================================
--- trunk/src/shared/Database/SQLStorage.cpp (revision 272)
+++ trunk/src/shared/Database/SQLStorage.cpp (revision 279)
@@ -11,16 +11,14 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include "SQLStorage.h"
-#include "ProgressBar.h"
-#include "Log.h"
-#include "dbcfile.h"
+#include "SQLStorageImpl.h"
 
 #ifdef DO_POSTGRESQL
@@ -30,25 +28,29 @@
 #endif
 
-const char CreatureInfofmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis";
+const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis";
+const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiii";
 const char CreatureDataAddonInfofmt[]="iiiiiiis";
 const char CreatureModelfmt[]="iffbi";
 const char CreatureInfoAddonInfofmt[]="iiiiiiis";
 const char EquipmentInfofmt[]="iiiiiiiiii";
-const char GameObjectInfofmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis";
-const char ItemPrototypefmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii";
+const char GameObjectInfosrcfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis";
+const char GameObjectInfodstfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiii";
+const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii";
+const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiii";
 const char PageTextfmt[]="isi";
 const char SpellThreatfmt[]="ii";
-const char InstanceTemplatefmt[]="iiiiiiffffs";
+const char InstanceTemplatesrcfmt[]="iiiiiiffffs";
+const char InstanceTemplatedstfmt[]="iiiiiiffffi";
 
-SQLStorage sCreatureStorage(CreatureInfofmt,"entry","creature_template");
+SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template");
 SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon");
 SQLStorage sCreatureModelStorage(CreatureModelfmt,"modelid","creature_model_info");
 SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt,"entry","creature_template_addon");
 SQLStorage sEquipmentStorage(EquipmentInfofmt,"entry","creature_equip_template");
-SQLStorage sGOStorage(GameObjectInfofmt,"entry","gameobject_template");
-SQLStorage sItemStorage(ItemPrototypefmt,"entry","item_template");
+SQLStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry","gameobject_template");
+SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "entry","item_template");
 SQLStorage sPageTextStore(PageTextfmt,"entry","page_text");
 SQLStorage sSpellThreatStore(SpellThreatfmt,"entry","spell_threat");
-SQLStorage sInstanceTemplate(InstanceTemplatefmt,"map","instance_template");
+SQLStorage sInstanceTemplate(InstanceTemplatesrcfmt, InstanceTemplatedstfmt, "map","instance_template");
 
 void SQLStorage::Free ()
@@ -56,5 +58,5 @@
     uint32 offset=0;
     for(uint32 x=0;x<iNumFields;x++)
-        if (format[x]==FT_STRING)
+        if (dst_format[x]==FT_STRING)
         {
             for(uint32 y=0;y<MaxEntry;y++)
@@ -62,12 +64,12 @@
                     delete [] *(char**)((char*)(pIndex[y])+offset);
 
-            offset+=sizeof(char*);
+            offset += sizeof(char*);
         }
-        else if (format[x]==FT_LOGIC)
-            offset+=sizeof(bool);
-        else if (format[x]==FT_BYTE)
-            offset+=sizeof(char);
+        else if (dst_format[x]==FT_LOGIC)
+            offset += sizeof(bool);
+        else if (dst_format[x]==FT_BYTE)
+            offset += sizeof(char);
         else
-            offset+=4;
+            offset += 4;
 
     delete [] pIndex;
@@ -75,119 +77,7 @@
 }
 
-void SQLStorage::Load ()
+void SQLStorage::Load()
 {
-    uint32 maxi;
-    Field *fields;
-    QueryResult *result  = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s",entry_field,table);
-    if(!result)
-    {
-        sLog.outError("Error loading %s table (not exist?)\n",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",table);
-    if(result)
-    {
-        fields = result->Fetch();
-        RecordCount=fields[0].GetUInt32();
-        delete result;
-    }
-    else
-        RecordCount = 0;
-
-    result = WorldDatabase.PQuery("SELECT * FROM %s",table);
-
-    if(!result)
-    {
-        sLog.outError("%s table is empty!\n",table);
-        RecordCount = 0;
-        return;
-    }
-
-    uint32 recordsize=0;
-    uint32 offset=0;
-
-    if(iNumFields!=result->GetFieldCount())
-    {
-        RecordCount = 0;
-        sLog.outError("Error in %s table, probably sql file format was updated (there should be %d fields in sql).\n",table,iNumFields);
-        delete result;
-        exit(1);                                            // Stop server at loading broken or non-compatiable table.
-    }
-
-    //get struct size
-    uint32 sc=0;
-    uint32 bo=0;
-    uint32 bb=0;
-    for(uint32 x=0;x<iNumFields;x++)
-        if(format[x]==FT_STRING)
-            ++sc;
-        else if (format[x]==FT_LOGIC)
-            ++bo;
-        else if (format[x]==FT_BYTE)
-            ++bb;
-    recordsize=(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[RecordCount *recordsize];
-    uint32 count=0;
-    barGoLink bar( RecordCount );
-    do
-    {
-        fields = result->Fetch();
-        bar.step();
-        char *p=(char*)&_data[recordsize*count];
-        newIndex[fields[0].GetUInt32()]=p;
-
-        offset=0;
-        for(uint32 x=0;x<iNumFields;x++)
-            switch(format[x])
-            {
-                case FT_LOGIC:
-                    *((bool*)(&p[offset]))=(fields[x].GetUInt32()>0);
-                    offset+=sizeof(bool);
-                    break;
-                case FT_BYTE:
-                    *((char*)(&p[offset]))=(fields[x].GetUInt8());
-                    offset+=sizeof(char);
-                    break;
-                case FT_INT:
-                    *((uint32*)(&p[offset]))=fields[x].GetUInt32();
-                    offset+=sizeof(uint32);
-                    break;
-                case FT_FLOAT:
-                    *((float*)(&p[offset]))=fields[x].GetFloat();
-                    offset+=sizeof(float);
-                    break;
-                case FT_STRING:
-                    char const* tmp = fields[x].GetString();
-                    char* st;
-                    if(!tmp)
-                    {
-                        st=new char[1];
-                        *st=0;
-                    }
-                    else
-                    {
-                        uint32 l=strlen(tmp)+1;
-                        st=new char[l];
-                        memcpy(st,tmp,l);
-                    }
-                    *((char**)(&p[offset]))=st;
-                    offset+=sizeof(char*);
-                    break;
-            }
-        ++count;
-    }while( result->NextRow() );
-
-    delete result;
-
-    pIndex =newIndex;
-    MaxEntry=maxi;
-    data=_data;
+    SQLStorageLoader loader;
+    loader.Load(*this);
 }
Index: trunk/src/shared/Database/dbcfile.cpp
===================================================================
--- trunk/src/shared/Database/dbcfile.cpp (revision 272)
+++ trunk/src/shared/Database/dbcfile.cpp (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/DatabaseImpl.h
===================================================================
--- trunk/src/shared/Database/DatabaseImpl.h (revision 272)
+++ trunk/src/shared/Database/DatabaseImpl.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
Index: trunk/src/shared/Database/DBCStores.h
===================================================================
--- trunk/src/shared/Database/DBCStores.h (revision 272)
+++ trunk/src/shared/Database/DBCStores.h (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
@@ -76,5 +76,4 @@
         bool Load(char const* fn)
         {
-
             DBCFile dbc;
             // Check if load was sucessful, only then continue
Index: trunk/src/shared/ProgressBar.cpp
===================================================================
--- trunk/src/shared/ProgressBar.cpp (revision 272)
+++ trunk/src/shared/ProgressBar.cpp (revision 279)
@@ -11,10 +11,10 @@
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
