0
0
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:
rbock 2014-01-26 15:44:44 +01:00
parent b0e7395f47
commit dfcd372611
4 changed files with 17 additions and 16 deletions

View File

@ -34,15 +34,14 @@
namespace sqlpp namespace sqlpp
{ {
template<typename T> template<typename Operand>
struct tvin_t struct tvin_t
{ {
using _operand_t = typename vendor::wrap_operand<T>::type; using _operand_t = Operand;
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; using _value_type = typename _operand_t::_value_type;
tvin_t(T t): tvin_t(Operand operand):
_value({t}) _value(operand)
{} {}
tvin_t(const tvin_t&) = default; tvin_t(const tvin_t&) = default;
tvin_t(tvin_t&&) = default; tvin_t(tvin_t&&) = default;
@ -60,10 +59,10 @@ namespace sqlpp
namespace vendor namespace vendor
{ {
template<typename Context, typename Type> template<typename Context, typename Operand>
struct interpreter_t<Context, tvin_t<Type>> struct interpreter_t<Context, tvin_t<Operand>>
{ {
using T = tvin_t<Type>; using T = tvin_t<Operand>;
static void _(const T& t, Context& context) static void _(const T& t, Context& context)
{ {
@ -114,10 +113,10 @@ namespace sqlpp
namespace vendor namespace vendor
{ {
template<typename Context, typename Type> template<typename Context, typename Operand>
struct interpreter_t<Context, tvin_wrap_t<Type>> 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) static Context& _(const T& t, Context& context)
{ {
@ -135,9 +134,12 @@ namespace sqlpp
} }
template<typename T> 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}};
} }
} }

View File

@ -60,7 +60,7 @@ namespace sqlpp
using _is_insert_value = std::true_type; using _is_insert_value = std::true_type;
using _pure_value_t = typename Column::_value_type::_cpp_value_type; using _pure_value_t = typename Column::_value_type::_cpp_value_type;
using _wrapped_value_t = typename wrap_operand<_pure_value_t>::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 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): insert_value_t(assignment_t<Column, _wrapped_value_t> assignment):

View File

@ -164,7 +164,6 @@ namespace sqlpp
}; };
// FIXME: Need to allow std::ref arguments // FIXME: Need to allow std::ref arguments
// FIXME: insert requires to work with value_list
} }
} }

View File

@ -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"), printer).flush();
interpret(insert_into(t).columns(t.gamma, t.beta) interpret(insert_into(t).columns(t.gamma, t.beta)
.add_values(t.gamma = true, t.beta = "cheesecake") .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())) .add_values(t.gamma = false, t.beta = sqlpp::tvin(std::string()))
, printer).flush(); , printer).flush();
interpret(insert_into(t).columns(t.gamma, t.beta) interpret(insert_into(t).columns(t.gamma, t.beta)