0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Merge pull request #247 from sjoubert/multi_insert_value_or_null

Add support of value_or_null in multi-insert
This commit is contained in:
Roland Bock 2018-08-13 22:22:03 +02:00 committed by GitHub
commit 80ccb35355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include <sqlpp11/default_value.h> #include <sqlpp11/default_value.h>
#include <sqlpp11/null.h> #include <sqlpp11/null.h>
#include <sqlpp11/tvin.h> #include <sqlpp11/tvin.h>
#include <sqlpp11/value_or_null.h>
#include <sqlpp11/type_traits.h> #include <sqlpp11/type_traits.h>
#include <sqlpp11/serializer.h> #include <sqlpp11/serializer.h>
#include <sqlpp11/detail/type_set.h> #include <sqlpp11/detail/type_set.h>
@ -64,6 +65,7 @@ namespace sqlpp
using _pure_value_t = typename value_type_of<Column>::_cpp_value_type; using _pure_value_t = typename value_type_of<Column>::_cpp_value_type;
using _wrapped_value_t = wrap_operand_t<_pure_value_t>; using _wrapped_value_t = wrap_operand_t<_pure_value_t>;
using _tvin_t = tvin_t<_wrapped_value_t>; using _tvin_t = tvin_t<_wrapped_value_t>;
using _value_or_null_t = value_or_null_t<typename Column::_traits::_value_type>;
insert_value_t(rhs_wrap_t<_wrapped_value_t, _trivial_value_is_null> rhs) insert_value_t(rhs_wrap_t<_wrapped_value_t, _trivial_value_is_null> rhs)
: _is_null(rhs._is_null()), _is_default(rhs._is_default()), _value(rhs._expr._t) : _is_null(rhs._is_null()), _is_default(rhs._is_default()), _value(rhs._expr._t)
@ -85,6 +87,11 @@ namespace sqlpp
{ {
} }
insert_value_t(const rhs_wrap_t<_value_or_null_t, _trivial_value_is_null>& rhs)
: _is_null(rhs._expr._is_null), _is_default(false), _value{rhs._expr._value}
{
}
insert_value_t(const insert_value_t&) = default; insert_value_t(const insert_value_t&) = default;
insert_value_t(insert_value_t&&) = default; insert_value_t(insert_value_t&&) = default;
insert_value_t& operator=(const insert_value_t&) = default; insert_value_t& operator=(const insert_value_t&) = default;

View File

@ -54,6 +54,8 @@ int Insert(int, char*[])
db(insert_into(t).default_values()); db(insert_into(t).default_values());
db(insert_into(t).set(t.gamma = true, t.beta = "kirschauflauf")); db(insert_into(t).set(t.gamma = true, t.beta = "kirschauflauf"));
db(insert_into(t).set(t.gamma = sqlpp::default_value, t.beta = sqlpp::value_or_null("pie"),
t.delta = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null)));
serialize(insert_into(t).default_values(), printer).str(); serialize(insert_into(t).default_values(), printer).str();
@ -64,6 +66,9 @@ int Insert(int, char*[])
multi_insert.values.add(t.gamma = true, t.beta = "cheesecake", t.delta = 1); multi_insert.values.add(t.gamma = true, t.beta = "cheesecake", t.delta = 1);
multi_insert.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::default_value, multi_insert.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::default_value,
t.delta = sqlpp::default_value); t.delta = sqlpp::default_value);
multi_insert.values.add(t.gamma = sqlpp::value_or_null(true),
t.beta = sqlpp::value_or_null("pie"),
t.delta = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null));
auto i = dynamic_insert_into(db, t).dynamic_set(); auto i = dynamic_insert_into(db, t).dynamic_set();
i.insert_list.add(t.beta = "kirschauflauf"); i.insert_list.add(t.beta = "kirschauflauf");
printer.reset(); printer.reset();