summaryrefslogtreecommitdiff
path: root/src/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/database')
-rw-r--r--src/database/database.hpp2
-rw-r--r--src/database/query.cpp12
-rw-r--r--src/database/query.hpp4
-rw-r--r--src/database/select_query.hpp9
4 files changed, 14 insertions, 13 deletions
diff --git a/src/database/database.hpp b/src/database/database.hpp
index 03d82ae..8a967d8 100644
--- a/src/database/database.hpp
+++ b/src/database/database.hpp
@@ -69,7 +69,7 @@ class Database
struct RecordHistory: Column<bool> { static constexpr auto name = "recordhistory_";
RecordHistory(): Column<bool>(true) {}};
- struct RecordHistoryOptional: Column<std::optional<bool>> { static constexpr auto name = "recordhistory_"; };
+ struct RecordHistoryOptional: Column<OptionalBool> { static constexpr auto name = "recordhistory_"; };
struct VerifyCert: Column<bool> { static constexpr auto name = "verifycert_";
VerifyCert(): Column<bool>(true) {} };
diff --git a/src/database/query.cpp b/src/database/query.cpp
index 13c881b..d72066e 100644
--- a/src/database/query.cpp
+++ b/src/database/query.cpp
@@ -11,11 +11,11 @@ void actual_bind(Statement& statement, const std::int64_t& value, int index)
statement.bind_int64(index, value);
}
-void actual_bind(Statement& statement, const std::optional<bool>& value, int index)
+void actual_bind(Statement& statement, const OptionalBool& value, int index)
{
- if (!value)
+ if (!value.is_set)
statement.bind_int64(index, 0);
- else if (*value)
+ else if (value.value)
statement.bind_int64(index, 1);
else
statement.bind_int64(index, -1);
@@ -26,11 +26,11 @@ void actual_add_param(Query& query, const std::string& val)
query.params.push_back(val);
}
-void actual_add_param(Query& query, const std::optional<bool>& val)
+void actual_add_param(Query& query, const OptionalBool& val)
{
- if (!val)
+ if (!val.is_set)
query.params.push_back("0");
- else if (*val)
+ else if (val.value)
query.params.push_back("1");
else
query.params.push_back("-1");
diff --git a/src/database/query.hpp b/src/database/query.hpp
index 1c4a5ff..ba28b1a 100644
--- a/src/database/query.hpp
+++ b/src/database/query.hpp
@@ -18,7 +18,7 @@ void actual_bind(Statement& statement, const T& value, int index)
{
actual_bind(statement, static_cast<std::int64_t>(value), index);
}
-void actual_bind(Statement& statement, const std::optional<bool>& value, int index);
+void actual_bind(Statement& statement, const OptionalBool& value, int index);
#ifdef DEBUG_SQL_QUERIES
#include <utils/scopetimer.hpp>
@@ -71,6 +71,7 @@ void actual_add_param(Query& query, const T& val)
}
void actual_add_param(Query& query, const std::string& val);
+void actual_add_param(Query& query, const OptionalBool& val);
template <typename T>
typename std::enable_if<!std::is_integral<T>::value, Query&>::type
@@ -79,7 +80,6 @@ operator<<(Query& query, const T&)
query.body += T::name;
return query;
}
-void actual_add_param(Query& query, const std::optional<bool>& val);
Query& operator<<(Query& query, const char* str);
Query& operator<<(Query& query, const std::string& str);
diff --git a/src/database/select_query.hpp b/src/database/select_query.hpp
index cd9943c..5a17f38 100644
--- a/src/database/select_query.hpp
+++ b/src/database/select_query.hpp
@@ -29,15 +29,16 @@ extract_row_value(Statement& statement, const int i)
}
template <typename T>
-typename std::enable_if<std::is_same<std::optional<bool>, T>::value, T>::type
+typename std::enable_if<std::is_same<OptionalBool, T>::value, T>::type
extract_row_value(Statement& statement, const int i)
{
const auto integer = statement.get_column_int(i);
+ OptionalBool result;
if (integer > 0)
- return true;
+ result.set_value(true);
else if (integer < 0)
- return false;
- return std::nullopt;
+ result.set_value(false);
+ return result;
}
template <std::size_t N=0, typename... T>