Skip to content

Commit 27609cd

Browse files
committed
Fixed always loading statement specific config
1 parent a4793e8 commit 27609cd

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

src/config.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,14 @@ void Config::reloadConfig() {
8686
if (it.second.IsMap()) {
8787
if (!it.second["query"]) throw std::runtime_error(("statement "+stmtName+" has no 'query' entry").c_str());
8888

89-
statements[stmtName] = {
90-
it.second["query"].as<r_string>(),
91-
it.second["parseTinyintAsBool"].as<bool>(false),
92-
dateTypeFromString(it.second["parseDateType"].as<r_string>("string"sv))
93-
};
89+
ConfigStatement stmt;
90+
stmt.query = it.second["query"].as<r_string>();
91+
if (it.second["parseTinyintAsBool"].IsDefined())
92+
stmt.parseTinyintAsBool = it.second["parseTinyintAsBool"].as<bool>();
93+
if (it.second["parseDateType"].IsDefined())
94+
stmt.dateType = dateTypeFromString(it.second["parseDateType"].as<r_string>());
95+
96+
statements[stmtName] = std::move(stmt);
9497
} else {
9598
statements[stmtName] = {it.second.as<r_string>()};
9699
}

src/config.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ ConfigDateType dateTypeFromString(std::string_view str);
1919
class ConfigStatement {
2020
public:
2121
r_string query;
22-
bool parseTinyintAsBool = false;
23-
ConfigDateType dateType = ConfigDateType::humanString;
22+
std::optional<bool> parseTinyintAsBool;
23+
std::optional<ConfigDateType> dateType;
2424
};
2525

2626

@@ -61,10 +61,31 @@ class Config : public intercept::singleton<Config> {
6161
return dateType;
6262
}
6363

64+
ConfigDateType getDateType(r_string statementName) const {
65+
if (statementName.empty()) return dateType;
66+
auto found = statements.find(statementName);
67+
if (found == statements.end()) return dateType;
68+
if (found->second.dateType)
69+
return *found->second.dateType;
70+
71+
return dateType;
72+
}
73+
6474
bool getTinyintAsBool() const {
6575
return parseTinyintAsBool;
6676
}
6777

78+
bool getTinyintAsBool(r_string statementName) const {
79+
if (statementName.empty()) return parseTinyintAsBool;
80+
auto found = statements.find(statementName);
81+
if (found == statements.end()) return parseTinyintAsBool;
82+
if (found->second.parseTinyintAsBool)
83+
return *found->second.parseTinyintAsBool;
84+
85+
return parseTinyintAsBool;
86+
}
87+
88+
6889
static void initCommands();
6990
static inline registered_sqf_function handle_cmd_reloadConfig;
7091
static inline registered_sqf_function handle_cmd_version;

src/res.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,8 @@ game_value Result::cmd_toArray(game_state&, game_value_parameter right) {
155155
if (!res) return auto_array<game_value>();
156156
auto_array<game_value> result;
157157

158-
const auto [dateParser, dateTimeParser, timeParser] = getDateParser(
159-
gdRes->statementName.empty() ? Config::get().getDateType() : Config::get().getStatement(gdRes->statementName).dateType);
160-
const auto parseTinyintAsBool =
161-
gdRes->statementName.empty() ? Config::get().getTinyintAsBool() : Config::get().getStatement(gdRes->statementName).parseTinyintAsBool;
158+
const auto [dateParser, dateTimeParser, timeParser] = getDateParser(Config::get().getDateType(gdRes->statementName));
159+
const auto parseTinyintAsBool = Config::get().getTinyintAsBool(gdRes->statementName);
162160

163161
while (res->next()) {
164162
auto_array<game_value> row;
@@ -212,10 +210,8 @@ game_value Result::cmd_toParsedArray(game_state& state, game_value_parameter rig
212210
if (!res) return auto_array<game_value>();
213211
auto_array<game_value> result;
214212

215-
const auto [dateParser, dateTimeParser, timeParser] = getDateParser(
216-
gdRes->statementName.empty() ? Config::get().getDateType() : Config::get().getStatement(gdRes->statementName).dateType);
217-
const auto parseTinyintAsBool =
218-
gdRes->statementName.empty() ? Config::get().getTinyintAsBool() : Config::get().getStatement(gdRes->statementName).parseTinyintAsBool;
213+
const auto [dateParser, dateTimeParser, timeParser] = getDateParser(Config::get().getDateType(gdRes->statementName));
214+
const auto parseTinyintAsBool = Config::get().getTinyintAsBool(gdRes->statementName);
219215

220216
while (res->next()) {
221217
auto_array<game_value> row;

0 commit comments

Comments
 (0)