From c042d99643f50ed21a21b1316e6e34f7f15bd315 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Wed, 18 Sep 2013 15:19:47 +0200 Subject: [PATCH] Introduced unary function templates which use one pair of braces less This is required for sqlite which cannot parse SELECT EXISTS((SELECT 1)) --- include/sqlpp11/expression.h | 65 ++++++++++++++++++++++++++++++++++++ include/sqlpp11/functions.h | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index 7b0e473e..2f1673fc 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -315,6 +315,38 @@ namespace sqlpp std::tuple _rhs; }; + template + struct unary_function_t: public F::_value_type::template operators> + { + using _value_type = typename F::_value_type; + + unary_function_t(Rhs&& r): + _rhs(std::move(r)) + {} + + unary_function_t(const Rhs& r): + _rhs(r) + {} + + unary_function_t(const unary_function_t&) = default; + unary_function_t(unary_function_t&&) = default; + unary_function_t& operator=(const unary_function_t&) = default; + unary_function_t& operator=(unary_function_t&&) = default; + ~unary_function_t() = default; + + template + void serialize(std::ostream& os, Db& db) const + { + os << F::_name; + os << "("; + _rhs.serialize(os, db); + os << ")"; + } + + private: + Rhs _rhs; + }; + template struct named_nary_function_t: public F::_value_type::template operators> { @@ -347,6 +379,39 @@ namespace sqlpp private: std::tuple _rhs; }; + + template + struct named_unary_function_t: public F::_value_type::template operators> + { + using _value_type = typename F::_value_type; + using _name_t = typename F::_name_t; + + named_unary_function_t(Rhs&& r): + _rhs(std::move(r)) + {} + + named_unary_function_t(const Rhs& r): + _rhs(r) + {} + + named_unary_function_t(const named_unary_function_t&) = default; + named_unary_function_t(named_unary_function_t&&) = default; + named_unary_function_t& operator=(const named_unary_function_t&) = default; + named_unary_function_t& operator=(named_unary_function_t&&) = default; + ~named_unary_function_t() = default; + + template + void serialize(std::ostream& os, Db& db) const + { + os << F::_name_t::_get_name(); + os << "("; + _rhs.serialize(os, db); + os << ")"; + } + + private: + Rhs _rhs; + }; } #endif diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index d1c48020..87225f0e 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -60,7 +60,7 @@ namespace sqlpp };\ };\ \ - using type = named_nary_function_t<_op, _operand>;\ + using type = named_unary_function_t<_op, _operand>;\ };\ }\ template\