0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Even moe function tests and a few corrections

This commit is contained in:
Roland Bock 2013-11-08 09:09:52 +01:00
parent 813549690e
commit 81c77a58f4
9 changed files with 73 additions and 17 deletions

View File

@ -42,7 +42,7 @@ namespace sqlpp
struct _value_type: public Select::_value_type::_base_value_type 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 struct _name_t

View File

@ -126,17 +126,20 @@ namespace sqlpp
template<typename T> template<typename T>
binary_expression_t<Base, and_, typename _constraint<T>::type> operator and(T&& t) const binary_expression_t<Base, and_, typename _constraint<T>::type> operator and(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, or_, typename _constraint<T>::type> operator or(T&& t) const binary_expression_t<Base, or_, typename _constraint<T>::type> operator or(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
not_t<Base> operator not() const not_t<Base> operator not() const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be as operand for operator not");
return { *static_cast<const Base*>(this) }; return { *static_cast<const Base*>(this) };
} }
}; };

View File

@ -65,13 +65,6 @@ namespace sqlpp
static constexpr const char* _name = ">"; static constexpr const char* _name = ">";
}; };
struct is_not_null_
{
using _value_type = boolean;
static constexpr const char* _name = "IS NOT NULL";
};
// basic operators // basic operators
template<typename Base, template<typename> class Constraint> template<typename Base, template<typename> class Constraint>
struct basic_operators struct basic_operators
@ -79,55 +72,65 @@ namespace sqlpp
template<typename T> template<typename T>
equal_t<Base, typename Constraint<T>::type> operator==(T&& t) const equal_t<Base, typename Constraint<T>::type> operator==(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
not_equal_t<Base, typename Constraint<T>::type> operator!=(T&& t) const not_equal_t<Base, typename Constraint<T>::type> operator!=(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, lt_, typename Constraint<T>::type> operator<(T&& t) const binary_expression_t<Base, lt_, typename Constraint<T>::type> operator<(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, le_, typename Constraint<T>::type> operator<=(T&& t) const binary_expression_t<Base, le_, typename Constraint<T>::type> operator<=(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, ge_, typename Constraint<T>::type> operator>=(T&& t) const binary_expression_t<Base, ge_, typename Constraint<T>::type> operator>=(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, gt_, typename Constraint<T>::type> operator>(T&& t) const binary_expression_t<Base, gt_, typename Constraint<T>::type> operator>(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
is_null_t<true, boolean, Base> is_null() const is_null_t<true, boolean, Base> is_null() const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used with is_null()");
return { *static_cast<const Base*>(this) }; return { *static_cast<const Base*>(this) };
} }
is_null_t<false, boolean, Base> is_not_null() const is_null_t<false, boolean, Base> is_not_null() const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used with is_not_null()");
return { *static_cast<const Base*>(this) }; return { *static_cast<const Base*>(this) };
} }
sort_order_t<Base, sort_type::asc> asc() sort_order_t<Base, sort_type::asc> asc()
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used for sorting");
return { *static_cast<const Base*>(this) }; return { *static_cast<const Base*>(this) };
} }
sort_order_t<Base, sort_type::desc> desc() sort_order_t<Base, sort_type::desc> desc()
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used for sorting");
return { *static_cast<const Base*>(this) }; return { *static_cast<const Base*>(this) };
} }
@ -135,19 +138,21 @@ namespace sqlpp
template<typename... T> template<typename... T>
in_t<true, boolean, Base, typename Constraint<T>::type...> in(T&&... t) const in_t<true, boolean, Base, typename Constraint<T>::type...> in(T&&... t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used with in()");
return { *static_cast<const Base*>(this), std::forward<T>(t)... }; return { *static_cast<const Base*>(this), std::forward<T>(t)... };
} }
template<typename... T> template<typename... T>
in_t<false, boolean, Base, typename Constraint<T>::type...> not_in(T&&... t) const in_t<false, boolean, Base, typename Constraint<T>::type...> not_in(T&&... t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot with be used with not_in()");
return { *static_cast<const Base*>(this), std::forward<T>(t)... }; return { *static_cast<const Base*>(this), std::forward<T>(t)... };
} }
template<typename alias_provider> template<typename alias_provider>
expression_alias_t<Base, typename std::decay<alias_provider>::type> as(alias_provider&&) expression_alias_t<Base, typename std::decay<alias_provider>::type> as(alias_provider&&)
{ {
static_assert(not is_nameless_expression_t<Base>::value, "expression cannot have a name, e.g. like any()"); static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot have a name");
return { *static_cast<const Base*>(this) }; return { *static_cast<const Base*>(this) };
} }

View File

@ -128,24 +128,28 @@ namespace sqlpp
template<typename T> template<typename T>
binary_expression_t<Base, plus_, typename _constraint<T>::type> operator +(T&& t) const binary_expression_t<Base, plus_, typename _constraint<T>::type> operator +(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, minus_, typename _constraint<T>::type> operator -(T&& t) const binary_expression_t<Base, minus_, typename _constraint<T>::type> operator -(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, multiplies_, typename _constraint<T>::type> operator *(T&& t) const binary_expression_t<Base, multiplies_, typename _constraint<T>::type> operator *(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, divides_, typename _constraint<T>::type> operator /(T&& t) const binary_expression_t<Base, divides_, typename _constraint<T>::type> operator /(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }

View File

@ -131,24 +131,28 @@ namespace sqlpp
template<typename T> template<typename T>
binary_expression_t<Base, plus_<T>, typename _constraint<T>::type> operator +(T&& t) const binary_expression_t<Base, plus_<T>, typename _constraint<T>::type> operator +(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, minus_<T>, typename _constraint<T>::type> operator -(T&& t) const binary_expression_t<Base, minus_<T>, typename _constraint<T>::type> operator -(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, multiplies_<T>, typename _constraint<T>::type> operator *(T&& t) const binary_expression_t<Base, multiplies_<T>, typename _constraint<T>::type> operator *(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
binary_expression_t<Base, divides_, typename _constraint<T>::type> operator /(T&& t) const binary_expression_t<Base, divides_, typename _constraint<T>::type> operator /(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }

View File

@ -42,7 +42,7 @@ namespace sqlpp
struct _value_type: public Select::_value_type::_base_value_type 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 struct _name_t

View File

@ -106,12 +106,14 @@ namespace sqlpp
template<typename T> template<typename T>
detail::concat_t<Base, typename _constraint<T>::type> operator+(T&& t) const detail::concat_t<Base, typename _constraint<T>::type> operator+(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }
template<typename T> template<typename T>
detail::like_t<boolean, Base, typename _constraint<T>::type> like(T&& t) const detail::like_t<boolean, Base, typename _constraint<T>::type> like(T&& t) const
{ {
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) }; return { *static_cast<const Base*>(this), std::forward<T>(t) };
} }

View File

@ -84,7 +84,7 @@ namespace sqlpp
SQLPP_IS_VALUE_TRAIT_GENERATOR(value); SQLPP_IS_VALUE_TRAIT_GENERATOR(value);
SQLPP_IS_VALUE_TRAIT_GENERATOR(expression); SQLPP_IS_VALUE_TRAIT_GENERATOR(expression);
SQLPP_IS_VALUE_TRAIT_GENERATOR(named_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(alias); // FIXME: Is this really part of the value?
SQLPP_IS_VALUE_TRAIT_GENERATOR(select_flag); SQLPP_IS_VALUE_TRAIT_GENERATOR(select_flag);

View File

@ -60,6 +60,25 @@ int main()
static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement");
} }
// Test in with value list
{
using TI = decltype(t.alpha.in(sqlpp::value_list(std::vector<int>({1, 2, 3}))));
using TF = decltype(f.omega.in(sqlpp::value_list(std::vector<float>({1.0, 2.0, 3.0}))));
using TT = decltype(t.beta.in(sqlpp::value_list(std::vector<std::string>({"a", "b", "c"}))));
static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TI>::value, "type requirement");
static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TF>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TF>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TF>::value, "type requirement");
static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TT>::value, "type requirement");
}
// Test not_in // Test not_in
{ {
using TI = decltype(t.alpha.not_in(1, 2, 3)); using TI = decltype(t.alpha.not_in(1, 2, 3));
@ -79,6 +98,25 @@ int main()
static_assert(not sqlpp::is_text_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TT>::value, "type requirement");
} }
// Test not in with value list
{
using TI = decltype(t.alpha.not_in(sqlpp::value_list(std::vector<int>({1, 2, 3}))));
using TF = decltype(f.omega.not_in(sqlpp::value_list(std::vector<float>({1.0, 2.0, 3.0}))));
using TT = decltype(t.beta.not_in(sqlpp::value_list(std::vector<std::string>({"a", "b", "c"}))));
static_assert(sqlpp::is_named_expression_t<TI>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TI>::value, "type requirement");
static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TF>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TF>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TF>::value, "type requirement");
static_assert(sqlpp::is_named_expression_t<TF>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TT>::value, "type requirement");
}
// Test like // Test like
{ {
using TT = decltype(t.beta.like("%c%")); using TT = decltype(t.beta.like("%c%"));
@ -149,17 +187,17 @@ int main()
using TT = decltype(any(select(t.beta).from(t))); using TT = decltype(any(select(t.beta).from(t)));
using TF = decltype(any(select(f.omega).from(t))); using TF = decltype(any(select(f.omega).from(t)));
static_assert(not sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TI>::value, "type requirement");
static_assert(sqlpp::is_nameless_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TI>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TF>::value, "type requirement");
static_assert(sqlpp::is_nameless_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TF>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TF>::value, "tFpe requirement"); static_assert(sqlpp::is_numeric_t<TF>::value, "tFpe requirement");
static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement");
static_assert(not sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TT>::value, "type requirement");
static_assert(sqlpp::is_nameless_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_integral_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_integral_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_floating_point_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TT>::value, "type requirement");
@ -172,18 +210,18 @@ int main()
using TT = decltype(some(select(t.beta).from(t))); using TT = decltype(some(select(t.beta).from(t)));
using TF = decltype(some(select(f.omega).from(t))); using TF = decltype(some(select(f.omega).from(t)));
static_assert(not sqlpp::is_named_expression_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TI>::value, "type requirement");
static_assert(sqlpp::is_nameless_expression_t<TI>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TI>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement"); static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TI>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TI>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement"); static_assert(sqlpp::is_numeric_t<TF>::value, "type requirement");
static_assert(not sqlpp::is_named_expression_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TF>::value, "type requirement");
static_assert(sqlpp::is_nameless_expression_t<TF>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TF>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement"); static_assert(sqlpp::is_floating_point_t<TF>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TF>::value, "type requirement"); static_assert(not sqlpp::is_text_t<TF>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_named_expression_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_named_expression_t<TT>::value, "type requirement");
static_assert(sqlpp::is_nameless_expression_t<TT>::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_integral_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_integral_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_floating_point_t<TT>::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t<TT>::value, "type requirement");
static_assert(sqlpp::is_text_t<TT>::value, "type requirement"); static_assert(sqlpp::is_text_t<TT>::value, "type requirement");