diff --git a/scwx-qt/source/scwx/qt/config/county_database.cpp b/scwx-qt/source/scwx/qt/config/county_database.cpp index 106b6911..6edcae4d 100644 --- a/scwx-qt/source/scwx/qt/config/county_database.cpp +++ b/scwx-qt/source/scwx/qt/config/county_database.cpp @@ -31,6 +31,7 @@ typedef std::unordered_map FormatMap; static bool initialized_ {false}; static FormatMap countyDatabase_; static std::unordered_map stateMap_; +static std::unordered_map 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& GetStates() return stateMap_; } +const std::unordered_map& GetWFOs() +{ + return wfoMap_; +} + +const std::string& GetWFOName(const std::string& wfoId) +{ + return wfoMap_.at(wfoId); +} + } // namespace CountyDatabase } // namespace config } // namespace qt diff --git a/scwx-qt/source/scwx/qt/config/county_database.hpp b/scwx-qt/source/scwx/qt/config/county_database.hpp index 5ee33e11..e2d427c6 100644 --- a/scwx-qt/source/scwx/qt/config/county_database.hpp +++ b/scwx-qt/source/scwx/qt/config/county_database.hpp @@ -19,6 +19,8 @@ std::string GetCountyName(const std::string& id); std::unordered_map GetCounties(const std::string& state); const std::unordered_map& GetStates(); +const std::unordered_map& GetWFOs(); +const std::string& GetWFOName(const std::string& wfoId); } // namespace CountyDatabase } // namespace config