TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PlayerDump.cpp File Reference
#include "Common.h"
#include "PlayerDump.h"
#include "DatabaseEnv.h"
#include "UpdateFields.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "AccountMgr.h"
#include "World.h"
+ Include dependency graph for PlayerDump.cpp:

Classes

struct  DumpTable
 

Macros

#define DUMP_TABLE_COUNT   30
 
#define ROLLBACK(DR)   {fclose(fin); return (DR);}
 

Functions

static bool FindTokNth (std::string const &str, uint32 n, std::string::size_type &s, std::string::size_type &e)
 
std::string GetTokNth (std::string const &str, uint32 n)
 
bool FindNth (std::string const &str, uint32 n, std::string::size_type &s, std::string::size_type &e)
 
std::string GetTableName (std::string const &str)
 
bool ChangeNth (std::string &str, uint32 n, char const *with, bool insert=false, bool allowZero=false)
 
std::string GetNth (std::string &str, uint32 n)
 
bool ChangeTokNth (std::string &str, uint32 n, char const *with, bool insert=false, bool allowZero=false)
 
ObjectGuid::LowType RegisterNewGuid (ObjectGuid::LowType oldGuid, PlayerDump::DumpGuidMap &guidMap, ObjectGuid::LowType guidOffset)
 
bool ChangeGuid (std::string &str, uint32 n, PlayerDump::DumpGuidMap &guidMap, ObjectGuid::LowType guidOffset, bool allowZero=false)
 
std::string CreateDumpString (char const *tableName, QueryResult result)
 
void StoreGUID (QueryResult result, uint32 field, PlayerDump::DumpGuidSet &guids)
 
void StoreGUID (QueryResult result, uint32 data, uint32 field, PlayerDump::DumpGuidSet &guids)
 
void fixNULLfields (std::string &line)
 

Variables

static DumpTable dumpTables [DUMP_TABLE_COUNT]
 

Macro Definition Documentation

#define DUMP_TABLE_COUNT   30
#define ROLLBACK (   DR)    {fclose(fin); return (DR);}

Function Documentation

bool ChangeGuid ( std::string &  str,
uint32  n,
PlayerDump::DumpGuidMap guidMap,
ObjectGuid::LowType  guidOffset,
bool  allowZero = false 
)
192 {
193  ObjectGuid::LowType oldGuid = strtoull(GetNth(str, n).c_str(), nullptr, 10);
194  if (allowZero && !oldGuid)
195  return true; // not an error
196 
197  char chritem[21];
198  ObjectGuid::LowType newGuid = RegisterNewGuid(oldGuid, guidMap, guidOffset);
199  snprintf(chritem, 21, UI64FMTD, newGuid);
200 
201  return ChangeNth(str, n, chritem, false, allowZero);
202 }
#define snprintf
Definition: Common.h:76
uint64 LowType
Definition: ObjectGuid.h:199
#define UI64FMTD
Definition: Define.h:137
std::string GetNth(std::string &str, uint32 n)
Definition: PlayerDump.cpp:154
ObjectGuid::LowType RegisterNewGuid(ObjectGuid::LowType oldGuid, PlayerDump::DumpGuidMap &guidMap, ObjectGuid::LowType guidOffset)
Definition: PlayerDump.cpp:180
bool ChangeNth(std::string &str, uint32 n, char const *with, bool insert=false, bool allowZero=false)
Definition: PlayerDump.cpp:137

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ChangeNth ( std::string &  str,
uint32  n,
char const with,
bool  insert = false,
bool  allowZero = false 
)
138 {
139  std::string::size_type s, e;
140  if (!FindNth(str, n, s, e))
141  return false;
142 
143  if (allowZero && str.substr(s, e - s) == "0")
144  return true; // not an error
145 
146  if (!insert)
147  str.replace(s, e - s, with);
148  else
149  str.insert(s, with);
150 
151  return true;
152 }
bool FindNth(std::string const &str, uint32 n, std::string::size_type &s, std::string::size_type &e)
Definition: PlayerDump.cpp:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ChangeTokNth ( std::string &  str,
uint32  n,
char const with,
bool  insert = false,
bool  allowZero = false 
)
164 {
165  std::string::size_type s = 0, e = 0;
166  if (!FindTokNth(str, n, s, e))
167  return false;
168 
169  if (allowZero && str.substr(s, e - s) == "0")
170  return true; // not an error
171 
172  if (!insert)
173  str.replace(s, e-s, with);
174  else
175  str.insert(s, with);
176 
177  return true;
178 }
static bool FindTokNth(std::string const &str, uint32 n, std::string::size_type &s, std::string::size_type &e)
Definition: PlayerDump.cpp:75

+ Here is the call graph for this function:

std::string CreateDumpString ( char const tableName,
QueryResult  result 
)
205 {
206  if (!tableName || !result) return "";
207  std::ostringstream ss;
208  ss << "INSERT INTO " << _TABLE_SIM_ << tableName << _TABLE_SIM_ << " VALUES (";
209  Field* fields = result->Fetch();
210  for (uint32 i = 0; i < result->GetFieldCount(); ++i)
211  {
212  if (i == 0) ss << '\'';
213  else ss << ", '";
214 
215  std::string s = fields[i].GetString();
217  ss << s;
218 
219  ss << '\'';
220  }
221  ss << ");";
222  return ss.str();
223 }
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32_t uint32
Definition: Define.h:150
void EscapeString(std::string &str)
Apply escape string'ing for current collation. (utf8)
Definition: DatabaseWorkerPool.cpp:231
#define _TABLE_SIM_
Definition: DatabaseEnv.h:33
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
std::string GetString() const
Definition: Field.h:276

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool FindNth ( std::string const str,
uint32  n,
std::string::size_type &  s,
std::string::size_type &  e 
)
102 {
103  s = str.find("VALUES ('") + 9;
104  if (s == std::string::npos)
105  return false;
106 
107  do
108  {
109  e = str.find('\'', s);
110  if (e == std::string::npos)
111  return false;
112  } while (str[e - 1] == '\\');
113 
114  for (uint32 i = 1; i < n; ++i)
115  {
116  do
117  {
118  s = e + 4;
119  e = str.find('\'', s);
120  if (e == std::string::npos)
121  return false;
122  } while (str[e - 1] == '\\');
123  }
124  return true;
125 }
uint32_t uint32
Definition: Define.h:150

+ Here is the caller graph for this function:

static bool FindTokNth ( std::string const str,
uint32  n,
std::string::size_type &  s,
std::string::size_type &  e 
)
static
76 {
77  s = e = 0;
78 
79  uint32 i = 1;
80  for (; s < str.size() && i < n; ++s)
81  if (str[s] == ' ')
82  ++i;
83 
84  if (i < n)
85  return false;
86 
87  e = str.find(' ', s);
88 
89  return e != std::string::npos;
90 }
uint32_t uint32
Definition: Define.h:150

+ Here is the caller graph for this function:

void fixNULLfields ( std::string &  line)
396 {
397  static std::string const nullString("'NULL'");
398  size_t pos = line.find(nullString);
399  while (pos != std::string::npos)
400  {
401  line.replace(pos, nullString.length(), "NULL");
402  pos = line.find(nullString);
403  }
404 }

+ Here is the caller graph for this function:

std::string GetNth ( std::string &  str,
uint32  n 
)
155 {
156  std::string::size_type s, e;
157  if (!FindNth(str, n, s, e))
158  return "";
159 
160  return str.substr(s, e-s);
161 }
bool FindNth(std::string const &str, uint32 n, std::string::size_type &s, std::string::size_type &e)
Definition: PlayerDump.cpp:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string GetTableName ( std::string const str)
128 {
129  static std::string::size_type const s = 13;
130  std::string::size_type e = str.find(_TABLE_SIM_, s);
131  if (e == std::string::npos)
132  return "";
133 
134  return str.substr(s, e - s);
135 }
#define _TABLE_SIM_
Definition: DatabaseEnv.h:33

+ Here is the caller graph for this function:

std::string GetTokNth ( std::string const str,
uint32  n 
)
93 {
94  std::string::size_type s = 0, e = 0;
95  if (!FindTokNth(str, n, s, e))
96  return "";
97 
98  return str.substr(s, e - s);
99 }
static bool FindTokNth(std::string const &str, uint32 n, std::string::size_type &s, std::string::size_type &e)
Definition: PlayerDump.cpp:75

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ObjectGuid::LowType RegisterNewGuid ( ObjectGuid::LowType  oldGuid,
PlayerDump::DumpGuidMap guidMap,
ObjectGuid::LowType  guidOffset 
)
181 {
182  PlayerDumpWriter::DumpGuidMap::const_iterator itr = guidMap.find(oldGuid);
183  if (itr != guidMap.end())
184  return itr->second;
185 
186  ObjectGuid::LowType newguid = guidOffset + guidMap.size();
187  guidMap[oldGuid] = newguid;
188  return newguid;
189 }
uint64 LowType
Definition: ObjectGuid.h:199

+ Here is the caller graph for this function:

void StoreGUID ( QueryResult  result,
uint32  field,
PlayerDump::DumpGuidSet guids 
)
252 {
253  Field* fields = result->Fetch();
254  ObjectGuid::LowType guid = fields[field].GetUInt64();
255  if (guid)
256  guids.insert(guid);
257 }
uint64 GetUInt64() const
Definition: Field.h:184
Class used to access individual fields of database query result.
Definition: Field.h:56
uint64 LowType
Definition: ObjectGuid.h:199

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void StoreGUID ( QueryResult  result,
uint32  data,
uint32  field,
PlayerDump::DumpGuidSet guids 
)
260 {
261  Field* fields = result->Fetch();
262  std::string dataStr = fields[data].GetString();
263  ObjectGuid::LowType guid = strtoull(GetTokNth(dataStr, field).c_str(), nullptr, 10);
264  if (guid)
265  guids.insert(guid);
266 }
Class used to access individual fields of database query result.
Definition: Field.h:56
uint64 LowType
Definition: ObjectGuid.h:199
std::string GetString() const
Definition: Field.h:276
std::string GetTokNth(std::string const &str, uint32 n)
Definition: PlayerDump.cpp:92

+ Here is the call graph for this function:

Variable Documentation

DumpTable dumpTables[DUMP_TABLE_COUNT]
static