mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Added is_trivial_value_is_null interpretation to assignment
This commit is contained in:
parent
67f1b09acb
commit
6cffdb6428
@ -36,8 +36,6 @@ namespace sqlpp
|
|||||||
static constexpr bool _is_expression = true;
|
static constexpr bool _is_expression = true;
|
||||||
using _value_type = no_value_t;
|
using _value_type = no_value_t;
|
||||||
using _table_set = ::sqlpp::detail::type_set<>;
|
using _table_set = ::sqlpp::detail::type_set<>;
|
||||||
|
|
||||||
static constexpr bool _is_trivial() { return false; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace vendor
|
namespace vendor
|
||||||
|
42
include/sqlpp11/vendor/assignment.h
vendored
42
include/sqlpp11/vendor/assignment.h
vendored
@ -38,6 +38,30 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
namespace vendor
|
namespace vendor
|
||||||
{
|
{
|
||||||
|
template<typename T, typename Enable = void>
|
||||||
|
struct is_trivial_t
|
||||||
|
{
|
||||||
|
static constexpr bool _(const T&)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct is_trivial_t<T, typename std::enable_if<std::is_member_function_pointer<decltype(&T::_is_trivial)>::value, void>::type>
|
||||||
|
{
|
||||||
|
static bool _(const T& t)
|
||||||
|
{
|
||||||
|
return t._is_trivial();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool is_trivial(const T& t)
|
||||||
|
{
|
||||||
|
return is_trivial_t<typename T::value_type>::_(t);
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs>
|
template<typename Lhs, typename Rhs>
|
||||||
struct assignment_t
|
struct assignment_t
|
||||||
{
|
{
|
||||||
@ -47,7 +71,7 @@ namespace sqlpp
|
|||||||
using _parameter_tuple_t = std::tuple<_column_t, Rhs>;
|
using _parameter_tuple_t = std::tuple<_column_t, Rhs>;
|
||||||
using _table_set = typename Lhs::_table_set::template join<typename Rhs::_table_set>::type;
|
using _table_set = typename Lhs::_table_set::template join<typename Rhs::_table_set>::type;
|
||||||
|
|
||||||
static_assert(not std::is_same<Rhs, null_t>::value or can_be_null_t<_column_t>::value, "column cannot be null");
|
static_assert(can_be_null_t<_column_t>::value ? true : not std::is_same<Rhs, null_t>::value, "column must not be null");
|
||||||
|
|
||||||
assignment_t(_column_t lhs, value_type rhs):
|
assignment_t(_column_t lhs, value_type rhs):
|
||||||
_lhs(lhs),
|
_lhs(lhs),
|
||||||
@ -71,9 +95,19 @@ namespace sqlpp
|
|||||||
|
|
||||||
static Context& _(const T& t, Context& context)
|
static Context& _(const T& t, Context& context)
|
||||||
{
|
{
|
||||||
serialize(simple_column(t._lhs), context);
|
if ((trivial_value_is_null_t<typename T::_column_t>::value
|
||||||
context << "=";
|
and is_trivial_t<typename T::value_type>::_(t._rhs))
|
||||||
serialize(t._rhs, context);
|
or (std::is_same<Rhs, null_t>::value))
|
||||||
|
{
|
||||||
|
serialize(simple_column(t._lhs), context);
|
||||||
|
context << "=NULL";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
serialize(simple_column(t._lhs), context);
|
||||||
|
context << "=";
|
||||||
|
serialize(t._rhs, context);
|
||||||
|
}
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -6,12 +6,12 @@ macro (build_and_run arg)
|
|||||||
add_test(${arg} ${arg})
|
add_test(${arg} ${arg})
|
||||||
endmacro ()
|
endmacro ()
|
||||||
|
|
||||||
#build_and_run(InterpretTest)
|
build_and_run(InterpretTest)
|
||||||
#build_and_run(InsertTest)
|
build_and_run(InsertTest)
|
||||||
#build_and_run(RemoveTest)
|
build_and_run(RemoveTest)
|
||||||
#build_and_run(UpdateTest)
|
build_and_run(UpdateTest)
|
||||||
#build_and_run(SelectTest)
|
build_and_run(SelectTest)
|
||||||
#build_and_run(FunctionTest)
|
build_and_run(FunctionTest)
|
||||||
build_and_run(PreparedTest)
|
build_and_run(PreparedTest)
|
||||||
|
|
||||||
find_package(PythonInterp REQUIRED)
|
find_package(PythonInterp REQUIRED)
|
||||||
|
Loading…
Reference in New Issue
Block a user