Added WFOs to the county database c++ code

This commit is contained in:
AdenKoperczak 2024-08-29 13:43:01 -04:00
parent 412c85647c
commit 6b4045081e
2 changed files with 46 additions and 0 deletions

View file

@ -31,6 +31,7 @@ typedef std::unordered_map<char, StateMap> FormatMap;
static bool initialized_ {false};
static FormatMap countyDatabase_;
static std::unordered_map<std::string, std::string> stateMap_;
static std::unordered_map<std::string, std::string> wfoMap_;
void Initialize()
{
@ -168,6 +169,39 @@ void Initialize()
sqlite3_free(errorMessage);
}
// Query database for WFOs
rc = sqlite3_exec(
db,
"SELECT id, city_state FROM wfos",
[](void* /* param */,
int columns,
char** columnText,
char** /* columnName */) -> int
{
int status = 0;
if (columns == 2)
{
wfoMap_.emplace(columnText[0], columnText[1]);
}
else
{
logger_->error(
"WFO database format error, invalid number of columns: {}",
columns);
status = -1;
}
return status;
},
nullptr,
&errorMessage);
if (rc != SQLITE_OK)
{
logger_->error("SQL error: {}", errorMessage);
sqlite3_free(errorMessage);
}
// Close database
sqlite3_close(db);
@ -230,6 +264,16 @@ const std::unordered_map<std::string, std::string>& GetStates()
return stateMap_;
}
const std::unordered_map<std::string, std::string>& GetWFOs()
{
return wfoMap_;
}
const std::string& GetWFOName(const std::string& wfoId)
{
return wfoMap_.at(wfoId);
}
} // namespace CountyDatabase
} // namespace config
} // namespace qt

View file

@ -19,6 +19,8 @@ std::string GetCountyName(const std::string& id);
std::unordered_map<std::string, std::string>
GetCounties(const std::string& state);
const std::unordered_map<std::string, std::string>& GetStates();
const std::unordered_map<std::string, std::string>& GetWFOs();
const std::string& GetWFOName(const std::string& wfoId);
} // namespace CountyDatabase
} // namespace config