mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 12:51:13 +08:00
Use name tag instead of the whole name tag provider in paramters
This commit is contained in:
parent
dc53fd5acc
commit
25879d1dc0
@ -34,15 +34,9 @@
|
|||||||
namespace sqlpp
|
namespace sqlpp
|
||||||
{
|
{
|
||||||
#warning: It would be sufficient to store the NameTag here, not the whole NameTagProvider
|
#warning: It would be sufficient to store the NameTag here, not the whole NameTagProvider
|
||||||
template <typename ValueType, typename NameType>
|
template <typename ValueType, typename NameTag>
|
||||||
struct parameter_t : public enable_comparison<parameter_t<ValueType, NameType>>
|
struct parameter_t : public enable_comparison<parameter_t<ValueType, NameTag>>
|
||||||
{
|
{
|
||||||
using _traits = make_traits<ValueType, tag::is_parameter, tag::is_expression>;
|
|
||||||
|
|
||||||
using _is_literal_expression = std::true_type;
|
|
||||||
|
|
||||||
using _instance_t = member_t<NameType, parameter_value_t<ValueType>>;
|
|
||||||
|
|
||||||
parameter_t() = default;
|
parameter_t() = default;
|
||||||
|
|
||||||
parameter_t(const parameter_t&) = default;
|
parameter_t(const parameter_t&) = default;
|
||||||
@ -52,31 +46,32 @@ namespace sqlpp
|
|||||||
~parameter_t() = default;
|
~parameter_t() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ValueType, typename NameType>
|
template<typename ValueType, typename NameTag>
|
||||||
struct parameters_of<parameter_t<ValueType, NameType>>
|
struct parameters_of<parameter_t<ValueType, NameTag>>
|
||||||
{
|
{
|
||||||
using type = detail::type_vector<parameter_t<ValueType, NameType>>;
|
using type = detail::type_vector<parameter_t<ValueType, NameTag>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ValueType, typename NameType>
|
template<typename ValueType, typename NameTag>
|
||||||
struct value_type_of<parameter_t<ValueType, NameType>>
|
struct value_type_of<parameter_t<ValueType, NameTag>>
|
||||||
{
|
{
|
||||||
using type = ValueType;
|
using type = ValueType;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename ValueType, typename NameType>
|
template <typename ValueType, typename NameTag>
|
||||||
struct name_tag_of<parameter_t<ValueType, NameType>> : public name_tag_of<NameType>
|
struct name_tag_of<parameter_t<ValueType, NameTag>>
|
||||||
{
|
{
|
||||||
|
using type = NameTag;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Context, typename ValueType, typename NameType>
|
template <typename Context, typename ValueType, typename NameTag>
|
||||||
auto to_sql_string(Context& , const parameter_t<ValueType, NameType>&) -> std::string
|
auto to_sql_string(Context& , const parameter_t<ValueType, NameTag>&) -> std::string
|
||||||
{
|
{
|
||||||
return "?";
|
return "?";
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename NamedExpr>
|
template <typename NamedExpr>
|
||||||
auto parameter(const NamedExpr & /*unused*/) -> parameter_t<value_type_of_t<NamedExpr>, NamedExpr>
|
auto parameter(const NamedExpr & /*unused*/) -> parameter_t<value_type_of_t<NamedExpr>, name_tag_of_t<NamedExpr>>
|
||||||
{
|
{
|
||||||
static_assert(is_selectable_t<NamedExpr>::value, "not a named expression");
|
static_assert(is_selectable_t<NamedExpr>::value, "not a named expression");
|
||||||
return {};
|
return {};
|
||||||
@ -84,7 +79,7 @@ namespace sqlpp
|
|||||||
|
|
||||||
template <typename ValueType, typename NameTagProvider>
|
template <typename ValueType, typename NameTagProvider>
|
||||||
auto parameter(const ValueType& /*unused*/, const NameTagProvider & /*unused*/)
|
auto parameter(const ValueType& /*unused*/, const NameTagProvider & /*unused*/)
|
||||||
-> parameter_t<value_type_of_t<ValueType>, NameTagProvider>
|
-> parameter_t<value_type_of_t<ValueType>, name_tag_of_t<NameTagProvider>>
|
||||||
{
|
{
|
||||||
static_assert(has_value_type<ValueType>::value, "first argument is not a value type");
|
static_assert(has_value_type<ValueType>::value, "first argument is not a value type");
|
||||||
static_assert(has_name_tag<NameTagProvider>::value, "second argument does not have a name");
|
static_assert(has_name_tag<NameTagProvider>::value, "second argument does not have a name");
|
||||||
|
@ -83,7 +83,7 @@ void test_cte()
|
|||||||
static_assert(std::is_same<sqlpp::parameters_of_t<X>, sqlpp::detail::type_vector<P>>::value, "");
|
static_assert(std::is_same<sqlpp::parameters_of_t<X>, sqlpp::detail::type_vector<P>>::value, "");
|
||||||
|
|
||||||
// CTE reference is what is stored in from_t or join_t.
|
// CTE reference is what is stored in from_t or join_t.
|
||||||
// While it refers to a CTE, it cannot be used as a CTE or table, i.e. with(rx) or from(ra) would not compile.
|
// While it refers to a CTE, it cannot be used as a CTE or table, i.e. with(rx) or from(rx) would not compile.
|
||||||
static_assert(not sqlpp::is_cte<RX>::value, "");
|
static_assert(not sqlpp::is_cte<RX>::value, "");
|
||||||
static_assert(not sqlpp::is_table<RX>::value, "");
|
static_assert(not sqlpp::is_table<RX>::value, "");
|
||||||
static_assert(sqlpp::parameters_of_t<RX>::empty(), "");
|
static_assert(sqlpp::parameters_of_t<RX>::empty(), "");
|
||||||
|
Loading…
Reference in New Issue
Block a user