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
@ -51,7 +50,7 @@ namespace sqlpp
bool operator==(const bind_result_t& rhs) const; bool operator==(const bind_result_t& rhs) const;
template<typename ResultRow> template <typename ResultRow>
void next(ResultRow& result_row); void next(ResultRow& result_row);
// something similar to this: // something similar to this:
@ -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
@ -42,22 +41,24 @@ namespace sqlpp
// context in order to specialize the behaviour, see also interpreter.h // context in order to specialize the behaviour, see also interpreter.h
struct context_t struct context_t
{ {
template<typename T> template <typename T>
std::ostream& operator<<(T t); std::ostream& operator<<(T t);
std::string escape(std::string arg); std::string escape(std::string arg);
}; };
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
@ -69,58 +70,60 @@ namespace sqlpp
connection& operator=(connection&&) = delete; connection& operator=(connection&&) = delete;
//! "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>
size_t insert(const Insert& i); size_t insert(const Insert& i);
//! prepared insert //! prepared insert
template<typename Insert> template <typename Insert>
_prepared_statement_t prepare_insert(Insert& i); _prepared_statement_t prepare_insert(Insert& i);
template<typename PreparedInsert> template <typename PreparedInsert>
size_t run_prepared_insert(const PreparedInsert& i); // call i._bind_params() size_t run_prepared_insert(const PreparedInsert& i); // call i._bind_params()
//! "direct" update //! "direct" update
template<typename Update> template <typename Update>
size_t update(const Update& u); size_t update(const Update& u);
//! "prepared" update //! "prepared" update
template<typename Update> template <typename Update>
_prepared_statement_t prepare_update(Update& u); _prepared_statement_t prepare_update(Update& u);
template<typename PreparedUpdate> template <typename PreparedUpdate>
size_t run_prepared_update(const PreparedUpdate& u); // call u._bind_params() size_t run_prepared_update(const PreparedUpdate& u); // call u._bind_params()
//! "direct" remove //! "direct" remove
template<typename Remove> template <typename Remove>
size_t remove(const Remove& r) size_t remove(const Remove& r)
//! prepared remove //! prepared remove
template<typename Remove> template <typename Remove>
_prepared_statement_t prepare_remove(Remove& r); _prepared_statement_t prepare_remove(Remove& r);
template<typename PreparedRemove> template <typename PreparedRemove>
size_t run_prepared_remove(const PreparedRemove& r); // call r._bind_params() size_t run_prepared_remove(const PreparedRemove& r); // call r._bind_params()
//! call run on the argument //! call run on the argument
template<typename T> template <typename T>
auto operator() (const T& t) -> decltype(t._run(*this)) auto operator()(const T& t) -> decltype(t._run(*this))
{ {
return t._run(*this); return t._run(*this);
} }
//! call prepare on the argument //! call prepare on the argument
template<typename T> template <typename T>
auto prepare(const T& t) -> decltype(t._prepare(*this)) auto prepare(const T& t) -> decltype(t._prepare(*this))
{ {
return t._prepare(*this); return t._prepare(*this);
@ -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

@ -43,7 +43,7 @@ namespace sqlpp
{ {
namespace vendor namespace vendor
{ {
template<typename ValueType, typename NameType> template <typename ValueType, typename NameType>
struct interpreter_t<database::context_t, parameter_t<ValueType, NameType>> struct interpreter_t<database::context_t, parameter_t<ValueType, NameType>>
{ {
using T = parameter_t<ValueType, NameType>; using T = parameter_t<ValueType, NameType>;
@ -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

@ -36,20 +36,19 @@ int insert(int, char**)
db(insert_into(f).set(f.name = "loves c++", f.fatal = false)); db(insert_into(f).set(f.name = "loves c++", f.fatal = false));
//db(insert_into(f).set(f.nahme = "loves c++", f.fatal = false)); // db(insert_into(f).set(f.nahme = "loves c++", f.fatal = false));
//db(insert_into(f).set(f.name == "loves c++", f.fatal = false)); // db(insert_into(f).set(f.name == "loves c++", f.fatal = false));
//db(insert_into(f).set(f.name = "loves c++", f.fatal = "false")); // db(insert_into(f).set(f.name = "loves c++", f.fatal = "false"));
//db(insert_into(p).set(f.name = "loves c++", f.fatal = false)); // db(insert_into(p).set(f.name = "loves c++", f.fatal = false));
//db(insert_into(f).set(f.name = "loves c++", p.feature = 7)); // db(insert_into(f).set(f.name = "loves c++", p.feature = 7));
//db(insert_into(f).set(f.id = 42, f.name = "loves c++", f.fatal = false)); // db(insert_into(f).set(f.id = 42, f.name = "loves c++", f.fatal = false));
//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());
@ -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**)
{ {
@ -69,20 +71,19 @@ int ppgen(int, char**)
db(insert_into(f).set(f.name = "loves c++", f.fatal = false)); db(insert_into(f).set(f.name = "loves c++", f.fatal = false));
//db(insert_into(f).set(f.nahme = "loves c++", f.fatal = false)); // db(insert_into(f).set(f.nahme = "loves c++", f.fatal = false));
//db(insert_into(f).set(f.name == "loves c++", f.fatal = false)); // db(insert_into(f).set(f.name == "loves c++", f.fatal = false));
//db(insert_into(f).set(f.name = "loves c++", f.fatal = "false")); // db(insert_into(f).set(f.name = "loves c++", f.fatal = "false"));
//db(insert_into(p).set(f.name = "loves c++", f.fatal = false)); // db(insert_into(p).set(f.name = "loves c++", f.fatal = false));
//db(insert_into(f).set(f.name = "loves c++", p.feature = 7)); // db(insert_into(f).set(f.name = "loves c++", p.feature = 7));
//db(insert_into(f).set(f.id = 42, f.name = "loves c++", f.fatal = false)); // db(insert_into(f).set(f.id = 42, f.name = "loves c++", f.fatal = false));
//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());
@ -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

@ -32,7 +32,7 @@ int update(int, char**)
MockDb db; MockDb db;
test::TabPerson p; test::TabPerson p;
//test::TabFeature q; // test::TabFeature q;
db(update(p).set(p.feature = 7).where(p.id == 23)); db(update(p).set(p.feature = 7).where(p.id == 23));
return 0; return 0;

View File

@ -32,7 +32,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Expression, typename AliasProvider> template <typename Expression, typename AliasProvider>
struct expression_alias_t struct expression_alias_t
{ {
using _traits = make_traits<value_type_of<Expression>, tag::is_selectable, tag::is_alias>; using _traits = make_traits<value_type_of<Expression>, tag::is_selectable, tag::is_alias>;
@ -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;
@ -56,7 +56,7 @@ namespace sqlpp
Expression _expression; Expression _expression;
}; };
template<typename Context, typename Expression, typename AliasProvider> template <typename Context, typename Expression, typename AliasProvider>
struct serializer_t<Context, expression_alias_t<Expression, AliasProvider>> struct serializer_t<Context, expression_alias_t<Expression, AliasProvider>>
{ {
using _serialize_check = serialize_check_of<Context, Expression>; using _serialize_check = serialize_check_of<Context, Expression>;
@ -70,7 +70,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -31,33 +31,41 @@
#include <sqlpp11/char_sequence.h> #include <sqlpp11/char_sequence.h>
#define SQLPP_ALIAS_PROVIDER(name) \ #define SQLPP_ALIAS_PROVIDER(name) \
struct name##_t\ struct name##_t \
{\ { \
struct _alias_t\ struct _alias_t \
{\ { \
static constexpr const char _literal[] = #name;\ static constexpr const char _literal[] = #name; \
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 name;\ T name; \
T& operator()() { return name; }\ T& operator()() \
const T& operator()() const { return name; }\ { \
};\ return name; \
};\ } \
};\ const T& operator()() const \
constexpr name##_t name = {}; { \
return name; \
} \
}; \
}; \
}; \
constexpr name##_t name = {};
namespace sqlpp namespace sqlpp
{ {
template<typename T, typename Enable = void> template <typename T, typename Enable = void>
struct is_alias_provider_t struct is_alias_provider_t
{ {
static constexpr bool value = false; static constexpr bool value = false;
}; };
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

@ -33,19 +33,19 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Table> template <typename Table>
struct all_of_t struct all_of_t
{ {
using _column_tuple_t = typename Table::_column_tuple_t; using _column_tuple_t = typename Table::_column_tuple_t;
template<typename AliasProvider> template <typename AliasProvider>
detail::copy_tuple_args_t<multi_column_alias_t, AliasProvider, _column_tuple_t> as(const AliasProvider& alias) detail::copy_tuple_args_t<multi_column_alias_t, AliasProvider, _column_tuple_t> as(const AliasProvider& alias)
{ {
return multi_column(_column_tuple_t{}).as(alias); return multi_column(_column_tuple_t{}).as(alias);
} }
}; };
template<typename Table> template <typename Table>
auto all_of(Table) -> all_of_t<Table> auto all_of(Table) -> all_of_t<Table>
{ {
return {}; return {};
@ -55,14 +55,14 @@ namespace sqlpp
{ {
using type = std::false_type; using type = std::false_type;
template<typename T = void> template <typename T = void>
static void _() static void _()
{ {
static_assert(wrong_t<T>::value, "all_of(table) seems to be used outside of select"); static_assert(wrong_t<T>::value, "all_of(table) seems to be used outside of select");
} }
}; };
template<typename Context, typename Table> template <typename Context, typename Table>
struct serializer_t<Context, all_of_t<Table>> struct serializer_t<Context, all_of_t<Table>>
{ {
using _serialize_check = assert_no_stand_alone_all_of_t; using _serialize_check = assert_no_stand_alone_all_of_t;
@ -73,8 +73,6 @@ namespace sqlpp
_serialize_check::_(); _serialize_check::_();
} }
}; };
} }
#endif #endif

View File

@ -33,15 +33,15 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Select> template <typename Select>
struct any_t struct any_t
{ {
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;
@ -52,7 +52,7 @@ namespace sqlpp
Select _select; Select _select;
}; };
template<typename Context, typename Select> template <typename Context, typename Select>
struct serializer_t<Context, any_t<Select>> struct serializer_t<Context, any_t<Select>>
{ {
using _serialize_check = serialize_check_of<Context, Select>; using _serialize_check = serialize_check_of<Context, Select>;
@ -67,15 +67,15 @@ namespace sqlpp
} }
}; };
template<typename T> template <typename T>
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

@ -37,7 +37,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
struct assignment_t struct assignment_t
{ {
using _traits = make_traits<no_value_t, tag::is_assignment>; using _traits = make_traits<no_value_t, tag::is_assignment>;
@ -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;
@ -62,7 +63,7 @@ namespace sqlpp
_rhs_t _rhs; _rhs_t _rhs;
}; };
template<typename Context, typename Lhs, typename Rhs> template <typename Context, typename Lhs, typename Rhs>
struct serializer_t<Context, assignment_t<Lhs, Rhs>> struct serializer_t<Context, assignment_t<Lhs, Rhs>>
{ {
using T = assignment_t<Lhs, Rhs>; using T = assignment_t<Lhs, Rhs>;
@ -76,7 +77,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -31,13 +31,13 @@
namespace sqlpp namespace sqlpp
{ {
template<typename T, typename Enable = void> template <typename T, typename Enable = void>
struct has_auto_alias_t struct has_auto_alias_t
{ {
static constexpr bool value = false; static constexpr bool value = false;
}; };
template<typename T> template <typename T>
struct has_auto_alias_t<T, typename std::enable_if<not wrong_t<typename T::_auto_alias_t>::value>::type> struct has_auto_alias_t<T, typename std::enable_if<not wrong_t<typename T::_auto_alias_t>::value>::type>
{ {
static constexpr bool value = true; static constexpr bool value = true;
@ -45,22 +45,21 @@ namespace sqlpp
namespace detail namespace detail
{ {
template<typename T, typename Enable = void> template <typename T, typename Enable = void>
struct auto_alias_impl struct auto_alias_impl
{ {
using type = T; using type = T;
}; };
template<typename T> template <typename T>
struct auto_alias_impl<T, typename std::enable_if<has_auto_alias_t<T>::value>::type> struct auto_alias_impl<T, typename std::enable_if<has_auto_alias_t<T>::value>::type>
{ {
using type = expression_alias_t<T, typename T::_auto_alias_t>; using type = expression_alias_t<T, typename T::_auto_alias_t>;
}; };
} }
template<typename T> template <typename T>
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

@ -38,32 +38,38 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "avg_"; static constexpr const char _literal[] = "avg_";
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 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;
@ -74,7 +80,7 @@ namespace sqlpp
Expr _expr; Expr _expr;
}; };
template<typename Context, typename Flag, typename Expr> template <typename Context, typename Flag, typename Expr>
struct serializer_t<Context, avg_t<Flag, Expr>> struct serializer_t<Context, avg_t<Flag, Expr>>
{ {
using _serialize_check = serialize_check_of<Context, Flag, Expr>; using _serialize_check = serialize_check_of<Context, Flag, Expr>;
@ -98,22 +104,23 @@ 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};
} }
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

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

View File

@ -39,118 +39,121 @@
namespace sqlpp namespace sqlpp
{ {
// basic operators // basic operators
template<typename Expr, typename ValueType> template <typename Expr, typename ValueType>
struct basic_expression_operators struct basic_expression_operators
{ {
template<typename T> template <typename T>
struct _is_valid_comparison_operand struct _is_valid_comparison_operand
{ {
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
; ;
}; };
template<typename T> template <typename T>
equal_to_t<Expr, wrap_operand_t<T>> operator==(T t) const equal_to_t<Expr, wrap_operand_t<T>> operator==(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
return { *static_cast<const Expr*>(this), {rhs{t}} }; return {*static_cast<const Expr*>(this), {rhs{t}}};
} }
template<typename T> template <typename T>
not_equal_to_t<Expr, wrap_operand_t<T>> operator!=(T t) const not_equal_to_t<Expr, wrap_operand_t<T>> operator!=(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
return { *static_cast<const Expr*>(this), {rhs{t}} }; return {*static_cast<const Expr*>(this), {rhs{t}}};
} }
template<typename T> template <typename T>
less_than_t<Expr, wrap_operand_t<T>> operator<(T t) const less_than_t<Expr, wrap_operand_t<T>> operator<(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
return { *static_cast<const Expr*>(this), rhs{t} }; return {*static_cast<const Expr*>(this), rhs{t}};
} }
template<typename T> template <typename T>
less_equal_t<Expr, wrap_operand_t<T>> operator<=(T t) const less_equal_t<Expr, wrap_operand_t<T>> operator<=(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
return { *static_cast<const Expr*>(this), rhs{t} }; return {*static_cast<const Expr*>(this), rhs{t}};
} }
template<typename T> template <typename T>
greater_than_t<Expr, wrap_operand_t<T>> operator>(T t) const greater_than_t<Expr, wrap_operand_t<T>> operator>(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
return { *static_cast<const Expr*>(this), rhs{t} }; return {*static_cast<const Expr*>(this), rhs{t}};
} }
template<typename T> template <typename T>
greater_equal_t<Expr, wrap_operand_t<T>> operator>=(T t) const greater_equal_t<Expr, wrap_operand_t<T>> operator>=(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
return { *static_cast<const Expr*>(this), rhs{t} }; return {*static_cast<const Expr*>(this), rhs{t}};
} }
is_null_t<Expr> is_null() const is_null_t<Expr> is_null() const
{ {
return { *static_cast<const Expr*>(this) }; return {*static_cast<const Expr*>(this)};
} }
is_not_null_t<Expr> is_not_null() const is_not_null_t<Expr> is_not_null() const
{ {
return { *static_cast<const Expr*>(this) }; return {*static_cast<const Expr*>(this)};
} }
sort_order_t<Expr, sort_type::asc> asc() const sort_order_t<Expr, sort_type::asc> asc() const
{ {
return { *static_cast<const Expr*>(this) }; return {*static_cast<const Expr*>(this)};
} }
sort_order_t<Expr, sort_type::desc> desc() const sort_order_t<Expr, sort_type::desc> desc() const
{ {
return { *static_cast<const Expr*>(this) }; return {*static_cast<const Expr*>(this)};
} }
// Hint: use value_list wrapper for containers... // Hint: use value_list wrapper for containers...
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,
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... }; "at least one operand of in() is not valid");
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,
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... }; "at least one operand of in() is not valid");
return {*static_cast<const Expr*>(this), wrap_operand_t<T>{t}...};
} }
}; };
template<typename Expr> template <typename Expr>
struct alias_operators struct alias_operators
{ {
template<typename alias_provider> template <typename alias_provider>
expression_alias_t<Expr, alias_provider> as(const alias_provider&) const expression_alias_t<Expr, alias_provider> as(const alias_provider&) const
{ {
return { *static_cast<const Expr*>(this) }; return {*static_cast<const Expr*>(this)};
} }
}; };
} }
#endif #endif

View File

@ -44,26 +44,24 @@ namespace sqlpp
using _tag = tag::is_boolean; using _tag = tag::is_boolean;
using _cpp_value_type = bool; using _cpp_value_type = bool;
template<typename T> template <typename T>
using _is_valid_operand = is_boolean_t<T>; using _is_valid_operand = is_boolean_t<T>;
}; };
// boolean parameter type // boolean parameter type
template<> template <>
struct parameter_value_t<boolean> struct parameter_value_t<boolean>
{ {
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,9 +102,12 @@ 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
{ {
target._bind_boolean_parameter(index, &_value, _is_null); target._bind_boolean_parameter(index, &_value, _is_null);
@ -118,54 +119,52 @@ namespace sqlpp
}; };
// boolean expression operators // boolean expression operators
template<typename Base> template <typename Base>
struct expression_operators<Base, boolean>: public basic_expression_operators<Base, boolean> struct expression_operators<Base, boolean> : public basic_expression_operators<Base, boolean>
{ {
template<typename T> template <typename T>
using _is_valid_operand = is_valid_operand<boolean, T>; using _is_valid_operand = is_valid_operand<boolean, T>;
template<typename T> template <typename T>
logical_and_t<Base, wrap_operand_t<T>> operator and(T t) const logical_and_t<Base, wrap_operand_t<T>> operator and(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), rhs{t} }; return {*static_cast<const Base*>(this), rhs{t}};
} }
template<typename T> template <typename T>
logical_or_t<Base, wrap_operand_t<T>> operator or(T t) const logical_or_t<Base, wrap_operand_t<T>> operator or(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), rhs{t} }; return {*static_cast<const Base*>(this), rhs{t}};
} }
logical_not_t<Base> operator not() const logical_not_t<Base> operator not() const
{ {
return { *static_cast<const Base*>(this) }; return {*static_cast<const Base*>(this)};
} }
}; };
// boolean column operators // boolean column operators
template<typename Base> template <typename Base>
struct column_operators<Base, boolean> struct column_operators<Base, boolean>
{ {
}; };
// boolean result field // boolean result field
template<typename Db, typename FieldSpec> template <typename Db, typename FieldSpec>
struct result_field_t<boolean, Db, FieldSpec>: public result_field_methods_t<result_field_t<boolean, Db, FieldSpec>> struct result_field_t<boolean, Db, FieldSpec> : public result_field_methods_t<result_field_t<boolean, Db, FieldSpec>>
{ {
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()
{ {
@ -213,7 +212,7 @@ namespace sqlpp
return _value; return _value;
} }
template<typename Target> template <typename Target>
void _bind(Target& target, size_t i) void _bind(Target& target, size_t i)
{ {
target._bind_boolean_result(i, &_value, &_is_null); target._bind_boolean_result(i, &_value, &_is_null);
@ -225,11 +224,10 @@ namespace sqlpp
signed char _value; signed char _value;
}; };
template<typename Db, typename FieldSpec> template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<boolean, Db, FieldSpec>& e) inline std::ostream& operator<<(std::ostream& os, const result_field_t<boolean, Db, FieldSpec>& e)
{ {
return serialize(e, os); return serialize(e, os);
} }
} }
#endif #endif

View File

@ -32,15 +32,15 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Database> template <typename Database>
struct boolean_expression_t: public expression_operators<boolean_expression_t<Database>, boolean> struct boolean_expression_t : public expression_operators<boolean_expression_t<Database>, boolean>
{ {
using _traits = make_traits<boolean, tag::is_expression>; using _traits = make_traits<boolean, tag::is_expression>;
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");
@ -55,20 +55,20 @@ namespace sqlpp
interpretable_t<Database> _expr; interpretable_t<Database> _expr;
}; };
template<typename Database, typename T> template <typename Database, typename T>
boolean_expression_t<Database> boolean_expression(T t) boolean_expression_t<Database> boolean_expression(T t)
{ {
using Expr = wrap_operand_t<T>; using Expr = wrap_operand_t<T>;
return {Expr{t}}; return {Expr{t}};
} }
template<typename Database, typename T> template <typename Database, typename T>
boolean_expression_t<Database> boolean_expression(const Database&, T t) boolean_expression_t<Database> boolean_expression(const Database&, T t)
{ {
return boolean_expression<Database>(t); return boolean_expression<Database>(t);
} }
template<typename Context, typename Database> template <typename Context, typename Database>
struct serializer_t<Context, boolean_expression_t<Database>> struct serializer_t<Context, boolean_expression_t<Database>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -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()
{ {
@ -40,17 +41,18 @@ namespace sqlpp
}; };
}; };
template<std::size_t N, const char (&s) [N], typename T> template <std::size_t N, const char(&s)[N], typename T>
struct make_char_sequence_impl; struct make_char_sequence_impl;
template<std::size_t N, const char (&s) [N], std::size_t... i> template <std::size_t N, const char(&s)[N], std::size_t... i>
struct make_char_sequence_impl<N, s, sqlpp::detail::index_sequence<i...>> struct make_char_sequence_impl<N, s, sqlpp::detail::index_sequence<i...>>
{ {
using type = char_sequence<s[i]...>; using type = char_sequence<s[i]...>;
}; };
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

@ -41,15 +41,15 @@
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<>;
@ -60,7 +60,7 @@ namespace sqlpp
using _table = Table; using _table = Table;
using _alias_t = typename _spec_t::_alias_t; using _alias_t = typename _spec_t::_alias_t;
template<typename T> template <typename T>
using _is_valid_operand = is_valid_operand<value_type_of<ColumnSpec>, T>; using _is_valid_operand = is_valid_operand<value_type_of<ColumnSpec>, T>;
column_t() = default; column_t() = default;
@ -70,43 +70,41 @@ namespace sqlpp
column_t& operator=(column_t&&) = default; column_t& operator=(column_t&&) = default;
~column_t() = default; ~column_t() = default;
template<typename T = _table> template <typename T = _table>
auto table() const -> _table auto table() const -> _table
{ {
static_assert(is_table_t<T>::value, "cannot call get_table for columns of a sub-selects or cte"); static_assert(is_table_t<T>::value, "cannot call get_table for columns of a sub-selects or cte");
return _table{}; return _table{};
} }
template<typename alias_provider> template <typename alias_provider>
expression_alias_t<column_t, alias_provider> as(const alias_provider&) const expression_alias_t<column_t, alias_provider> as(const alias_provider&) const
{ {
return { *this }; return {*this};
} }
template<typename T> template <typename T>
auto operator =(T t) const -> assignment_t<column_t, wrap_operand_t<T>> auto operator=(T t) const -> assignment_t<column_t, wrap_operand_t<T>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
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{}};
} }
}; };
template<typename Context, typename... Args> template <typename Context, typename... Args>
struct serializer_t<Context, column_t<Args...>> struct serializer_t<Context, column_t<Args...>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -118,7 +116,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -24,13 +24,12 @@
* 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
namespace sqlpp namespace sqlpp
{ {
template<typename Table, typename ColumnSpec> template <typename Table, typename ColumnSpec>
struct column_t; struct column_t;
} }

View File

@ -43,7 +43,7 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "concat_"; static constexpr const char _literal[] = "concat_";
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 concat; T concat;
@ -51,19 +51,17 @@ 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;
@ -74,7 +72,7 @@ namespace sqlpp
std::tuple<Args...> _args; std::tuple<Args...> _args;
}; };
template<typename Context, typename... Args> template <typename Context, typename... Args>
struct serializer_t<Context, concat_t<Args...>> struct serializer_t<Context, concat_t<Args...>>
{ {
using _serialize_check = serialize_check_of<Context, Args...>; using _serialize_check = serialize_check_of<Context, Args...>;
@ -89,12 +87,12 @@ 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

@ -39,33 +39,39 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "count_"; static constexpr const char _literal[] = "count_";
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 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*/>;
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;
@ -76,7 +82,7 @@ namespace sqlpp
Expr _expr; Expr _expr;
}; };
template<typename Context, typename Flag, typename Expr> template <typename Context, typename Flag, typename Expr>
struct serializer_t<Context, count_t<Flag, Expr>> struct serializer_t<Context, count_t<Flag, Expr>>
{ {
using _serialize_check = serialize_check_of<Context, Flag, Expr>; using _serialize_check = serialize_check_of<Context, Flag, Expr>;
@ -100,22 +106,23 @@ 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};
} }
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

@ -40,17 +40,16 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Flag, typename Lhs, typename Rhs> template <typename Flag, typename Lhs, typename Rhs>
struct cte_union_t struct cte_union_t
{ {
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
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;
@ -63,7 +62,7 @@ namespace sqlpp
}; };
// Interpreters // Interpreters
template<typename Context, typename Flag, typename Lhs, typename Rhs> template <typename Context, typename Flag, typename Lhs, typename Rhs>
struct serializer_t<Context, cte_union_t<Flag, Lhs, Rhs>> struct serializer_t<Context, cte_union_t<Flag, Lhs, Rhs>>
{ {
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>; using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
@ -80,26 +79,25 @@ namespace sqlpp
} }
}; };
template<typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct cte_t; struct cte_t;
template<typename AliasProvider> template <typename AliasProvider>
struct cte_ref_t; struct cte_ref_t;
template<typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
auto from_table(cte_t<AliasProvider, Statement, FieldSpecs...>) -> cte_ref_t<AliasProvider> auto from_table(cte_t<AliasProvider, Statement, FieldSpecs...>) -> cte_ref_t<AliasProvider>
{ {
return cte_ref_t<AliasProvider>{}; return cte_ref_t<AliasProvider>{};
} }
template<typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct from_table_impl<cte_t<AliasProvider, Statement, FieldSpecs...>> struct from_table_impl<cte_t<AliasProvider, Statement, FieldSpecs...>>
{ {
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
{ {
using _alias_t = typename FieldSpec::_alias_t; using _alias_t = typename FieldSpec::_alias_t;
@ -107,27 +105,27 @@ 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>
struct make_cte_impl struct make_cte_impl
{ {
using type = void; using type = void;
}; };
template<typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct make_cte_impl<AliasProvider, Statement, result_row_t<void, FieldSpecs...>> struct make_cte_impl<AliasProvider, Statement, result_row_t<void, FieldSpecs...>>
{ {
using type = cte_t<AliasProvider, Statement, FieldSpecs...>; using type = cte_t<AliasProvider, Statement, FieldSpecs...>;
}; };
template<typename AliasProvider, typename Statement> template <typename AliasProvider, typename Statement>
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<>;
@ -139,43 +137,48 @@ namespace sqlpp
using _column_tuple_t = std::tuple<column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>...>; using _column_tuple_t = std::tuple<column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>...>;
template<typename... T> template <typename... T>
using _check = logic::all_t<is_statement_t<T>::value...>; using _check = logic::all_t<is_statement_t<T>::value...>;
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
-> cte_t<AliasProvider, cte_union_t<Flag, Statement, Rhs>, FieldSpecs...> -> cte_t<AliasProvider, cte_union_t<Flag, Statement, Rhs>, FieldSpecs...>
{ {
@ -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;
@ -194,7 +198,7 @@ namespace sqlpp
Statement _statement; Statement _statement;
}; };
template<typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs> template <typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs>
struct serializer_t<Context, cte_t<AliasProvider, Statement, ColumnSpecs...>> struct serializer_t<Context, cte_t<AliasProvider, Statement, ColumnSpecs...>>
{ {
using _serialize_check = serialize_check_of<Context, Statement>; using _serialize_check = serialize_check_of<Context, Statement>;
@ -209,12 +213,11 @@ 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) // The result row of the select should not have dynamic parts
// The result row of the select should not have dynamic parts template <typename AliasProvider>
template<typename AliasProvider>
struct cte_ref_t struct cte_ref_t
{ {
using _traits = make_traits<no_value_t, tag::is_alias, tag::is_cte, tag::is_table>; // FIXME: is table? really? using _traits = make_traits<no_value_t, tag::is_alias, tag::is_cte, tag::is_table>; // FIXME: is table? really?
@ -224,19 +227,22 @@ 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};
} }
}; };
template<typename Context, typename AliasProvider> template <typename Context, typename AliasProvider>
struct serializer_t<Context, cte_ref_t<AliasProvider>> struct serializer_t<Context, cte_ref_t<AliasProvider>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -249,13 +255,11 @@ 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

@ -34,12 +34,12 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Database, typename... Parts> template <typename Database, typename... Parts>
struct custom_query_t; struct custom_query_t;
namespace detail namespace detail
{ {
template<typename Db, typename... Parts> template <typename Db, typename... Parts>
struct custom_parts_t struct custom_parts_t
{ {
using _custom_query_t = custom_query_t<Db, Parts...>; using _custom_query_t = custom_query_t<Db, Parts...>;
@ -48,27 +48,27 @@ 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;
@ -76,14 +76,14 @@ namespace sqlpp
custom_query_t& operator=(custom_query_t&&) = default; custom_query_t& operator=(custom_query_t&&) = default;
~custom_query_t() = default; ~custom_query_t() = default;
template<typename Db> template <typename Db>
auto _run(Db& db) const -> decltype(std::declval<_methods_t>()._run(db, *this)) auto _run(Db& db) const -> decltype(std::declval<_methods_t>()._run(db, *this))
{ {
_run_check::_(); _run_check::_();
return _methods_t::_run(db, *this); return _methods_t::_run(db, *this);
} }
template<typename Db> template <typename Db>
auto _prepare(Db& db) const -> decltype(std::declval<_methods_t>()._prepare(db, *this)) auto _prepare(Db& db) const -> decltype(std::declval<_methods_t>()._prepare(db, *this))
{ {
_prepare_check::_(); _prepare_check::_();
@ -100,9 +100,8 @@ namespace sqlpp
return _get_static_no_of_parameters(); return _get_static_no_of_parameters();
} }
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)};
} }
@ -110,7 +109,7 @@ namespace sqlpp
std::tuple<Parts...> _parts; std::tuple<Parts...> _parts;
}; };
template<typename Context, typename Database, typename... Parts> template <typename Context, typename Database, typename... Parts>
struct serializer_t<Context, custom_query_t<Database, Parts...>> struct serializer_t<Context, custom_query_t<Database, Parts...>>
{ {
using _serialize_check = serialize_check_of<Context, Parts...>; using _serialize_check = serialize_check_of<Context, Parts...>;
@ -123,17 +122,15 @@ 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,10 +36,13 @@ 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>
struct serializer_t<Context, default_value_t> struct serializer_t<Context, default_value_t>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -53,7 +56,6 @@ namespace sqlpp
}; };
constexpr default_value_t default_value = {}; constexpr default_value_t default_value = {};
} }
#endif #endif

View File

@ -32,52 +32,59 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Table> template <typename Table>
struct all_of_t; struct all_of_t;
namespace detail namespace detail
{ {
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>
struct copy_tuple_args_impl struct copy_tuple_args_impl
{ {
static_assert(wrong_t<copy_tuple_args_impl>::value, "copy_tuple_args must be called with a tuple"); static_assert(wrong_t<copy_tuple_args_impl>::value, "copy_tuple_args must be called with a tuple");
}; };
template<template<typename First, typename...> class Target, typename First, typename... Args> template <template <typename First, typename...> class Target, typename First, typename... Args>
struct copy_tuple_args_impl<Target, First, std::tuple<Args...>> struct copy_tuple_args_impl<Target, First, std::tuple<Args...>>
{ {
using type = Target<First, Args...>; using type = Target<First, Args...>;
}; };
template<template<typename First, typename...> class Target, typename First, typename T> template <template <typename First, typename...> class Target, typename First, typename T>
using copy_tuple_args_t = typename copy_tuple_args_impl<Target, First, T>::type; using copy_tuple_args_t = typename copy_tuple_args_impl<Target, First, T>::type;
template<typename... Columns> template <typename... Columns>
auto column_tuple_merge(Columns... columns) -> decltype(std::tuple_cat(as_column_tuple<Columns>::_(columns)...)) auto column_tuple_merge(Columns... columns) -> decltype(std::tuple_cat(as_column_tuple<Columns>::_(columns)...))
{ {
return std::tuple_cat(as_column_tuple<Columns>::_(columns)...); return std::tuple_cat(as_column_tuple<Columns>::_(columns)...);
} }
} }
} }
#endif #endif

View File

@ -34,41 +34,53 @@ namespace sqlpp
{ {
namespace detail namespace detail
{ {
template<std::size_t NextIndex, std::size_t... Ints> template <std::size_t NextIndex, std::size_t... Ints>
struct field_index_sequence struct field_index_sequence
{ {
static constexpr std::size_t _next_index = NextIndex; static constexpr std::size_t _next_index = NextIndex;
}; };
template<typename T, typename... Fields> template <typename T, typename... Fields>
struct make_field_index_sequence_impl struct make_field_index_sequence_impl
{ {
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>
struct make_field_index_sequence_impl<field_index_sequence<NextIndex, Ints...>> struct make_field_index_sequence_impl<field_index_sequence<NextIndex, Ints...>>
{ {
using type = field_index_sequence<NextIndex, Ints...>; using type = field_index_sequence<NextIndex, Ints...>;
}; };
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

@ -33,28 +33,25 @@ namespace sqlpp
{ {
namespace detail namespace detail
{ {
template<template<typename> class Predicate, typename Default, typename... T> template <template <typename> class Predicate, typename Default, typename... T>
struct get_first_if_impl; struct get_first_if_impl;
template<template<typename> class Predicate, typename Default> template <template <typename> class Predicate, typename Default>
struct get_first_if_impl<Predicate, Default> struct get_first_if_impl<Predicate, Default>
{ {
using type = Default; using type = Default;
}; };
template<template<typename> class Predicate, typename Default, typename T, typename... Rest> template <template <typename> class Predicate, typename Default, typename T, typename... Rest>
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>
using get_first_if = typename get_first_if_impl<Predicate, Default, T...>::type; using get_first_if = typename get_first_if_impl<Predicate, Default, T...>::type;
} }
} }
#endif #endif

View File

@ -33,28 +33,25 @@ namespace sqlpp
{ {
namespace detail namespace detail
{ {
template<template<typename> class Predicate, typename Default, typename... T> template <template <typename> class Predicate, typename Default, typename... T>
struct get_last_if_impl; struct get_last_if_impl;
template<template<typename> class Predicate, typename Default> template <template <typename> class Predicate, typename Default>
struct get_last_if_impl<Predicate, Default> struct get_last_if_impl<Predicate, Default>
{ {
using type = Default; using type = Default;
}; };
template<template<typename> class Predicate, typename Default, typename T, typename... Rest> template <template <typename> class Predicate, typename Default, typename T, typename... Rest>
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>
using get_last_if = typename get_last_if_impl<Predicate, Default, T...>::type; using get_last_if = typename get_last_if_impl<Predicate, Default, T...>::type;
} }
} }
#endif #endif

View File

@ -35,30 +35,29 @@ namespace sqlpp
{ {
// Note: This is a minimalistic implementation of index_sequence available in C++14 // Note: This is a minimalistic implementation of index_sequence available in C++14
// 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;
template<std::size_t N, std::size_t... Ints> template <std::size_t N, std::size_t... Ints>
struct make_index_sequence_impl<index_sequence<Ints...>, N> struct make_index_sequence_impl<index_sequence<Ints...>, N>
{ {
using type = typename make_index_sequence_impl<index_sequence<Ints..., sizeof...(Ints)>, N - 1>::type; using type = typename make_index_sequence_impl<index_sequence<Ints..., sizeof...(Ints)>, N - 1>::type;
}; };
template<std::size_t... Ints> template <std::size_t... Ints>
struct make_index_sequence_impl<index_sequence<Ints...>, 0> struct make_index_sequence_impl<index_sequence<Ints...>, 0>
{ {
using type = index_sequence<Ints...>; using type = index_sequence<Ints...>;
}; };
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

@ -33,20 +33,20 @@ namespace sqlpp
{ {
namespace detail namespace detail
{ {
template<typename Target, typename Statement, typename Term> template <typename Target, typename Statement, typename Term>
typename Target::_data_t pick_arg_impl(Statement /* statement */, Term term, const std::true_type&) typename Target::_data_t pick_arg_impl(Statement /* statement */, Term term, const std::true_type&)
{ {
return term; return term;
} }
template<typename Target, typename Statement, typename Term> template <typename Target, typename Statement, typename Term>
typename Target::_data_t pick_arg_impl(Statement statement, Term /* term */, const std::false_type&) typename Target::_data_t pick_arg_impl(Statement statement, Term /* term */, const std::false_type&)
{ {
return Target::_get_member(statement)._data; return Target::_get_member(statement)._data;
} }
// Returns a statement's term either by picking the term from the statement or using the new term // Returns a statement's term either by picking the term from the statement or using the new term
template<typename Target, typename Statement, typename Term> template <typename Target, typename Statement, typename Term>
typename Target::_data_t pick_arg(Statement statement, Term term) typename Target::_data_t pick_arg(Statement statement, Term term)
{ {
return pick_arg_impl<Target>(statement, term, std::is_same<typename Target::_data_t, Term>()); return pick_arg_impl<Target>(statement, term, std::is_same<typename Target::_data_t, Term>());
@ -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)
@ -50,7 +49,7 @@ namespace sqlpp
return 0; return 0;
} }
template<typename Arg, typename... Rest> template <typename Arg, typename... Rest>
constexpr std::size_t sum(Arg arg, Rest... rest) constexpr std::size_t sum(Arg arg, Rest... rest)
{ {
return arg + sum(rest...); return arg + sum(rest...);
@ -59,4 +58,3 @@ namespace sqlpp
} }
#endif #endif

View File

@ -36,33 +36,33 @@ namespace sqlpp
namespace detail namespace detail
{ {
// some forward declarations and helpers // some forward declarations and helpers
template<typename... T> template <typename... T>
struct make_type_set; struct make_type_set;
template<typename... T> template <typename... T>
using make_type_set_t = typename make_type_set<T...>::type; using make_type_set_t = typename make_type_set<T...>::type;
template<typename E, typename SET> template <typename E, typename SET>
struct is_element_of; struct is_element_of;
// A type set // A type set
template<typename... Elements> template <typename... Elements>
struct type_set struct type_set
{ {
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>
struct insert_if struct insert_if
{ {
using type = typename std::conditional<Predicate<T>::value and not is_element_of<T, type_set>::value, using type = typename std::conditional<Predicate<T>::value and not is_element_of<T, type_set>::value,
@ -71,121 +71,122 @@ namespace sqlpp
}; };
}; };
template <typename E, typename SET>
template<typename E, typename SET>
struct is_element_of struct is_element_of
{ {
static_assert(wrong_t<is_element_of>::value, "SET has to be a type set"); static_assert(wrong_t<is_element_of>::value, "SET has to be a type set");
}; };
template<typename E, typename... Elements> template <typename E, typename... Elements>
struct is_element_of<E, type_set<Elements...>> struct is_element_of<E, type_set<Elements...>>
{ {
static constexpr bool value = ::sqlpp::logic::any_t<std::is_same<E, Elements>::value...>::value; static constexpr bool value = ::sqlpp::logic::any_t<std::is_same<E, Elements>::value...>::value;
}; };
template<typename L, typename R> template <typename L, typename R>
struct joined_set struct joined_set
{ {
static_assert(wrong_t<joined_set>::value, "L and R have to be type sets"); static_assert(wrong_t<joined_set>::value, "L and R have to be type sets");
}; };
template<typename... LElements, typename... RElements> template <typename... LElements, typename... RElements>
struct joined_set<type_set<LElements...>, type_set<RElements...>> struct joined_set<type_set<LElements...>, type_set<RElements...>>
{ {
using type = make_type_set_t<LElements..., RElements...>; using type = make_type_set_t<LElements..., RElements...>;
}; };
template<typename L, typename R> template <typename L, typename R>
using joined_set_t = typename joined_set<L, R>::type; using joined_set_t = typename joined_set<L, R>::type;
template<typename L, typename R> template <typename L, typename R>
struct is_superset_of struct is_superset_of
{ {
static_assert(wrong_t<is_superset_of>::value, "L and R have to be type sets"); static_assert(wrong_t<is_superset_of>::value, "L and R have to be type sets");
}; };
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>
struct is_subset_of struct is_subset_of
{ {
static constexpr bool value = is_superset_of<R, L>::value; static constexpr bool value = is_superset_of<R, L>::value;
}; };
template<typename L, typename R> template <typename L, typename R>
struct is_disjunct_from struct is_disjunct_from
{ {
static_assert(wrong_t<is_disjunct_from>::value, "invalid argument for is_disjunct_from"); static_assert(wrong_t<is_disjunct_from>::value, "invalid argument for is_disjunct_from");
}; };
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 <>
struct make_type_set<> struct make_type_set<>
{ {
using type = type_set<>; using type = type_set<>;
}; };
template<typename T, typename... Rest> template <typename T, typename... Rest>
struct make_type_set<T, Rest...> struct make_type_set<T, Rest...>
{ {
using type = typename make_type_set<Rest...>::type::template insert<T>::type; using type = typename make_type_set<Rest...>::type::template insert<T>::type;
}; };
template<template<typename> class Predicate, typename... T> template <template <typename> class Predicate, typename... T>
struct make_type_set_if; struct make_type_set_if;
template<template<typename> class Predicate> template <template <typename> class Predicate>
struct make_type_set_if<Predicate> struct make_type_set_if<Predicate>
{ {
using type = type_set<>; using type = type_set<>;
}; };
template<template<typename> class Predicate, typename T, typename... Rest> template <template <typename> class Predicate, typename T, typename... Rest>
struct make_type_set_if<Predicate, T, Rest...> struct make_type_set_if<Predicate, T, Rest...>
{ {
using type = typename make_type_set_if<Predicate, Rest...>::type::template insert_if<Predicate, T>::type; using type = typename make_type_set_if<Predicate, Rest...>::type::template insert_if<Predicate, T>::type;
}; };
template<template<typename> class Predicate, typename... T> template <template <typename> class Predicate, typename... T>
using make_type_set_if_t = typename make_type_set_if<Predicate, T...>::type; using make_type_set_if_t = typename make_type_set_if<Predicate, T...>::type;
template<template<typename> class Predicate, typename... T> template <template <typename> class Predicate, typename... T>
struct make_type_set_if_not struct make_type_set_if_not
{ {
template<typename X> template <typename X>
using InversePredicate = std::integral_constant<bool, not Predicate<X>::value>; using InversePredicate = std::integral_constant<bool, not Predicate<X>::value>;
using type = typename make_type_set_if<InversePredicate, T...>::type; using type = typename make_type_set_if<InversePredicate, T...>::type;
}; };
template<template<typename> class Predicate, typename... T> template <template <typename> class Predicate, typename... T>
using make_type_set_if_not_t = typename make_type_set_if_not<Predicate, T...>::type; using make_type_set_if_not_t = typename make_type_set_if_not<Predicate, T...>::type;
template<typename... T> template <typename... T>
using has_duplicates = std::integral_constant<bool, make_type_set_t<T...>::size::value != sizeof...(T)>; using has_duplicates = std::integral_constant<bool, make_type_set_t<T...>::size::value != sizeof...(T)>;
template<typename... T> template <typename... T>
struct make_joined_set struct make_joined_set
{ {
static_assert(wrong_t<make_joined_set>::value, "invalid argument for joined set"); static_assert(wrong_t<make_joined_set>::value, "invalid argument for joined set");
}; };
template<> template <>
struct make_joined_set<> struct make_joined_set<>
{ {
using type = type_set<>; using type = type_set<>;
}; };
template<typename... E, typename... T> template <typename... E, typename... T>
struct make_joined_set<type_set<E...>, T...> struct make_joined_set<type_set<E...>, T...>
{ {
using _rest = typename make_joined_set<T...>::type; using _rest = typename make_joined_set<T...>::type;
@ -193,63 +194,59 @@ namespace sqlpp
using type = joined_set_t<type_set<E...>, _rest>; using type = joined_set_t<type_set<E...>, _rest>;
}; };
template<typename... Sets> template <typename... Sets>
using make_joined_set_t = typename make_joined_set<Sets...>::type; using make_joined_set_t = typename make_joined_set<Sets...>::type;
template<typename Minuend, typename Subtrahend> template <typename Minuend, typename Subtrahend>
struct make_difference_set struct make_difference_set
{ {
static_assert(wrong_t<make_difference_set>::value, "invalid argument for difference set"); static_assert(wrong_t<make_difference_set>::value, "invalid argument for difference set");
}; };
template<typename... Minuends, typename... Subtrahends> template <typename... Minuends, typename... Subtrahends>
struct make_difference_set<type_set<Minuends...>, type_set<Subtrahends...>> struct make_difference_set<type_set<Minuends...>, type_set<Subtrahends...>>
{ {
template<typename E> template <typename E>
using is_subtrahend = is_element_of<E, type_set<Subtrahends...>>; using is_subtrahend = is_element_of<E, type_set<Subtrahends...>>;
using type = make_type_set_if_not_t<is_subtrahend, Minuends...>; using type = make_type_set_if_not_t<is_subtrahend, Minuends...>;
}; };
template<typename Minuend, typename Subtrahend> template <typename Minuend, typename Subtrahend>
using make_difference_set_t = typename make_difference_set<Minuend, Subtrahend>::type; using make_difference_set_t = typename make_difference_set<Minuend, Subtrahend>::type;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
struct make_intersect_set struct make_intersect_set
{ {
static_assert(wrong_t<make_intersect_set>::value, "invalid argument for intersect set"); static_assert(wrong_t<make_intersect_set>::value, "invalid argument for intersect set");
}; };
template<typename... LhsElements, typename... RhsElements> template <typename... LhsElements, typename... RhsElements>
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
{ {
static_assert(wrong_t<transform_set>::value, "invalid argument for transform_set"); static_assert(wrong_t<transform_set>::value, "invalid argument for transform_set");
}; };
template<template<typename> class Transformation, typename... E> template <template <typename> class Transformation, typename... E>
struct transform_set<Transformation, type_set<E...>> struct transform_set<Transformation, type_set<E...>>
{ {
using type = make_type_set_t<Transformation<E>...>; using type = make_type_set_t<Transformation<E>...>;
}; };
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

@ -33,50 +33,52 @@ namespace sqlpp
{ {
namespace detail namespace detail
{ {
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
{ {
static_assert(wrong_t<type_vector_cat_impl>::value, "type_vector_cat must be called with type_vector arguments"); static_assert(wrong_t<type_vector_cat_impl>::value, "type_vector_cat must be called with type_vector arguments");
}; };
template<> template <>
struct type_vector_cat_impl<> struct type_vector_cat_impl<>
{ {
using type = type_vector<>; using type = type_vector<>;
}; };
template<typename... T> template <typename... T>
struct type_vector_cat_impl<type_vector<T...>> struct type_vector_cat_impl<type_vector<T...>>
{ {
using type = type_vector<T...>; using type = type_vector<T...>;
}; };
template<typename... L, typename... R> template <typename... L, typename... R>
struct type_vector_cat_impl<type_vector<L...>, type_vector<R...>> struct type_vector_cat_impl<type_vector<L...>, type_vector<R...>>
{ {
using type = type_vector<L..., R...>; using type = type_vector<L..., R...>;
}; };
template<typename... L, typename... Rest> template <typename... L, typename... Rest>
struct type_vector_cat_impl<type_vector<L...>, Rest...> struct type_vector_cat_impl<type_vector<L...>, Rest...>
{ {
using type = typename type_vector_cat_impl<type_vector<L...>, typename type_vector_cat_impl<Rest...>::type>::type; using type = typename type_vector_cat_impl<type_vector<L...>, typename type_vector_cat_impl<Rest...>::type>::type;
}; };
template<typename... T> template <typename... T>
using type_vector_cat_t = typename type_vector_cat_impl<T...>::type; using type_vector_cat_t = typename type_vector_cat_impl<T...>::type;
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>
struct type_vector_size<type_vector<T...>> struct type_vector_size<type_vector<T...>>
{ {
static constexpr std::size_t value = sizeof...(T); static constexpr std::size_t value = sizeof...(T);
@ -84,5 +86,4 @@ namespace sqlpp
} }
} }
#endif #endif

View File

@ -34,25 +34,29 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Db, typename Expr> template <typename Db, typename Expr>
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;
} }
template<typename ValueType, typename Db> template <typename ValueType, typename Db>
auto eval(Db& db, std::string sql_code) -> decltype(eval(db, verbatim<ValueType>(sql_code))) auto eval(Db& db, std::string sql_code) -> decltype(eval(db, verbatim<ValueType>(sql_code)))
{ {
return eval(db, verbatim<ValueType>(sql_code)); return eval(db, verbatim<ValueType>(sql_code));

View File

@ -31,13 +31,16 @@
namespace sqlpp 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

@ -38,20 +38,24 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "exists_"; static constexpr const char _literal[] = "exists_";
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 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;
@ -73,7 +77,7 @@ namespace sqlpp
Select _select; Select _select;
}; };
template<typename Context, typename Select> template <typename Context, typename Select>
struct serializer_t<Context, exists_t<Select>> struct serializer_t<Context, exists_t<Select>>
{ {
using _serialize_check = serialize_check_of<Context, Select>; using _serialize_check = serialize_check_of<Context, Select>;
@ -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

@ -38,9 +38,9 @@
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;
@ -63,7 +62,7 @@ namespace sqlpp
_rhs_t _rhs; _rhs_t _rhs;
}; };
template<typename Context, typename Lhs, typename Rhs> template <typename Context, typename Lhs, typename Rhs>
struct serializer_t<Context, binary_expression_t<Lhs, op::equal_to, Rhs>> struct serializer_t<Context, binary_expression_t<Lhs, op::equal_to, Rhs>>
{ {
using T = binary_expression_t<Lhs, op::equal_to, Rhs>; using T = binary_expression_t<Lhs, op::equal_to, Rhs>;
@ -87,9 +86,9 @@ 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;
@ -112,7 +110,7 @@ namespace sqlpp
_rhs_t _rhs; _rhs_t _rhs;
}; };
template<typename Context, typename Lhs, typename Rhs> template <typename Context, typename Lhs, typename Rhs>
struct serializer_t<Context, binary_expression_t<Lhs, op::not_equal_to, Rhs>> struct serializer_t<Context, binary_expression_t<Lhs, op::not_equal_to, Rhs>>
{ {
using T = binary_expression_t<Lhs, op::not_equal_to, Rhs>; using T = binary_expression_t<Lhs, op::not_equal_to, Rhs>;
@ -136,17 +134,17 @@ 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;
@ -157,7 +155,7 @@ namespace sqlpp
Rhs _rhs; Rhs _rhs;
}; };
template<typename Context, typename Rhs> template <typename Context, typename Rhs>
struct serializer_t<Context, unary_expression_t<op::logical_not, Rhs>> struct serializer_t<Context, unary_expression_t<op::logical_not, Rhs>>
{ {
using _serialize_check = serialize_check_of<Context, Rhs>; using _serialize_check = serialize_check_of<Context, Rhs>;
@ -182,18 +180,16 @@ 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;
@ -205,7 +201,7 @@ namespace sqlpp
Rhs _rhs; Rhs _rhs;
}; };
template<typename Context, typename Lhs, typename O, typename Rhs> template <typename Context, typename Lhs, typename O, typename Rhs>
struct serializer_t<Context, binary_expression_t<Lhs, O, Rhs>> struct serializer_t<Context, binary_expression_t<Lhs, O, Rhs>>
{ {
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>; using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
@ -222,17 +218,16 @@ 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;
@ -243,7 +238,7 @@ namespace sqlpp
Rhs _rhs; Rhs _rhs;
}; };
template<typename Context, typename O, typename Rhs> template <typename Context, typename O, typename Rhs>
struct serializer_t<Context, unary_expression_t<O, Rhs>> struct serializer_t<Context, unary_expression_t<O, Rhs>>
{ {
using _serialize_check = serialize_check_of<Context, Rhs>; using _serialize_check = serialize_check_of<Context, Rhs>;

View File

@ -86,21 +86,21 @@ namespace sqlpp
using _traits = make_traits<boolean>; using _traits = make_traits<boolean>;
}; };
template<typename ValueType> template <typename ValueType>
struct plus struct plus
{ {
using _traits = make_traits<ValueType>; using _traits = make_traits<ValueType>;
static constexpr const char* _name = "+"; static constexpr const char* _name = "+";
}; };
template<typename ValueType> template <typename ValueType>
struct minus struct minus
{ {
using _traits = make_traits<ValueType>; using _traits = make_traits<ValueType>;
static constexpr const char* _name = "-"; static constexpr const char* _name = "-";
}; };
template<typename ValueType> template <typename ValueType>
struct multiplies struct multiplies
{ {
using _traits = make_traits<ValueType>; using _traits = make_traits<ValueType>;
@ -119,100 +119,99 @@ namespace sqlpp
static constexpr const char* _name = "%"; static constexpr const char* _name = "%";
}; };
template<typename ValueType> template <typename ValueType>
struct unary_minus struct unary_minus
{ {
using _traits = make_traits<ValueType>; using _traits = make_traits<ValueType>;
static constexpr const char* _name = "-"; static constexpr const char* _name = "-";
}; };
template<typename ValueType> template <typename ValueType>
struct unary_plus struct unary_plus
{ {
using _traits = make_traits<ValueType>; using _traits = make_traits<ValueType>;
static constexpr const char* _name = "+"; static constexpr const char* _name = "+";
}; };
template<typename ValueType> template <typename ValueType>
struct bitwise_and struct bitwise_and
{ {
using _traits = make_traits<ValueType>; using _traits = make_traits<ValueType>;
static constexpr const char* _name = "&"; static constexpr const char* _name = "&";
}; };
template<typename ValueType> template <typename ValueType>
struct bitwise_or struct bitwise_or
{ {
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>
struct binary_expression_t; struct binary_expression_t;
template<typename O, typename Rhs> template <typename O, typename Rhs>
struct unary_expression_t; struct unary_expression_t;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using less_than_t = binary_expression_t<Lhs, op::less, Rhs>; using less_than_t = binary_expression_t<Lhs, op::less, Rhs>;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using less_equal_t = binary_expression_t<Lhs, op::less_equal, Rhs>; using less_equal_t = binary_expression_t<Lhs, op::less_equal, Rhs>;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using equal_to_t = binary_expression_t<Lhs, op::equal_to, Rhs>; using equal_to_t = binary_expression_t<Lhs, op::equal_to, Rhs>;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using not_equal_to_t = binary_expression_t<Lhs, op::not_equal_to, Rhs>; using not_equal_to_t = binary_expression_t<Lhs, op::not_equal_to, Rhs>;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using greater_than_t = binary_expression_t<Lhs, op::greater, Rhs>; using greater_than_t = binary_expression_t<Lhs, op::greater, Rhs>;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using greater_equal_t = binary_expression_t<Lhs, op::greater_equal, Rhs>; using greater_equal_t = binary_expression_t<Lhs, op::greater_equal, Rhs>;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using logical_and_t = binary_expression_t<Lhs, op::logical_and, Rhs>; using logical_and_t = binary_expression_t<Lhs, op::logical_and, Rhs>;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using logical_or_t = binary_expression_t<Lhs, op::logical_or, Rhs>; using logical_or_t = binary_expression_t<Lhs, op::logical_or, Rhs>;
template<typename Lhs, typename ValueType, typename Rhs> template <typename Lhs, typename ValueType, typename Rhs>
using plus_t = binary_expression_t<Lhs, op::plus<ValueType>, Rhs>; using plus_t = binary_expression_t<Lhs, op::plus<ValueType>, Rhs>;
template<typename Lhs, typename ValueType, typename Rhs> template <typename Lhs, typename ValueType, typename Rhs>
using minus_t = binary_expression_t<Lhs, op::minus<ValueType>, Rhs>; using minus_t = binary_expression_t<Lhs, op::minus<ValueType>, Rhs>;
template<typename Lhs, typename ValueType, typename Rhs> template <typename Lhs, typename ValueType, typename Rhs>
using multiplies_t = binary_expression_t<Lhs, op::multiplies<ValueType>, Rhs>; using multiplies_t = binary_expression_t<Lhs, op::multiplies<ValueType>, Rhs>;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using divides_t = binary_expression_t<Lhs, op::divides, Rhs>; using divides_t = binary_expression_t<Lhs, op::divides, Rhs>;
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using modulus_t = binary_expression_t<Lhs, op::modulus, Rhs>; using modulus_t = binary_expression_t<Lhs, op::modulus, Rhs>;
template<typename Rhs> template <typename Rhs>
using logical_not_t = unary_expression_t<op::logical_not, Rhs>; using logical_not_t = unary_expression_t<op::logical_not, Rhs>;
template<typename ValueType, typename Rhs> template <typename ValueType, typename Rhs>
using unary_plus_t = unary_expression_t<op::unary_plus<ValueType>, Rhs>; using unary_plus_t = unary_expression_t<op::unary_plus<ValueType>, Rhs>;
template<typename ValueType, typename Rhs> template <typename ValueType, typename Rhs>
using unary_minus_t = unary_expression_t<op::unary_minus<ValueType>, Rhs>; using unary_minus_t = unary_expression_t<op::unary_minus<ValueType>, Rhs>;
template<typename Lhs, typename ValueType, typename Rhs> template <typename Lhs, typename ValueType, typename Rhs>
using bitwise_and_t = binary_expression_t<Lhs, op::bitwise_and<ValueType>, Rhs>; using bitwise_and_t = binary_expression_t<Lhs, op::bitwise_and<ValueType>, Rhs>;
template<typename Lhs, typename ValueType, typename Rhs> template <typename Lhs, typename ValueType, typename Rhs>
using bitwise_or_t = binary_expression_t<Lhs, op::bitwise_or<ValueType>, Rhs>; using bitwise_or_t = binary_expression_t<Lhs, op::bitwise_or<ValueType>, Rhs>;
template<typename Expr> template <typename Expr>
using lhs_t = typename Expr::_lhs_t; using lhs_t = typename Expr::_lhs_t;
template<typename Expr> template <typename Expr>
using rhs_t = typename Expr::_rhs_t; using rhs_t = typename Expr::_rhs_t;
} }

View File

@ -33,22 +33,22 @@
namespace sqlpp namespace sqlpp
{ {
template<typename... Tables> template <typename... Tables>
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
template<typename... Tables> template <typename... Tables>
struct extra_tables_t struct extra_tables_t
{ {
using _traits = make_traits<no_value_t, tag::is_extra_tables>; using _traits = make_traits<no_value_t, tag::is_extra_tables>;
@ -67,16 +67,22 @@ namespace sqlpp
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.extra_tables; return t.extra_tables;
@ -96,39 +102,44 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.no_extra_tables; return t.no_extra_tables;
} }
template<typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_extra_tables_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_extra_tables_t, T>;
template<typename... T> template <typename... T>
using _check = logic::all_t<is_table_t<T>::value...>; using _check = logic::all_t<is_table_t<T>::value...>;
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()");
@ -136,29 +147,31 @@ 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...>{}};
} }
}; };
}; };
// Interpreters // Interpreters
template<typename Context, typename Database, typename... Tables> template <typename Context, typename Database, typename... Tables>
struct serializer_t<Context, extra_tables_data_t<Database, Tables...>> struct serializer_t<Context, extra_tables_data_t<Database, Tables...>>
{ {
using _serialize_check = serialize_check_of<Context, Tables...>; using _serialize_check = serialize_check_of<Context, Tables...>;
@ -169,7 +182,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -31,30 +31,32 @@
namespace sqlpp 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;
}; };
template<typename AliasProvider, typename FieldSpecTuple> template <typename AliasProvider, typename FieldSpecTuple>
struct multi_field_spec_t struct multi_field_spec_t
{ {
}; };
namespace detail namespace detail
{ {
template<typename Select, typename NamedExpr> template <typename Select, typename NamedExpr>
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>,
@ -62,16 +64,16 @@ namespace sqlpp
null_is_trivial_value_t<NamedExpr>::value>; null_is_trivial_value_t<NamedExpr>::value>;
}; };
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

@ -42,26 +42,24 @@ namespace sqlpp
using _tag = tag::is_floating_point; using _tag = tag::is_floating_point;
using _cpp_value_type = double; using _cpp_value_type = double;
template<typename T> template <typename T>
using _is_valid_operand = is_numeric_t<T>; using _is_valid_operand = is_numeric_t<T>;
}; };
// floating_point parameter type // floating_point parameter type
template<> template <>
struct parameter_value_t<floating_point> struct parameter_value_t<floating_point>
{ {
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,9 +100,12 @@ 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
{ {
target._bind_floating_point_parameter(index, &_value, _is_null); target._bind_floating_point_parameter(index, &_value, _is_null);
@ -116,113 +117,111 @@ 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>;
template<typename T> template <typename T>
plus_t<Expr, floating_point, wrap_operand_t<T>> operator +(T t) const plus_t<Expr, floating_point, wrap_operand_t<T>> operator+(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Expr*>(this), rhs{t} }; return {*static_cast<const Expr*>(this), rhs{t}};
} }
template<typename T> template <typename T>
minus_t<Expr, floating_point, wrap_operand_t<T>> operator -(T t) const minus_t<Expr, floating_point, wrap_operand_t<T>> operator-(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Expr*>(this), rhs{t} }; return {*static_cast<const Expr*>(this), rhs{t}};
} }
template<typename T> template <typename T>
multiplies_t<Expr, floating_point, wrap_operand_t<T>> operator *(T t) const multiplies_t<Expr, floating_point, wrap_operand_t<T>> operator*(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
return { *static_cast<const Expr*>(this), rhs{t} }; return {*static_cast<const Expr*>(this), rhs{t}};
} }
template<typename T> template <typename T>
divides_t<Expr, wrap_operand_t<T>> operator /(T t) const divides_t<Expr, wrap_operand_t<T>> operator/(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
return { *static_cast<const Expr*>(this), rhs{t} }; return {*static_cast<const Expr*>(this), rhs{t}};
} }
unary_plus_t<floating_point, Expr> operator +() const unary_plus_t<floating_point, Expr> operator+() const
{ {
return { *static_cast<const Expr*>(this) }; return {*static_cast<const Expr*>(this)};
} }
unary_minus_t<floating_point, Expr> operator -() const unary_minus_t<floating_point, Expr> operator-() const
{ {
return { *static_cast<const Expr*>(this) }; return {*static_cast<const Expr*>(this)};
} }
}; };
// floating_point column operators // floating_point column operators
template<typename Column> template <typename Column>
struct column_operators<Column, floating_point> struct column_operators<Column, 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>;
template<typename T> template <typename T>
auto operator +=(T t) const -> assignment_t<Column, plus_t<Column, floating_point, wrap_operand_t<T>>> auto operator+=(T t) const -> assignment_t<Column, plus_t<Column, floating_point, wrap_operand_t<T>>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *static_cast<const Column*>(this), { *static_cast<const Column*>(this), rhs{t} } }; return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
} }
template<typename T> template <typename T>
auto operator -=(T t) const -> assignment_t<Column, minus_t<Column, floating_point, wrap_operand_t<T>>> auto operator-=(T t) const -> assignment_t<Column, minus_t<Column, floating_point, wrap_operand_t<T>>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *static_cast<const Column*>(this), { *static_cast<const Column*>(this), rhs{t} } }; return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
} }
template<typename T> template <typename T>
auto operator /=(T t) const -> assignment_t<Column, divides_t<Column, wrap_operand_t<T>>> auto operator/=(T t) const -> assignment_t<Column, divides_t<Column, wrap_operand_t<T>>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *static_cast<const Column*>(this), { *static_cast<const Column*>(this), rhs{t} } }; return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
} }
template<typename T> template <typename T>
auto operator *=(T t) const -> assignment_t<Column, multiplies_t<Column, floating_point, wrap_operand_t<T>>> auto operator*=(T t) const -> assignment_t<Column, multiplies_t<Column, floating_point, wrap_operand_t<T>>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *static_cast<const Column*>(this), { *static_cast<const Column*>(this), rhs{t} } }; return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
} }
}; };
// 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()
{ {
@ -270,7 +269,7 @@ namespace sqlpp
return _value; return _value;
} }
template<typename Target> template <typename Target>
void _bind(Target& target, size_t i) void _bind(Target& target, size_t i)
{ {
target._bind_floating_point_result(i, &_value, &_is_null); target._bind_floating_point_result(i, &_value, &_is_null);
@ -282,11 +281,10 @@ namespace sqlpp
_cpp_value_type _value; _cpp_value_type _value;
}; };
template<typename Db, typename FieldSpec> template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<floating_point, Db, FieldSpec>& e) inline std::ostream& operator<<(std::ostream& os, const result_field_t<floating_point, Db, FieldSpec>& e)
{ {
return serialize(e, os); return serialize(e, os);
} }
} }
#endif #endif

View File

@ -39,12 +39,12 @@
namespace sqlpp namespace sqlpp
{ {
// FROM DATA // FROM DATA
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;
@ -57,7 +57,7 @@ namespace sqlpp
}; };
// FROM // FROM
template<typename Database, typename... Tables> template <typename Database, typename... Tables>
struct from_t struct from_t
{ {
using _traits = make_traits<no_value_t, tag::is_from>; using _traits = make_traits<no_value_t, tag::is_from>;
@ -68,17 +68,19 @@ namespace sqlpp
using _data_t = from_data_t<Database, Tables...>; using _data_t = from_data_t<Database, Tables...>;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
template<typename Table> template <typename Table>
void add(Table table) void add(Table table)
{ {
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::_();
@ -88,13 +90,13 @@ namespace sqlpp
} }
private: private:
template<typename Table> template <typename Table>
void _add_impl(Table table, const std::true_type&) void _add_impl(Table table, const std::true_type&)
{ {
return _data._dynamic_tables.emplace_back(from_table(table)); return _data._dynamic_tables.emplace_back(from_table(table));
} }
template<typename Table> template <typename Table>
void _add_impl(Table table, const std::false_type&); void _add_impl(Table table, const std::false_type&);
public: public:
@ -102,16 +104,22 @@ namespace sqlpp
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.from; return t.from;
@ -131,23 +139,29 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.no_from; return t.no_from;
@ -155,57 +169,59 @@ namespace sqlpp
using _database_t = typename Policies::_database_t; using _database_t = typename Policies::_database_t;
template<typename... T> template <typename... T>
using _check = logic::all_t<is_table_t<T>::value...>; using _check = logic::all_t<is_table_t<T>::value...>;
template<typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_from_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_from_t, T>;
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()");
return _from_impl<void>(_check<Tables...>{}, tables...); return _from_impl<void>(_check<Tables...>{}, tables...);
} }
template<typename... Tables> template <typename... Tables>
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)...}};
} }
}; };
}; };
// Interpreters // Interpreters
template<typename Context, typename Database, typename... Tables> template <typename Context, typename Database, typename... Tables>
struct serializer_t<Context, from_data_t<Database, Tables...>> struct serializer_t<Context, from_data_t<Database, Tables...>>
{ {
using _serialize_check = serialize_check_of<Context, Tables...>; using _serialize_check = serialize_check_of<Context, Tables...>;
@ -224,7 +240,7 @@ namespace sqlpp
} }
}; };
template<typename... T> template <typename... T>
auto from(T&&... t) -> decltype(statement_t<void, no_from_t>().from(std::forward<T>(t)...)) auto from(T&&... t) -> decltype(statement_t<void, no_from_t>().from(std::forward<T>(t)...))
{ {
return statement_t<void, no_from_t>().from(std::forward<T>(t)...); return statement_t<void, no_from_t>().from(std::forward<T>(t)...);

View File

@ -51,35 +51,37 @@
namespace sqlpp 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,
return { t }; "value() is to be called with non-sql-type like int, or string");
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()};
} }
template<typename Expression> template <typename Expression>
auto is_null(Expression e) -> decltype(e.is_null()) auto is_null(Expression e) -> decltype(e.is_null())
{ {
return e.is_null(); return e.is_null();
} }
template<typename Expression> template <typename Expression>
auto is_not_null(Expression e) -> decltype(e.is_not_null()) auto is_not_null(Expression e) -> decltype(e.is_not_null())
{ {
return e.is_not_null(); return e.is_not_null();
} }
template<typename Container> template <typename Container>
struct value_list_t // to be used in .in() method struct value_list_t // to be used in .in() method
{ {
using _traits = make_traits<value_type_t<typename Container::value_type>, tag::is_expression>; using _traits = make_traits<value_type_t<typename Container::value_type>, tag::is_expression>;
@ -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;
@ -100,7 +102,7 @@ namespace sqlpp
_container_t _container; _container_t _container;
}; };
template<typename Context, typename Container> template <typename Context, typename Container>
struct serializer_t<Context, value_list_t<Container>> struct serializer_t<Context, value_list_t<Container>>
{ {
using _serialize_check = serialize_check_of<Context, wrap_operand_t<typename Container::value_type>>; using _serialize_check = serialize_check_of<Context, wrap_operand_t<typename Container::value_type>>;
@ -114,7 +116,7 @@ namespace sqlpp
} }
bool first = true; bool first = true;
for (const auto& entry: t._container) for (const auto& entry : t._container)
{ {
if (first) if (first)
first = false; first = false;
@ -127,20 +129,20 @@ 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(
return { c }; 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};
} }
template<typename T> template <typename T>
constexpr const char* get_sql_name(const T&) constexpr const char* get_sql_name(const T&)
{ {
return name_of<T>::char_ptr(); return name_of<T>::char_ptr();
} }
} }
#endif #endif

View File

@ -38,12 +38,12 @@
namespace sqlpp namespace sqlpp
{ {
// GROUP BY DATA // GROUP BY DATA
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;
@ -59,15 +59,16 @@ namespace sqlpp
{ {
using type = std::false_type; using type = std::false_type;
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");
} }
}; };
// GROUP BY // GROUP BY
template<typename Database, typename... Expressions> template <typename Database, typename... Expressions>
struct group_by_t struct group_by_t
{ {
using _traits = make_traits<no_value_t, tag::is_group_by>; using _traits = make_traits<no_value_t, tag::is_group_by>;
@ -79,21 +80,22 @@ namespace sqlpp
using _data_t = group_by_data_t<Database, Expressions...>; using _data_t = group_by_data_t<Database, Expressions...>;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
template<typename Expression> template <typename Expression>
void add_ntc(Expression expression) void add_ntc(Expression expression)
{ {
add<Expression, std::false_type>(expression); add<Expression, std::false_type>(expression);
} }
template<typename Expression, typename TableCheckRequired = std::true_type> template <typename Expression, typename TableCheckRequired = std::true_type>
void add(Expression expression) void add(Expression expression)
{ {
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::_();
@ -103,29 +105,36 @@ namespace sqlpp
} }
private: private:
template<typename Expression> template <typename Expression>
void _add_impl(Expression expression, const std::true_type&) void _add_impl(Expression expression, const std::true_type&)
{ {
return _data._dynamic_expressions.emplace_back(expression); return _data._dynamic_expressions.emplace_back(expression);
} }
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;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.group_by; return t.group_by;
@ -147,23 +156,29 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.no_group_by; return t.no_group_by;
@ -171,15 +186,15 @@ namespace sqlpp
using _database_t = typename Policies::_database_t; using _database_t = typename Policies::_database_t;
template<typename... T> template <typename... T>
using _check = logic::all_t<is_expression_t<T>::value...>; using _check = logic::all_t<is_expression_t<T>::value...>;
template<typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_group_by_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_group_by_t, T>;
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
template<typename... Expressions> template <typename... Expressions>
auto group_by(Expressions... expressions) const auto group_by(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, group_by_t<void, Expressions...>> -> _new_statement_t<_check<Expressions...>, group_by_t<void, Expressions...>>
{ {
@ -189,34 +204,36 @@ namespace sqlpp
return _group_by_impl<void>(_check<Expressions...>{}, expressions...); return _group_by_impl<void>(_check<Expressions...>{}, expressions...);
} }
template<typename... Expressions> template <typename... Expressions>
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...);
} }
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...}};
} }
}; };
}; };
// Interpreters // Interpreters
template<typename Context, typename Database, typename... Expressions> template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, group_by_data_t<Database, Expressions...>> struct serializer_t<Context, group_by_data_t<Database, Expressions...>>
{ {
using _serialize_check = serialize_check_of<Context, Expressions...>; using _serialize_check = serialize_check_of<Context, Expressions...>;

View File

@ -37,12 +37,12 @@
namespace sqlpp namespace sqlpp
{ {
// HAVING DATA // HAVING DATA
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;
@ -58,15 +58,16 @@ namespace sqlpp
{ {
using type = std::false_type; using type = std::false_type;
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");
} }
}; };
// HAVING // HAVING
template<typename Database, typename... Expressions> template <typename Database, typename... Expressions>
struct having_t struct having_t
{ {
using _traits = make_traits<no_value_t, tag::is_having>; using _traits = make_traits<no_value_t, tag::is_having>;
@ -81,18 +82,19 @@ namespace sqlpp
template <typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
template<typename Expression> template <typename Expression>
void add_ntc(Expression expression) void add_ntc(Expression expression)
{ {
add<Expression, std::false_type>(expression); add<Expression, std::false_type>(expression);
} }
template<typename Expression, typename TableCheckRequired = std::true_type> template <typename Expression, typename TableCheckRequired = std::true_type>
void add(Expression expression) void add(Expression expression)
{ {
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::_();
@ -102,13 +104,13 @@ namespace sqlpp
} }
private: private:
template<typename Expression> template <typename Expression>
void _add_impl(Expression expression, const std::true_type&) void _add_impl(Expression expression, const std::true_type&)
{ {
return _data._dynamic_expressions.emplace_back(expression); return _data._dynamic_expressions.emplace_back(expression);
} }
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:
@ -116,16 +118,22 @@ namespace sqlpp
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.having; return t.having;
@ -147,23 +155,29 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.no_having; return t.no_having;
@ -171,15 +185,15 @@ namespace sqlpp
using _database_t = typename Policies::_database_t; using _database_t = typename Policies::_database_t;
template<typename... T> template <typename... T>
using _check = logic::all_t<is_expression_t<T>::value...>; using _check = logic::all_t<is_expression_t<T>::value...>;
template<typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_having_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_having_t, T>;
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
template<typename... Expressions> template <typename... Expressions>
auto having(Expressions... expressions) const auto having(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, having_t<void, Expressions...>> -> _new_statement_t<_check<Expressions...>, having_t<void, Expressions...>>
{ {
@ -189,32 +203,32 @@ namespace sqlpp
return _having_impl<void>(_check<Expressions...>{}, expressions...); return _having_impl<void>(_check<Expressions...>{}, expressions...);
} }
template<typename... Expressions> template <typename... Expressions>
auto dynamic_having(Expressions... expressions) const auto dynamic_having(Expressions... expressions) const
-> _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...}};
} }
}; };
}; };
// Interpreters // Interpreters
template<typename Context, typename Database, typename... Expressions> template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, having_data_t<Database, Expressions...>> struct serializer_t<Context, having_data_t<Database, Expressions...>>
{ {
using _serialize_check = serialize_check_of<Context, Expressions...>; using _serialize_check = serialize_check_of<Context, Expressions...>;

View File

@ -29,13 +29,12 @@
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;
@ -44,7 +43,7 @@ namespace sqlpp
~hidden_t() = default; ~hidden_t() = default;
}; };
template<typename Context, typename Part> template <typename Context, typename Part>
struct serializer_t<Context, hidden_t<Part>> struct serializer_t<Context, hidden_t<Part>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -56,9 +55,8 @@ 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

@ -41,7 +41,7 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "in_"; static constexpr const char _literal[] = "in_";
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 in; T in;
@ -49,9 +49,8 @@ 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;
@ -76,7 +74,7 @@ namespace sqlpp
std::tuple<Args...> _args; std::tuple<Args...> _args;
}; };
template<typename Context, typename Operand, typename... Args> template <typename Context, typename Operand, typename... Args>
struct serializer_t<Context, in_t<Operand, Args...>> struct serializer_t<Context, in_t<Operand, Args...>>
{ {
using _serialize_check = serialize_check_of<Context, Args...>; using _serialize_check = serialize_check_of<Context, Args...>;
@ -95,10 +93,10 @@ namespace sqlpp
} }
}; };
template<typename Container> template <typename Container>
struct value_list_t; struct value_list_t;
template<typename Context, typename Operand, typename Container> template <typename Context, typename Operand, typename Container>
struct serializer_t<Context, in_t<Operand, value_list_t<Container>>> struct serializer_t<Context, in_t<Operand, value_list_t<Container>>>
{ {
using _serialize_check = serialize_check_of<Context, value_list_t<Container>>; using _serialize_check = serialize_check_of<Context, value_list_t<Container>>;
@ -121,7 +119,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -29,11 +29,10 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Operand, typename... Args> template <typename Operand, typename... Args>
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,14 +39,18 @@
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
{ {
using _statement_t = Statement; using _statement_t = Statement;
@ -57,37 +61,34 @@ 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);
} }
template<typename Db> template <typename Db>
auto _run(Db& db) const -> decltype(db.insert(this->_get_statement())) auto _run(Db& db) const -> decltype(db.insert(this->_get_statement()))
{ {
return db.insert(_get_statement()); return db.insert(_get_statement());
} }
// 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())};
} }
}; };
}; };
template<typename Context> template <typename Context>
struct serializer_t<Context, insert_name_t> struct serializer_t<Context, insert_name_t>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -101,39 +102,32 @@ 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

@ -38,13 +38,13 @@ namespace sqlpp
{ {
namespace detail namespace detail
{ {
template<typename Type, bool> template <typename Type, bool>
struct type_if struct type_if
{ {
using type = Type; using type = Type;
}; };
template<typename Type> template <typename Type>
struct type_if<Type, false> struct type_if<Type, false>
{ {
struct type struct type
@ -55,7 +55,7 @@ namespace sqlpp
}; };
} }
template<typename Column> template <typename Column>
struct insert_value_t struct insert_value_t
{ {
using _is_insert_value = std::true_type; using _is_insert_value = std::true_type;
@ -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;
@ -100,7 +95,7 @@ namespace sqlpp
_wrapped_value_t _value; _wrapped_value_t _value;
}; };
template<typename Context, typename ValueType> template <typename Context, typename ValueType>
struct serializer_t<Context, insert_value_t<ValueType>> struct serializer_t<Context, insert_value_t<ValueType>>
{ {
using _serialize_check = serialize_check_of<Context, ValueType>; using _serialize_check = serialize_check_of<Context, ValueType>;
@ -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

@ -41,13 +41,13 @@ namespace sqlpp
{ {
namespace detail namespace detail
{ {
template<typename... Columns> template <typename... Columns>
struct have_all_required_columns struct have_all_required_columns
{ {
static constexpr bool value = false; static constexpr bool value = false;
}; };
template<typename First, typename... Columns> template <typename First, typename... Columns>
struct have_all_required_columns<First, Columns...> struct have_all_required_columns<First, Columns...>
{ {
using _table = typename First::_table; using _table = typename First::_table;
@ -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
@ -70,23 +71,29 @@ namespace sqlpp
using _data_t = insert_default_values_data_t; using _data_t = insert_default_values_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.default_values; return t.default_values;
@ -96,14 +103,13 @@ 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;
@ -122,14 +129,15 @@ namespace sqlpp
{ {
using type = std::false_type; using type = std::false_type;
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");
} }
}; };
template<typename Database, typename... Assignments> template <typename Database, typename... Assignments>
struct insert_list_t struct insert_list_t
{ {
using _traits = make_traits<no_value_t, tag::is_insert_list>; using _traits = make_traits<no_value_t, tag::is_insert_list>;
@ -137,9 +145,9 @@ namespace sqlpp
using _is_dynamic = is_database<Database>; using _is_dynamic = is_database<Database>;
template<template<typename...> class Target> template <template <typename...> class Target>
using copy_assignments_t = Target<Assignments...>; // FIXME: Nice idea to copy variadic template arguments? using copy_assignments_t = Target<Assignments...>; // FIXME: Nice idea to copy variadic template arguments?
template<template<typename...> class Target, template<typename> class Wrap> template <template <typename...> class Target, template <typename> class Wrap>
using copy_wrapped_assignments_t = Target<Wrap<Assignments>...>; using copy_wrapped_assignments_t = Target<Wrap<Assignments>...>;
// Data // Data
@ -149,57 +157,63 @@ namespace sqlpp
template <typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
template<typename Assignment> template <typename Assignment>
void add_ntc(Assignment assignment) void add_ntc(Assignment assignment)
{ {
add<Assignment, std::false_type>(assignment); add<Assignment, std::false_type>(assignment);
} }
template<typename Assignment, typename TableCheckRequired = std::true_type> template <typename Assignment, typename TableCheckRequired = std::true_type>
void add(Assignment assignment) void add(Assignment assignment)
{ {
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
} }
private: private:
template<typename Assignment> template <typename Assignment>
void _add_impl(Assignment assignment, const std::true_type&) void _add_impl(Assignment assignment, const std::true_type&)
{ {
_data._dynamic_columns.emplace_back(simple_column_t<lhs_t<Assignment>>{assignment._lhs}); _data._dynamic_columns.emplace_back(simple_column_t<lhs_t<Assignment>>{assignment._lhs});
_data._dynamic_values.emplace_back(assignment._rhs); _data._dynamic_values.emplace_back(assignment._rhs);
} }
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;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.insert_list; return 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;
@ -234,14 +247,15 @@ namespace sqlpp
{ {
using type = std::false_type; using type = std::false_type;
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");
} }
}; };
template<typename... Columns> template <typename... Columns>
struct column_list_t struct column_list_t
{ {
using _traits = make_traits<no_value_t, tag::is_column_list>; using _traits = make_traits<no_value_t, tag::is_column_list>;
@ -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...>;
@ -257,45 +270,51 @@ namespace sqlpp
template <typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
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
} }
private: private:
template<typename... Assignments> template <typename... Assignments>
void _add_impl(const std::true_type&, Assignments... assignments) void _add_impl(const std::true_type&, Assignments... assignments)
{ {
return _data._insert_values.emplace_back(insert_value_t<lhs_t<Assignments>>{assignments._rhs}...); return _data._insert_values.emplace_back(insert_value_t<lhs_t<Assignments>>{assignments._rhs}...);
} }
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;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.values; return t.values;
@ -311,7 +330,7 @@ namespace sqlpp
{ {
using type = std::false_type; using type = std::false_type;
template<typename T = void> template <typename T = void>
static void _() static void _()
{ {
static_assert(wrong_t<T>::value, "insert values required, e.g. set(...) or default_values()"); static_assert(wrong_t<T>::value, "insert values required, e.g. set(...) or default_values()");
@ -328,23 +347,29 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.no_insert_values; return t.no_insert_values;
@ -352,34 +377,33 @@ namespace sqlpp
using _database_t = typename Policies::_database_t; using _database_t = typename Policies::_database_t;
template<typename... T> template <typename... T>
using _column_check = logic::all_t<is_column_t<T>::value...>; using _column_check = logic::all_t<is_column_t<T>::value...>;
template<typename... T> template <typename... T>
using _assignment_check = logic::all_t<is_assignment_t<T>::value...>; using _assignment_check = logic::all_t<is_assignment_t<T>::value...>;
template<typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_insert_value_list_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_insert_value_list_t, T>;
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...);
} }
template<typename... Assignments> template <typename... Assignments>
auto set(Assignments... assignments) const auto set(Assignments... assignments) const
-> _new_statement_t<_assignment_check<Assignments...>, insert_list_t<void, Assignments...>> -> _new_statement_t<_assignment_check<Assignments...>, insert_list_t<void, Assignments...>>
{ {
@ -389,57 +413,66 @@ namespace sqlpp
return _set_impl<void>(_assignment_check<Assignments...>{}, assignments...); return _set_impl<void>(_assignment_check<Assignments...>{}, assignments...);
} }
template<typename... Assignments> template <typename... Assignments>
auto dynamic_set(Assignments... assignments) const auto dynamic_set(Assignments... assignments) const
-> _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:
template<typename... Columns>
auto _columns_impl(const std::false_type&, Columns... cols) const
-> bad_statement;
template<typename... Columns> private:
template <typename... Columns>
auto _columns_impl(const std::false_type&, Columns... cols) const -> bad_statement;
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...}};
} }
}; };
}; };
// Interpreters // Interpreters
template<typename Context> template <typename Context>
struct serializer_t<Context, insert_default_values_data_t> struct serializer_t<Context, insert_default_values_data_t>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -452,7 +485,7 @@ namespace sqlpp
} }
}; };
template<typename Context, typename... Columns> template <typename Context, typename... Columns>
struct serializer_t<Context, column_list_data_t<Columns...>> struct serializer_t<Context, column_list_data_t<Columns...>>
{ {
using _serialize_check = serialize_check_of<Context, Columns...>; using _serialize_check = serialize_check_of<Context, Columns...>;
@ -480,7 +513,7 @@ namespace sqlpp
} }
}; };
template<typename Context, typename Database, typename... Assignments> template <typename Context, typename Database, typename... Assignments>
struct serializer_t<Context, insert_list_data_t<Database, Assignments...>> struct serializer_t<Context, insert_list_data_t<Database, Assignments...>>
{ {
using _serialize_check = serialize_check_of<Context, Assignments...>; using _serialize_check = serialize_check_of<Context, Assignments...>;
@ -509,7 +542,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -44,26 +44,24 @@ namespace sqlpp
using _tag = tag::is_integral; using _tag = tag::is_integral;
using _cpp_value_type = int64_t; using _cpp_value_type = int64_t;
template<typename T> template <typename T>
using _is_valid_operand = is_numeric_t<T>; using _is_valid_operand = is_numeric_t<T>;
}; };
// integral parameter value // integral parameter value
template<> template <>
struct parameter_value_t<integral> struct parameter_value_t<integral>
{ {
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,9 +101,12 @@ 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
{ {
target._bind_integral_parameter(index, &_value, _is_null); target._bind_integral_parameter(index, &_value, _is_null);
@ -117,143 +118,141 @@ namespace sqlpp
}; };
// integral expression operators // integral expression operators
template<typename Base> template <typename Base>
struct expression_operators<Base, integral>: public basic_expression_operators<Base, integral> struct expression_operators<Base, integral> : public basic_expression_operators<Base, integral>
{ {
template<typename T> template <typename T>
using _is_valid_operand = is_valid_operand<integral, T>; using _is_valid_operand = is_valid_operand<integral, T>;
template<typename T> template <typename T>
plus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator +(T t) const plus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator+(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), {t} }; return {*static_cast<const Base*>(this), {t}};
} }
template<typename T> template <typename T>
minus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator -(T t) const minus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator-(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), {t} }; return {*static_cast<const Base*>(this), {t}};
} }
template<typename T> template <typename T>
multiplies_t<Base, value_type_t<T>, wrap_operand_t<T>> operator *(T t) const multiplies_t<Base, value_type_t<T>, wrap_operand_t<T>> operator*(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), {t} }; return {*static_cast<const Base*>(this), {t}};
} }
template<typename T> template <typename T>
divides_t<Base, wrap_operand_t<T>> operator /(T t) const divides_t<Base, wrap_operand_t<T>> operator/(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), {t} }; return {*static_cast<const Base*>(this), {t}};
} }
template<typename T> template <typename T>
modulus_t<Base, wrap_operand_t<T>> operator %(T t) const modulus_t<Base, wrap_operand_t<T>> operator%(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), {t} }; return {*static_cast<const Base*>(this), {t}};
} }
unary_plus_t<integral, Base> operator +() const unary_plus_t<integral, Base> operator+() const
{ {
return { *static_cast<const Base*>(this) }; return {*static_cast<const Base*>(this)};
} }
unary_minus_t<integral, Base> operator -() const unary_minus_t<integral, Base> operator-() const
{ {
return { *static_cast<const Base*>(this) }; return {*static_cast<const Base*>(this)};
} }
template<typename T> template <typename T>
bitwise_and_t<Base, value_type_t<T>, wrap_operand_t<T>> operator &(T t) const bitwise_and_t<Base, value_type_t<T>, wrap_operand_t<T>> operator&(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), {t} }; return {*static_cast<const Base*>(this), {t}};
} }
template<typename T> template <typename T>
bitwise_or_t<Base, value_type_t<T>, wrap_operand_t<T>> operator |(T t) const bitwise_or_t<Base, value_type_t<T>, wrap_operand_t<T>> operator|(T t) const
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), {t} }; return {*static_cast<const Base*>(this), {t}};
} }
}; };
// integral column operators // integral column operators
template<typename Base> template <typename Base>
struct column_operators<Base, integral> struct column_operators<Base, integral>
{ {
template<typename T> template <typename T>
using _is_valid_operand = is_valid_operand<integral, T>; using _is_valid_operand = is_valid_operand<integral, T>;
template<typename T> template <typename T>
auto operator +=(T t) const -> assignment_t<Base, plus_t<Base, value_type_t<T>, wrap_operand_t<T>>> auto operator+=(T t) const -> assignment_t<Base, plus_t<Base, value_type_t<T>, wrap_operand_t<T>>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *static_cast<const Base*>(this), {{*static_cast<const Base*>(this), rhs{t}}}}; return {*static_cast<const Base*>(this), {{*static_cast<const Base*>(this), rhs{t}}}};
} }
template<typename T> template <typename T>
auto operator -=(T t) const -> assignment_t<Base, minus_t<Base, value_type_t<T>, wrap_operand_t<T>>> auto operator-=(T t) const -> assignment_t<Base, minus_t<Base, value_type_t<T>, wrap_operand_t<T>>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *static_cast<const Base*>(this), {{*static_cast<const Base*>(this), rhs{t}}}}; return {*static_cast<const Base*>(this), {{*static_cast<const Base*>(this), rhs{t}}}};
} }
template<typename T> template <typename T>
auto operator /=(T t) const -> assignment_t<Base, divides_t<Base, wrap_operand_t<T>>> auto operator/=(T t) const -> assignment_t<Base, divides_t<Base, wrap_operand_t<T>>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *static_cast<const Base*>(this), {{*static_cast<const Base*>(this), rhs{t}}}}; return {*static_cast<const Base*>(this), {{*static_cast<const Base*>(this), rhs{t}}}};
} }
template<typename T> template <typename T>
auto operator *=(T t) const -> assignment_t<Base, multiplies_t<Base, value_type_t<T>, wrap_operand_t<T>>> auto operator*=(T t) const -> assignment_t<Base, multiplies_t<Base, value_type_t<T>, wrap_operand_t<T>>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *static_cast<const Base*>(this), {{*static_cast<const Base*>(this), rhs{t}}}}; return {*static_cast<const Base*>(this), {{*static_cast<const Base*>(this), rhs{t}}}};
} }
}; };
// 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()
{ {
@ -301,7 +300,7 @@ namespace sqlpp
return _value; return _value;
} }
template<typename Target> template <typename Target>
void _bind(Target& target, size_t i) void _bind(Target& target, size_t i)
{ {
target._bind_integral_result(i, &_value, &_is_null); target._bind_integral_result(i, &_value, &_is_null);
@ -314,7 +313,7 @@ namespace sqlpp
}; };
// ostream operator for integral result field // ostream operator for integral result field
template<typename Db, typename FieldSpec> template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<integral, Db, FieldSpec>& e) inline std::ostream& operator<<(std::ostream& os, const result_field_t<integral, Db, FieldSpec>& e)
{ {
return serialize(e, os); return serialize(e, os);
@ -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

@ -31,13 +31,11 @@
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

@ -34,8 +34,9 @@
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;
@ -45,33 +46,37 @@ namespace sqlpp
serialize(element, context); serialize(element, context);
} }
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

@ -35,17 +35,17 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Db> template <typename Db>
struct interpretable_t struct interpretable_t
{ {
using _serializer_context_t = typename Db::_serializer_context_t; using _serializer_context_t = typename Db::_serializer_context_t;
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;
@ -59,10 +59,11 @@ 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);
} }
@ -82,13 +83,13 @@ namespace sqlpp
virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0; virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0;
}; };
template<typename T> template <typename T>
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
{ {
@ -114,7 +115,7 @@ namespace sqlpp
std::shared_ptr<const _impl_base> _impl; std::shared_ptr<const _impl_base> _impl;
}; };
template<typename Context, typename Database> template <typename Context, typename Database>
struct serializer_t<Context, interpretable_t<Database>> struct serializer_t<Context, interpretable_t<Database>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -134,7 +135,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -32,7 +32,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Db> template <typename Db>
struct interpretable_list_t struct interpretable_list_t
{ {
std::vector<interpretable_t<Db>> _serializables; std::vector<interpretable_t<Db>> _serializables;
@ -47,15 +47,14 @@ namespace sqlpp
return _serializables.empty(); return _serializables.empty();
} }
template<typename Expr> template <typename Expr>
void emplace_back(Expr expr) void emplace_back(Expr expr)
{ {
_serializables.emplace_back(expr); _serializables.emplace_back(expr);
} }
}; };
template<> template <>
struct interpretable_list_t<void> struct interpretable_list_t<void>
{ {
static constexpr std::size_t size() static constexpr std::size_t size()
@ -67,15 +66,14 @@ namespace sqlpp
{ {
return true; return true;
} }
}; };
template<typename Context, typename List> template <typename Context, typename List>
struct serializable_list_interpreter_t struct serializable_list_interpreter_t
{ {
using T = List; using T = List;
template<typename Separator> template <typename Separator>
static Context& _(const T& t, const Separator& separator, Context& context) static Context& _(const T& t, const Separator& separator, Context& context)
{ {
bool first = true; bool first = true;
@ -92,25 +90,24 @@ namespace sqlpp
} }
}; };
template<typename Context> template <typename Context>
struct serializable_list_interpreter_t<Context, interpretable_list_t<void>> struct serializable_list_interpreter_t<Context, interpretable_list_t<void>>
{ {
using T = interpretable_list_t<void>; using T = interpretable_list_t<void>;
template<typename Separator> template <typename Separator>
static Context& _(const T&, const Separator& /* separator */, Context& context) static Context& _(const T&, const Separator& /* separator */, Context& context)
{ {
return context; return context;
} }
}; };
template<typename T, typename Separator, typename Context> template <typename T, typename Separator, typename Context>
auto interpret_list(const T& t, const Separator& separator, Context& context) auto interpret_list(const T& t, const Separator& separator, Context& context)
-> decltype(serializable_list_interpreter_t<Context, T>::_(t, separator, context)) -> decltype(serializable_list_interpreter_t<Context, T>::_(t, separator, context))
{ {
return serializable_list_interpreter_t<Context, T>::_(t, separator, context); return serializable_list_interpreter_t<Context, T>::_(t, separator, context);
} }
} }
#endif #endif

View File

@ -31,7 +31,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Context, typename T, typename Enable = void> template <typename Context, typename T, typename Enable = void>
struct interpreter_t struct interpreter_t
{ {
static void _(const T&, Context&) static void _(const T&, Context&)
@ -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

@ -38,12 +38,12 @@
namespace sqlpp namespace sqlpp
{ {
// A SINGLE TABLE DATA // A SINGLE TABLE DATA
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;
@ -55,7 +55,7 @@ namespace sqlpp
}; };
// A SINGLE TABLE // A SINGLE TABLE
template<typename Database, typename Table> template <typename Database, typename Table>
struct into_t struct into_t
{ {
using _traits = make_traits<no_value_t, tag::is_into>; using _traits = make_traits<no_value_t, tag::is_into>;
@ -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>
@ -73,16 +75,22 @@ namespace sqlpp
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.into; return t.into;
@ -90,14 +98,13 @@ namespace sqlpp
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
}; };
}; };
struct assert_into_t struct assert_into_t
{ {
using type = std::false_type; using type = std::false_type;
template<typename T = void> template <typename T = void>
static void _() static void _()
{ {
static_assert(wrong_t<T>::value, "into() required"); static_assert(wrong_t<T>::value, "into() required");
@ -114,23 +121,29 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.no_into; return t.no_into;
@ -138,40 +151,39 @@ namespace sqlpp
using _database_t = typename Policies::_database_t; using _database_t = typename Policies::_database_t;
template<typename T> template <typename T>
using _check = logic::all_t<is_raw_table_t<T>::value>; using _check = logic::all_t<is_raw_table_t<T>::value>;
template<typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_into_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_into_t, T>;
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);
} }
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}};
} }
}; };
}; };
// Interpreters // Interpreters
template<typename Context, typename Database, typename Table> template <typename Context, typename Database, typename Table>
struct serializer_t<Context, into_data_t<Database, Table>> struct serializer_t<Context, into_data_t<Database, Table>>
{ {
using _serialize_check = serialize_check_of<Context, Table>; using _serialize_check = serialize_check_of<Context, Table>;
@ -185,7 +197,7 @@ namespace sqlpp
} }
}; };
template<typename T> template <typename T>
auto into(T&& t) -> decltype(statement_t<void, no_into_t>().into(std::forward<T>(t))) auto into(T&& t) -> decltype(statement_t<void, no_into_t>().into(std::forward<T>(t)))
{ {
return statement_t<void, no_into_t>().into(std::forward<T>(t)); return statement_t<void, no_into_t>().into(std::forward<T>(t));

View File

@ -40,7 +40,7 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "is_not_null_"; static constexpr const char _literal[] = "is_not_null_";
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 is_not_null; T is_not_null;
@ -48,9 +48,8 @@ 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;
@ -71,7 +70,7 @@ namespace sqlpp
Operand _operand; Operand _operand;
}; };
template<typename Context, typename Operand> template <typename Context, typename Operand>
struct serializer_t<Context, is_not_null_t<Operand>> struct serializer_t<Context, is_not_null_t<Operand>>
{ {
using _serialize_check = serialize_check_of<Context, Operand>; using _serialize_check = serialize_check_of<Context, Operand>;
@ -84,7 +83,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -40,7 +40,7 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "is_null_"; static constexpr const char _literal[] = "is_null_";
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 is_null; T is_null;
@ -48,9 +48,8 @@ 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;
@ -71,7 +70,7 @@ namespace sqlpp
Operand _operand; Operand _operand;
}; };
template<typename Context, typename Operand> template <typename Context, typename Operand>
struct serializer_t<Context, is_null_t<Operand>> struct serializer_t<Context, is_null_t<Operand>>
{ {
using _serialize_check = serialize_check_of<Context, Operand>; using _serialize_check = serialize_check_of<Context, Operand>;
@ -84,7 +83,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -29,9 +29,9 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Operand> template <typename Operand>
struct is_null_t; struct is_null_t;
template<typename Operand> template <typename Operand>
struct is_not_null_t; struct is_not_null_t;
} }

View File

@ -35,34 +35,35 @@ 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 ";
}; };
struct outer_join_t struct outer_join_t
{ {
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using _provided_outer_tables = detail::make_joined_set_t<provided_tables_of<Lhs>, provided_tables_of<Rhs>>; using _provided_outer_tables = detail::make_joined_set_t<provided_tables_of<Lhs>, provided_tables_of<Rhs>>;
static constexpr const char* _name = " OUTER "; static constexpr const char* _name = " OUTER ";
}; };
struct left_outer_join_t struct left_outer_join_t
{ {
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
using _provided_outer_tables = detail::make_joined_set_t<provided_tables_of<Lhs>, provided_outer_tables_of<Rhs>>; using _provided_outer_tables = detail::make_joined_set_t<provided_tables_of<Lhs>, provided_outer_tables_of<Rhs>>;
static constexpr const char* _name = " LEFT OUTER "; static constexpr const char* _name = " LEFT OUTER ";
}; };
struct right_outer_join_t struct right_outer_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_tables_of<Rhs>>; using _provided_outer_tables = detail::make_joined_set_t<provided_outer_tables_of<Lhs>, provided_tables_of<Rhs>>;
static constexpr const char* _name = " RIGHT OUTER "; static constexpr const char* _name = " RIGHT OUTER ";
}; };
template<typename JoinType, typename Lhs, typename Rhs, typename On = noop> template <typename JoinType, typename Lhs, typename Rhs, typename On = noop>
struct join_t struct join_t
{ {
using _traits = make_traits<no_value_t, tag::is_table, tag::is_join>; using _traits = make_traits<no_value_t, tag::is_table, tag::is_join>;
@ -74,59 +75,57 @@ 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");
template<typename OnT> template <typename OnT>
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>
join_t<inner_join_t, join_t, T> join(T t) join_t<inner_join_t, join_t, T> join(T t)
{ {
static_assert(not is_noop<On>::value, "join type requires on()"); static_assert(not is_noop<On>::value, "join type requires on()");
return { *this, t, {} }; return {*this, t, {}};
} }
template<typename T> template <typename T>
join_t<inner_join_t, join_t, T> inner_join(T t) join_t<inner_join_t, join_t, T> inner_join(T t)
{ {
static_assert(not is_noop<On>::value, "join type requires on()"); static_assert(not is_noop<On>::value, "join type requires on()");
return { *this, t, {} }; return {*this, t, {}};
} }
template<typename T> template <typename T>
join_t<outer_join_t, join_t, T> outer_join(T t) join_t<outer_join_t, join_t, T> outer_join(T t)
{ {
static_assert(not is_noop<On>::value, "join type requires on()"); static_assert(not is_noop<On>::value, "join type requires on()");
return { *this, t, {} }; return {*this, t, {}};
} }
template<typename T> template <typename T>
join_t<left_outer_join_t, join_t, T> left_outer_join(T t) join_t<left_outer_join_t, join_t, T> left_outer_join(T t)
{ {
static_assert(not is_noop<On>::value, "join type requires on()"); static_assert(not is_noop<On>::value, "join type requires on()");
return { *this, t, {} }; return {*this, t, {}};
} }
template<typename T> template <typename T>
join_t<right_outer_join_t, join_t, T> right_outer_join(T t) join_t<right_outer_join_t, join_t, T> right_outer_join(T t)
{ {
static_assert(not is_noop<On>::value, "join type requires on()"); static_assert(not is_noop<On>::value, "join type requires on()");
return { *this, t, {} }; return {*this, t, {}};
} }
Lhs _lhs; Lhs _lhs;
@ -134,7 +133,7 @@ namespace sqlpp
On _on; On _on;
}; };
template<typename Context, typename JoinType, typename Lhs, typename Rhs, typename On> template <typename Context, typename JoinType, typename Lhs, typename Rhs, typename On>
struct serializer_t<Context, join_t<JoinType, Lhs, Rhs, On>> struct serializer_t<Context, join_t<JoinType, Lhs, Rhs, On>>
{ {
using _serialize_check = serialize_check_of<Context, Lhs, Rhs, On>; using _serialize_check = serialize_check_of<Context, Lhs, Rhs, On>;
@ -151,7 +150,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -34,9 +34,8 @@
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>;
@ -46,19 +45,24 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "like_"; static constexpr const char _literal[] = "like_";
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 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;
@ -70,7 +74,7 @@ namespace sqlpp
Pattern _pattern; Pattern _pattern;
}; };
template<typename Context, typename Operand, typename Pattern> template <typename Context, typename Operand, typename Pattern>
struct serializer_t<Context, like_t<Operand, Pattern>> struct serializer_t<Context, like_t<Operand, Pattern>>
{ {
using _serialize_check = serialize_check_of<Context, Operand, Pattern>; using _serialize_check = serialize_check_of<Context, Operand, Pattern>;

View File

@ -34,12 +34,12 @@
namespace sqlpp namespace sqlpp
{ {
// LIMIT DATA // LIMIT DATA
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;
@ -51,7 +51,7 @@ namespace sqlpp
}; };
// LIMIT // LIMIT
template<typename Limit> template <typename Limit>
struct limit_t struct limit_t
{ {
using _traits = make_traits<no_value_t, tag::is_limit>; using _traits = make_traits<no_value_t, tag::is_limit>;
@ -68,16 +68,22 @@ namespace sqlpp
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.limit; return t.limit;
@ -88,18 +94,16 @@ namespace sqlpp
}; };
// DYNAMIC LIMIT DATA // DYNAMIC LIMIT DATA
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))
{ {
} }
@ -114,7 +118,7 @@ namespace sqlpp
}; };
// DYNAMIC LIMIT // DYNAMIC LIMIT
template<typename Database> template <typename Database>
struct dynamic_limit_t struct dynamic_limit_t
{ {
using _traits = make_traits<no_value_t, tag::is_limit>; using _traits = make_traits<no_value_t, tag::is_limit>;
@ -127,7 +131,7 @@ namespace sqlpp
template <typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
template<typename Limit> template <typename Limit>
void set(Limit value) void set(Limit value)
{ {
// FIXME: Make sure that Limit does not require external tables? Need to read up on SQL // FIXME: Make sure that Limit does not require external tables? Need to read up on SQL
@ -136,21 +140,28 @@ 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;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.limit; return t.limit;
@ -169,23 +180,29 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.no_limit; return t.no_limit;
@ -193,45 +210,40 @@ namespace sqlpp
using _database_t = typename Policies::_database_t; using _database_t = typename Policies::_database_t;
template<typename T> template <typename T>
using _check = is_integral_t<wrap_operand_t<T>>; using _check = is_integral_t<wrap_operand_t<T>>;
template<typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_limit_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_limit_t, T>;
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}};
} }
}; };
}; };
// Interpreters // Interpreters
template<typename Context, typename Database> template <typename Context, typename Database>
struct serializer_t<Context, dynamic_limit_data_t<Database>> struct serializer_t<Context, dynamic_limit_data_t<Database>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -248,7 +260,7 @@ namespace sqlpp
} }
}; };
template<typename Context, typename Limit> template <typename Context, typename Limit>
struct serializer_t<Context, limit_data_t<Limit>> struct serializer_t<Context, limit_data_t<Limit>>
{ {
using _serialize_check = serialize_check_of<Context, Limit>; using _serialize_check = serialize_check_of<Context, Limit>;

View File

@ -34,49 +34,42 @@ namespace sqlpp
{ {
namespace logic namespace logic
{ {
template<bool... B> template <bool... B>
struct logic_helper; struct logic_helper;
// 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;
template<> template <>
struct not_impl<true> struct not_impl<true>
{ {
using type = std::false_type; using type = std::false_type;
}; };
template<> template <>
struct not_impl<false> struct not_impl<false>
{ {
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

@ -38,29 +38,33 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "max_"; static constexpr const char _literal[] = "max_";
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 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;
@ -71,7 +75,7 @@ namespace sqlpp
Expr _expr; Expr _expr;
}; };
template<typename Context, typename Expr> template <typename Context, typename Expr>
struct serializer_t<Context, max_t<Expr>> struct serializer_t<Context, max_t<Expr>>
{ {
using _serialize_check = serialize_check_of<Context, Expr>; using _serialize_check = serialize_check_of<Context, Expr>;
@ -86,14 +90,14 @@ 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

@ -38,29 +38,33 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "min_"; static constexpr const char _literal[] = "min_";
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 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;
@ -71,7 +75,7 @@ namespace sqlpp
Expr _expr; Expr _expr;
}; };
template<typename Context, typename Expr> template <typename Context, typename Expr>
struct serializer_t<Context, min_t<Expr>> struct serializer_t<Context, min_t<Expr>>
{ {
using _serialize_check = serialize_check_of<Context, Expr>; using _serialize_check = serialize_check_of<Context, Expr>;
@ -86,14 +90,14 @@ 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

@ -35,24 +35,25 @@
namespace sqlpp namespace sqlpp
{ {
template<typename AliasProvider, typename... Columns> template <typename AliasProvider, typename... Columns>
struct multi_column_alias_t; struct multi_column_alias_t;
template<typename Unused, typename... Columns> template <typename Unused, typename... Columns>
struct multi_column_t struct multi_column_t
{ {
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;
@ -60,36 +61,37 @@ namespace sqlpp
multi_column_t& operator=(multi_column_t&&) = default; multi_column_t& operator=(multi_column_t&&) = default;
~multi_column_t() = default; ~multi_column_t() = default;
template<typename AliasProvider> template <typename AliasProvider>
multi_column_alias_t<AliasProvider, Columns...> as(const AliasProvider&) multi_column_alias_t<AliasProvider, Columns...> as(const AliasProvider&)
{ {
return { *this }; return {*this};
} }
std::tuple<Columns...> _columns; std::tuple<Columns...> _columns;
}; };
template<typename AliasProvider, typename... Columns> template <typename AliasProvider, typename... Columns>
struct multi_column_alias_t struct multi_column_alias_t
{ {
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;
@ -100,7 +102,7 @@ namespace sqlpp
std::tuple<Columns...> _columns; std::tuple<Columns...> _columns;
}; };
template<typename Context, typename... Columns> template <typename Context, typename... Columns>
struct serializer_t<Context, multi_column_t<void, Columns...>> struct serializer_t<Context, multi_column_t<void, Columns...>>
{ {
using _serialize_check = serialize_check_of<Context, Columns...>; using _serialize_check = serialize_check_of<Context, Columns...>;
@ -112,7 +114,7 @@ namespace sqlpp
} }
}; };
template<typename Context, typename AliasProvider, typename... Columns> template <typename Context, typename AliasProvider, typename... Columns>
struct serializer_t<Context, multi_column_alias_t<AliasProvider, Columns...>> struct serializer_t<Context, multi_column_alias_t<AliasProvider, Columns...>>
{ {
using _serialize_check = serialize_check_of<Context, Columns...>; using _serialize_check = serialize_check_of<Context, Columns...>;
@ -127,20 +129,16 @@ namespace sqlpp
namespace detail namespace detail
{ {
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

@ -34,17 +34,17 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Db> template <typename Db>
struct named_interpretable_t struct named_interpretable_t
{ {
using _serializer_context_t = typename Db::_serializer_context_t; using _serializer_context_t = typename Db::_serializer_context_t;
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;
@ -58,10 +58,11 @@ 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);
} }
@ -87,13 +88,13 @@ namespace sqlpp
virtual std::string _get_name() const = 0; virtual std::string _get_name() const = 0;
}; };
template<typename T> template <typename T>
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
{ {
@ -124,7 +125,7 @@ namespace sqlpp
std::shared_ptr<const _impl_base> _impl; std::shared_ptr<const _impl_base> _impl;
}; };
template<typename Context, typename Database> template <typename Context, typename Database>
struct serializer_t<Context, named_interpretable_t<Database>> struct serializer_t<Context, named_interpretable_t<Database>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -144,7 +145,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -32,9 +32,11 @@
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>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;

View File

@ -37,15 +37,14 @@ namespace sqlpp
using _tag = void; using _tag = void;
}; };
template<typename Base> template <typename Base>
struct expression_operators<Base, no_value_t> struct expression_operators<Base, no_value_t>
{ {
}; };
template<typename Base> template <typename Base>
struct column_operators<Base, no_value_t> struct column_operators<Base, no_value_t>
{ {
}; };
} }
#endif #endif

View File

@ -39,9 +39,11 @@ 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
{ {
using _statement_t = Statement; using _statement_t = Statement;
@ -52,36 +54,34 @@ namespace sqlpp
} }
// Execute // Execute
template<typename Db, typename Composite> template <typename Db, typename Composite>
auto _run(Db& db, const Composite& composite) const -> size_t auto _run(Db& db, const Composite& composite) const -> size_t
{ {
return db.execute(composite); return db.execute(composite);
} }
template<typename Db> template <typename Db>
auto _run(Db& db) const -> size_t auto _run(Db& db) const -> size_t
{ {
return db.execute(_get_statement()); return db.execute(_get_statement());
} }
// 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())};
} }
}; };
}; };
template<typename Context> template <typename Context>
struct serializer_t<Context, noop> struct serializer_t<Context, noop>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -93,8 +93,9 @@ 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

@ -31,7 +31,7 @@ namespace sqlpp
{ {
struct noop; struct noop;
template<typename T> template <typename T>
struct is_noop; struct is_noop;
} }
#endif #endif

View File

@ -41,7 +41,7 @@ namespace sqlpp
{ {
static constexpr const char _literal[] = "not_in_"; static constexpr const char _literal[] = "not_in_";
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 in; T in;
@ -49,9 +49,8 @@ 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;
@ -76,7 +74,7 @@ namespace sqlpp
std::tuple<Args...> _args; std::tuple<Args...> _args;
}; };
template<typename Context, typename Operand, typename... Args> template <typename Context, typename Operand, typename... Args>
struct serializer_t<Context, not_in_t<Operand, Args...>> struct serializer_t<Context, not_in_t<Operand, Args...>>
{ {
using _serialize_check = serialize_check_of<Context, Args...>; using _serialize_check = serialize_check_of<Context, Args...>;
@ -95,10 +93,10 @@ namespace sqlpp
} }
}; };
template<typename Container> template <typename Container>
struct value_list_t; struct value_list_t;
template<typename Context, typename Operand, typename Container> template <typename Context, typename Operand, typename Container>
struct serializer_t<Context, not_in_t<Operand, value_list_t<Container>>> struct serializer_t<Context, not_in_t<Operand, value_list_t<Container>>>
{ {
using _serialize_check = serialize_check_of<Context, value_list_t<Container>>; using _serialize_check = serialize_check_of<Context, value_list_t<Container>>;
@ -121,8 +119,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -37,7 +37,7 @@ namespace sqlpp
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
}; };
template<typename Context> template <typename Context>
struct serializer_t<Context, null_t> struct serializer_t<Context, null_t>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -51,7 +51,6 @@ namespace sqlpp
}; };
constexpr null_t null = {}; constexpr null_t null = {};
} }
#endif #endif

View File

@ -34,12 +34,12 @@
namespace sqlpp namespace sqlpp
{ {
// OFFSET DATA // OFFSET DATA
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;
@ -51,7 +51,7 @@ namespace sqlpp
}; };
// OFFSET // OFFSET
template<typename Offset> template <typename Offset>
struct offset_t struct offset_t
{ {
using _traits = make_traits<no_value_t, tag::is_offset>; using _traits = make_traits<no_value_t, tag::is_offset>;
@ -70,16 +70,22 @@ namespace sqlpp
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.offset; return t.offset;
@ -90,18 +96,16 @@ namespace sqlpp
}; };
// DYNAMIC OFFSET DATA // DYNAMIC OFFSET DATA
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))
{ {
} }
@ -116,7 +120,7 @@ namespace sqlpp
}; };
// DYNAMIC OFFSET // DYNAMIC OFFSET
template<typename Database> template <typename Database>
struct dynamic_offset_t struct dynamic_offset_t
{ {
using _traits = make_traits<no_value_t, tag::is_offset>; using _traits = make_traits<no_value_t, tag::is_offset>;
@ -129,7 +133,7 @@ namespace sqlpp
template <typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
template<typename Offset> template <typename Offset>
void set(Offset value) void set(Offset value)
{ {
// FIXME: Make sure that Offset does not require external tables? Need to read up on SQL // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL
@ -138,21 +142,28 @@ 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;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.offset; return t.offset;
@ -160,7 +171,7 @@ namespace sqlpp
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
template<typename Offset> template <typename Offset>
void set_offset(Offset value) void set_offset(Offset value)
{ {
// FIXME: Make sure that Offset does not require external tables? Need to read up on SQL // FIXME: Make sure that Offset does not require external tables? Need to read up on SQL
@ -183,23 +194,29 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.no_offset; return t.no_offset;
@ -207,46 +224,42 @@ namespace sqlpp
using _database_t = typename Policies::_database_t; using _database_t = typename Policies::_database_t;
template<typename T> template <typename T>
using _check = is_integral_t<wrap_operand_t<T>>; using _check = is_integral_t<wrap_operand_t<T>>;
template<typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_offset_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_offset_t, T>;
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,
return { static_cast<const derived_statement_t<Policies>&>(*this), dynamic_offset_data_t<_database_t>{} }; "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>{}};
} }
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}};
} }
}; };
}; };
// Interpreters // Interpreters
template<typename Context, typename Offset> template <typename Context, typename Offset>
struct serializer_t<Context, offset_data_t<Offset>> struct serializer_t<Context, offset_data_t<Offset>>
{ {
using _serialize_check = serialize_check_of<Context, Offset>; using _serialize_check = serialize_check_of<Context, Offset>;
@ -260,7 +273,7 @@ namespace sqlpp
} }
}; };
template<typename Context, typename Database> template <typename Context, typename Database>
struct serializer_t<Context, dynamic_offset_data_t<Database>> struct serializer_t<Context, dynamic_offset_data_t<Database>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;

View File

@ -34,7 +34,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Database, typename... Expressions> template <typename Database, typename... Expressions>
struct on_t struct on_t
{ {
using _traits = make_traits<no_value_t, tag::is_on>; using _traits = make_traits<no_value_t, tag::is_on>;
@ -44,7 +44,7 @@ namespace sqlpp
static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in on()"); static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in on()");
template<typename Expr> template <typename Expr>
void add(Expr expr) void add(Expr expr)
{ {
static_assert(_is_dynamic::value, "on::add() must not be called for static on()"); static_assert(_is_dynamic::value, "on::add() must not be called for static on()");
@ -58,13 +58,13 @@ namespace sqlpp
} }
private: private:
template<typename Expr> template <typename Expr>
void _add_impl(Expr expr, const std::true_type&) void _add_impl(Expr expr, const std::true_type&)
{ {
return _dynamic_expressions.emplace_back(expr); return _dynamic_expressions.emplace_back(expr);
} }
template<typename Expr> template <typename Expr>
void _add_impl(Expr expr, const std::false_type&); void _add_impl(Expr expr, const std::false_type&);
public: public:
@ -72,7 +72,7 @@ namespace sqlpp
interpretable_list_t<Database> _dynamic_expressions; interpretable_list_t<Database> _dynamic_expressions;
}; };
template<typename Context, typename Database, typename... Expressions> template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, on_t<Database, Expressions...>> struct serializer_t<Context, on_t<Database, Expressions...>>
{ {
using _serialize_check = serialize_check_of<Context, Expressions...>; using _serialize_check = serialize_check_of<Context, Expressions...>;
@ -90,7 +90,6 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -38,12 +38,12 @@
namespace sqlpp namespace sqlpp
{ {
// ORDER BY DATA // ORDER BY DATA
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;
@ -59,15 +59,16 @@ namespace sqlpp
{ {
using type = std::false_type; using type = std::false_type;
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");
} }
}; };
// ORDER BY // ORDER BY
template<typename Database, typename... Expressions> template <typename Database, typename... Expressions>
struct order_by_t struct order_by_t
{ {
using _traits = make_traits<no_value_t, tag::is_order_by>; using _traits = make_traits<no_value_t, tag::is_order_by>;
@ -79,21 +80,22 @@ namespace sqlpp
using _data_t = order_by_data_t<Database, Expressions...>; using _data_t = order_by_data_t<Database, Expressions...>;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
template<typename Expression> template <typename Expression>
void add_ntc(Expression expression) void add_ntc(Expression expression)
{ {
add<Expression, std::false_type>(expression); add<Expression, std::false_type>(expression);
} }
template<typename Expression, typename TableCheckRequired = std::true_type> template <typename Expression, typename TableCheckRequired = std::true_type>
void add(Expression expression) void add(Expression expression)
{ {
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::_();
@ -103,29 +105,36 @@ namespace sqlpp
} }
private: private:
template<typename Expression> template <typename Expression>
void _add_impl(Expression expression, const std::true_type&) void _add_impl(Expression expression, const std::true_type&)
{ {
return _data._dynamic_expressions.emplace_back(expression); return _data._dynamic_expressions.emplace_back(expression);
} }
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;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.order_by; return t.order_by;
@ -147,23 +156,29 @@ namespace sqlpp
using _data_t = no_data_t; using _data_t = no_data_t;
// Member implementation with data and methods // Member implementation with data and methods
template<typename Policies> template <typename Policies>
struct _impl_t struct _impl_t
{ {
_data_t _data; _data_t _data;
}; };
// Base template to be inherited by the statement // Base template to be inherited by the statement
template<typename Policies> template <typename Policies>
struct _base_t struct _base_t
{ {
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)
{ {
return t.no_order_by; return t.no_order_by;
@ -171,15 +186,15 @@ namespace sqlpp
using _database_t = typename Policies::_database_t; using _database_t = typename Policies::_database_t;
template<typename... T> template <typename... T>
using _check = logic::all_t<is_sort_order_t<T>::value...>; using _check = logic::all_t<is_sort_order_t<T>::value...>;
template<typename Check, typename T> template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_order_by_t, T>; using _new_statement_t = new_statement_t<Check::value, Policies, no_order_by_t, T>;
using _consistency_check = consistent_t; using _consistency_check = consistent_t;
template<typename... Expressions> template <typename... Expressions>
auto order_by(Expressions... expressions) const auto order_by(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, order_by_t<void, Expressions...>> -> _new_statement_t<_check<Expressions...>, order_by_t<void, Expressions...>>
{ {
@ -189,34 +204,36 @@ namespace sqlpp
return _order_by_impl<void>(_check<Expressions...>{}, expressions...); return _order_by_impl<void>(_check<Expressions...>{}, expressions...);
} }
template<typename... Expressions> template <typename... Expressions>
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...);
} }
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...}};
} }
}; };
}; };
// Interpreters // Interpreters
template<typename Context, typename Database, typename... Expressions> template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, order_by_data_t<Database, Expressions...>> struct serializer_t<Context, order_by_data_t<Database, Expressions...>>
{ {
using _serialize_check = serialize_check_of<Context, Expressions...>; using _serialize_check = serialize_check_of<Context, Expressions...>;

View File

@ -33,9 +33,8 @@
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;
@ -55,7 +55,7 @@ namespace sqlpp
~parameter_t() = default; ~parameter_t() = default;
}; };
template<typename Context, typename ValueType, typename NameType> template <typename Context, typename ValueType, typename NameType>
struct serializer_t<Context, parameter_t<ValueType, NameType>> struct serializer_t<Context, parameter_t<ValueType, NameType>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -68,23 +68,20 @@ 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

@ -34,39 +34,40 @@
namespace sqlpp namespace sqlpp
{ {
template<typename T> template <typename T>
struct parameter_list_t struct parameter_list_t
{ {
static_assert(wrong_t<parameter_list_t>::value, "Template parameter for parameter_list_t has to be a type_vector"); static_assert(wrong_t<parameter_list_t>::value, "Template parameter for parameter_list_t has to be a type_vector");
}; };
template<typename... Parameter> template <typename... Parameter>
struct parameter_list_t<detail::type_vector<Parameter...>>: public Parameter::_instance_t... struct parameter_list_t<detail::type_vector<Parameter...>> : public Parameter::_instance_t...
{ {
using _member_tuple_t = std::tuple<typename Parameter::_instance_t...>; using _member_tuple_t = std::tuple<typename Parameter::_instance_t...>;
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
{ {
_bind_impl(target, detail::make_index_sequence<size::value>{}); _bind_impl(target, detail::make_index_sequence<size::value>{});
} }
private: private:
template<typename Target, size_t... Is> template <typename Target, size_t... Is>
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

@ -32,43 +32,42 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Needle, typename Replacement> template <typename Needle, typename Replacement>
struct policy_update_impl struct policy_update_impl
{ {
template<typename T> template <typename T>
using _policy_t = typename std::conditional<std::is_same<Needle, T>::value, Replacement, T>::type; using _policy_t = typename std::conditional<std::is_same<Needle, T>::value, Replacement, T>::type;
}; };
template<typename T, typename Needle, typename Replacement> template <typename T, typename Needle, typename Replacement>
using policy_update_t = typename policy_update_impl<Needle, Replacement>::template _policy_t<T>; using policy_update_t = typename policy_update_impl<Needle, Replacement>::template _policy_t<T>;
template<typename Original, typename Needle, typename Replacement> template <typename Original, typename Needle, typename Replacement>
struct update_policies_impl struct update_policies_impl
{ {
using type = typename Original::template _policy_update_t<Needle, Replacement>; using type = typename Original::template _policy_update_t<Needle, Replacement>;
}; };
template<typename Original, typename Needle, typename Replacement> template <typename Original, typename Needle, typename Replacement>
using update_policies_t = typename update_policies_impl<Original, Needle, Replacement>::type; using update_policies_t = typename update_policies_impl<Original, Needle, Replacement>::type;
template<typename Policies, typename Needle, typename Replacement> template <typename Policies, typename Needle, typename Replacement>
using new_statement = typename Policies::template _new_statement_t<Needle, Replacement>; using new_statement = typename Policies::template _new_statement_t<Needle, Replacement>;
template<bool, typename Policies, typename Needle, typename Replacement> template <bool, typename Policies, typename Needle, typename Replacement>
struct new_statement_impl struct new_statement_impl
{ {
using type = typename Policies::template _new_statement_t<Needle, Replacement>; using type = typename Policies::template _new_statement_t<Needle, Replacement>;
}; };
template<typename Policies, typename Needle, typename Replacement> template <typename Policies, typename Needle, typename Replacement>
struct new_statement_impl<false, Policies, Needle, Replacement> struct new_statement_impl<false, Policies, Needle, Replacement>
{ {
using type = bad_statement; using type = bad_statement;
}; };
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

@ -31,8 +31,8 @@
// enable the Clang support // enable the Clang support
#if defined(__clang__) && !BOOST_PP_VARIADICS #if defined(__clang__) && !BOOST_PP_VARIADICS
# undef BOOST_PP_VARIADICS #undef BOOST_PP_VARIADICS
# define BOOST_PP_VARIADICS 1 #define BOOST_PP_VARIADICS 1
#endif // defined(__clang__) #endif // defined(__clang__)
// boost.preprocessor // boost.preprocessor
@ -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

@ -33,7 +33,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Db, typename Statement> template <typename Db, typename Statement>
struct prepared_execute_t struct prepared_execute_t
{ {
using _traits = make_traits<no_value_t, tag::is_prepared_statement>; using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
@ -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

@ -33,7 +33,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Db, typename Insert> template <typename Db, typename Insert>
struct prepared_insert_t struct prepared_insert_t
{ {
using _traits = make_traits<no_value_t, tag::is_prepared_statement>; using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
@ -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

@ -33,7 +33,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Db, typename Remove> template <typename Db, typename Remove>
struct prepared_remove_t struct prepared_remove_t
{ {
using _traits = make_traits<no_value_t, tag::is_prepared_statement>; using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
@ -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

@ -33,7 +33,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Database, typename Statement, typename Composite = Statement> template <typename Database, typename Statement, typename Composite = Statement>
struct prepared_select_t struct prepared_select_t
{ {
using _traits = make_traits<no_value_t, tag::is_prepared_statement>; using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
@ -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

@ -33,7 +33,7 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Db, typename Update> template <typename Db, typename Update>
struct prepared_update_t struct prepared_update_t
{ {
using _traits = make_traits<no_value_t, tag::is_prepared_statement>; using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
@ -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,13 +40,17 @@
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
{ {
using _statement_t = Statement; using _statement_t = Statement;
@ -57,38 +61,34 @@ 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);
} }
template<typename Db> template <typename Db>
auto _run(Db& db) const -> decltype(db.remove(this->_get_statement())) auto _run(Db& db) const -> decltype(db.remove(this->_get_statement()))
{ {
return db.remove(_get_statement()); return db.remove(_get_statement());
} }
// 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>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -102,42 +102,32 @@ 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

@ -30,7 +30,7 @@
// FIXME: include for move? // FIXME: include for move?
namespace sqlpp namespace sqlpp
{ {
template<typename DbResult, typename ResultRow> template <typename DbResult, typename ResultRow>
class result_t class result_t
{ {
using db_result_t = DbResult; using db_result_t = DbResult;
@ -44,10 +44,9 @@ namespace sqlpp
public: public:
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)
{ {
} }
@ -84,7 +81,7 @@ namespace sqlpp
bool operator!=(const iterator& rhs) const bool operator!=(const iterator& rhs) const
{ {
return not (operator==(rhs)); return not(operator==(rhs));
} }
void operator++() void operator++()
@ -120,7 +117,6 @@ namespace sqlpp
{ {
_result.next(_result_row); _result.next(_result_row);
} }
}; };
} }

View File

@ -32,13 +32,13 @@
namespace sqlpp namespace sqlpp
{ {
template<typename ValueType, typename Db, typename FieldSpec> template <typename ValueType, typename Db, typename FieldSpec>
struct result_field_t struct result_field_t
{ {
static_assert(wrong_t<result_field_t>::value, "Missing specialization for result_field_t"); static_assert(wrong_t<result_field_t>::value, "Missing specialization for result_field_t");
}; };
template<typename Context, typename ValueType, typename Db, typename FieldSpec> template <typename Context, typename ValueType, typename Db, typename FieldSpec>
struct serializer_t<Context, result_field_t<ValueType, Db, FieldSpec>> struct serializer_t<Context, result_field_t<ValueType, Db, FieldSpec>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
@ -57,7 +57,5 @@ namespace sqlpp
return context; return context;
} }
}; };
} }
#endif #endif

View File

@ -34,44 +34,45 @@ namespace sqlpp
{ {
namespace detail namespace detail
{ {
template<typename Field> template <typename Field>
struct get_field_spec_impl struct get_field_spec_impl
{ {
static_assert(wrong_t<get_field_spec_impl>::value, "Invalid argument for get_field_spec"); static_assert(wrong_t<get_field_spec_impl>::value, "Invalid argument for get_field_spec");
}; };
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 get_field_spec_impl<Field<ValueType, Db, FieldSpec>> struct get_field_spec_impl<Field<ValueType, Db, FieldSpec>>
{ {
using type = FieldSpec; using type = FieldSpec;
}; };
template<typename Field> template <typename Field>
using get_field_spec_t = typename get_field_spec_impl<Field>::type; using get_field_spec_t = typename get_field_spec_impl<Field>::type;
} }
template<typename Field, typename Enable = void> template <typename Field, typename Enable = void>
struct result_field_methods_base_t struct result_field_methods_base_t
{ {
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

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