21 auto it = m_tables.find(name);
22 if (it != m_tables.end())
23 return it->second.get();
25 auto table = buildDB2Table(name);
26 const DB2Table* result = table.get();
27 m_tables[name] = std::move(table);
33 LOG_INFO <<
"buildDB2Table: start for " << tableName;
35 LOG_INFO <<
"buildDB2Table: buildTableStructure for " << tableName;
36 std::unique_ptr<core::TableStructure> tblStruct(buildTableStructure(tableName));
41 std::vector<DB2FieldInfo> fields;
42 for (
auto* f : tblStruct->fields)
48 info.
pos = wf ? wf->pos : -1;
50 info.
isKey = f->isKey;
52 fields.push_back(std::move(info));
56 LOG_INFO <<
"buildDB2Table: creating DB2Reader for " << tableName;
71 const int fileDataId =
GAMEDATABASE.getFileDataIdForTable(tblStruct->file);
81 LOG_ERROR <<
"WoWDatabase: DB2 file not found for table " << tableName;
85 auto reader = std::make_unique<DB2Reader>(db2Path);
87 LOG_INFO <<
"buildDB2Table: reader->open() for " << tableName;
90 LOG_ERROR <<
"WoWDatabase: failed to open DB2 for table " << tableName;
94 LOG_INFO <<
"buildDB2Table: done for " << tableName;
95 return std::make_unique<DB2Table>(std::move(reader), std::move(fields));
119 unsigned long val = std::stoul(verDef.
layoutHashes[0],
nullptr, 16);
120 tbl->
hash =
static_cast<unsigned int>(val);
151 fileToOpen =
GAMEDIRECTORY.getFile(
"DBFilesClient\\" + tableName + ext);
159 const int fileDataId =
GAMEDATABASE.getFileDataIdForTable(tableName);
167 if (!fileToOpen->
open(
false))
171 fileToOpen->
read(magic, 4);
177 size_t layoutHashOffset = 0;
179 if (strncmp(magic,
"WDC5", 4) == 0)
180 layoutHashOffset = 4 + 132 + 20;
181 else if (strncmp(magic,
"WDC2", 4) == 0 || strncmp(magic,
"WDC3", 4) == 0 || strncmp(magic,
"WDC4", 4) == 0)
182 layoutHashOffset = 24;
189 fileToOpen->
seek(layoutHashOffset);
190 unsigned int layoutHash = 0;
191 fileToOpen->
read(&layoutHash,
sizeof(layoutHash));
196 std::snprintf(hexBuf,
sizeof(hexBuf),
"%08X", layoutHash);
197 return std::string(hexBuf);
const std::vector< std::string > POSSIBLE_DB_EXT
Provides typed, field-name-based access to records in a WDC DB2 file.
Abstract base class representing a file within the game data archive.
bool open(bool useMemoryBuffer=true)
Open the file, optionally loading into a memory buffer.
virtual void seek(size_t offset)
Seek to an absolute byte offset.
bool close()
Close the file and release the internal buffer.
virtual size_t read(void *dest, size_t bytes)
Read bytes from the file into dest.
const std::string & fullname() const
Describes a single field (column) in a database table.
Describes the schema of a database table (name, file path, fields).
std::string getLayoutHashForTable(const std::string &tableName) override
void setFieldPos(core::FieldStructure *, int pos) override
core::FieldStructure * createFieldStructure()
void readSpecificFieldAttributesFromDBD(const core::DBDVersionField &, const core::DBDColumnDef &, core::FieldStructure *) override
const DB2Table * getTable(const std::string &name)
void readSpecificTableAttributesFromDBD(const core::DBDVersionDef &, core::TableStructure *) override
std::unique_ptr< DB2Table > buildDB2Table(const std::string &tableName)
core::TableStructure * createTableStructure()
Describes a single field (column) in a DB2 table.
bool isRelationshipData
Whether this field is relationship data.
int pos
DB2 field position index (-1 for non-inline/key).
std::string name
Column name.
std::string type
Type string ("text", "float", "int8", "uint8", etc.).
unsigned int arraySize
Array size (> 1 for array fields).
bool isKey
Whether this field is the primary key.
std::vector< std::string > layoutHashes