37 SqlDbc(std::string
const* _filename, std::string
const* _format, std::string
const* _idname,
char const*
fmt)
38 : formatString(_format), indexName (_idname), sqlIndexPos(0)
41 sqlTableName = *_filename;
42 for (
uint32 i = 0; i< sqlTableName.size(); ++i)
44 if (isalpha(sqlTableName[i]))
45 sqlTableName[i] =
char(tolower(sqlTableName[i]));
46 else if (sqlTableName[i] ==
'.')
47 sqlTableName[i] =
'_';
55 for (
uint32 x = 0;
x < formatString->size(); ++
x)
112 uint32 sqlRecordCount = 0;
113 uint32 sqlHighestIndex = 0;
121 query +=
" ORDER BY " + *sql->
indexName +
" DESC";
128 sqlRecordCount =
uint32(result->GetRowCount());
131 fields = result->Fetch();
144 char* sqlDataTable =
NULL;
148 sqlRecordCount, sqlHighestIndex, sqlDataTable));
162 fields = result->Fetch();
173 indexTable.asT[id] =
reinterpret_cast<T*
>(&sqlDataTable[offset]);
176 indexTable.asT[rowIndex]=
reinterpret_cast<T*
>(&sqlDataTable[offset]);
179 uint32 sqlColumnNumber = 0;
181 for (; columnNumber < sql->
formatString->size(); ++columnNumber)
185 switch (
fmt[columnNumber])
188 *
reinterpret_cast<float*
>(&sqlDataTable[offset]) = 0.0f;
193 *
reinterpret_cast<uint32*
>(&sqlDataTable[offset]) =
uint32(0);
197 *
reinterpret_cast<uint8*
>(&sqlDataTable[offset]) =
uint8(0);
201 *
reinterpret_cast<uint64*
>(&sqlDataTable[offset]) =
uint64(0);
206 *
reinterpret_cast<char**
>(&sqlDataTable[offset]) =
stringPoolList.back();
207 offset +=
sizeof(
char*);
213 bool validSqlColumn =
true;
214 switch (
fmt[columnNumber])
217 *
reinterpret_cast<float*
>(&sqlDataTable[offset]) = fields[sqlColumnNumber].GetFloat();
222 *
reinterpret_cast<uint32*
>(&sqlDataTable[offset]) = fields[sqlColumnNumber].GetUInt32();
226 *
reinterpret_cast<uint8*
>(&sqlDataTable[offset]) = fields[sqlColumnNumber].GetUInt8();
230 *
reinterpret_cast<uint64*
>(&sqlDataTable[offset]) = fields[sqlColumnNumber].GetUInt64();
234 TC_LOG_ERROR(
"server.loading",
"Unsupported data type in table '%s' at char %d", sql->
sqlTableName.c_str(), columnNumber);
239 validSqlColumn =
false;
242 if (validSqlColumn && (columnNumber != (sql->
formatString->size()-1)))
247 TC_LOG_ERROR(
"server.loading",
"Incorrect sql format string '%s' at char %d", sql->
sqlTableName.c_str(), columnNumber);
252 if (sqlColumnNumber != (result->GetFieldCount() - 1))
254 TC_LOG_ERROR(
"server.loading",
"SQL and DBC format strings are not matching for table: '%s'", sql->
sqlTableName.c_str());
260 }
while (result->NextRow());
289 delete[]
reinterpret_cast<char*
>(
indexTable.asT);
291 delete[]
reinterpret_cast<char*
>(
dataTable);
std::string const * indexName
Definition: DBCStore.h:33
int32 sqlIndexPos
Definition: DBCStore.h:36
uint32 fieldCount
Definition: DBCStore.h:309
StringPoolList stringPoolList
Definition: DBCStore.h:319
std::list< char * > StringPoolList
Definition: DBCStore.h:76
Definition: DBCStore.h:74
Class used to access individual fields of database query result.
Definition: Field.h:56
iterator begin()
Definition: DBCStore.h:303
DBCStorage & operator=(DBCStorage const &right)=delete
void Clear()
Definition: DBCStore.h:284
Definition: DBCStore.h:30
std::string const * formatString
Definition: DBCStore.h:32
char const * fmt
Definition: DBCStore.h:307
arena_t NULL
Definition: jemalloc_internal.h:624
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
char ** asChar
Definition: DBCStore.h:314
uint64_t uint64
Definition: g3dmath.h:170
char * query(struct soap *soap)
Definition: httpget.cpp:244
char const * GetFormat() const
Definition: DBCStore.h:102
bool LoadStringsFrom(char const *fn)
Definition: DBCStore.h:268
iterator end()
Definition: DBCStore.h:304
~DBCStorage()
Definition: DBCStore.h:87
bool Load(const char *filename, const char *fmt)
Definition: DBCFileLoader.cpp:28
SqlDbc(std::string const *_filename, std::string const *_format, std::string const *_idname, char const *fmt)
Definition: DBCStore.h:37
Definition: DBCFileLoader.h:26
Definition: DBStorageIterator.h:25
int32 indexPos
Definition: DBCStore.h:35
std::string sqlTableName
Definition: DBCStore.h:34
uint32 GetFieldCount() const
Definition: DBCStore.h:103
char * AutoProduceStrings(const char *fmt, char *dataTable)
Definition: DBCFileLoader.cpp:272
uint32 GetNumRows() const
Get begin iterator over records.
Definition: DBCFileLoader.h:84
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
T ** asT
Definition: DBCStore.h:313
T const * AssertEntry(uint32 id) const
Definition: DBCStore.h:94
SqlDbc & operator=(SqlDbc const &right)=delete
bool Load(char const *fn, SqlDbc *sql)
Definition: DBCStore.h:105
DBStorageIterator< T > iterator
Definition: DBCStore.h:79
char * AutoProduceData(const char *fmt, uint32 &count, char **&indexTable, uint32 sqlRecordCount, uint32 sqlHighestIndex, char *&sqlDataTable)
Definition: DBCFileLoader.cpp:173
uint32 GetNumRows() const
Definition: DBCStore.h:101
T * dataTable
Definition: DBCStore.h:318
uint8_t uint8
Definition: g3dmath.h:164
uint32 GetCols() const
Definition: DBCFileLoader.h:86
static uint32 GetFormatRecordSize(const char *format, int32 *index_pos=NULL)
Definition: DBCFileLoader.cpp:128
DBCStorage(char const *f)
Definition: DBCStore.h:81
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
int32_t int32
Definition: g3dmath.h:167
uint8_t uint8
Definition: Define.h:152
#define ASSERT
Definition: Errors.h:55
T const * LookupEntry(uint32 id) const
Definition: DBCStore.h:89
union DBCStorage::@339 indexTable
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32_t uint32
Definition: g3dmath.h:168
G3D::int16 x
Definition: Vector2int16.h:37
uint32 nCount
Definition: DBCStore.h:308