diff --git a/include/sqlpp11/detail/basic_operators.h b/include/sqlpp11/detail/basic_operators.h index 7498ea05..a7ee0ca0 100644 --- a/include/sqlpp11/detail/basic_operators.h +++ b/include/sqlpp11/detail/basic_operators.h @@ -73,27 +73,27 @@ namespace sqlpp equal_t::type> operator==(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template not_equal_t::type> operator!=(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template binary_expression_t::type> operator<(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template binary_expression_t::type> operator<=(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index 1f954f88..9c59dc70 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -75,10 +75,9 @@ namespace sqlpp { using _value_type = detail::boolean; - template - equal_t(L&& l, R&& r): - _lhs(std::forward(l)), - _rhs(std::forward(r)) + equal_t(Lhs lhs, Rhs rhs): + _lhs(lhs), + _rhs(rhs) {} equal_t(const equal_t&) = default; @@ -87,7 +86,6 @@ namespace sqlpp equal_t& operator=(equal_t&&) = default; ~equal_t() = default; - private: Lhs _lhs; Rhs _rhs; }; @@ -97,7 +95,7 @@ namespace sqlpp { using T = equal_t; - static Context& interpret(const T& t, Context& context) + static Context& _(const T& t, Context& context) { context << "("; interpret(t._lhs, context); @@ -120,10 +118,9 @@ namespace sqlpp { using _value_type = detail::boolean; - template - not_equal_t(L&& l, R&& r): - _lhs(std::forward(l)), - _rhs(std::forward(r)) + not_equal_t(Lhs lhs, Rhs rhs): + _lhs(lhs), + _rhs(rhs) {} not_equal_t(const not_equal_t&) = default; @@ -141,7 +138,7 @@ namespace sqlpp { using T = not_equal_t; - static Context& interpret(const T& t, Context& context) + static Context& _(const T& t, Context& context) { context << "("; interpret(t._lhs, context); @@ -182,7 +179,7 @@ namespace sqlpp { using T = not_t; - static Context& interpret(const T& t, Context& context) + static Context& _(const T& t, Context& context) { context << "("; if (trivial_value_is_null_t::value and t._lhs._is_trivial()) @@ -225,7 +222,7 @@ namespace sqlpp { using T = binary_expression_t; - static Context& interpret(const T& t, Context& context) + static Context& _(const T& t, Context& context) { context << "("; interpret(t._lhs, context); diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 782f1ac4..a4d736d8 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -62,22 +62,30 @@ namespace sqlpp template void serialize(std::ostream& os, Db& db) const { - if (sizeof...(Expr) == 0 and _dynamic_expressions.empty()) - return; - os << " WHERE "; - detail::serialize_tuple(os, db, _expressions, " AND "); - _dynamic_expressions.serialize(os, db, " AND ", sizeof...(Expr) == 0); } - size_t _set_parameter_index(size_t index) - { - index = set_parameter_index(_expressions, index); - return index; - } - _parameter_tuple_t _expressions; detail::serializable_list _dynamic_expressions; }; + + template + struct interpreter_t> + { + using T = where_t; + + static Context& _(const T& t, Context& context) + { + if (sizeof...(Expr) == 0 and t._dynamic_expressions.empty()) + return context; + context << " WHERE "; + interpret_tuple(t._expressions, " AND ", context); + if (sizeof...(Expr) and not t._dynamic_expressions.empty()) + context << " AND "; + interpret_serializable_list(t._dynamic_expressions, " AND ", context); + return context; + } + }; + } #endif diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index 7e02922e..bd80f178 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -39,11 +39,13 @@ int main() interpret(t.alpha, printer).flush(); interpret(t.alpha = 7, printer).flush(); + interpret(t.alpha == 7, printer).flush(); sqlpp::text_operand o = {"kaesekuchen"}; interpret(t.beta + "kaesekuchen", printer).flush(); interpret(select(sqlpp::distinct, t.alpha, t.beta), printer).flush(); interpret(select(sqlpp::distinct, t.alpha, t.beta).from(t), printer).flush(); + interpret(select(sqlpp::distinct, t.alpha, t.beta).from(t).where(t.alpha == 3), printer).flush(); return 0; }