diff --git a/include/sqlpp11/null.h b/include/sqlpp11/null.h index af742da1..c3d864c9 100644 --- a/include/sqlpp11/null.h +++ b/include/sqlpp11/null.h @@ -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 diff --git a/include/sqlpp11/vendor/assignment.h b/include/sqlpp11/vendor/assignment.h index c0d288d9..5a21731b 100644 --- a/include/sqlpp11/vendor/assignment.h +++ b/include/sqlpp11/vendor/assignment.h @@ -38,6 +38,30 @@ namespace sqlpp { namespace vendor { + template + struct is_trivial_t + { + static constexpr bool _(const T&) + { + return false; + } + }; + + template + struct is_trivial_t::value, void>::type> + { + static bool _(const T& t) + { + return t._is_trivial(); + } + }; + + template + bool is_trivial(const T& t) + { + return is_trivial_t::_(t); + } + template 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::type; - static_assert(not std::is_same::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::value, "column must not be null"); assignment_t(_column_t lhs, value_type rhs): _lhs(lhs), @@ -71,9 +95,19 @@ namespace sqlpp static Context& _(const T& t, Context& context) { - serialize(simple_column(t._lhs), context); - context << "="; - serialize(t._rhs, context); + if ((trivial_value_is_null_t::value + and is_trivial_t::_(t._rhs)) + or (std::is_same::value)) + { + serialize(simple_column(t._lhs), context); + context << "=NULL"; + } + else + { + serialize(simple_column(t._lhs), context); + context << "="; + serialize(t._rhs, context); + } return context; } }; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c572a9ea..8d04a9e3 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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)