mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
tvin works with const char*, too
This commit is contained in:
parent
b0e7395f47
commit
dfcd372611
@ -34,15 +34,14 @@
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template<typename T>
|
||||
template<typename Operand>
|
||||
struct tvin_t
|
||||
{
|
||||
using _operand_t = typename vendor::wrap_operand<T>::type;
|
||||
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 _operand_t = Operand;
|
||||
using _value_type = typename _operand_t::_value_type;
|
||||
|
||||
tvin_t(T t):
|
||||
_value({t})
|
||||
tvin_t(Operand operand):
|
||||
_value(operand)
|
||||
{}
|
||||
tvin_t(const tvin_t&) = default;
|
||||
tvin_t(tvin_t&&) = default;
|
||||
@ -60,10 +59,10 @@ namespace sqlpp
|
||||
|
||||
namespace vendor
|
||||
{
|
||||
template<typename Context, typename Type>
|
||||
struct interpreter_t<Context, tvin_t<Type>>
|
||||
template<typename Context, typename Operand>
|
||||
struct interpreter_t<Context, tvin_t<Operand>>
|
||||
{
|
||||
using T = tvin_t<Type>;
|
||||
using T = tvin_t<Operand>;
|
||||
|
||||
static void _(const T& t, Context& context)
|
||||
{
|
||||
@ -114,10 +113,10 @@ namespace sqlpp
|
||||
|
||||
namespace vendor
|
||||
{
|
||||
template<typename Context, typename Type>
|
||||
struct interpreter_t<Context, tvin_wrap_t<Type>>
|
||||
template<typename Context, typename Operand>
|
||||
struct interpreter_t<Context, tvin_wrap_t<Operand>>
|
||||
{
|
||||
using T = tvin_wrap_t<Type>;
|
||||
using T = tvin_wrap_t<Operand>;
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
@ -135,9 +134,12 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto tvin(T t) -> tvin_t<typename std::decay<T>::type>
|
||||
auto tvin(T t) -> tvin_t<typename vendor::wrap_operand<T>::type>
|
||||
{
|
||||
return {t};
|
||||
using _operand_t = typename vendor::wrap_operand<T>::type;
|
||||
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)");
|
||||
return {{t}};
|
||||
}
|
||||
|
||||
}
|
||||
|
2
include/sqlpp11/vendor/insert_value.h
vendored
2
include/sqlpp11/vendor/insert_value.h
vendored
@ -60,7 +60,7 @@ namespace sqlpp
|
||||
using _is_insert_value = std::true_type;
|
||||
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<tvin_t<_pure_value_t>, can_be_null_t<Column>::value>::type; // static asserts and SFINAE do not work together
|
||||
using _tvin_t = typename detail::type_if<tvin_t<_wrapped_value_t>, can_be_null_t<Column>::value>::type; // static asserts and SFINAE do not work together
|
||||
using _null_t = typename detail::type_if<null_t, can_be_null_t<Column>::value>::type; // static asserts and SFINAE do not work together
|
||||
|
||||
insert_value_t(assignment_t<Column, _wrapped_value_t> assignment):
|
||||
|
1
include/sqlpp11/vendor/wrap_operand.h
vendored
1
include/sqlpp11/vendor/wrap_operand.h
vendored
@ -164,7 +164,6 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
// FIXME: Need to allow std::ref arguments
|
||||
// FIXME: insert requires to work with value_list
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ int main()
|
||||
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("coffee"))
|
||||
.add_values(t.gamma = false, t.beta = sqlpp::tvin(std::string()))
|
||||
, printer).flush();
|
||||
interpret(insert_into(t).columns(t.gamma, t.beta)
|
||||
|
Loading…
Reference in New Issue
Block a user