diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 7947f546..8f0a5eda 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -114,13 +114,9 @@ namespace sqlpp return *this; } - template - //using _insert_value_t = vendor::insert_value_t::type>; - using _insert_value_t = vendor::insert_value_t; - template auto columns(Column... columns) - -> set_column_value_list_t, vendor::insert_value_list_t<_insert_value_t...>> + -> set_column_value_list_t, vendor::insert_value_list_t...>> { static_assert(vendor::is_noop::value, "cannot call columns() twice"); static_assert(vendor::is_noop::value, "cannot call columns() after set() or dynamic_set()"); @@ -130,7 +126,7 @@ namespace sqlpp _table, _insert_list, {std::tuple{columns...}}, - vendor::insert_value_list_t<_insert_value_t...>{}, + vendor::insert_value_list_t...>{}, }; } diff --git a/include/sqlpp11/tvin.h b/include/sqlpp11/tvin.h index c161008d..9e47969c 100644 --- a/include/sqlpp11/tvin.h +++ b/include/sqlpp11/tvin.h @@ -38,7 +38,7 @@ namespace sqlpp struct tvin_t { using _operand_t = typename vendor::wrap_operand::type; - static_assert(not std::is_same<_operand_t, T>::value, "tvin() used with invalid type (only string and primitive types allowed)"); + static_assert(std::is_same<_operand_t, vendor::text_operand>::value or not std::is_same<_operand_t, T>::value, "tvin() used with invalid type (only string and primitive types allowed)"); using _value_type = typename _operand_t::_value_type; tvin_t(T t): diff --git a/include/sqlpp11/vendor/insert_value.h b/include/sqlpp11/vendor/insert_value.h index 9c6fdf33..13835709 100644 --- a/include/sqlpp11/vendor/insert_value.h +++ b/include/sqlpp11/vendor/insert_value.h @@ -37,31 +37,51 @@ namespace sqlpp { namespace vendor { - template + namespace detail + { + template + struct type_if + { + using type = Type; + }; + + template + struct type_if + { + struct type + { + }; + }; + } + + template struct insert_value_t { using _is_insert_value = std::true_type; - using _value_t = ValueType; + using _pure_value_t = typename Column::_value_type::_cpp_value_type; + using _wrapped_value_t = typename wrap_operand<_pure_value_t>::type; + using _tvin_t = typename detail::type_if, can_be_null_t::value>::type; // static asserts and SFINAE do not work together + using _null_t = typename detail::type_if::value>::type; // static asserts and SFINAE do not work together - insert_value_t(_value_t value): + insert_value_t(assignment_t assignment): _is_null(false), _is_default(false), - _value({value}) + _value(assignment._rhs) {} - insert_value_t(tvin_t<_value_t> tvin): - _is_null(tvin._is_trivial()), + insert_value_t(assignment_t assignment): + _is_null(assignment._rhs._is_trivial()), _is_default(false), - _value({tvin._value}) + _value(assignment._rhs._value) {} - insert_value_t(const ::sqlpp::null_t&): + insert_value_t(const assignment_t&): _is_null(true), _is_default(false), _value() {} - insert_value_t(const ::sqlpp::default_value_t&): + insert_value_t(const assignment_t&): _is_null(false), _is_default(true), _value() @@ -75,7 +95,7 @@ namespace sqlpp bool _is_null; bool _is_default; - typename wrap_operand<_value_t>::type _value; + _wrapped_value_t _value; }; template diff --git a/include/sqlpp11/vendor/select_flag_list.h b/include/sqlpp11/vendor/select_flag_list.h index c58d3f39..ab5e4918 100644 --- a/include/sqlpp11/vendor/select_flag_list.h +++ b/include/sqlpp11/vendor/select_flag_list.h @@ -41,7 +41,7 @@ namespace sqlpp template struct select_flag_list_t { - static_assert(detail::wrong::value, "invalid argument for select_flag_list"); + static_assert(::sqlpp::detail::wrong::value, "invalid argument for select_flag_list"); }; // select_flag_list_t @@ -54,10 +54,10 @@ namespace sqlpp using size = std::tuple_size<_parameter_tuple_t>; // check for duplicate order expressions - static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); // check for invalid order expressions - using _valid_flags = typename detail::make_set_if::type; + using _valid_flags = typename ::sqlpp::detail::make_set_if::type; static_assert(_valid_flags::size::value == sizeof...(Flag), "at least one argument is not a select flag in select flag list"); template diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index a58e7328..77670dd8 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -44,10 +44,16 @@ int main() TabFoo f; interpret(insert_into(t).columns(t.gamma, t.beta), printer).flush(); - interpret(insert_into(t).columns(t.gamma, t.beta).add_values(true, "cheesecake"), printer).flush(); - interpret(insert_into(t).columns(t.gamma, t.beta).add_values(true, "cheesecake").add_values(false, sqlpp::tvin(std::string("coffee"))).add_values(false, sqlpp::tvin(std::string())), printer).flush(); - interpret(insert_into(t).columns(t.gamma, t.beta).add_values(sqlpp::default_value, sqlpp::null), printer).flush(); - interpret(insert_into(t).columns(t.gamma, t.beta), printer).flush(); + interpret(insert_into(t).columns(t.gamma, t.beta).add_values(t.gamma = true, t.beta = "cheesecake"), printer).flush(); + interpret(insert_into(t).columns(t.gamma, t.beta) + .add_values(t.gamma = true, t.beta = "cheesecake") + .add_values(t.gamma = false, t.beta = sqlpp::tvin(std::string("coffee"))) // FIXME: Want to use const char* const here, too + .add_values(t.gamma = false, t.beta = sqlpp::tvin(std::string())) + , printer).flush(); + interpret(insert_into(t).columns(t.gamma, t.beta) + .add_values(t.gamma = sqlpp::default_value, t.beta = sqlpp::null) + , printer).flush(); + interpret(t.alpha = sqlpp::null, printer).flush(); interpret(t.alpha = sqlpp::default_value, printer).flush(); interpret(t.alpha, printer).flush();