39{
41
42
44 if (!result)
45 return nullptr;
46
47
49 {
51 return nullptr;
52 }
53
54
55
57 if (indexTableSize > records)
58 {
59 char** tmpIdxTable = new char* [indexTableSize];
60 memset(tmpIdxTable, 0, indexTableSize * sizeof(char*));
61 memcpy(tmpIdxTable, indexTable, records * sizeof(char*));
62 delete[] indexTable;
63 indexTable = tmpIdxTable;
64 }
65
66 std::unique_ptr<char[]> dataTable = std::make_unique<char[]>(result->GetRowCount() *
_recordSize);
67 std::unique_ptr<uint32[]> newIndexes = std::make_unique<uint32[]>(result->GetRowCount());
69
70
71 do
72 {
73 Field* fields = result->Fetch();
75 char* dataValue = indexTable[indexValue];
76
77
78 newIndexes[newRecords] = indexValue;
80
82 uint32 sqlColumnNumber = 0;
84
85 for (; (*dbcFormat); ++dbcFormat)
86 {
87 switch (*dbcFormat)
88 {
90 *reinterpret_cast<float*>(&dataValue[dataOffset]) = fields[sqlColumnNumber].Get<float>();
91 dataOffset += sizeof(float);
92 break;
95 *
reinterpret_cast<uint32*
>(&dataValue[dataOffset]) = fields[sqlColumnNumber].Get<uint32>();
96 dataOffset +=
sizeof(
uint32);
97 break;
99 *
reinterpret_cast<uint8*
>(&dataValue[dataOffset]) = fields[sqlColumnNumber].Get<uint8>();
100 dataOffset +=
sizeof(
uint8);
101 break;
103 *
reinterpret_cast<char**
>(&dataValue[dataOffset]) =
CloneStringToPool(fields[sqlColumnNumber].Get<std::string>());
104 dataOffset += sizeof(char*);
105 break;
109 break;
110 default:
112 return nullptr;
113 }
114
115 ++sqlColumnNumber;
116 }
117
118 ASSERT(sqlColumnNumber == result->GetFieldCount(),
"SQL format string does not match database for table: '{}'",
_sqlTableName);
120 } while (result->NextRow());
121
122 ASSERT(newRecords == result->GetRowCount());
123
124
125 for (
uint32 i = 0; i < newRecords; ++i)
126 {
127
128 indexTable[newIndexes[i]] = &dataTable[i *
_recordSize];
129 }
130
131 records = indexTableSize;
132
133 return dataTable.release();
134}
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
@ 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
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
Class used to access individual fields of database query result.
Definition: Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
char * CloneStringToPool(std::string const &str)
Definition: DBCDatabaseLoader.cpp:136