0
0
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:
Roland Bock 2024-07-18 20:17:57 +02:00
parent 700c263f90
commit 7cc4e45abd
4 changed files with 30 additions and 11 deletions

View File

@ -29,11 +29,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <type_traits>
#include <sqlpp11/operator/as_expression.h>
//#include <sqlpp11/bad_expression.h>
#include <sqlpp11/dynamic.h>
//#include <sqlpp11/embrace.h>
//#include <sqlpp11/to_sql_string.h>
#include <sqlpp11/type_traits.h>
//#include <sqlpp11/wrapped_static_assert.h>
namespace sqlpp
{
@ -65,7 +64,7 @@ namespace sqlpp
template <typename L, typename Operator, typename 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>,
boolean>
{
@ -141,7 +140,8 @@ namespace sqlpp
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>
{
return {std::move(l), std::move(r)};
@ -152,7 +152,7 @@ namespace sqlpp
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>
{
return {std::move(l), std::move(r)};

View File

@ -47,6 +47,16 @@ namespace sqlpp
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>
auto serialize(const bool& t, Context& context) -> Context&
{

View File

@ -23,6 +23,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set(test_files
logical_expression.cpp
Any.cpp
As.cpp
Avg.cpp

View File

@ -23,14 +23,10 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "MockDb.h"
#include "Sample.h"
#include <sqlpp11/sqlpp11.h>
namespace
{
auto db = MockDb{};
template <typename T>
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 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 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 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.
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 and dynamic(true, v_maybe_null))>::value, "");
static_assert(is_maybe_bool<decltype(v_maybe_null or dynamic(true, v_maybe_null))>::value, "");
// not.
static_assert(is_bool<decltype(not(v_not_null))>::value, "");
static_assert(is_maybe_bool<decltype(not(v_maybe_null))>::value, "");