Skip to content

Commit c0e3dcb

Browse files
committed
Allow binding null values
x
1 parent deae4ae commit c0e3dcb

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/connection.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class GameDataDBConnection : public game_data {
2828
r_string to_string() const override {
2929
if (!session) return r_string("<no session>"sv);
3030
if (!session->connected()) return r_string("<not connected>"sv);
31-
return "<connected to database: " + session->schema() + ">";
31+
return "<connected to database: " + session->schema() + ">";
3232
}
3333
//virtual bool equals(const game_data*) const override; //#TODO isEqualTo on hashMaps would be quite nice I guess?
3434
const char* type_as_string() const override { return "databaseConnection"; }
@@ -85,10 +85,15 @@ GameDataDBAsyncResult* Connection::pushAsyncQuery(game_state& gs, mariadb::conne
8585

8686
//If we give them to task, it will destruct the array after task is done, and may call dealloc int he pool allocator
8787
std::vector<
88-
std::variant<float, bool, r_string>
88+
std::variant<float, bool, r_string, std::monostate>
8989
> boundValuesQuery;
9090

9191
for (auto& it : boundValues) {
92+
if (it.is_null()) {
93+
boundValuesQuery.emplace_back(std::monostate());
94+
continue;
95+
}
96+
9297
switch (it.type_enum()) {
9398
case game_data_type::SCALAR: boundValuesQuery.emplace_back(static_cast<float>(it)); break;
9499
case game_data_type::BOOL: boundValuesQuery.emplace_back(static_cast<bool>(it)); break;
@@ -119,6 +124,8 @@ GameDataDBAsyncResult* Connection::pushAsyncQuery(game_state& gs, mariadb::conne
119124
statement->set_boolean(idx++, arg);
120125
else if constexpr (std::is_same_v<T, r_string>)
121126
statement->set_string(idx++, arg);
127+
else if constexpr (std::is_same_v<T, std::monostate>)
128+
statement->set_null(idx++);
122129
else
123130
static_assert(false, "non-exhaustive visitor!");
124131
}, it);

src/res.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ game_value Result::cmd_toParsedArray(game_state& state, game_value_parameter rig
7979
while (res->next()) {
8080
auto_array<game_value> row;
8181

82-
auto addParsedString = [&row](const r_string& content) {
82+
auto addParsedString = [&row, &state](const r_string& content) {
8383

8484
if (content.front() == '[') {//array
8585
//attempt parse

0 commit comments

Comments
 (0)