28 if (m_manifestUrl.empty())
34 LOG_INFO <<
"Downloading DBD manifest from " << m_manifestUrl;
36 if (!resp.success || resp.body.empty())
38 LOG_ERROR <<
"Failed to download manifest:" << resp.error;
44 const auto manifest = nlohmann::json::parse(resp.body);
45 for (
const auto& entry : manifest)
47 if (entry.contains(
"tableName") && entry.contains(
"db2FileDataID"))
49 const std::string tableName = entry[
"tableName"].get<std::string>();
50 const int fileDataId = entry[
"db2FileDataID"].get<
int>();
51 if (!tableName.empty() && fileDataId > 0)
52 m_tableFileDataIds[tableName] = fileDataId;
56 LOG_INFO <<
"Loaded DBD manifest with " << m_tableFileDataIds.size() <<
" entries ";
59 catch (
const std::exception& e)
61 LOG_ERROR <<
"Failed to parse manifest JSON:" << e.what();
76 namespace fs = std::filesystem;
78 std::string dbdPath = m_dbdDir +
"/" + tableName +
".dbd";
80 if (!fs::exists(dbdPath) && !m_dbdBaseUrl.empty())
82 std::string url = m_dbdBaseUrl;
83 auto pos = url.find(
"%s");
84 if (pos != std::string::npos)
85 url.replace(pos, 2, tableName);
87 url += tableName +
".dbd";
89 LOG_INFO <<
"Downloading DBD for" << tableName <<
"from" << url;
91 if (resp.success && !resp.body.empty())
93 fs::create_directories(m_dbdDir);
94 std::ofstream out(dbdPath, std::ios::binary);
97 out.write(resp.body.data(), resp.body.size());
103 LOG_ERROR <<
"Failed to download DBD for" << tableName <<
":" << resp.error;
107 if (!fs::exists(dbdPath))
109 LOG_ERROR <<
"DBD file not found:" << dbdPath;
114 if (!dbd.
parse(dbdPath))
116 LOG_ERROR <<
"Failed to parse DBD file:" << dbdPath;
120 const std::string layoutHash = getLayoutHashForTable(tableName);
124 LOG_ERROR <<
"No matching version definition found in" << dbdPath
125 <<
"for build" << m_build.major <<
"." << m_build.minor
126 <<
"." << m_build.patch <<
"." << m_build.build;
131 tblStruct->
name = tableName;
132 tblStruct->
file = tableName;
134 readSpecificTableAttributesFromDBD(*verDef, tblStruct);
139 for (
const auto& vField : verDef->
fields)
144 LOG_ERROR <<
"Column definition not found for field" << vField.
name
145 <<
"in table" << tableName;
146 if (!vField.isNonInline)
152 fieldStruct->
id = fieldId++;
153 fieldStruct->
name = vField.name;
155 fieldStruct->
arraySize = vField.arraySize;
156 fieldStruct->
isKey = vField.isID;
159 readSpecificFieldAttributesFromDBD(vField, *colDef, fieldStruct);
161 if (!vField.isNonInline)
163 setFieldPos(fieldStruct, fieldPos);
167 tblStruct->
fields.push_back(fieldStruct);