From 81c77a58f46bbf63e9fd39c3098bde804f53572e Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Fri, 8 Nov 2013 09:09:52 +0100 Subject: [PATCH] Even moe function tests and a few corrections --- include/sqlpp11/any.h | 2 +- include/sqlpp11/boolean.h | 3 ++ include/sqlpp11/detail/basic_operators.h | 21 ++++++---- include/sqlpp11/floating_point.h | 4 ++ include/sqlpp11/integral.h | 4 ++ include/sqlpp11/some.h | 2 +- include/sqlpp11/text.h | 2 + include/sqlpp11/type_traits.h | 2 +- tests/FunctionTest.cpp | 50 +++++++++++++++++++++--- 9 files changed, 73 insertions(+), 17 deletions(-) diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index ec01a4e0..43b6f3c4 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -42,7 +42,7 @@ namespace sqlpp struct _value_type: public Select::_value_type::_base_value_type { - using _is_nameless_expression = std::true_type; // must not be named + using _is_multi_expression = std::true_type; // must not be named }; struct _name_t diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index bf38f541..00ffbc3a 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -126,17 +126,20 @@ namespace sqlpp template binary_expression_t::type> operator and(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) }; } template binary_expression_t::type> operator or(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) }; } not_t operator not() const { + static_assert(not is_multi_expression_t::value, "multi-expression cannot be as operand for operator not"); return { *static_cast(this) }; } }; diff --git a/include/sqlpp11/detail/basic_operators.h b/include/sqlpp11/detail/basic_operators.h index d0a5a5b1..630555eb 100644 --- a/include/sqlpp11/detail/basic_operators.h +++ b/include/sqlpp11/detail/basic_operators.h @@ -65,13 +65,6 @@ namespace sqlpp static constexpr const char* _name = ">"; }; - struct is_not_null_ - { - using _value_type = boolean; - static constexpr const char* _name = "IS NOT NULL"; - }; - - // basic operators template class Constraint> struct basic_operators @@ -79,55 +72,65 @@ namespace sqlpp template 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) }; } 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) }; } 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) }; } 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) }; } 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) }; } 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) }; } is_null_t is_null() const { + static_assert(not is_multi_expression_t::value, "multi-expression cannot be used with is_null()"); return { *static_cast(this) }; } is_null_t is_not_null() const { + static_assert(not is_multi_expression_t::value, "multi-expression cannot be used with is_not_null()"); return { *static_cast(this) }; } sort_order_t asc() { + static_assert(not is_multi_expression_t::value, "multi-expression cannot be used for sorting"); return { *static_cast(this) }; } sort_order_t desc() { + static_assert(not is_multi_expression_t::value, "multi-expression cannot be used for sorting"); return { *static_cast(this) }; } @@ -135,19 +138,21 @@ namespace sqlpp template in_t::type...> in(T&&... t) const { + static_assert(not is_multi_expression_t::value, "multi-expression cannot be used with in()"); return { *static_cast(this), std::forward(t)... }; } template in_t::type...> not_in(T&&... t) const { + static_assert(not is_multi_expression_t::value, "multi-expression cannot with be used with not_in()"); return { *static_cast(this), std::forward(t)... }; } template expression_alias_t::type> as(alias_provider&&) { - static_assert(not is_nameless_expression_t::value, "expression cannot have a name, e.g. like any()"); + static_assert(not is_multi_expression_t::value, "multi-expression cannot have a name"); return { *static_cast(this) }; } diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index b4319127..65215ac5 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -128,24 +128,28 @@ namespace sqlpp 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) }; } 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) }; } 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) }; } 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) }; } diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 19d7fc71..cbf0b298 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -131,24 +131,28 @@ namespace sqlpp template binary_expression_t, typename _constraint::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) }; } template binary_expression_t, typename _constraint::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) }; } template binary_expression_t, typename _constraint::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) }; } 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) }; } diff --git a/include/sqlpp11/some.h b/include/sqlpp11/some.h index 976a8285..0a538822 100644 --- a/include/sqlpp11/some.h +++ b/include/sqlpp11/some.h @@ -42,7 +42,7 @@ namespace sqlpp struct _value_type: public Select::_value_type::_base_value_type { - using _is_nameless_expression = std::true_type; // must not be named + using _is_multi_expression = std::true_type; // must not be named }; struct _name_t diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 33faec34..8ba3d6b7 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -106,12 +106,14 @@ namespace sqlpp template detail::concat_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) }; } template detail::like_t::type> like(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) }; } diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index c4917c58..ef495acf 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -84,7 +84,7 @@ namespace sqlpp SQLPP_IS_VALUE_TRAIT_GENERATOR(value); SQLPP_IS_VALUE_TRAIT_GENERATOR(expression); SQLPP_IS_VALUE_TRAIT_GENERATOR(named_expression); - SQLPP_IS_VALUE_TRAIT_GENERATOR(nameless_expression); + SQLPP_IS_VALUE_TRAIT_GENERATOR(multi_expression); SQLPP_IS_VALUE_TRAIT_GENERATOR(alias); // FIXME: Is this really part of the value? SQLPP_IS_VALUE_TRAIT_GENERATOR(select_flag); diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp index bb58d246..1ec044f4 100644 --- a/tests/FunctionTest.cpp +++ b/tests/FunctionTest.cpp @@ -60,6 +60,25 @@ int main() static_assert(not sqlpp::is_text_t::value, "type requirement"); } + // Test in with value list + { + using TI = decltype(t.alpha.in(sqlpp::value_list(std::vector({1, 2, 3})))); + using TF = decltype(f.omega.in(sqlpp::value_list(std::vector({1.0, 2.0, 3.0})))); + using TT = decltype(t.beta.in(sqlpp::value_list(std::vector({"a", "b", "c"})))); + static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_boolean_t::value, "type requirement"); + static_assert(not sqlpp::is_numeric_t::value, "type requirement"); + static_assert(not sqlpp::is_text_t::value, "type requirement"); + static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_boolean_t::value, "type requirement"); + static_assert(not sqlpp::is_numeric_t::value, "type requirement"); + static_assert(not sqlpp::is_text_t::value, "type requirement"); + static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_boolean_t::value, "type requirement"); + static_assert(not sqlpp::is_numeric_t::value, "type requirement"); + static_assert(not sqlpp::is_text_t::value, "type requirement"); + } + // Test not_in { using TI = decltype(t.alpha.not_in(1, 2, 3)); @@ -79,6 +98,25 @@ int main() static_assert(not sqlpp::is_text_t::value, "type requirement"); } + // Test not in with value list + { + using TI = decltype(t.alpha.not_in(sqlpp::value_list(std::vector({1, 2, 3})))); + using TF = decltype(f.omega.not_in(sqlpp::value_list(std::vector({1.0, 2.0, 3.0})))); + using TT = decltype(t.beta.not_in(sqlpp::value_list(std::vector({"a", "b", "c"})))); + static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_boolean_t::value, "type requirement"); + static_assert(not sqlpp::is_numeric_t::value, "type requirement"); + static_assert(not sqlpp::is_text_t::value, "type requirement"); + static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_boolean_t::value, "type requirement"); + static_assert(not sqlpp::is_numeric_t::value, "type requirement"); + static_assert(not sqlpp::is_text_t::value, "type requirement"); + static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_boolean_t::value, "type requirement"); + static_assert(not sqlpp::is_numeric_t::value, "type requirement"); + static_assert(not sqlpp::is_text_t::value, "type requirement"); + } + // Test like { using TT = decltype(t.beta.like("%c%")); @@ -149,17 +187,17 @@ int main() using TT = decltype(any(select(t.beta).from(t))); using TF = decltype(any(select(f.omega).from(t))); static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); - static_assert(sqlpp::is_nameless_expression_t::value, "type requirement"); + static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); - static_assert(sqlpp::is_nameless_expression_t::value, "type requirement"); + static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "tFpe requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); - static_assert(sqlpp::is_nameless_expression_t::value, "type requirement"); + static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); @@ -172,18 +210,18 @@ int main() using TT = decltype(some(select(t.beta).from(t))); using TF = decltype(some(select(f.omega).from(t))); static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); - static_assert(sqlpp::is_nameless_expression_t::value, "type requirement"); + static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); - static_assert(sqlpp::is_nameless_expression_t::value, "type requirement"); + static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); - static_assert(sqlpp::is_nameless_expression_t::value, "type requirement"); + static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); static_assert(sqlpp::is_text_t::value, "type requirement");