diff options
Diffstat (limited to 'src/database/select_query.hpp')
-rw-r--r-- | src/database/select_query.hpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/database/select_query.hpp b/src/database/select_query.hpp index 93d69ed..837b064 100644 --- a/src/database/select_query.hpp +++ b/src/database/select_query.hpp @@ -5,6 +5,8 @@ #include <logger/logger.hpp> #include <database/row.hpp> +#include <utils/optional_bool.hpp> + #include <vector> #include <string> @@ -20,7 +22,7 @@ extract_row_value(Statement& statement, const int i) } template <typename T> -typename std::enable_if<std::is_same<std::string, T>::value, std::string>::type +typename std::enable_if<std::is_same<std::string, T>::value, T>::type extract_row_value(Statement& statement, const int i) { const auto size = sqlite3_column_bytes(statement.get(), i); @@ -29,6 +31,19 @@ extract_row_value(Statement& statement, const int i) return result; } +template <typename T> +typename std::enable_if<std::is_same<OptionalBool, T>::value, T>::type +extract_row_value(Statement& statement, const int i) +{ + const auto integer = sqlite3_column_int(statement.get(), i); + OptionalBool result; + if (integer > 0) + result.set_value(true); + else if (integer < 0) + result.set_value(false); + return result; +} + template <std::size_t N=0, typename... T> typename std::enable_if<N < sizeof...(T), void>::type extract_row_values(Row<T...>& row, Statement& statement) |