diff options
Diffstat (limited to 'src/shared/Database')
36 files changed, 494 insertions, 1482 deletions
diff --git a/src/shared/Database/CMakeLists.txt b/src/shared/Database/CMakeLists.txt index 78cc48436e7..c8d087b518f 100644 --- a/src/shared/Database/CMakeLists.txt +++ b/src/shared/Database/CMakeLists.txt @@ -1,18 +1,15 @@ SET(trinitydatabase_STAT_SRCS - DBCStores.cpp - DBCStores.h - DBCStructure.h - DBCfmt.cpp + DBCFileLoader.cpp + DBCFileLoader.h + DBCStore.h Database.cpp Database.h - DatabaseEnv.h + DatabaseEnv.h DatabaseImpl.h DatabaseMysql.cpp DatabasePostgre.cpp DatabaseMysql.h DatabasePostgre.h - DatabaseSqlite.cpp - DatabaseSqlite.h Field.cpp Field.h MySQLDelayThread.h @@ -22,16 +19,12 @@ SET(trinitydatabase_STAT_SRCS QueryResultMysql.h QueryResultPostgre.cpp QueryResultPostgre.h - QueryResultSqlite.cpp - QueryResultSqlite.h SQLStorage.cpp SQLStorage.h SqlDelayThread.cpp SqlDelayThread.h SqlOperations.cpp SqlOperations.h - dbcfile.cpp - dbcfile.h ) add_library(trinitydatabase STATIC ${trinitydatabase_STAT_SRCS}) diff --git a/src/shared/Database/dbcfile.cpp b/src/shared/Database/DBCFileLoader.cpp index 9b363dbff8d..23f602f5c93 100644 --- a/src/shared/Database/dbcfile.cpp +++ b/src/shared/Database/DBCFileLoader.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,15 +22,15 @@ #include <stdlib.h> #include <string.h> -#include "dbcfile.h" +#include "DBCFileLoader.h" -DBCFile::DBCFile() +DBCFileLoader::DBCFileLoader() { data = NULL; fieldsOffset = NULL; } -bool DBCFile::Load(const char *filename, const char *fmt) +bool DBCFileLoader::Load(const char *filename, const char *fmt) { uint32 header; @@ -39,23 +39,35 @@ bool DBCFile::Load(const char *filename, const char *fmt) delete [] data; data=NULL; } + FILE * f=fopen(filename,"rb"); if(!f)return false; - fread(&header,4,1,f); // Number of records + if(fread(&header,4,1,f)!=1) // Number of records + return false; + EndianConvert(header); if(header!=0x43424457) - { - //printf("not dbc file"); return false; //'WDBC' - } - fread(&recordCount,4,1,f); // Number of records + + if(fread(&recordCount,4,1,f)!=1) // Number of records + return false; + EndianConvert(recordCount); - fread(&fieldCount,4,1,f); // Number of fields + + if(fread(&fieldCount,4,1,f)!=1) // Number of fields + return false; + EndianConvert(fieldCount); - fread(&recordSize,4,1,f); // Size of a record + + if(fread(&recordSize,4,1,f)!=1) // Size of a record + return false; + EndianConvert(recordSize); - fread(&stringSize,4,1,f); // String size + + if(fread(&stringSize,4,1,f)!=1) // String size + return false; + EndianConvert(stringSize); fieldsOffset = new uint32[fieldCount]; @@ -71,12 +83,15 @@ bool DBCFile::Load(const char *filename, const char *fmt) data = new unsigned char[recordSize*recordCount+stringSize]; stringTable = data + recordSize*recordCount; - fread(data,recordSize*recordCount+stringSize,1,f); + + if(fread(data,recordSize*recordCount+stringSize,1,f)!=1) + return false; + fclose(f); return true; } -DBCFile::~DBCFile() +DBCFileLoader::~DBCFileLoader() { if(data) delete [] data; @@ -84,13 +99,13 @@ DBCFile::~DBCFile() delete [] fieldsOffset; } -DBCFile::Record DBCFile::getRecord(size_t id) +DBCFileLoader::Record DBCFileLoader::getRecord(size_t id) { assert(data); return Record(*this, data + id*recordSize); } -uint32 DBCFile::GetFormatRecordSize(const char * format,int32* index_pos) +uint32 DBCFileLoader::GetFormatRecordSize(const char * format,int32* index_pos) { uint32 recordsize = 0; int32 i = -1; @@ -122,7 +137,7 @@ uint32 DBCFile::GetFormatRecordSize(const char * format,int32* index_pos) return recordsize; } -char* DBCFile::AutoProduceData(const char* format, uint32& records, char**& indexTable) +char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**& indexTable) { /* format STRING, NA, FLOAT,NA,INT <=> @@ -205,7 +220,7 @@ char* DBCFile::AutoProduceData(const char* format, uint32& records, char**& inde return dataTable; } -char* DBCFile::AutoProduceStrings(const char* format, char* dataTable) +char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable) { if(strlen(format)!=fieldCount) return NULL; diff --git a/src/shared/Database/dbcfile.h b/src/shared/Database/DBCFileLoader.h index aa36f6003dc..13562148dfc 100644 --- a/src/shared/Database/dbcfile.h +++ b/src/shared/Database/DBCFileLoader.h @@ -1,7 +1,5 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> - * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,8 +16,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef DBCFILE_H -#define DBCFILE_H +#ifndef DBC_FILE_LOADER_H +#define DBC_FILE_LOADER_H #include "Platform/Define.h" #include "Utilities/ByteConverter.h" #include <cassert> @@ -37,11 +35,11 @@ enum FT_LOGIC='l' //Logical (boolean) }; -class DBCFile +class DBCFileLoader { public: - DBCFile(); - ~DBCFile(); + DBCFileLoader(); + ~DBCFileLoader(); bool Load(const char *filename, const char *fmt); @@ -77,11 +75,11 @@ class DBCFile } private: - Record(DBCFile &file_, unsigned char *offset_): offset(offset_), file(file_) {} + Record(DBCFileLoader &file_, unsigned char *offset_): offset(offset_), file(file_) {} unsigned char *offset; - DBCFile &file; + DBCFileLoader &file; - friend class DBCFile; + friend class DBCFileLoader; }; @@ -107,4 +105,3 @@ class DBCFile unsigned char *stringTable; }; #endif - diff --git a/src/shared/Database/DBCStore.h b/src/shared/Database/DBCStore.h new file mode 100644 index 00000000000..523d5c5a0b3 --- /dev/null +++ b/src/shared/Database/DBCStore.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + * 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 + */ + +#ifndef DBCSTORE_H +#define DBCSTORE_H + +#include "DBCFileLoader.h" + +template<class T> +class DBCStorage +{ + typedef std::list<char*> StringPoolList; + public: + explicit DBCStorage(const char *f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { } + ~DBCStorage() { Clear(); } + + T const* LookupEntry(uint32 id) const { return (id>=nCount)?NULL:indexTable[id]; } + uint32 GetNumRows() const { return nCount; } + char const* GetFormat() const { return fmt; } + uint32 GetFieldCount() const { return fieldCount; } + + bool Load(char const* fn) + { + DBCFileLoader dbc; + // Check if load was sucessful, only then continue + if(!dbc.Load(fn, fmt)) + return false; + + fieldCount = dbc.GetCols(); + m_dataTable = (T*)dbc.AutoProduceData(fmt,nCount,(char**&)indexTable); + m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); + + // error in dbc file at loading if NULL + return indexTable!=NULL; + } + + bool LoadStringsFrom(char const* fn) + { + // DBC must be already loaded using Load + if(!indexTable) + return false; + + DBCFileLoader dbc; + // Check if load was successful, only then continue + if(!dbc.Load(fn, fmt)) + return false; + + m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); + + return true; + } + + void Clear() + { + if (!indexTable) + return; + + delete[] ((char*)indexTable); + indexTable = NULL; + delete[] ((char*)m_dataTable); + m_dataTable = NULL; + + while(!m_stringPoolList.empty()) + { + delete[] m_stringPoolList.front(); + m_stringPoolList.pop_front(); + } + nCount = 0; + } + + private: + uint32 nCount; + uint32 fieldCount; + char const* fmt; + T** indexTable; + T* m_dataTable; + StringPoolList m_stringPoolList; +}; +#endif diff --git a/src/shared/Database/DBCStores.cpp b/src/shared/Database/DBCStores.cpp deleted file mode 100644 index 2031457ceaf..00000000000 --- a/src/shared/Database/DBCStores.cpp +++ /dev/null @@ -1,654 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> - * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - * 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 - */ - -#include "DBCStores.h" -//#include "DataStore.h" -#include "Policies/SingletonImp.h" -#include "Log.h" -#include "ProgressBar.h" - -#include "DBCfmt.cpp" - -#include <map> - -typedef std::map<uint16,uint32> AreaFlagByAreaID; -typedef std::map<uint32,uint32> AreaFlagByMapID; - -DBCStorage <AreaTableEntry> sAreaStore(AreaTableEntryfmt); -static AreaFlagByAreaID sAreaFlagByAreaID; -static AreaFlagByMapID sAreaFlagByMapID; // for instances without generated *.map files - -DBCStorage <AreaTriggerEntry> sAreaTriggerStore(AreaTriggerEntryfmt); -DBCStorage <AuctionHouseEntry> sAuctionHouseStore(AuctionHouseEntryfmt); -DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore(BankBagSlotPricesEntryfmt); -DBCStorage <BattlemasterListEntry> sBattlemasterListStore(BattlemasterListEntryfmt); -DBCStorage <CharStartOutfitEntry> sCharStartOutfitStore(CharStartOutfitEntryfmt); -DBCStorage <CharTitlesEntry> sCharTitlesStore(CharTitlesEntryfmt); -DBCStorage <ChatChannelsEntry> sChatChannelsStore(ChatChannelsEntryfmt); -DBCStorage <ChrClassesEntry> sChrClassesStore(ChrClassesEntryfmt); -DBCStorage <ChrRacesEntry> sChrRacesStore(ChrRacesEntryfmt); -DBCStorage <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore(CreatureDisplayInfofmt); -DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore(CreatureFamilyfmt); -DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore(CreatureSpellDatafmt); - -DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore(DurabilityQualityfmt); -DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore(DurabilityCostsfmt); - -DBCStorage <EmotesTextEntry> sEmotesTextStore(EmoteEntryfmt); - -typedef std::map<uint32,SimpleFactionsList> FactionTeamMap; -static FactionTeamMap sFactionTeamMap; -DBCStorage <FactionEntry> sFactionStore(FactionEntryfmt); -DBCStorage <FactionTemplateEntry> sFactionTemplateStore(FactionTemplateEntryfmt); - -DBCStorage <GemPropertiesEntry> sGemPropertiesStore(GemPropertiesEntryfmt); - -DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore(GtCombatRatingsfmt); -DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt); -DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt); -DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt); -DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore(GtChanceToSpellCritfmt); -DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore(GtOCTRegenHPfmt); -//DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore(GtOCTRegenMPfmt); -- not used currently -DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore(GtRegenHPPerSptfmt); -DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore(GtRegenMPPerSptfmt); -DBCStorage <ItemEntry> sItemStore(Itemfmt); -//DBCStorage <ItemCondExtCostsEntry> sItemCondExtCostsStore(ItemCondExtCostsEntryfmt); -//DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently -DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore(ItemExtendedCostEntryfmt); -DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore(ItemRandomPropertiesfmt); -DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore(ItemRandomSuffixfmt); -DBCStorage <ItemSetEntry> sItemSetStore(ItemSetEntryfmt); - -DBCStorage <LockEntry> sLockStore(LockEntryfmt); - -DBCStorage <MailTemplateEntry> sMailTemplateStore(MailTemplateEntryfmt); -DBCStorage <MapEntry> sMapStore(MapEntryfmt); - -DBCStorage <QuestSortEntry> sQuestSortStore(QuestSortEntryfmt); - -DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore(RandomPropertiesPointsfmt); - -DBCStorage <SkillLineEntry> sSkillLineStore(SkillLinefmt); -DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore(SkillLineAbilityfmt); - -DBCStorage <SoundEntriesEntry> sSoundEntriesStore(SoundEntriesfmt); - -DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore(SpellItemEnchantmentfmt); -DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt); -DBCStorage <SpellEntry> sSpellStore(SpellEntryfmt); -SpellCategoryStore sSpellCategoryStore; -PetFamilySpellsStore sPetFamilySpellsStore; - -DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore(SpellCastTimefmt); -DBCStorage <SpellDurationEntry> sSpellDurationStore(SpellDurationfmt); -DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore(SpellFocusObjectfmt); -DBCStorage <SpellRadiusEntry> sSpellRadiusStore(SpellRadiusfmt); -DBCStorage <SpellRangeEntry> sSpellRangeStore(SpellRangefmt); -DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore(SpellShapeshiftfmt); -DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore(StableSlotPricesfmt); -DBCStorage <TalentEntry> sTalentStore(TalentEntryfmt); -TalentSpellPosMap sTalentSpellPosMap; -DBCStorage <TalentTabEntry> sTalentTabStore(TalentTabEntryfmt); - -// store absolute bit position for first rank for talent inspect -typedef std::map<uint32,uint32> TalentInspectMap; -static TalentInspectMap sTalentPosInInspect; -static TalentInspectMap sTalentTabSizeInInspect; -static uint32 sTalentTabPages[12/*MAX_CLASSES*/][3]; - -DBCStorage <TaxiNodesEntry> sTaxiNodesStore(TaxiNodesEntryfmt); -TaxiMask sTaxiNodesMask; - -// DBC used only for initialization sTaxiPathSetBySource at startup. -TaxiPathSetBySource sTaxiPathSetBySource; -DBCStorage <TaxiPathEntry> sTaxiPathStore(TaxiPathEntryfmt); - -// DBC used only for initialization sTaxiPathSetBySource at startup. -TaxiPathNodesByPath sTaxiPathNodesByPath; - -static DBCStorage <TaxiPathNodeEntry> sTaxiPathNodeStore(TaxiPathNodeEntryfmt); -DBCStorage <TotemCategoryEntry> sTotemCategoryStore(TotemCategoryEntryfmt); -DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore(WorldMapAreaEntryfmt); -DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore(WorldSafeLocsEntryfmt); - -typedef std::list<std::string> StoreProblemList; - -static bool LoadDBC_assert_print(uint32 fsize,uint32 rsize, const std::string& filename) -{ - sLog.outError("ERROR: Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).",filename.c_str(),fsize,rsize); - - // assert must fail after function call - return false; -} - -template<class T> -inline void LoadDBC(uint32& availableDbcLocales,barGoLink& bar, StoreProblemList& errlist, DBCStorage<T>& storage, const std::string& dbc_path, const std::string& filename) -{ - // compatibility format and C++ structure sizes - assert(DBCFile::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFile::GetFormatRecordSize(storage.GetFormat()),sizeof(T),filename)); - - std::string dbc_filename = dbc_path + filename; - if(storage.Load(dbc_filename.c_str())) - { - bar.step(); - for(uint8 i = 0; i < MAX_LOCALE; ++i) - { - if(!(availableDbcLocales & (1 << i))) - continue; - - std::string dbc_filename_loc = dbc_path + localeNames[i] + "/" + filename; - if(!storage.LoadStringsFrom(dbc_filename_loc.c_str())) - availableDbcLocales &= ~(1<<i); // mark as not available for speedup next checks - } - } - else - { - // sort problematic dbc to (1) non compatible and (2) non-existed - FILE * f=fopen(dbc_filename.c_str(),"rb"); - if(f) - { - char buf[100]; - snprintf(buf,100," (exist, but have %d fields instead %d) Wrong client version DBC file?",storage.GetFieldCount(),strlen(storage.GetFormat())); - errlist.push_back(dbc_filename + buf); - fclose(f); - } - else - errlist.push_back(dbc_filename); - } -} - -void LoadDBCStores(const std::string& dataPath) -{ - std::string dbcPath = dataPath+"dbc/"; - - const uint32 DBCFilesCount = 57; - - barGoLink bar( DBCFilesCount ); - - StoreProblemList bad_dbc_files; - uint32 availableDbcLocales = 0xFFFFFFFF; - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaStore, dbcPath,"AreaTable.dbc"); - - // must be after sAreaStore loading - for(uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0 - { - if(AreaTableEntry const* area = sAreaStore.LookupEntry(i)) - { - // fill AreaId->DBC records - sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID),area->exploreFlag)); - - // fill MapId->DBC records ( skip sub zones and continents ) - if(area->zone==0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530 ) - sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid,area->exploreFlag)); - } - } - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAreaTriggerStore, dbcPath,"AreaTrigger.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sAuctionHouseStore, dbcPath,"AuctionHouse.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBankBagSlotPricesStore, dbcPath,"BankBagSlotPrices.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sBattlemasterListStore, dbcPath,"BattlemasterList.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharStartOutfitStore, dbcPath,"CharStartOutfit.dbc"); - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCharTitlesStore, dbcPath,"CharTitles.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChatChannelsStore, dbcPath,"ChatChannels.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrClassesStore, dbcPath,"ChrClasses.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sChrRacesStore, dbcPath,"ChrRaces.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureDisplayInfoStore, dbcPath,"CreatureDisplayInfo.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureFamilyStore, dbcPath,"CreatureFamily.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sCreatureSpellDataStore, dbcPath,"CreatureSpellData.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityCostsStore, dbcPath,"DurabilityCosts.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sDurabilityQualityStore, dbcPath,"DurabilityQuality.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sEmotesTextStore, dbcPath,"EmotesText.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionStore, dbcPath,"Faction.dbc"); - for (uint32 i=0;i<sFactionStore.GetNumRows(); ++i) - { - FactionEntry const * faction = sFactionStore.LookupEntry(i); - if (faction && faction->team) - { - SimpleFactionsList &flist = sFactionTeamMap[faction->team]; - flist.push_back(i); - } - } - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sFactionTemplateStore, dbcPath,"FactionTemplate.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGemPropertiesStore, dbcPath,"GemProperties.dbc"); - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtCombatRatingsStore, dbcPath,"gtCombatRatings.dbc"); - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritBaseStore, dbcPath,"gtChanceToMeleeCritBase.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToMeleeCritStore, dbcPath,"gtChanceToMeleeCrit.dbc"); - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritBaseStore, dbcPath,"gtChanceToSpellCritBase.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtChanceToSpellCritStore, dbcPath,"gtChanceToSpellCrit.dbc"); - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenHPStore, dbcPath,"gtOCTRegenHP.dbc"); - //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenHPPerSptStore, dbcPath,"gtRegenHPPerSpt.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtRegenMPPerSptStore, dbcPath,"gtRegenMPPerSpt.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemStore, dbcPath,"Item.dbc"); - //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently - //LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemExtendedCostStore, dbcPath,"ItemExtendedCost.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomPropertiesStore,dbcPath,"ItemRandomProperties.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemRandomSuffixStore, dbcPath,"ItemRandomSuffix.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemSetStore, dbcPath,"ItemSet.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sLockStore, dbcPath,"Lock.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMailTemplateStore, dbcPath,"MailTemplate.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sMapStore, dbcPath,"Map.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sQuestSortStore, dbcPath,"QuestSort.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sRandomPropertiesPointsStore, dbcPath,"RandPropPoints.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineStore, dbcPath,"SkillLine.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSkillLineAbilityStore, dbcPath,"SkillLineAbility.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSoundEntriesStore, dbcPath,"SoundEntries.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellStore, dbcPath,"Spell.dbc"); - for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i) - { - SpellEntry const * spell = sSpellStore.LookupEntry(i); - if(spell && spell->Category) - sSpellCategoryStore[spell->Category].insert(i); - - // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields - // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view - #if TRINITY_ENDIAN == TRINITY_BIGENDIAN - std::swap(*((uint32*)(&spell->SpellFamilyFlags)),*(((uint32*)(&spell->SpellFamilyFlags))+1)); - #endif - } - - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) - { - SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j); - - if(!skillLine) - continue; - - SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId); - - if(spellInfo && (spellInfo->Attributes & 0x1D0) == 0x1D0) - { - for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i) - { - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i); - if(!cFamily) - continue; - - if(skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1]) - continue; - - sPetFamilySpellsStore[i].insert(spellInfo->Id); - } - } - } - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellCastTimesStore, dbcPath,"SpellCastTimes.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellDurationStore, dbcPath,"SpellDuration.dbc"); - 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"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellRangeStore, dbcPath,"SpellRange.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sSpellShapeshiftStore, dbcPath,"SpellShapeshiftForm.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sStableSlotPricesStore, dbcPath,"StableSlotPrices.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentStore, dbcPath,"Talent.dbc"); - - // create talent spells set - for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i) - { - TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); - if (!talentInfo) continue; - for (int j = 0; j < 5; j++) - if(talentInfo->RankID[j]) - sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i,j); - } - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTalentTabStore, dbcPath,"TalentTab.dbc"); - - // prepare fast data access to bit pos of talent ranks for use at inspecting - { - // fill table by amount of talent ranks and fill sTalentTabBitSizeInInspect - // store in with (row,col,talent)->size key for correct sorting by (row,col) - typedef std::map<uint32,uint32> TalentBitSize; - TalentBitSize sTalentBitSize; - for(uint32 i = 1; i < sTalentStore.GetNumRows(); ++i) - { - TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); - if (!talentInfo) continue; - - TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab ); - if(!talentTabInfo) - continue; - - // find talent rank - uint32 curtalent_maxrank = 0; - for(uint32 k = 5; k > 0; --k) - { - if(talentInfo->RankID[k-1]) - { - curtalent_maxrank = k; - break; - } - } - - sTalentBitSize[(talentInfo->Row<<24) + (talentInfo->Col<<16)+talentInfo->TalentID] = curtalent_maxrank; - sTalentTabSizeInInspect[talentInfo->TalentTab] += curtalent_maxrank; - } - - // now have all max ranks (and then bit amount used for store talent ranks in inspect) - for(uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId) - { - TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentTabId ); - if(!talentTabInfo) - continue; - - // store class talent tab pages - uint32 cls = 1; - for(uint32 m=1;!(m & talentTabInfo->ClassMask) && cls < 12 /*MAX_CLASSES*/;m <<=1, ++cls) {} - - sTalentTabPages[cls][talentTabInfo->tabpage]=talentTabId; - - // add total amount bits for first rank starting from talent tab first talent rank pos. - uint32 pos = 0; - for(TalentBitSize::iterator itr = sTalentBitSize.begin(); itr != sTalentBitSize.end(); ++itr) - { - uint32 talentId = itr->first & 0xFFFF; - TalentEntry const *talentInfo = sTalentStore.LookupEntry( talentId ); - if(!talentInfo) - continue; - - if(talentInfo->TalentTab != talentTabId) - continue; - - sTalentPosInInspect[talentId] = pos; - pos+= itr->second; - } - } - } - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiNodesStore, dbcPath,"TaxiNodes.dbc"); - - // Initialize global taxinodes mask - memset(sTaxiNodesMask,0,sizeof(sTaxiNodesMask)); - for(uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i) - { - if(sTaxiNodesStore.LookupEntry(i)) - { - uint8 field = (uint8)((i - 1) / 32); - uint32 submask = 1<<((i-1)%32); - sTaxiNodesMask[field] |= submask; - } - } - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathStore, dbcPath,"TaxiPath.dbc"); - for(uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i) - if(TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i)) - sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID,entry->price); - uint32 pathCount = sTaxiPathStore.GetNumRows(); - - //## TaxiPathNode.dbc ## Loaded only for initialization different structures - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTaxiPathNodeStore, dbcPath,"TaxiPathNode.dbc"); - // Calculate path nodes count - std::vector<uint32> pathLength; - pathLength.resize(pathCount); // 0 and some other indexes not used - for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i) - if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i)) - ++pathLength[entry->path]; - // Set path length - sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used - for(uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i) - sTaxiPathNodesByPath[i].resize(pathLength[i]); - // fill data - for(uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i) - if(TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i)) - sTaxiPathNodesByPath[entry->path][entry->index] = TaxiPathNode(entry->mapid,entry->x,entry->y,entry->z,entry->actionFlag,entry->delay); - sTaxiPathNodeStore.Clear(); - - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sTotemCategoryStore, dbcPath,"TotemCategory.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapAreaStore, dbcPath,"WorldMapArea.dbc"); - LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldSafeLocsStore, dbcPath,"WorldSafeLocs.dbc"); - - // error checks - if(bad_dbc_files.size() >= DBCFilesCount ) - { - sLog.outError("\nIncorrect DataDir value in Trinityd.conf or ALL required *.dbc files (%d) not found by path: %sdbc",DBCFilesCount,dataPath.c_str()); - exit(1); - } - else if(!bad_dbc_files.empty() ) - { - std::string str; - for(std::list<std::string>::iterator i = bad_dbc_files.begin(); i != bad_dbc_files.end(); ++i) - str += *i + "\n"; - - sLog.outError("\nSome required *.dbc files (%u from %d) not found or not compatible:\n%s",bad_dbc_files.size(),DBCFilesCount,str.c_str()); - exit(1); - } - - // check at up-to-date DBC files (53085 is last added spell in 2.4.3) - // check at up-to-date DBC files (17514 is last ID in SkillLineAbilities in 2.4.3) - // check at up-to-date DBC files (598 is last map added in 2.4.3) - // check at up-to-date DBC files (1127 is last gem property added in 2.4.3) - // check at up-to-date DBC files (2425 is last item extended cost added in 2.4.3) - // 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) || - !sMapStore.LookupEntry(598) || - !sGemPropertiesStore.LookupEntry(1127) || - !sItemExtendedCostStore.LookupEntry(2425) || - !sCharTitlesStore.LookupEntry(71) || - !sAreaStore.LookupEntry(1768) ) - { - sLog.outError("\nYou have _outdated_ DBC files. Please extract correct versions from current using client."); - exit(1); - } - - sLog.outString(); - sLog.outString( ">> Loaded %d data stores", DBCFilesCount ); - sLog.outString(); -} - -SimpleFactionsList const* GetFactionTeamList(uint32 faction) -{ - FactionTeamMap::const_iterator itr = sFactionTeamMap.find(faction); - if(itr==sFactionTeamMap.end()) - return NULL; - return &itr->second; -} - -char* GetPetName(uint32 petfamily, uint32 dbclang) -{ - if(!petfamily) - return NULL; - CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(petfamily); - if(!pet_family) - return NULL; - return pet_family->Name[dbclang]?pet_family->Name[dbclang]:NULL; -} - -TalentSpellPos const* GetTalentSpellPos(uint32 spellId) -{ - TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId); - if(itr==sTalentSpellPosMap.end()) - return NULL; - - return &itr->second; -} - -uint32 GetTalentSpellCost(uint32 spellId) -{ - if(TalentSpellPos const* pos = GetTalentSpellPos(spellId)) - return pos->rank+1; - - return 0; -} - -int32 GetAreaFlagByAreaID(uint32 area_id) -{ - AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id); - if(i == sAreaFlagByAreaID.end()) - return -1; - - return i->second; -} - -AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id) -{ - int32 areaflag = GetAreaFlagByAreaID(area_id); - if(areaflag < 0) - return NULL; - - return sAreaStore.LookupEntry(areaflag ); -} - -AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id) -{ - if(area_flag) - return sAreaStore.LookupEntry(area_flag); - - if(MapEntry const* mapEntry = sMapStore.LookupEntry(map_id)) - return GetAreaEntryByAreaID(mapEntry->linked_zone); - - return NULL; -} - -uint32 GetAreaFlagByMapId(uint32 mapid) -{ - AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid); - if(i == sAreaFlagByMapID.end()) - return 0; - else - return i->second; -} - -uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId) -{ - if(mapid != 530) // speed for most cases - return mapid; - - if(WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId)) - return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id; - - return mapid; -} - -ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId) -{ - mapid = GetVirtualMapForMapAndZone(mapid,zoneId); - if(mapid < 2) - return CONTENT_1_60; - - MapEntry const* mapEntry = sMapStore.LookupEntry(mapid); - if(!mapEntry) - return CONTENT_1_60; - - switch(mapEntry->Expansion()) - { - default: return CONTENT_1_60; - case 1: return CONTENT_61_70; - case 2: return CONTENT_71_80; - } -} - -ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id) -{ - // not sorted, numbering index from 0 - for(uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i) - { - ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(i); - if(ch && ch->ChannelID == channel_id) - return ch; - } - return NULL; -} - -bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId) -{ - if(requiredTotemCategoryId==0) - return true; - if(itemTotemCategoryId==0) - return false; - - TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId); - if(!itemEntry) - return false; - TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId); - if(!reqEntry) - return false; - - if(itemEntry->categoryType!=reqEntry->categoryType) - return false; - - return (itemEntry->categoryMask & reqEntry->categoryMask)==reqEntry->categoryMask; -} - -void Zone2MapCoordinates(float& x,float& y,uint32 zone) -{ - WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone); - - // if not listed then map coordinates (instance) - if(!maEntry) - return; - - std::swap(x,y); // at client map coords swapped - x = x*((maEntry->x2-maEntry->x1)/100)+maEntry->x1; - y = y*((maEntry->y2-maEntry->y1)/100)+maEntry->y1; // client y coord from top to down -} - -void Map2ZoneCoordinates(float& x,float& y,uint32 zone) -{ - WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone); - - // if not listed then map coordinates (instance) - if(!maEntry) - return; - - x = (x-maEntry->x1)/((maEntry->x2-maEntry->x1)/100); - y = (y-maEntry->y1)/((maEntry->y2-maEntry->y1)/100); // client y coord from top to down - std::swap(x,y); // client have map coords swapped -} - -uint32 GetTalentInspectBitPosInTab(uint32 talentId) -{ - TalentInspectMap::const_iterator itr = sTalentPosInInspect.find(talentId); - if(itr == sTalentPosInInspect.end()) - return 0; - - return itr->second; -} - -uint32 GetTalentTabInspectBitSize(uint32 talentTabId) -{ - TalentInspectMap::const_iterator itr = sTalentTabSizeInInspect.find(talentTabId); - if(itr == sTalentTabSizeInInspect.end()) - return 0; - - return itr->second; -} - -uint32 const* GetTalentTabPages(uint32 cls) -{ - return sTalentTabPages[cls]; -} - -// script support functions -TRINITY_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore() { return &sSoundEntriesStore; } -TRINITY_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore() { return &sSpellStore; } -TRINITY_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore() { return &sSpellRangeStore; } - diff --git a/src/shared/Database/DBCStores.h b/src/shared/Database/DBCStores.h deleted file mode 100644 index 4ad275653e7..00000000000 --- a/src/shared/Database/DBCStores.h +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> - * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - * 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 - */ - -#ifndef DBCSTORES_H -#define DBCSTORES_H - -#include "Common.h" -//#include "DataStore.h" -#include "dbcfile.h" -#include "DBCStructure.h" - -#include <list> - -typedef std::list<uint32> SimpleFactionsList; - -SimpleFactionsList const* GetFactionTeamList(uint32 faction); -char* GetPetName(uint32 petfamily, uint32 dbclang); -uint32 GetTalentSpellCost(uint32 spellId); -TalentSpellPos const* GetTalentSpellPos(uint32 spellId); - -int32 GetAreaFlagByAreaID(uint32 area_id); // -1 if not found -AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id); -AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag,uint32 map_id); -uint32 GetAreaFlagByMapId(uint32 mapid); - -uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId); - -enum ContentLevels -{ - CONTENT_1_60 = 0, - CONTENT_61_70, - CONTENT_71_80 -}; -ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId); - -ChatChannelsEntry const* GetChannelEntryFor(uint32 channel_id); - -bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId); - -void Zone2MapCoordinates(float& x,float& y,uint32 zone); -void Map2ZoneCoordinates(float& x,float& y,uint32 zone); - -uint32 GetTalentInspectBitPosInTab(uint32 talentId); -uint32 GetTalentTabInspectBitSize(uint32 talentTabId); -uint32 const* /*[3]*/ GetTalentTabPages(uint32 cls); - -template<class T> -class DBCStorage -{ - typedef std::list<char*> StringPoolList; - public: - explicit DBCStorage(const char *f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { } - ~DBCStorage() { Clear(); } - - T const* LookupEntry(uint32 id) const { return (id>=nCount)?NULL:indexTable[id]; } - uint32 GetNumRows() const { return nCount; } - char const* GetFormat() const { return fmt; } - uint32 GetFieldCount() const { return fieldCount; } - - bool Load(char const* fn) - { - DBCFile dbc; - // Check if load was sucessful, only then continue - if(!dbc.Load(fn, fmt)) - return false; - - fieldCount = dbc.GetCols(); - m_dataTable = (T*)dbc.AutoProduceData(fmt,nCount,(char**&)indexTable); - m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); - - // error in dbc file at loading if NULL - return indexTable!=NULL; - } - - bool LoadStringsFrom(char const* fn) - { - // DBC must be already loaded using Load - if(!indexTable) - return false; - - DBCFile dbc; - // Check if load was successful, only then continue - if(!dbc.Load(fn, fmt)) - return false; - - m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable)); - - return true; - } - - void Clear() - { - if (!indexTable) - return; - - delete[] ((char*)indexTable); - indexTable = NULL; - delete[] ((char*)m_dataTable); - m_dataTable = NULL; - - while(!m_stringPoolList.empty()) - { - delete[] m_stringPoolList.front(); - m_stringPoolList.pop_front(); - } - nCount = 0; - } - - private: - uint32 nCount; - uint32 fieldCount; - char const* fmt; - T** indexTable; - T* m_dataTable; - StringPoolList m_stringPoolList; -}; - -extern DBCStorage <AreaTableEntry> sAreaStore;// recommend access using functions -extern DBCStorage <AreaTriggerEntry> sAreaTriggerStore; -extern DBCStorage <AuctionHouseEntry> sAuctionHouseStore; -extern DBCStorage <BankBagSlotPricesEntry> sBankBagSlotPricesStore; -extern DBCStorage <BattlemasterListEntry> sBattlemasterListStore; -//extern DBCStorage <ChatChannelsEntry> sChatChannelsStore; -- accessed using function, no usable index -extern DBCStorage <CharStartOutfitEntry> sCharStartOutfitStore; -extern DBCStorage <CharTitlesEntry> sCharTitlesStore; -extern DBCStorage <ChrClassesEntry> sChrClassesStore; -extern DBCStorage <ChrRacesEntry> sChrRacesStore; -extern DBCStorage <CreatureDisplayInfoEntry> sCreatureDisplayInfoStore; -extern DBCStorage <CreatureFamilyEntry> sCreatureFamilyStore; -extern DBCStorage <CreatureSpellDataEntry> sCreatureSpellDataStore; -extern DBCStorage <DurabilityCostsEntry> sDurabilityCostsStore; -extern DBCStorage <DurabilityQualityEntry> sDurabilityQualityStore; -extern DBCStorage <EmotesTextEntry> sEmotesTextStore; -extern DBCStorage <FactionEntry> sFactionStore; -extern DBCStorage <FactionTemplateEntry> sFactionTemplateStore; -extern DBCStorage <GemPropertiesEntry> sGemPropertiesStore; - -extern DBCStorage <GtCombatRatingsEntry> sGtCombatRatingsStore; -extern DBCStorage <GtChanceToMeleeCritBaseEntry> sGtChanceToMeleeCritBaseStore; -extern DBCStorage <GtChanceToMeleeCritEntry> sGtChanceToMeleeCritStore; -extern DBCStorage <GtChanceToSpellCritBaseEntry> sGtChanceToSpellCritBaseStore; -extern DBCStorage <GtChanceToSpellCritEntry> sGtChanceToSpellCritStore; -extern DBCStorage <GtOCTRegenHPEntry> sGtOCTRegenHPStore; -//extern DBCStorage <GtOCTRegenMPEntry> sGtOCTRegenMPStore; -- not used currently -extern DBCStorage <GtRegenHPPerSptEntry> sGtRegenHPPerSptStore; -extern DBCStorage <GtRegenMPPerSptEntry> sGtRegenMPPerSptStore; -extern DBCStorage <ItemEntry> sItemStore; -//extern DBCStorage <ItemDisplayInfoEntry> sItemDisplayInfoStore; -- not used currently -extern DBCStorage <ItemExtendedCostEntry> sItemExtendedCostStore; -extern DBCStorage <ItemRandomPropertiesEntry> sItemRandomPropertiesStore; -extern DBCStorage <ItemRandomSuffixEntry> sItemRandomSuffixStore; -extern DBCStorage <ItemSetEntry> sItemSetStore; -extern DBCStorage <LockEntry> sLockStore; -extern DBCStorage <MailTemplateEntry> sMailTemplateStore; -extern DBCStorage <MapEntry> sMapStore; -extern DBCStorage <QuestSortEntry> sQuestSortStore; -extern DBCStorage <RandomPropertiesPointsEntry> sRandomPropertiesPointsStore; -extern DBCStorage <SkillLineEntry> sSkillLineStore; -extern DBCStorage <SkillLineAbilityEntry> sSkillLineAbilityStore; -extern DBCStorage <SoundEntriesEntry> sSoundEntriesStore; -extern DBCStorage <SpellCastTimesEntry> sSpellCastTimesStore; -extern DBCStorage <SpellDurationEntry> sSpellDurationStore; -extern DBCStorage <SpellFocusObjectEntry> sSpellFocusObjectStore; -extern DBCStorage <SpellItemEnchantmentEntry> sSpellItemEnchantmentStore; -extern DBCStorage <SpellItemEnchantmentConditionEntry> sSpellItemEnchantmentConditionStore; -extern SpellCategoryStore sSpellCategoryStore; -extern PetFamilySpellsStore sPetFamilySpellsStore; -extern DBCStorage <SpellRadiusEntry> sSpellRadiusStore; -extern DBCStorage <SpellRangeEntry> sSpellRangeStore; -extern DBCStorage <SpellShapeshiftEntry> sSpellShapeshiftStore; -extern DBCStorage <SpellEntry> sSpellStore; -extern DBCStorage <StableSlotPricesEntry> sStableSlotPricesStore; -extern DBCStorage <TalentEntry> sTalentStore; -extern DBCStorage <TalentTabEntry> sTalentTabStore; -extern DBCStorage <TaxiNodesEntry> sTaxiNodesStore; -extern DBCStorage <TaxiPathEntry> sTaxiPathStore; -extern TaxiMask sTaxiNodesMask; -extern TaxiPathSetBySource sTaxiPathSetBySource; -extern TaxiPathNodesByPath sTaxiPathNodesByPath; -extern DBCStorage <TotemCategoryEntry> sTotemCategoryStore; -//extern DBCStorage <WorldMapAreaEntry> sWorldMapAreaStore; -- use Zone2MapCoordinates and Map2ZoneCoordinates -extern DBCStorage <WorldSafeLocsEntry> sWorldSafeLocsStore; - -void LoadDBCStores(const std::string& dataPath); - -// script support functions -TRINITY_DLL_SPEC DBCStorage <SoundEntriesEntry> const* GetSoundEntriesStore(); -TRINITY_DLL_SPEC DBCStorage <SpellEntry> const* GetSpellStore(); -TRINITY_DLL_SPEC DBCStorage <SpellRangeEntry> const* GetSpellRangeStore(); -#endif - diff --git a/src/shared/Database/DBCfmt.cpp b/src/shared/Database/DBCfmt.cpp deleted file mode 100644 index 14cf6486933..00000000000 --- a/src/shared/Database/DBCfmt.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> - * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - * 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 - */ - -const char AreaTableEntryfmt[]="iiinixxxxxissssssssssssssssxixxxxxx"; -const char AuctionHouseEntryfmt[]="niiixxxxxxxxxxxxxxxxx"; -const char AreaTriggerEntryfmt[]="niffffffff"; -const char BankBagSlotPricesEntryfmt[]="ni"; -const char BattlemasterListEntryfmt[]="niiixxxxxiiiixxssssssssssssssssxx"; -const char CharStartOutfitEntryfmt[]="diiiiiiiiiiiiixxxxxxxxxxxxxxxxxxxxxxxxxxx"; -// 3*12 new item fields in 3.0.x -//const char CharStartOutfitEntryfmt[]="diiiiiiiiiiiiiiiiiiiiiiiiixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; -const char CharTitlesEntryfmt[]="nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxi"; -const char ChatChannelsEntryfmt[]="iixssssssssssssssssxxxxxxxxxxxxxxxxxx"; - // ChatChannelsEntryfmt, index not used (more compact store) -//const char ChrClassesEntryfmt[]="nxixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxix"; -const char ChrClassesEntryfmt[]="nxixssssssssssssssssxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxix"; -const char ChrRacesEntryfmt[]="nxixiixxixxxxissssssssssssssssxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxi"; -const char CreatureDisplayInfofmt[]="nxxxfxxxxxxxxx"; -const char CreatureFamilyfmt[]="nfifiiiissssssssssssssssxx"; -const char CreatureSpellDatafmt[]="nxxxxxxxx"; -const char DurabilityCostsfmt[]="niiiiiiiiiiiiiiiiiiiiiiiiiiiii"; -const char DurabilityQualityfmt[]="nf"; -const char EmoteEntryfmt[]="nxixxxxxxxxxxxxxxxx"; -const char FactionEntryfmt[]="niiiiiiiiiiiiiiiiiissssssssssssssssxxxxxxxxxxxxxxxxxx"; -const char FactionTemplateEntryfmt[]="niiiiiiiiiiiii"; -const char GemPropertiesEntryfmt[]="nixxi"; -const char GtCombatRatingsfmt[]="f"; -const char GtChanceToMeleeCritBasefmt[]="f"; -const char GtChanceToMeleeCritfmt[]="f"; -const char GtChanceToSpellCritBasefmt[]="f"; -const char GtChanceToSpellCritfmt[]="f"; -const char GtOCTRegenHPfmt[]="f"; -//const char GtOCTRegenMPfmt[]="f"; -const char GtRegenHPPerSptfmt[]="f"; -const char GtRegenMPPerSptfmt[]="f"; -const char Itemfmt[]="niii"; -//const char ItemDisplayTemplateEntryfmt[]="nxxxxxxxxxxixxxxxxxxxxx"; -//const char ItemCondExtCostsEntryfmt[]="xiii"; -const char ItemExtendedCostEntryfmt[]="niiiiiiiiiiiii"; -const char ItemRandomPropertiesfmt[]="nxiiixxxxxxxxxxxxxxxxxxx"; -const char ItemRandomSuffixfmt[]="nxxxxxxxxxxxxxxxxxxiiiiii"; -const char ItemSetEntryfmt[]="dssssssssssssssssxxxxxxxxxxxxxxxxxxiiiiiiiiiiiiiiiiii"; -const char LockEntryfmt[]="niiiiixxxiiiiixxxiixxxxxxxxxxxxxx"; -const char MailTemplateEntryfmt[]="nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; -const char MapEntryfmt[]="nxixssssssssssssssssxxxxxxxixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxiffiixxi"; -const char QuestSortEntryfmt[]="nxxxxxxxxxxxxxxxxx"; -const char RandomPropertiesPointsfmt[]="niiiiiiiiiiiiiii"; -const char SkillLinefmt[]="nixssssssssssssssssxxxxxxxxxxxxxxxxxxi"; -const char SkillLineAbilityfmt[]="niiiixxiiiiixxi"; -const char SoundEntriesfmt[]="nxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; -const char SpellCastTimefmt[]="nixx"; -const char SpellDurationfmt[]="niii"; -const char SpellEntryfmt[]="nixiiiiiiiixiiiiiiiiiiiiiiiiiiiiiiiiiiiiifxiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffffffiiiiiiiiiiiiiiiiiiiiifffiiiiiiiiiiiiiiifffixiixssssssssssssssssxssssssssssssssssxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxiiiiiiiiiixfffxxxiiii"; -const char SpellFocusObjectfmt[]="nxxxxxxxxxxxxxxxxx"; -const char SpellItemEnchantmentfmt[]="niiiiiixxxiiissssssssssssssssxiiii"; -const char SpellItemEnchantmentConditionfmt[]="nbbbbbxxxxxbbbbbbbbbbiiiiiXXXXX"; -const char SpellRadiusfmt[]="nfxf"; -const char SpellRangefmt[]="nffixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; -const char SpellShapeshiftfmt[]="nxxxxxxxxxxxxxxxxxxiixixxxxxxxxxxxx"; -const char StableSlotPricesfmt[] = "ni"; -const char TalentEntryfmt[]="niiiiiiiixxxxixxixxxi"; -const char TalentTabEntryfmt[]="nxxxxxxxxxxxxxxxxxxxiix"; -const char TaxiNodesEntryfmt[]="nifffxxxxxxxxxxxxxxxxxii"; -const char TaxiPathEntryfmt[]="niii"; -const char TaxiPathNodeEntryfmt[]="diiifffiixx"; -const char TotemCategoryEntryfmt[]="nxxxxxxxxxxxxxxxxxii"; -const char WorldMapAreaEntryfmt[]="xinxffffi"; -const char WorldSafeLocsEntryfmt[]="nifffxxxxxxxxxxxxxxxxx"; - diff --git a/src/shared/Database/Database.cpp b/src/shared/Database/Database.cpp index 7110fe44c54..651ea7f41fb 100644 --- a/src/shared/Database/Database.cpp +++ b/src/shared/Database/Database.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -110,7 +110,8 @@ bool Database::PExecuteLog(const char * format,...) void Database::SetResultQueue(SqlResultQueue * queue) { - m_queryQueues[ZThread::ThreadImpl::current()] = queue; + m_queryQueues[ACE_Based::Thread::current()] = queue; + } QueryResult* Database::PQuery(const char *format,...) @@ -132,6 +133,25 @@ QueryResult* Database::PQuery(const char *format,...) return Query(szQuery); } +QueryNamedResult* Database::PQueryNamed(const char *format,...) +{ + if(!format) return NULL; + + va_list ap; + char szQuery [MAX_QUERY_LEN]; + va_start(ap, format); + int res = vsnprintf( szQuery, MAX_QUERY_LEN, format, ap ); + va_end(ap); + + if(res==-1) + { + sLog.outError("SQL Query truncated (and not execute) for format: %s",format); + return false; + } + + return QueryNamed(szQuery); +} + bool Database::PExecute(const char * format,...) { if (!format) diff --git a/src/shared/Database/Database.h b/src/shared/Database/Database.h index c2ee9349979..7f2bdaefdb7 100644 --- a/src/shared/Database/Database.h +++ b/src/shared/Database/Database.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,8 +21,7 @@ #ifndef DATABASE_H #define DATABASE_H -#include "zthread/Thread.h" -#include "../src/zthread/ThreadImpl.h" +#include "Threading.h" #include "Utilities/UnorderedMap.h" #include "Database/SqlDelayThread.h" @@ -30,10 +29,10 @@ class SqlTransaction; class SqlResultQueue; class SqlQueryHolder; -typedef UNORDERED_MAP<ZThread::ThreadImpl*, SqlTransaction*> TransactionQueues; -typedef UNORDERED_MAP<ZThread::ThreadImpl*, SqlResultQueue*> QueryQueues; +typedef UNORDERED_MAP<ACE_Based::Thread* , SqlTransaction*> TransactionQueues; +typedef UNORDERED_MAP<ACE_Based::Thread* , SqlResultQueue*> QueryQueues; -#define MAX_QUERY_LEN 1024 +#define MAX_QUERY_LEN 32*1024 class TRINITY_DLL_SPEC Database { @@ -43,7 +42,7 @@ class TRINITY_DLL_SPEC Database TransactionQueues m_tranQueues; ///< Transaction queues from diff. threads QueryQueues m_queryQueues; ///< Query queues from diff threads SqlDelayThread* m_threadBody; ///< Pointer to delay sql executer - ZThread::Thread* m_delayThread; ///< Pointer to executer thread + ACE_Based::Thread* m_delayThread; ///< Pointer to executer thread public: @@ -55,6 +54,8 @@ class TRINITY_DLL_SPEC Database virtual QueryResult* Query(const char *sql) = 0; QueryResult* PQuery(const char *format,...) ATTR_PRINTF(2,3); + virtual QueryNamedResult* QueryNamed(const char *sql) = 0; + QueryNamedResult* PQueryNamed(const char *format,...) ATTR_PRINTF(2,3); /// Async queries and query holders, implemented in DatabaseImpl.h @@ -80,16 +81,16 @@ class TRINITY_DLL_SPEC Database template<class Class, typename ParamType1> bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6); template<class Class, typename ParamType1, typename ParamType2> - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6); + bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(6,7); template<class Class, typename ParamType1, typename ParamType2, typename ParamType3> - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(5,6); + bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(7,8); // PQuery / static template<typename ParamType1> - bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6); + bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(4,5); template<typename ParamType1, typename ParamType2> bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6); template<typename ParamType1, typename ParamType2, typename ParamType3> - bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(5,6); + bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(6,7); template<class Class> // QueryHolder bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder); diff --git a/src/shared/Database/DatabaseEnv.h b/src/shared/Database/DatabaseEnv.h index 664459473af..1d3d735881c 100644 --- a/src/shared/Database/DatabaseEnv.h +++ b/src/shared/Database/DatabaseEnv.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,6 @@ #include "Log.h" #include "Errors.h" -#include "Database/DBCStores.h" #include "Database/Field.h" #include "Database/QueryResult.h" @@ -40,10 +39,8 @@ typedef DatabasePostgre DatabaseType; #define _OFFSET_ "LIMIT 1 OFFSET %d" #else #include "Database/QueryResultMysql.h" -#include "Database/QueryResultSqlite.h" #include "Database/Database.h" #include "Database/DatabaseMysql.h" -#include "Database/DatabaseSqlite.h" typedef DatabaseMysql DatabaseType; #define _LIKE_ "LIKE" #define _TABLE_SIM_ "`" diff --git a/src/shared/Database/DatabaseImpl.h b/src/shared/Database/DatabaseImpl.h index 5ab4ec04a65..7cbd0ed8ba5 100644 --- a/src/shared/Database/DatabaseImpl.h +++ b/src/shared/Database/DatabaseImpl.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ QueryQueues::iterator queue_itr; \ \ { \ - ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); \ + ACE_Based::Thread * queryThread = ACE_Based::Thread::current(); \ queue_itr = m_queryQueues.find(queryThread); \ if (queue_itr == m_queryQueues.end()) return false; \ } @@ -59,7 +59,7 @@ QueryQueues::iterator queue_itr; \ \ { \ - ZThread::ThreadImpl * queryThread = ZThread::ThreadImpl::current(); \ + ACE_Based::Thread * queryThread = ACE_Based::Thread::current(); \ queue_itr = m_queryQueues.find(queryThread); \ if (queue_itr == m_queryQueues.end()) return false; \ } diff --git a/src/shared/Database/DatabaseMysql.cpp b/src/shared/Database/DatabaseMysql.cpp index 77a59a69c57..0189b5883f7 100644 --- a/src/shared/Database/DatabaseMysql.cpp +++ b/src/shared/Database/DatabaseMysql.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ #include "Util.h" #include "Policies/SingletonImp.h" #include "Platform/Define.h" -#include "../src/zthread/ThreadImpl.h" +#include "Threading.h" #include "DatabaseEnv.h" #include "Database/MySQLDelayThread.h" #include "Database/SqlOperations.h" @@ -192,26 +192,22 @@ bool DatabaseMysql::Initialize(const char *infoString) } } -QueryResult* DatabaseMysql::Query(const char *sql) +bool DatabaseMysql::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount) { if (!mMysql) return 0; - MYSQL_RES *result = 0; - uint64 rowCount = 0; - uint32 fieldCount = 0; - { // guarded block for thread-safe mySQL request - ZThread::Guard<ZThread::FastMutex> query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex); + #ifdef MANGOS_DEBUG uint32 _s = getMSTime(); #endif if(mysql_query(mMysql, sql)) { sLog.outErrorDb( "SQL: %s", sql ); sLog.outErrorDb("query ERROR: %s", mysql_error(mMysql)); - return NULL; + return false; } else { @@ -220,29 +216,63 @@ QueryResult* DatabaseMysql::Query(const char *sql) #endif } - result = mysql_store_result(mMysql); - - rowCount = mysql_affected_rows(mMysql); - fieldCount = mysql_field_count(mMysql); + *pResult = mysql_store_result(mMysql); + *pRowCount = mysql_affected_rows(mMysql); + *pFieldCount = mysql_field_count(mMysql); // end guarded block } - if (!result ) - return NULL; + if (!*pResult ) + return false; - if (!rowCount) + if (!*pRowCount) { - mysql_free_result(result); - return NULL; + mysql_free_result(*pResult); + return false; } - QueryResultMysql *queryResult = new QueryResultMysql(result, rowCount, fieldCount); + *pFields = mysql_fetch_fields(*pResult); + return true; +} + +QueryResult* DatabaseMysql::Query(const char *sql) +{ + MYSQL_RES *result = NULL; + MYSQL_FIELD *fields = NULL; + uint64 rowCount = 0; + uint32 fieldCount = 0; + + if(!_Query(sql,&result,&fields,&rowCount,&fieldCount)) + return NULL; + + QueryResultMysql *queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount); queryResult->NextRow(); return queryResult; } +QueryNamedResult* DatabaseMysql::QueryNamed(const char *sql) +{ + MYSQL_RES *result = NULL; + MYSQL_FIELD *fields = NULL; + uint64 rowCount = 0; + uint32 fieldCount = 0; + + if(!_Query(sql,&result,&fields,&rowCount,&fieldCount)) + return NULL; + + QueryFieldNames names(fieldCount); + for (uint32 i = 0; i < fieldCount; i++) + names[i] = fields[i].name; + + QueryResultMysql *queryResult = new QueryResultMysql(result, fields, rowCount, fieldCount); + + queryResult->NextRow(); + + return new QueryNamedResult(queryResult,names); +} + bool DatabaseMysql::Execute(const char *sql) { if (!mMysql) @@ -251,7 +281,7 @@ bool DatabaseMysql::Execute(const char *sql) // don't use queued execution if it has not been initialized if (!m_threadBody) return DirectExecute(sql); - tranThread = ZThread::ThreadImpl::current(); // owner of this transaction + tranThread = ACE_Based::Thread::current(); // owner of this transaction TransactionQueues::iterator i = m_tranQueues.find(tranThread); if (i != m_tranQueues.end() && i->second != NULL) { // Statement for transaction @@ -273,8 +303,9 @@ bool DatabaseMysql::DirectExecute(const char* sql) { // guarded block for thread-safe mySQL request - ZThread::Guard<ZThread::FastMutex> query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex); + + #ifdef MANGOS_DEBUG uint32 _s = getMSTime(); #endif if(mysql_query(mMysql, sql)) @@ -318,8 +349,9 @@ bool DatabaseMysql::BeginTransaction() // don't use queued execution if it has not been initialized if (!m_threadBody) { - if (tranThread==ZThread::ThreadImpl::current()) + if (tranThread == ACE_Based::Thread::current()) return false; // huh? this thread already started transaction + mMutex.acquire(); if (!_TransactionCmd("START TRANSACTION")) { @@ -329,7 +361,7 @@ bool DatabaseMysql::BeginTransaction() return true; // transaction started } - tranThread = ZThread::ThreadImpl::current(); // owner of this transaction + tranThread = ACE_Based::Thread::current(); // owner of this transaction TransactionQueues::iterator i = m_tranQueues.find(tranThread); if (i != m_tranQueues.end() && i->second != NULL) // If for thread exists queue and also contains transaction @@ -349,7 +381,7 @@ bool DatabaseMysql::CommitTransaction() // don't use queued execution if it has not been initialized if (!m_threadBody) { - if (tranThread!=ZThread::ThreadImpl::current()) + if (tranThread != ACE_Based::Thread::current()) return false; bool _res = _TransactionCmd("COMMIT"); tranThread = NULL; @@ -357,7 +389,7 @@ bool DatabaseMysql::CommitTransaction() return _res; } - tranThread = ZThread::ThreadImpl::current(); + tranThread = ACE_Based::Thread::current(); TransactionQueues::iterator i = m_tranQueues.find(tranThread); if (i != m_tranQueues.end() && i->second != NULL) { @@ -377,7 +409,7 @@ bool DatabaseMysql::RollbackTransaction() // don't use queued execution if it has not been initialized if (!m_threadBody) { - if (tranThread!=ZThread::ThreadImpl::current()) + if (tranThread != ACE_Based::Thread::current()) return false; bool _res = _TransactionCmd("ROLLBACK"); tranThread = NULL; @@ -385,7 +417,7 @@ bool DatabaseMysql::RollbackTransaction() return _res; } - tranThread = ZThread::ThreadImpl::current(); + tranThread = ACE_Based::Thread::current(); TransactionQueues::iterator i = m_tranQueues.find(tranThread); if (i != m_tranQueues.end() && i->second != NULL) { @@ -408,7 +440,8 @@ void DatabaseMysql::InitDelayThread() assert(!m_delayThread); //New delay thread for delay execute - m_delayThread = new ZThread::Thread(m_threadBody = new MySQLDelayThread(this)); + m_threadBody = new MySQLDelayThread(this); + m_delayThread = new ACE_Based::Thread(*m_threadBody); } void DatabaseMysql::HaltDelayThread() diff --git a/src/shared/Database/DatabaseMysql.h b/src/shared/Database/DatabaseMysql.h index 1826a08f2aa..4612ebfc462 100644 --- a/src/shared/Database/DatabaseMysql.h +++ b/src/shared/Database/DatabaseMysql.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,8 @@ #include "Database.h" #include "Policies/Singleton.h" -#include "zthread/FastMutex.h" +#include "ace/Thread_Mutex.h" +#include "ace/Guard_T.h" #ifdef WIN32 #define FD_SETSIZE 1024 @@ -49,6 +50,7 @@ class TRINITY_DLL_SPEC DatabaseMysql : public Database void InitDelayThread(); void HaltDelayThread(); QueryResult* Query(const char *sql); + QueryNamedResult* QueryNamed(const char *sql); bool Execute(const char *sql); bool DirectExecute(const char* sql); bool BeginTransaction(); @@ -65,15 +67,16 @@ class TRINITY_DLL_SPEC DatabaseMysql : public Database // must be call before finish thread run void ThreadEnd(); private: - ZThread::FastMutex mMutex; + ACE_Thread_Mutex mMutex; - ZThread::ThreadImpl* tranThread; + ACE_Based::Thread * tranThread; MYSQL *mMysql; static size_t db_count; bool _TransactionCmd(const char *sql); + bool _Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount); }; #endif #endif diff --git a/src/shared/Database/DatabasePostgre.cpp b/src/shared/Database/DatabasePostgre.cpp index 25b5a58b863..c70067dfdba 100644 --- a/src/shared/Database/DatabasePostgre.cpp +++ b/src/shared/Database/DatabasePostgre.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ #include "Util.h" #include "Policies/SingletonImp.h" #include "Platform/Define.h" -#include "../src/zthread/ThreadImpl.h" +#include "Threading.h" #include "DatabaseEnv.h" #include "Database/PGSQLDelayThread.h" #include "Database/SqlOperations.h" @@ -79,14 +79,14 @@ bool DatabasePostgre::Initialize(const char *infoString) Tokens::iterator iter; - std::string host, port_or_socket, user, password, database; + std::string host, port_or_socket_dir, user, password, database; iter = tokens.begin(); if(iter != tokens.end()) host = *iter++; if(iter != tokens.end()) - port_or_socket = *iter++; + port_or_socket_dir = *iter++; if(iter != tokens.end()) user = *iter++; if(iter != tokens.end()) @@ -94,7 +94,10 @@ bool DatabasePostgre::Initialize(const char *infoString) if(iter != tokens.end()) database = *iter++; - mPGconn = PQsetdbLogin(host.c_str(), port_or_socket.c_str(), NULL, NULL, database.c_str(), user.c_str(), password.c_str()); + if (host == ".") + mPGconn = PQsetdbLogin(NULL, port_or_socket_dir == "." ? NULL : port_or_socket_dir.c_str(), NULL, NULL, database.c_str(), user.c_str(), password.c_str()); + else + mPGconn = PQsetdbLogin(host.c_str(), port_or_socket_dir.c_str(), NULL, NULL, database.c_str(), user.c_str(), password.c_str()); /* check to see that the backend connection was successfully made */ if (PQstatus(mPGconn) != CONNECTION_OK) @@ -114,32 +117,27 @@ bool DatabasePostgre::Initialize(const char *infoString) } -QueryResult* DatabasePostgre::Query(const char *sql) +bool DatabasePostgre::_Query(const char *sql, PGresult** pResult, uint64* pRowCount, uint32* pFieldCount) { if (!mPGconn) return 0; - uint64 rowCount = 0; - uint32 fieldCount = 0; - // guarded block for thread-safe request - ZThread::Guard<ZThread::FastMutex> query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex); + #ifdef MANGOS_DEBUG uint32 _s = getMSTime(); #endif // Send the query - PGresult * result = PQexec(mPGconn, sql); - if (!result ) - { - return NULL; - } + *pResult = PQexec(mPGconn, sql); + if(!*pResult ) + return false; - if (PQresultStatus(result) != PGRES_TUPLES_OK) + if (PQresultStatus(*pResult) != PGRES_TUPLES_OK) { sLog.outErrorDb( "SQL : %s", sql ); sLog.outErrorDb( "SQL %s", PQerrorMessage(mPGconn)); - PQclear(result); - return NULL; + PQclear(*pResult); + return false; } else { @@ -148,15 +146,29 @@ QueryResult* DatabasePostgre::Query(const char *sql) #endif } - rowCount = PQntuples(result); - fieldCount = PQnfields(result); + *pRowCount = PQntuples(*pResult); + *pFieldCount = PQnfields(*pResult); // end guarded block - if (!rowCount) + if (!*pRowCount) { - PQclear(result); - return NULL; + PQclear(*pResult); + return false; } + return true; +} + +QueryResult* DatabasePostgre::Query(const char *sql) +{ + if (!mPGconn) + return 0; + + PGresult* result = NULL; + uint64 rowCount = 0; + uint32 fieldCount = 0; + + if(!_Query(sql,&result,&rowCount,&fieldCount)) + return NULL; QueryResultPostgre * queryResult = new QueryResultPostgre(result, rowCount, fieldCount); queryResult->NextRow(); @@ -164,6 +176,28 @@ QueryResult* DatabasePostgre::Query(const char *sql) return queryResult; } +QueryNamedResult* DatabasePostgre::QueryNamed(const char *sql) +{ + if (!mPGconn) + return 0; + + PGresult* result = NULL; + uint64 rowCount = 0; + uint32 fieldCount = 0; + + if(!_Query(sql,&result,&rowCount,&fieldCount)) + return NULL; + + QueryFieldNames names(fieldCount); + for (uint32 i = 0; i < fieldCount; i++) + names[i] = PQfname(result, i); + + QueryResultPostgre * queryResult = new QueryResultPostgre(result, rowCount, fieldCount); + queryResult->NextRow(); + + return new QueryNamedResult(queryResult,names); +} + bool DatabasePostgre::Execute(const char *sql) { @@ -171,9 +205,10 @@ bool DatabasePostgre::Execute(const char *sql) return false; // don't use queued execution if it has not been initialized - if (!m_threadBody) return DirectExecute(sql); + if (!m_threadBody) + return DirectExecute(sql); - tranThread = ZThread::ThreadImpl::current(); // owner of this transaction + tranThread = ACE_Based::Thread::current(); // owner of this transaction TransactionQueues::iterator i = m_tranQueues.find(tranThread); if (i != m_tranQueues.end() && i->second != NULL) { // Statement for transaction @@ -194,8 +229,8 @@ bool DatabasePostgre::DirectExecute(const char* sql) return false; { // guarded block for thread-safe request - ZThread::Guard<ZThread::FastMutex> query_connection_guard(mMutex); - #ifdef TRINITY_DEBUG + ACE_Guard<ACE_Thread_Mutex> query_connection_guard(mMutex); + #ifdef MANGOS_DEBUG uint32 _s = getMSTime(); #endif PGresult *res = PQexec(mPGconn, sql); @@ -244,7 +279,7 @@ bool DatabasePostgre::BeginTransaction() // don't use queued execution if it has not been initialized if (!m_threadBody) { - if (tranThread==ZThread::ThreadImpl::current()) + if (tranThread == ACE_Based::Thread::current()) return false; // huh? this thread already started transaction mMutex.acquire(); if (!_TransactionCmd("START TRANSACTION")) @@ -255,7 +290,7 @@ bool DatabasePostgre::BeginTransaction() return true; } // transaction started - tranThread = ZThread::ThreadImpl::current(); // owner of this transaction + tranThread = ACE_Based::Thread::current(); // owner of this transaction TransactionQueues::iterator i = m_tranQueues.find(tranThread); if (i != m_tranQueues.end() && i->second != NULL) // If for thread exists queue and also contains transaction @@ -275,14 +310,14 @@ bool DatabasePostgre::CommitTransaction() // don't use queued execution if it has not been initialized if (!m_threadBody) { - if (tranThread!=ZThread::ThreadImpl::current()) + if (tranThread != ACE_Based::Thread::current()) return false; bool _res = _TransactionCmd("COMMIT"); tranThread = NULL; mMutex.release(); return _res; } - tranThread = ZThread::ThreadImpl::current(); + tranThread = ACE_Based::Thread::current(); TransactionQueues::iterator i = m_tranQueues.find(tranThread); if (i != m_tranQueues.end() && i->second != NULL) { @@ -301,14 +336,14 @@ bool DatabasePostgre::RollbackTransaction() // don't use queued execution if it has not been initialized if (!m_threadBody) { - if (tranThread!=ZThread::ThreadImpl::current()) + if (tranThread != ACE_Based::Thread::current()) return false; bool _res = _TransactionCmd("ROLLBACK"); tranThread = NULL; mMutex.release(); return _res; } - tranThread = ZThread::ThreadImpl::current(); + tranThread = ACE_Based::Thread::current(); TransactionQueues::iterator i = m_tranQueues.find(tranThread); if (i != m_tranQueues.end() && i->second != NULL) { @@ -331,7 +366,8 @@ void DatabasePostgre::InitDelayThread() assert(!m_delayThread); //New delay thread for delay execute - m_delayThread = new ZThread::Thread(m_threadBody = new PGSQLDelayThread(this)); + m_threadBody = new PGSQLDelayThread(this); + m_delayThread = new ACE_Based::Thread(*m_threadBody); } void DatabasePostgre::HaltDelayThread() diff --git a/src/shared/Database/DatabasePostgre.h b/src/shared/Database/DatabasePostgre.h index 6dc0c509869..92a8dff045a 100644 --- a/src/shared/Database/DatabasePostgre.h +++ b/src/shared/Database/DatabasePostgre.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,7 +22,6 @@ #define _DatabasePostgre_H #include "Policies/Singleton.h" -#include "zthread/FastMutex.h" #include <stdarg.h> #ifdef WIN32 @@ -47,6 +46,7 @@ class DatabasePostgre : public Database void InitDelayThread(); void HaltDelayThread(); QueryResult* Query(const char *sql); + QueryNamedResult* QueryNamed(const char *sql); bool Execute(const char *sql); bool DirectExecute(const char* sql); bool BeginTransaction(); @@ -63,16 +63,15 @@ class DatabasePostgre : public Database // must be call before finish thread run void ThreadEnd(); private: - ZThread::FastMutex mMutex; - ZThread::FastMutex tranMutex; - - ZThread::ThreadImpl* tranThread; + ACE_Thread_Mutex mMutex; + ACE_Based::Thread * tranThread; PGconn *mPGconn; static size_t db_count; bool _TransactionCmd(const char *sql); + bool _Query(const char *sql, PGresult **pResult, uint64* pRowCount, uint32* pFieldCount); }; #endif diff --git a/src/shared/Database/DatabaseSqlite.cpp b/src/shared/Database/DatabaseSqlite.cpp deleted file mode 100644 index a7a4a2a9847..00000000000 --- a/src/shared/Database/DatabaseSqlite.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> - * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - * 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 - */ - -#ifndef DO_POSTGRESQL - -#include "DatabaseEnv.h" - -DatabaseSqlite::DatabaseSqlite() : Database(), mSqlite(0) -{ -} - -DatabaseSqlite::~DatabaseSqlite() -{ - if (mSqlite) - sqlite_close(mSqlite); -} - -bool DatabaseSqlite::Initialize(const char *infoString) -{ - if(!Database::Initialize(infoString)) - return false; - - char *errmsg; - - mSqlite = sqlite_open(infoString, 0, &errmsg); - - if (!mSqlite) - { - - if (errmsg) - sqlite_freemem(errmsg); - return false; - } - - return true; -} - -QueryResult* DatabaseSqlite::Query(const char *sql) -{ - char *errmsg; - - if (!mSqlite) - return 0; - - char **tableData; - int rowCount; - int fieldCount; - - sqlite_get_table(mSqlite, sql, &tableData, &rowCount, &fieldCount, &errmsg); - - if (!rowCount) - return 0; - - if (!tableData) - { - - if (errmsg) - sqlite_freemem(errmsg); - return 0; - } - - QueryResultSqlite *queryResult = new QueryResultSqlite(tableData, rowCount, fieldCount); - if(!queryResult) - { - - return 0; - } - - queryResult->NextRow(); - - return queryResult; -} - -bool DatabaseSqlite::Execute(const char *sql) -{ - char *errmsg; - - if (!mSqlite) - return false; - - if(sqlite_exec(mSqlite, sql, NULL, NULL, &errmsg) != SQLITE_OK) - return false; - - return true; -} -#endif - diff --git a/src/shared/Database/DatabaseSqlite.h b/src/shared/Database/DatabaseSqlite.h deleted file mode 100644 index 32d49d0124b..00000000000 --- a/src/shared/Database/DatabaseSqlite.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> - * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - * 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 - */ - -#ifndef DO_POSTGRESQL - -#ifndef _DATABASESQLITE_H -#define _DATABASESQLITE_H - -#include <sqlite/sqlite.h> - -class DatabaseSqlite : public Database -{ - public: - DatabaseSqlite(); - ~DatabaseSqlite(); - - bool Initialize(const char *infoString); - - QueryResult* Query(const char *sql); - bool Execute(const char *sql); - - operator bool () const { return mSqlite != NULL; } - - private: - sqlite *mSqlite; -}; -#endif -#endif - diff --git a/src/shared/Database/Field.cpp b/src/shared/Database/Field.cpp index a7817d9a630..9a1fbfa5178 100644 --- a/src/shared/Database/Field.cpp +++ b/src/shared/Database/Field.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/shared/Database/Field.h b/src/shared/Database/Field.h index 3e5f26376bb..f365a96df64 100644 --- a/src/shared/Database/Field.h +++ b/src/shared/Database/Field.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,7 +59,7 @@ class Field if(mValue) { uint64 value; - sscanf(mValue,I64FMTD,&value); + sscanf(mValue,UI64FMTD,&value); return value; } else diff --git a/src/shared/Database/Makefile.am b/src/shared/Database/Makefile.am new file mode 100644 index 00000000000..518ea4c98a3 --- /dev/null +++ b/src/shared/Database/Makefile.am @@ -0,0 +1,59 @@ +# Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> +# +# Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# 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 +# 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 + +## Process this file with automake to produce Makefile.in + +## Sub-directories to parse + +## CPP flags for includes, defines, etc. +AM_CPPFLAGS = $(TRINI_INCLUDES) -I$(top_builddir)/src/shared -I$(srcdir) -I$(srcdir)/../../../dep/include -I$(srcdir)/../../framework -I$(srcdir)/../../shared -I$(srcdir)/../../../dep/include/g3dlite + +## Build MaNGOS shared library and its parts as convenience library. +# All libraries will be convenience libraries. Might be changed to shared +# later. +noinst_LIBRARIES = libmangosdatabase.a + +libmangosdatabase_a_SOURCES = \ + DBCFileLoader.cpp \ + DBCFileLoader.h \ + DBCStore.h \ + Database.cpp \ + Database.h \ + DatabaseEnv.h \ + DatabaseImpl.h \ + DatabaseMysql.cpp \ + DatabasePostgre.cpp \ + DatabaseMysql.h \ + DatabasePostgre.h \ + DBCEnums.h \ + Field.cpp \ + Field.h \ + MySQLDelayThread.h \ + PGSQLDelayThread.h \ + QueryResult.h \ + QueryResultMysql.cpp \ + QueryResultMysql.h \ + QueryResultPostgre.cpp \ + QueryResultPostgre.h \ + SQLStorage.cpp \ + SQLStorage.h \ + SQLStorageImpl.h \ + SqlDelayThread.cpp \ + SqlDelayThread.h \ + SqlOperations.cpp \ + SqlOperations.h diff --git a/src/shared/Database/MySQLDelayThread.h b/src/shared/Database/MySQLDelayThread.h index 14cf1a64617..fcebe3fbd35 100644 --- a/src/shared/Database/MySQLDelayThread.h +++ b/src/shared/Database/MySQLDelayThread.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/shared/Database/PGSQLDelayThread.h b/src/shared/Database/PGSQLDelayThread.h index 19941464cca..8d219bd9c1e 100644 --- a/src/shared/Database/PGSQLDelayThread.h +++ b/src/shared/Database/PGSQLDelayThread.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/shared/Database/QueryResult.h b/src/shared/Database/QueryResult.h index 32e47c0959f..f9f1a009833 100644 --- a/src/shared/Database/QueryResult.h +++ b/src/shared/Database/QueryResult.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -31,37 +31,53 @@ class TRINITY_DLL_SPEC QueryResult virtual bool NextRow() = 0; - typedef std::map<uint32, std::string> FieldNames; - - uint32 GetField_idx(const std::string &name) const - { - for(FieldNames::const_iterator iter = GetFieldNames().begin(); iter != GetFieldNames().end(); ++iter) - { - if(iter->second == name) - return iter->first; - } - assert(false && "unknown field name"); - return uint32(-1); - } - Field *Fetch() const { return mCurrentRow; } const Field & operator [] (int index) const { return mCurrentRow[index]; } - const Field & operator [] (const std::string &name) const - { - return mCurrentRow[GetField_idx(name)]; - } - uint32 GetFieldCount() const { return mFieldCount; } uint64 GetRowCount() const { return mRowCount; } - FieldNames const& GetFieldNames() const {return mFieldNames; } protected: Field *mCurrentRow; uint32 mFieldCount; uint64 mRowCount; - FieldNames mFieldNames; }; + +typedef std::vector<std::string> QueryFieldNames; + +class MANGOS_DLL_SPEC QueryNamedResult +{ + public: + explicit QueryNamedResult(QueryResult* query, QueryFieldNames const& names) : mQuery(query), mFieldNames(names) {} + ~QueryNamedResult() { delete mQuery; } + + // compatible interface with QueryResult + bool NextRow() { return mQuery->NextRow(); } + Field *Fetch() const { return mQuery->Fetch(); } + uint32 GetFieldCount() const { return mQuery->GetFieldCount(); } + uint64 GetRowCount() const { return mQuery->GetRowCount(); } + Field const& operator[] (int index) const { return (*mQuery)[index]; } + + // named access + Field const& operator[] (const std::string &name) const { return mQuery->Fetch()[GetField_idx(name)]; } + QueryFieldNames const& GetFieldNames() const { return mFieldNames; } + + uint32 GetField_idx(const std::string &name) const + { + for(size_t idx = 0; idx < mFieldNames.size(); ++idx) + { + if(mFieldNames[idx] == name) + return idx; + } + ASSERT(false && "unknown field name"); + return uint32(-1); + } + + protected: + QueryResult *mQuery; + QueryFieldNames mFieldNames; +}; + #endif diff --git a/src/shared/Database/QueryResultMysql.cpp b/src/shared/Database/QueryResultMysql.cpp index d995b9f2473..2e4738469c9 100644 --- a/src/shared/Database/QueryResultMysql.cpp +++ b/src/shared/Database/QueryResultMysql.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,20 +22,15 @@ #include "DatabaseEnv.h" -QueryResultMysql::QueryResultMysql(MYSQL_RES *result, uint64 rowCount, uint32 fieldCount) : -QueryResult(rowCount, fieldCount), mResult(result) +QueryResultMysql::QueryResultMysql(MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount) : + QueryResult(rowCount, fieldCount), mResult(result) { mCurrentRow = new Field[mFieldCount]; ASSERT(mCurrentRow); - MYSQL_FIELD *fields = mysql_fetch_fields(mResult); - for (uint32 i = 0; i < mFieldCount; i++) - { - mFieldNames[i] = fields[i].name; mCurrentRow[i].SetType(ConvertNativeType(fields[i].type)); - } } QueryResultMysql::~QueryResultMysql() diff --git a/src/shared/Database/QueryResultMysql.h b/src/shared/Database/QueryResultMysql.h index 3131bd4bbe4..89aceb12b13 100644 --- a/src/shared/Database/QueryResultMysql.h +++ b/src/shared/Database/QueryResultMysql.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ class QueryResultMysql : public QueryResult { public: - QueryResultMysql(MYSQL_RES *result, uint64 rowCount, uint32 fieldCount); + QueryResultMysql(MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount); ~QueryResultMysql(); diff --git a/src/shared/Database/QueryResultPostgre.cpp b/src/shared/Database/QueryResultPostgre.cpp index def1b0061e5..915b0fba253 100644 --- a/src/shared/Database/QueryResultPostgre.cpp +++ b/src/shared/Database/QueryResultPostgre.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,17 +23,14 @@ #include "DatabaseEnv.h" QueryResultPostgre::QueryResultPostgre(PGresult *result, uint64 rowCount, uint32 fieldCount) : -QueryResult(rowCount, fieldCount), mResult(result), mTableIndex(0) + QueryResult(rowCount, fieldCount), mResult(result), mTableIndex(0) { mCurrentRow = new Field[mFieldCount]; ASSERT(mCurrentRow); for (uint32 i = 0; i < mFieldCount; i++) - { - mFieldNames[i] = PQfname(result, i); mCurrentRow[i].SetType(ConvertNativeType(PQftype( result, i ))); - } } QueryResultPostgre::~QueryResultPostgre() diff --git a/src/shared/Database/QueryResultPostgre.h b/src/shared/Database/QueryResultPostgre.h index 61311728f2d..30d69114dc6 100644 --- a/src/shared/Database/QueryResultPostgre.h +++ b/src/shared/Database/QueryResultPostgre.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/shared/Database/QueryResultSqlite.cpp b/src/shared/Database/QueryResultSqlite.cpp deleted file mode 100644 index a041232f600..00000000000 --- a/src/shared/Database/QueryResultSqlite.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> - * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - * 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 - */ - -#ifndef DO_POSTGRESQL - -#include "DatabaseEnv.h" - -QueryResultSqlite::QueryResultSqlite(char **tableData, uint32 rowCount, uint32 fieldCount) : -QueryResult(rowCount, fieldCount), mTableData(tableData), mTableIndex(0) -{ - mCurrentRow = new Field[mFieldCount]; - - for (uint32 i = 0; i < mFieldCount; i++) - { - mFieldNames[i] = mTableData[i]; - mCurrentRow[i].SetType(Field::DB_TYPE_UNKNOWN); - } -} - -QueryResultSqlite::~QueryResultSqlite() -{ - EndQuery(); -} - -bool QueryResultSqlite::NextRow() -{ - int startIndex; - uint32 i; - - if (!mTableData) - return false; - - if (mTableIndex >= mRowCount) - { - EndQuery(); - return false; - } - - startIndex = (mTableIndex + 1) * mFieldCount; - for (i = 0; i < mFieldCount; i++) - { - mCurrentRow[i].SetValue(mTableData[startIndex + i]); - } - - ++mTableIndex; - return true; -} - -void QueryResultSqlite::EndQuery() -{ - if (mCurrentRow) - { - delete [] mCurrentRow; - mCurrentRow = NULL; - } - if (mTableData) - { - sqlite_free_table(mTableData); - mTableData = NULL; - } -} - -enum Field::DataTypes QueryResultSqlite::ConvertNativeType(const char* sqliteType) const -{ - if (sqliteType) - { - switch (*sqliteType) - { - case 'S': - return Field::DB_TYPE_STRING; - case 'I': - return Field::DB_TYPE_INTEGER; - case 'F': - return Field::DB_TYPE_FLOAT; - default: - return Field::DB_TYPE_UNKNOWN; - }; - } - return Field::DB_TYPE_UNKNOWN; -} -#endif - diff --git a/src/shared/Database/QueryResultSqlite.h b/src/shared/Database/QueryResultSqlite.h deleted file mode 100644 index b2622f96707..00000000000 --- a/src/shared/Database/QueryResultSqlite.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> - * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * 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 - * 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 - */ - -#ifndef DO_POSTGRESQL - -#if !defined(QUERYRESULTSQLITE_H) -#define QUERYRESULTSQLITE_H - -#include <sqlite/sqlite.h> - -class QueryResultSqlite : public QueryResult -{ - public: - QueryResultSqlite(char **tableData, uint32 rowCount, uint32 fieldCount); - - ~QueryResultSqlite(); - - bool NextRow(); - - private: - enum Field::DataTypes ConvertNativeType(const char* sqliteType) const; - void EndQuery(); - - char **mTableData; - uint32 mTableIndex; -}; -#endif -#endif - diff --git a/src/shared/Database/SQLStorage.cpp b/src/shared/Database/SQLStorage.cpp index 0eeefbf10ca..61ecaa7412f 100644 --- a/src/shared/Database/SQLStorage.cpp +++ b/src/shared/Database/SQLStorage.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,20 +27,20 @@ extern DatabasePostgre WorldDatabase; extern DatabaseMysql WorldDatabase; #endif -const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiis"; -const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiiiiiiiiiiiffiiiiiiiiiiiiiiiiiiisiilliiii"; -const char CreatureDataAddonInfofmt[]="iiiiiiiis"; +const char CreatureInfosrcfmt[]="iiiiiisssiiiiiiiiiiffiffiifiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifflliiis"; +const char CreatureInfodstfmt[]="iiiiiisssiiiiiiiiiiffiffiifiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifflliiii"; +const char CreatureDataAddonInfofmt[]="iiiiiis"; const char CreatureModelfmt[]="iffbi"; -const char CreatureInfoAddonInfofmt[]="iiiiiiiis"; -const char EquipmentInfofmt[]="iiiiiiiiii"; -const char GameObjectInfosrcfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiis"; -const char GameObjectInfodstfmt[]="iiissiifiiiiiiiiiiiiiiiiiiiiiiiii"; -const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiii"; -const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiii"; +const char CreatureInfoAddonInfofmt[]="iiiiiis"; +const char EquipmentInfofmt[]="iiii"; +const char GameObjectInfosrcfmt[]="iiisssiifiiiiiiiiiiiiiiiiiiiiiiiis"; +const char GameObjectInfodstfmt[]="iiisssiifiiiiiiiiiiiiiiiiiiiiiiiii"; +const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiisiiii"; +const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiii"; const char PageTextfmt[]="isi"; const char SpellThreatfmt[]="ii"; -const char InstanceTemplatesrcfmt[]="iiiiiffffs"; -const char InstanceTemplatedstfmt[]="iiiiiffffi"; +const char InstanceTemplatesrcfmt[]="iiiiiiffffs"; +const char InstanceTemplatedstfmt[]="iiiiiiffffi"; SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template"); SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon"); diff --git a/src/shared/Database/SQLStorage.h b/src/shared/Database/SQLStorage.h index 43e34532607..1b5b9d5dcf1 100644 --- a/src/shared/Database/SQLStorage.h +++ b/src/shared/Database/SQLStorage.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/shared/Database/SQLStorageImpl.h b/src/shared/Database/SQLStorageImpl.h index 82ff0beb60e..b511bdad68c 100644 --- a/src/shared/Database/SQLStorageImpl.h +++ b/src/shared/Database/SQLStorageImpl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,17 +18,17 @@ #include "ProgressBar.h" #include "Log.h" -#include "dbcfile.h" +#include "DBCFileLoader.h" template<class T> template<class S, class D> -void SQLStorageLoaderBase<T>::convert(uint32 field_pos, S src, D &dst) +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) +void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 /*field_pos*/, char *src, char *&dst) { if(!src) { @@ -45,7 +45,7 @@ void SQLStorageLoaderBase<T>::convert_str_to_str(uint32 field_pos, char *src, ch template<class T> template<class S> -void SQLStorageLoaderBase<T>::convert_to_str(uint32 field_pos, S src, char * & dst) +void SQLStorageLoaderBase<T>::convert_to_str(uint32 /*field_pos*/, S /*src*/, char * & dst) { dst = new char[1]; *dst = 0; @@ -53,7 +53,7 @@ void SQLStorageLoaderBase<T>::convert_to_str(uint32 field_pos, S src, char * & d template<class T> template<class D> -void SQLStorageLoaderBase<T>::convert_from_str(uint32 field_pos, char * src, D& dst) +void SQLStorageLoaderBase<T>::convert_from_str(uint32 /*field_pos*/, char * /*src*/, D& dst) { dst = 0; } diff --git a/src/shared/Database/SqlDelayThread.cpp b/src/shared/Database/SqlDelayThread.cpp index 16d5146fc53..9a92fd5dd63 100644 --- a/src/shared/Database/SqlDelayThread.cpp +++ b/src/shared/Database/SqlDelayThread.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,7 +37,7 @@ void SqlDelayThread::run() { // if the running state gets turned off while sleeping // empty the queue before exiting - ZThread::Thread::sleep(10); + ACE_Based::Thread::Sleep(10); while (!m_sqlQueue.empty()) { s = m_sqlQueue.next(); diff --git a/src/shared/Database/SqlDelayThread.h b/src/shared/Database/SqlDelayThread.h index 4c77c122f1e..3c24d3525b7 100644 --- a/src/shared/Database/SqlDelayThread.h +++ b/src/shared/Database/SqlDelayThread.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,28 +21,29 @@ #ifndef __SQLDELAYTHREAD_H #define __SQLDELAYTHREAD_H -#include "zthread/Thread.h" -#include "zthread/Runnable.h" -#include "zthread/FastMutex.h" -#include "zthread/LockedQueue.h" +#include "ace/Thread_Mutex.h" +#include "LockedQueue.h" +#include "Threading.h" + class Database; class SqlOperation; -class SqlDelayThread : public ZThread::Runnable +class SqlDelayThread : public ACE_Based::Runnable { - typedef ZThread::LockedQueue<SqlOperation*, ZThread::FastMutex> SqlQueue; + typedef ACE_Based::LockedQueue<SqlOperation*, ACE_Thread_Mutex> SqlQueue; + private: SqlQueue m_sqlQueue; ///< Queue of SQL statements Database* m_dbEngine; ///< Pointer to used Database engine - bool m_running; + volatile bool m_running; SqlDelayThread(); public: SqlDelayThread(Database* db); ///< Put sql statement to delay queue - inline bool Delay(SqlOperation* sql) { m_sqlQueue.add(sql); return true; } + bool Delay(SqlOperation* sql) { m_sqlQueue.add(sql); return true; } virtual void Stop(); ///< Stop event virtual void run(); ///< Main Thread loop diff --git a/src/shared/Database/SqlOperations.cpp b/src/shared/Database/SqlOperations.cpp index c11c5b9269d..53b99359c09 100644 --- a/src/shared/Database/SqlOperations.cpp +++ b/src/shared/Database/SqlOperations.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -97,7 +97,7 @@ bool SqlQueryHolder::SetQuery(size_t index, const char *sql) { if(m_queries.size() <= index) { - sLog.outError("Query index (%u) out of range (size: %u) for query: %s",index,m_queries.size(),sql); + sLog.outError("Query index (%u) out of range (size: %u) for query: %s",index,(uint32)m_queries.size(),sql); return false; } diff --git a/src/shared/Database/SqlOperations.h b/src/shared/Database/SqlOperations.h index 1a0d3c78d1b..e91d83b6611 100644 --- a/src/shared/Database/SqlOperations.h +++ b/src/shared/Database/SqlOperations.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,9 +23,8 @@ #include "Common.h" -#include "zthread/LockedQueue.h" -#include "zthread/FastMutex.h" -#include "zthread/Thread.h" +#include "ace/Thread_Mutex.h" +#include "LockedQueue.h" #include <queue> #include "Utilities/Callback.h" @@ -72,7 +71,7 @@ class SqlResultQueue; /// queue for thread class SqlQueryHolder; /// groups several async quries class SqlQueryHolderEx; /// points to a holder, added to the delay thread -class SqlResultQueue : public ZThread::LockedQueue<Trinity::IQueryCallback*, ZThread::FastMutex> +class SqlResultQueue : public ACE_Based::LockedQueue<MaNGOS::IQueryCallback* , ACE_Thread_Mutex> { public: SqlResultQueue() {} |