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

Interpret works for parameters now

Also, paramters inherit the operators they need
This commit is contained in:
rbock 2014-01-13 21:00:20 +01:00
parent c03ef1b0b1
commit eb9f92543e
5 changed files with 32 additions and 31 deletions

View File

@ -56,11 +56,7 @@ namespace sqlpp
};
};
concat_t(First&& first, Args&&... args):
_args(std::move(first), std::move(args)...)
{}
concat_t(const First& first, const Args&... args):
concat_t(First first, Args... args):
_args(first, args...)
{}

View File

@ -73,7 +73,7 @@ namespace sqlpp
equal_t<Base, typename Constraint<T>::type> operator==(T&& t) const
{
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), {std::forward<T>(t)} };
return { *static_cast<const Base*>(this), {std::forward<T>(t)} };
}
template<typename T>
@ -100,14 +100,14 @@ namespace sqlpp
binary_expression_t<Base, ge_, typename Constraint<T>::type> operator>=(T&& t) const
{
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) };
return { *static_cast<const Base*>(this), {std::forward<T>(t)} };
}
template<typename T>
binary_expression_t<Base, gt_, typename Constraint<T>::type> operator>(T&& t) const
{
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used as left hand side operand");
return { *static_cast<const Base*>(this), std::forward<T>(t) };
return { *static_cast<const Base*>(this), {std::forward<T>(t)} };
}
is_null_t<true, boolean, Base> is_null() const
@ -139,14 +139,14 @@ namespace sqlpp
in_t<true, boolean, Base, typename Constraint<T>::type...> in(T&&... t) const
{
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot be used with in()");
return { *static_cast<const Base*>(this), std::forward<T>(t)... };
return { *static_cast<const Base*>(this), {std::forward<T>(t)}... };
}
template<typename... T>
in_t<false, boolean, Base, typename Constraint<T>::type...> not_in(T&&... t) const
{
static_assert(not is_multi_expression_t<Base>::value, "multi-expression cannot with be used with not_in()");
return { *static_cast<const Base*>(this), std::forward<T>(t)... };
return { *static_cast<const Base*>(this), {std::forward<T>(t)}... };
}
template<typename alias_provider>

View File

@ -34,7 +34,7 @@
namespace sqlpp
{
template<typename ValueType, typename NameType, typename TrivialValueIsNull>
struct parameter_t
struct parameter_t: public ValueType::template operators<parameter_t<ValueType, NameType, TrivialValueIsNull>>
{
using _value_type = ValueType;
using _is_parameter = std::true_type;
@ -44,31 +44,33 @@ namespace sqlpp
static_assert(std::is_same<_trivial_value_is_null_t, std::true_type>::value or std::is_same<_trivial_value_is_null_t, std::false_type>::value, "Invalid template parameter TrivialValueIsNull");
template<typename Db>
void serialize(std::ostream& os, Db& db) const
{
static_assert(Db::_supports_prepared, "prepared statements not supported by current database");
static_assert(Db::_use_questionmark_parameter or Db::_use_positional_dollar_parameter, "no known way to serialize parameter placeholders for current database");
if (Db::_use_questionmark_parameter)
os << '?';
else if (Db::_use_positional_dollar_parameter)
os << '$' << _index + 1;
}
parameter_t()
{}
parameter_t(const parameter_t&) = default;
parameter_t(parameter_t&&) = default;
parameter_t& operator=(const parameter_t&) = default;
parameter_t& operator=(parameter_t&&) = default;
~parameter_t() = default;
constexpr bool _is_trivial() const
{
return false;
}
size_t _set_parameter_index(size_t index)
{
_index = index;
return index + 1;
}
size_t _index;
};
template<typename Context, typename ValueType, typename NameType, typename TrivialValueIsNull>
struct interpreter_t<Context, parameter_t<ValueType, NameType, TrivialValueIsNull>>
{
using T = parameter_t<ValueType, NameType, TrivialValueIsNull>;
static Context& _(const T& t, Context& context)
{
context << "?";
return context;
}
};
template<typename NamedExpr, typename TrivialValueIsNull = trivial_value_is_null_t<typename std::decay<NamedExpr>::type>>
auto parameter(NamedExpr&& namedExpr)
-> parameter_t<typename std::decay<NamedExpr>::type::_value_type, typename std::decay<NamedExpr>::type, TrivialValueIsNull>

View File

@ -47,7 +47,7 @@ namespace sqlpp
};
}
struct verbatim_table_t: public sqlpp::table_base_t<verbatim_table_t, detail::unusable_pseudo_column_t>
struct verbatim_table_t: public sqlpp::table_t<verbatim_table_t, detail::unusable_pseudo_column_t>
{
using _value_type = no_value_t;

View File

@ -26,6 +26,7 @@
#include "TabSample.h"
#include "MockDb.h"
#include <sqlpp11/select.h>
#include <sqlpp11/functions.h>
#include <iostream>
@ -40,7 +41,6 @@ int main()
interpret(t.alpha, printer).flush();
interpret(t.alpha = 7, printer).flush();
interpret(t.alpha == 7, printer).flush();
sqlpp::text_operand o = {"kaesekuchen"};
interpret(t.beta + "kaesekuchen", printer).flush();
interpret(select(sqlpp::distinct, t.alpha, t.beta), printer).flush();
@ -51,5 +51,8 @@ int main()
interpret(select(sqlpp::distinct, t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")).order_by(t.beta.asc()), printer).flush();
interpret(select(sqlpp::distinct, t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")).order_by(t.beta.asc()).limit(17).offset(3), printer).flush();
interpret(parameter(t.alpha), printer).flush();
interpret(t.alpha == parameter(t.alpha), printer).flush();
return 0;
}