mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Add dynamic to AND and OR
This commit is contained in:
parent
700c263f90
commit
7cc4e45abd
@ -29,11 +29,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
#include <sqlpp11/operator/as_expression.h>
|
#include <sqlpp11/operator/as_expression.h>
|
||||||
//#include <sqlpp11/bad_expression.h>
|
#include <sqlpp11/dynamic.h>
|
||||||
//#include <sqlpp11/embrace.h>
|
//#include <sqlpp11/embrace.h>
|
||||||
//#include <sqlpp11/to_sql_string.h>
|
//#include <sqlpp11/to_sql_string.h>
|
||||||
#include <sqlpp11/type_traits.h>
|
#include <sqlpp11/type_traits.h>
|
||||||
//#include <sqlpp11/wrapped_static_assert.h>
|
|
||||||
|
|
||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
@ -65,7 +64,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
template <typename L, typename Operator, typename R>
|
template <typename L, typename Operator, typename R>
|
||||||
struct value_type_of<logical_expression<L, Operator, R>>
|
struct value_type_of<logical_expression<L, Operator, R>>
|
||||||
: std::conditional<sqlpp::is_optional<value_type_of_t<L>>::value or sqlpp::is_optional<value_type_of_t<R>>::value,
|
: std::conditional<sqlpp::is_optional<value_type_of_t<L>>::value or sqlpp::is_optional<value_type_of_t<remove_dynamic_t<R>>>::value,
|
||||||
sqlpp::compat::optional<boolean>,
|
sqlpp::compat::optional<boolean>,
|
||||||
boolean>
|
boolean>
|
||||||
{
|
{
|
||||||
@ -141,7 +140,8 @@ namespace sqlpp
|
|||||||
static constexpr auto symbol = " AND ";
|
static constexpr auto symbol = " AND ";
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_logical_args<L, R>>
|
#warning: need tests with dynamic AND/OR
|
||||||
|
template <typename L, typename R, typename = check_logical_args<L, remove_dynamic_t<R>>>
|
||||||
constexpr auto operator and(L l, R r) -> logical_expression<L, logical_and, R>
|
constexpr auto operator and(L l, R r) -> logical_expression<L, logical_and, R>
|
||||||
{
|
{
|
||||||
return {std::move(l), std::move(r)};
|
return {std::move(l), std::move(r)};
|
||||||
@ -152,7 +152,7 @@ namespace sqlpp
|
|||||||
static constexpr auto symbol = " OR ";
|
static constexpr auto symbol = " OR ";
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename L, typename R, typename = check_logical_args<L, R>>
|
template <typename L, typename R, typename = check_logical_args<L, remove_dynamic_t<R>>>
|
||||||
constexpr auto operator||(L l, R r) -> logical_expression<L, logical_or, R>
|
constexpr auto operator||(L l, R r) -> logical_expression<L, logical_or, R>
|
||||||
{
|
{
|
||||||
return {std::move(l), std::move(r)};
|
return {std::move(l), std::move(r)};
|
||||||
|
@ -47,6 +47,16 @@ namespace sqlpp
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#warning: We should switch context and arg to allow for this to have fewer error messages
|
||||||
|
/*
|
||||||
|
template <typename Context, typename X = void>
|
||||||
|
auto serialize(Context& context, ...) -> Context&
|
||||||
|
{
|
||||||
|
static_assert(wrong_t<X>::value, "Missing specialization");
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
template <typename Context>
|
template <typename Context>
|
||||||
auto serialize(const bool& t, Context& context) -> Context&
|
auto serialize(const bool& t, Context& context) -> Context&
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
set(test_files
|
set(test_files
|
||||||
|
logical_expression.cpp
|
||||||
Any.cpp
|
Any.cpp
|
||||||
As.cpp
|
As.cpp
|
||||||
Avg.cpp
|
Avg.cpp
|
||||||
|
@ -23,14 +23,10 @@
|
|||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MockDb.h"
|
|
||||||
#include "Sample.h"
|
|
||||||
#include <sqlpp11/sqlpp11.h>
|
#include <sqlpp11/sqlpp11.h>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
auto db = MockDb{};
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using is_bool = std::is_same<sqlpp::value_type_of_t<T>, sqlpp::boolean>;
|
using is_bool = std::is_same<sqlpp::value_type_of_t<T>, sqlpp::boolean>;
|
||||||
|
|
||||||
@ -48,18 +44,30 @@ void test_logical_expression(Value v)
|
|||||||
static_assert(is_bool<decltype(v_not_null and v_not_null)>::value, "");
|
static_assert(is_bool<decltype(v_not_null and v_not_null)>::value, "");
|
||||||
static_assert(is_bool<decltype(v_not_null or v_not_null)>::value, "");
|
static_assert(is_bool<decltype(v_not_null or v_not_null)>::value, "");
|
||||||
|
|
||||||
// Compare non-nullable with nullable.
|
static_assert(is_bool<decltype(v_not_null and dynamic(true, v_not_null))>::value, "");
|
||||||
|
static_assert(is_bool<decltype(v_not_null or dynamic(true, v_not_null))>::value, "");
|
||||||
|
|
||||||
|
// Compare nullable with non-nullable.
|
||||||
static_assert(is_maybe_bool<decltype(v_maybe_null and v_not_null)>::value, "");
|
static_assert(is_maybe_bool<decltype(v_maybe_null and v_not_null)>::value, "");
|
||||||
static_assert(is_maybe_bool<decltype(v_maybe_null or v_not_null)>::value, "");
|
static_assert(is_maybe_bool<decltype(v_maybe_null or v_not_null)>::value, "");
|
||||||
|
|
||||||
// Compare nullable with non-nullable.
|
static_assert(is_maybe_bool<decltype(v_maybe_null and dynamic(true, v_not_null))>::value, "");
|
||||||
|
static_assert(is_maybe_bool<decltype(v_maybe_null or dynamic(true, v_not_null))>::value, "");
|
||||||
|
|
||||||
|
// Compare non-nullable with nullable.
|
||||||
static_assert(is_maybe_bool<decltype(v_not_null and v_maybe_null)>::value, "");
|
static_assert(is_maybe_bool<decltype(v_not_null and v_maybe_null)>::value, "");
|
||||||
static_assert(is_maybe_bool<decltype(v_not_null or v_maybe_null)>::value, "");
|
static_assert(is_maybe_bool<decltype(v_not_null or v_maybe_null)>::value, "");
|
||||||
|
|
||||||
|
static_assert(is_maybe_bool<decltype(v_not_null and dynamic(true, v_maybe_null))>::value, "");
|
||||||
|
static_assert(is_maybe_bool<decltype(v_not_null or dynamic(true, v_maybe_null))>::value, "");
|
||||||
|
|
||||||
// Compare nullable with nullable.
|
// Compare nullable with nullable.
|
||||||
static_assert(is_maybe_bool<decltype(v_maybe_null and v_maybe_null)>::value, "");
|
static_assert(is_maybe_bool<decltype(v_maybe_null and v_maybe_null)>::value, "");
|
||||||
static_assert(is_maybe_bool<decltype(v_maybe_null or v_maybe_null)>::value, "");
|
static_assert(is_maybe_bool<decltype(v_maybe_null or v_maybe_null)>::value, "");
|
||||||
|
|
||||||
|
static_assert(is_maybe_bool<decltype(v_maybe_null and dynamic(true, v_maybe_null))>::value, "");
|
||||||
|
static_assert(is_maybe_bool<decltype(v_maybe_null or dynamic(true, v_maybe_null))>::value, "");
|
||||||
|
|
||||||
// not.
|
// not.
|
||||||
static_assert(is_bool<decltype(not(v_not_null))>::value, "");
|
static_assert(is_bool<decltype(not(v_not_null))>::value, "");
|
||||||
static_assert(is_maybe_bool<decltype(not(v_maybe_null))>::value, "");
|
static_assert(is_maybe_bool<decltype(not(v_maybe_null))>::value, "");
|
||||||
|
Loading…
Reference in New Issue
Block a user