0
0
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:
rbock 2014-03-07 08:53:32 +01:00
parent 67f1b09acb
commit 6cffdb6428
3 changed files with 44 additions and 12 deletions

View File

@ -36,8 +36,6 @@ namespace sqlpp
static constexpr bool _is_expression = true;
using _value_type = no_value_t;
using _table_set = ::sqlpp::detail::type_set<>;
static constexpr bool _is_trivial() { return false; }
};
namespace vendor

View File

@ -38,6 +38,30 @@ namespace sqlpp
{
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>
struct assignment_t
{
@ -47,7 +71,7 @@ namespace sqlpp
using _parameter_tuple_t = std::tuple<_column_t, Rhs>;
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):
_lhs(lhs),
@ -70,10 +94,20 @@ namespace sqlpp
using T = assignment_t<Lhs, Rhs>;
static Context& _(const T& t, Context& context)
{
if ((trivial_value_is_null_t<typename T::_column_t>::value
and is_trivial_t<typename T::value_type>::_(t._rhs))
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;
}
};

View File

@ -6,12 +6,12 @@ macro (build_and_run arg)
add_test(${arg} ${arg})
endmacro ()
#build_and_run(InterpretTest)
#build_and_run(InsertTest)
#build_and_run(RemoveTest)
#build_and_run(UpdateTest)
#build_and_run(SelectTest)
#build_and_run(FunctionTest)
build_and_run(InterpretTest)
build_and_run(InsertTest)
build_and_run(RemoveTest)
build_and_run(UpdateTest)
build_and_run(SelectTest)
build_and_run(FunctionTest)
build_and_run(PreparedTest)
find_package(PythonInterp REQUIRED)