38{
40
41
43 if (!result)
44 return nullptr;
45
46
48 {
50 return nullptr;
51 }
52
53
54
56 if (indexTableSize > records)
57 {
58 char** tmpIdxTable = new char* [indexTableSize];
59 memset(tmpIdxTable, 0, indexTableSize * sizeof(char*));
60 memcpy(tmpIdxTable, indexTable, records * sizeof(char*));
61 delete[] indexTable;
62 indexTable = tmpIdxTable;
63 }
64
65 std::unique_ptr<char[]> dataTable = std::make_unique<char[]>(result->GetRowCount() *
_recordSize);
66 std::unique_ptr<uint32[]> newIndexes = std::make_unique<uint32[]>(result->GetRowCount());
68
69
70 do
71 {
72 Field* fields = result->Fetch();
74 char* dataValue = indexTable[indexValue];
75
76
77 newIndexes[newRecords] = indexValue;
79
81 uint32 sqlColumnNumber = 0;
83
84 for (; (*dbcFormat); ++dbcFormat)
85 {
86 switch (*dbcFormat)
87 {
89 *reinterpret_cast<float*>(&dataValue[dataOffset]) = fields[sqlColumnNumber].Get<float>();
90 dataOffset += sizeof(float);
91 break;
94 *
reinterpret_cast<uint32*
>(&dataValue[dataOffset]) = fields[sqlColumnNumber].Get<uint32>();
95 dataOffset +=
sizeof(
uint32);
96 break;
98 *
reinterpret_cast<uint8*
>(&dataValue[dataOffset]) = fields[sqlColumnNumber].Get<uint8>();
99 dataOffset +=
sizeof(
uint8);
100 break;
102 *
reinterpret_cast<char**
>(&dataValue[dataOffset]) =
CloneStringToPool(fields[sqlColumnNumber].Get<std::string>());
103 dataOffset += sizeof(char*);
104 break;
108 break;
109 default:
111 return nullptr;
112 }
113
114 ++sqlColumnNumber;
115 }
116
117 ASSERT(sqlColumnNumber == result->GetFieldCount(),
"SQL format string does not match database for table: '{}'",
_sqlTableName);
119 } while (result->NextRow());
120
121 ASSERT(newRecords == result->GetRowCount());
122
123
124 for (
uint32 i = 0; i < newRecords; ++i)
125 {
126
127 indexTable[newIndexes[i]] = &dataTable[i *
_recordSize];
128 }
129
130 records = indexTableSize;
131
132 return dataTable.release();
133}
@ FT_IND
Definition: DBCFileLoader.h:34
@ FT_NA
Definition: DBCFileLoader.h:27
@ FT_FLOAT
Definition: DBCFileLoader.h:30
@ FT_STRING
Definition: DBCFileLoader.h:29
@ FT_SORT
Definition: DBCFileLoader.h:33
@ FT_NA_BYTE
Definition: DBCFileLoader.h:28
@ FT_INT
Definition: DBCFileLoader.h:31
@ FT_BYTE
Definition: DBCFileLoader.h:32
std::uint8_t uint8
Definition: Define.h:110
std::uint32_t uint32
Definition: Define.h:108
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
std::string StringFormat(Format &&fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:30
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
char * CloneStringToPool(std::string const &str)
Definition: DBCDatabaseLoader.cpp:135