summaryrefslogtreecommitdiff
path: root/src/database/update_query.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/database/update_query.hpp')
-rw-r--r--src/database/update_query.hpp51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/database/update_query.hpp b/src/database/update_query.hpp
index 0ee2bd9..a29ac3f 100644
--- a/src/database/update_query.hpp
+++ b/src/database/update_query.hpp
@@ -39,25 +39,27 @@ struct UpdateQuery: public Query
}
template <int N=0, typename... T>
- void insert_col_name_and_value(const std::tuple<T...>& columns)
+ typename std::enable_if<N < sizeof...(T), void>::type
+ insert_col_name_and_value(const std::tuple<T...>& columns)
{
- if constexpr(N < sizeof...(T))
- {
- using ColumnType = std::decay_t<decltype(std::get<N>(columns))>;
-
- if (!std::is_same<ColumnType, Id>::value)
- {
- this->body += ColumnType::name + "=$"s
- + std::to_string(this->current_param);
- this->current_param++;
+ using ColumnType = std::decay_t<decltype(std::get<N>(columns))>;
- if (N < (sizeof...(T) - 1))
- this->body += ", ";
- }
+ if (!std::is_same<ColumnType, Id>::value)
+ {
+ this->body += ColumnType::name + "=$"s + std::to_string(this->current_param);
+ this->current_param++;
- this->insert_col_name_and_value<N + 1>(columns);
+ if (N < (sizeof...(T) - 1))
+ this->body += ", ";
}
+
+ this->insert_col_name_and_value<N+1>(columns);
}
+ template <int N=0, typename... T>
+ typename std::enable_if<N == sizeof...(T), void>::type
+ insert_col_name_and_value(const std::tuple<T...>&)
+ {}
+
template <typename... T>
void execute(DatabaseEngine& db, const std::tuple<T...>& columns)
@@ -74,20 +76,23 @@ struct UpdateQuery: public Query
}
template <int N=0, typename... T>
- void bind_param(const std::tuple<T...>& columns, Statement& statement, int index=1)
+ typename std::enable_if<N < sizeof...(T), void>::type
+ bind_param(const std::tuple<T...>& columns, Statement& statement, int index=1)
{
- if constexpr(N < sizeof...(T))
- {
- auto&& column = std::get<N>(columns);
- using ColumnType = std::decay_t<decltype(column)>;
+ auto&& column = std::get<N>(columns);
+ using ColumnType = std::decay_t<decltype(column)>;
- if (!std::is_same<ColumnType, Id>::value)
- actual_bind(statement, column.value, index++);
+ if (!std::is_same<ColumnType, Id>::value)
+ actual_bind(statement, column.value, index++);
- this->bind_param<N + 1>(columns, statement, index);
- }
+ this->bind_param<N+1>(columns, statement, index);
}
+ template <int N=0, typename... T>
+ typename std::enable_if<N == sizeof...(T), void>::type
+ bind_param(const std::tuple<T...>&, Statement&, int)
+ {}
+
template <typename... T>
void bind_id(const std::tuple<T...>& columns, Statement& statement)
{