diff options
author | louiz’ <louiz@louiz.org> | 2017-12-16 16:32:32 +0100 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2017-12-16 16:32:32 +0100 |
commit | 2c4016a4898a050c7f6ebd1843b265e209da1704 (patch) | |
tree | b6c57d4fa446fe588cac6999c498dc1d7587dd9e /src/database/select_query.hpp | |
parent | aaa9de8fe2c67b67310b7ba78c607bddbf4b25bf (diff) | |
parent | b1f850b6395610c738a8e58abcdf2abfca3edd4e (diff) | |
download | biboumi-2c4016a4898a050c7f6ebd1843b265e209da1704.tar.gz biboumi-2c4016a4898a050c7f6ebd1843b265e209da1704.tar.bz2 biboumi-2c4016a4898a050c7f6ebd1843b265e209da1704.tar.xz biboumi-2c4016a4898a050c7f6ebd1843b265e209da1704.zip |
Merge branch 'postgresql' into 'master'
Add postgresql support
Closes #3237
See merge request louiz/biboumi!18
Diffstat (limited to 'src/database/select_query.hpp')
-rw-r--r-- | src/database/select_query.hpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/database/select_query.hpp b/src/database/select_query.hpp index 872001c..837a866 100644 --- a/src/database/select_query.hpp +++ b/src/database/select_query.hpp @@ -1,5 +1,7 @@ #pragma once +#include <database/engine.hpp> + #include <database/statement.hpp> #include <database/query.hpp> #include <logger/logger.hpp> @@ -10,32 +12,27 @@ #include <vector> #include <string> -#include <sqlite3.h> - using namespace std::string_literals; template <typename T> -typename std::enable_if<std::is_integral<T>::value, sqlite3_int64>::type +typename std::enable_if<std::is_integral<T>::value, std::int64_t>::type extract_row_value(Statement& statement, const int i) { - return sqlite3_column_int64(statement.get(), i); + return statement.get_column_int64(i); } template <typename T> 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); - const unsigned char* str = sqlite3_column_text(statement.get(), i); - std::string result(reinterpret_cast<const char*>(str), static_cast<std::size_t>(size)); - return result; + return statement.get_column_text(i); } 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); + const auto integer = statement.get_column_int(i); OptionalBool result; if (integer > 0) result.set_value(true); @@ -109,16 +106,21 @@ struct SelectQuery: public Query return *this; } - auto execute(sqlite3* db) + auto execute(DatabaseEngine& db) { - auto statement = this->prepare(db); std::vector<Row<T...>> rows; - while (sqlite3_step(statement.get()) == SQLITE_ROW) + + auto statement = db.prepare(this->body); + statement->bind(std::move(this->params)); + + while (statement->step() == StepResult::Row) { + log_debug("one result."); Row<T...> row(this->table_name); - extract_row_values(row, statement); + extract_row_values(row, *statement); rows.push_back(row); } + return rows; } |