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

Reformatted using clang-format

Please use clang-format before submitting code, e.g via the pre-commit
supplied in the repo (thanks AndiDog)
This commit is contained in:
rbock 2015-09-13 21:33:19 +02:00
parent 46c565c5c5
commit 09f23cea0a
168 changed files with 11984 additions and 11583 deletions

View File

@ -14,7 +14,7 @@ BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false BreakConstructorInitializersBeforeComma: false
BinPackParameters: false BinPackParameters: false
ColumnLimit: 160 ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerAlignment: false DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false ExperimentalAutoDetectBinPacking: false

View File

@ -24,7 +24,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SQLPP_DATABASE_BIND_RESULT_H #ifndef SQLPP_DATABASE_BIND_RESULT_H
#define SQLPP_DATABASE_BIND_RESULT_H #define SQLPP_DATABASE_BIND_RESULT_H
@ -87,7 +86,6 @@ namespace sqlpp
void _bind_text_result(size_t index, const char** text, size_t* len); void _bind_text_result(size_t index, const char** text, size_t* len);
... ...
}; };
} }
} }
#endif #endif

View File

@ -24,7 +24,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SQLPP_DATABASE_CONNECTION_H #ifndef SQLPP_DATABASE_CONNECTION_H
#define SQLPP_DATABASE_CONNECTION_H #define SQLPP_DATABASE_CONNECTION_H
@ -51,13 +50,15 @@ namespace sqlpp
class connection : public sqlpp::connection // this inheritance helps with ADL for dynamic_select, for instance class connection : public sqlpp::connection // this inheritance helps with ADL for dynamic_select, for instance
{ {
public: public:
using _traits = ::sqlpp::make_traits<::sqlpp::no_value_t, using _traits = ::sqlpp::make_traits<
::sqlpp::no_value_t,
::sqlpp::tag::enforce_null_result_treatment // If that is what you really want, leave it out otherwise ::sqlpp::tag::enforce_null_result_treatment // If that is what you really want, leave it out otherwise
>; >;
using _prepared_statement_t = << handle to a prepared statement of the database >> ; using _prepared_statement_t = << handle to a prepared statement of the database >> ;
using _serializer_context_t = << This context is used to serialize a statement >> using _serializer_context_t = << This context is used to serialize a statement >> using _interpreter_context_t =
using _interpreter_context_t = << This context is used interpret a statement >>; << This context is used interpret a statement >>
;
// serializer and interpreter are typically the same for string based connectors // serializer and interpreter are typically the same for string based connectors
// the types are required for dynamic statement components, see sqlpp11/interpretable.h // the types are required for dynamic statement components, see sqlpp11/interpretable.h
@ -70,14 +71,16 @@ namespace sqlpp
//! "direct" select //! "direct" select
template <typename Select> template <typename Select>
<<bind_result_t>> select(const Select& s); << bind_result_t >>
select(const Select& s);
//! prepared select //! prepared select
template <typename Select> template <typename Select>
_prepared_statement_t prepare_select(Select& s); _prepared_statement_t prepare_select(Select& s);
template <typename PreparedSelect> template <typename PreparedSelect>
<<bind_result_t>> run_prepared_select(const PreparedSelect& s); // call s._bind_params() << bind_result_t >>
run_prepared_select(const PreparedSelect& s); // call s._bind_params()
//! "direct insert //! "direct insert
template <typename Insert> template <typename Insert>
@ -132,13 +135,13 @@ namespace sqlpp
//! commit transaction (or throw transaction if the transaction has been finished already) //! commit transaction (or throw transaction if the transaction has been finished already)
void commit_transaction(); void commit_transaction();
//! rollback transaction with or without reporting the rollback (or throw if the transaction has been finished already) //! rollback transaction with or without reporting the rollback (or throw if the transaction has been finished
// already)
void rollback_transaction(bool report); void rollback_transaction(bool report);
//! report a rollback failure (will be called by transactions in case of a rollback failure in the destructor) //! report a rollback failure (will be called by transactions in case of a rollback failure in the destructor)
void report_rollback_failure(const std::string message) noexcept; void report_rollback_failure(const std::string message) noexcept;
}; };
} }
} }

View File

@ -55,7 +55,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
} }

View File

@ -24,7 +24,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SQLPP_DATABASE_PREPARED_STATEMENT_H #ifndef SQLPP_DATABASE_PREPARED_STATEMENT_H
#define SQLPP_DATABASE_PREPARED_STATEMENT_H #define SQLPP_DATABASE_PREPARED_STATEMENT_H

View File

@ -5,6 +5,7 @@
#include <sqlpp11/column_types.h> #include <sqlpp11/column_types.h>
#include <sqlpp11/char_sequence.h> #include <sqlpp11/char_sequence.h>
// clang-format off
namespace test namespace test
{ {
namespace TabPerson_ namespace TabPerson_

View File

@ -30,7 +30,7 @@
#include <sqlpp11/table_base.h> #include <sqlpp11/table_base.h>
#include <sqlpp11/column_types.h> #include <sqlpp11/column_types.h>
// clang-format off
namespace TabFoo_ namespace TabFoo_
{ {
struct Omega struct Omega

View File

@ -50,7 +50,6 @@ int insert(int, char**)
// db(insert_into(f).set(f.name = "loves c++")); // db(insert_into(f).set(f.name = "loves c++"));
db(insert_into(f).default_values()); db(insert_into(f).default_values());
auto i = insert_into(p).columns(p.name, p.feature); auto i = insert_into(p).columns(p.name, p.feature);
@ -58,7 +57,6 @@ int insert(int, char**)
i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value); i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value);
db(i); db(i);
auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature))); auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature)));
pi.params.name = "likes java"; pi.params.name = "likes java";
pi.params.feature = true; pi.params.feature = true;

View File

@ -45,6 +45,7 @@ SQLPP_DECLARE_TABLE(
#include "MockDb.h" #include "MockDb.h"
// clang-format off
SQLPP_DECLARE_TABLE( SQLPP_DECLARE_TABLE(
(tab_person) (tab_person)
, ,
@ -60,6 +61,7 @@ SQLPP_DECLARE_TABLE(
(name , varchar(255), SQLPP_NULL ) (name , varchar(255), SQLPP_NULL )
(fatal, bool , SQLPP_NOT_NULL ) (fatal, bool , SQLPP_NOT_NULL )
) )
// clang-format on
int ppgen(int, char**) int ppgen(int, char**)
{ {
@ -83,7 +85,6 @@ int ppgen(int, char**)
// db(insert_into(f).set(f.name = "loves c++")); // db(insert_into(f).set(f.name = "loves c++"));
db(insert_into(f).default_values()); db(insert_into(f).default_values());
auto i = insert_into(p).columns(p.name, p.feature); auto i = insert_into(p).columns(p.name, p.feature);
@ -91,7 +92,6 @@ int ppgen(int, char**)
i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value); i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value);
db(i); db(i);
auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature))); auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature)));
pi.params.name = "likes java"; pi.params.name = "likes java";
pi.params.feature = true; pi.params.feature = true;

View File

@ -34,8 +34,6 @@ int remove(int, char**)
test::TabPerson p; test::TabPerson p;
test::TabFeature q; test::TabFeature q;
db(remove_from(p) db(remove_from(p).using_(p, q).where(p.feature == q.id and q.fatal == true));
.using_(p, q)
.where(p.feature == q.id and q.fatal == true));
return 0; return 0;
} }

View File

@ -40,18 +40,15 @@ int main()
auto s = select(all_of(p)) auto s = select(all_of(p))
.from(p, q) .from(p, q)
.where(p.name == any(select(q.name) .where(p.name == any(select(q.name).from(q).where(true)))
.from(q)
.where(true)))
.group_by(q.name) .group_by(q.name)
.having(p.name.like("%Bee%")) .having(p.name.like("%Bee%"))
.order_by(p.name.asc()) .order_by(p.name.asc())
.limit(3).offset(7); .limit(3)
.offset(7);
auto x = s.as(sqlpp::alias::x); auto x = s.as(sqlpp::alias::x);
for (const auto& row : db(select(p.id, x.name) for (const auto& row : db(select(p.id, x.name).from(p.join(x).on(p.feature == x.feature)).where(true)))
.from(p.join(x).on(p.feature == x.feature))
.where(true)))
{ {
int id = row.id; int id = row.id;
std::string name = row.name; std::string name = row.name;

View File

@ -53,7 +53,6 @@ int select(int, char**)
int64_t feature = row.feature; int64_t feature = row.feature;
} }
#if 0 #if 0
for (const auto& row : db(select(p.name).from(p).where(p.name.like("Herb%")))) for (const auto& row : db(select(p.name).from(p).where(p.name.like("Herb%"))))
{ {
@ -63,8 +62,6 @@ int select(int, char**)
} }
#endif #endif
#if 0 #if 0
for (const auto& row : db(select(p.name, f.name.as(cheesecake)).from(p,f).where(p.id > 7 and p.feature == 3))) for (const auto& row : db(select(p.name, f.name.as(cheesecake)).from(p,f).where(p.id > 7 and p.feature == 3)))
{ {
@ -75,8 +72,6 @@ int select(int, char**)
} }
#endif #endif
#if 0 #if 0
for (const auto& row : db(select(multi_column(all_of(p)).as(p), multi_column(f.name, f.id).as(f)).from(p,f).where(true))) for (const auto& row : db(select(multi_column(all_of(p)).as(p), multi_column(f.name, f.id).as(f)).from(p,f).where(true)))
{ {
@ -88,12 +83,6 @@ int select(int, char**)
} }
#endif #endif
#if 0 #if 0
auto s = select(p.id, p.name, f.id.as(cheesecake)) auto s = select(p.id, p.name, f.id.as(cheesecake))
.from(p, f) .from(p, f)
@ -117,8 +106,6 @@ int select(int, char**)
} }
#endif #endif
#if !0 #if !0
auto dysel = dynamic_select(db).dynamic_columns(p.name).from(p).dynamic_where(); auto dysel = dynamic_select(db).dynamic_columns(p.name).from(p).dynamic_where();
@ -135,23 +122,5 @@ int select(int, char**)
} }
#endif #endif
return 0; return 0;
} }

View File

@ -43,9 +43,9 @@ namespace sqlpp
using _alias_t = typename AliasProvider::_alias_t; using _alias_t = typename AliasProvider::_alias_t;
expression_alias_t(Expression expression): expression_alias_t(Expression expression) : _expression(expression)
_expression(expression) {
{} }
expression_alias_t(const expression_alias_t&) = default; expression_alias_t(const expression_alias_t&) = default;
expression_alias_t(expression_alias_t&&) = default; expression_alias_t(expression_alias_t&&) = default;
@ -70,7 +70,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -41,8 +41,14 @@
struct _member_t \ struct _member_t \
{ \ { \
T name; \ T name; \
T& operator()() { return name; }\ T& operator()() \
const T& operator()() const { return name; }\ { \
return name; \
} \
const T& operator()() const \
{ \
return name; \
} \
}; \ }; \
}; \ }; \
}; \ }; \
@ -57,7 +63,9 @@ namespace sqlpp
}; };
template <typename T> template <typename T>
struct is_alias_provider_t<T, typename std::enable_if<std::is_class<typename T::_alias_t::template _member_t<int>>::value, void>::type> struct is_alias_provider_t<
T,
typename std::enable_if<std::is_class<typename T::_alias_t::template _member_t<int>>::value, void>::type>
{ {
static constexpr bool value = true; static constexpr bool value = true;
}; };
@ -95,4 +103,3 @@ namespace sqlpp
} }
#endif #endif

View File

@ -73,8 +73,6 @@ namespace sqlpp
_serialize_check::_(); _serialize_check::_();
} }
}; };
} }
#endif #endif

View File

@ -39,9 +39,9 @@ namespace sqlpp
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>; using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
using _nodes = detail::type_vector<Select>; using _nodes = detail::type_vector<Select>;
any_t(Select select): any_t(Select select) : _select(select)
_select(select) {
{} }
any_t(const any_t&) = default; any_t(const any_t&) = default;
any_t(any_t&&) = default; any_t(any_t&&) = default;
@ -71,11 +71,11 @@ namespace sqlpp
auto any(T t) -> any_t<wrap_operand_t<T>> auto any(T t) -> any_t<wrap_operand_t<T>>
{ {
static_assert(is_select_t<wrap_operand_t<T>>::value, "any() requires a select expression as argument"); static_assert(is_select_t<wrap_operand_t<T>>::value, "any() requires a select expression as argument");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "any() requires a single column select expression as argument"); static_assert(is_expression_t<wrap_operand_t<T>>::value,
"any() requires a single column select expression as argument");
// FIXME: can we accept non-values like NULL here? // FIXME: can we accept non-values like NULL here?
return {t}; return {t};
} }
} }
#endif #endif

View File

@ -45,12 +45,13 @@ namespace sqlpp
using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>; using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>;
using _nodes = detail::type_vector<_lhs_t, _rhs_t>; using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
static_assert(can_be_null_t<_lhs_t>::value ? true : not (std::is_same<_rhs_t, null_t>::value or is_tvin_t<_rhs_t>::value), "column must not be null"); static_assert(can_be_null_t<_lhs_t>::value ? true
: not(std::is_same<_rhs_t, null_t>::value or is_tvin_t<_rhs_t>::value),
"column must not be null");
assignment_t(_lhs_t lhs, _rhs_t rhs): assignment_t(_lhs_t lhs, _rhs_t rhs) : _lhs(lhs), _rhs(rhs)
_lhs(lhs), {
_rhs(rhs) }
{}
assignment_t(const assignment_t&) = default; assignment_t(const assignment_t&) = default;
assignment_t(assignment_t&&) = default; assignment_t(assignment_t&&) = default;
@ -76,7 +77,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -62,5 +62,4 @@ namespace sqlpp
using auto_alias_t = typename detail::auto_alias_impl<T>::type; using auto_alias_t = typename detail::auto_alias_impl<T>::type;
} }
#endif #endif

View File

@ -42,28 +42,34 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T avg; T avg;
T& operator()() { return avg; } T& operator()()
const T& operator()() const { return avg; } {
return avg;
}
const T& operator()() const
{
return avg;
}
}; };
}; };
}; };
template <typename Flag, typename Expr> template <typename Flag, typename Expr>
struct avg_t: struct avg_t : public expression_operators<avg_t<Flag, Expr>, floating_point>,
public expression_operators<avg_t<Flag, Expr>, floating_point>,
public alias_operators<avg_t<Flag, Expr>> public alias_operators<avg_t<Flag, Expr>>
{ {
using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>; using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>; using _nodes = detail::type_vector<Expr, aggregate_function>;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "avg() used with flag other than 'distinct'"); static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value,
"avg() used with flag other than 'distinct'");
static_assert(is_numeric_t<Expr>::value, "avg() requires a value expression as argument"); static_assert(is_numeric_t<Expr>::value, "avg() requires a value expression as argument");
using _auto_alias_t = avg_alias_t; using _auto_alias_t = avg_alias_t;
avg_t(Expr expr): avg_t(Expr expr) : _expr(expr)
_expr(expr) {
{} }
avg_t(const avg_t&) = default; avg_t(const avg_t&) = default;
avg_t(avg_t&&) = default; avg_t(avg_t&&) = default;
@ -101,7 +107,8 @@ namespace sqlpp
template <typename T> template <typename T>
auto avg(T t) -> avg_t<noop, wrap_operand_t<T>> auto avg(T t) -> avg_t<noop, wrap_operand_t<T>>
{ {
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "avg() cannot be used on an aggregate function"); static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"avg() cannot be used on an aggregate function");
static_assert(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument"); static_assert(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return {t}; return {t};
} }
@ -109,11 +116,11 @@ namespace sqlpp
template <typename T> template <typename T>
auto avg(const distinct_t&, T t) -> avg_t<distinct_t, wrap_operand_t<T>> auto avg(const distinct_t&, T t) -> avg_t<distinct_t, wrap_operand_t<T>>
{ {
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "avg() cannot be used on an aggregate function"); static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"avg() cannot be used on an aggregate function");
static_assert(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument"); static_assert(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return {t}; return {t};
} }
} }
#endif #endif

View File

@ -32,10 +32,10 @@ namespace sqlpp
struct bad_statement struct bad_statement
{ {
template <typename... T> template <typename... T>
bad_statement(T&&...) {} bad_statement(T&&...)
{
}
}; };
} }
#endif #endif

View File

@ -47,8 +47,10 @@ namespace sqlpp
{ {
static constexpr bool value = static constexpr bool value =
(is_expression_t<T>::value // expressions are OK (is_expression_t<T>::value // expressions are OK
or is_multi_expression_t<T>::value) // multi-expressions like ANY are OK for comparisons, too or
and ValueType::template _is_valid_operand<T>::value // the correct value type is required, of course is_multi_expression_t<T>::value) // multi-expressions like ANY are OK for comparisons, too
and
ValueType::template _is_valid_operand<T>::value // the correct value type is required, of course
; ;
}; };
@ -130,14 +132,16 @@ namespace sqlpp
template <typename... T> template <typename... T>
in_t<Expr, wrap_operand_t<T>...> in(T... t) const in_t<Expr, wrap_operand_t<T>...> in(T... t) const
{ {
static_assert(logic::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid"); static_assert(logic::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value,
"at least one operand of in() is not valid");
return {*static_cast<const Expr*>(this), wrap_operand_t<T>{t}...}; return {*static_cast<const Expr*>(this), wrap_operand_t<T>{t}...};
} }
template <typename... T> template <typename... T>
not_in_t<Expr, wrap_operand_t<T>...> not_in(T... t) const not_in_t<Expr, wrap_operand_t<T>...> not_in(T... t) const
{ {
static_assert(logic::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid"); static_assert(logic::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value,
"at least one operand of in() is not valid");
return {*static_cast<const Expr*>(this), wrap_operand_t<T>{t}...}; return {*static_cast<const Expr*>(this), wrap_operand_t<T>{t}...};
} }
}; };
@ -151,6 +155,5 @@ namespace sqlpp
return {*static_cast<const Expr*>(this)}; return {*static_cast<const Expr*>(this)};
} }
}; };
} }
#endif #endif

View File

@ -55,15 +55,13 @@ namespace sqlpp
using _value_type = boolean; // FIXME using _value_type = boolean; // FIXME
using _cpp_value_type = typename _value_type::_cpp_value_type; using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t(): parameter_value_t() : _value(false), _is_null(true)
_value(false), {
_is_null(true) }
{}
parameter_value_t(const _cpp_value_type& val): parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false)
_value(val), {
_is_null(false) }
{}
parameter_value_t& operator=(const _cpp_value_type& val) parameter_value_t& operator=(const _cpp_value_type& val)
{ {
@ -104,7 +102,10 @@ namespace sqlpp
return _value; return _value;
} }
operator _cpp_value_type() const { return value(); } operator _cpp_value_type() const
{
return value();
}
template <typename Target> template <typename Target>
void _bind(Target& target, size_t index) const void _bind(Target& target, size_t index) const
@ -161,11 +162,9 @@ namespace sqlpp
static_assert(std::is_same<value_type_of<FieldSpec>, boolean>::value, "field type mismatch"); static_assert(std::is_same<value_type_of<FieldSpec>, boolean>::value, "field type mismatch");
using _cpp_value_type = typename boolean::_cpp_value_type; using _cpp_value_type = typename boolean::_cpp_value_type;
result_field_t(): result_field_t() : _is_valid(false), _is_null(true), _value(false)
_is_valid(false), {
_is_null(true), }
_value(false)
{}
void _validate() void _validate()
{ {
@ -230,6 +229,5 @@ namespace sqlpp
{ {
return serialize(e, os); return serialize(e, os);
} }
} }
#endif #endif

View File

@ -39,8 +39,8 @@ namespace sqlpp
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
template <typename Expr> template <typename Expr>
boolean_expression_t(Expr expr): boolean_expression_t(Expr expr)
_expr(expr) : _expr(expr)
{ {
static_assert(is_expression_t<Expr>::value, "boolean_expression requires a boolean expression argument"); static_assert(is_expression_t<Expr>::value, "boolean_expression requires a boolean expression argument");
static_assert(is_boolean_t<Expr>::value, "boolean_expression requires a boolean expression argument"); static_assert(is_boolean_t<Expr>::value, "boolean_expression requires a boolean expression argument");
@ -79,7 +79,6 @@ namespace sqlpp
return serialize(t._expr, context); return serialize(t._expr, context);
} }
}; };
} }
#endif #endif

View File

@ -31,7 +31,8 @@
namespace sqlpp namespace sqlpp
{ {
template<char... Cs> struct char_sequence template <char... Cs>
struct char_sequence
{ {
static const char* char_ptr() static const char* char_ptr()
{ {
@ -50,7 +51,8 @@ namespace sqlpp
}; };
template <std::size_t N, const char(&Input)[N]> template <std::size_t N, const char(&Input)[N]>
using make_char_sequence = typename make_char_sequence_impl<sizeof(Input), Input, sqlpp::detail::make_index_sequence<sizeof(Input)>>::type; using make_char_sequence =
typename make_char_sequence_impl<sizeof(Input), Input, sqlpp::detail::make_index_sequence<sizeof(Input)>>::type;
} }
#endif #endif

View File

@ -42,14 +42,14 @@
namespace sqlpp namespace sqlpp
{ {
template <typename Table, typename ColumnSpec> template <typename Table, typename ColumnSpec>
struct column_t: struct column_t : public expression_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>,
public expression_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>,
public column_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>> public column_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>
{ {
struct _traits struct _traits
{ {
using _value_type = value_type_of<ColumnSpec>; using _value_type = value_type_of<ColumnSpec>;
using _tags = detail::make_joined_set_t<detail::type_set<tag::is_column, tag::is_expression, tag::is_selectable>, typename ColumnSpec::_traits::_tags>; using _tags = detail::make_joined_set_t<detail::type_set<tag::is_column, tag::is_expression, tag::is_selectable>,
typename ColumnSpec::_traits::_tags>;
}; };
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
@ -92,15 +92,13 @@ namespace sqlpp
return {*this, {rhs{t}}}; return {*this, {rhs{t}}};
} }
auto operator =(null_t) const auto operator=(null_t) const -> assignment_t<column_t, null_t>
->assignment_t<column_t, null_t>
{ {
static_assert(can_be_null_t<column_t>::value, "column cannot be null"); static_assert(can_be_null_t<column_t>::value, "column cannot be null");
return {*this, null_t{}}; return {*this, null_t{}};
} }
auto operator =(default_value_t) const auto operator=(default_value_t) const -> assignment_t<column_t, default_value_t>
->assignment_t<column_t, default_value_t>
{ {
return {*this, default_value_t{}}; return {*this, default_value_t{}};
} }
@ -118,7 +116,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -24,7 +24,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SQLPP_COLUMN_FWD_H #ifndef SQLPP_COLUMN_FWD_H
#define SQLPP_COLUMN_FWD_H #define SQLPP_COLUMN_FWD_H

View File

@ -52,18 +52,16 @@ namespace sqlpp
}; };
template <typename... Args> template <typename... Args>
struct concat_t: struct concat_t : public expression_operators<concat_t<Args...>, text>, public alias_operators<concat_t<Args...>>
public expression_operators<concat_t<Args...>, text>,
public alias_operators<concat_t<Args...>>
{ {
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>; using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Args...>; using _nodes = detail::type_vector<Args...>;
using _auto_alias_t = concat_alias_t; using _auto_alias_t = concat_alias_t;
concat_t(Args... args): concat_t(Args... args) : _args(args...)
_args(args...) {
{} }
concat_t(const concat_t&) = default; concat_t(const concat_t&) = default;
concat_t(concat_t&&) = default; concat_t(concat_t&&) = default;
@ -90,11 +88,11 @@ namespace sqlpp
}; };
template <typename... Args> template <typename... Args>
auto concat(Args... args) auto concat(Args... args) -> concat_t<Args...>
-> concat_t<Args...>
{ {
static_assert(sizeof...(Args) >= 2, "concat requires two arguments at least"); static_assert(sizeof...(Args) >= 2, "concat requires two arguments at least");
static_assert(logic::all_t<is_text_t<wrap_operand_t<Args>>::value...>::value, "at least one non-text argument detected in concat()"); static_assert(logic::all_t<is_text_t<wrap_operand_t<Args>>::value...>::value,
"at least one non-text argument detected in concat()");
return {args...}; return {args...};
} }

View File

@ -29,8 +29,9 @@
namespace sqlpp namespace sqlpp
{ {
struct connection {}; struct connection
{
};
} }
#endif #endif

View File

@ -43,15 +43,20 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T count; T count;
T& operator()() { return count; } T& operator()()
const T& operator()() const { return count; } {
return count;
}
const T& operator()() const
{
return count;
}
}; };
}; };
}; };
template <typename Flag, typename Expr> template <typename Flag, typename Expr>
struct count_t: struct count_t : public expression_operators<count_t<Flag, Expr>, integral>,
public expression_operators<count_t<Flag, Expr>, integral>,
public alias_operators<count_t<Flag, Expr>> public alias_operators<count_t<Flag, Expr>>
{ {
using _traits = make_traits<integral, tag::is_expression /*, tag::is_selectable*/>; using _traits = make_traits<integral, tag::is_expression /*, tag::is_selectable*/>;
@ -59,13 +64,14 @@ namespace sqlpp
using _nodes = detail::type_vector<Expr, aggregate_function>; using _nodes = detail::type_vector<Expr, aggregate_function>;
using _can_be_null = std::false_type; using _can_be_null = std::false_type;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "count() used with flag other than 'distinct'"); static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value,
"count() used with flag other than 'distinct'");
using _auto_alias_t = count_alias_t; using _auto_alias_t = count_alias_t;
count_t(const Expr expr): count_t(const Expr expr) : _expr(expr)
_expr(expr) {
{} }
count_t(const count_t&) = default; count_t(const count_t&) = default;
count_t(count_t&&) = default; count_t(count_t&&) = default;
@ -103,7 +109,8 @@ namespace sqlpp
template <typename T> template <typename T>
auto count(T t) -> count_t<noop, wrap_operand_t<T>> auto count(T t) -> count_t<noop, wrap_operand_t<T>>
{ {
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "count() cannot be used on an aggregate function"); static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"count() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument"); static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return {t}; return {t};
} }
@ -111,11 +118,11 @@ namespace sqlpp
template <typename T> template <typename T>
auto count(const distinct_t&, T t) -> count_t<distinct_t, wrap_operand_t<T>> auto count(const distinct_t&, T t) -> count_t<distinct_t, wrap_operand_t<T>>
{ {
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "count() cannot be used on an aggregate function"); static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"count() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument"); static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return {t}; return {t};
} }
} }
#endif #endif

View File

@ -47,10 +47,9 @@ namespace sqlpp
using _required_ctes = detail::make_joined_set_t<required_ctes_of<Lhs>, required_ctes_of<Rhs>>; using _required_ctes = detail::make_joined_set_t<required_ctes_of<Lhs>, required_ctes_of<Rhs>>;
using _parameters = detail::type_vector_cat_t<parameters_of<Lhs>, parameters_of<Rhs>>; using _parameters = detail::type_vector_cat_t<parameters_of<Lhs>, parameters_of<Rhs>>;
cte_union_t(Lhs lhs, Rhs rhs): cte_union_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
_lhs(lhs), {
_rhs(rhs) }
{}
cte_union_t(const cte_union_t&) = default; cte_union_t(const cte_union_t&) = default;
cte_union_t(cte_union_t&&) = default; cte_union_t(cte_union_t&&) = default;
@ -98,7 +97,6 @@ namespace sqlpp
using type = cte_ref_t<AliasProvider>; using type = cte_ref_t<AliasProvider>;
}; };
template <typename FieldSpec> template <typename FieldSpec>
struct cte_column_spec_t struct cte_column_spec_t
{ {
@ -107,8 +105,7 @@ namespace sqlpp
using _traits = make_traits<value_type_of<FieldSpec>, using _traits = make_traits<value_type_of<FieldSpec>,
tag::must_not_insert, tag::must_not_insert,
tag::must_not_update, tag::must_not_update,
tag_if<tag::can_be_null, column_spec_can_be_null_t<FieldSpec>::value> tag_if<tag::can_be_null, column_spec_can_be_null_t<FieldSpec>::value>>;
>;
}; };
template <typename AliasProvider, typename Statement, typename ResultRow> template <typename AliasProvider, typename Statement, typename ResultRow>
@ -127,7 +124,8 @@ namespace sqlpp
using make_cte_t = typename make_cte_impl<AliasProvider, Statement, get_result_row_t<Statement>>::type; using make_cte_t = typename make_cte_impl<AliasProvider, Statement, get_result_row_t<Statement>>::type;
template <typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct cte_t: public member_t<cte_column_spec_t<FieldSpecs>, column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>>... struct cte_t
: public member_t<cte_column_spec_t<FieldSpecs>, column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>>...
{ {
using _traits = make_traits<no_value_t, tag::is_cte, tag::is_table>; // FIXME: is table? really? using _traits = make_traits<no_value_t, tag::is_cte, tag::is_table>; // FIXME: is table? really?
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
@ -145,35 +143,40 @@ namespace sqlpp
using _result_row_t = result_row_t<void, FieldSpecs...>; using _result_row_t = result_row_t<void, FieldSpecs...>;
template <typename Rhs> template <typename Rhs>
auto union_distinct(Rhs rhs) const auto union_distinct(Rhs rhs) const ->
-> typename std::conditional<_check<Rhs>::value, cte_t<AliasProvider, cte_union_t<distinct_t, Statement, Rhs>, FieldSpecs...>, bad_statement>::type typename std::conditional<_check<Rhs>::value,
cte_t<AliasProvider, cte_union_t<distinct_t, Statement, Rhs>, FieldSpecs...>,
bad_statement>::type
{ {
static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement"); static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement");
static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select"); static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select");
static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement"); static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement");
static_assert(std::is_same<_result_row_t, get_result_row_t<Rhs>>::value, "both select statements in a union have to have the same result columns (type and name)"); static_assert(std::is_same<_result_row_t, get_result_row_t<Rhs>>::value,
"both select statements in a union have to have the same result columns (type and name)");
return _union_impl<void, distinct_t>(_check<Rhs>{}, rhs); return _union_impl<void, distinct_t>(_check<Rhs>{}, rhs);
} }
template <typename Rhs> template <typename Rhs>
auto union_all(Rhs rhs) const auto union_all(Rhs rhs) const ->
-> typename std::conditional<_check<Rhs>::value, cte_t<AliasProvider, cte_union_t<all_t, Statement, Rhs>, FieldSpecs...>, bad_statement>::type typename std::conditional<_check<Rhs>::value,
cte_t<AliasProvider, cte_union_t<all_t, Statement, Rhs>, FieldSpecs...>,
bad_statement>::type
{ {
static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement"); static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement");
static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select"); static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select");
static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement"); static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement");
static_assert(std::is_same<_result_row_t, get_result_row_t<Rhs>>::value, "both select statements in a union have to have the same result columns (type and name)"); static_assert(std::is_same<_result_row_t, get_result_row_t<Rhs>>::value,
"both select statements in a union have to have the same result columns (type and name)");
return _union_impl<all_t>(_check<Rhs>{}, rhs); return _union_impl<all_t>(_check<Rhs>{}, rhs);
} }
private: private:
template <typename Flag, typename Rhs> template <typename Flag, typename Rhs>
auto _union_impl(const std::false_type&, Rhs rhs) const auto _union_impl(const std::false_type&, Rhs rhs) const -> bad_statement;
-> bad_statement;
template <typename Flag, typename Rhs> template <typename Flag, typename Rhs>
auto _union_impl(const std::true_type&, Rhs rhs) const auto _union_impl(const std::true_type&, Rhs rhs) const
@ -183,8 +186,9 @@ namespace sqlpp
} }
public: public:
cte_t(Statement statement) : _statement(statement)
cte_t(Statement statement): _statement(statement){} {
}
cte_t(const cte_t&) = default; cte_t(const cte_t&) = default;
cte_t(cte_t&&) = default; cte_t(cte_t&&) = default;
cte_t& operator=(const cte_t&) = default; cte_t& operator=(const cte_t&) = default;
@ -209,7 +213,6 @@ namespace sqlpp
} }
}; };
// The cte_t is displayed as AliasProviderName except within the with: // The cte_t is displayed as AliasProviderName except within the with:
// - the with needs the // - the with needs the
// AliasProviderName AS (ColumnNames) (select/union) // AliasProviderName AS (ColumnNames) (select/union)
@ -225,12 +228,15 @@ namespace sqlpp
using _alias_t = typename AliasProvider::_alias_t; using _alias_t = typename AliasProvider::_alias_t;
template <typename Statement> template <typename Statement>
auto as(Statement statement) auto as(Statement statement) -> make_cte_t<AliasProvider, Statement>
-> make_cte_t<AliasProvider, Statement>
{ {
static_assert(required_tables_of<Statement>::size::value == 0, "common table expression must not use unknown tables"); static_assert(required_tables_of<Statement>::size::value == 0,
static_assert(not detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value, "common table expression must not self-reference in the first part, use union_all/union_distinct for recursion"); "common table expression must not use unknown tables");
static_assert(is_static_result_row_t<get_result_row_t<Statement>>::value, "ctes must not have dynamically added columns"); static_assert(not detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value,
"common table expression must not self-reference in the first part, use union_all/union_distinct "
"for recursion");
static_assert(is_static_result_row_t<get_result_row_t<Statement>>::value,
"ctes must not have dynamically added columns");
return {statement}; return {statement};
} }
@ -250,12 +256,10 @@ namespace sqlpp
}; };
template <typename AliasProvider> template <typename AliasProvider>
auto cte(const AliasProvider&) auto cte(const AliasProvider&) -> cte_ref_t<AliasProvider>
-> cte_ref_t<AliasProvider>
{ {
return {}; return {};
} }
} }
#endif #endif

View File

@ -49,26 +49,26 @@ namespace sqlpp
} }
template <typename Database, typename... Parts> template <typename Database, typename... Parts>
struct custom_query_t: struct custom_query_t : private detail::custom_parts_t<Database, Parts...>::_result_methods_t
private detail::custom_parts_t<Database, Parts...>::_result_methods_t
{ {
using _methods_t = typename detail::custom_parts_t<Database, Parts...>::_result_methods_t; using _methods_t = typename detail::custom_parts_t<Database, Parts...>::_result_methods_t;
using _traits = make_traits<no_value_t, tag::is_statement>; using _traits = make_traits<no_value_t, tag::is_statement>;
using _nodes = detail::type_vector<Parts...>; using _nodes = detail::type_vector<Parts...>;
using _parameter_check = typename std::conditional<detail::type_vector_size<parameters_of<custom_query_t>>::value == 0, using _parameter_check =
consistent_t, assert_no_parameters_t>::type; typename std::conditional<detail::type_vector_size<parameters_of<custom_query_t>>::value == 0,
using _run_check = detail::get_first_if<is_inconsistent_t, consistent_t, consistent_t,
_parameter_check>; assert_no_parameters_t>::type;
using _run_check = detail::get_first_if<is_inconsistent_t, consistent_t, _parameter_check>;
using _prepare_check = consistent_t; using _prepare_check = consistent_t;
custom_query_t(Parts... parts): custom_query_t(Parts... parts) : _parts(parts...)
_parts(parts...) {
{} }
custom_query_t(std::tuple<Parts...> parts): custom_query_t(std::tuple<Parts...> parts) : _parts(parts)
_parts(parts) {
{} }
custom_query_t(const custom_query_t&) = default; custom_query_t(const custom_query_t&) = default;
custom_query_t(custom_query_t&&) = default; custom_query_t(custom_query_t&&) = default;
@ -101,8 +101,7 @@ namespace sqlpp
} }
template <typename Part> template <typename Part>
auto with_result_type_of(Part part) auto with_result_type_of(Part part) -> custom_query_t<Database, Part, Parts...>
-> custom_query_t<Database, Part, Parts...>
{ {
return {tuple_cat(std::make_tuple(part), _parts)}; return {tuple_cat(std::make_tuple(part), _parts)};
} }
@ -124,16 +123,14 @@ namespace sqlpp
}; };
template <typename... Parts> template <typename... Parts>
auto custom_query(Parts... parts) auto custom_query(Parts... parts) -> custom_query_t<void, wrap_operand_t<Parts>...>
-> custom_query_t<void, wrap_operand_t<Parts>...>
{ {
static_assert(sizeof...(Parts) > 0, "custom query requires at least one argument"); static_assert(sizeof...(Parts) > 0, "custom query requires at least one argument");
return custom_query_t<void, wrap_operand_t<Parts>...>(parts...); return custom_query_t<void, wrap_operand_t<Parts>...>(parts...);
} }
template <typename Database, typename... Parts> template <typename Database, typename... Parts>
auto dynamic_custom_query(const Database&, Parts... parts) auto dynamic_custom_query(const Database&, Parts... parts) -> custom_query_t<Database, wrap_operand_t<Parts>...>
-> custom_query_t<Database, wrap_operand_t<Parts>...>
{ {
static_assert(sizeof...(Parts) > 0, "custom query requires at least one query argument"); static_assert(sizeof...(Parts) > 0, "custom query requires at least one query argument");
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter"); static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");

View File

@ -36,7 +36,10 @@ namespace sqlpp
using _traits = make_traits<no_value_t, tag::is_expression>; using _traits = make_traits<no_value_t, tag::is_expression>;
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
static constexpr bool _is_trivial() { return false; } static constexpr bool _is_trivial()
{
return false;
}
}; };
template <typename Context> template <typename Context>
@ -53,7 +56,6 @@ namespace sqlpp
}; };
constexpr default_value_t default_value = {}; constexpr default_value_t default_value = {};
} }
#endif #endif

View File

@ -40,19 +40,28 @@ namespace sqlpp
template <typename T> template <typename T>
struct as_column_tuple struct as_column_tuple
{ {
static std::tuple<auto_alias_t<T>> _(T t) { return std::tuple<auto_alias_t<T>>(auto_alias_t<T>{t}); } static std::tuple<auto_alias_t<T>> _(T t)
{
return std::tuple<auto_alias_t<T>>(auto_alias_t<T>{t});
}
}; };
template <typename T> template <typename T>
struct as_column_tuple<all_of_t<T>> struct as_column_tuple<all_of_t<T>>
{ {
static typename all_of_t<T>::_column_tuple_t _(all_of_t<T>) { return { }; } static typename all_of_t<T>::_column_tuple_t _(all_of_t<T>)
{
return {};
}
}; };
template <typename... Args> template <typename... Args>
struct as_column_tuple<std::tuple<Args...>> struct as_column_tuple<std::tuple<Args...>>
{ {
static std::tuple<auto_alias_t<Args>...> _(std::tuple<Args...> t) { return t; } static std::tuple<auto_alias_t<Args>...> _(std::tuple<Args...> t)
{
return t;
}
}; };
template <template <typename, typename...> class Target, typename First, typename T> template <template <typename, typename...> class Target, typename First, typename T>
@ -75,9 +84,7 @@ namespace sqlpp
{ {
return std::tuple_cat(as_column_tuple<Columns>::_(columns)...); return std::tuple_cat(as_column_tuple<Columns>::_(columns)...);
} }
} }
} }
#endif #endif

View File

@ -46,16 +46,29 @@ namespace sqlpp
static_assert(wrong_t<make_field_index_sequence_impl>::value, "invalid field index sequence arguments"); static_assert(wrong_t<make_field_index_sequence_impl>::value, "invalid field index sequence arguments");
}; };
template<std::size_t NextIndex, std::size_t... Ints, typename NameType, typename ValueType, bool CanBeNull, bool NullIsTrivialValue, typename... Rest> template <std::size_t NextIndex,
struct make_field_index_sequence_impl<field_index_sequence<NextIndex, Ints...>, field_spec_t<NameType, ValueType, CanBeNull, NullIsTrivialValue>, Rest...> std::size_t... Ints,
typename NameType,
typename ValueType,
bool CanBeNull,
bool NullIsTrivialValue,
typename... Rest>
struct make_field_index_sequence_impl<field_index_sequence<NextIndex, Ints...>,
field_spec_t<NameType, ValueType, CanBeNull, NullIsTrivialValue>,
Rest...>
{ {
using type = typename make_field_index_sequence_impl<field_index_sequence<NextIndex + 1, Ints..., NextIndex>, Rest...>::type; using type = typename make_field_index_sequence_impl<field_index_sequence<NextIndex + 1, Ints..., NextIndex>,
Rest...>::type;
}; };
template <std::size_t NextIndex, std::size_t... Ints, typename AliasProvider, typename FieldTuple, typename... Rest> template <std::size_t NextIndex, std::size_t... Ints, typename AliasProvider, typename FieldTuple, typename... Rest>
struct make_field_index_sequence_impl<field_index_sequence<NextIndex, Ints...>, multi_field_spec_t<AliasProvider, FieldTuple>, Rest...> struct make_field_index_sequence_impl<field_index_sequence<NextIndex, Ints...>,
multi_field_spec_t<AliasProvider, FieldTuple>,
Rest...>
{ {
using type = typename make_field_index_sequence_impl<field_index_sequence<NextIndex + std::tuple_size<FieldTuple>::value, Ints..., NextIndex>, Rest...>::type; using type = typename make_field_index_sequence_impl<
field_index_sequence<NextIndex + std::tuple_size<FieldTuple>::value, Ints..., NextIndex>,
Rest...>::type;
}; };
template <std::size_t NextIndex, std::size_t... Ints> template <std::size_t NextIndex, std::size_t... Ints>
@ -65,10 +78,9 @@ namespace sqlpp
}; };
template <std::size_t StartIndex, typename... Fields> template <std::size_t StartIndex, typename... Fields>
using make_field_index_sequence = typename make_field_index_sequence_impl<field_index_sequence<StartIndex>, Fields...>::type; using make_field_index_sequence =
typename make_field_index_sequence_impl<field_index_sequence<StartIndex>, Fields...>::type;
} }
} }
#endif #endif

View File

@ -46,9 +46,7 @@ namespace sqlpp
struct get_first_if_impl<Predicate, Default, T, Rest...> struct get_first_if_impl<Predicate, Default, T, Rest...>
{ {
using rest = typename get_first_if_impl<Predicate, Default, Rest...>::type; using rest = typename get_first_if_impl<Predicate, Default, Rest...>::type;
using type = typename std::conditional<Predicate<T>::value, using type = typename std::conditional<Predicate<T>::value, T, rest>::type;
T,
rest>::type;
}; };
template <template <typename> class Predicate, typename Default, typename... T> template <template <typename> class Predicate, typename Default, typename... T>
@ -56,5 +54,4 @@ namespace sqlpp
} }
} }
#endif #endif

View File

@ -46,9 +46,7 @@ namespace sqlpp
struct get_last_if_impl<Predicate, Default, T, Rest...> struct get_last_if_impl<Predicate, Default, T, Rest...>
{ {
using rest = typename get_last_if_impl<Predicate, Default, Rest...>::type; using rest = typename get_last_if_impl<Predicate, Default, Rest...>::type;
using type = typename std::conditional<std::is_same<rest, Default>::value and Predicate<T>::value, using type = typename std::conditional<std::is_same<rest, Default>::value and Predicate<T>::value, T, rest>::type;
T,
rest>::type;
}; };
template <template <typename> class Predicate, typename Default, typename... T> template <template <typename> class Predicate, typename Default, typename... T>
@ -56,5 +54,4 @@ namespace sqlpp
} }
} }
#endif #endif

View File

@ -37,7 +37,8 @@ namespace sqlpp
// It should be replaced once the project is moved to C++14 or beyond // It should be replaced once the project is moved to C++14 or beyond
template <std::size_t... Ints> template <std::size_t... Ints>
struct index_sequence struct index_sequence
{}; {
};
template <typename T, std::size_t N> template <typename T, std::size_t N>
struct make_index_sequence_impl; struct make_index_sequence_impl;
@ -56,9 +57,7 @@ namespace sqlpp
template <std::size_t N> template <std::size_t N>
using make_index_sequence = typename make_index_sequence_impl<index_sequence<>, N>::type; using make_index_sequence = typename make_index_sequence_impl<index_sequence<>, N>::type;
} }
} }
#endif #endif

View File

@ -54,5 +54,4 @@ namespace sqlpp
} }
} }
#endif #endif

View File

@ -31,7 +31,6 @@ namespace sqlpp
{ {
namespace detail namespace detail
{ {
/** a non-recursive C++14 version /** a non-recursive C++14 version
template<typename... Args> template<typename... Args>
constexpr std::size_t sum(Args... args) constexpr std::size_t sum(Args... args)
@ -59,4 +58,3 @@ namespace sqlpp
} }
#endif #endif

View File

@ -52,14 +52,14 @@ namespace sqlpp
using size = std::integral_constant<size_t, sizeof...(Elements)>; using size = std::integral_constant<size_t, sizeof...(Elements)>;
using _is_type_set = std::true_type; using _is_type_set = std::true_type;
static_assert(std::is_same<type_set, make_type_set_t<Elements...>>::value, "use make_type_set to construct a typeset"); static_assert(std::is_same<type_set, make_type_set_t<Elements...>>::value,
"use make_type_set to construct a typeset");
template <typename T> template <typename T>
struct insert struct insert
{ {
using type = typename std::conditional<not is_element_of<T, type_set>::value, using type =
type_set<T, Elements...>, typename std::conditional<not is_element_of<T, type_set>::value, type_set<T, Elements...>, type_set>::type;
type_set>::type;
}; };
template <template <typename A> class Predicate, typename T> template <template <typename A> class Predicate, typename T>
@ -71,7 +71,6 @@ namespace sqlpp
}; };
}; };
template <typename E, typename SET> template <typename E, typename SET>
struct is_element_of struct is_element_of
{ {
@ -108,7 +107,8 @@ namespace sqlpp
template <typename... LElements, typename... RElements> template <typename... LElements, typename... RElements>
struct is_superset_of<type_set<LElements...>, type_set<RElements...>> struct is_superset_of<type_set<LElements...>, type_set<RElements...>>
{ {
static constexpr bool value = joined_set_t<type_set<LElements...>, type_set<RElements...>>::size::value == sizeof...(LElements); static constexpr bool value =
joined_set_t<type_set<LElements...>, type_set<RElements...>>::size::value == sizeof...(LElements);
}; };
template <typename L, typename R> template <typename L, typename R>
@ -126,7 +126,8 @@ namespace sqlpp
template <typename... LElements, typename... RElements> template <typename... LElements, typename... RElements>
struct is_disjunct_from<type_set<LElements...>, type_set<RElements...>> struct is_disjunct_from<type_set<LElements...>, type_set<RElements...>>
{ {
static constexpr bool value = joined_set_t<type_set<LElements...>, type_set<RElements...>>::size::value == sizeof...(LElements) + sizeof...(RElements); static constexpr bool value = joined_set_t<type_set<LElements...>, type_set<RElements...>>::size::value ==
sizeof...(LElements) + sizeof...(RElements);
}; };
template <> template <>
@ -223,14 +224,14 @@ namespace sqlpp
struct make_intersect_set<type_set<LhsElements...>, type_set<RhsElements...>> struct make_intersect_set<type_set<LhsElements...>, type_set<RhsElements...>>
{ {
template <typename E> template <typename E>
using is_in_both = ::sqlpp::logic::all_t<is_element_of<E, type_set<LhsElements...>>::value, is_element_of<E, type_set<RhsElements...>>::value>; using is_in_both = ::sqlpp::logic::all_t<is_element_of<E, type_set<LhsElements...>>::value,
is_element_of<E, type_set<RhsElements...>>::value>;
using type = make_type_set_if_t<is_in_both, LhsElements...>; using type = make_type_set_if_t<is_in_both, LhsElements...>;
}; };
template <typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using make_intersect_set_t = typename make_intersect_set<Lhs, Rhs>::type; using make_intersect_set_t = typename make_intersect_set<Lhs, Rhs>::type;
template <template <typename> class Transformation, typename T> template <template <typename> class Transformation, typename T>
struct transform_set struct transform_set
{ {
@ -245,11 +246,7 @@ namespace sqlpp
template <template <typename> class Transformation, typename T> template <template <typename> class Transformation, typename T>
using transform_set_t = typename transform_set<Transformation, T>::type; using transform_set_t = typename transform_set<Transformation, T>::type;
} }
} }
#endif #endif

View File

@ -35,7 +35,8 @@ namespace sqlpp
{ {
template <typename... T> template <typename... T>
struct type_vector struct type_vector
{}; {
};
template <typename... T> template <typename... T>
struct type_vector_cat_impl struct type_vector_cat_impl
@ -73,7 +74,8 @@ namespace sqlpp
template <typename T> template <typename T>
struct type_vector_size struct type_vector_size
{ {
static_assert(wrong_t<type_vector_size>::value, "type_vector_size needs to be called with a type_vector argument"); static_assert(wrong_t<type_vector_size>::value,
"type_vector_size needs to be called with a type_vector argument");
}; };
template <typename... T> template <typename... T>
@ -84,5 +86,4 @@ namespace sqlpp
} }
} }
#endif #endif

View File

@ -38,15 +38,19 @@ namespace sqlpp
struct eval_t struct eval_t
{ {
static_assert(is_database<Db>::value, "Db parameter of eval has to be a database connection"); static_assert(is_database<Db>::value, "Db parameter of eval has to be a database connection");
static_assert(is_expression_t<Expr>::value, "Expression parameter of eval has to be an sqlpp expression or a string"); static_assert(is_expression_t<Expr>::value,
static_assert(required_tables_of<Expr>::size::value == 0, "Expression cannot be used in eval because it requires tables"); "Expression parameter of eval has to be an sqlpp expression or a string");
static_assert(required_tables_of<Expr>::size::value == 0,
"Expression cannot be used in eval because it requires tables");
using _name_type = alias::a_t::_alias_t; using _name_type = alias::a_t::_alias_t;
using _value_type = value_type_of<Expr>; using _value_type = value_type_of<Expr>;
using _field_spec = field_spec_t<_name_type, _value_type, true, false>; using _field_spec = field_spec_t<_name_type, _value_type, true, false>;
using type = result_field_t<_value_type, Db, _field_spec>; using type = result_field_t<_value_type, Db, _field_spec>;
}; };
template<typename Db, typename Expr, typename std::enable_if<not std::is_convertible<Expr, std::string>::value, int>::type = 0> template <typename Db,
typename Expr,
typename std::enable_if<not std::is_convertible<Expr, std::string>::value, int>::type = 0>
auto eval(Db& db, Expr expr) -> typename eval_t<Db, Expr>::type auto eval(Db& db, Expr expr) -> typename eval_t<Db, Expr>::type
{ {
return db(select(expr.as(alias::a))).front().a; return db(select(expr.as(alias::a))).front().a;

View File

@ -34,10 +34,13 @@ namespace sqlpp
class exception : public std::runtime_error class exception : public std::runtime_error
{ {
public: public:
exception(const std::string& what_arg): std::runtime_error(what_arg) {} exception(const std::string& what_arg) : std::runtime_error(what_arg)
exception(const char* what_arg): std::runtime_error(what_arg) {} {
}
exception(const char* what_arg) : std::runtime_error(what_arg)
{
}
}; };
} }
#endif #endif

View File

@ -42,16 +42,20 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T exists; T exists;
T& operator()() { return exists; } T& operator()()
const T& operator()() const { return exists; } {
return exists;
}
const T& operator()() const
{
return exists;
}
}; };
}; };
}; };
template <typename Select> template <typename Select>
struct exists_t: struct exists_t : public expression_operators<exists_t<Select>, boolean>, public alias_operators<exists_t<Select>>
public expression_operators<exists_t<Select>, boolean>,
public alias_operators<exists_t<Select>>
{ {
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>; using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Select>; using _nodes = detail::type_vector<Select>;
@ -60,9 +64,9 @@ namespace sqlpp
using _auto_alias_t = exists_alias_t; using _auto_alias_t = exists_alias_t;
exists_t(Select select): exists_t(Select select) : _select(select)
_select(select) {
{} }
exists_t(const exists_t&) = default; exists_t(const exists_t&) = default;
exists_t(exists_t&&) = default; exists_t(exists_t&&) = default;
@ -88,14 +92,12 @@ namespace sqlpp
} }
}; };
template <typename T> template <typename T>
auto exists(T t) -> exists_t<wrap_operand_t<T>> auto exists(T t) -> exists_t<wrap_operand_t<T>>
{ {
static_assert(is_select_t<wrap_operand_t<T>>::value, "exists() requires a select expression as argument"); static_assert(is_select_t<wrap_operand_t<T>>::value, "exists() requires a select expression as argument");
return {t}; return {t};
} }
} }
#endif #endif

View File

@ -39,8 +39,8 @@
namespace sqlpp namespace sqlpp
{ {
template <typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
struct binary_expression_t<Lhs, op::equal_to, Rhs>: struct binary_expression_t<Lhs, op::equal_to, Rhs>
public expression_operators<binary_expression_t<Lhs, op::equal_to, Rhs>, boolean>, : public expression_operators<binary_expression_t<Lhs, op::equal_to, Rhs>, boolean>,
public alias_operators<binary_expression_t<Lhs, op::equal_to, Rhs>> public alias_operators<binary_expression_t<Lhs, op::equal_to, Rhs>>
{ {
using _traits = make_traits<boolean, tag::is_expression>; using _traits = make_traits<boolean, tag::is_expression>;
@ -48,10 +48,9 @@ namespace sqlpp
using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>; using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>;
using _nodes = detail::type_vector<_lhs_t, _rhs_t>; using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
binary_expression_t(_lhs_t lhs, _rhs_t rhs): binary_expression_t(_lhs_t lhs, _rhs_t rhs) : _lhs(lhs), _rhs(rhs)
_lhs(lhs), {
_rhs(rhs) }
{}
binary_expression_t(const binary_expression_t&) = default; binary_expression_t(const binary_expression_t&) = default;
binary_expression_t(binary_expression_t&&) = default; binary_expression_t(binary_expression_t&&) = default;
@ -88,8 +87,8 @@ namespace sqlpp
}; };
template <typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
struct binary_expression_t<Lhs, op::not_equal_to, Rhs>: struct binary_expression_t<Lhs, op::not_equal_to, Rhs>
public expression_operators<binary_expression_t<Lhs, op::not_equal_to, Rhs>, boolean>, : public expression_operators<binary_expression_t<Lhs, op::not_equal_to, Rhs>, boolean>,
public alias_operators<binary_expression_t<Lhs, op::not_equal_to, Rhs>> public alias_operators<binary_expression_t<Lhs, op::not_equal_to, Rhs>>
{ {
using _traits = make_traits<boolean, tag::is_expression>; using _traits = make_traits<boolean, tag::is_expression>;
@ -97,10 +96,9 @@ namespace sqlpp
using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>; using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>;
using _nodes = detail::type_vector<_lhs_t, _rhs_t>; using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
binary_expression_t(Lhs lhs, _rhs_t rhs): binary_expression_t(Lhs lhs, _rhs_t rhs) : _lhs(lhs), _rhs(rhs)
_lhs(lhs), {
_rhs(rhs) }
{}
binary_expression_t(const binary_expression_t&) = default; binary_expression_t(const binary_expression_t&) = default;
binary_expression_t(binary_expression_t&&) = default; binary_expression_t(binary_expression_t&&) = default;
@ -137,16 +135,16 @@ namespace sqlpp
}; };
template <typename Rhs> template <typename Rhs>
struct unary_expression_t<op::logical_not, Rhs>: struct unary_expression_t<op::logical_not, Rhs>
public expression_operators<unary_expression_t<op::logical_not, Rhs>, boolean>, : public expression_operators<unary_expression_t<op::logical_not, Rhs>, boolean>,
public alias_operators<unary_expression_t<op::logical_not, Rhs>> public alias_operators<unary_expression_t<op::logical_not, Rhs>>
{ {
using _traits = make_traits<boolean, tag::is_expression>; using _traits = make_traits<boolean, tag::is_expression>;
using _nodes = detail::type_vector<Rhs>; using _nodes = detail::type_vector<Rhs>;
unary_expression_t(Rhs rhs): unary_expression_t(Rhs rhs) : _rhs(rhs)
_rhs(rhs) {
{} }
unary_expression_t(const unary_expression_t&) = default; unary_expression_t(const unary_expression_t&) = default;
unary_expression_t(unary_expression_t&&) = default; unary_expression_t(unary_expression_t&&) = default;
@ -183,17 +181,15 @@ namespace sqlpp
}; };
template <typename Lhs, typename O, typename Rhs> template <typename Lhs, typename O, typename Rhs>
struct binary_expression_t: struct binary_expression_t : public expression_operators<binary_expression_t<Lhs, O, Rhs>, value_type_of<O>>,
public expression_operators<binary_expression_t<Lhs, O, Rhs>, value_type_of<O>>,
public alias_operators<binary_expression_t<Lhs, O, Rhs>> public alias_operators<binary_expression_t<Lhs, O, Rhs>>
{ {
using _traits = make_traits<value_type_of<O>, tag::is_expression>; using _traits = make_traits<value_type_of<O>, tag::is_expression>;
using _nodes = detail::type_vector<Lhs, Rhs>; using _nodes = detail::type_vector<Lhs, Rhs>;
binary_expression_t(Lhs lhs, Rhs rhs): binary_expression_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
_lhs(lhs), {
_rhs(rhs) }
{}
binary_expression_t(const binary_expression_t&) = default; binary_expression_t(const binary_expression_t&) = default;
binary_expression_t(binary_expression_t&&) = default; binary_expression_t(binary_expression_t&&) = default;
@ -223,16 +219,15 @@ namespace sqlpp
}; };
template <typename O, typename Rhs> template <typename O, typename Rhs>
struct unary_expression_t: struct unary_expression_t : public expression_operators<unary_expression_t<O, Rhs>, value_type_of<O>>,
public expression_operators<unary_expression_t<O, Rhs>, value_type_of<O>>,
public alias_operators<unary_expression_t<O, Rhs>> public alias_operators<unary_expression_t<O, Rhs>>
{ {
using _traits = make_traits<value_type_of<O>, tag::is_expression>; using _traits = make_traits<value_type_of<O>, tag::is_expression>;
using _nodes = detail::type_vector<Rhs>; using _nodes = detail::type_vector<Rhs>;
unary_expression_t(Rhs rhs): unary_expression_t(Rhs rhs) : _rhs(rhs)
_rhs(rhs) {
{} }
unary_expression_t(const unary_expression_t&) = default; unary_expression_t(const unary_expression_t&) = default;
unary_expression_t(unary_expression_t&&) = default; unary_expression_t(unary_expression_t&&) = default;

View File

@ -146,7 +146,6 @@ namespace sqlpp
using _traits = make_traits<ValueType>; using _traits = make_traits<ValueType>;
static constexpr const char* _name = "|"; static constexpr const char* _name = "|";
}; };
} }
template <typename Lhs, typename O, typename Rhs> template <typename Lhs, typename O, typename Rhs>

View File

@ -37,14 +37,14 @@ namespace sqlpp
struct extra_tables_data_t struct extra_tables_data_t
{ {
extra_tables_data_t() extra_tables_data_t()
{} {
}
extra_tables_data_t(const extra_tables_data_t&) = default; extra_tables_data_t(const extra_tables_data_t&) = default;
extra_tables_data_t(extra_tables_data_t&&) = default; extra_tables_data_t(extra_tables_data_t&&) = default;
extra_tables_data_t& operator=(const extra_tables_data_t&) = default; extra_tables_data_t& operator=(const extra_tables_data_t&) = default;
extra_tables_data_t& operator=(extra_tables_data_t&&) = default; extra_tables_data_t& operator=(extra_tables_data_t&&) = default;
~extra_tables_data_t() = default; ~extra_tables_data_t() = default;
}; };
// EXTRA_TABLES // EXTRA_TABLES
@ -73,8 +73,14 @@ namespace sqlpp
using _data_t = extra_tables_data_t<Tables...>; using _data_t = extra_tables_data_t<Tables...>;
_impl_t<Policies> extra_tables; _impl_t<Policies> extra_tables;
_impl_t<Policies>& operator()() { return extra_tables; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return extra_tables; } {
return extra_tables;
}
const _impl_t<Policies>& operator()() const
{
return extra_tables;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.extra_tables) static auto _get_member(T t) -> decltype(t.extra_tables)
@ -109,8 +115,14 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
_impl_t<Policies> no_extra_tables; _impl_t<Policies> no_extra_tables;
_impl_t<Policies>& operator()() { return no_extra_tables; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return no_extra_tables; } {
return no_extra_tables;
}
const _impl_t<Policies>& operator()() const
{
return no_extra_tables;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.no_extra_tables) static auto _get_member(T t) -> decltype(t.no_extra_tables)
@ -127,8 +139,7 @@ namespace sqlpp
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
template <typename... Tables> template <typename... Tables>
auto extra_tables(Tables... tables) const auto extra_tables(Tables... tables) const -> _new_statement_t<_check<Tables...>, extra_tables_t<Tables...>>
-> _new_statement_t<_check<Tables...>, extra_tables_t<Tables...>>
{ {
static_assert(_check<Tables...>::value, "at least one argument is not a table or join in extra_tables()"); static_assert(_check<Tables...>::value, "at least one argument is not a table or join in extra_tables()");
@ -137,20 +148,22 @@ namespace sqlpp
private: private:
template <typename Database, typename... Tables> template <typename Database, typename... Tables>
auto _extra_tables_impl(const std::false_type&, Tables... tables) const auto _extra_tables_impl(const std::false_type&, Tables... tables) const -> bad_statement;
-> bad_statement;
template <typename Database, typename... Tables> template <typename Database, typename... Tables>
auto _extra_tables_impl(const std::true_type&, Tables...) const auto _extra_tables_impl(const std::true_type&, Tables...) const
-> _new_statement_t<std::true_type, extra_tables_t<Tables...>> -> _new_statement_t<std::true_type, extra_tables_t<Tables...>>
{ {
static_assert(required_tables_of<extra_tables_t<Tables...>>::size::value == 0, "at least one table depends on another table in extra_tables()"); static_assert(required_tables_of<extra_tables_t<Tables...>>::size::value == 0,
"at least one table depends on another table in extra_tables()");
static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of<Tables>::size::value...); static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of<Tables>::size::value...);
using _unique_tables = detail::make_joined_set_t<provided_tables_of<Tables>...>; using _unique_tables = detail::make_joined_set_t<provided_tables_of<Tables>...>;
using _unique_table_names = detail::transform_set_t<name_of, _unique_tables>; using _unique_table_names = detail::transform_set_t<name_of, _unique_tables>;
static_assert(_number_of_tables == _unique_tables::size::value, "at least one duplicate table detected in extra_tables()"); static_assert(_number_of_tables == _unique_tables::size::value,
static_assert(_number_of_tables == _unique_table_names::size::value, "at least one duplicate table name detected in extra_tables()"); "at least one duplicate table detected in extra_tables()");
static_assert(_number_of_tables == _unique_table_names::size::value,
"at least one duplicate table name detected in extra_tables()");
return {static_cast<const derived_statement_t<Policies>&>(*this), extra_tables_data_t<Tables...>{}}; return {static_cast<const derived_statement_t<Policies>&>(*this), extra_tables_data_t<Tables...>{}};
} }
@ -169,7 +182,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -34,10 +34,10 @@ namespace sqlpp
template <typename NameType, typename ValueType, bool CanBeNull, bool NullIsTrivialValue> template <typename NameType, typename ValueType, bool CanBeNull, bool NullIsTrivialValue>
struct field_spec_t struct field_spec_t
{ {
using _traits = make_traits<ValueType, tag::is_noop, using _traits = make_traits<ValueType,
tag::is_noop,
tag_if<tag::can_be_null, CanBeNull>, tag_if<tag::can_be_null, CanBeNull>,
tag_if<tag::null_is_trivial_value, NullIsTrivialValue> tag_if<tag::null_is_trivial_value, NullIsTrivialValue>>;
>;
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
using _alias_t = NameType; using _alias_t = NameType;
@ -54,7 +54,9 @@ namespace sqlpp
struct make_field_spec_impl struct make_field_spec_impl
{ {
static constexpr bool _can_be_null = can_be_null_t<NamedExpr>::value; static constexpr bool _can_be_null = can_be_null_t<NamedExpr>::value;
static constexpr bool _depends_on_outer_table = detail::make_intersect_set_t<required_tables_of<NamedExpr>, typename Select::_used_outer_tables>::size::value > 0; static constexpr bool _depends_on_outer_table =
detail::make_intersect_set_t<required_tables_of<NamedExpr>,
typename Select::_used_outer_tables>::size::value > 0;
using type = field_spec_t<typename NamedExpr::_alias_t, using type = field_spec_t<typename NamedExpr::_alias_t,
value_type_of<NamedExpr>, value_type_of<NamedExpr>,
@ -65,13 +67,13 @@ namespace sqlpp
template <typename Select, typename AliasProvider, typename... NamedExprs> template <typename Select, typename AliasProvider, typename... NamedExprs>
struct make_field_spec_impl<Select, multi_column_alias_t<AliasProvider, NamedExprs...>> struct make_field_spec_impl<Select, multi_column_alias_t<AliasProvider, NamedExprs...>>
{ {
using type = multi_field_spec_t<AliasProvider, std::tuple<typename make_field_spec_impl<Select, NamedExprs>::type...>>; using type =
multi_field_spec_t<AliasProvider, std::tuple<typename make_field_spec_impl<Select, NamedExprs>::type...>>;
}; };
} }
template <typename Select, typename NamedExpr> template <typename Select, typename NamedExpr>
using make_field_spec_t = typename detail::make_field_spec_impl<Select, NamedExpr>::type; using make_field_spec_t = typename detail::make_field_spec_impl<Select, NamedExpr>::type;
} }
#endif #endif

View File

@ -53,15 +53,13 @@ namespace sqlpp
using _value_type = floating_point; using _value_type = floating_point;
using _cpp_value_type = typename _value_type::_cpp_value_type; using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t(): parameter_value_t() : _value(0), _is_null(true)
_value(0), {
_is_null(true) }
{}
parameter_value_t(const _cpp_value_type& val): parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false)
_value(val), {
_is_null(false) }
{}
parameter_value_t& operator=(const _cpp_value_type& val) parameter_value_t& operator=(const _cpp_value_type& val)
{ {
@ -102,7 +100,10 @@ namespace sqlpp
return _value; return _value;
} }
operator _cpp_value_type() const { return _value; } operator _cpp_value_type() const
{
return _value;
}
template <typename Target> template <typename Target>
void _bind(Target& target, size_t index) const void _bind(Target& target, size_t index) const
@ -117,8 +118,7 @@ namespace sqlpp
// floating_point expression operators // floating_point expression operators
template <typename Expr> template <typename Expr>
struct expression_operators<Expr, floating_point>: struct expression_operators<Expr, floating_point> : public basic_expression_operators<Expr, floating_point>
public basic_expression_operators<Expr, floating_point>
{ {
template <typename T> template <typename T>
using _is_valid_operand = is_valid_operand<floating_point, T>; using _is_valid_operand = is_valid_operand<floating_point, T>;
@ -213,16 +213,15 @@ namespace sqlpp
}; };
// floating_point result field // floating_point result field
template <typename Db, typename FieldSpec> template <typename Db, typename FieldSpec>
struct result_field_t<floating_point, Db, FieldSpec>: public result_field_methods_t<result_field_t<floating_point, Db, FieldSpec>> struct result_field_t<floating_point, Db, FieldSpec>
: public result_field_methods_t<result_field_t<floating_point, Db, FieldSpec>>
{ {
static_assert(std::is_same<value_type_of<FieldSpec>, floating_point>::value, "field type mismatch"); static_assert(std::is_same<value_type_of<FieldSpec>, floating_point>::value, "field type mismatch");
using _cpp_value_type = typename floating_point::_cpp_value_type; using _cpp_value_type = typename floating_point::_cpp_value_type;
result_field_t(): result_field_t() : _is_valid(false), _is_null(true), _value(0)
_is_valid(false), {
_is_null(true), }
_value(0)
{}
void _validate() void _validate()
{ {
@ -287,6 +286,5 @@ namespace sqlpp
{ {
return serialize(e, os); return serialize(e, os);
} }
} }
#endif #endif

View File

@ -42,9 +42,9 @@ namespace sqlpp
template <typename Database, typename... Tables> template <typename Database, typename... Tables>
struct from_data_t struct from_data_t
{ {
from_data_t(Tables... tables): from_data_t(Tables... tables) : _tables(tables...)
_tables(tables...) {
{} }
from_data_t(const from_data_t&) = default; from_data_t(const from_data_t&) = default;
from_data_t(from_data_t&&) = default; from_data_t(from_data_t&&) = default;
@ -76,9 +76,11 @@ namespace sqlpp
{ {
static_assert(_is_dynamic::value, "from::add() must not be called for static from()"); static_assert(_is_dynamic::value, "from::add() must not be called for static from()");
static_assert(is_table_t<Table>::value, "invalid table argument in from::add()"); static_assert(is_table_t<Table>::value, "invalid table argument in from::add()");
using _known_tables = detail::make_joined_set_t<provided_tables_of<Tables>...>; // Hint: Joins contain more than one table using _known_tables =
detail::make_joined_set_t<provided_tables_of<Tables>...>; // Hint: Joins contain more than one table
using _known_table_names = detail::transform_set_t<name_of, _known_tables>; using _known_table_names = detail::transform_set_t<name_of, _known_tables>;
static_assert(not detail::is_element_of<typename Table::_alias_t, _known_table_names>::value, "Must not use the same table name twice in from()"); static_assert(not detail::is_element_of<typename Table::_alias_t, _known_table_names>::value,
"Must not use the same table name twice in from()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Table>; using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Table>;
_serialize_check::_(); _serialize_check::_();
@ -108,8 +110,14 @@ namespace sqlpp
using _data_t = from_data_t<Database, Tables...>; using _data_t = from_data_t<Database, Tables...>;
_impl_t<Policies> from; _impl_t<Policies> from;
_impl_t<Policies>& operator()() { return from; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return from; } {
return from;
}
const _impl_t<Policies>& operator()() const
{
return from;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.from) static auto _get_member(T t) -> decltype(t.from)
@ -144,8 +152,14 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
_impl_t<Policies> no_from; _impl_t<Policies> no_from;
_impl_t<Policies>& operator()() { return no_from; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return no_from; } {
return no_from;
}
const _impl_t<Policies>& operator()() const
{
return no_from;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.no_from) static auto _get_member(T t) -> decltype(t.no_from)
@ -164,8 +178,7 @@ namespace sqlpp
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
template <typename... Tables> template <typename... Tables>
auto from(Tables... tables) const auto from(Tables... tables) const -> _new_statement_t<_check<Tables...>, from_t<void, from_table_t<Tables>...>>
-> _new_statement_t<_check<Tables...>, from_t<void, from_table_t<Tables>...>>
{ {
static_assert(_check<Tables...>::value, "at least one argument is not a table or join in from()"); static_assert(_check<Tables...>::value, "at least one argument is not a table or join in from()");
static_assert(sizeof...(Tables), "at least one table or join argument required in from()"); static_assert(sizeof...(Tables), "at least one table or join argument required in from()");
@ -176,31 +189,34 @@ namespace sqlpp
auto dynamic_from(Tables... tables) const auto dynamic_from(Tables... tables) const
-> _new_statement_t<_check<Tables...>, from_t<_database_t, from_table_t<Tables>...>> -> _new_statement_t<_check<Tables...>, from_t<_database_t, from_table_t<Tables>...>>
{ {
static_assert(not std::is_same<_database_t, void>::value, "dynamic_from must not be called in a static statement"); static_assert(not std::is_same<_database_t, void>::value,
"dynamic_from must not be called in a static statement");
static_assert(_check<Tables...>::value, "at least one argument is not a table or join in from()"); static_assert(_check<Tables...>::value, "at least one argument is not a table or join in from()");
return _from_impl<_database_t>(_check<Tables...>{}, tables...); return _from_impl<_database_t>(_check<Tables...>{}, tables...);
} }
private: private:
template <typename Database, typename... Tables> template <typename Database, typename... Tables>
auto _from_impl(const std::false_type&, Tables... tables) const auto _from_impl(const std::false_type&, Tables... tables) const -> bad_statement;
-> bad_statement;
template <typename Database, typename... Tables> template <typename Database, typename... Tables>
auto _from_impl(const std::true_type&, Tables... tables) const auto _from_impl(const std::true_type&, Tables... tables) const
-> _new_statement_t<std::true_type, from_t<Database, from_table_t<Tables>...>> -> _new_statement_t<std::true_type, from_t<Database, from_table_t<Tables>...>>
{ {
static_assert(required_tables_of<from_t<Database, Tables...>>::size::value == 0, "at least one table depends on another table in from()"); static_assert(required_tables_of<from_t<Database, Tables...>>::size::value == 0,
"at least one table depends on another table in from()");
static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of<Tables>::size::value...); static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of<Tables>::size::value...);
using _unique_tables = detail::make_joined_set_t<provided_tables_of<Tables>...>; using _unique_tables = detail::make_joined_set_t<provided_tables_of<Tables>...>;
using _unique_table_names = detail::transform_set_t<name_of, _unique_tables>; using _unique_table_names = detail::transform_set_t<name_of, _unique_tables>;
static_assert(_number_of_tables == _unique_tables::size::value, "at least one duplicate table detected in from()"); static_assert(_number_of_tables == _unique_tables::size::value,
static_assert(_number_of_tables == _unique_table_names::size::value, "at least one duplicate table name detected in from()"); "at least one duplicate table detected in from()");
static_assert(_number_of_tables == _unique_table_names::size::value,
"at least one duplicate table name detected in from()");
return { static_cast<const derived_statement_t<Policies>&>(*this), from_data_t<Database, from_table_t<Tables>...>{from_table(tables)...} }; return {static_cast<const derived_statement_t<Policies>&>(*this),
from_data_t<Database, from_table_t<Tables>...>{from_table(tables)...}};
} }
}; };
}; };

View File

@ -54,14 +54,16 @@ namespace sqlpp
template <typename T> template <typename T>
auto value(T t) -> wrap_operand_t<T> auto value(T t) -> wrap_operand_t<T>
{ {
static_assert(is_wrapped_value_t<wrap_operand_t<T>>::value, "value() is to be called with non-sql-type like int, or string"); static_assert(is_wrapped_value_t<wrap_operand_t<T>>::value,
"value() is to be called with non-sql-type like int, or string");
return {t}; return {t};
} }
template <typename Expression, typename Db> template <typename Expression, typename Db>
auto flatten(const Expression& exp, Db& db) -> verbatim_t<value_type_of<Expression>> auto flatten(const Expression& exp, Db& db) -> verbatim_t<value_type_of<Expression>>
{ {
static_assert(not make_parameter_list_t<Expression>::size::value, "parameters are not allowed in flattened expressions"); static_assert(not make_parameter_list_t<Expression>::size::value,
"parameters are not allowed in flattened expressions");
auto context = db.get_serializer_context(); auto context = db.get_serializer_context();
serialize(exp, context); serialize(exp, context);
return {context.str()}; return {context.str()};
@ -87,9 +89,9 @@ namespace sqlpp
using _container_t = Container; using _container_t = Container;
value_list_t(_container_t container): value_list_t(_container_t container) : _container(container)
_container(container) {
{} }
value_list_t(const value_list_t&) = default; value_list_t(const value_list_t&) = default;
value_list_t(value_list_t&&) = default; value_list_t(value_list_t&&) = default;
@ -130,7 +132,9 @@ namespace sqlpp
template <typename Container> template <typename Container>
auto value_list(Container c) -> value_list_t<Container> auto value_list(Container c) -> value_list_t<Container>
{ {
static_assert(is_wrapped_value_t<wrap_operand_t<typename Container::value_type>>::value, "value_list() is to be called with a container of non-sql-type like std::vector<int>, or std::list(string)"); static_assert(
is_wrapped_value_t<wrap_operand_t<typename Container::value_type>>::value,
"value_list() is to be called with a container of non-sql-type like std::vector<int>, or std::list(string)");
return {c}; return {c};
} }
@ -139,8 +143,6 @@ namespace sqlpp
{ {
return name_of<T>::char_ptr(); return name_of<T>::char_ptr();
} }
} }
#endif #endif

View File

@ -41,9 +41,9 @@ namespace sqlpp
template <typename Database, typename... Expressions> template <typename Database, typename... Expressions>
struct group_by_data_t struct group_by_data_t
{ {
group_by_data_t(Expressions... expressions): group_by_data_t(Expressions... expressions) : _expressions(expressions...)
_expressions(expressions...) {
{} }
group_by_data_t(const group_by_data_t&) = default; group_by_data_t(const group_by_data_t&) = default;
group_by_data_t(group_by_data_t&&) = default; group_by_data_t(group_by_data_t&&) = default;
@ -62,7 +62,8 @@ namespace sqlpp
template <typename T = void> template <typename T = void>
static void _() static void _()
{ {
static_assert(wrong_t<T>::value, "at least one group-by expression requires a table which is otherwise not known in the statement"); static_assert(wrong_t<T>::value,
"at least one group-by expression requires a table which is otherwise not known in the statement");
} }
}; };
@ -93,7 +94,8 @@ namespace sqlpp
{ {
static_assert(_is_dynamic::value, "add() must not be called for static group_by"); static_assert(_is_dynamic::value, "add() must not be called for static group_by");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in group_by::add()"); static_assert(is_expression_t<Expression>::value, "invalid expression argument in group_by::add()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in group_by::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value,
"expression uses tables unknown to this statement in group_by::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>; using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
_serialize_check::_(); _serialize_check::_();
@ -111,6 +113,7 @@ namespace sqlpp
template <typename Expression> template <typename Expression>
void _add_impl(Expression expression, const std::false_type&); void _add_impl(Expression expression, const std::false_type&);
public: public:
_data_t _data; _data_t _data;
}; };
@ -122,8 +125,14 @@ namespace sqlpp
using _data_t = group_by_data_t<Database, Expressions...>; using _data_t = group_by_data_t<Database, Expressions...>;
_impl_t<Policies> group_by; _impl_t<Policies> group_by;
_impl_t<Policies>& operator()() { return group_by; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return group_by; } {
return group_by;
}
const _impl_t<Policies>& operator()() const
{
return group_by;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.group_by) static auto _get_member(T t) -> decltype(t.group_by)
@ -160,8 +169,14 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
_impl_t<Policies> no_group_by; _impl_t<Policies> no_group_by;
_impl_t<Policies>& operator()() { return no_group_by; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return no_group_by; } {
return no_group_by;
}
const _impl_t<Policies>& operator()() const
{
return no_group_by;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.no_group_by) static auto _get_member(T t) -> decltype(t.no_group_by)
@ -193,7 +208,8 @@ namespace sqlpp
auto dynamic_group_by(Expressions... expressions) const auto dynamic_group_by(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, group_by_t<_database_t, Expressions...>> -> _new_statement_t<_check<Expressions...>, group_by_t<_database_t, Expressions...>>
{ {
static_assert(not std::is_same<_database_t, void>::value, "dynamic_group_by must not be called in a static statement"); static_assert(not std::is_same<_database_t, void>::value,
"dynamic_group_by must not be called in a static statement");
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in group_by()"); static_assert(_check<Expressions...>::value, "at least one argument is not an expression in group_by()");
return _group_by_impl<_database_t>(_check<Expressions...>{}, expressions...); return _group_by_impl<_database_t>(_check<Expressions...>{}, expressions...);
@ -201,16 +217,17 @@ namespace sqlpp
private: private:
template <typename Database, typename... Expressions> template <typename Database, typename... Expressions>
auto _group_by_impl(const std::false_type&, Expressions... expressions) const auto _group_by_impl(const std::false_type&, Expressions... expressions) const -> bad_statement;
-> bad_statement;
template <typename Database, typename... Expressions> template <typename Database, typename... Expressions>
auto _group_by_impl(const std::true_type&, Expressions... expressions) const auto _group_by_impl(const std::true_type&, Expressions... expressions) const
-> _new_statement_t<std::true_type, group_by_t<_database_t, Expressions...>> -> _new_statement_t<std::true_type, group_by_t<_database_t, Expressions...>>
{ {
static_assert(not detail::has_duplicates<Expressions...>::value, "at least one duplicate argument detected in group_by()"); static_assert(not detail::has_duplicates<Expressions...>::value,
"at least one duplicate argument detected in group_by()");
return { static_cast<const derived_statement_t<Policies>&>(*this), group_by_data_t<Database, Expressions...>{expressions...} }; return {static_cast<const derived_statement_t<Policies>&>(*this),
group_by_data_t<Database, Expressions...>{expressions...}};
} }
}; };
}; };

View File

@ -40,9 +40,9 @@ namespace sqlpp
template <typename Database, typename... Expressions> template <typename Database, typename... Expressions>
struct having_data_t struct having_data_t
{ {
having_data_t(Expressions... expressions): having_data_t(Expressions... expressions) : _expressions(expressions...)
_expressions(expressions...) {
{} }
having_data_t(const having_data_t&) = default; having_data_t(const having_data_t&) = default;
having_data_t(having_data_t&&) = default; having_data_t(having_data_t&&) = default;
@ -61,7 +61,8 @@ namespace sqlpp
template <typename T = void> template <typename T = void>
static void _() static void _()
{ {
static_assert(wrong_t<T>::value, "at least one having-expression requires a table which is otherwise not known in the statement"); static_assert(wrong_t<T>::value,
"at least one having-expression requires a table which is otherwise not known in the statement");
} }
}; };
@ -92,7 +93,8 @@ namespace sqlpp
{ {
static_assert(_is_dynamic::value, "having::add() can only be called for dynamic_having"); static_assert(_is_dynamic::value, "having::add() can only be called for dynamic_having");
static_assert(is_expression_t<Expression>::value, "invalid expression argument in having::add()"); static_assert(is_expression_t<Expression>::value, "invalid expression argument in having::add()");
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in having::add()"); static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value,
"expression uses tables unknown to this statement in having::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>; using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
_serialize_check::_(); _serialize_check::_();
@ -122,8 +124,14 @@ namespace sqlpp
using _data_t = having_data_t<Database, Expressions...>; using _data_t = having_data_t<Database, Expressions...>;
_impl_t<Policies> having; _impl_t<Policies> having;
_impl_t<Policies>& operator()() { return having; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return having; } {
return having;
}
const _impl_t<Policies>& operator()() const
{
return having;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.having) static auto _get_member(T t) -> decltype(t.having)
@ -160,8 +168,14 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
_impl_t<Policies> no_having; _impl_t<Policies> no_having;
_impl_t<Policies>& operator()() { return no_having; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return no_having; } {
return no_having;
}
const _impl_t<Policies>& operator()() const
{
return no_having;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.no_having) static auto _get_member(T t) -> decltype(t.no_having)
@ -194,22 +208,22 @@ namespace sqlpp
-> _new_statement_t<_check<Expressions...>, having_t<_database_t, Expressions...>> -> _new_statement_t<_check<Expressions...>, having_t<_database_t, Expressions...>>
{ {
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in having()"); static_assert(_check<Expressions...>::value, "at least one argument is not an expression in having()");
static_assert(not std::is_same<_database_t, void>::value, "dynamic_having must not be called in a static statement"); static_assert(not std::is_same<_database_t, void>::value,
"dynamic_having must not be called in a static statement");
return _having_impl<_database_t>(_check<Expressions...>{}, expressions...); return _having_impl<_database_t>(_check<Expressions...>{}, expressions...);
} }
private: private:
template <typename Database, typename... Expressions> template <typename Database, typename... Expressions>
auto _having_impl(const std::false_type&, Expressions... expressions) const auto _having_impl(const std::false_type&, Expressions... expressions) const -> bad_statement;
-> bad_statement;
template <typename Database, typename... Expressions> template <typename Database, typename... Expressions>
auto _having_impl(const std::true_type&, Expressions... expressions) const auto _having_impl(const std::true_type&, Expressions... expressions) const
-> _new_statement_t<std::true_type, having_t<Database, Expressions...>> -> _new_statement_t<std::true_type, having_t<Database, Expressions...>>
{ {
return { static_cast<const derived_statement_t<Policies>&>(*this), having_data_t<_database_t, Expressions...>{expressions...} }; return {static_cast<const derived_statement_t<Policies>&>(*this),
having_data_t<_database_t, Expressions...>{expressions...}};
} }
}; };
}; };

View File

@ -30,12 +30,11 @@
namespace sqlpp namespace sqlpp
{ {
template <typename Part> template <typename Part>
struct hidden_t: struct hidden_t : public Part
public Part
{ {
hidden_t(Part part): hidden_t(Part part) : Part(part)
Part(part) {
{} }
hidden_t(const hidden_t&) = default; hidden_t(const hidden_t&) = default;
hidden_t(hidden_t&&) = default; hidden_t(hidden_t&&) = default;
@ -57,8 +56,7 @@ namespace sqlpp
}; };
template <typename Part> template <typename Part>
auto hidden(Part part) auto hidden(Part part) -> hidden_t<Part>
-> hidden_t<Part>
{ {
return {part}; return {part};
} }

View File

@ -50,8 +50,7 @@ namespace sqlpp
}; };
template <typename Operand, typename... Args> template <typename Operand, typename... Args>
struct in_t: struct in_t : public expression_operators<in_t<Operand, Args...>, boolean>,
public expression_operators<in_t<Operand, Args...>, boolean>,
public alias_operators<in_t<Operand, Args...>> public alias_operators<in_t<Operand, Args...>>
{ {
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>; using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
@ -61,10 +60,9 @@ namespace sqlpp
using _auto_alias_t = in_alias_t; using _auto_alias_t = in_alias_t;
in_t(Operand operand, Args... args): in_t(Operand operand, Args... args) : _operand(operand), _args(args...)
_operand(operand), {
_args(args...) }
{}
in_t(const in_t&) = default; in_t(const in_t&) = default;
in_t(in_t&&) = default; in_t(in_t&&) = default;
@ -121,7 +119,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -33,7 +33,6 @@ namespace sqlpp
struct in_t; struct in_t;
template <typename Operand, typename... Args> template <typename Operand, typename... Args>
struct not_in_t; struct not_in_t;
} }
#endif #endif

View File

@ -39,12 +39,16 @@
namespace sqlpp namespace sqlpp
{ {
struct insert_name_t {}; struct insert_name_t
{
};
struct insert_t : public statement_name_t<insert_name_t> struct insert_t : public statement_name_t<insert_name_t>
{ {
using _traits = make_traits<no_value_t, tag::is_return_value>; using _traits = make_traits<no_value_t, tag::is_return_value>;
struct _alias_t {}; struct _alias_t
{
};
template <typename Statement> template <typename Statement>
struct _result_methods_t struct _result_methods_t
@ -58,8 +62,7 @@ namespace sqlpp
// Execute // Execute
template <typename Db, typename Composite> template <typename Db, typename Composite>
auto _run(Db& db, const Composite& composite) const auto _run(Db& db, const Composite& composite) const -> decltype(db.insert(composite))
-> decltype(db.insert(composite))
{ {
return db.insert(composite); return db.insert(composite);
} }
@ -72,15 +75,13 @@ namespace sqlpp
// Prepare // Prepare
template <typename Db, typename Composite> template <typename Db, typename Composite>
auto _prepare(Db& db, const Composite& composite) const auto _prepare(Db& db, const Composite& composite) const -> prepared_insert_t<Db, Composite>
-> prepared_insert_t<Db, Composite>
{ {
return {{}, db.prepare_insert(composite)}; return {{}, db.prepare_insert(composite)};
} }
template <typename Db> template <typename Db>
auto _prepare(Db& db) const auto _prepare(Db& db) const -> prepared_insert_t<Db, _statement_t>
-> prepared_insert_t<Db, _statement_t>
{ {
return {{}, db.prepare_insert(_get_statement())}; return {{}, db.prepare_insert(_get_statement())};
} }
@ -102,35 +103,28 @@ namespace sqlpp
}; };
template <typename Database> template <typename Database>
using blank_insert_t = statement_t<Database, using blank_insert_t = statement_t<Database, insert_t, no_into_t, no_insert_value_list_t>;
insert_t,
no_into_t,
no_insert_value_list_t>;
inline auto insert() inline auto insert() -> blank_insert_t<void>
-> blank_insert_t<void>
{ {
return {blank_insert_t<void>()}; return {blank_insert_t<void>()};
} }
template <typename Table> template <typename Table>
constexpr auto insert_into(Table table) constexpr auto insert_into(Table table) -> decltype(blank_insert_t<void>().into(table))
-> decltype(blank_insert_t<void>().into(table))
{ {
return {blank_insert_t<void>().into(table)}; return {blank_insert_t<void>().into(table)};
} }
template <typename Database> template <typename Database>
constexpr auto dynamic_insert(const Database&) constexpr auto dynamic_insert(const Database&) -> decltype(blank_insert_t<Database>())
-> decltype(blank_insert_t<Database>())
{ {
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter"); static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return {blank_insert_t<Database>()}; return {blank_insert_t<Database>()};
} }
template <typename Database, typename Table> template <typename Database, typename Table>
constexpr auto dynamic_insert_into(const Database&, Table table) constexpr auto dynamic_insert_into(const Database&, Table table) -> decltype(blank_insert_t<Database>().into(table))
-> decltype(blank_insert_t<Database>().into(table))
{ {
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter"); static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return {blank_insert_t<Database>().into(table)}; return {blank_insert_t<Database>().into(table)};

View File

@ -65,29 +65,24 @@ namespace sqlpp
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>;
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_null(rhs._is_null()), _is_default(rhs._is_default()), _value(rhs._expr._t)
_is_default(rhs._is_default()), {
_value(rhs._expr._t) }
{}
insert_value_t(rhs_wrap_t<_tvin_t, _trivial_value_is_null> rhs): insert_value_t(rhs_wrap_t<_tvin_t, _trivial_value_is_null> rhs)
_is_null(rhs._is_null()), : _is_null(rhs._is_null()), _is_default(rhs._is_default()), _value(rhs._expr._value)
_is_default(rhs._is_default()), {
_value(rhs._expr._value) }
{}
insert_value_t(const rhs_wrap_t<null_t, _trivial_value_is_null>&): insert_value_t(const rhs_wrap_t<null_t, _trivial_value_is_null>&) : _is_null(true), _is_default(false), _value{}
_is_null(true), {
_is_default(false), }
_value{}
{}
insert_value_t(const rhs_wrap_t<default_value_t, _trivial_value_is_null>&): insert_value_t(const rhs_wrap_t<default_value_t, _trivial_value_is_null>&)
_is_null(false), : _is_null(false), _is_default(true), _value{}
_is_default(true), {
_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;
@ -108,8 +103,7 @@ namespace sqlpp
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {
if ((trivial_value_is_null_t<typename T::_column_t>::value and t._value._is_trivial()) if ((trivial_value_is_null_t<typename T::_column_t>::value and t._value._is_trivial()) or t._is_null)
or t._is_null)
{ {
context << "NULL"; context << "NULL";
} }
@ -120,7 +114,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -58,7 +58,8 @@ namespace sqlpp
} }
struct insert_default_values_data_t struct insert_default_values_data_t
{}; {
};
// COLUMN AND VALUE LIST // COLUMN AND VALUE LIST
struct insert_default_values_t struct insert_default_values_t
@ -83,8 +84,14 @@ namespace sqlpp
using _data_t = insert_default_values_data_t; using _data_t = insert_default_values_data_t;
_impl_t<Policies> default_values; _impl_t<Policies> default_values;
_impl_t<Policies>& operator()() { return default_values; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return default_values; } {
return default_values;
}
const _impl_t<Policies>& operator()() const
{
return default_values;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.default_values) static auto _get_member(T t) -> decltype(t.default_values)
@ -99,11 +106,10 @@ namespace sqlpp
template <typename Database, typename... Assignments> template <typename Database, typename... Assignments>
struct insert_list_data_t struct insert_list_data_t
{ {
insert_list_data_t(Assignments... assignments): insert_list_data_t(Assignments... assignments)
_assignments(assignments...), : _assignments(assignments...), _columns({assignments._lhs}...), _values(assignments._rhs...)
_columns({assignments._lhs}...), {
_values(assignments._rhs...) }
{}
insert_list_data_t(const insert_list_data_t&) = default; insert_list_data_t(const insert_list_data_t&) = default;
insert_list_data_t(insert_list_data_t&&) = default; insert_list_data_t(insert_list_data_t&&) = default;
@ -111,7 +117,8 @@ namespace sqlpp
insert_list_data_t& operator=(insert_list_data_t&&) = default; insert_list_data_t& operator=(insert_list_data_t&&) = default;
~insert_list_data_t() = default; ~insert_list_data_t() = default;
std::tuple<Assignments...> _assignments; // FIXME: Need to replace _columns and _values by _assignments (connector-container requires assignments) std::tuple<Assignments...> _assignments; // FIXME: Need to replace _columns and _values by _assignments
// (connector-container requires assignments)
std::tuple<simple_column_t<lhs_t<Assignments>>...> _columns; std::tuple<simple_column_t<lhs_t<Assignments>>...> _columns;
std::tuple<rhs_t<Assignments>...> _values; std::tuple<rhs_t<Assignments>...> _values;
interpretable_list_t<Database> _dynamic_columns; interpretable_list_t<Database> _dynamic_columns;
@ -125,7 +132,8 @@ namespace sqlpp
template <typename T = void> template <typename T = void>
static void _() static void _()
{ {
static_assert(wrong_t<T>::value, "at least one insert assignment requires a table which is otherwise not known in the statement"); static_assert(wrong_t<T>::value,
"at least one insert assignment requires a table which is otherwise not known in the statement");
} }
}; };
@ -161,16 +169,15 @@ namespace sqlpp
static_assert(_is_dynamic::value, "add must not be called for static from()"); static_assert(_is_dynamic::value, "add must not be called for static from()");
static_assert(is_assignment_t<Assignment>::value, "add() arguments require to be assigments"); static_assert(is_assignment_t<Assignment>::value, "add() arguments require to be assigments");
using _assigned_columns = detail::make_type_set_t<lhs_t<Assignments>...>; using _assigned_columns = detail::make_type_set_t<lhs_t<Assignments>...>;
static_assert(not detail::is_element_of<lhs_t<Assignment>, _assigned_columns>::value, "Must not assign value to column twice"); static_assert(not detail::is_element_of<lhs_t<Assignment>, _assigned_columns>::value,
"Must not assign value to column twice");
static_assert(not must_not_insert_t<lhs_t<Assignment>>::value, "add() argument must not be used in insert"); static_assert(not must_not_insert_t<lhs_t<Assignment>>::value, "add() argument must not be used in insert");
static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Assignment>::value, "add() contains a column from a foreign table"); static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables<Assignment>::value,
"add() contains a column from a foreign table");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>; using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>;
_serialize_check::_(); _serialize_check::_();
using ok = logic::all_t< using ok = logic::all_t<_is_dynamic::value, is_assignment_t<Assignment>::value, _serialize_check::type::value>;
_is_dynamic::value,
is_assignment_t<Assignment>::value,
_serialize_check::type::value>;
_add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert _add_impl(assignment, ok()); // dispatch to prevent compile messages after the static_assert
} }
@ -185,6 +192,7 @@ namespace sqlpp
template <typename Assignment> template <typename Assignment>
void _add_impl(Assignment assignment, const std::false_type&); void _add_impl(Assignment assignment, const std::false_type&);
public: public:
_data_t _data; _data_t _data;
}; };
@ -196,8 +204,14 @@ namespace sqlpp
using _data_t = insert_list_data_t<Database, Assignments...>; using _data_t = insert_list_data_t<Database, Assignments...>;
_impl_t<Policies> insert_list; _impl_t<Policies> insert_list;
_impl_t<Policies>& operator()() { return insert_list; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return insert_list; } {
return insert_list;
}
const _impl_t<Policies>& operator()() const
{
return insert_list;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.insert_list) static auto _get_member(T t) -> decltype(t.insert_list)
@ -209,15 +223,14 @@ namespace sqlpp
consistent_t, consistent_t,
assert_no_unknown_tables_in_insert_assignments_t>::type; assert_no_unknown_tables_in_insert_assignments_t>::type;
}; };
}; };
template <typename... Columns> template <typename... Columns>
struct column_list_data_t struct column_list_data_t
{ {
column_list_data_t(Columns... cols): column_list_data_t(Columns... cols) : _columns(simple_column_t<Columns>{cols}...)
_columns(simple_column_t<Columns>{cols}...) {
{} }
column_list_data_t(const column_list_data_t&) = default; column_list_data_t(const column_list_data_t&) = default;
column_list_data_t(column_list_data_t&&) = default; column_list_data_t(column_list_data_t&&) = default;
@ -237,7 +250,8 @@ namespace sqlpp
template <typename T = void> template <typename T = void>
static void _() static void _()
{ {
static_assert(wrong_t<T>::value, "at least one column requires a table which is otherwise not known in the statement"); static_assert(wrong_t<T>::value,
"at least one column requires a table which is otherwise not known in the statement");
} }
}; };
@ -249,7 +263,6 @@ namespace sqlpp
using _value_tuple_t = typename column_list_data_t<Columns...>::_value_tuple_t; using _value_tuple_t = typename column_list_data_t<Columns...>::_value_tuple_t;
// Data // Data
using _data_t = column_list_data_t<Columns...>; using _data_t = column_list_data_t<Columns...>;
@ -260,14 +273,13 @@ namespace sqlpp
template <typename... Assignments> template <typename... Assignments>
void add(Assignments... assignments) void add(Assignments... assignments)
{ {
static_assert(logic::all_t<is_assignment_t<Assignments>::value...>::value, "add_values() arguments have to be assignments"); static_assert(logic::all_t<is_assignment_t<Assignments>::value...>::value,
"add_values() arguments have to be assignments");
using _arg_value_tuple = std::tuple<insert_value_t<lhs_t<Assignments>>...>; using _arg_value_tuple = std::tuple<insert_value_t<lhs_t<Assignments>>...>;
using _args_correct = std::is_same<_arg_value_tuple, _value_tuple_t>; using _args_correct = std::is_same<_arg_value_tuple, _value_tuple_t>;
static_assert(_args_correct::value, "add_values() arguments do not match columns() arguments"); static_assert(_args_correct::value, "add_values() arguments do not match columns() arguments");
using ok = logic::all_t< using ok = logic::all_t<logic::all_t<is_assignment_t<Assignments>::value...>::value, _args_correct::value>;
logic::all_t<is_assignment_t<Assignments>::value...>::value,
_args_correct::value>;
_add_impl(ok(), assignments...); // dispatch to prevent compile messages after the static_assert _add_impl(ok(), assignments...); // dispatch to prevent compile messages after the static_assert
} }
@ -281,6 +293,7 @@ namespace sqlpp
template <typename... Assignments> template <typename... Assignments>
void _add_impl(const std::false_type&, Assignments... assignments); void _add_impl(const std::false_type&, Assignments... assignments);
public: public:
_data_t _data; _data_t _data;
}; };
@ -292,8 +305,14 @@ namespace sqlpp
using _data_t = column_list_data_t<Columns...>; using _data_t = column_list_data_t<Columns...>;
_impl_t<Policies> values; _impl_t<Policies> values;
_impl_t<Policies>& operator()() { return values; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return values; } {
return values;
}
const _impl_t<Policies>& operator()() const
{
return values;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.values) static auto _get_member(T t) -> decltype(t.values)
@ -341,8 +360,14 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
_impl_t<Policies> no_insert_values; _impl_t<Policies> no_insert_values;
_impl_t<Policies>& operator()() { return no_insert_values; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return no_insert_values; } {
return no_insert_values;
}
const _impl_t<Policies>& operator()() const
{
return no_insert_values;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.no_insert_values) static auto _get_member(T t) -> decltype(t.no_insert_values)
@ -363,17 +388,16 @@ namespace sqlpp
using _consistency_check = assert_insert_values_t; using _consistency_check = assert_insert_values_t;
auto default_values() const auto default_values() const -> _new_statement_t<std::true_type, insert_default_values_t>
-> _new_statement_t<std::true_type, insert_default_values_t>
{ {
return {static_cast<const derived_statement_t<Policies>&>(*this), insert_default_values_data_t{}}; return {static_cast<const derived_statement_t<Policies>&>(*this), insert_default_values_data_t{}};
} }
template <typename... Columns> template <typename... Columns>
auto columns(Columns... cols) const auto columns(Columns... cols) const -> _new_statement_t<_column_check<Columns...>, column_list_t<Columns...>>
-> _new_statement_t<_column_check<Columns...>, column_list_t<Columns...>>
{ {
static_assert(logic::all_t<is_column_t<Columns>::value...>::value, "at least one argument is not a column in columns()"); static_assert(logic::all_t<is_column_t<Columns>::value...>::value,
"at least one argument is not a column in columns()");
static_assert(sizeof...(Columns), "at least one column required in columns()"); static_assert(sizeof...(Columns), "at least one column required in columns()");
return _columns_impl(_column_check<Columns...>{}, cols...); return _columns_impl(_column_check<Columns...>{}, cols...);
@ -394,46 +418,55 @@ namespace sqlpp
-> _new_statement_t<_assignment_check<Assignments...>, insert_list_t<_database_t, Assignments...>> -> _new_statement_t<_assignment_check<Assignments...>, insert_list_t<_database_t, Assignments...>>
{ {
static_assert(_assignment_check<Assignments...>::value, "at least one argument is not an assignment in set()"); static_assert(_assignment_check<Assignments...>::value, "at least one argument is not an assignment in set()");
static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); static_assert(not std::is_same<_database_t, void>::value,
"dynamic_set must not be called in a static statement");
return _set_impl<_database_t>(_assignment_check<Assignments...>{}, assignments...); return _set_impl<_database_t>(_assignment_check<Assignments...>{}, assignments...);
} }
private: private:
template <typename... Columns> template <typename... Columns>
auto _columns_impl(const std::false_type&, Columns... cols) const auto _columns_impl(const std::false_type&, Columns... cols) const -> bad_statement;
-> bad_statement;
template <typename... Columns> template <typename... Columns>
auto _columns_impl(const std::true_type&, Columns... cols) const auto _columns_impl(const std::true_type&, Columns... cols) const
-> _new_statement_t<std::true_type, column_list_t<Columns...>> -> _new_statement_t<std::true_type, column_list_t<Columns...>>
{ {
static_assert(not detail::has_duplicates<Columns...>::value, "at least one duplicate argument detected in columns()"); static_assert(not detail::has_duplicates<Columns...>::value,
static_assert(logic::none_t<must_not_insert_t<Columns>::value...>::value, "at least one column argument has a must_not_insert tag in its definition"); "at least one duplicate argument detected in columns()");
static_assert(logic::none_t<must_not_insert_t<Columns>::value...>::value,
"at least one column argument has a must_not_insert tag in its definition");
using _column_required_tables = detail::make_joined_set_t<required_tables_of<Columns>...>; using _column_required_tables = detail::make_joined_set_t<required_tables_of<Columns>...>;
static_assert(_column_required_tables::size::value == 1, "columns() contains columns from several tables"); static_assert(_column_required_tables::size::value == 1, "columns() contains columns from several tables");
static_assert(detail::have_all_required_columns<Columns...>::value, "At least one required column is missing in columns()"); static_assert(detail::have_all_required_columns<Columns...>::value,
"At least one required column is missing in columns()");
return {static_cast<const derived_statement_t<Policies>&>(*this), column_list_data_t<Columns...>{cols...}}; return {static_cast<const derived_statement_t<Policies>&>(*this), column_list_data_t<Columns...>{cols...}};
} }
template <typename Database, typename... Assignments> template <typename Database, typename... Assignments>
auto _set_impl(const std::false_type&, Assignments... assignments) const auto _set_impl(const std::false_type&, Assignments... assignments) const -> bad_statement;
-> bad_statement;
template <typename Database, typename... Assignments> template <typename Database, typename... Assignments>
auto _set_impl(const std::true_type&, Assignments... assignments) const auto _set_impl(const std::true_type&, Assignments... assignments) const
-> _new_statement_t<std::true_type, insert_list_t<Database, Assignments...>> -> _new_statement_t<std::true_type, insert_list_t<Database, Assignments...>>
{ {
static_assert(not detail::has_duplicates<lhs_t<Assignments>...>::value, "at least one duplicate column detected in set()"); static_assert(not detail::has_duplicates<lhs_t<Assignments>...>::value,
static_assert(logic::none_t<must_not_insert_t<lhs_t<Assignments>>::value...>::value, "at least one assignment is prohibited by its column definition in set()"); "at least one duplicate column detected in set()");
static_assert(logic::none_t<must_not_insert_t<lhs_t<Assignments>>::value...>::value,
"at least one assignment is prohibited by its column definition in set()");
using _column_required_tables = detail::make_joined_set_t<required_tables_of<lhs_t<Assignments>>...>; using _column_required_tables = detail::make_joined_set_t<required_tables_of<lhs_t<Assignments>>...>;
static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true, "set() contains assignments for columns from several tables"); static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true,
"set() contains assignments for columns from several tables");
static_assert(not std::is_same<_database_t, void>::value or detail::have_all_required_columns<lhs_t<Assignments>...>::value, "At least one required column is missing in set()"); static_assert(not std::is_same<_database_t, void>::value or
detail::have_all_required_columns<lhs_t<Assignments>...>::value,
"At least one required column is missing in set()");
return { static_cast<const derived_statement_t<Policies>&>(*this), insert_list_data_t<Database, Assignments...>{assignments...} }; return {static_cast<const derived_statement_t<Policies>&>(*this),
insert_list_data_t<Database, Assignments...>{assignments...}};
} }
}; };
}; };
@ -509,7 +542,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -55,15 +55,13 @@ namespace sqlpp
using _value_type = integral; using _value_type = integral;
using _cpp_value_type = typename _value_type::_cpp_value_type; using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t(): parameter_value_t() : _value(0), _is_null(true)
_value(0), {
_is_null(true) }
{}
explicit parameter_value_t(const _cpp_value_type& val): explicit parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false)
_value(val), {
_is_null(false) }
{}
parameter_value_t& operator=(const _cpp_value_type& val) parameter_value_t& operator=(const _cpp_value_type& val)
{ {
@ -103,7 +101,10 @@ namespace sqlpp
return _value; return _value;
} }
operator _cpp_value_type() const { return _value; } operator _cpp_value_type() const
{
return _value;
}
template <typename Target> template <typename Target>
void _bind(Target& target, size_t index) const void _bind(Target& target, size_t index) const
@ -195,7 +196,6 @@ namespace sqlpp
return {*static_cast<const Base*>(this), {t}}; return {*static_cast<const Base*>(this), {t}};
} }
}; };
// integral column operators // integral column operators
@ -244,16 +244,15 @@ namespace sqlpp
// integral result field // integral result field
template <typename Db, typename FieldSpec> template <typename Db, typename FieldSpec>
struct result_field_t<integral, Db, FieldSpec>: public result_field_methods_t<result_field_t<integral, Db, FieldSpec>> struct result_field_t<integral, Db, FieldSpec>
: public result_field_methods_t<result_field_t<integral, Db, FieldSpec>>
{ {
static_assert(std::is_same<value_type_of<FieldSpec>, integral>::value, "field type mismatch"); static_assert(std::is_same<value_type_of<FieldSpec>, integral>::value, "field type mismatch");
using _cpp_value_type = typename integral::_cpp_value_type; using _cpp_value_type = typename integral::_cpp_value_type;
result_field_t(): result_field_t() : _is_valid(false), _is_null(true), _value(0)
_is_valid(false), {
_is_null(true), }
_value(0)
{}
void _invalidate() void _invalidate()
{ {
@ -324,6 +323,5 @@ namespace sqlpp
using smallint = integral; using smallint = integral;
using integer = integral; using integer = integral;
using bigint = integral; using bigint = integral;
} }
#endif #endif

View File

@ -32,12 +32,10 @@
namespace sqlpp namespace sqlpp
{ {
template <typename T, typename Context> template <typename T, typename Context>
auto interpret(const T& t, Context& context) auto interpret(const T& t, Context& context) -> decltype(interpreter_t<Context, T>::_(t, context))
-> decltype(interpreter_t<Context, T>::_(t, context))
{ {
return interpreter_t<Context, T>::_(t, context); return interpreter_t<Context, T>::_(t, context);
} }
} }
#endif #endif

View File

@ -35,7 +35,8 @@
namespace sqlpp namespace sqlpp
{ {
template <typename Element, typename Separator, typename Context, typename UseBraces> template <typename Element, typename Separator, typename Context, typename UseBraces>
static void interpret_tuple_element(const Element& element, const Separator& separator, Context& context, const UseBraces&, size_t index) static void interpret_tuple_element(
const Element& element, const Separator& separator, Context& context, const UseBraces&, size_t index)
{ {
if (index) if (index)
context << separator; context << separator;
@ -46,32 +47,36 @@ namespace sqlpp
} }
template <typename Tuple, typename Separator, typename Context, typename UseBraces, size_t... Is> template <typename Tuple, typename Separator, typename Context, typename UseBraces, size_t... Is>
auto interpret_tuple_impl(const Tuple& t, const Separator& separator, Context& context, const UseBraces& useBraces, const detail::index_sequence<Is...>&) auto interpret_tuple_impl(const Tuple& t,
-> Context& const Separator& separator,
Context& context,
const UseBraces& useBraces,
const detail::index_sequence<Is...>&) -> Context &
{ {
// Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init] paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4. // Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init]
// paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4.
// See for example: "http://en.cppreference.com/w/cpp/utility/integer_sequence" // See for example: "http://en.cppreference.com/w/cpp/utility/integer_sequence"
// See also: "http://stackoverflow.com/questions/6245735/pretty-print-stdtuple/6245777#6245777" // See also: "http://stackoverflow.com/questions/6245735/pretty-print-stdtuple/6245777#6245777"
// Beware of gcc-bug: "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253", otherwise an empty swallow struct could be used // Beware of gcc-bug: "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253", otherwise an empty swallow struct could
// be used
using swallow = int[]; using swallow = int[];
(void) swallow{ (void)swallow{0, // workaround against -Wpedantic GCC warning "zero-size array 'int [0]'"
0, //workaround against -Wpedantic GCC warning "zero-size array 'int [0]'"
(interpret_tuple_element(std::get<Is>(t), separator, context, useBraces, Is), 0)...}; (interpret_tuple_element(std::get<Is>(t), separator, context, useBraces, Is), 0)...};
return context; return context;
} }
template <typename Tuple, typename Separator, typename Context> template <typename Tuple, typename Separator, typename Context>
auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) -> Context &
-> Context&
{ {
return interpret_tuple_impl(t, separator, context, std::true_type{}, detail::make_index_sequence<std::tuple_size<Tuple>::value>{}); return interpret_tuple_impl(t, separator, context, std::true_type{},
detail::make_index_sequence<std::tuple_size<Tuple>::value>{});
} }
template <typename Tuple, typename Separator, typename Context> template <typename Tuple, typename Separator, typename Context>
auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context) auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context) -> Context &
-> Context&
{ {
return interpret_tuple_impl(t, separator, context, std::false_type{}, detail::make_index_sequence<std::tuple_size<Tuple>::value>{}); return interpret_tuple_impl(t, separator, context, std::false_type{},
detail::make_index_sequence<std::tuple_size<Tuple>::value>{});
} }
} }

View File

@ -42,10 +42,10 @@ namespace sqlpp
using _interpreter_context_t = typename Db::_interpreter_context_t; using _interpreter_context_t = typename Db::_interpreter_context_t;
template <typename T> template <typename T>
interpretable_t(T t): interpretable_t(T t)
_requires_braces(requires_braces_t<T>::value), : _requires_braces(requires_braces_t<T>::value), _impl(std::make_shared<_impl_t<T>>(t))
_impl(std::make_shared<_impl_t<T>>(t)) {
{} }
interpretable_t(const interpretable_t&) = default; interpretable_t(const interpretable_t&) = default;
interpretable_t(interpretable_t&&) = default; interpretable_t(interpretable_t&&) = default;
@ -60,9 +60,10 @@ namespace sqlpp
// This method only exists if Db::_serializer_context_t and serializer_context_t are not the same // This method only exists if Db::_serializer_context_t and serializer_context_t are not the same
template <typename Context> template <typename Context>
auto serialize(Context& context) const auto serialize(Context& context) const ->
-> typename std::enable_if<std::is_same<Context, _serializer_context_t>::value typename std::enable_if<std::is_same<Context, _serializer_context_t>::value and
and not std::is_same<Context, serializer_context_t>::value, Context&>::type not std::is_same<Context, serializer_context_t>::value,
Context&>::type
{ {
return _impl->db_serialize(context); return _impl->db_serialize(context);
} }
@ -86,9 +87,9 @@ namespace sqlpp
struct _impl_t : public _impl_base struct _impl_t : public _impl_base
{ {
static_assert(not make_parameter_list_t<T>::size::value, "parameters not supported in dynamic statement parts"); static_assert(not make_parameter_list_t<T>::size::value, "parameters not supported in dynamic statement parts");
_impl_t(T t): _impl_t(T t) : _t(t)
_t(t) {
{} }
serializer_context_t& serialize(serializer_context_t& context) const serializer_context_t& serialize(serializer_context_t& context) const
{ {
@ -134,7 +135,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -52,7 +52,6 @@ namespace sqlpp
{ {
_serializables.emplace_back(expr); _serializables.emplace_back(expr);
} }
}; };
template <> template <>
@ -67,7 +66,6 @@ namespace sqlpp
{ {
return true; return true;
} }
}; };
template <typename Context, typename List> template <typename Context, typename List>
@ -110,7 +108,6 @@ namespace sqlpp
{ {
return serializable_list_interpreter_t<Context, T>::_(t, separator, context); return serializable_list_interpreter_t<Context, T>::_(t, separator, context);
} }
} }
#endif #endif

View File

@ -39,7 +39,6 @@ namespace sqlpp
static_assert(wrong_t<interpreter_t>::value, "missing interpreter specialization"); static_assert(wrong_t<interpreter_t>::value, "missing interpreter specialization");
} }
}; };
} }
#endif #endif

View File

@ -41,9 +41,9 @@ namespace sqlpp
template <typename Database, typename Table> template <typename Database, typename Table>
struct into_data_t struct into_data_t
{ {
into_data_t(Table table): into_data_t(Table table) : _table(table)
_table(table) {
{} }
into_data_t(const into_data_t&) = default; into_data_t(const into_data_t&) = default;
into_data_t(into_data_t&&) = default; into_data_t(into_data_t&&) = default;
@ -63,7 +63,9 @@ namespace sqlpp
using _data_t = into_data_t<Database, Table>; using _data_t = into_data_t<Database, Table>;
struct _alias_t {}; struct _alias_t
{
};
// Member implementation with data and methods // Member implementation with data and methods
template <typename Policies> template <typename Policies>
@ -79,8 +81,14 @@ namespace sqlpp
using _data_t = into_data_t<Database, Table>; using _data_t = into_data_t<Database, Table>;
_impl_t<Policies> into; _impl_t<Policies> into;
_impl_t<Policies>& operator()() { return into; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return into; } {
return into;
}
const _impl_t<Policies>& operator()() const
{
return into;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.into) static auto _get_member(T t) -> decltype(t.into)
@ -90,7 +98,6 @@ namespace sqlpp
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
}; };
}; };
struct assert_into_t struct assert_into_t
@ -127,8 +134,14 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
_impl_t<Policies> no_into; _impl_t<Policies> no_into;
_impl_t<Policies>& operator()() { return no_into; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return no_into; } {
return no_into;
}
const _impl_t<Policies>& operator()() const
{
return no_into;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.no_into) static auto _get_member(T t) -> decltype(t.no_into)
@ -147,8 +160,7 @@ namespace sqlpp
using _consistency_check = assert_into_t; using _consistency_check = assert_into_t;
template <typename Table> template <typename Table>
auto into(Table table) const auto into(Table table) const -> _new_statement_t<_check<Table>, into_t<void, Table>>
-> _new_statement_t<_check<Table>, into_t<void, Table>>
{ {
static_assert(_check<Table>::value, "argument is not a raw table in into()"); static_assert(_check<Table>::value, "argument is not a raw table in into()");
return _into_impl<void>(_check<Table>{}, table); return _into_impl<void>(_check<Table>{}, table);
@ -156,14 +168,14 @@ namespace sqlpp
private: private:
template <typename Database, typename Table> template <typename Database, typename Table>
auto _into_impl(const std::false_type&, Table table) const auto _into_impl(const std::false_type&, Table table) const -> bad_statement;
-> bad_statement;
template <typename Database, typename Table> template <typename Database, typename Table>
auto _into_impl(const std::true_type&, Table table) const auto _into_impl(const std::true_type&, Table table) const
-> _new_statement_t<std::true_type, into_t<Database, Table>> -> _new_statement_t<std::true_type, into_t<Database, Table>>
{ {
static_assert(required_tables_of<into_t<Database, Table>>::size::value == 0, "argument depends on another table in into()"); static_assert(required_tables_of<into_t<Database, Table>>::size::value == 0,
"argument depends on another table in into()");
return {static_cast<const derived_statement_t<Policies>&>(*this), into_data_t<Database, Table>{table}}; return {static_cast<const derived_statement_t<Policies>&>(*this), into_data_t<Database, Table>{table}};
} }

View File

@ -49,8 +49,7 @@ namespace sqlpp
}; };
template <typename Operand> template <typename Operand>
struct is_not_null_t: struct is_not_null_t : public expression_operators<is_not_null_t<Operand>, boolean>,
public expression_operators<is_not_null_t<Operand>, boolean>,
public alias_operators<is_not_null_t<Operand>> public alias_operators<is_not_null_t<Operand>>
{ {
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>; using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
@ -58,9 +57,9 @@ namespace sqlpp
using _auto_alias_t = is_not_null_alias_t; using _auto_alias_t = is_not_null_alias_t;
is_not_null_t(Operand operand): is_not_null_t(Operand operand) : _operand(operand)
_operand(operand) {
{} }
is_not_null_t(const is_not_null_t&) = default; is_not_null_t(const is_not_null_t&) = default;
is_not_null_t(is_not_null_t&&) = default; is_not_null_t(is_not_null_t&&) = default;
@ -84,7 +83,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -49,8 +49,7 @@ namespace sqlpp
}; };
template <typename Operand> template <typename Operand>
struct is_null_t: struct is_null_t : public expression_operators<is_null_t<Operand>, boolean>,
public expression_operators<is_null_t<Operand>, boolean>,
public alias_operators<is_null_t<Operand>> public alias_operators<is_null_t<Operand>>
{ {
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>; using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
@ -58,9 +57,9 @@ namespace sqlpp
using _auto_alias_t = is_null_alias_t; using _auto_alias_t = is_null_alias_t;
is_null_t(Operand operand): is_null_t(Operand operand) : _operand(operand)
_operand(operand) {
{} }
is_null_t(const is_null_t&) = default; is_null_t(const is_null_t&) = default;
is_null_t(is_null_t&&) = default; is_null_t(is_null_t&&) = default;
@ -84,7 +83,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -36,7 +36,8 @@ namespace sqlpp
struct inner_join_t struct inner_join_t
{ {
template <typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using _provided_outer_tables = detail::make_joined_set_t<provided_outer_tables_of<Lhs>, provided_outer_tables_of<Rhs>>; using _provided_outer_tables =
detail::make_joined_set_t<provided_outer_tables_of<Lhs>, provided_outer_tables_of<Rhs>>;
static constexpr const char* _name = " INNER "; static constexpr const char* _name = " INNER ";
}; };
@ -74,7 +75,8 @@ namespace sqlpp
static_assert(not is_join_t<Rhs>::value, "rhs argument for join must not be a join"); static_assert(not is_join_t<Rhs>::value, "rhs argument for join must not be a join");
static_assert(is_noop<On>::value or is_on_t<On>::value, "invalid on expression in join().on()"); static_assert(is_noop<On>::value or is_on_t<On>::value, "invalid on expression in join().on()");
static_assert(detail::is_disjunct_from<provided_tables_of<Lhs>, provided_tables_of<Rhs>>::value, "joined tables must not be identical"); static_assert(detail::is_disjunct_from<provided_tables_of<Lhs>, provided_tables_of<Rhs>>::value,
"joined tables must not be identical");
static_assert(required_tables_of<join_t>::size::value == 0, "joined tables must not depend on other tables"); static_assert(required_tables_of<join_t>::size::value == 0, "joined tables must not depend on other tables");
@ -82,16 +84,13 @@ namespace sqlpp
using set_on_t = join_t<JoinType, Lhs, Rhs, OnT>; using set_on_t = join_t<JoinType, Lhs, Rhs, OnT>;
template <typename... Expr> template <typename... Expr>
auto on(Expr... expr) auto on(Expr... expr) -> set_on_t<on_t<void, Expr...>>
-> set_on_t<on_t<void, Expr...>>
{ {
static_assert(is_noop<On>::value, "cannot call on() twice for a single join()"); static_assert(is_noop<On>::value, "cannot call on() twice for a single join()");
static_assert(logic::all_t<is_expression_t<Expr>::value...>::value, "at least one argument is not an expression in on()"); static_assert(logic::all_t<is_expression_t<Expr>::value...>::value,
"at least one argument is not an expression in on()");
return { _lhs, return {_lhs, _rhs, {std::tuple<Expr...>{expr...}, {}}};
_rhs,
{std::tuple<Expr...>{expr...}, {}}
};
} }
template <typename T> template <typename T>
@ -151,7 +150,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -35,8 +35,7 @@
namespace sqlpp namespace sqlpp
{ {
template <typename Operand, typename Pattern> template <typename Operand, typename Pattern>
struct like_t: struct like_t : public expression_operators<like_t<Operand, Pattern>, boolean>,
public expression_operators<like_t<Operand, Pattern>, boolean>,
public alias_operators<like_t<Operand, Pattern>> public alias_operators<like_t<Operand, Pattern>>
{ {
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>; using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
@ -50,15 +49,20 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T like; T like;
T& operator()() { return like; } T& operator()()
const T& operator()() const { return like; } {
return like;
}
const T& operator()() const
{
return like;
}
}; };
}; };
like_t(Operand operand, Pattern pattern): like_t(Operand operand, Pattern pattern) : _operand(operand), _pattern(pattern)
_operand(operand), {
_pattern(pattern) }
{}
like_t(const like_t&) = default; like_t(const like_t&) = default;
like_t(like_t&&) = default; like_t(like_t&&) = default;

View File

@ -37,9 +37,9 @@ namespace sqlpp
template <typename Limit> template <typename Limit>
struct limit_data_t struct limit_data_t
{ {
limit_data_t(Limit value): limit_data_t(Limit value) : _value(value)
_value(value) {
{} }
limit_data_t(const limit_data_t&) = default; limit_data_t(const limit_data_t&) = default;
limit_data_t(limit_data_t&&) = default; limit_data_t(limit_data_t&&) = default;
@ -74,8 +74,14 @@ namespace sqlpp
using _data_t = limit_data_t<Limit>; using _data_t = limit_data_t<Limit>;
_impl_t<Policies> limit; _impl_t<Policies> limit;
_impl_t<Policies>& operator()() { return limit; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return limit; } {
return limit;
}
const _impl_t<Policies>& operator()() const
{
return limit;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.limit) static auto _get_member(T t) -> decltype(t.limit)
@ -91,15 +97,13 @@ namespace sqlpp
template <typename Database> template <typename Database>
struct dynamic_limit_data_t struct dynamic_limit_data_t
{ {
dynamic_limit_data_t(): dynamic_limit_data_t() : _value(noop())
_value(noop())
{ {
} }
template <typename Limit> template <typename Limit>
dynamic_limit_data_t(Limit value): dynamic_limit_data_t(Limit value)
_initialized(true), : _initialized(true), _value(wrap_operand_t<Limit>(value))
_value(wrap_operand_t<Limit>(value))
{ {
} }
@ -136,6 +140,7 @@ namespace sqlpp
_data._value = arg_t{value}; _data._value = arg_t{value};
_data._initialized = true; _data._initialized = true;
} }
public: public:
_data_t _data; _data_t _data;
}; };
@ -147,8 +152,14 @@ namespace sqlpp
using _data_t = dynamic_limit_data_t<Database>; using _data_t = dynamic_limit_data_t<Database>;
_impl_t<Policies> limit; _impl_t<Policies> limit;
_impl_t<Policies>& operator()() { return limit; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return limit; } {
return limit;
}
const _impl_t<Policies>& operator()() const
{
return limit;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.limit) static auto _get_member(T t) -> decltype(t.limit)
@ -182,8 +193,14 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
_impl_t<Policies> no_limit; _impl_t<Policies> no_limit;
_impl_t<Policies>& operator()() { return no_limit; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return no_limit; } {
return no_limit;
}
const _impl_t<Policies>& operator()() const
{
return no_limit;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.no_limit) static auto _get_member(T t) -> decltype(t.no_limit)
@ -202,31 +219,26 @@ namespace sqlpp
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
template <typename Arg> template <typename Arg>
auto limit(Arg arg) const auto limit(Arg arg) const -> _new_statement_t<_check<Arg>, limit_t<wrap_operand_t<Arg>>>
-> _new_statement_t<_check<Arg>, limit_t<wrap_operand_t<Arg>>>
{ {
static_assert(_check<Arg>::value, "limit requires an integral value or integral parameter"); static_assert(_check<Arg>::value, "limit requires an integral value or integral parameter");
return _limit_impl(_check<Arg>{}, wrap_operand_t<Arg>{arg}); return _limit_impl(_check<Arg>{}, wrap_operand_t<Arg>{arg});
} }
auto dynamic_limit() const auto dynamic_limit() const -> _new_statement_t<std::true_type, dynamic_limit_t<_database_t>>
-> _new_statement_t<std::true_type, dynamic_limit_t<_database_t>>
{ {
return {static_cast<const derived_statement_t<Policies>&>(*this), dynamic_limit_data_t<_database_t>{}}; return {static_cast<const derived_statement_t<Policies>&>(*this), dynamic_limit_data_t<_database_t>{}};
} }
private: private:
template <typename Arg> template <typename Arg>
auto _limit_impl(const std::false_type&, Arg arg) const auto _limit_impl(const std::false_type&, Arg arg) const -> bad_statement;
-> bad_statement;
template <typename Arg> template <typename Arg>
auto _limit_impl(const std::true_type&, Arg arg) const auto _limit_impl(const std::true_type&, Arg arg) const -> _new_statement_t<std::true_type, limit_t<Arg>>
-> _new_statement_t<std::true_type, limit_t<Arg>>
{ {
return {static_cast<const derived_statement_t<Policies>&>(*this), limit_data_t<Arg>{arg}}; return {static_cast<const derived_statement_t<Policies>&>(*this), limit_data_t<Arg>{arg}};
} }
}; };
}; };

View File

@ -39,19 +39,15 @@ namespace sqlpp
// see http://lists.boost.org/Archives/boost/2014/05/212946.php :-) // see http://lists.boost.org/Archives/boost/2014/05/212946.php :-)
template <bool... B> template <bool... B>
using all_t = std::integral_constant< using all_t = std::integral_constant<bool, std::is_same<logic_helper<B...>, logic_helper<(true or B)...>>::value>;
bool,
std::is_same<logic_helper<B...>, logic_helper<(true or B)...>>::value>;
template <bool... B> template <bool... B>
using any_t = std::integral_constant< using any_t =
bool, std::integral_constant<bool, not std::is_same<logic_helper<B...>, logic_helper<(false and B)...>>::value>;
not std::is_same<logic_helper<B...>, logic_helper<(false and B)...>>::value>;
template <bool... B> template <bool... B>
using none_t = std::integral_constant< using none_t =
bool, std::integral_constant<bool, std::is_same<logic_helper<B...>, logic_helper<(false and B)...>>::value>;
std::is_same<logic_helper<B...>, logic_helper<(false and B)...>>::value>;
template <bool> template <bool>
struct not_impl; struct not_impl;
@ -68,15 +64,12 @@ namespace sqlpp
using type = std::true_type; using type = std::true_type;
}; };
template <template <typename> class Predicate, typename... T> template <template <typename> class Predicate, typename... T>
using not_t = typename not_impl<Predicate<T>::value...>::type; using not_t = typename not_impl<Predicate<T>::value...>::type;
template <typename T> template <typename T>
using identity_t = T; using identity_t = T;
} }
} }
#endif #endif

View File

@ -42,25 +42,29 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T max; T max;
T& operator()() { return max; } T& operator()()
const T& operator()() const { return max; } {
return max;
}
const T& operator()() const
{
return max;
}
}; };
}; };
}; };
template <typename Expr> template <typename Expr>
struct max_t: struct max_t : public expression_operators<max_t<Expr>, value_type_of<Expr>>, public alias_operators<max_t<Expr>>
public expression_operators<max_t<Expr>, value_type_of<Expr>>,
public alias_operators<max_t<Expr>>
{ {
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>; using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>; using _nodes = detail::type_vector<Expr, aggregate_function>;
using _auto_alias_t = max_alias_t; using _auto_alias_t = max_alias_t;
max_t(Expr expr): max_t(Expr expr) : _expr(expr)
_expr(expr) {
{} }
max_t(const max_t&) = default; max_t(const max_t&) = default;
max_t(max_t&&) = default; max_t(max_t&&) = default;
@ -89,11 +93,11 @@ namespace sqlpp
template <typename T> template <typename T>
auto max(T t) -> max_t<wrap_operand_t<T>> auto max(T t) -> max_t<wrap_operand_t<T>>
{ {
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "max() cannot be used on an aggregate function"); static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"max() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "max() requires an expression as argument"); static_assert(is_expression_t<wrap_operand_t<T>>::value, "max() requires an expression as argument");
return {t}; return {t};
} }
} }
#endif #endif

View File

@ -42,25 +42,29 @@ namespace sqlpp
struct _member_t struct _member_t
{ {
T min; T min;
T& operator()() { return min; } T& operator()()
const T& operator()() const { return min; } {
return min;
}
const T& operator()() const
{
return min;
}
}; };
}; };
}; };
template <typename Expr> template <typename Expr>
struct min_t: struct min_t : public expression_operators<min_t<Expr>, value_type_of<Expr>>, public alias_operators<min_t<Expr>>
public expression_operators<min_t<Expr>, value_type_of<Expr>>,
public alias_operators<min_t<Expr>>
{ {
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>; using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>; using _nodes = detail::type_vector<Expr, aggregate_function>;
using _auto_alias_t = min_alias_t; using _auto_alias_t = min_alias_t;
min_t(Expr expr): min_t(Expr expr) : _expr(expr)
_expr(expr) {
{} }
min_t(const min_t&) = default; min_t(const min_t&) = default;
min_t(min_t&&) = default; min_t(min_t&&) = default;
@ -89,11 +93,11 @@ namespace sqlpp
template <typename T> template <typename T>
auto min(T t) -> min_t<wrap_operand_t<T>> auto min(T t) -> min_t<wrap_operand_t<T>>
{ {
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "min() cannot be used on an aggregate function"); static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"min() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "min() requires an expression as argument"); static_assert(is_expression_t<wrap_operand_t<T>>::value, "min() requires an expression as argument");
return {t}; return {t};
} }
} }
#endif #endif

View File

@ -44,15 +44,16 @@ namespace sqlpp
using _traits = make_traits<no_value_t>; using _traits = make_traits<no_value_t>;
using _nodes = detail::type_vector<Columns...>; using _nodes = detail::type_vector<Columns...>;
static_assert(logic::all_t<is_selectable_t<Columns>::value...>::value, "multi_column parameters need to be named expressions"); static_assert(logic::all_t<is_selectable_t<Columns>::value...>::value,
"multi_column parameters need to be named expressions");
multi_column_t(std::tuple<Columns...> columns): multi_column_t(std::tuple<Columns...> columns) : _columns(columns)
_columns(columns) {
{} }
multi_column_t(Columns... columns): multi_column_t(Columns... columns) : _columns(columns...)
_columns(columns...) {
{} }
multi_column_t(const multi_column_t&) = default; multi_column_t(const multi_column_t&) = default;
multi_column_t(multi_column_t&&) = default; multi_column_t(multi_column_t&&) = default;
@ -75,21 +76,22 @@ namespace sqlpp
using _traits = make_traits<no_value_t, tag::is_alias, tag::is_multi_column, tag::is_selectable>; using _traits = make_traits<no_value_t, tag::is_alias, tag::is_multi_column, tag::is_selectable>;
using _nodes = detail::type_vector<Columns...>; using _nodes = detail::type_vector<Columns...>;
static_assert(logic::all_t<is_selectable_t<Columns>::value...>::value, "multi_column parameters need to be named expressions"); static_assert(logic::all_t<is_selectable_t<Columns>::value...>::value,
"multi_column parameters need to be named expressions");
using _alias_t = typename AliasProvider::_alias_t; using _alias_t = typename AliasProvider::_alias_t;
multi_column_alias_t(multi_column_t<void, Columns...> multi_column): multi_column_alias_t(multi_column_t<void, Columns...> multi_column) : _columns(multi_column._columns)
_columns(multi_column._columns) {
{} }
multi_column_alias_t(std::tuple<Columns...> columns): multi_column_alias_t(std::tuple<Columns...> columns) : _columns(columns)
_columns(columns) {
{} }
multi_column_alias_t(Columns... columns): multi_column_alias_t(Columns... columns) : _columns(columns...)
_columns(columns...) {
{} }
multi_column_alias_t(const multi_column_alias_t&) = default; multi_column_alias_t(const multi_column_alias_t&) = default;
multi_column_alias_t(multi_column_alias_t&&) = default; multi_column_alias_t(multi_column_alias_t&&) = default;
@ -129,18 +131,14 @@ namespace sqlpp
{ {
template <typename... Columns> template <typename... Columns>
using make_multi_column_t = using make_multi_column_t =
copy_tuple_args_t<multi_column_t, void, copy_tuple_args_t<multi_column_t, void, decltype(column_tuple_merge(std::declval<Columns>()...))>;
decltype(column_tuple_merge(std::declval<Columns>()...))>;
} }
template <typename... Columns> template <typename... Columns>
auto multi_column(Columns... columns) auto multi_column(Columns... columns) -> detail::make_multi_column_t<Columns...>
-> detail::make_multi_column_t<Columns...>
{ {
return detail::make_multi_column_t<Columns...>(std::tuple_cat(detail::as_column_tuple<Columns>::_(columns)...)); return detail::make_multi_column_t<Columns...>(std::tuple_cat(detail::as_column_tuple<Columns>::_(columns)...));
} }
} }
#endif #endif

View File

@ -41,10 +41,10 @@ namespace sqlpp
using _interpreter_context_t = typename Db::_interpreter_context_t; using _interpreter_context_t = typename Db::_interpreter_context_t;
template <typename T> template <typename T>
named_interpretable_t(T t): named_interpretable_t(T t)
_requires_braces(requires_braces_t<T>::value), : _requires_braces(requires_braces_t<T>::value), _impl(std::make_shared<_impl_t<T>>(t))
_impl(std::make_shared<_impl_t<T>>(t)) {
{} }
named_interpretable_t(const named_interpretable_t&) = default; named_interpretable_t(const named_interpretable_t&) = default;
named_interpretable_t(named_interpretable_t&&) = default; named_interpretable_t(named_interpretable_t&&) = default;
@ -59,9 +59,10 @@ namespace sqlpp
// This method only exists if Db::_serializer_context_t and serializer_context_t are not the same // This method only exists if Db::_serializer_context_t and serializer_context_t are not the same
template <typename Context> template <typename Context>
auto serialize(Context& context) const auto serialize(Context& context) const ->
-> typename std::enable_if<std::is_same<Context, _serializer_context_t>::value typename std::enable_if<std::is_same<Context, _serializer_context_t>::value and
and not std::is_same<Context, serializer_context_t>::value, Context&>::type not std::is_same<Context, serializer_context_t>::value,
Context&>::type
{ {
return _impl->db_serialize(context); return _impl->db_serialize(context);
} }
@ -91,9 +92,9 @@ namespace sqlpp
struct _impl_t : public _impl_base struct _impl_t : public _impl_base
{ {
static_assert(not make_parameter_list_t<T>::size::value, "parameters not supported in dynamic statement parts"); static_assert(not make_parameter_list_t<T>::size::value, "parameters not supported in dynamic statement parts");
_impl_t(T t): _impl_t(T t) : _t(t)
_t(t) {
{} }
serializer_context_t& serialize(serializer_context_t& context) const serializer_context_t& serialize(serializer_context_t& context) const
{ {
@ -144,7 +145,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -32,7 +32,9 @@
namespace sqlpp namespace sqlpp
{ {
struct no_data_t {}; struct no_data_t
{
};
template <typename Context> template <typename Context>
struct serializer_t<Context, no_data_t> struct serializer_t<Context, no_data_t>

View File

@ -46,6 +46,5 @@ namespace sqlpp
struct column_operators<Base, no_value_t> struct column_operators<Base, no_value_t>
{ {
}; };
} }
#endif #endif

View File

@ -39,7 +39,9 @@ namespace sqlpp
using _traits = make_traits<no_value_t, tag::is_noop>; using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
struct _alias_t {}; struct _alias_t
{
};
template <typename Statement> template <typename Statement>
struct _result_methods_t struct _result_methods_t
@ -66,15 +68,13 @@ namespace sqlpp
// Prepare // Prepare
template <typename Db, typename Composite> template <typename Db, typename Composite>
auto _prepare(Db& db, const Composite& composite) const auto _prepare(Db& db, const Composite& composite) const -> prepared_execute_t<Db, Composite>
-> prepared_execute_t<Db, Composite>
{ {
return {{}, db.prepare_execute(composite)}; return {{}, db.prepare_execute(composite)};
} }
template <typename Db> template <typename Db>
auto _prepare(Db& db) const auto _prepare(Db& db) const -> prepared_execute_t<Db, _statement_t>
-> prepared_execute_t<Db, _statement_t>
{ {
return {{}, db.prepare_execute(_get_statement())}; return {{}, db.prepare_execute(_get_statement())};
} }
@ -94,7 +94,8 @@ namespace sqlpp
}; };
template <typename T> template <typename T>
struct is_noop: std::is_same<T, noop> {}; struct is_noop : std::is_same<T, noop>
{
};
} }
#endif #endif

View File

@ -50,8 +50,7 @@ namespace sqlpp
}; };
template <typename Operand, typename... Args> template <typename Operand, typename... Args>
struct not_in_t: struct not_in_t : public expression_operators<not_in_t<Operand, Args...>, boolean>,
public expression_operators<not_in_t<Operand, Args...>, boolean>,
public alias_operators<not_in_t<Operand, Args...>> public alias_operators<not_in_t<Operand, Args...>>
{ {
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>; using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
@ -61,10 +60,9 @@ namespace sqlpp
using _auto_alias_t = not_in_alias_t; using _auto_alias_t = not_in_alias_t;
not_in_t(Operand operand, Args... args): not_in_t(Operand operand, Args... args) : _operand(operand), _args(args...)
_operand(operand), {
_args(args...) }
{}
not_in_t(const not_in_t&) = default; not_in_t(const not_in_t&) = default;
not_in_t(not_in_t&&) = default; not_in_t(not_in_t&&) = default;
@ -121,8 +119,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -51,7 +51,6 @@ namespace sqlpp
}; };
constexpr null_t null = {}; constexpr null_t null = {};
} }
#endif #endif

View File

@ -37,9 +37,9 @@ namespace sqlpp
template <typename Offset> template <typename Offset>
struct offset_data_t struct offset_data_t
{ {
offset_data_t(Offset value): offset_data_t(Offset value) : _value(value)
_value(value) {
{} }
offset_data_t(const offset_data_t&) = default; offset_data_t(const offset_data_t&) = default;
offset_data_t(offset_data_t&&) = default; offset_data_t(offset_data_t&&) = default;
@ -76,8 +76,14 @@ namespace sqlpp
using _data_t = offset_data_t<Offset>; using _data_t = offset_data_t<Offset>;
_impl_t<Policies> offset; _impl_t<Policies> offset;
_impl_t<Policies>& operator()() { return offset; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return offset; } {
return offset;
}
const _impl_t<Policies>& operator()() const
{
return offset;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.offset) static auto _get_member(T t) -> decltype(t.offset)
@ -93,15 +99,13 @@ namespace sqlpp
template <typename Database> template <typename Database>
struct dynamic_offset_data_t struct dynamic_offset_data_t
{ {
dynamic_offset_data_t(): dynamic_offset_data_t() : _value(noop())
_value(noop())
{ {
} }
template <typename Offset> template <typename Offset>
dynamic_offset_data_t(Offset value): dynamic_offset_data_t(Offset value)
_initialized(true), : _initialized(true), _value(wrap_operand_t<Offset>(value))
_value(wrap_operand_t<Offset>(value))
{ {
} }
@ -138,6 +142,7 @@ namespace sqlpp
_data._value = arg_t{value}; _data._value = arg_t{value};
_data._initialized = true; _data._initialized = true;
} }
public: public:
_data_t _data; _data_t _data;
}; };
@ -149,8 +154,14 @@ namespace sqlpp
using _data_t = dynamic_offset_data_t<Database>; using _data_t = dynamic_offset_data_t<Database>;
_impl_t<Policies> offset; _impl_t<Policies> offset;
_impl_t<Policies>& operator()() { return offset; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return offset; } {
return offset;
}
const _impl_t<Policies>& operator()() const
{
return offset;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.offset) static auto _get_member(T t) -> decltype(t.offset)
@ -196,8 +207,14 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
_impl_t<Policies> no_offset; _impl_t<Policies> no_offset;
_impl_t<Policies>& operator()() { return no_offset; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return no_offset; } {
return no_offset;
}
const _impl_t<Policies>& operator()() const
{
return no_offset;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.no_offset) static auto _get_member(T t) -> decltype(t.no_offset)
@ -216,32 +233,28 @@ namespace sqlpp
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
template <typename Arg> template <typename Arg>
auto offset(Arg arg) const auto offset(Arg arg) const -> _new_statement_t<_check<Arg>, offset_t<wrap_operand_t<Arg>>>
-> _new_statement_t<_check<Arg>, offset_t<wrap_operand_t<Arg>>>
{ {
static_assert(_check<Arg>::value, "offset requires an integral value or integral parameter"); static_assert(_check<Arg>::value, "offset requires an integral value or integral parameter");
return _offset_impl(_check<Arg>{}, wrap_operand_t<Arg>{arg}); return _offset_impl(_check<Arg>{}, wrap_operand_t<Arg>{arg});
} }
auto dynamic_offset() const auto dynamic_offset() const -> _new_statement_t<std::true_type, dynamic_offset_t<_database_t>>
-> _new_statement_t<std::true_type, dynamic_offset_t<_database_t>>
{ {
static_assert(not std::is_same<_database_t, void>::value, "dynamic_offset must not be called in a static statement"); static_assert(not std::is_same<_database_t, void>::value,
"dynamic_offset must not be called in a static statement");
return {static_cast<const derived_statement_t<Policies>&>(*this), dynamic_offset_data_t<_database_t>{}}; return {static_cast<const derived_statement_t<Policies>&>(*this), dynamic_offset_data_t<_database_t>{}};
} }
private: private:
template <typename Arg> template <typename Arg>
auto _offset_impl(const std::false_type&, Arg arg) const auto _offset_impl(const std::false_type&, Arg arg) const -> bad_statement;
-> bad_statement;
template <typename Arg> template <typename Arg>
auto _offset_impl(const std::true_type&, Arg arg) const auto _offset_impl(const std::true_type&, Arg arg) const -> _new_statement_t<std::true_type, offset_t<Arg>>
-> _new_statement_t<std::true_type, offset_t<Arg>>
{ {
return {static_cast<const derived_statement_t<Policies>&>(*this), offset_data_t<Arg>{arg}}; return {static_cast<const derived_statement_t<Policies>&>(*this), offset_data_t<Arg>{arg}};
} }
}; };
}; };

View File

@ -90,7 +90,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -41,9 +41,9 @@ namespace sqlpp
template <typename Database, typename... Expressions> template <typename Database, typename... Expressions>
struct order_by_data_t struct order_by_data_t
{ {
order_by_data_t(Expressions... expressions): order_by_data_t(Expressions... expressions) : _expressions(expressions...)
_expressions(expressions...) {
{} }
order_by_data_t(const order_by_data_t&) = default; order_by_data_t(const order_by_data_t&) = default;
order_by_data_t(order_by_data_t&&) = default; order_by_data_t(order_by_data_t&&) = default;
@ -62,7 +62,8 @@ namespace sqlpp
template <typename T = void> template <typename T = void>
static void _() static void _()
{ {
static_assert(wrong_t<T>::value, "at least one order-by expression requires a table which is otherwise not known in the statement"); static_assert(wrong_t<T>::value,
"at least one order-by expression requires a table which is otherwise not known in the statement");
} }
}; };
@ -93,7 +94,8 @@ namespace sqlpp
{ {
static_assert(_is_dynamic::value, "add() must not be called for static order_by"); static_assert(_is_dynamic::value, "add() must not be called for static order_by");
static_assert(is_sort_order_t<Expression>::value, "invalid expression argument in order_by::add()"); static_assert(is_sort_order_t<Expression>::value, "invalid expression argument in order_by::add()");
static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value, "expression uses tables unknown to this statement in order_by::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables<Expression>::value,
"expression uses tables unknown to this statement in order_by::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>; using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expression>;
_serialize_check::_(); _serialize_check::_();
@ -111,6 +113,7 @@ namespace sqlpp
template <typename Expression> template <typename Expression>
void _add_impl(Expression expression, const std::false_type&); void _add_impl(Expression expression, const std::false_type&);
public: public:
_data_t _data; _data_t _data;
}; };
@ -122,8 +125,14 @@ namespace sqlpp
using _data_t = order_by_data_t<Database, Expressions...>; using _data_t = order_by_data_t<Database, Expressions...>;
_impl_t<Policies> order_by; _impl_t<Policies> order_by;
_impl_t<Policies>& operator()() { return order_by; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return order_by; } {
return order_by;
}
const _impl_t<Policies>& operator()() const
{
return order_by;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.order_by) static auto _get_member(T t) -> decltype(t.order_by)
@ -160,8 +169,14 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
_impl_t<Policies> no_order_by; _impl_t<Policies> no_order_by;
_impl_t<Policies>& operator()() { return no_order_by; } _impl_t<Policies>& operator()()
const _impl_t<Policies>& operator()() const { return no_order_by; } {
return no_order_by;
}
const _impl_t<Policies>& operator()() const
{
return no_order_by;
}
template <typename T> template <typename T>
static auto _get_member(T t) -> decltype(t.no_order_by) static auto _get_member(T t) -> decltype(t.no_order_by)
@ -193,7 +208,8 @@ namespace sqlpp
auto dynamic_order_by(Expressions... expressions) const auto dynamic_order_by(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, order_by_t<_database_t, Expressions...>> -> _new_statement_t<_check<Expressions...>, order_by_t<_database_t, Expressions...>>
{ {
static_assert(not std::is_same<_database_t, void>::value, "dynamic_order_by must not be called in a static statement"); static_assert(not std::is_same<_database_t, void>::value,
"dynamic_order_by must not be called in a static statement");
static_assert(_check<Expressions...>::value, "at least one argument is not a sort order in order_by()"); static_assert(_check<Expressions...>::value, "at least one argument is not a sort order in order_by()");
return _order_by_impl<_database_t>(_check<Expressions...>{}, expressions...); return _order_by_impl<_database_t>(_check<Expressions...>{}, expressions...);
@ -201,16 +217,17 @@ namespace sqlpp
private: private:
template <typename Database, typename... Expressions> template <typename Database, typename... Expressions>
auto _order_by_impl(const std::false_type&, Expressions... expressions) const auto _order_by_impl(const std::false_type&, Expressions... expressions) const -> bad_statement;
-> bad_statement;
template <typename Database, typename... Expressions> template <typename Database, typename... Expressions>
auto _order_by_impl(const std::true_type&, Expressions... expressions) const auto _order_by_impl(const std::true_type&, Expressions... expressions) const
-> _new_statement_t<std::true_type, order_by_t<_database_t, Expressions...>> -> _new_statement_t<std::true_type, order_by_t<_database_t, Expressions...>>
{ {
static_assert(not detail::has_duplicates<Expressions...>::value, "at least one duplicate argument detected in order_by()"); static_assert(not detail::has_duplicates<Expressions...>::value,
"at least one duplicate argument detected in order_by()");
return { static_cast<const derived_statement_t<Policies>&>(*this), order_by_data_t<Database, Expressions...>{expressions...} }; return {static_cast<const derived_statement_t<Policies>&>(*this),
order_by_data_t<Database, Expressions...>{expressions...}};
} }
}; };
}; };

View File

@ -34,8 +34,7 @@
namespace sqlpp namespace sqlpp
{ {
template <typename ValueType, typename NameType> template <typename ValueType, typename NameType>
struct parameter_t: struct parameter_t : public expression_operators<parameter_t<ValueType, NameType>, ValueType>
public expression_operators<parameter_t<ValueType, NameType>, ValueType>
{ {
using _traits = make_traits<ValueType, tag::is_parameter, tag::is_expression>; using _traits = make_traits<ValueType, tag::is_parameter, tag::is_expression>;
@ -46,7 +45,8 @@ namespace sqlpp
using _instance_t = member_t<NameType, parameter_value_t<ValueType>>; using _instance_t = member_t<NameType, parameter_value_t<ValueType>>;
parameter_t() parameter_t()
{} {
}
parameter_t(const parameter_t&) = default; parameter_t(const parameter_t&) = default;
parameter_t(parameter_t&&) = default; parameter_t(parameter_t&&) = default;
@ -69,22 +69,19 @@ namespace sqlpp
}; };
template <typename NamedExpr> template <typename NamedExpr>
auto parameter(const NamedExpr&) auto parameter(const NamedExpr&) -> parameter_t<value_type_of<NamedExpr>, NamedExpr>
-> parameter_t<value_type_of<NamedExpr>, 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 {};
} }
template <typename ValueType, typename AliasProvider> template <typename ValueType, typename AliasProvider>
auto parameter(const ValueType&, const AliasProvider&) auto parameter(const ValueType&, const AliasProvider&) -> parameter_t<wrap_operand_t<ValueType>, AliasProvider>
-> parameter_t<wrap_operand_t<ValueType>, AliasProvider>
{ {
static_assert(is_value_type_t<ValueType>::value, "first argument is not a value type"); static_assert(is_value_type_t<ValueType>::value, "first argument is not a value type");
static_assert(is_alias_provider_t<AliasProvider>::value, "second argument is not an alias provider"); static_assert(is_alias_provider_t<AliasProvider>::value, "second argument is not an alias provider");
return {}; return {};
} }
} }
#endif #endif

View File

@ -47,7 +47,8 @@ namespace sqlpp
using size = std::integral_constant<std::size_t, sizeof...(Parameter)>; using size = std::integral_constant<std::size_t, sizeof...(Parameter)>;
parameter_list_t() parameter_list_t()
{} {
}
template <typename Target> template <typename Target>
void _bind(Target& target) const void _bind(Target& target) const
@ -60,13 +61,13 @@ namespace sqlpp
void _bind_impl(Target& target, const detail::index_sequence<Is...>&) const void _bind_impl(Target& target, const detail::index_sequence<Is...>&) const
{ {
using swallow = int[]; // see interpret_tuple.h using swallow = int[]; // see interpret_tuple.h
(void) swallow{(static_cast<typename std::tuple_element<Is, const _member_tuple_t>::type&>(*this)()._bind(target, Is), 0)...}; (void)swallow{(
static_cast<typename std::tuple_element<Is, const _member_tuple_t>::type&>(*this)()._bind(target, Is), 0)...};
} }
}; };
template <typename Exp> template <typename Exp>
using make_parameter_list_t = parameter_list_t<parameters_of<Exp>>; using make_parameter_list_t = parameter_list_t<parameters_of<Exp>>;
} }
#endif #endif

View File

@ -68,7 +68,6 @@ namespace sqlpp
template <bool Check, typename Policies, typename Needle, typename Replacement> template <bool Check, typename Policies, typename Needle, typename Replacement>
using new_statement_t = typename new_statement_impl<Check, Policies, Needle, Replacement>::type; using new_statement_t = typename new_statement_impl<Check, Policies, Needle, Replacement>::type;
} }
#endif #endif

View File

@ -78,54 +78,49 @@
/***************************************************************************/ /***************************************************************************/
// tools // tools
#define SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \ #define SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) BOOST_PP_TUPLE_ELEM(0, BOOST_PP_EXPAND table)
BOOST_PP_TUPLE_ELEM(0, BOOST_PP_EXPAND table)
#define SQLPP_DECLARE_TABLE_GET_TABLE_PROPS(table) \ #define SQLPP_DECLARE_TABLE_GET_TABLE_PROPS(table) SQLPP_BOOST_PP_TUPLE_POP_FRONT(BOOST_PP_EXPAND table)
SQLPP_BOOST_PP_TUPLE_POP_FRONT(BOOST_PP_EXPAND table)
#define SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(col) \ #define SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(col) BOOST_PP_TUPLE_ELEM(0, col)
BOOST_PP_TUPLE_ELEM(0, col)
#define SQLPP_DECLARE_TABLE_ENUM_COLUMNS(unused, table, elem) \ #define SQLPP_DECLARE_TABLE_ENUM_COLUMNS(unused, table, elem) , table::SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)
,table::SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)
/***************************************************************************/ /***************************************************************************/
// columns // columns
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX(unused, size, idx, elem) \ #define SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX(unused, size, idx, elem) \
BOOST_PP_CAT( \ BOOST_PP_CAT(SQLPP_DECLARE_COLUMN_GEN_TRAITS_, BOOST_PP_CAT(SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_, elem))(elem) \
SQLPP_DECLARE_COLUMN_GEN_TRAITS_ \
,BOOST_PP_CAT(SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_, elem) \
)(elem) \
BOOST_PP_COMMA_IF(BOOST_PP_LESS(BOOST_PP_ADD(idx, 1), size)) BOOST_PP_COMMA_IF(BOOST_PP_LESS(BOOST_PP_ADD(idx, 1), size))
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS(props) \ #define SQLPP_DECLARE_COLUMN_GEN_TRAITS(props) \
BOOST_PP_SEQ_FOR_EACH_I( \ BOOST_PP_SEQ_FOR_EACH_I(SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX, BOOST_PP_TUPLE_SIZE(props), BOOST_PP_TUPLE_TO_SEQ(props))
SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX \
,BOOST_PP_TUPLE_SIZE(props) \
,BOOST_PP_TUPLE_TO_SEQ(props) \
)
#define SQLPP_DECLARE_COLUMN(unused, data, elem) \ #define SQLPP_DECLARE_COLUMN(unused, data, elem) \
struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) { \ struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) \
struct _alias_t { \ { \
static constexpr const char _literal[] = \ struct _alias_t \
BOOST_PP_STRINGIZE(SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)); \ { \
static constexpr const char _literal[] = BOOST_PP_STRINGIZE(SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)); \
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>; \ using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>; \
\ \
template <typename T> \ template <typename T> \
struct _member_t { \ struct _member_t \
{ \
T SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \ T SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \
\ \
T& operator()() { return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); } \ T& operator()() \
const T& operator()() const { return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); } \ { \
return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \
} \
const T& operator()() const \
{ \
return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \
} \
}; /* struct _member_t */ \ }; /* struct _member_t */ \
}; /* struct _alias_t */ \ }; /* struct _alias_t */ \
\ \
using _traits = sqlpp::make_traits< \ using _traits = sqlpp::make_traits<SQLPP_DECLARE_COLUMN_GEN_TRAITS(SQLPP_BOOST_PP_TUPLE_POP_FRONT(elem))>; \
SQLPP_DECLARE_COLUMN_GEN_TRAITS(SQLPP_BOOST_PP_TUPLE_POP_FRONT(elem)) \
>; \
\ \
}; /* struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) */ }; /* struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) */
@ -133,74 +128,61 @@
// table props // table props
#define SQLPP_DECLARE_TABLE_GEN_PROPS_AUX(unused1, unused2, elem) \ #define SQLPP_DECLARE_TABLE_GEN_PROPS_AUX(unused1, unused2, elem) \
BOOST_PP_CAT( \ BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GEN_, BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_PROC_LAZY_, elem))(elem)
SQLPP_DECLARE_TABLE_GEN_ \
,BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_PROC_LAZY_, elem) \
)(elem)
#define SQLPP_DECLARE_TABLE_GEN_PROPS(table) \ #define SQLPP_DECLARE_TABLE_GEN_PROPS(table) \
BOOST_PP_SEQ_FOR_EACH( \ BOOST_PP_SEQ_FOR_EACH(SQLPP_DECLARE_TABLE_GEN_PROPS_AUX, ~, \
SQLPP_DECLARE_TABLE_GEN_PROPS_AUX \ BOOST_PP_TUPLE_TO_SEQ(SQLPP_BOOST_PP_TUPLE_POP_FRONT(table)))
,~ \
,BOOST_PP_TUPLE_TO_SEQ(SQLPP_BOOST_PP_TUPLE_POP_FRONT(table)) \
)
/***************************************************************************/ /***************************************************************************/
// main // main
#define SQLPP_DECLARE_TABLE_IMPL(table, cols) \ #define SQLPP_DECLARE_TABLE_IMPL(table, cols) \
namespace SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) { \ namespace SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) { \ { \
BOOST_PP_SEQ_FOR_EACH( \ namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) \
SQLPP_DECLARE_COLUMN \ { \
,~ \ BOOST_PP_SEQ_FOR_EACH(SQLPP_DECLARE_COLUMN, ~, cols) \
,cols \
) \
} /* namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) */ \ } /* namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) */ \
\ \
struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \ struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
: sqlpp::table_t< \ : sqlpp::table_t<SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) BOOST_PP_SEQ_FOR_EACH( \
SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \ SQLPP_DECLARE_TABLE_ENUM_COLUMNS, BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _), cols)> \
BOOST_PP_SEQ_FOR_EACH( \
SQLPP_DECLARE_TABLE_ENUM_COLUMNS \
,BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) \
,cols \
) \
> \
{ \ { \
BOOST_PP_IF( \ BOOST_PP_IF(BOOST_PP_LESS(BOOST_PP_TUPLE_SIZE(table), 2), \
BOOST_PP_LESS(BOOST_PP_TUPLE_SIZE(table), 2) \ BOOST_PP_TUPLE_EAT(), \
,BOOST_PP_TUPLE_EAT() \ SQLPP_DECLARE_TABLE_GEN_PROPS)(BOOST_PP_EXPAND table) \
,SQLPP_DECLARE_TABLE_GEN_PROPS \
)(BOOST_PP_EXPAND table) \
\ \
struct _alias_t { \ struct _alias_t \
static constexpr const char _literal[] = \ { \
BOOST_PP_STRINGIZE(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table)); \ static constexpr const char _literal[] = BOOST_PP_STRINGIZE(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table)); \
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>; \ using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>; \
\ \
template <typename T> \ template <typename T> \
struct _member_t { \ struct _member_t \
{ \
T SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \ T SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \
\ \
T& operator()() { return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); } \ T& operator()() \
const T& operator()() const { return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); } \ { \
return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \
} \
const T& operator()() const \
{ \
return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \
} \
\ \
}; /* struct _member_t */ \ }; /* struct _member_t */ \
\ \
}; /* struct _alias_t */ \ }; /* struct _alias_t */ \
\ \
}; /* struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) */ \ }; /* struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) */ \
\
} }
/***************************************************************************/ /***************************************************************************/
#define SQLPP_DECLARE_TABLE(table, cols) \ #define SQLPP_DECLARE_TABLE(table, cols) \
SQLPP_DECLARE_TABLE_IMPL( \ SQLPP_DECLARE_TABLE_IMPL(BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X table, 0), BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X cols, 0))
BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X table, 0) \
,BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X cols, 0) \
)
/***************************************************************************/ /***************************************************************************/

View File

@ -44,8 +44,7 @@ namespace sqlpp
using _run_check = consistent_t; using _run_check = consistent_t;
auto _run(Db& db) const auto _run(Db& db) const -> size_t
-> size_t
{ {
return db.run_prepared_execute(*this); return db.run_prepared_execute(*this);
} }
@ -58,7 +57,6 @@ namespace sqlpp
_parameter_list_t params; _parameter_list_t params;
mutable _prepared_statement_t _prepared_statement; mutable _prepared_statement_t _prepared_statement;
}; };
} }
#endif #endif

View File

@ -44,8 +44,7 @@ namespace sqlpp
using _run_check = consistent_t; using _run_check = consistent_t;
auto _run(Db& db) const auto _run(Db& db) const -> size_t
-> size_t
{ {
return db.run_prepared_insert(*this); return db.run_prepared_insert(*this);
} }
@ -58,7 +57,6 @@ namespace sqlpp
_parameter_list_t params; _parameter_list_t params;
mutable _prepared_statement_t _prepared_statement; mutable _prepared_statement_t _prepared_statement;
}; };
} }
#endif #endif

View File

@ -44,8 +44,7 @@ namespace sqlpp
using _run_check = consistent_t; using _run_check = consistent_t;
auto _run(Db& db) const auto _run(Db& db) const -> size_t
-> size_t
{ {
return db.run_prepared_insert(*this); return db.run_prepared_insert(*this);
} }
@ -58,7 +57,6 @@ namespace sqlpp
_parameter_list_t params; _parameter_list_t params;
mutable _prepared_statement_t _prepared_statement; mutable _prepared_statement_t _prepared_statement;
}; };
} }
#endif #endif

View File

@ -46,8 +46,7 @@ namespace sqlpp
using _run_check = consistent_t; using _run_check = consistent_t;
auto _run(Database& db) const auto _run(Database& db) const -> result_t<decltype(db.run_prepared_select(*this)), _result_row_t>
-> result_t<decltype(db.run_prepared_select(*this)), _result_row_t>
{ {
return {db.run_prepared_select(*this), _dynamic_names}; return {db.run_prepared_select(*this), _dynamic_names};
} }
@ -61,7 +60,6 @@ namespace sqlpp
_dynamic_names_t _dynamic_names; _dynamic_names_t _dynamic_names;
mutable _prepared_statement_t _prepared_statement; mutable _prepared_statement_t _prepared_statement;
}; };
} }
#endif #endif

View File

@ -44,8 +44,7 @@ namespace sqlpp
using _run_check = consistent_t; using _run_check = consistent_t;
auto _run(Db& db) const auto _run(Db& db) const -> size_t
-> size_t
{ {
return db.run_prepared_insert(*this); return db.run_prepared_insert(*this);
} }
@ -58,7 +57,6 @@ namespace sqlpp
_parameter_list_t params; _parameter_list_t params;
mutable _prepared_statement_t _prepared_statement; mutable _prepared_statement_t _prepared_statement;
}; };
} }
#endif #endif

View File

@ -40,11 +40,15 @@
namespace sqlpp namespace sqlpp
{ {
struct remove_name_t {}; struct remove_name_t
{
};
struct remove_t : public statement_name_t<remove_name_t> struct remove_t : public statement_name_t<remove_name_t>
{ {
using _traits = make_traits<no_value_t, tag::is_return_value>; using _traits = make_traits<no_value_t, tag::is_return_value>;
struct _alias_t {}; struct _alias_t
{
};
template <typename Statement> template <typename Statement>
struct _result_methods_t struct _result_methods_t
@ -58,8 +62,7 @@ namespace sqlpp
// Execute // Execute
template <typename Db, typename Composite> template <typename Db, typename Composite>
auto _run(Db& db, const Composite& composite) const auto _run(Db& db, const Composite& composite) const -> decltype(db.remove(composite))
-> decltype(db.remove(composite))
{ {
return db.remove(composite); return db.remove(composite);
} }
@ -72,22 +75,19 @@ namespace sqlpp
// Prepare // Prepare
template <typename Db, typename Composite> template <typename Db, typename Composite>
auto _prepare(Db& db, const Composite& composite) const auto _prepare(Db& db, const Composite& composite) const -> prepared_remove_t<Db, Composite>
-> prepared_remove_t<Db, Composite>
{ {
return {{}, db.prepare_remove(composite)}; return {{}, db.prepare_remove(composite)};
} }
template <typename Db> template <typename Db>
auto _prepare(Db& db) const auto _prepare(Db& db) const -> prepared_remove_t<Db, _statement_t>
-> prepared_remove_t<Db, _statement_t>
{ {
return {{}, db.prepare_remove(_get_statement())}; return {{}, db.prepare_remove(_get_statement())};
} }
}; };
}; };
template <typename Context> template <typename Context>
struct serializer_t<Context, remove_name_t> struct serializer_t<Context, remove_name_t>
{ {
@ -103,38 +103,28 @@ namespace sqlpp
}; };
template <typename Database> template <typename Database>
using blank_remove_t = statement_t<Database, using blank_remove_t = statement_t<Database, remove_t, no_from_t, no_using_t, no_extra_tables_t, no_where_t<true>>;
remove_t,
no_from_t,
no_using_t,
no_extra_tables_t,
no_where_t<true>
>;
inline auto remove() inline auto remove() -> blank_remove_t<void>
-> blank_remove_t<void>
{ {
return {blank_remove_t<void>()}; return {blank_remove_t<void>()};
} }
template <typename Table> template <typename Table>
auto remove_from(Table table) auto remove_from(Table table) -> decltype(blank_remove_t<void>().from(table))
-> decltype(blank_remove_t<void>().from(table))
{ {
return {blank_remove_t<void>().from(table)}; return {blank_remove_t<void>().from(table)};
} }
template <typename Database> template <typename Database>
auto dynamic_remove(const Database&) auto dynamic_remove(const Database&) -> decltype(blank_remove_t<Database>())
-> decltype(blank_remove_t<Database>())
{ {
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter"); static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return {blank_remove_t<Database>()}; return {blank_remove_t<Database>()};
} }
template <typename Database, typename Table> template <typename Database, typename Table>
auto dynamic_remove_from(const Database&, Table table) auto dynamic_remove_from(const Database&, Table table) -> decltype(blank_remove_t<Database>().from(table))
-> decltype(blank_remove_t<Database>().from(table))
{ {
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter"); static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return {blank_remove_t<Database>().from(table)}; return {blank_remove_t<Database>().from(table)};

View File

@ -45,9 +45,8 @@ namespace sqlpp
result_t() = default; result_t() = default;
template <typename DynamicNames> template <typename DynamicNames>
result_t(db_result_t&& result, const DynamicNames& dynamic_names): result_t(db_result_t&& result, const DynamicNames& dynamic_names)
_result(std::move(result)), : _result(std::move(result)), _result_row(dynamic_names)
_result_row(dynamic_names)
{ {
_result.next(_result_row); _result.next(_result_row);
} }
@ -61,9 +60,7 @@ namespace sqlpp
class iterator class iterator
{ {
public: public:
iterator(db_result_t& result, result_row_t& result_row): iterator(db_result_t& result, result_row_t& result_row) : _result(result), _result_row(result_row)
_result(result),
_result_row(result_row)
{ {
} }
@ -120,7 +117,6 @@ namespace sqlpp
{ {
_result.next(_result_row); _result.next(_result_row);
} }
}; };
} }

View File

@ -57,7 +57,5 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -55,23 +55,24 @@ namespace sqlpp
{ {
using _field_spec_t = detail::get_field_spec_t<Field>; using _field_spec_t = detail::get_field_spec_t<Field>;
static constexpr bool _null_is_trivial = true; static constexpr bool _null_is_trivial = true;
operator cpp_value_type_of<_field_spec_t>() const { return static_cast<const Field&>(*this).value(); } operator cpp_value_type_of<_field_spec_t>() const
{
return static_cast<const Field&>(*this).value();
}
}; };
template <template <typename, typename, typename> class Field, typename ValueType, typename Db, typename FieldSpec> template <template <typename, typename, typename> class Field, typename ValueType, typename Db, typename FieldSpec>
struct result_field_methods_base_t< struct result_field_methods_base_t<Field<ValueType, Db, FieldSpec>,
Field<ValueType, Db, FieldSpec>, typename std::enable_if<enforce_null_result_treatment_t<Db>::value and
typename std::enable_if<enforce_null_result_treatment_t<Db>::value column_spec_can_be_null_t<FieldSpec>::value and
and column_spec_can_be_null_t<FieldSpec>::value not null_is_trivial_value_t<FieldSpec>::value>::type>
and not null_is_trivial_value_t<FieldSpec>::value>::type>
{ {
using _field_spec_t = FieldSpec; using _field_spec_t = FieldSpec;
static constexpr bool _null_is_trivial = false; static constexpr bool _null_is_trivial = false;
}; };
template <typename Field> template <typename Field>
struct result_field_methods_t: public result_field_methods_base_t<Field>, struct result_field_methods_t : public result_field_methods_base_t<Field>, public alias_operators<Field>
public alias_operators<Field>
{ {
using _base_t = result_field_methods_base_t<Field>; using _base_t = result_field_methods_base_t<Field>;
using _field_spec_t = typename _base_t::_field_spec_t; using _field_spec_t = typename _base_t::_field_spec_t;
@ -84,6 +85,5 @@ namespace sqlpp
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
using _can_be_null = column_spec_can_be_null_t<_field_spec_t>; using _can_be_null = column_spec_can_be_null_t<_field_spec_t>;
}; };
} }
#endif #endif

View File

@ -41,8 +41,7 @@ namespace sqlpp
struct result_row_impl; struct result_row_impl;
template <typename Db, std::size_t index, typename FieldSpec> template <typename Db, std::size_t index, typename FieldSpec>
struct result_field: struct result_field : public member_t<FieldSpec, result_field_t<value_type_of<FieldSpec>, Db, FieldSpec>>
public member_t<FieldSpec, result_field_t<value_type_of<FieldSpec>, Db, FieldSpec>>
{ {
using _field = member_t<FieldSpec, result_field_t<value_type_of<FieldSpec>, Db, FieldSpec>>; using _field = member_t<FieldSpec, result_field_t<value_type_of<FieldSpec>, Db, FieldSpec>>;
@ -66,10 +65,13 @@ namespace sqlpp
}; };
template <std::size_t index, typename AliasProvider, typename Db, typename... FieldSpecs> template <std::size_t index, typename AliasProvider, typename Db, typename... FieldSpecs>
struct result_field<Db, index, multi_field_spec_t<AliasProvider, std::tuple<FieldSpecs...>>>: struct result_field<Db, index, multi_field_spec_t<AliasProvider, std::tuple<FieldSpecs...>>>
public member_t<AliasProvider, result_row_impl<Db, detail::make_field_index_sequence<index, FieldSpecs...>, FieldSpecs...>> : public member_t<AliasProvider,
result_row_impl<Db, detail::make_field_index_sequence<index, FieldSpecs...>, FieldSpecs...>>
{ {
using _multi_field = member_t<AliasProvider, result_row_impl<Db, detail::make_field_index_sequence<index, FieldSpecs...>, FieldSpecs...>>; using _multi_field =
member_t<AliasProvider,
result_row_impl<Db, detail::make_field_index_sequence<index, FieldSpecs...>, FieldSpecs...>>;
result_field() = default; result_field() = default;
@ -91,8 +93,8 @@ namespace sqlpp
}; };
template <typename Db, std::size_t NextIndex, std::size_t... Is, typename... FieldSpecs> template <typename Db, std::size_t NextIndex, std::size_t... Is, typename... FieldSpecs>
struct result_row_impl<Db, detail::field_index_sequence<NextIndex, Is...>, FieldSpecs...>: struct result_row_impl<Db, detail::field_index_sequence<NextIndex, Is...>, FieldSpecs...>
public result_field<Db, Is, FieldSpecs>... : public result_field<Db, Is, FieldSpecs>...
{ {
result_row_impl() = default; result_row_impl() = default;
@ -115,26 +117,23 @@ namespace sqlpp
(void)swallow{(result_field<Db, Is, FieldSpecs>::_bind(target), 0)...}; (void)swallow{(result_field<Db, Is, FieldSpecs>::_bind(target), 0)...};
} }
}; };
} }
template <typename Db, typename... FieldSpecs> template <typename Db, typename... FieldSpecs>
struct result_row_t: public detail::result_row_impl<Db, detail::make_field_index_sequence<0, FieldSpecs...>, FieldSpecs...> struct result_row_t
: public detail::result_row_impl<Db, detail::make_field_index_sequence<0, FieldSpecs...>, FieldSpecs...>
{ {
using _field_index_sequence = detail::make_field_index_sequence<0, FieldSpecs...>; using _field_index_sequence = detail::make_field_index_sequence<0, FieldSpecs...>;
using _impl = detail::result_row_impl<Db, _field_index_sequence, FieldSpecs...>; using _impl = detail::result_row_impl<Db, _field_index_sequence, FieldSpecs...>;
bool _is_valid; bool _is_valid;
result_row_t(): result_row_t() : _impl(), _is_valid(false)
_impl(),
_is_valid(false)
{ {
} }
template <typename DynamicNames> template <typename DynamicNames>
result_row_t(const DynamicNames&): result_row_t(const DynamicNames&)
_impl(), : _impl(), _is_valid(false)
_is_valid(false)
{ {
} }
@ -178,7 +177,8 @@ namespace sqlpp
}; };
template <typename Db, typename... FieldSpecs> template <typename Db, typename... FieldSpecs>
struct dynamic_result_row_t: public detail::result_row_impl<Db, detail::make_field_index_sequence<0, FieldSpecs...>, FieldSpecs...> struct dynamic_result_row_t
: public detail::result_row_impl<Db, detail::make_field_index_sequence<0, FieldSpecs...>, FieldSpecs...>
{ {
using _field_index_sequence = detail::make_field_index_sequence<0, FieldSpecs...>; using _field_index_sequence = detail::make_field_index_sequence<0, FieldSpecs...>;
using _impl = detail::result_row_impl<Db, _field_index_sequence, FieldSpecs...>; using _impl = detail::result_row_impl<Db, _field_index_sequence, FieldSpecs...>;
@ -187,7 +187,9 @@ namespace sqlpp
using _traits = make_traits<text, tag::is_noop, tag::can_be_null, tag::null_is_trivial_value>; using _traits = make_traits<text, tag::is_noop, tag::can_be_null, tag::null_is_trivial_value>;
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
struct _alias_t {}; struct _alias_t
{
};
}; };
using _field_type = result_field_t<text, Db, _field_spec_t>; using _field_type = result_field_t<text, Db, _field_spec_t>;
@ -195,16 +197,12 @@ namespace sqlpp
std::vector<std::string> _dynamic_field_names; std::vector<std::string> _dynamic_field_names;
std::map<std::string, _field_type> _dynamic_fields; std::map<std::string, _field_type> _dynamic_fields;
dynamic_result_row_t(): dynamic_result_row_t() : _impl(), _is_valid(false)
_impl(),
_is_valid(false)
{ {
} }
dynamic_result_row_t(const std::vector<std::string>& dynamic_field_names): dynamic_result_row_t(const std::vector<std::string>& dynamic_field_names)
_impl(), : _impl(), _is_valid(false), _dynamic_field_names(dynamic_field_names)
_is_valid(false),
_dynamic_field_names(dynamic_field_names)
{ {
for (auto field_name : _dynamic_field_names) for (auto field_name : _dynamic_field_names)
{ {
@ -219,7 +217,6 @@ namespace sqlpp
void _validate() void _validate()
{ {
_impl::_validate(); _impl::_validate();
_is_valid = true; _is_valid = true;
for (auto& field : _dynamic_fields) for (auto& field : _dynamic_fields)

View File

@ -111,7 +111,6 @@ namespace sqlpp
return t.is_null(); return t.is_null();
} }
}; };
} }
template <typename Expr, bool TrivialValueIsNull> template <typename Expr, bool TrivialValueIsNull>
@ -120,9 +119,9 @@ namespace sqlpp
using _traits = typename Expr::_traits; using _traits = typename Expr::_traits;
using _nodes = detail::type_vector<Expr>; using _nodes = detail::type_vector<Expr>;
rhs_wrap_t(Expr expr): rhs_wrap_t(Expr expr) : _expr(expr)
_expr(expr) {
{} }
rhs_wrap_t(const rhs_wrap_t&) = default; rhs_wrap_t(const rhs_wrap_t&) = default;
rhs_wrap_t(rhs_wrap_t&&) = default; rhs_wrap_t(rhs_wrap_t&&) = default;
@ -132,8 +131,7 @@ namespace sqlpp
bool _is_null() const bool _is_null() const
{ {
return (TrivialValueIsNull and detail::rhs_is_trivial_t<Expr>::_(_expr)) return (TrivialValueIsNull and detail::rhs_is_trivial_t<Expr>::_(_expr)) or detail::rhs_is_null_t<Expr>::_(_expr);
or detail::rhs_is_null_t<Expr>::_(_expr);
} }
static constexpr bool _is_default() static constexpr bool _is_default()
@ -167,7 +165,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -49,8 +49,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

Some files were not shown because too many files have changed in this diff Show More