0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 12:29:41 +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
BreakConstructorInitializersBeforeComma: false
BinPackParameters: false
ColumnLimit: 160
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false

View File

@ -24,7 +24,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_DATABASE_BIND_RESULT_H
#define SQLPP_DATABASE_BIND_RESULT_H
@ -32,62 +31,61 @@
namespace sqlpp
{
namespace database
{
/*
* bind_result_t binds values of a sqlpp11 result row
* to the results of a statement
*/
class bind_result_t
{
public:
bind_result_t(); // default constructor for a result that will not yield a valid row
bind_result_t(...);
bind_result_t(const bind_result_t&) = delete;
bind_result_t(bind_result_t&& rhs);
bind_result_t& operator=(const bind_result_t&) = delete;
bind_result_t& operator=(bind_result_t&&);
~bind_result_t();
namespace database
{
/*
* bind_result_t binds values of a sqlpp11 result row
* to the results of a statement
*/
class bind_result_t
{
public:
bind_result_t(); // default constructor for a result that will not yield a valid row
bind_result_t(...);
bind_result_t(const bind_result_t&) = delete;
bind_result_t(bind_result_t&& rhs);
bind_result_t& operator=(const bind_result_t&) = delete;
bind_result_t& operator=(bind_result_t&&);
~bind_result_t();
bool operator==(const bind_result_t& rhs) const;
bool operator==(const bind_result_t& rhs) const;
template<typename ResultRow>
void next(ResultRow& result_row);
template <typename ResultRow>
void next(ResultRow& result_row);
// something similar to this:
/*
{
if (!_handle)
{
result_row.invalidate();
return;
}
// something similar to this:
/*
{
if (!_handle)
{
result_row.invalidate();
return;
}
if (next_impl())
{
if (not result_row)
{
result_row.validate();
}
result_row._bind(*this); // bind result row values to results
}
else
{
if (result_row)
result_row.invalidate();
}
};
*/
if (next_impl())
{
if (not result_row)
{
result_row.validate();
}
result_row._bind(*this); // bind result row values to results
}
else
{
if (result_row)
result_row.invalidate();
}
};
*/
// These are called by the result row to bind individual result values
// More will be added over time
void _bind_boolean_result(size_t index, signed char* value, bool* is_null);
void _bind_floating_point_result(size_t index, double* value, bool* is_null);
void _bind_integral_result(size_t index, int64_t* value, bool* is_null);
void _bind_text_result(size_t index, const char** text, size_t* len);
...
};
}
// These are called by the result row to bind individual result values
// More will be added over time
void _bind_boolean_result(size_t index, signed char* value, bool* is_null);
void _bind_floating_point_result(size_t index, double* value, bool* is_null);
void _bind_integral_result(size_t index, int64_t* value, bool* is_null);
void _bind_text_result(size_t index, const char** text, size_t* len);
...
};
}
}
#endif

View File

@ -24,122 +24,125 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_DATABASE_CONNECTION_H
#define SQLPP_DATABASE_CONNECTION_H
#include <string>
#include <sqlpp11/connection.h>
#include <sqlpp11/database/char_result.h> // You may use char result or bind result or both
#include <sqlpp11/database/bind_result.h> // to represent results of select and prepared select
#include <sqlpp11/database/char_result.h> // You may use char result or bind result or both
#include <sqlpp11/database/bind_result.h> // to represent results of select and prepared select
namespace sqlpp
{
namespace database
{
// The context is not a requirement, but if the database requires
// any deviations from the SQL standard, you should use your own
// context in order to specialize the behaviour, see also interpreter.h
struct context_t
{
template<typename T>
std::ostream& operator<<(T t);
namespace database
{
// The context is not a requirement, but if the database requires
// any deviations from the SQL standard, you should use your own
// context in order to specialize the behaviour, see also interpreter.h
struct context_t
{
template <typename 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
{
public:
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
>;
class connection : public sqlpp::connection // this inheritance helps with ADL for dynamic_select, for instance
{
public:
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
>;
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 _interpreter_context_t = << This context is used interpret a statement >>;
// serializer and interpreter are typically the same for string based connectors
// the types are required for dynamic statement components, see sqlpp11/interpretable.h
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 _interpreter_context_t =
<< This context is used interpret a statement >>
;
// serializer and interpreter are typically the same for string based connectors
// the types are required for dynamic statement components, see sqlpp11/interpretable.h
connection(...);
~connection();
connection(const connection&) = delete;
connection(connection&&) = delete;
connection& operator=(const connection&) = delete;
connection& operator=(connection&&) = delete;
connection(...);
~connection();
connection(const connection&) = delete;
connection(connection&&) = delete;
connection& operator=(const connection&) = delete;
connection& operator=(connection&&) = delete;
//! "direct" select
template<typename Select>
<<bind_result_t>> select(const Select& s);
//! "direct" select
template <typename Select>
<< bind_result_t >>
select(const Select& s);
//! prepared select
template<typename Select>
_prepared_statement_t prepare_select(Select& s);
//! prepared select
template <typename Select>
_prepared_statement_t prepare_select(Select& s);
template<typename PreparedSelect>
<<bind_result_t>> run_prepared_select(const PreparedSelect& s); // call s._bind_params()
template <typename PreparedSelect>
<< bind_result_t >>
run_prepared_select(const PreparedSelect& s); // call s._bind_params()
//! "direct insert
template<typename Insert>
size_t insert(const Insert& i);
//! "direct insert
template <typename Insert>
size_t insert(const Insert& i);
//! prepared insert
template<typename Insert>
_prepared_statement_t prepare_insert(Insert& i);
//! prepared insert
template <typename Insert>
_prepared_statement_t prepare_insert(Insert& i);
template<typename PreparedInsert>
size_t run_prepared_insert(const PreparedInsert& i); // call i._bind_params()
template <typename PreparedInsert>
size_t run_prepared_insert(const PreparedInsert& i); // call i._bind_params()
//! "direct" update
template<typename Update>
size_t update(const Update& u);
//! "direct" update
template <typename Update>
size_t update(const Update& u);
//! "prepared" update
template<typename Update>
_prepared_statement_t prepare_update(Update& u);
//! "prepared" update
template <typename Update>
_prepared_statement_t prepare_update(Update& u);
template<typename PreparedUpdate>
size_t run_prepared_update(const PreparedUpdate& u); // call u._bind_params()
template <typename PreparedUpdate>
size_t run_prepared_update(const PreparedUpdate& u); // call u._bind_params()
//! "direct" remove
template<typename Remove>
size_t remove(const Remove& r)
//! "direct" remove
template <typename Remove>
size_t remove(const Remove& r)
//! prepared remove
template<typename Remove>
_prepared_statement_t prepare_remove(Remove& r);
//! prepared remove
template <typename Remove>
_prepared_statement_t prepare_remove(Remove& r);
template<typename PreparedRemove>
size_t run_prepared_remove(const PreparedRemove& r); // call r._bind_params()
template <typename PreparedRemove>
size_t run_prepared_remove(const PreparedRemove& r); // call r._bind_params()
//! call run on the argument
template<typename T>
auto operator() (const T& t) -> decltype(t._run(*this))
{
return t._run(*this);
}
//! call run on the argument
template <typename T>
auto operator()(const T& t) -> decltype(t._run(*this))
{
return t._run(*this);
}
//! call prepare on the argument
template<typename T>
auto prepare(const T& t) -> decltype(t._prepare(*this))
{
return t._prepare(*this);
}
//! call prepare on the argument
template <typename T>
auto prepare(const T& t) -> decltype(t._prepare(*this))
{
return t._prepare(*this);
}
//! start transaction
void start_transaction();
//! start transaction
void start_transaction();
//! commit transaction (or throw transaction if the transaction has been finished already)
void commit_transaction();
//! commit transaction (or throw transaction if the transaction has been finished already)
void commit_transaction();
//! rollback transaction with or without reporting the rollback (or throw if the transaction has been finished already)
void rollback_transaction(bool report);
//! rollback transaction with or without reporting the rollback (or throw if the transaction has been finished
// already)
void rollback_transaction(bool report);
//! 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;
};
}
//! 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;
};
}
}
#include <sqlpp11/database/interpreter.h>

View File

@ -41,22 +41,21 @@
*/
namespace sqlpp
{
namespace vendor
{
template<typename ValueType, typename NameType>
struct interpreter_t<database::context_t, parameter_t<ValueType, NameType>>
{
using T = parameter_t<ValueType, NameType>;
namespace vendor
{
template <typename ValueType, typename NameType>
struct interpreter_t<database::context_t, parameter_t<ValueType, NameType>>
{
using T = parameter_t<ValueType, NameType>;
static database::context_t& _(const T& t, database::context_t& context)
{
context << "?" << context.count();
context.pop_count();
return context;
}
};
}
static database::context_t& _(const T& t, database::context_t& context)
{
context << "?" << context.count();
context.pop_count();
return context;
}
};
}
}
#endif

View File

@ -24,7 +24,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_DATABASE_PREPARED_STATEMENT_H
#define SQLPP_DATABASE_PREPARED_STATEMENT_H
@ -33,28 +32,28 @@
namespace sqlpp
{
namespace database
{
class prepared_statement_t
{
public:
prepared_statement_t() = delete;
prepared_statement_t(...);
prepared_statement_t(const prepared_statement_t&) = delete;
prepared_statement_t(prepared_statement_t&& rhs);
prepared_statement_t& operator=(const prepared_statement_t&) = delete;
prepared_statement_t& operator=(prepared_statement_t&&);
~prepared_statement_t();
namespace database
{
class prepared_statement_t
{
public:
prepared_statement_t() = delete;
prepared_statement_t(...);
prepared_statement_t(const prepared_statement_t&) = delete;
prepared_statement_t(prepared_statement_t&& rhs);
prepared_statement_t& operator=(const prepared_statement_t&) = delete;
prepared_statement_t& operator=(prepared_statement_t&&);
~prepared_statement_t();
bool operator==(const prepared_statement_t& rhs) const;
bool operator==(const prepared_statement_t& rhs) const;
// These are called by the sqlpp11::prepared_*_t to bind the individual parameters
// More will be added over time
void _bind_boolean_parameter(size_t index, const signed char* value, bool is_null);
void _bind_floating_point_parameter(size_t index, const double* value, bool is_null);
void _bind_integral_parameter(size_t index, const int64_t* value, bool is_null);
void _bind_text_parameter(size_t index, const std::string* value, bool is_null);
};
}
// These are called by the sqlpp11::prepared_*_t to bind the individual parameters
// More will be added over time
void _bind_boolean_parameter(size_t index, const signed char* value, bool is_null);
void _bind_floating_point_parameter(size_t index, const double* value, bool is_null);
void _bind_integral_parameter(size_t index, const int64_t* value, bool is_null);
void _bind_text_parameter(size_t index, const std::string* value, bool is_null);
};
}
}
#endif

View File

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

View File

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

View File

@ -29,40 +29,38 @@
int insert(int, char**)
{
MockDb db;
MockDb db;
test::TabPerson p;
test::TabFeature f;
test::TabPerson p;
test::TabFeature f;
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());
auto i = insert_into(p).columns(p.name, p.feature);
i.values.add(p.name = "Roland", p.feature = 1);
i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value);
db(i);
auto i = insert_into(p).columns(p.name, p.feature);
i.values.add(p.name = "Roland", p.feature = 1);
i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value);
db(i);
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.feature = true;
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.feature = true;
db(pi);
return 0;
db(pi);
return 0;
}

View File

@ -24,7 +24,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if 0 // syntax example
#if 0 // syntax example
SQLPP_DECLARE_TABLE(
(table, \
SQLPP_DROP_IF_EXISTS \
@ -45,6 +45,7 @@ SQLPP_DECLARE_TABLE(
#include "MockDb.h"
// clang-format off
SQLPP_DECLARE_TABLE(
(tab_person)
,
@ -60,42 +61,41 @@ SQLPP_DECLARE_TABLE(
(name , varchar(255), SQLPP_NULL )
(fatal, bool , SQLPP_NOT_NULL )
)
// clang-format on
int ppgen(int, char**)
{
MockDb db;
tab_person::tab_person p;
tab_feature::tab_feature f;
MockDb db;
tab_person::tab_person p;
tab_feature::tab_feature f;
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());
auto i = insert_into(p).columns(p.name, p.feature);
i.values.add(p.name = "Roland", p.feature = 1);
i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value);
db(i);
auto i = insert_into(p).columns(p.name, p.feature);
i.values.add(p.name = "Roland", p.feature = 1);
i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value);
db(i);
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.feature = true;
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.feature = true;
db(pi);
return 0;
db(pi);
return 0;
}

View File

@ -29,13 +29,11 @@
int remove(int, char**)
{
MockDb db;
MockDb db;
test::TabPerson p;
test::TabFeature q;
test::TabPerson p;
test::TabFeature q;
db(remove_from(p)
.using_(p, q)
.where(p.feature == q.id and q.fatal == true));
return 0;
db(remove_from(p).using_(p, q).where(p.feature == q.id and q.fatal == true));
return 0;
}

View File

@ -29,31 +29,28 @@
int main()
{
MockDb db;
MockDb db;
test::TabPerson p;
test::TabFeature f;
test::TabPerson p;
test::TabFeature f;
db(insert_into(f).set(f.name = "Loves C++", p.fatal = false));
db(insert_into(f).set(f.name = "Loves C++", p.fatal = false));
db(insert_into(f).set(p.name = "Roland", p.feature = 1));
db(insert_into(f).set(p.name = "Roland", p.feature = 1));
auto s = select(all_of(p))
.from(p, q)
.where(p.name == any(select(q.name)
.from(q)
.where(true)))
.group_by(q.name)
.having(p.name.like("%Bee%"))
.order_by(p.name.asc())
.limit(3).offset(7);
auto s = select(all_of(p))
.from(p, q)
.where(p.name == any(select(q.name).from(q).where(true)))
.group_by(q.name)
.having(p.name.like("%Bee%"))
.order_by(p.name.asc())
.limit(3)
.offset(7);
auto x = s.as(sqlpp::alias::x);
for (const auto& row : db(select(p.id, x.name)
.from(p.join(x).on(p.feature == x.feature))
.where(true)))
{
int id = row.id;
std::string name = row.name;
}
auto x = s.as(sqlpp::alias::x);
for (const auto& row : db(select(p.id, x.name).from(p.join(x).on(p.feature == x.feature)).where(true)))
{
int id = row.id;
std::string name = row.name;
}
}

View File

@ -38,23 +38,22 @@ SQLPP_ALIAS_PROVIDER(cheesecake)
int select(int, char**)
{
static constexpr bool some_condition = true;
static constexpr bool some_other_condition = false;
static constexpr bool some_condition = true;
static constexpr bool some_other_condition = false;
MockDb db;
MockDb db;
test::TabPerson p;
test::TabFeature f;
test::TabPerson p;
test::TabFeature f;
for (const auto& row : db(select(all_of(p)).from(p).where(p.id > 7)))
{
int64_t id = row.id;
std::string name = row.name;
int64_t feature = row.feature;
}
for (const auto& row : db(select(all_of(p)).from(p).where(p.id > 7)))
{
int64_t id = row.id;
std::string name = row.name;
int64_t feature = row.feature;
}
#if 0
#if 0
for (const auto& row : db(select(p.name).from(p).where(p.name.like("Herb%"))))
{
int64_t id = row.id;
@ -63,8 +62,6 @@ int select(int, char**)
}
#endif
#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)))
{
@ -75,8 +72,6 @@ int select(int, char**)
}
#endif
#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)))
{
@ -88,12 +83,6 @@ int select(int, char**)
}
#endif
#if 0
auto s = select(p.id, p.name, f.id.as(cheesecake))
.from(p, f)
@ -117,41 +106,21 @@ int select(int, char**)
}
#endif
#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();
if (some_condition)
dysel.selected_columns.add(p.feature);
if (some_condition)
dysel.selected_columns.add(p.feature);
if (some_other_condition)
dysel.where.add(p.id > 17);
if (some_other_condition)
dysel.where.add(p.id > 17);
for (const auto& row : db(dysel))
{
std::string name = row.name;
std::string feature = row.at("feature");
}
for (const auto& row : db(dysel))
{
std::string name = row.name;
std::string feature = row.at("feature");
}
#endif
return 0;
return 0;
}

View File

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

View File

@ -32,45 +32,44 @@
namespace sqlpp
{
template<typename Expression, typename AliasProvider>
struct expression_alias_t
{
using _traits = make_traits<value_type_of<Expression>, tag::is_selectable, tag::is_alias>;
using _nodes = detail::type_vector<Expression>;
template <typename Expression, typename AliasProvider>
struct expression_alias_t
{
using _traits = make_traits<value_type_of<Expression>, tag::is_selectable, tag::is_alias>;
using _nodes = detail::type_vector<Expression>;
static_assert(is_expression_t<Expression>::value, "invalid argument for an expression alias");
static_assert(not is_alias_t<Expression>::value, "cannot create an alias of an alias");
static_assert(is_expression_t<Expression>::value, "invalid argument for an expression alias");
static_assert(not is_alias_t<Expression>::value, "cannot create an alias of an alias");
using _alias_t = typename AliasProvider::_alias_t;
using _alias_t = typename AliasProvider::_alias_t;
expression_alias_t(Expression expression):
_expression(expression)
{}
expression_alias_t(Expression expression) : _expression(expression)
{
}
expression_alias_t(const expression_alias_t&) = default;
expression_alias_t(expression_alias_t&&) = default;
expression_alias_t& operator=(const expression_alias_t&) = default;
expression_alias_t& operator=(expression_alias_t&&) = default;
~expression_alias_t() = default;
expression_alias_t(const expression_alias_t&) = default;
expression_alias_t(expression_alias_t&&) = default;
expression_alias_t& operator=(const expression_alias_t&) = default;
expression_alias_t& operator=(expression_alias_t&&) = default;
~expression_alias_t() = default;
Expression _expression;
};
Expression _expression;
};
template<typename Context, typename Expression, typename AliasProvider>
struct serializer_t<Context, expression_alias_t<Expression, AliasProvider>>
{
using _serialize_check = serialize_check_of<Context, Expression>;
using T = expression_alias_t<Expression, AliasProvider>;
static Context& _(const T& t, Context& context)
{
serialize_operand(t._expression, context);
context << " AS ";
context << name_of<T>::char_ptr();
return context;
}
};
template <typename Context, typename Expression, typename AliasProvider>
struct serializer_t<Context, expression_alias_t<Expression, AliasProvider>>
{
using _serialize_check = serialize_check_of<Context, Expression>;
using T = expression_alias_t<Expression, AliasProvider>;
static Context& _(const T& t, Context& context)
{
serialize_operand(t._expression, context);
context << " AS ";
context << name_of<T>::char_ptr();
return context;
}
};
}
#endif

View File

@ -30,69 +30,76 @@
#include <type_traits>
#include <sqlpp11/char_sequence.h>
#define SQLPP_ALIAS_PROVIDER(name) \
struct name##_t\
{\
struct _alias_t\
{\
static constexpr const char _literal[] = #name;\
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;\
template<typename T>\
struct _member_t\
{\
T name;\
T& operator()() { return name; }\
const T& operator()() const { return name; }\
};\
};\
};\
constexpr name##_t name = {};
#define SQLPP_ALIAS_PROVIDER(name) \
struct name##_t \
{ \
struct _alias_t \
{ \
static constexpr const char _literal[] = #name; \
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>; \
template <typename T> \
struct _member_t \
{ \
T name; \
T& operator()() \
{ \
return name; \
} \
const T& operator()() const \
{ \
return name; \
} \
}; \
}; \
}; \
constexpr name##_t name = {};
namespace sqlpp
{
template<typename T, typename Enable = void>
struct is_alias_provider_t
{
static constexpr bool value = false;
};
template <typename T, typename Enable = void>
struct is_alias_provider_t
{
static constexpr bool value = false;
};
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>
{
static constexpr bool value = true;
};
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>
{
static constexpr bool value = true;
};
namespace alias
{
SQLPP_ALIAS_PROVIDER(a)
SQLPP_ALIAS_PROVIDER(b)
SQLPP_ALIAS_PROVIDER(c)
SQLPP_ALIAS_PROVIDER(d)
SQLPP_ALIAS_PROVIDER(e)
SQLPP_ALIAS_PROVIDER(f)
SQLPP_ALIAS_PROVIDER(g)
SQLPP_ALIAS_PROVIDER(h)
SQLPP_ALIAS_PROVIDER(i)
SQLPP_ALIAS_PROVIDER(j)
SQLPP_ALIAS_PROVIDER(k)
SQLPP_ALIAS_PROVIDER(l)
SQLPP_ALIAS_PROVIDER(m)
SQLPP_ALIAS_PROVIDER(n)
SQLPP_ALIAS_PROVIDER(o)
SQLPP_ALIAS_PROVIDER(p)
SQLPP_ALIAS_PROVIDER(q)
SQLPP_ALIAS_PROVIDER(s)
SQLPP_ALIAS_PROVIDER(t)
SQLPP_ALIAS_PROVIDER(u)
SQLPP_ALIAS_PROVIDER(v)
SQLPP_ALIAS_PROVIDER(w)
SQLPP_ALIAS_PROVIDER(x)
SQLPP_ALIAS_PROVIDER(y)
SQLPP_ALIAS_PROVIDER(z)
SQLPP_ALIAS_PROVIDER(left)
SQLPP_ALIAS_PROVIDER(right)
}
namespace alias
{
SQLPP_ALIAS_PROVIDER(a)
SQLPP_ALIAS_PROVIDER(b)
SQLPP_ALIAS_PROVIDER(c)
SQLPP_ALIAS_PROVIDER(d)
SQLPP_ALIAS_PROVIDER(e)
SQLPP_ALIAS_PROVIDER(f)
SQLPP_ALIAS_PROVIDER(g)
SQLPP_ALIAS_PROVIDER(h)
SQLPP_ALIAS_PROVIDER(i)
SQLPP_ALIAS_PROVIDER(j)
SQLPP_ALIAS_PROVIDER(k)
SQLPP_ALIAS_PROVIDER(l)
SQLPP_ALIAS_PROVIDER(m)
SQLPP_ALIAS_PROVIDER(n)
SQLPP_ALIAS_PROVIDER(o)
SQLPP_ALIAS_PROVIDER(p)
SQLPP_ALIAS_PROVIDER(q)
SQLPP_ALIAS_PROVIDER(s)
SQLPP_ALIAS_PROVIDER(t)
SQLPP_ALIAS_PROVIDER(u)
SQLPP_ALIAS_PROVIDER(v)
SQLPP_ALIAS_PROVIDER(w)
SQLPP_ALIAS_PROVIDER(x)
SQLPP_ALIAS_PROVIDER(y)
SQLPP_ALIAS_PROVIDER(z)
SQLPP_ALIAS_PROVIDER(left)
SQLPP_ALIAS_PROVIDER(right)
}
}
#endif

View File

@ -33,48 +33,46 @@
namespace sqlpp
{
template<typename Table>
struct all_of_t
{
using _column_tuple_t = typename Table::_column_tuple_t;
template <typename Table>
struct all_of_t
{
using _column_tuple_t = typename Table::_column_tuple_t;
template<typename AliasProvider>
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);
}
};
template <typename AliasProvider>
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);
}
};
template<typename Table>
auto all_of(Table) -> all_of_t<Table>
{
return {};
}
template <typename Table>
auto all_of(Table) -> all_of_t<Table>
{
return {};
}
struct assert_no_stand_alone_all_of_t
{
using type = std::false_type;
struct assert_no_stand_alone_all_of_t
{
using type = std::false_type;
template<typename T = void>
static void _()
{
static_assert(wrong_t<T>::value, "all_of(table) seems to be used outside of select");
}
};
template <typename T = void>
static void _()
{
static_assert(wrong_t<T>::value, "all_of(table) seems to be used outside of select");
}
};
template<typename Context, typename Table>
struct serializer_t<Context, all_of_t<Table>>
{
using _serialize_check = assert_no_stand_alone_all_of_t;
using T = all_of_t<Table>;
static Context& _(const T&, const Context&)
{
_serialize_check::_();
}
};
template <typename Context, typename Table>
struct serializer_t<Context, all_of_t<Table>>
{
using _serialize_check = assert_no_stand_alone_all_of_t;
using T = all_of_t<Table>;
static Context& _(const T&, const Context&)
{
_serialize_check::_();
}
};
}
#endif

View File

@ -33,49 +33,49 @@
namespace sqlpp
{
template<typename Select>
struct any_t
{
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
using _nodes = detail::type_vector<Select>;
template <typename Select>
struct any_t
{
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
using _nodes = detail::type_vector<Select>;
any_t(Select select):
_select(select)
{}
any_t(Select select) : _select(select)
{
}
any_t(const any_t&) = default;
any_t(any_t&&) = default;
any_t& operator=(const any_t&) = default;
any_t& operator=(any_t&&) = default;
~any_t() = default;
any_t(const any_t&) = default;
any_t(any_t&&) = default;
any_t& operator=(const any_t&) = default;
any_t& operator=(any_t&&) = default;
~any_t() = default;
Select _select;
};
Select _select;
};
template<typename Context, typename Select>
struct serializer_t<Context, any_t<Select>>
{
using _serialize_check = serialize_check_of<Context, Select>;
using T = any_t<Select>;
template <typename Context, typename Select>
struct serializer_t<Context, any_t<Select>>
{
using _serialize_check = serialize_check_of<Context, Select>;
using T = any_t<Select>;
static Context& _(const T& t, Context& context)
{
context << "ANY(";
serialize(t._select, context);
context << ")";
return context;
}
};
template<typename 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_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?
return { t };
}
static Context& _(const T& t, Context& context)
{
context << "ANY(";
serialize(t._select, context);
context << ")";
return context;
}
};
template <typename 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_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?
return {t};
}
}
#endif

View File

@ -37,46 +37,46 @@
namespace sqlpp
{
template<typename Lhs, typename Rhs>
struct assignment_t
{
using _traits = make_traits<no_value_t, tag::is_assignment>;
using _lhs_t = Lhs;
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>;
template <typename Lhs, typename Rhs>
struct assignment_t
{
using _traits = make_traits<no_value_t, tag::is_assignment>;
using _lhs_t = Lhs;
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>;
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):
_lhs(lhs),
_rhs(rhs)
{}
assignment_t(_lhs_t lhs, _rhs_t rhs) : _lhs(lhs), _rhs(rhs)
{
}
assignment_t(const assignment_t&) = default;
assignment_t(assignment_t&&) = default;
assignment_t& operator=(const assignment_t&) = default;
assignment_t& operator=(assignment_t&&) = default;
~assignment_t() = default;
assignment_t(const assignment_t&) = default;
assignment_t(assignment_t&&) = default;
assignment_t& operator=(const assignment_t&) = default;
assignment_t& operator=(assignment_t&&) = default;
~assignment_t() = default;
_lhs_t _lhs;
_rhs_t _rhs;
};
_lhs_t _lhs;
_rhs_t _rhs;
};
template<typename Context, typename Lhs, typename Rhs>
struct serializer_t<Context, assignment_t<Lhs, Rhs>>
{
using T = assignment_t<Lhs, Rhs>;
using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
static Context& _(const T& t, Context& context)
{
serialize(simple_column(t._lhs), context);
context << "=";
serialize_operand(t._rhs, context);
return context;
}
};
template <typename Context, typename Lhs, typename Rhs>
struct serializer_t<Context, assignment_t<Lhs, Rhs>>
{
using T = assignment_t<Lhs, Rhs>;
using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
static Context& _(const T& t, Context& context)
{
serialize(simple_column(t._lhs), context);
context << "=";
serialize_operand(t._rhs, context);
return context;
}
};
}
#endif

View File

@ -31,36 +31,35 @@
namespace sqlpp
{
template<typename T, typename Enable = void>
struct has_auto_alias_t
{
static constexpr bool value = false;
};
template <typename T, typename Enable = void>
struct has_auto_alias_t
{
static constexpr bool value = false;
};
template<typename T>
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;
};
template <typename T>
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;
};
namespace detail
{
template<typename T, typename Enable = void>
struct auto_alias_impl
{
using type = T;
};
namespace detail
{
template <typename T, typename Enable = void>
struct auto_alias_impl
{
using type = T;
};
template<typename T>
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>;
};
}
template <typename T>
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>;
};
}
template<typename T>
using auto_alias_t = typename detail::auto_alias_impl<T>::type;
template <typename T>
using auto_alias_t = typename detail::auto_alias_impl<T>::type;
}
#endif

View File

@ -32,88 +32,95 @@
namespace sqlpp
{
struct avg_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "avg_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T avg;
T& operator()() { return avg; }
const T& operator()() const { return avg; }
};
};
};
struct avg_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "avg_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T avg;
T& operator()()
{
return avg;
}
const T& operator()() const
{
return avg;
}
};
};
};
template<typename Flag, typename Expr>
struct avg_t:
public expression_operators<avg_t<Flag, Expr>, floating_point>,
public alias_operators<avg_t<Flag, Expr>>
{
using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
template <typename Flag, typename Expr>
struct avg_t : public expression_operators<avg_t<Flag, Expr>, floating_point>,
public alias_operators<avg_t<Flag, Expr>>
{
using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>;
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_numeric_t<Expr>::value, "avg() requires a value expression as argument");
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");
using _auto_alias_t = avg_alias_t;
using _auto_alias_t = avg_alias_t;
avg_t(Expr expr):
_expr(expr)
{}
avg_t(Expr expr) : _expr(expr)
{
}
avg_t(const avg_t&) = default;
avg_t(avg_t&&) = default;
avg_t& operator=(const avg_t&) = default;
avg_t& operator=(avg_t&&) = default;
~avg_t() = default;
avg_t(const avg_t&) = default;
avg_t(avg_t&&) = default;
avg_t& operator=(const avg_t&) = default;
avg_t& operator=(avg_t&&) = default;
~avg_t() = default;
Expr _expr;
};
Expr _expr;
};
template<typename Context, typename Flag, typename Expr>
struct serializer_t<Context, avg_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = avg_t<Flag, Expr>;
template <typename Context, typename Flag, typename Expr>
struct serializer_t<Context, avg_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = avg_t<Flag, Expr>;
static Context& _(const T& t, Context& context)
{
context << "AVG(";
if (std::is_same<distinct_t, Flag>::value)
{
serialize(Flag(), context);
context << ' ';
serialize_operand(t._expr, context);
}
else
{
serialize(t._expr, context);
}
context << ")";
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << "AVG(";
if (std::is_same<distinct_t, Flag>::value)
{
serialize(Flag(), context);
context << ' ';
serialize_operand(t._expr, context);
}
else
{
serialize(t._expr, context);
}
context << ")";
return context;
}
};
template<typename 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(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return { t };
}
template<typename 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(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return { t };
}
template <typename 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(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return {t};
}
template <typename 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(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return {t};
}
}
#endif

View File

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

View File

@ -38,119 +38,122 @@
namespace sqlpp
{
// basic operators
template<typename Expr, typename ValueType>
struct basic_expression_operators
{
template<typename T>
struct _is_valid_comparison_operand
{
static constexpr bool value =
(is_expression_t<T>::value // expressions are OK
or 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
;
};
// basic operators
template <typename Expr, typename ValueType>
struct basic_expression_operators
{
template <typename T>
struct _is_valid_comparison_operand
{
static constexpr bool value =
(is_expression_t<T>::value // expressions are OK
or
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>
equal_to_t<Expr, wrap_operand_t<T>> operator==(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
template <typename T>
equal_to_t<Expr, wrap_operand_t<T>> operator==(T t) const
{
using rhs = wrap_operand_t<T>;
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>
not_equal_to_t<Expr, wrap_operand_t<T>> operator!=(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
template <typename T>
not_equal_to_t<Expr, wrap_operand_t<T>> operator!=(T t) const
{
using rhs = wrap_operand_t<T>;
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>
less_than_t<Expr, wrap_operand_t<T>> operator<(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
template <typename T>
less_than_t<Expr, wrap_operand_t<T>> operator<(T t) const
{
using rhs = wrap_operand_t<T>;
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>
less_equal_t<Expr, wrap_operand_t<T>> operator<=(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
template <typename T>
less_equal_t<Expr, wrap_operand_t<T>> operator<=(T t) const
{
using rhs = wrap_operand_t<T>;
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>
greater_than_t<Expr, wrap_operand_t<T>> operator>(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
template <typename T>
greater_than_t<Expr, wrap_operand_t<T>> operator>(T t) const
{
using rhs = wrap_operand_t<T>;
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>
greater_equal_t<Expr, wrap_operand_t<T>> operator>=(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
template <typename T>
greater_equal_t<Expr, wrap_operand_t<T>> operator>=(T t) const
{
using rhs = wrap_operand_t<T>;
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
{
return { *static_cast<const Expr*>(this) };
}
is_null_t<Expr> is_null() const
{
return {*static_cast<const Expr*>(this)};
}
is_not_null_t<Expr> is_not_null() const
{
return { *static_cast<const Expr*>(this) };
}
is_not_null_t<Expr> is_not_null() const
{
return {*static_cast<const Expr*>(this)};
}
sort_order_t<Expr, sort_type::asc> asc() const
{
return { *static_cast<const Expr*>(this) };
}
sort_order_t<Expr, sort_type::asc> asc() const
{
return {*static_cast<const Expr*>(this)};
}
sort_order_t<Expr, sort_type::desc> desc() const
{
return { *static_cast<const Expr*>(this) };
}
sort_order_t<Expr, sort_type::desc> desc() const
{
return {*static_cast<const Expr*>(this)};
}
// Hint: use value_list wrapper for containers...
template<typename... T>
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");
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... };
}
// Hint: use value_list wrapper for containers...
template <typename... T>
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");
return {*static_cast<const Expr*>(this), wrap_operand_t<T>{t}...};
}
template<typename... T>
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");
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... };
}
};
template<typename Expr>
struct alias_operators
{
template<typename alias_provider>
expression_alias_t<Expr, alias_provider> as(const alias_provider&) const
{
return { *static_cast<const Expr*>(this) };
}
};
template <typename... T>
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");
return {*static_cast<const Expr*>(this), wrap_operand_t<T>{t}...};
}
};
template <typename Expr>
struct alias_operators
{
template <typename alias_provider>
expression_alias_t<Expr, alias_provider> as(const alias_provider&) const
{
return {*static_cast<const Expr*>(this)};
}
};
}
#endif

View File

@ -37,199 +37,197 @@
namespace sqlpp
{
// boolean value type
struct boolean
{
using _traits = make_traits<boolean, tag::is_value_type>;
using _tag = tag::is_boolean;
using _cpp_value_type = bool;
// boolean value type
struct boolean
{
using _traits = make_traits<boolean, tag::is_value_type>;
using _tag = tag::is_boolean;
using _cpp_value_type = bool;
template<typename T>
using _is_valid_operand = is_boolean_t<T>;
};
template <typename T>
using _is_valid_operand = is_boolean_t<T>;
};
// boolean parameter type
template<>
struct parameter_value_t<boolean>
{
using _value_type = boolean; // FIXME
using _cpp_value_type = typename _value_type::_cpp_value_type;
// boolean parameter type
template <>
struct parameter_value_t<boolean>
{
using _value_type = boolean; // FIXME
using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t():
_value(false),
_is_null(true)
{}
parameter_value_t() : _value(false), _is_null(true)
{
}
parameter_value_t(const _cpp_value_type& val):
_value(val),
_is_null(false)
{}
parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false)
{
}
parameter_value_t& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_t& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_t& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = false;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
parameter_value_t& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = false;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
parameter_value_t& operator=(const std::nullptr_t&)
{
_value = false;
_is_null = true;
return *this;
}
parameter_value_t& operator=(const std::nullptr_t&)
{
_value = false;
_is_null = true;
return *this;
}
bool is_null() const
{
return _is_null;
}
bool is_null() const
{
return _is_null;
}
_cpp_value_type value() const
{
return _value;
}
_cpp_value_type value() const
{
return _value;
}
operator _cpp_value_type() const { return value(); }
operator _cpp_value_type() const
{
return value();
}
template<typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_boolean_parameter(index, &_value, _is_null);
}
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_boolean_parameter(index, &_value, _is_null);
}
private:
signed char _value;
bool _is_null;
};
private:
signed char _value;
bool _is_null;
};
// boolean expression operators
template<typename Base>
struct expression_operators<Base, boolean>: public basic_expression_operators<Base, boolean>
{
template<typename T>
using _is_valid_operand = is_valid_operand<boolean, T>;
// boolean expression operators
template <typename Base>
struct expression_operators<Base, boolean> : public basic_expression_operators<Base, boolean>
{
template <typename T>
using _is_valid_operand = is_valid_operand<boolean, T>;
template<typename T>
logical_and_t<Base, wrap_operand_t<T>> operator and(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
logical_and_t<Base, wrap_operand_t<T>> operator and(T t) const
{
using rhs = wrap_operand_t<T>;
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>
logical_or_t<Base, wrap_operand_t<T>> operator or(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
logical_or_t<Base, wrap_operand_t<T>> operator or(T t) const
{
using rhs = wrap_operand_t<T>;
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
{
return { *static_cast<const Base*>(this) };
}
};
logical_not_t<Base> operator not() const
{
return {*static_cast<const Base*>(this)};
}
};
// boolean column operators
template<typename Base>
struct column_operators<Base, boolean>
{
};
// boolean column operators
template <typename Base>
struct column_operators<Base, boolean>
{
};
// boolean result field
template<typename Db, typename 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");
using _cpp_value_type = typename boolean::_cpp_value_type;
// boolean result field
template <typename Db, typename 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");
using _cpp_value_type = typename boolean::_cpp_value_type;
result_field_t():
_is_valid(false),
_is_null(true),
_value(false)
{}
result_field_t() : _is_valid(false), _is_null(true), _value(false)
{
}
void _validate()
{
_is_valid = true;
}
void _validate()
{
_is_valid = true;
}
void _invalidate()
{
_is_valid = false;
_is_null = true;
_value = 0;
}
void _invalidate()
{
_is_valid = false;
_is_null = true;
_value = 0;
}
bool is_null() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return _is_null;
}
bool is_null() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return _is_null;
}
bool _is_trivial() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
bool _is_trivial() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return value() == false;
}
return value() == false;
}
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
if (_is_null)
{
if (enforce_null_result_treatment_t<Db>::value and not null_is_trivial_value_t<FieldSpec>::value)
{
throw exception("accessing value of NULL field");
}
else
{
return false;
}
}
return _value;
}
if (_is_null)
{
if (enforce_null_result_treatment_t<Db>::value and not null_is_trivial_value_t<FieldSpec>::value)
{
throw exception("accessing value of NULL field");
}
else
{
return false;
}
}
return _value;
}
template<typename Target>
void _bind(Target& target, size_t i)
{
target._bind_boolean_result(i, &_value, &_is_null);
}
template <typename Target>
void _bind(Target& target, size_t i)
{
target._bind_boolean_result(i, &_value, &_is_null);
}
private:
bool _is_valid;
bool _is_null;
signed char _value;
};
template<typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<boolean, Db, FieldSpec>& e)
{
return serialize(e, os);
}
private:
bool _is_valid;
bool _is_null;
signed char _value;
};
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<boolean, Db, FieldSpec>& e)
{
return serialize(e, os);
}
}
#endif

View File

@ -32,54 +32,53 @@
namespace sqlpp
{
template<typename Database>
struct boolean_expression_t: public expression_operators<boolean_expression_t<Database>, boolean>
{
using _traits = make_traits<boolean, tag::is_expression>;
using _nodes = detail::type_vector<>;
template <typename Database>
struct boolean_expression_t : public expression_operators<boolean_expression_t<Database>, boolean>
{
using _traits = make_traits<boolean, tag::is_expression>;
using _nodes = detail::type_vector<>;
template<typename Expr>
boolean_expression_t(Expr expr):
_expr(expr)
{
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");
}
template <typename Expr>
boolean_expression_t(Expr expr)
: _expr(expr)
{
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");
}
boolean_expression_t(const boolean_expression_t&) = default;
boolean_expression_t(boolean_expression_t&&) = default;
boolean_expression_t& operator=(const boolean_expression_t&) = default;
boolean_expression_t& operator=(boolean_expression_t&&) = default;
~boolean_expression_t() = default;
boolean_expression_t(const boolean_expression_t&) = default;
boolean_expression_t(boolean_expression_t&&) = default;
boolean_expression_t& operator=(const boolean_expression_t&) = default;
boolean_expression_t& operator=(boolean_expression_t&&) = default;
~boolean_expression_t() = default;
interpretable_t<Database> _expr;
};
interpretable_t<Database> _expr;
};
template<typename Database, typename T>
boolean_expression_t<Database> boolean_expression(T t)
{
using Expr = wrap_operand_t<T>;
return {Expr{t}};
}
template <typename Database, typename T>
boolean_expression_t<Database> boolean_expression(T t)
{
using Expr = wrap_operand_t<T>;
return {Expr{t}};
}
template<typename Database, typename T>
boolean_expression_t<Database> boolean_expression(const Database&, T t)
{
return boolean_expression<Database>(t);
}
template <typename Database, typename T>
boolean_expression_t<Database> boolean_expression(const Database&, T t)
{
return boolean_expression<Database>(t);
}
template<typename Context, typename Database>
struct serializer_t<Context, boolean_expression_t<Database>>
{
using _serialize_check = consistent_t;
using T = boolean_expression_t<Database>;
static Context& _(const T& t, Context& context)
{
return serialize(t._expr, context);
}
};
template <typename Context, typename Database>
struct serializer_t<Context, boolean_expression_t<Database>>
{
using _serialize_check = consistent_t;
using T = boolean_expression_t<Database>;
static Context& _(const T& t, Context& context)
{
return serialize(t._expr, context);
}
};
}
#endif

View File

@ -31,26 +31,28 @@
namespace sqlpp
{
template<char... Cs> struct char_sequence
{
static const char* char_ptr()
{
static char s[] = {Cs...};
return s;
};
};
template <char... Cs>
struct char_sequence
{
static const char* char_ptr()
{
static char s[] = {Cs...};
return s;
};
};
template<std::size_t N, const char (&s) [N], typename T>
struct make_char_sequence_impl;
template <std::size_t N, const char(&s)[N], typename T>
struct make_char_sequence_impl;
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...>>
{
using type = char_sequence<s[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...>>
{
using type = char_sequence<s[i]...>;
};
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;
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;
}
#endif

View File

@ -41,84 +41,81 @@
namespace sqlpp
{
template<typename Table, typename ColumnSpec>
struct column_t:
public expression_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>,
public column_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>
{
struct _traits
{
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>;
};
template <typename Table, typename ColumnSpec>
struct column_t : public expression_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>,
public column_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>
{
struct _traits
{
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 _nodes = detail::type_vector<>;
using _required_tables = detail::type_set<Table>;
using _can_be_null = column_spec_can_be_null_t<ColumnSpec>;
using _nodes = detail::type_vector<>;
using _required_tables = detail::type_set<Table>;
using _can_be_null = column_spec_can_be_null_t<ColumnSpec>;
using _spec_t = ColumnSpec;
using _table = Table;
using _alias_t = typename _spec_t::_alias_t;
using _spec_t = ColumnSpec;
using _table = Table;
using _alias_t = typename _spec_t::_alias_t;
template<typename T>
using _is_valid_operand = is_valid_operand<value_type_of<ColumnSpec>, T>;
template <typename T>
using _is_valid_operand = is_valid_operand<value_type_of<ColumnSpec>, T>;
column_t() = default;
column_t(const column_t&) = default;
column_t(column_t&&) = default;
column_t& operator=(const column_t&) = default;
column_t& operator=(column_t&&) = default;
~column_t() = default;
column_t() = default;
column_t(const column_t&) = default;
column_t(column_t&&) = default;
column_t& operator=(const column_t&) = default;
column_t& operator=(column_t&&) = default;
~column_t() = default;
template<typename T = _table>
auto table() const -> _table
{
static_assert(is_table_t<T>::value, "cannot call get_table for columns of a sub-selects or cte");
return _table{};
}
template <typename T = _table>
auto table() const -> _table
{
static_assert(is_table_t<T>::value, "cannot call get_table for columns of a sub-selects or cte");
return _table{};
}
template<typename alias_provider>
expression_alias_t<column_t, alias_provider> as(const alias_provider&) const
{
return { *this };
}
template <typename alias_provider>
expression_alias_t<column_t, alias_provider> as(const alias_provider&) const
{
return {*this};
}
template<typename T>
auto operator =(T t) const -> assignment_t<column_t, wrap_operand_t<T>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
template <typename T>
auto operator=(T t) const -> assignment_t<column_t, wrap_operand_t<T>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *this, {rhs{t}} };
}
return {*this, {rhs{t}}};
}
auto operator =(null_t) const
->assignment_t<column_t, null_t>
{
static_assert(can_be_null_t<column_t>::value, "column cannot be null");
return { *this, null_t{} };
}
auto operator=(null_t) const -> assignment_t<column_t, null_t>
{
static_assert(can_be_null_t<column_t>::value, "column cannot be null");
return {*this, null_t{}};
}
auto operator =(default_value_t) const
->assignment_t<column_t, default_value_t>
{
return { *this, default_value_t{} };
}
};
auto operator=(default_value_t) const -> assignment_t<column_t, default_value_t>
{
return {*this, default_value_t{}};
}
};
template<typename Context, typename... Args>
struct serializer_t<Context, column_t<Args...>>
{
using _serialize_check = consistent_t;
using T = column_t<Args...>;
static Context& _(const T&, Context& context)
{
context << name_of<typename T::_table>::char_ptr() << '.' << name_of<T>::char_ptr();
return context;
}
};
template <typename Context, typename... Args>
struct serializer_t<Context, column_t<Args...>>
{
using _serialize_check = consistent_t;
using T = column_t<Args...>;
static Context& _(const T&, Context& context)
{
context << name_of<typename T::_table>::char_ptr() << '.' << name_of<T>::char_ptr();
return context;
}
};
}
#endif

View File

@ -24,14 +24,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_COLUMN_FWD_H
#define SQLPP_COLUMN_FWD_H
namespace sqlpp
{
template<typename Table, typename ColumnSpec>
struct column_t;
template <typename Table, typename ColumnSpec>
struct column_t;
}
#endif

View File

@ -35,69 +35,67 @@
namespace sqlpp
{
struct text;
struct text;
struct concat_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "concat_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T concat;
};
};
};
struct concat_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "concat_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T concat;
};
};
};
template<typename... Args>
struct concat_t:
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 _nodes = detail::type_vector<Args...>;
template <typename... Args>
struct concat_t : 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 _nodes = detail::type_vector<Args...>;
using _auto_alias_t = concat_alias_t;
using _auto_alias_t = concat_alias_t;
concat_t(Args... args):
_args(args...)
{}
concat_t(Args... args) : _args(args...)
{
}
concat_t(const concat_t&) = default;
concat_t(concat_t&&) = default;
concat_t& operator=(const concat_t&) = default;
concat_t& operator=(concat_t&&) = default;
~concat_t() = default;
concat_t(const concat_t&) = default;
concat_t(concat_t&&) = default;
concat_t& operator=(const concat_t&) = default;
concat_t& operator=(concat_t&&) = default;
~concat_t() = default;
std::tuple<Args...> _args;
};
std::tuple<Args...> _args;
};
template<typename Context, typename... Args>
struct serializer_t<Context, concat_t<Args...>>
{
using _serialize_check = serialize_check_of<Context, Args...>;
using T = concat_t<Args...>;
template <typename Context, typename... Args>
struct serializer_t<Context, concat_t<Args...>>
{
using _serialize_check = serialize_check_of<Context, Args...>;
using T = concat_t<Args...>;
static Context& _(const T& t, Context& context)
{
context << "(";
interpret_tuple(t._args, "||", context);
context << ")";
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << "(";
interpret_tuple(t._args, "||", context);
context << ")";
return context;
}
};
template<typename... Args>
auto concat(Args... args)
-> concat_t<Args...>
{
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()");
template <typename... Args>
auto concat(Args... args) -> concat_t<Args...>
{
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()");
return {args...};
}
return {args...};
}
}
#endif

View File

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

View File

@ -33,89 +33,96 @@
namespace sqlpp
{
struct count_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "count_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T count;
T& operator()() { return count; }
const T& operator()() const { return count; }
};
};
};
struct count_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "count_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T count;
T& operator()()
{
return count;
}
const T& operator()() const
{
return count;
}
};
};
};
template<typename Flag, typename Expr>
struct count_t:
public expression_operators<count_t<Flag, Expr>, integral>,
public alias_operators<count_t<Flag, Expr>>
{
using _traits = make_traits<integral, tag::is_expression/*, tag::is_selectable*/>;
template <typename Flag, typename Expr>
struct count_t : public expression_operators<count_t<Flag, Expr>, integral>,
public alias_operators<count_t<Flag, Expr>>
{
using _traits = make_traits<integral, tag::is_expression /*, tag::is_selectable*/>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _can_be_null = std::false_type;
using _nodes = detail::type_vector<Expr, aggregate_function>;
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):
_expr(expr)
{}
count_t(const Expr expr) : _expr(expr)
{
}
count_t(const count_t&) = default;
count_t(count_t&&) = default;
count_t& operator=(const count_t&) = default;
count_t& operator=(count_t&&) = default;
~count_t() = default;
count_t(const count_t&) = default;
count_t(count_t&&) = default;
count_t& operator=(const count_t&) = default;
count_t& operator=(count_t&&) = default;
~count_t() = default;
Expr _expr;
};
Expr _expr;
};
template<typename Context, typename Flag, typename Expr>
struct serializer_t<Context, count_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = count_t<Flag, Expr>;
template <typename Context, typename Flag, typename Expr>
struct serializer_t<Context, count_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = count_t<Flag, Expr>;
static Context& _(const T& t, Context& context)
{
context << "COUNT(";
if (std::is_same<distinct_t, Flag>::value)
{
serialize(Flag(), context);
context << ' ';
serialize_operand(t._expr, context);
}
else
{
serialize(t._expr, context);
}
context << ")";
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << "COUNT(";
if (std::is_same<distinct_t, Flag>::value)
{
serialize(Flag(), context);
context << ' ';
serialize_operand(t._expr, context);
}
else
{
serialize(t._expr, context);
}
context << ")";
return context;
}
};
template<typename 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(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return { t };
}
template<typename 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(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return { t };
}
template <typename 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(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return {t};
}
template <typename 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(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return {t};
}
}
#endif

View File

@ -40,222 +40,226 @@
namespace sqlpp
{
template<typename Flag, typename Lhs, typename Rhs>
struct cte_union_t
{
using _nodes = detail::type_vector<>;
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>>;
template <typename Flag, typename Lhs, typename Rhs>
struct cte_union_t
{
using _nodes = detail::type_vector<>;
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>>;
cte_union_t(Lhs lhs, Rhs rhs):
_lhs(lhs),
_rhs(rhs)
{}
cte_union_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
{
}
cte_union_t(const cte_union_t&) = default;
cte_union_t(cte_union_t&&) = default;
cte_union_t& operator=(const cte_union_t&) = default;
cte_union_t& operator=(cte_union_t&&) = default;
~cte_union_t() = default;
cte_union_t(const cte_union_t&) = default;
cte_union_t(cte_union_t&&) = default;
cte_union_t& operator=(const cte_union_t&) = default;
cte_union_t& operator=(cte_union_t&&) = default;
~cte_union_t() = default;
Lhs _lhs;
Rhs _rhs;
};
Lhs _lhs;
Rhs _rhs;
};
// Interpreters
template<typename Context, typename Flag, typename Lhs, typename Rhs>
struct serializer_t<Context, cte_union_t<Flag, Lhs, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
using T = cte_union_t<Flag, Lhs, Rhs>;
// Interpreters
template <typename Context, typename Flag, typename Lhs, typename Rhs>
struct serializer_t<Context, cte_union_t<Flag, Lhs, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
using T = cte_union_t<Flag, Lhs, Rhs>;
static Context& _(const T& t, Context& context)
{
serialize(t._lhs, context);
context << " UNION ";
serialize(Flag{}, context);
context << " ";
serialize(t._rhs, context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
serialize(t._lhs, context);
context << " UNION ";
serialize(Flag{}, context);
context << " ";
serialize(t._rhs, context);
return context;
}
};
template<typename AliasProvider, typename Statement, typename... FieldSpecs>
struct cte_t;
template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct cte_t;
template<typename AliasProvider>
struct cte_ref_t;
template <typename AliasProvider>
struct cte_ref_t;
template<typename AliasProvider, typename Statement, typename... FieldSpecs>
auto from_table(cte_t<AliasProvider, Statement, FieldSpecs...>) -> cte_ref_t<AliasProvider>
{
return cte_ref_t<AliasProvider>{};
}
template <typename AliasProvider, typename Statement, typename... FieldSpecs>
auto from_table(cte_t<AliasProvider, Statement, FieldSpecs...>) -> cte_ref_t<AliasProvider>
{
return cte_ref_t<AliasProvider>{};
}
template<typename AliasProvider, typename Statement, typename... FieldSpecs>
struct from_table_impl<cte_t<AliasProvider, Statement, FieldSpecs...>>
{
using type = cte_ref_t<AliasProvider>;
};
template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct from_table_impl<cte_t<AliasProvider, Statement, FieldSpecs...>>
{
using type = cte_ref_t<AliasProvider>;
};
template <typename FieldSpec>
struct cte_column_spec_t
{
using _alias_t = typename FieldSpec::_alias_t;
template<typename FieldSpec>
struct cte_column_spec_t
{
using _alias_t = typename FieldSpec::_alias_t;
using _traits = make_traits<value_type_of<FieldSpec>,
tag::must_not_insert,
tag::must_not_update,
tag_if<tag::can_be_null, column_spec_can_be_null_t<FieldSpec>::value>>;
};
using _traits = make_traits<value_type_of<FieldSpec>,
tag::must_not_insert,
tag::must_not_update,
tag_if<tag::can_be_null, column_spec_can_be_null_t<FieldSpec>::value>
>;
};
template <typename AliasProvider, typename Statement, typename ResultRow>
struct make_cte_impl
{
using type = void;
};
template<typename AliasProvider, typename Statement, typename ResultRow>
struct make_cte_impl
{
using type = void;
};
template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct make_cte_impl<AliasProvider, Statement, result_row_t<void, FieldSpecs...>>
{
using type = cte_t<AliasProvider, Statement, FieldSpecs...>;
};
template<typename AliasProvider, typename Statement, typename... FieldSpecs>
struct make_cte_impl<AliasProvider, Statement, result_row_t<void, FieldSpecs...>>
{
using type = cte_t<AliasProvider, Statement, FieldSpecs...>;
};
template <typename AliasProvider, typename Statement>
using make_cte_t = typename make_cte_impl<AliasProvider, Statement, get_result_row_t<Statement>>::type;
template<typename AliasProvider, typename Statement>
using make_cte_t = typename make_cte_impl<AliasProvider, Statement, get_result_row_t<Statement>>::type;
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>>>...
{
using _traits = make_traits<no_value_t, tag::is_cte, tag::is_table>; // FIXME: is table? really?
using _nodes = detail::type_vector<>;
using _required_ctes = detail::make_joined_set_t<required_ctes_of<Statement>, detail::type_set<AliasProvider>>;
using _parameters = parameters_of<Statement>;
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>>>...
{
using _traits = make_traits<no_value_t, tag::is_cte, tag::is_table>; // FIXME: is table? really?
using _nodes = detail::type_vector<>;
using _required_ctes = detail::make_joined_set_t<required_ctes_of<Statement>, detail::type_set<AliasProvider>>;
using _parameters = parameters_of<Statement>;
using _alias_t = typename AliasProvider::_alias_t;
constexpr static bool _is_recursive = detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value;
using _alias_t = typename AliasProvider::_alias_t;
constexpr static bool _is_recursive = detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value;
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>
using _check = logic::all_t<is_statement_t<T>::value...>;
template<typename... T>
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>
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
{
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_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement");
template<typename Rhs>
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
{
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_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>
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
{
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_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement");
template<typename Rhs>
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
{
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_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:
template <typename Flag, typename Rhs>
auto _union_impl(const std::false_type&, Rhs rhs) const -> bad_statement;
private:
template<typename Flag, typename Rhs>
auto _union_impl(const std::false_type&, Rhs rhs) const
-> bad_statement;
template <typename Flag, typename Rhs>
auto _union_impl(const std::true_type&, Rhs rhs) const
-> cte_t<AliasProvider, cte_union_t<Flag, Statement, Rhs>, FieldSpecs...>
{
return cte_union_t<Flag, Statement, Rhs>{_statement, rhs};
}
template<typename Flag, typename Rhs>
auto _union_impl(const std::true_type&, Rhs rhs) const
-> cte_t<AliasProvider, cte_union_t<Flag, Statement, Rhs>, FieldSpecs...>
{
return cte_union_t<Flag, Statement, Rhs>{_statement, rhs};
}
public:
cte_t(Statement statement) : _statement(statement)
{
}
cte_t(const cte_t&) = default;
cte_t(cte_t&&) = default;
cte_t& operator=(const cte_t&) = default;
cte_t& operator=(cte_t&&) = default;
~cte_t() = default;
public:
Statement _statement;
};
cte_t(Statement statement): _statement(statement){}
cte_t(const cte_t&) = default;
cte_t(cte_t&&) = default;
cte_t& operator=(const cte_t&) = default;
cte_t& operator=(cte_t&&) = default;
~cte_t() = default;
template <typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs>
struct serializer_t<Context, cte_t<AliasProvider, Statement, ColumnSpecs...>>
{
using _serialize_check = serialize_check_of<Context, Statement>;
using T = cte_t<AliasProvider, Statement, ColumnSpecs...>;
Statement _statement;
};
static Context& _(const T& t, Context& context)
{
context << name_of<T>::char_ptr() << " AS (";
serialize(t._statement, context);
context << ")";
return context;
}
};
template<typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs>
struct serializer_t<Context, cte_t<AliasProvider, Statement, ColumnSpecs...>>
{
using _serialize_check = serialize_check_of<Context, Statement>;
using T = cte_t<AliasProvider, Statement, ColumnSpecs...>;
// The cte_t is displayed as AliasProviderName except within the with:
// - the with needs the
// AliasProviderName AS (ColumnNames) (select/union)
// The result row of the select should not have dynamic parts
template <typename AliasProvider>
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 _nodes = detail::type_vector<>;
using _required_ctes = detail::make_type_set_t<AliasProvider>;
using _provided_tables = detail::type_set<AliasProvider>;
static Context& _(const T& t, Context& context)
{
context << name_of<T>::char_ptr() << " AS (";
serialize(t._statement, context);
context << ")";
return context;
}
};
using _alias_t = typename AliasProvider::_alias_t;
template <typename Statement>
auto as(Statement 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(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");
// The cte_t is displayed as AliasProviderName except within the with:
// - the with needs the
// AliasProviderName AS (ColumnNames) (select/union)
// The result row of the select should not have dynamic parts
template<typename AliasProvider>
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 _nodes = detail::type_vector<>;
using _required_ctes = detail::make_type_set_t<AliasProvider>;
using _provided_tables = detail::type_set<AliasProvider>;
return {statement};
}
};
using _alias_t = typename AliasProvider::_alias_t;
template <typename Context, typename AliasProvider>
struct serializer_t<Context, cte_ref_t<AliasProvider>>
{
using _serialize_check = consistent_t;
using T = cte_ref_t<AliasProvider>;
template<typename Statement>
auto as(Statement 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(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 };
}
};
template<typename Context, typename AliasProvider>
struct serializer_t<Context, cte_ref_t<AliasProvider>>
{
using _serialize_check = consistent_t;
using T = cte_ref_t<AliasProvider>;
static Context& _(const T&, Context& context)
{
context << name_of<T>::char_ptr();
return context;
}
};
template<typename AliasProvider>
auto cte(const AliasProvider&)
-> cte_ref_t<AliasProvider>
{
return {};
}
static Context& _(const T&, Context& context)
{
context << name_of<T>::char_ptr();
return context;
}
};
template <typename AliasProvider>
auto cte(const AliasProvider&) -> cte_ref_t<AliasProvider>
{
return {};
}
}
#endif

View File

@ -34,111 +34,108 @@
namespace sqlpp
{
template<typename Database, typename... Parts>
struct custom_query_t;
template <typename Database, typename... Parts>
struct custom_query_t;
namespace detail
{
template<typename Db, typename... Parts>
struct custom_parts_t
{
using _custom_query_t = custom_query_t<Db, Parts...>;
using _result_type_provider = detail::get_first_if<is_return_value_t, noop, Parts...>;
using _result_methods_t = typename _result_type_provider::template _result_methods_t<_result_type_provider>;
};
}
namespace detail
{
template <typename Db, typename... Parts>
struct custom_parts_t
{
using _custom_query_t = custom_query_t<Db, Parts...>;
using _result_type_provider = detail::get_first_if<is_return_value_t, noop, Parts...>;
using _result_methods_t = typename _result_type_provider::template _result_methods_t<_result_type_provider>;
};
}
template<typename Database, typename... Parts>
struct custom_query_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 _traits = make_traits<no_value_t, tag::is_statement>;
using _nodes = detail::type_vector<Parts...>;
template <typename Database, typename... Parts>
struct custom_query_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 _traits = make_traits<no_value_t, tag::is_statement>;
using _nodes = detail::type_vector<Parts...>;
using _parameter_check = typename std::conditional<detail::type_vector_size<parameters_of<custom_query_t>>::value == 0,
consistent_t, 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 _parameter_check =
typename std::conditional<detail::type_vector_size<parameters_of<custom_query_t>>::value == 0,
consistent_t,
assert_no_parameters_t>::type;
using _run_check = detail::get_first_if<is_inconsistent_t, consistent_t, _parameter_check>;
using _prepare_check = consistent_t;
custom_query_t(Parts... parts):
_parts(parts...)
{}
custom_query_t(Parts... parts) : _parts(parts...)
{
}
custom_query_t(std::tuple<Parts...> parts):
_parts(parts)
{}
custom_query_t(std::tuple<Parts...> parts) : _parts(parts)
{
}
custom_query_t(const custom_query_t&) = default;
custom_query_t(custom_query_t&&) = default;
custom_query_t& operator=(const custom_query_t&) = default;
custom_query_t& operator=(custom_query_t&&) = default;
~custom_query_t() = default;
custom_query_t(const custom_query_t&) = default;
custom_query_t(custom_query_t&&) = default;
custom_query_t& operator=(const custom_query_t&) = default;
custom_query_t& operator=(custom_query_t&&) = default;
~custom_query_t() = default;
template<typename Db>
auto _run(Db& db) const -> decltype(std::declval<_methods_t>()._run(db, *this))
{
_run_check::_();
return _methods_t::_run(db, *this);
}
template <typename Db>
auto _run(Db& db) const -> decltype(std::declval<_methods_t>()._run(db, *this))
{
_run_check::_();
return _methods_t::_run(db, *this);
}
template<typename Db>
auto _prepare(Db& db) const -> decltype(std::declval<_methods_t>()._prepare(db, *this))
{
_prepare_check::_();
return _methods_t::_prepare(db, *this);
}
template <typename Db>
auto _prepare(Db& db) const -> decltype(std::declval<_methods_t>()._prepare(db, *this))
{
_prepare_check::_();
return _methods_t::_prepare(db, *this);
}
static constexpr size_t _get_static_no_of_parameters()
{
return std::tuple_size<parameters_of<custom_query_t>>::value;
}
static constexpr size_t _get_static_no_of_parameters()
{
return std::tuple_size<parameters_of<custom_query_t>>::value;
}
size_t _get_no_of_parameters() const
{
return _get_static_no_of_parameters();
}
size_t _get_no_of_parameters() const
{
return _get_static_no_of_parameters();
}
template<typename Part>
auto with_result_type_of(Part part)
-> custom_query_t<Database, Part, Parts...>
{
return {tuple_cat(std::make_tuple(part), _parts)};
}
template <typename Part>
auto with_result_type_of(Part part) -> custom_query_t<Database, Part, Parts...>
{
return {tuple_cat(std::make_tuple(part), _parts)};
}
std::tuple<Parts...> _parts;
};
std::tuple<Parts...> _parts;
};
template<typename Context, typename Database, typename... Parts>
struct serializer_t<Context, custom_query_t<Database, Parts...>>
{
using _serialize_check = serialize_check_of<Context, Parts...>;
using T = custom_query_t<Database, Parts...>;
template <typename Context, typename Database, typename... Parts>
struct serializer_t<Context, custom_query_t<Database, Parts...>>
{
using _serialize_check = serialize_check_of<Context, Parts...>;
using T = custom_query_t<Database, Parts...>;
static Context& _(const T& t, Context& context)
{
interpret_tuple_without_braces(t._parts, " ", context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
interpret_tuple_without_braces(t._parts, " ", context);
return context;
}
};
template<typename... Parts>
auto custom_query(Parts... parts)
-> custom_query_t<void, wrap_operand_t<Parts>...>
{
static_assert(sizeof...(Parts) > 0, "custom query requires at least one argument");
return custom_query_t<void, wrap_operand_t<Parts>...>(parts...);
}
template <typename... Parts>
auto custom_query(Parts... parts) -> custom_query_t<void, wrap_operand_t<Parts>...>
{
static_assert(sizeof...(Parts) > 0, "custom query requires at least one argument");
return custom_query_t<void, wrap_operand_t<Parts>...>(parts...);
}
template<typename Database, typename... Parts>
auto dynamic_custom_query(const Database&, Parts... parts)
-> custom_query_t<Database, wrap_operand_t<Parts>...>
{
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");
template <typename Database, typename... Parts>
auto dynamic_custom_query(const Database&, Parts... parts) -> custom_query_t<Database, wrap_operand_t<Parts>...>
{
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");
return custom_query_t<Database, wrap_operand_t<Parts>...>(parts...);
}
return custom_query_t<Database, wrap_operand_t<Parts>...>(parts...);
}
}
#endif

View File

@ -31,29 +31,31 @@
namespace sqlpp
{
struct default_value_t
{
using _traits = make_traits<no_value_t, tag::is_expression>;
using _nodes = detail::type_vector<>;
struct default_value_t
{
using _traits = make_traits<no_value_t, tag::is_expression>;
using _nodes = detail::type_vector<>;
static constexpr bool _is_trivial() { return false; }
};
static constexpr bool _is_trivial()
{
return false;
}
};
template<typename Context>
struct serializer_t<Context, default_value_t>
{
using _serialize_check = consistent_t;
using Operand = default_value_t;
template <typename Context>
struct serializer_t<Context, default_value_t>
{
using _serialize_check = consistent_t;
using Operand = default_value_t;
static Context& _(const Operand&, Context& context)
{
context << "DEFAULT";
return context;
}
};
constexpr default_value_t default_value = {};
static Context& _(const Operand&, Context& context)
{
context << "DEFAULT";
return context;
}
};
constexpr default_value_t default_value = {};
}
#endif

View File

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

View File

@ -32,43 +32,55 @@
namespace sqlpp
{
namespace detail
{
template<std::size_t NextIndex, std::size_t... Ints>
struct field_index_sequence
{
static constexpr std::size_t _next_index = NextIndex;
};
namespace detail
{
template <std::size_t NextIndex, std::size_t... Ints>
struct field_index_sequence
{
static constexpr std::size_t _next_index = NextIndex;
};
template<typename T, typename... Fields>
struct make_field_index_sequence_impl
{
static_assert(wrong_t<make_field_index_sequence_impl>::value, "invalid field index sequence arguments");
};
template <typename T, typename... Fields>
struct make_field_index_sequence_impl
{
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>
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;
};
template <std::size_t NextIndex,
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;
};
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...>
{
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, typename AliasProvider, typename FieldTuple, typename... 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;
};
template<std::size_t NextIndex, std::size_t... Ints>
struct make_field_index_sequence_impl<field_index_sequence<NextIndex, Ints...>>
{
using type = field_index_sequence<NextIndex, Ints...>;
};
template <std::size_t NextIndex, std::size_t... Ints>
struct make_field_index_sequence_impl<field_index_sequence<NextIndex, Ints...>>
{
using type = field_index_sequence<NextIndex, Ints...>;
};
template<std::size_t StartIndex, typename... Fields>
using make_field_index_sequence = typename make_field_index_sequence_impl<field_index_sequence<StartIndex>, Fields...>::type;
}
template <std::size_t StartIndex, typename... Fields>
using make_field_index_sequence =
typename make_field_index_sequence_impl<field_index_sequence<StartIndex>, Fields...>::type;
}
}
#endif

View File

@ -31,30 +31,27 @@
namespace sqlpp
{
namespace detail
{
template<template<typename> class Predicate, typename Default, typename... T>
struct get_first_if_impl;
namespace detail
{
template <template <typename> class Predicate, typename Default, typename... T>
struct get_first_if_impl;
template<template<typename> class Predicate, typename Default>
struct get_first_if_impl<Predicate, Default>
{
using type = Default;
};
template <template <typename> class Predicate, typename Default>
struct get_first_if_impl<Predicate, Default>
{
using type = Default;
};
template<template<typename> class Predicate, typename Default, typename T, typename... Rest>
struct get_first_if_impl<Predicate, Default, T, Rest...>
{
using rest = typename get_first_if_impl<Predicate, Default, Rest...>::type;
using type = typename std::conditional<Predicate<T>::value,
T,
rest>::type;
};
template <template <typename> class Predicate, typename Default, typename T, typename... Rest>
struct get_first_if_impl<Predicate, Default, T, Rest...>
{
using rest = typename get_first_if_impl<Predicate, Default, Rest...>::type;
using type = typename std::conditional<Predicate<T>::value, T, rest>::type;
};
template<template<typename> class Predicate, typename Default, typename... T>
using get_first_if = typename get_first_if_impl<Predicate, Default, T...>::type;
}
template <template <typename> class Predicate, typename Default, typename... T>
using get_first_if = typename get_first_if_impl<Predicate, Default, T...>::type;
}
}
#endif

View File

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

View File

@ -31,34 +31,33 @@
namespace sqlpp
{
namespace detail
{
// 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
template<std::size_t... Ints>
struct index_sequence
{};
namespace detail
{
// 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
template <std::size_t... Ints>
struct index_sequence
{
};
template<typename T, std::size_t N>
struct make_index_sequence_impl;
template <typename T, std::size_t N>
struct make_index_sequence_impl;
template<std::size_t N, std::size_t... Ints>
struct make_index_sequence_impl<index_sequence<Ints...>, N>
{
using type = typename make_index_sequence_impl<index_sequence<Ints..., sizeof...(Ints)>, N - 1>::type;
};
template <std::size_t N, std::size_t... Ints>
struct make_index_sequence_impl<index_sequence<Ints...>, N>
{
using type = typename make_index_sequence_impl<index_sequence<Ints..., sizeof...(Ints)>, N - 1>::type;
};
template<std::size_t... Ints>
struct make_index_sequence_impl<index_sequence<Ints...>, 0>
{
using type = index_sequence<Ints...>;
};
template <std::size_t... Ints>
struct make_index_sequence_impl<index_sequence<Ints...>, 0>
{
using type = index_sequence<Ints...>;
};
template<std::size_t N>
using make_index_sequence = typename make_index_sequence_impl<index_sequence<>, N>::type;
}
template <std::size_t N>
using make_index_sequence = typename make_index_sequence_impl<index_sequence<>, N>::type;
}
}
#endif

View File

@ -31,28 +31,27 @@
namespace sqlpp
{
namespace detail
{
template<typename Target, typename Statement, typename Term>
typename Target::_data_t pick_arg_impl(Statement /* statement */, Term term, const std::true_type&)
{
return term;
}
namespace detail
{
template <typename Target, typename Statement, typename Term>
typename Target::_data_t pick_arg_impl(Statement /* statement */, Term term, const std::true_type&)
{
return term;
}
template<typename Target, typename Statement, typename Term>
typename Target::_data_t pick_arg_impl(Statement statement, Term /* term */, const std::false_type&)
{
return Target::_get_member(statement)._data;
}
template <typename Target, typename Statement, typename Term>
typename Target::_data_t pick_arg_impl(Statement statement, Term /* term */, const std::false_type&)
{
return Target::_get_member(statement)._data;
}
// 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>
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>());
}
}
// 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>
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>());
}
}
}
#endif

View File

@ -29,34 +29,32 @@
namespace sqlpp
{
namespace detail
{
namespace detail
{
/** a non-recursive C++14 version
template<typename... Args>
constexpr std::size_t sum(Args... args)
{
std::size_t result = 0;
/** a non-recursive C++14 version
template<typename... Args>
constexpr std::size_t sum(Args... args)
{
std::size_t result = 0;
using swallow = int[];
(void) swallow{(result += args, 0)...};
using swallow = int[];
(void) swallow{(result += args, 0)...};
return result;
}
*/
return result;
}
*/
constexpr std::size_t sum()
{
return 0;
}
constexpr std::size_t sum()
{
return 0;
}
template<typename Arg, typename... Rest>
constexpr std::size_t sum(Arg arg, Rest... rest)
{
return arg + sum(rest...);
}
}
template <typename Arg, typename... Rest>
constexpr std::size_t sum(Arg arg, Rest... rest)
{
return arg + sum(rest...);
}
}
}
#endif

View File

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

View File

@ -31,58 +31,59 @@
namespace sqlpp
{
namespace detail
{
template<typename... T>
struct type_vector
{};
namespace detail
{
template <typename... T>
struct type_vector
{
};
template<typename...T>
struct type_vector_cat_impl
{
static_assert(wrong_t<type_vector_cat_impl>::value, "type_vector_cat must be called with type_vector arguments");
};
template <typename... T>
struct type_vector_cat_impl
{
static_assert(wrong_t<type_vector_cat_impl>::value, "type_vector_cat must be called with type_vector arguments");
};
template<>
struct type_vector_cat_impl<>
{
using type = type_vector<>;
};
template <>
struct type_vector_cat_impl<>
{
using type = type_vector<>;
};
template<typename... T>
struct type_vector_cat_impl<type_vector<T...>>
{
using type = type_vector<T...>;
};
template <typename... T>
struct type_vector_cat_impl<type_vector<T...>>
{
using type = type_vector<T...>;
};
template<typename... L, typename... R>
struct type_vector_cat_impl<type_vector<L...>, type_vector<R...>>
{
using type = type_vector<L..., R...>;
};
template <typename... L, typename... R>
struct type_vector_cat_impl<type_vector<L...>, type_vector<R...>>
{
using type = type_vector<L..., R...>;
};
template<typename... L, typename... 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;
};
template <typename... L, typename... 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;
};
template<typename... T>
using type_vector_cat_t = typename type_vector_cat_impl<T...>::type;
template <typename... T>
using type_vector_cat_t = typename type_vector_cat_impl<T...>::type;
template<typename T>
struct type_vector_size
{
static_assert(wrong_t<type_vector_size>::value, "type_vector_size needs to be called with a type_vector argument");
};
template <typename T>
struct type_vector_size
{
static_assert(wrong_t<type_vector_size>::value,
"type_vector_size needs to be called with a type_vector argument");
};
template<typename... T>
struct type_vector_size<type_vector<T...>>
{
static constexpr std::size_t value = sizeof...(T);
};
}
template <typename... T>
struct type_vector_size<type_vector<T...>>
{
static constexpr std::size_t value = sizeof...(T);
};
}
}
#endif

View File

@ -34,29 +34,33 @@
namespace sqlpp
{
template<typename Db, typename Expr>
struct eval_t
{
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(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 _value_type = value_type_of<Expr>;
using _field_spec = field_spec_t<_name_type, _value_type, true, false>;
using type = result_field_t<_value_type, Db, _field_spec>;
};
template <typename Db, typename Expr>
struct eval_t
{
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(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 _value_type = value_type_of<Expr>;
using _field_spec = field_spec_t<_name_type, _value_type, true, false>;
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>
auto eval(Db& db, Expr expr) -> typename eval_t<Db, Expr>::type
{
return db(select(expr.as(alias::a))).front().a;
}
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
{
return db(select(expr.as(alias::a))).front().a;
}
template<typename ValueType, typename Db>
auto eval(Db& db, std::string sql_code) -> decltype(eval(db, verbatim<ValueType>(sql_code)))
{
return eval(db, verbatim<ValueType>(sql_code));
}
template <typename ValueType, typename Db>
auto eval(Db& db, std::string sql_code) -> decltype(eval(db, verbatim<ValueType>(sql_code)))
{
return eval(db, verbatim<ValueType>(sql_code));
}
}
#endif

View File

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

View File

@ -32,70 +32,72 @@
namespace sqlpp
{
struct exists_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "exists_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T exists;
T& operator()() { return exists; }
const T& operator()() const { return exists; }
};
};
};
struct exists_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "exists_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T exists;
T& operator()()
{
return exists;
}
const T& operator()() const
{
return exists;
}
};
};
};
template<typename Select>
struct exists_t:
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 _nodes = detail::type_vector<Select>;
template <typename Select>
struct exists_t : 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 _nodes = detail::type_vector<Select>;
static_assert(is_select_t<Select>::value, "exists() requires a select expression as argument");
static_assert(is_select_t<Select>::value, "exists() requires a select expression as argument");
using _auto_alias_t = exists_alias_t;
using _auto_alias_t = exists_alias_t;
exists_t(Select select):
_select(select)
{}
exists_t(Select select) : _select(select)
{
}
exists_t(const exists_t&) = default;
exists_t(exists_t&&) = default;
exists_t& operator=(const exists_t&) = default;
exists_t& operator=(exists_t&&) = default;
~exists_t() = default;
exists_t(const exists_t&) = default;
exists_t(exists_t&&) = default;
exists_t& operator=(const exists_t&) = default;
exists_t& operator=(exists_t&&) = default;
~exists_t() = default;
Select _select;
};
Select _select;
};
template<typename Context, typename Select>
struct serializer_t<Context, exists_t<Select>>
{
using _serialize_check = serialize_check_of<Context, Select>;
using T = exists_t<Select>;
template <typename Context, typename Select>
struct serializer_t<Context, exists_t<Select>>
{
using _serialize_check = serialize_check_of<Context, Select>;
using T = exists_t<Select>;
static Context& _(const T& t, Context& context)
{
context << "EXISTS(";
serialize(t._select, context);
context << ")";
return context;
}
};
template<typename 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");
return { t };
}
static Context& _(const T& t, Context& context)
{
context << "EXISTS(";
serialize(t._select, context);
context << ")";
return context;
}
};
template <typename 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");
return {t};
}
}
#endif

View File

@ -38,226 +38,221 @@
namespace sqlpp
{
template<typename Lhs, typename Rhs>
struct binary_expression_t<Lhs, op::equal_to, Rhs>:
public expression_operators<binary_expression_t<Lhs, op::equal_to, Rhs>, boolean>,
public alias_operators<binary_expression_t<Lhs, op::equal_to, Rhs>>
{
using _traits = make_traits<boolean, tag::is_expression>;
using _lhs_t = Lhs;
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>;
template <typename Lhs, typename Rhs>
struct binary_expression_t<Lhs, op::equal_to, Rhs>
: public expression_operators<binary_expression_t<Lhs, op::equal_to, Rhs>, boolean>,
public alias_operators<binary_expression_t<Lhs, op::equal_to, Rhs>>
{
using _traits = make_traits<boolean, tag::is_expression>;
using _lhs_t = Lhs;
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>;
binary_expression_t(_lhs_t lhs, _rhs_t rhs):
_lhs(lhs),
_rhs(rhs)
{}
binary_expression_t(_lhs_t lhs, _rhs_t rhs) : _lhs(lhs), _rhs(rhs)
{
}
binary_expression_t(const binary_expression_t&) = default;
binary_expression_t(binary_expression_t&&) = default;
binary_expression_t& operator=(const binary_expression_t&) = default;
binary_expression_t& operator=(binary_expression_t&&) = default;
~binary_expression_t() = default;
binary_expression_t(const binary_expression_t&) = default;
binary_expression_t(binary_expression_t&&) = default;
binary_expression_t& operator=(const binary_expression_t&) = default;
binary_expression_t& operator=(binary_expression_t&&) = default;
~binary_expression_t() = default;
_lhs_t _lhs;
_rhs_t _rhs;
};
_lhs_t _lhs;
_rhs_t _rhs;
};
template<typename Context, typename Lhs, typename Rhs>
struct serializer_t<Context, binary_expression_t<Lhs, op::equal_to, Rhs>>
{
using T = binary_expression_t<Lhs, op::equal_to, Rhs>;
using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
template <typename Context, typename Lhs, typename Rhs>
struct serializer_t<Context, binary_expression_t<Lhs, op::equal_to, Rhs>>
{
using T = binary_expression_t<Lhs, op::equal_to, Rhs>;
using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
static Context& _(const T& t, Context& context)
{
context << "(";
serialize_operand(t._lhs, context);
if (t._rhs._is_null())
{
context << " IS NULL";
}
else
{
context << "=";
serialize_operand(t._rhs, context);
}
context << ")";
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << "(";
serialize_operand(t._lhs, context);
if (t._rhs._is_null())
{
context << " IS NULL";
}
else
{
context << "=";
serialize_operand(t._rhs, context);
}
context << ")";
return context;
}
};
template<typename Lhs, typename 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 alias_operators<binary_expression_t<Lhs, op::not_equal_to, Rhs>>
{
using _traits = make_traits<boolean, tag::is_expression>;
using _lhs_t = Lhs;
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>;
template <typename Lhs, typename 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 alias_operators<binary_expression_t<Lhs, op::not_equal_to, Rhs>>
{
using _traits = make_traits<boolean, tag::is_expression>;
using _lhs_t = Lhs;
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>;
binary_expression_t(Lhs lhs, _rhs_t rhs):
_lhs(lhs),
_rhs(rhs)
{}
binary_expression_t(Lhs lhs, _rhs_t rhs) : _lhs(lhs), _rhs(rhs)
{
}
binary_expression_t(const binary_expression_t&) = default;
binary_expression_t(binary_expression_t&&) = default;
binary_expression_t& operator=(const binary_expression_t&) = default;
binary_expression_t& operator=(binary_expression_t&&) = default;
~binary_expression_t() = default;
binary_expression_t(const binary_expression_t&) = default;
binary_expression_t(binary_expression_t&&) = default;
binary_expression_t& operator=(const binary_expression_t&) = default;
binary_expression_t& operator=(binary_expression_t&&) = default;
~binary_expression_t() = default;
_lhs_t _lhs;
_rhs_t _rhs;
};
_lhs_t _lhs;
_rhs_t _rhs;
};
template<typename Context, typename Lhs, typename 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 _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
template <typename Context, typename Lhs, typename 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 _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
static Context& _(const T& t, Context& context)
{
context << "(";
serialize_operand(t._lhs, context);
if (t._rhs._is_null())
{
context << " IS NOT NULL";
}
else
{
context << "!=";
serialize_operand(t._rhs, context);
}
context << ")";
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << "(";
serialize_operand(t._lhs, context);
if (t._rhs._is_null())
{
context << " IS NOT NULL";
}
else
{
context << "!=";
serialize_operand(t._rhs, context);
}
context << ")";
return context;
}
};
template<typename Rhs>
struct unary_expression_t<op::logical_not, Rhs>:
public expression_operators<unary_expression_t<op::logical_not, Rhs>, boolean>,
public alias_operators<unary_expression_t<op::logical_not, Rhs>>
{
using _traits = make_traits<boolean, tag::is_expression>;
using _nodes = detail::type_vector<Rhs>;
template <typename Rhs>
struct unary_expression_t<op::logical_not, Rhs>
: public expression_operators<unary_expression_t<op::logical_not, Rhs>, boolean>,
public alias_operators<unary_expression_t<op::logical_not, Rhs>>
{
using _traits = make_traits<boolean, tag::is_expression>;
using _nodes = detail::type_vector<Rhs>;
unary_expression_t(Rhs rhs):
_rhs(rhs)
{}
unary_expression_t(Rhs rhs) : _rhs(rhs)
{
}
unary_expression_t(const unary_expression_t&) = default;
unary_expression_t(unary_expression_t&&) = default;
unary_expression_t& operator=(const unary_expression_t&) = default;
unary_expression_t& operator=(unary_expression_t&&) = default;
~unary_expression_t() = default;
unary_expression_t(const unary_expression_t&) = default;
unary_expression_t(unary_expression_t&&) = default;
unary_expression_t& operator=(const unary_expression_t&) = default;
unary_expression_t& operator=(unary_expression_t&&) = default;
~unary_expression_t() = default;
Rhs _rhs;
};
Rhs _rhs;
};
template<typename Context, typename Rhs>
struct serializer_t<Context, unary_expression_t<op::logical_not, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Rhs>;
using T = unary_expression_t<op::logical_not, Rhs>;
template <typename Context, typename Rhs>
struct serializer_t<Context, unary_expression_t<op::logical_not, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Rhs>;
using T = unary_expression_t<op::logical_not, Rhs>;
static Context& _(const T& t, Context& context)
{
context << "(";
if (trivial_value_is_null_t<Rhs>::value)
{
serialize_operand(t._rhs, context);
context << " IS NULL ";
}
else
{
context << "NOT ";
serialize_operand(t._rhs, context);
}
context << ")";
static Context& _(const T& t, Context& context)
{
context << "(";
if (trivial_value_is_null_t<Rhs>::value)
{
serialize_operand(t._rhs, context);
context << " IS NULL ";
}
else
{
context << "NOT ";
serialize_operand(t._rhs, context);
}
context << ")";
return context;
}
};
return context;
}
};
template<typename Lhs, typename O, typename Rhs>
struct binary_expression_t:
public expression_operators<binary_expression_t<Lhs, O, Rhs>, value_type_of<O>>,
public alias_operators<binary_expression_t<Lhs, O, Rhs>>
{
using _traits = make_traits<value_type_of<O>, tag::is_expression>;
using _nodes = detail::type_vector<Lhs, Rhs>;
template <typename Lhs, typename O, typename Rhs>
struct binary_expression_t : public expression_operators<binary_expression_t<Lhs, O, Rhs>, value_type_of<O>>,
public alias_operators<binary_expression_t<Lhs, O, Rhs>>
{
using _traits = make_traits<value_type_of<O>, tag::is_expression>;
using _nodes = detail::type_vector<Lhs, Rhs>;
binary_expression_t(Lhs lhs, Rhs rhs):
_lhs(lhs),
_rhs(rhs)
{}
binary_expression_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
{
}
binary_expression_t(const binary_expression_t&) = default;
binary_expression_t(binary_expression_t&&) = default;
binary_expression_t& operator=(const binary_expression_t&) = default;
binary_expression_t& operator=(binary_expression_t&&) = default;
~binary_expression_t() = default;
binary_expression_t(const binary_expression_t&) = default;
binary_expression_t(binary_expression_t&&) = default;
binary_expression_t& operator=(const binary_expression_t&) = default;
binary_expression_t& operator=(binary_expression_t&&) = default;
~binary_expression_t() = default;
Lhs _lhs;
Rhs _rhs;
};
Lhs _lhs;
Rhs _rhs;
};
template<typename Context, typename Lhs, typename O, typename Rhs>
struct serializer_t<Context, binary_expression_t<Lhs, O, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
using T = binary_expression_t<Lhs, O, Rhs>;
template <typename Context, typename Lhs, typename O, typename Rhs>
struct serializer_t<Context, binary_expression_t<Lhs, O, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
using T = binary_expression_t<Lhs, O, Rhs>;
static Context& _(const T& t, Context& context)
{
context << "(";
serialize_operand(t._lhs, context);
context << O::_name;
serialize_operand(t._rhs, context);
context << ")";
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << "(";
serialize_operand(t._lhs, context);
context << O::_name;
serialize_operand(t._rhs, context);
context << ")";
return context;
}
};
template<typename O, typename Rhs>
struct unary_expression_t:
public expression_operators<unary_expression_t<O, Rhs>, value_type_of<O>>,
public alias_operators<unary_expression_t<O, Rhs>>
{
using _traits = make_traits<value_type_of<O>, tag::is_expression>;
using _nodes = detail::type_vector<Rhs>;
template <typename O, typename Rhs>
struct unary_expression_t : public expression_operators<unary_expression_t<O, Rhs>, value_type_of<O>>,
public alias_operators<unary_expression_t<O, Rhs>>
{
using _traits = make_traits<value_type_of<O>, tag::is_expression>;
using _nodes = detail::type_vector<Rhs>;
unary_expression_t(Rhs rhs):
_rhs(rhs)
{}
unary_expression_t(Rhs rhs) : _rhs(rhs)
{
}
unary_expression_t(const unary_expression_t&) = default;
unary_expression_t(unary_expression_t&&) = default;
unary_expression_t& operator=(const unary_expression_t&) = default;
unary_expression_t& operator=(unary_expression_t&&) = default;
~unary_expression_t() = default;
unary_expression_t(const unary_expression_t&) = default;
unary_expression_t(unary_expression_t&&) = default;
unary_expression_t& operator=(const unary_expression_t&) = default;
unary_expression_t& operator=(unary_expression_t&&) = default;
~unary_expression_t() = default;
Rhs _rhs;
};
Rhs _rhs;
};
template<typename Context, typename O, typename Rhs>
struct serializer_t<Context, unary_expression_t<O, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Rhs>;
using T = unary_expression_t<O, Rhs>;
template <typename Context, typename O, typename Rhs>
struct serializer_t<Context, unary_expression_t<O, Rhs>>
{
using _serialize_check = serialize_check_of<Context, Rhs>;
using T = unary_expression_t<O, Rhs>;
static Context& _(const T& t, Context& context)
{
context << "(";
context << O::_name;
serialize_operand(t._rhs, context);
context << ")";
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << "(";
context << O::_name;
serialize_operand(t._rhs, context);
context << ")";
return context;
}
};
}
#endif

View File

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

View File

@ -33,143 +33,155 @@
namespace sqlpp
{
template<typename... Tables>
struct extra_tables_data_t
{
extra_tables_data_t()
{}
template <typename... Tables>
struct extra_tables_data_t
{
extra_tables_data_t()
{
}
extra_tables_data_t(const 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=(extra_tables_data_t&&) = default;
~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& operator=(const extra_tables_data_t&) = default;
extra_tables_data_t& operator=(extra_tables_data_t&&) = default;
~extra_tables_data_t() = default;
};
};
// EXTRA_TABLES
template <typename... Tables>
struct extra_tables_t
{
using _traits = make_traits<no_value_t, tag::is_extra_tables>;
using _nodes = detail::type_vector<>;
using _required_ctes = detail::make_joined_set_t<required_ctes_of<Tables>...>;
using _extra_tables = detail::type_set<Tables...>;
// EXTRA_TABLES
template<typename... Tables>
struct extra_tables_t
{
using _traits = make_traits<no_value_t, tag::is_extra_tables>;
using _nodes = detail::type_vector<>;
using _required_ctes = detail::make_joined_set_t<required_ctes_of<Tables>...>;
using _extra_tables = detail::type_set<Tables...>;
// Data
using _data_t = extra_tables_data_t<Tables...>;
// Data
using _data_t = extra_tables_data_t<Tables...>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = extra_tables_data_t<Tables...>;
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = extra_tables_data_t<Tables...>;
_impl_t<Policies> extra_tables;
_impl_t<Policies>& operator()()
{
return extra_tables;
}
const _impl_t<Policies>& operator()() const
{
return extra_tables;
}
_impl_t<Policies> extra_tables;
_impl_t<Policies>& operator()() { return extra_tables; }
const _impl_t<Policies>& operator()() const { return extra_tables; }
template <typename T>
static auto _get_member(T t) -> decltype(t.extra_tables)
{
return t.extra_tables;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.extra_tables)
{
return t.extra_tables;
}
using _consistency_check = consistent_t;
};
};
using _consistency_check = consistent_t;
};
};
// NO EXTRA TABLES YET
struct no_extra_tables_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// NO EXTRA TABLES YET
struct no_extra_tables_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = no_data_t;
// Data
using _data_t = no_data_t;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = no_data_t;
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = no_data_t;
_impl_t<Policies> no_extra_tables;
_impl_t<Policies>& operator()()
{
return no_extra_tables;
}
const _impl_t<Policies>& operator()() const
{
return no_extra_tables;
}
_impl_t<Policies> no_extra_tables;
_impl_t<Policies>& operator()() { return no_extra_tables; }
const _impl_t<Policies>& operator()() const { return no_extra_tables; }
template <typename T>
static auto _get_member(T t) -> decltype(t.no_extra_tables)
{
return t.no_extra_tables;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.no_extra_tables)
{
return t.no_extra_tables;
}
template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_extra_tables_t, T>;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_extra_tables_t, T>;
template <typename... T>
using _check = logic::all_t<is_table_t<T>::value...>;
template<typename... T>
using _check = logic::all_t<is_table_t<T>::value...>;
using _consistency_check = consistent_t;
using _consistency_check = consistent_t;
template <typename... Tables>
auto extra_tables(Tables... tables) const -> _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()");
template<typename... Tables>
auto extra_tables(Tables... tables) const
-> _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()");
return _extra_tables_impl<void>(_check<Tables...>{}, tables...);
}
return _extra_tables_impl<void>(_check<Tables...>{}, tables...);
}
private:
template <typename Database, typename... Tables>
auto _extra_tables_impl(const std::false_type&, Tables... tables) const -> bad_statement;
private:
template<typename Database, typename... Tables>
auto _extra_tables_impl(const std::false_type&, Tables... tables) const
-> bad_statement;
template <typename Database, typename... Tables>
auto _extra_tables_impl(const std::true_type&, Tables...) const
-> _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()");
template<typename Database, typename... Tables>
auto _extra_tables_impl(const std::true_type&, Tables...) const
-> _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 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_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_table_names::size::value,
"at least one duplicate table name detected in extra_tables()");
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_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_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
template<typename Context, typename Database, typename... Tables>
struct serializer_t<Context, extra_tables_data_t<Database, Tables...>>
{
using _serialize_check = serialize_check_of<Context, Tables...>;
using T = extra_tables_data_t<Database, Tables...>;
static Context& _(const T&, Context& context)
{
return context;
}
};
// Interpreters
template <typename Context, typename Database, typename... Tables>
struct serializer_t<Context, extra_tables_data_t<Database, Tables...>>
{
using _serialize_check = serialize_check_of<Context, Tables...>;
using T = extra_tables_data_t<Database, Tables...>;
static Context& _(const T&, Context& context)
{
return context;
}
};
}
#endif

View File

@ -31,47 +31,49 @@
namespace sqlpp
{
template<typename NameType, typename ValueType, bool CanBeNull, bool NullIsTrivialValue>
struct field_spec_t
{
using _traits = make_traits<ValueType, tag::is_noop,
tag_if<tag::can_be_null, CanBeNull>,
tag_if<tag::null_is_trivial_value, NullIsTrivialValue>
>;
using _nodes = detail::type_vector<>;
template <typename NameType, typename ValueType, bool CanBeNull, bool NullIsTrivialValue>
struct field_spec_t
{
using _traits = make_traits<ValueType,
tag::is_noop,
tag_if<tag::can_be_null, CanBeNull>,
tag_if<tag::null_is_trivial_value, NullIsTrivialValue>>;
using _nodes = detail::type_vector<>;
using _alias_t = NameType;
};
using _alias_t = NameType;
};
template<typename AliasProvider, typename FieldSpecTuple>
struct multi_field_spec_t
{
};
template <typename AliasProvider, typename FieldSpecTuple>
struct multi_field_spec_t
{
};
namespace detail
{
template<typename Select, typename NamedExpr>
struct make_field_spec_impl
{
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;
namespace detail
{
template <typename Select, typename NamedExpr>
struct make_field_spec_impl
{
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;
using type = field_spec_t<typename NamedExpr::_alias_t,
value_type_of<NamedExpr>,
logic::any_t<_can_be_null, _depends_on_outer_table>::value,
null_is_trivial_value_t<NamedExpr>::value>;
};
using type = field_spec_t<typename NamedExpr::_alias_t,
value_type_of<NamedExpr>,
logic::any_t<_can_be_null, _depends_on_outer_table>::value,
null_is_trivial_value_t<NamedExpr>::value>;
};
template<typename Select, typename AliasProvider, typename... 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...>>;
};
}
template<typename Select, typename NamedExpr>
using make_field_spec_t = typename detail::make_field_spec_impl<Select, NamedExpr>::type;
template <typename Select, typename AliasProvider, typename... 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...>>;
};
}
template <typename Select, typename NamedExpr>
using make_field_spec_t = typename detail::make_field_spec_impl<Select, NamedExpr>::type;
}
#endif

View File

@ -35,258 +35,256 @@
namespace sqlpp
{
// floating_point value type
struct floating_point
{
using _traits = make_traits<floating_point, tag::is_value_type>;
using _tag = tag::is_floating_point;
using _cpp_value_type = double;
// floating_point value type
struct floating_point
{
using _traits = make_traits<floating_point, tag::is_value_type>;
using _tag = tag::is_floating_point;
using _cpp_value_type = double;
template<typename T>
using _is_valid_operand = is_numeric_t<T>;
};
template <typename T>
using _is_valid_operand = is_numeric_t<T>;
};
// floating_point parameter type
template<>
struct parameter_value_t<floating_point>
{
using _value_type = floating_point;
using _cpp_value_type = typename _value_type::_cpp_value_type;
// floating_point parameter type
template <>
struct parameter_value_t<floating_point>
{
using _value_type = floating_point;
using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t():
_value(0),
_is_null(true)
{}
parameter_value_t() : _value(0), _is_null(true)
{
}
parameter_value_t(const _cpp_value_type& val):
_value(val),
_is_null(false)
{}
parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false)
{
}
parameter_value_t& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_t& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_t& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = 0;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
parameter_value_t& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = 0;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
parameter_value_t& operator=(const std::nullptr_t&)
{
_value = 0;
_is_null = true;
return *this;
}
parameter_value_t& operator=(const std::nullptr_t&)
{
_value = 0;
_is_null = true;
return *this;
}
bool is_null() const
{
return _is_null;
}
bool is_null() const
{
return _is_null;
}
const _cpp_value_type& value() const
{
return _value;
}
const _cpp_value_type& value() const
{
return _value;
}
operator _cpp_value_type() const { return _value; }
operator _cpp_value_type() const
{
return _value;
}
template<typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_floating_point_parameter(index, &_value, _is_null);
}
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_floating_point_parameter(index, &_value, _is_null);
}
private:
_cpp_value_type _value;
bool _is_null;
};
private:
_cpp_value_type _value;
bool _is_null;
};
// floating_point expression operators
template<typename Expr>
struct expression_operators<Expr, floating_point>:
public basic_expression_operators<Expr, floating_point>
{
template<typename T>
using _is_valid_operand = is_valid_operand<floating_point, T>;
// floating_point expression operators
template <typename Expr>
struct expression_operators<Expr, floating_point> : public basic_expression_operators<Expr, floating_point>
{
template <typename T>
using _is_valid_operand = is_valid_operand<floating_point, T>;
template<typename T>
plus_t<Expr, floating_point, wrap_operand_t<T>> operator +(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
plus_t<Expr, floating_point, wrap_operand_t<T>> operator+(T t) const
{
using rhs = wrap_operand_t<T>;
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>
minus_t<Expr, floating_point, wrap_operand_t<T>> operator -(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
minus_t<Expr, floating_point, wrap_operand_t<T>> operator-(T t) const
{
using rhs = wrap_operand_t<T>;
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>
multiplies_t<Expr, floating_point, wrap_operand_t<T>> operator *(T t) const
{
using rhs = wrap_operand_t<T>;
template <typename T>
multiplies_t<Expr, floating_point, wrap_operand_t<T>> operator*(T t) const
{
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>
divides_t<Expr, wrap_operand_t<T>> operator /(T t) const
{
using rhs = wrap_operand_t<T>;
template <typename T>
divides_t<Expr, wrap_operand_t<T>> operator/(T t) const
{
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
{
return { *static_cast<const Expr*>(this) };
}
unary_plus_t<floating_point, Expr> operator+() const
{
return {*static_cast<const Expr*>(this)};
}
unary_minus_t<floating_point, Expr> operator -() const
{
return { *static_cast<const Expr*>(this) };
}
};
unary_minus_t<floating_point, Expr> operator-() const
{
return {*static_cast<const Expr*>(this)};
}
};
// floating_point column operators
template<typename Column>
struct column_operators<Column, floating_point>
{
template<typename T>
using _is_valid_operand = is_valid_operand<floating_point, T>;
// floating_point column operators
template <typename Column>
struct column_operators<Column, floating_point>
{
template <typename T>
using _is_valid_operand = is_valid_operand<floating_point, T>;
template<typename T>
auto operator +=(T t) const -> assignment_t<Column, plus_t<Column, floating_point, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
template <typename T>
auto operator+=(T t) const -> assignment_t<Column, plus_t<Column, floating_point, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
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>
auto operator -=(T t) const -> assignment_t<Column, minus_t<Column, floating_point, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
template <typename T>
auto operator-=(T t) const -> assignment_t<Column, minus_t<Column, floating_point, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
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>
auto operator /=(T t) const -> assignment_t<Column, divides_t<Column, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
template <typename T>
auto operator/=(T t) const -> assignment_t<Column, divides_t<Column, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
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>
auto operator *=(T t) const -> assignment_t<Column, multiplies_t<Column, floating_point, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
template <typename T>
auto operator*=(T t) const -> assignment_t<Column, multiplies_t<Column, floating_point, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return { *static_cast<const Column*>(this), { *static_cast<const Column*>(this), rhs{t} } };
}
};
// floating_point result field
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>>
{
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;
return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
}
};
// floating_point result field
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>>
{
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;
result_field_t():
_is_valid(false),
_is_null(true),
_value(0)
{}
result_field_t() : _is_valid(false), _is_null(true), _value(0)
{
}
void _validate()
{
_is_valid = true;
}
void _validate()
{
_is_valid = true;
}
void _invalidate()
{
_is_valid = false;
_is_null = true;
_value = 0;
}
void _invalidate()
{
_is_valid = false;
_is_null = true;
_value = 0;
}
bool is_null() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return _is_null;
}
bool is_null() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return _is_null;
}
bool _is_trivial() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
bool _is_trivial() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return value() == 0;
}
return value() == 0;
}
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
if (_is_null)
{
if (enforce_null_result_treatment_t<Db>::value and not null_is_trivial_value_t<FieldSpec>::value)
{
throw exception("accessing value of NULL field");
}
else
{
return 0;
}
}
return _value;
}
if (_is_null)
{
if (enforce_null_result_treatment_t<Db>::value and not null_is_trivial_value_t<FieldSpec>::value)
{
throw exception("accessing value of NULL field");
}
else
{
return 0;
}
}
return _value;
}
template<typename Target>
void _bind(Target& target, size_t i)
{
target._bind_floating_point_result(i, &_value, &_is_null);
}
template <typename Target>
void _bind(Target& target, size_t i)
{
target._bind_floating_point_result(i, &_value, &_is_null);
}
private:
bool _is_valid;
bool _is_null;
_cpp_value_type _value;
};
template<typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<floating_point, Db, FieldSpec>& e)
{
return serialize(e, os);
}
private:
bool _is_valid;
bool _is_null;
_cpp_value_type _value;
};
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<floating_point, Db, FieldSpec>& e)
{
return serialize(e, os);
}
}
#endif

View File

@ -38,197 +38,213 @@
namespace sqlpp
{
// FROM DATA
template<typename Database, typename... Tables>
struct from_data_t
{
from_data_t(Tables... tables):
_tables(tables...)
{}
// FROM DATA
template <typename Database, typename... Tables>
struct from_data_t
{
from_data_t(Tables... tables) : _tables(tables...)
{
}
from_data_t(const from_data_t&) = default;
from_data_t(from_data_t&&) = default;
from_data_t& operator=(const from_data_t&) = default;
from_data_t& operator=(from_data_t&&) = default;
~from_data_t() = default;
from_data_t(const from_data_t&) = default;
from_data_t(from_data_t&&) = default;
from_data_t& operator=(const from_data_t&) = default;
from_data_t& operator=(from_data_t&&) = default;
~from_data_t() = default;
std::tuple<Tables...> _tables;
interpretable_list_t<Database> _dynamic_tables;
};
std::tuple<Tables...> _tables;
interpretable_list_t<Database> _dynamic_tables;
};
// FROM
template<typename Database, typename... Tables>
struct from_t
{
using _traits = make_traits<no_value_t, tag::is_from>;
using _nodes = detail::type_vector<Tables...>;
using _is_dynamic = is_database<Database>;
// FROM
template <typename Database, typename... Tables>
struct from_t
{
using _traits = make_traits<no_value_t, tag::is_from>;
using _nodes = detail::type_vector<Tables...>;
using _is_dynamic = is_database<Database>;
// Data
using _data_t = from_data_t<Database, Tables...>;
// Data
using _data_t = from_data_t<Database, Tables...>;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
template<typename Table>
void add(Table table)
{
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()");
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>;
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>;
_serialize_check::_();
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template <typename Table>
void add(Table table)
{
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()");
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>;
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>;
_serialize_check::_();
using ok = logic::all_t<_is_dynamic::value, is_table_t<Table>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_table_t<Table>::value, _serialize_check::type::value>;
_add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
}
_add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Table>
void _add_impl(Table table, const std::true_type&)
{
return _data._dynamic_tables.emplace_back(from_table(table));
}
private:
template <typename Table>
void _add_impl(Table table, const std::true_type&)
{
return _data._dynamic_tables.emplace_back(from_table(table));
}
template<typename Table>
void _add_impl(Table table, const std::false_type&);
template <typename Table>
void _add_impl(Table table, const std::false_type&);
public:
_data_t _data;
};
public:
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = from_data_t<Database, Tables...>;
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = from_data_t<Database, Tables...>;
_impl_t<Policies> from;
_impl_t<Policies>& operator()() { return from; }
const _impl_t<Policies>& operator()() const { return from; }
_impl_t<Policies> from;
_impl_t<Policies>& operator()()
{
return from;
}
const _impl_t<Policies>& operator()() const
{
return from;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.from)
{
return t.from;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.from)
{
return t.from;
}
// FIXME: We might want to check if we have too many tables define in the FROM
using _consistency_check = consistent_t;
};
};
// FIXME: We might want to check if we have too many tables define in the FROM
using _consistency_check = consistent_t;
};
};
struct no_from_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
struct no_from_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = no_data_t;
// Data
using _data_t = no_data_t;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = no_data_t;
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = no_data_t;
_impl_t<Policies> no_from;
_impl_t<Policies>& operator()() { return no_from; }
const _impl_t<Policies>& operator()() const { return no_from; }
_impl_t<Policies> no_from;
_impl_t<Policies>& operator()()
{
return no_from;
}
const _impl_t<Policies>& operator()() const
{
return no_from;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.no_from)
{
return t.no_from;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.no_from)
{
return t.no_from;
}
using _database_t = typename Policies::_database_t;
using _database_t = typename Policies::_database_t;
template<typename... T>
using _check = logic::all_t<is_table_t<T>::value...>;
template <typename... T>
using _check = logic::all_t<is_table_t<T>::value...>;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_from_t, T>;
template <typename Check, typename 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>
auto from(Tables... tables) const
-> _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(sizeof...(Tables), "at least one table or join argument required in from()");
return _from_impl<void>(_check<Tables...>{}, tables...);
}
template <typename... Tables>
auto from(Tables... tables) const -> _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(sizeof...(Tables), "at least one table or join argument required in from()");
return _from_impl<void>(_check<Tables...>{}, tables...);
}
template<typename... Tables>
auto dynamic_from(Tables... tables) const
-> _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(_check<Tables...>::value, "at least one argument is not a table or join in from()");
return _from_impl<_database_t>(_check<Tables...>{}, tables...);
}
template <typename... Tables>
auto dynamic_from(Tables... tables) const
-> _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(_check<Tables...>::value, "at least one argument is not a table or join in from()");
return _from_impl<_database_t>(_check<Tables...>{}, tables...);
}
private:
template<typename Database, typename... Tables>
auto _from_impl(const std::false_type&, Tables... tables) const
-> bad_statement;
private:
template <typename Database, typename... Tables>
auto _from_impl(const std::false_type&, Tables... tables) const -> bad_statement;
template<typename Database, typename... Tables>
auto _from_impl(const std::true_type&, Tables... tables) const
-> _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()");
template <typename Database, typename... Tables>
auto _from_impl(const std::true_type&, Tables... tables) const
-> _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 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_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_table_names::size::value, "at least one duplicate table name detected in from()");
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_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_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
template <typename Context, typename Database, typename... Tables>
struct serializer_t<Context, from_data_t<Database, Tables...>>
{
using _serialize_check = serialize_check_of<Context, Tables...>;
using T = from_data_t<Database, Tables...>;
// Interpreters
template<typename Context, typename Database, typename... Tables>
struct serializer_t<Context, from_data_t<Database, Tables...>>
{
using _serialize_check = serialize_check_of<Context, Tables...>;
using T = from_data_t<Database, Tables...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Tables) == 0 and t._dynamic_tables.empty())
return context;
context << " FROM ";
interpret_tuple(t._tables, ',', context);
if (sizeof...(Tables) and not t._dynamic_tables.empty())
context << ',';
interpret_list(t._dynamic_tables, ',', context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
if (sizeof...(Tables) == 0 and t._dynamic_tables.empty())
return context;
context << " FROM ";
interpret_tuple(t._tables, ',', context);
if (sizeof...(Tables) and not t._dynamic_tables.empty())
context << ',';
interpret_list(t._dynamic_tables, ',', context);
return context;
}
};
template<typename... 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)...);
}
template <typename... 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)...);
}
}
#endif

View File

@ -44,103 +44,105 @@
#include <sqlpp11/avg.h>
#include <sqlpp11/sum.h>
#include <sqlpp11/value_type.h>
#include <sqlpp11/verbatim.h> // Csaba Csoma suggests: unsafe_sql instead of verbatim
#include <sqlpp11/verbatim.h> // Csaba Csoma suggests: unsafe_sql instead of verbatim
#include <sqlpp11/verbatim_table.h>
#include <sqlpp11/value_or_null.h>
#include <sqlpp11/eval.h>
namespace sqlpp
{
template<typename 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");
return { t };
}
template <typename 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");
return {t};
}
template<typename Expression, typename Db>
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");
auto context = db.get_serializer_context();
serialize(exp, context);
return { context.str() };
}
template <typename Expression, typename Db>
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");
auto context = db.get_serializer_context();
serialize(exp, context);
return {context.str()};
}
template<typename Expression>
auto is_null(Expression e) -> decltype(e.is_null())
{
return e.is_null();
}
template <typename Expression>
auto is_null(Expression e) -> decltype(e.is_null())
{
return e.is_null();
}
template<typename Expression>
auto is_not_null(Expression e) -> decltype(e.is_not_null())
{
return e.is_not_null();
}
template <typename Expression>
auto is_not_null(Expression e) -> decltype(e.is_not_null())
{
return e.is_not_null();
}
template<typename Container>
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 _nodes = detail::type_vector<>;
template <typename Container>
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 _nodes = detail::type_vector<>;
using _container_t = Container;
using _container_t = Container;
value_list_t(_container_t container):
_container(container)
{}
value_list_t(_container_t container) : _container(container)
{
}
value_list_t(const value_list_t&) = default;
value_list_t(value_list_t&&) = default;
value_list_t& operator=(const value_list_t&) = default;
value_list_t& operator=(value_list_t&&) = default;
~value_list_t() = default;
value_list_t(const value_list_t&) = default;
value_list_t(value_list_t&&) = default;
value_list_t& operator=(const value_list_t&) = default;
value_list_t& operator=(value_list_t&&) = default;
~value_list_t() = default;
_container_t _container;
};
_container_t _container;
};
template<typename Context, typename Container>
struct serializer_t<Context, value_list_t<Container>>
{
using _serialize_check = serialize_check_of<Context, wrap_operand_t<typename Container::value_type>>;
using T = value_list_t<Container>;
template <typename Context, typename Container>
struct serializer_t<Context, value_list_t<Container>>
{
using _serialize_check = serialize_check_of<Context, wrap_operand_t<typename Container::value_type>>;
using T = value_list_t<Container>;
static Context& _(const T& t, Context& context)
{
if (t._container.size() == 1)
{
return serialize(value(*begin(t._container)), context);
}
static Context& _(const T& t, Context& context)
{
if (t._container.size() == 1)
{
return serialize(value(*begin(t._container)), context);
}
bool first = true;
for (const auto& entry: t._container)
{
if (first)
first = false;
else
context << ',';
bool first = true;
for (const auto& entry : t._container)
{
if (first)
first = false;
else
context << ',';
serialize_operand(value(entry), context);
}
return context;
}
};
template<typename 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)");
return { c };
}
template<typename T>
constexpr const char* get_sql_name(const T&)
{
return name_of<T>::char_ptr();
}
serialize_operand(value(entry), context);
}
return context;
}
};
template <typename 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)");
return {c};
}
template <typename T>
constexpr const char* get_sql_name(const T&)
{
return name_of<T>::char_ptr();
}
}
#endif

View File

@ -37,203 +37,220 @@
namespace sqlpp
{
// GROUP BY DATA
template<typename Database, typename... Expressions>
struct group_by_data_t
{
group_by_data_t(Expressions... expressions):
_expressions(expressions...)
{}
// GROUP BY DATA
template <typename Database, typename... Expressions>
struct group_by_data_t
{
group_by_data_t(Expressions... expressions) : _expressions(expressions...)
{
}
group_by_data_t(const group_by_data_t&) = default;
group_by_data_t(group_by_data_t&&) = default;
group_by_data_t& operator=(const group_by_data_t&) = default;
group_by_data_t& operator=(group_by_data_t&&) = default;
~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& operator=(const group_by_data_t&) = default;
group_by_data_t& operator=(group_by_data_t&&) = default;
~group_by_data_t() = default;
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
struct assert_no_unknown_tables_in_group_by_t
{
using type = std::false_type;
struct assert_no_unknown_tables_in_group_by_t
{
using type = std::false_type;
template<typename T = 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");
}
};
template <typename T = 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");
}
};
// GROUP BY
template<typename Database, typename... Expressions>
struct group_by_t
{
using _traits = make_traits<no_value_t, tag::is_group_by>;
using _nodes = detail::type_vector<Expressions...>;
// GROUP BY
template <typename Database, typename... Expressions>
struct group_by_t
{
using _traits = make_traits<no_value_t, tag::is_group_by>;
using _nodes = detail::type_vector<Expressions...>;
using _is_dynamic = is_database<Database>;
using _is_dynamic = is_database<Database>;
// Data
using _data_t = group_by_data_t<Database, Expressions...>;
// Data
using _data_t = group_by_data_t<Database, Expressions...>;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
template<typename Expression>
void add_ntc(Expression expression)
{
add<Expression, std::false_type>(expression);
}
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template <typename Expression>
void add_ntc(Expression expression)
{
add<Expression, std::false_type>(expression);
}
template<typename Expression, typename TableCheckRequired = std::true_type>
void add(Expression expression)
{
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(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>;
_serialize_check::_();
template <typename Expression, typename TableCheckRequired = std::true_type>
void add(Expression expression)
{
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(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>;
_serialize_check::_();
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Expression>
void _add_impl(Expression expression, const std::true_type&)
{
return _data._dynamic_expressions.emplace_back(expression);
}
private:
template <typename Expression>
void _add_impl(Expression expression, const std::true_type&)
{
return _data._dynamic_expressions.emplace_back(expression);
}
template<typename Expression>
void _add_impl(Expression expression, const std::false_type&);
public:
_data_t _data;
};
template <typename Expression>
void _add_impl(Expression expression, const std::false_type&);
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = group_by_data_t<Database, Expressions...>;
public:
_data_t _data;
};
_impl_t<Policies> group_by;
_impl_t<Policies>& operator()() { return group_by; }
const _impl_t<Policies>& operator()() const { return group_by; }
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = group_by_data_t<Database, Expressions...>;
template<typename T>
static auto _get_member(T t) -> decltype(t.group_by)
{
return t.group_by;
}
_impl_t<Policies> group_by;
_impl_t<Policies>& operator()()
{
return group_by;
}
const _impl_t<Policies>& operator()() const
{
return group_by;
}
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<group_by_t>::value,
consistent_t,
assert_no_unknown_tables_in_group_by_t>::type;
};
};
template <typename T>
static auto _get_member(T t) -> decltype(t.group_by)
{
return t.group_by;
}
// NO GROUP BY YET
struct no_group_by_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<group_by_t>::value,
consistent_t,
assert_no_unknown_tables_in_group_by_t>::type;
};
};
// Data
using _data_t = no_data_t;
// NO GROUP BY YET
struct no_group_by_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Data
using _data_t = no_data_t;
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = no_data_t;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
_impl_t<Policies> no_group_by;
_impl_t<Policies>& operator()() { return no_group_by; }
const _impl_t<Policies>& operator()() const { return no_group_by; }
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = no_data_t;
template<typename T>
static auto _get_member(T t) -> decltype(t.no_group_by)
{
return t.no_group_by;
}
_impl_t<Policies> no_group_by;
_impl_t<Policies>& operator()()
{
return no_group_by;
}
const _impl_t<Policies>& operator()() const
{
return no_group_by;
}
using _database_t = typename Policies::_database_t;
template <typename T>
static auto _get_member(T t) -> decltype(t.no_group_by)
{
return t.no_group_by;
}
template<typename... T>
using _check = logic::all_t<is_expression_t<T>::value...>;
using _database_t = typename Policies::_database_t;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_group_by_t, T>;
template <typename... T>
using _check = logic::all_t<is_expression_t<T>::value...>;
using _consistency_check = consistent_t;
template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_group_by_t, T>;
template<typename... Expressions>
auto group_by(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, group_by_t<void, Expressions...>>
{
static_assert(sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()");
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in group_by()");
using _consistency_check = consistent_t;
return _group_by_impl<void>(_check<Expressions...>{}, expressions...);
}
template <typename... Expressions>
auto group_by(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, group_by_t<void, Expressions...>>
{
static_assert(sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()");
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in group_by()");
template<typename... Expressions>
auto dynamic_group_by(Expressions... expressions) const
-> _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(_check<Expressions...>::value, "at least one argument is not an expression in group_by()");
return _group_by_impl<void>(_check<Expressions...>{}, expressions...);
}
return _group_by_impl<_database_t>(_check<Expressions...>{}, expressions...);
}
template <typename... Expressions>
auto dynamic_group_by(Expressions... expressions) const
-> _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(_check<Expressions...>::value, "at least one argument is not an expression in group_by()");
private:
template<typename Database, typename... Expressions>
auto _group_by_impl(const std::false_type&, Expressions... expressions) const
-> bad_statement;
return _group_by_impl<_database_t>(_check<Expressions...>{}, expressions...);
}
template<typename Database, typename... Expressions>
auto _group_by_impl(const std::true_type&, Expressions... expressions) const
-> _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()");
private:
template <typename Database, typename... Expressions>
auto _group_by_impl(const std::false_type&, Expressions... expressions) const -> bad_statement;
return { static_cast<const derived_statement_t<Policies>&>(*this), group_by_data_t<Database, Expressions...>{expressions...} };
}
};
};
template <typename Database, typename... Expressions>
auto _group_by_impl(const std::true_type&, Expressions... expressions) const
-> _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()");
// Interpreters
template<typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, group_by_data_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = group_by_data_t<Database, Expressions...>;
return {static_cast<const derived_statement_t<Policies>&>(*this),
group_by_data_t<Database, Expressions...>{expressions...}};
}
};
};
static Context& _(const T& t, Context& context)
{
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " GROUP BY ";
interpret_tuple(t._expressions, ',', context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
context << ',';
interpret_list(t._dynamic_expressions, ',', context);
return context;
}
};
// Interpreters
template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, group_by_data_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = group_by_data_t<Database, Expressions...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " GROUP BY ";
interpret_tuple(t._expressions, ',', context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
context << ',';
interpret_list(t._dynamic_expressions, ',', context);
return context;
}
};
}
#endif

View File

@ -36,202 +36,216 @@
namespace sqlpp
{
// HAVING DATA
template<typename Database, typename... Expressions>
struct having_data_t
{
having_data_t(Expressions... expressions):
_expressions(expressions...)
{}
// HAVING DATA
template <typename Database, typename... Expressions>
struct having_data_t
{
having_data_t(Expressions... expressions) : _expressions(expressions...)
{
}
having_data_t(const having_data_t&) = default;
having_data_t(having_data_t&&) = default;
having_data_t& operator=(const having_data_t&) = default;
having_data_t& operator=(having_data_t&&) = default;
~having_data_t() = default;
having_data_t(const having_data_t&) = default;
having_data_t(having_data_t&&) = default;
having_data_t& operator=(const having_data_t&) = default;
having_data_t& operator=(having_data_t&&) = default;
~having_data_t() = default;
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
struct assert_no_unknown_tables_in_having_t
{
using type = std::false_type;
struct assert_no_unknown_tables_in_having_t
{
using type = std::false_type;
template<typename T = 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");
}
};
template <typename T = 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");
}
};
// HAVING
template<typename Database, typename... Expressions>
struct having_t
{
using _traits = make_traits<no_value_t, tag::is_having>;
using _nodes = detail::type_vector<Expressions...>;
// HAVING
template <typename Database, typename... Expressions>
struct having_t
{
using _traits = make_traits<no_value_t, tag::is_having>;
using _nodes = detail::type_vector<Expressions...>;
using _is_dynamic = is_database<Database>;
using _is_dynamic = is_database<Database>;
// Data
using _data_t = having_data_t<Database, Expressions...>;
// Data
using _data_t = having_data_t<Database, Expressions...>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template<typename Expression>
void add_ntc(Expression expression)
{
add<Expression, std::false_type>(expression);
}
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template <typename Expression>
void add_ntc(Expression expression)
{
add<Expression, std::false_type>(expression);
}
template<typename Expression, typename TableCheckRequired = std::true_type>
void add(Expression expression)
{
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(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>;
_serialize_check::_();
template <typename Expression, typename TableCheckRequired = std::true_type>
void add(Expression expression)
{
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(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>;
_serialize_check::_();
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expression>::value, _serialize_check::type::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Expression>
void _add_impl(Expression expression, const std::true_type&)
{
return _data._dynamic_expressions.emplace_back(expression);
}
private:
template <typename Expression>
void _add_impl(Expression expression, const std::true_type&)
{
return _data._dynamic_expressions.emplace_back(expression);
}
template<typename Expression>
void _add_impl(Expression expression, const std::false_type&);
template <typename Expression>
void _add_impl(Expression expression, const std::false_type&);
public:
_data_t _data;
};
public:
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = having_data_t<Database, Expressions...>;
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = having_data_t<Database, Expressions...>;
_impl_t<Policies> having;
_impl_t<Policies>& operator()() { return having; }
const _impl_t<Policies>& operator()() const { return having; }
_impl_t<Policies> having;
_impl_t<Policies>& operator()()
{
return having;
}
const _impl_t<Policies>& operator()() const
{
return having;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.having)
{
return t.having;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.having)
{
return t.having;
}
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<having_t>::value,
consistent_t,
assert_no_unknown_tables_in_having_t>::type;
};
};
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<having_t>::value,
consistent_t,
assert_no_unknown_tables_in_having_t>::type;
};
};
// NO HAVING YET
struct no_having_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// NO HAVING YET
struct no_having_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = no_data_t;
// Data
using _data_t = no_data_t;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = no_data_t;
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = no_data_t;
_impl_t<Policies> no_having;
_impl_t<Policies>& operator()() { return no_having; }
const _impl_t<Policies>& operator()() const { return no_having; }
_impl_t<Policies> no_having;
_impl_t<Policies>& operator()()
{
return no_having;
}
const _impl_t<Policies>& operator()() const
{
return no_having;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.no_having)
{
return t.no_having;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.no_having)
{
return t.no_having;
}
using _database_t = typename Policies::_database_t;
using _database_t = typename Policies::_database_t;
template<typename... T>
using _check = logic::all_t<is_expression_t<T>::value...>;
template <typename... T>
using _check = logic::all_t<is_expression_t<T>::value...>;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_having_t, T>;
template <typename Check, typename 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>
auto having(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, having_t<void, Expressions...>>
{
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in having()");
static_assert(sizeof...(Expressions), "at least one expression argument required in having()");
template <typename... Expressions>
auto having(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, having_t<void, Expressions...>>
{
static_assert(_check<Expressions...>::value, "at least one argument is not an expression in having()");
static_assert(sizeof...(Expressions), "at least one expression argument required in having()");
return _having_impl<void>(_check<Expressions...>{}, expressions...);
}
return _having_impl<void>(_check<Expressions...>{}, expressions...);
}
template<typename... Expressions>
auto dynamic_having(Expressions... expressions) const
-> _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(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...);
}
template <typename... Expressions>
auto dynamic_having(Expressions... expressions) const
-> _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(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...);
}
private:
template<typename Database, typename... Expressions>
auto _having_impl(const std::false_type&, Expressions... expressions) const
-> bad_statement;
private:
template <typename Database, typename... Expressions>
auto _having_impl(const std::false_type&, Expressions... expressions) const -> bad_statement;
template<typename Database, typename... Expressions>
auto _having_impl(const std::true_type&, Expressions... expressions) const
-> _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...} };
}
template <typename Database, typename... Expressions>
auto _having_impl(const std::true_type&, Expressions... expressions) const
-> _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...}};
}
};
};
};
};
// Interpreters
template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, having_data_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = having_data_t<Database, Expressions...>;
// Interpreters
template<typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, having_data_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = having_data_t<Database, Expressions...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " HAVING ";
interpret_tuple(t._expressions, " AND ", context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
context << " AND ";
interpret_list(t._dynamic_expressions, " AND ", context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " HAVING ";
interpret_tuple(t._expressions, " AND ", context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
context << " AND ";
interpret_list(t._dynamic_expressions, " AND ", context);
return context;
}
};
}
#endif

View File

@ -29,38 +29,36 @@
namespace sqlpp
{
template<typename Part>
struct hidden_t:
public Part
{
hidden_t(Part part):
Part(part)
{}
template <typename Part>
struct hidden_t : public Part
{
hidden_t(Part part) : Part(part)
{
}
hidden_t(const hidden_t&) = default;
hidden_t(hidden_t&&) = default;
hidden_t& operator=(const hidden_t&) = default;
hidden_t& operator=(hidden_t&&) = default;
~hidden_t() = default;
};
hidden_t(const hidden_t&) = default;
hidden_t(hidden_t&&) = default;
hidden_t& operator=(const hidden_t&) = default;
hidden_t& operator=(hidden_t&&) = default;
~hidden_t() = default;
};
template<typename Context, typename Part>
struct serializer_t<Context, hidden_t<Part>>
{
using _serialize_check = consistent_t;
using T = hidden_t<Part>;
template <typename Context, typename Part>
struct serializer_t<Context, hidden_t<Part>>
{
using _serialize_check = consistent_t;
using T = hidden_t<Part>;
static Context& _(const T&, Context& context)
{
return context;
}
};
static Context& _(const T&, Context& context)
{
return context;
}
};
template<typename Part>
auto hidden(Part part)
-> hidden_t<Part>
{
return {part};
}
template <typename Part>
auto hidden(Part part) -> hidden_t<Part>
{
return {part};
}
}
#endif

View File

@ -35,93 +35,90 @@
namespace sqlpp
{
struct in_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "in_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T in;
};
};
};
struct in_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "in_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T in;
};
};
};
template<typename Operand, typename... Args>
struct in_t:
public expression_operators<in_t<Operand, Args...>, boolean>,
public alias_operators<in_t<Operand, Args...>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand, Args...>;
template <typename Operand, typename... Args>
struct in_t : public expression_operators<in_t<Operand, Args...>, boolean>,
public alias_operators<in_t<Operand, Args...>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand, Args...>;
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
static_assert(sizeof...(Args) > 0, "in() requires at least one argument");
using _auto_alias_t = in_alias_t;
using _auto_alias_t = in_alias_t;
in_t(Operand operand, Args... args):
_operand(operand),
_args(args...)
{}
in_t(Operand operand, Args... args) : _operand(operand), _args(args...)
{
}
in_t(const in_t&) = default;
in_t(in_t&&) = default;
in_t& operator=(const in_t&) = default;
in_t& operator=(in_t&&) = default;
~in_t() = default;
in_t(const in_t&) = default;
in_t(in_t&&) = default;
in_t& operator=(const in_t&) = default;
in_t& operator=(in_t&&) = default;
~in_t() = default;
Operand _operand;
std::tuple<Args...> _args;
};
Operand _operand;
std::tuple<Args...> _args;
};
template<typename Context, typename Operand, typename... Args>
struct serializer_t<Context, in_t<Operand, Args...>>
{
using _serialize_check = serialize_check_of<Context, Args...>;
using T = in_t<Operand, Args...>;
template <typename Context, typename Operand, typename... Args>
struct serializer_t<Context, in_t<Operand, Args...>>
{
using _serialize_check = serialize_check_of<Context, Args...>;
using T = in_t<Operand, Args...>;
static Context& _(const T& t, Context& context)
{
serialize(t._operand, context);
context << " IN(";
if (sizeof...(Args) == 1)
serialize(std::get<0>(t._args), context);
else
interpret_tuple(t._args, ',', context);
context << ')';
return context;
}
};
static Context& _(const T& t, Context& context)
{
serialize(t._operand, context);
context << " IN(";
if (sizeof...(Args) == 1)
serialize(std::get<0>(t._args), context);
else
interpret_tuple(t._args, ',', context);
context << ')';
return context;
}
};
template<typename Container>
struct value_list_t;
template <typename Container>
struct value_list_t;
template<typename Context, typename Operand, typename Container>
struct serializer_t<Context, in_t<Operand, value_list_t<Container>>>
{
using _serialize_check = serialize_check_of<Context, value_list_t<Container>>;
using T = in_t<Operand, value_list_t<Container>>;
static Context& _(const T& t, Context& context)
{
const auto& value_list = std::get<0>(t._args);
if (value_list._container.empty())
{
context << " 'operand in empty list' = 'false' ";
}
else
{
serialize(t._operand, context);
context << " IN(";
serialize(value_list, context);
context << ')';
}
return context;
}
};
template <typename Context, typename Operand, typename Container>
struct serializer_t<Context, in_t<Operand, value_list_t<Container>>>
{
using _serialize_check = serialize_check_of<Context, value_list_t<Container>>;
using T = in_t<Operand, value_list_t<Container>>;
static Context& _(const T& t, Context& context)
{
const auto& value_list = std::get<0>(t._args);
if (value_list._container.empty())
{
context << " 'operand in empty list' = 'false' ";
}
else
{
serialize(t._operand, context);
context << " IN(";
serialize(value_list, context);
context << ')';
}
return context;
}
};
}
#endif

View File

@ -29,11 +29,10 @@
namespace sqlpp
{
template<typename Operand, typename... Args>
struct in_t;
template<typename Operand, typename... Args>
struct not_in_t;
template <typename Operand, typename... Args>
struct in_t;
template <typename Operand, typename... Args>
struct not_in_t;
}
#endif

View File

@ -39,102 +39,96 @@
namespace sqlpp
{
struct insert_name_t {};
struct insert_name_t
{
};
struct insert_t: public statement_name_t<insert_name_t>
{
using _traits = make_traits<no_value_t, tag::is_return_value>;
struct _alias_t {};
struct insert_t : public statement_name_t<insert_name_t>
{
using _traits = make_traits<no_value_t, tag::is_return_value>;
struct _alias_t
{
};
template<typename Statement>
struct _result_methods_t
{
using _statement_t = Statement;
template <typename Statement>
struct _result_methods_t
{
using _statement_t = Statement;
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
// Execute
template<typename Db, typename Composite>
auto _run(Db& db, const Composite& composite) const
-> decltype(db.insert(composite))
{
return db.insert(composite);
}
// Execute
template <typename Db, typename Composite>
auto _run(Db& db, const Composite& composite) const -> decltype(db.insert(composite))
{
return db.insert(composite);
}
template<typename Db>
auto _run(Db& db) const -> decltype(db.insert(this->_get_statement()))
{
return db.insert(_get_statement());
}
template <typename Db>
auto _run(Db& db) const -> decltype(db.insert(this->_get_statement()))
{
return db.insert(_get_statement());
}
// Prepare
template<typename Db, typename Composite>
auto _prepare(Db& db, const Composite& composite) const
-> prepared_insert_t<Db, Composite>
{
return {{}, db.prepare_insert(composite)};
}
// Prepare
template <typename Db, typename Composite>
auto _prepare(Db& db, const Composite& composite) const -> prepared_insert_t<Db, Composite>
{
return {{}, db.prepare_insert(composite)};
}
template<typename Db>
auto _prepare(Db& db) const
-> prepared_insert_t<Db, _statement_t>
{
return {{}, db.prepare_insert(_get_statement())};
}
};
};
template <typename Db>
auto _prepare(Db& db) const -> prepared_insert_t<Db, _statement_t>
{
return {{}, db.prepare_insert(_get_statement())};
}
};
};
template<typename Context>
struct serializer_t<Context, insert_name_t>
{
using _serialize_check = consistent_t;
using T = insert_name_t;
template <typename Context>
struct serializer_t<Context, insert_name_t>
{
using _serialize_check = consistent_t;
using T = insert_name_t;
static Context& _(const T&, Context& context)
{
context << "INSERT ";
static Context& _(const T&, Context& context)
{
context << "INSERT ";
return context;
}
};
return context;
}
};
template<typename Database>
using blank_insert_t = statement_t<Database,
insert_t,
no_into_t,
no_insert_value_list_t>;
template <typename Database>
using blank_insert_t = statement_t<Database, insert_t, no_into_t, no_insert_value_list_t>;
inline auto insert()
-> blank_insert_t<void>
{
return { blank_insert_t<void>() };
}
inline auto insert() -> blank_insert_t<void>
{
return {blank_insert_t<void>()};
}
template<typename Table>
constexpr auto insert_into(Table table)
-> decltype(blank_insert_t<void>().into(table))
{
return { blank_insert_t<void>().into(table) };
}
template <typename Table>
constexpr auto insert_into(Table table) -> decltype(blank_insert_t<void>().into(table))
{
return {blank_insert_t<void>().into(table)};
}
template<typename Database>
constexpr auto dynamic_insert(const Database&)
-> decltype(blank_insert_t<Database>())
{
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return { blank_insert_t<Database>() };
}
template <typename Database>
constexpr auto dynamic_insert(const Database&) -> decltype(blank_insert_t<Database>())
{
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return {blank_insert_t<Database>()};
}
template<typename Database, typename Table>
constexpr auto dynamic_insert_into(const Database&, Table table)
-> decltype(blank_insert_t<Database>().into(table))
{
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return { blank_insert_t<Database>().into(table) };
}
template <typename Database, typename Table>
constexpr auto dynamic_insert_into(const Database&, Table table) -> decltype(blank_insert_t<Database>().into(table))
{
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return {blank_insert_t<Database>().into(table)};
}
}
#endif

View File

@ -36,91 +36,84 @@
namespace sqlpp
{
namespace detail
{
template<typename Type, bool>
struct type_if
{
using type = Type;
};
namespace detail
{
template <typename Type, bool>
struct type_if
{
using type = Type;
};
template<typename Type>
struct type_if<Type, false>
{
struct type
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
};
};
}
template <typename Type>
struct type_if<Type, false>
{
struct type
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
};
};
}
template<typename Column>
struct insert_value_t
{
using _is_insert_value = std::true_type;
using _column_t = Column;
static constexpr bool _trivial_value_is_null = trivial_value_is_null_t<Column>::value;
using _pure_value_t = typename value_type_of<Column>::_cpp_value_type;
using _wrapped_value_t = wrap_operand_t<_pure_value_t>;
using _tvin_t = tvin_t<_wrapped_value_t>;
template <typename Column>
struct insert_value_t
{
using _is_insert_value = std::true_type;
using _column_t = Column;
static constexpr bool _trivial_value_is_null = trivial_value_is_null_t<Column>::value;
using _pure_value_t = typename value_type_of<Column>::_cpp_value_type;
using _wrapped_value_t = wrap_operand_t<_pure_value_t>;
using _tvin_t = tvin_t<_wrapped_value_t>;
insert_value_t(rhs_wrap_t<_wrapped_value_t, _trivial_value_is_null> rhs):
_is_null(rhs._is_null()),
_is_default(rhs._is_default()),
_value(rhs._expr._t)
{}
insert_value_t(rhs_wrap_t<_wrapped_value_t, _trivial_value_is_null> rhs)
: _is_null(rhs._is_null()), _is_default(rhs._is_default()), _value(rhs._expr._t)
{
}
insert_value_t(rhs_wrap_t<_tvin_t, _trivial_value_is_null> rhs):
_is_null(rhs._is_null()),
_is_default(rhs._is_default()),
_value(rhs._expr._value)
{}
insert_value_t(rhs_wrap_t<_tvin_t, _trivial_value_is_null> rhs)
: _is_null(rhs._is_null()), _is_default(rhs._is_default()), _value(rhs._expr._value)
{
}
insert_value_t(const rhs_wrap_t<null_t, _trivial_value_is_null>&):
_is_null(true),
_is_default(false),
_value{}
{}
insert_value_t(const rhs_wrap_t<null_t, _trivial_value_is_null>&) : _is_null(true), _is_default(false), _value{}
{
}
insert_value_t(const rhs_wrap_t<default_value_t, _trivial_value_is_null>&):
_is_null(false),
_is_default(true),
_value{}
{}
insert_value_t(const rhs_wrap_t<default_value_t, _trivial_value_is_null>&)
: _is_null(false), _is_default(true), _value{}
{
}
insert_value_t(const insert_value_t&) = default;
insert_value_t(insert_value_t&&) = default;
insert_value_t& operator=(const insert_value_t&) = default;
insert_value_t& operator=(insert_value_t&&) = default;
~insert_value_t() = default;
insert_value_t(const insert_value_t&) = default;
insert_value_t(insert_value_t&&) = default;
insert_value_t& operator=(const insert_value_t&) = default;
insert_value_t& operator=(insert_value_t&&) = default;
~insert_value_t() = default;
bool _is_null;
bool _is_default;
_wrapped_value_t _value;
};
bool _is_null;
bool _is_default;
_wrapped_value_t _value;
};
template<typename Context, typename ValueType>
struct serializer_t<Context, insert_value_t<ValueType>>
{
using _serialize_check = serialize_check_of<Context, ValueType>;
using T = insert_value_t<ValueType>;
static Context& _(const T& t, Context& context)
{
if ((trivial_value_is_null_t<typename T::_column_t>::value and t._value._is_trivial())
or t._is_null)
{
context << "NULL";
}
else if (t._is_default)
context << "DEFAULT";
else
serialize_operand(t._value, context);
return context;
}
};
template <typename Context, typename ValueType>
struct serializer_t<Context, insert_value_t<ValueType>>
{
using _serialize_check = serialize_check_of<Context, ValueType>;
using T = insert_value_t<ValueType>;
static Context& _(const T& t, Context& context)
{
if ((trivial_value_is_null_t<typename T::_column_t>::value and t._value._is_trivial()) or t._is_null)
{
context << "NULL";
}
else if (t._is_default)
context << "DEFAULT";
else
serialize_operand(t._value, context);
return context;
}
};
}
#endif

View File

@ -39,477 +39,509 @@
namespace sqlpp
{
namespace detail
{
template<typename... Columns>
struct have_all_required_columns
{
static constexpr bool value = false;
};
template<typename First, typename... Columns>
struct have_all_required_columns<First, Columns...>
{
using _table = typename First::_table;
using required_columns = typename _table::_required_insert_columns;
using set_columns = detail::make_type_set_t<First, Columns...>;
static constexpr bool value = detail::is_subset_of<required_columns, set_columns>::value;
};
}
struct insert_default_values_data_t
{};
// COLUMN AND VALUE LIST
struct insert_default_values_t
{
using _traits = make_traits<no_value_t>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = insert_default_values_data_t;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = insert_default_values_data_t;
_impl_t<Policies> default_values;
_impl_t<Policies>& operator()() { return default_values; }
const _impl_t<Policies>& operator()() const { return default_values; }
template<typename T>
static auto _get_member(T t) -> decltype(t.default_values)
{
return t.default_values;
}
using _consistency_check = consistent_t;
};
};
template<typename Database, typename... Assignments>
struct insert_list_data_t
{
insert_list_data_t(Assignments... assignments):
_assignments(assignments...),
_columns({assignments._lhs}...),
_values(assignments._rhs...)
{}
insert_list_data_t(const insert_list_data_t&) = default;
insert_list_data_t(insert_list_data_t&&) = default;
insert_list_data_t& operator=(const insert_list_data_t&) = default;
insert_list_data_t& operator=(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<simple_column_t<lhs_t<Assignments>>...> _columns;
std::tuple<rhs_t<Assignments>...> _values;
interpretable_list_t<Database> _dynamic_columns;
interpretable_list_t<Database> _dynamic_values;
};
struct assert_no_unknown_tables_in_insert_assignments_t
{
using type = std::false_type;
template<typename T = 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");
}
};
template<typename Database, typename... Assignments>
struct insert_list_t
{
using _traits = make_traits<no_value_t, tag::is_insert_list>;
using _nodes = detail::type_vector<lhs_t<Assignments>..., rhs_t<Assignments>...>;
using _is_dynamic = is_database<Database>;
template<template<typename...> class Target>
using copy_assignments_t = Target<Assignments...>; // FIXME: Nice idea to copy variadic template arguments?
template<template<typename...> class Target, template<typename> class Wrap>
using copy_wrapped_assignments_t = Target<Wrap<Assignments>...>;
// Data
using _data_t = insert_list_data_t<Database, Assignments...>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template<typename Assignment>
void add_ntc(Assignment assignment)
{
add<Assignment, std::false_type>(assignment);
}
template<typename Assignment, typename TableCheckRequired = std::true_type>
void add(Assignment assignment)
{
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");
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 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");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>;
_serialize_check::_();
using ok = logic::all_t<
_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
}
private:
template<typename Assignment>
void _add_impl(Assignment assignment, const std::true_type&)
{
_data._dynamic_columns.emplace_back(simple_column_t<lhs_t<Assignment>>{assignment._lhs});
_data._dynamic_values.emplace_back(assignment._rhs);
}
template<typename Assignment>
void _add_impl(Assignment assignment, const std::false_type&);
public:
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = insert_list_data_t<Database, Assignments...>;
_impl_t<Policies> insert_list;
_impl_t<Policies>& operator()() { return insert_list; }
const _impl_t<Policies>& operator()() const { return insert_list; }
template<typename T>
static auto _get_member(T t) -> decltype(t.insert_list)
{
return t.insert_list;
}
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<insert_list_t>::value,
consistent_t,
assert_no_unknown_tables_in_insert_assignments_t>::type;
};
};
template<typename... Columns>
struct column_list_data_t
{
column_list_data_t(Columns... cols):
_columns(simple_column_t<Columns>{cols}...)
{}
column_list_data_t(const column_list_data_t&) = default;
column_list_data_t(column_list_data_t&&) = default;
column_list_data_t& operator=(const column_list_data_t&) = default;
column_list_data_t& operator=(column_list_data_t&&) = default;
~column_list_data_t() = default;
using _value_tuple_t = std::tuple<insert_value_t<Columns>...>;
std::tuple<simple_column_t<Columns>...> _columns;
std::vector<_value_tuple_t> _insert_values;
};
struct assert_no_unknown_tables_in_column_list_t
{
using type = std::false_type;
template<typename T = void>
static void _()
{
static_assert(wrong_t<T>::value, "at least one column requires a table which is otherwise not known in the statement");
}
};
template<typename... Columns>
struct column_list_t
{
using _traits = make_traits<no_value_t, tag::is_column_list>;
using _nodes = detail::type_vector<Columns...>;
using _value_tuple_t = typename column_list_data_t<Columns...>::_value_tuple_t;
// Data
using _data_t = column_list_data_t<Columns...>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template<typename... Assignments>
void add(Assignments... 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 _args_correct = std::is_same<_arg_value_tuple, _value_tuple_t>;
static_assert(_args_correct::value, "add_values() arguments do not match columns() arguments");
using ok = logic::all_t<
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
}
private:
template<typename... Assignments>
void _add_impl(const std::true_type&, Assignments... assignments)
{
return _data._insert_values.emplace_back(insert_value_t<lhs_t<Assignments>>{assignments._rhs}...);
}
template<typename... Assignments>
void _add_impl(const std::false_type&, Assignments... assignments);
public:
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = column_list_data_t<Columns...>;
_impl_t<Policies> values;
_impl_t<Policies>& operator()() { return values; }
const _impl_t<Policies>& operator()() const { return values; }
template<typename T>
static auto _get_member(T t) -> decltype(t.values)
{
return t.values;
}
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<column_list_t>::value,
consistent_t,
assert_no_unknown_tables_in_column_list_t>::type;
};
};
struct assert_insert_values_t
{
using type = std::false_type;
template<typename T = void>
static void _()
{
static_assert(wrong_t<T>::value, "insert values required, e.g. set(...) or default_values()");
}
};
// NO INSERT COLUMNS/VALUES YET
struct no_insert_value_list_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = no_data_t;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = no_data_t;
_impl_t<Policies> no_insert_values;
_impl_t<Policies>& operator()() { return no_insert_values; }
const _impl_t<Policies>& operator()() const { return no_insert_values; }
template<typename T>
static auto _get_member(T t) -> decltype(t.no_insert_values)
{
return t.no_insert_values;
}
using _database_t = typename Policies::_database_t;
template<typename... T>
using _column_check = logic::all_t<is_column_t<T>::value...>;
template<typename... T>
using _assignment_check = logic::all_t<is_assignment_t<T>::value...>;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_insert_value_list_t, T>;
using _consistency_check = assert_insert_values_t;
auto default_values() const
-> _new_statement_t<std::true_type, insert_default_values_t>
{
return { static_cast<const derived_statement_t<Policies>&>(*this), insert_default_values_data_t{} };
}
template<typename... Columns>
auto columns(Columns... cols) const
-> _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(sizeof...(Columns), "at least one column required in columns()");
return _columns_impl(_column_check<Columns...>{}, cols...);
}
template<typename... Assignments>
auto set(Assignments... assignments) const
-> _new_statement_t<_assignment_check<Assignments...>, insert_list_t<void, Assignments...>>
{
static_assert(_assignment_check<Assignments...>::value, "at least one argument is not an assignment in set()");
static_assert(sizeof...(Assignments), "at least one assignment expression required in set()");
return _set_impl<void>(_assignment_check<Assignments...>{}, assignments...);
}
template<typename... Assignments>
auto dynamic_set(Assignments... assignments) const
-> _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(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...);
}
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
-> _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(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>...>;
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()");
return { static_cast<const derived_statement_t<Policies>&>(*this), column_list_data_t<Columns...>{cols...} };
}
template<typename Database, typename... Assignments>
auto _set_impl(const std::false_type&, Assignments... assignments) const
-> bad_statement;
template<typename Database, typename... Assignments>
auto _set_impl(const std::true_type&, Assignments... assignments) const
-> _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(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>>...>;
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()");
return { static_cast<const derived_statement_t<Policies>&>(*this), insert_list_data_t<Database, Assignments...>{assignments...} };
}
};
};
// Interpreters
template<typename Context>
struct serializer_t<Context, insert_default_values_data_t>
{
using _serialize_check = consistent_t;
using T = insert_default_values_data_t;
static Context& _(const T&, Context& context)
{
context << " DEFAULT VALUES";
return context;
}
};
template<typename Context, typename... Columns>
struct serializer_t<Context, column_list_data_t<Columns...>>
{
using _serialize_check = serialize_check_of<Context, Columns...>;
using T = column_list_data_t<Columns...>;
static Context& _(const T& t, Context& context)
{
context << " (";
interpret_tuple(t._columns, ",", context);
context << ")";
context << " VALUES ";
bool first = true;
for (const auto& row : t._insert_values)
{
if (not first)
context << ',';
else
first = false;
context << '(';
interpret_tuple(row, ",", context);
context << ')';
}
return context;
}
};
template<typename Context, typename Database, typename... Assignments>
struct serializer_t<Context, insert_list_data_t<Database, Assignments...>>
{
using _serialize_check = serialize_check_of<Context, Assignments...>;
using T = insert_list_data_t<Database, Assignments...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Assignments) + t._dynamic_columns.size() == 0)
{
serialize(insert_default_values_data_t(), context);
}
else
{
context << " (";
interpret_tuple(t._columns, ",", context);
if (sizeof...(Assignments) and not t._dynamic_columns.empty())
context << ',';
interpret_list(t._dynamic_columns, ',', context);
context << ") VALUES(";
interpret_tuple(t._values, ",", context);
if (sizeof...(Assignments) and not t._dynamic_values.empty())
context << ',';
interpret_list(t._dynamic_values, ',', context);
context << ")";
}
return context;
}
};
namespace detail
{
template <typename... Columns>
struct have_all_required_columns
{
static constexpr bool value = false;
};
template <typename First, typename... Columns>
struct have_all_required_columns<First, Columns...>
{
using _table = typename First::_table;
using required_columns = typename _table::_required_insert_columns;
using set_columns = detail::make_type_set_t<First, Columns...>;
static constexpr bool value = detail::is_subset_of<required_columns, set_columns>::value;
};
}
struct insert_default_values_data_t
{
};
// COLUMN AND VALUE LIST
struct insert_default_values_t
{
using _traits = make_traits<no_value_t>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = insert_default_values_data_t;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = insert_default_values_data_t;
_impl_t<Policies> default_values;
_impl_t<Policies>& operator()()
{
return default_values;
}
const _impl_t<Policies>& operator()() const
{
return default_values;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.default_values)
{
return t.default_values;
}
using _consistency_check = consistent_t;
};
};
template <typename Database, typename... Assignments>
struct insert_list_data_t
{
insert_list_data_t(Assignments... assignments)
: _assignments(assignments...), _columns({assignments._lhs}...), _values(assignments._rhs...)
{
}
insert_list_data_t(const insert_list_data_t&) = default;
insert_list_data_t(insert_list_data_t&&) = default;
insert_list_data_t& operator=(const insert_list_data_t&) = default;
insert_list_data_t& operator=(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<simple_column_t<lhs_t<Assignments>>...> _columns;
std::tuple<rhs_t<Assignments>...> _values;
interpretable_list_t<Database> _dynamic_columns;
interpretable_list_t<Database> _dynamic_values;
};
struct assert_no_unknown_tables_in_insert_assignments_t
{
using type = std::false_type;
template <typename T = 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");
}
};
template <typename Database, typename... Assignments>
struct insert_list_t
{
using _traits = make_traits<no_value_t, tag::is_insert_list>;
using _nodes = detail::type_vector<lhs_t<Assignments>..., rhs_t<Assignments>...>;
using _is_dynamic = is_database<Database>;
template <template <typename...> class Target>
using copy_assignments_t = Target<Assignments...>; // FIXME: Nice idea to copy variadic template arguments?
template <template <typename...> class Target, template <typename> class Wrap>
using copy_wrapped_assignments_t = Target<Wrap<Assignments>...>;
// Data
using _data_t = insert_list_data_t<Database, Assignments...>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template <typename Assignment>
void add_ntc(Assignment assignment)
{
add<Assignment, std::false_type>(assignment);
}
template <typename Assignment, typename TableCheckRequired = std::true_type>
void add(Assignment assignment)
{
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");
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 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");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Assignment>;
_serialize_check::_();
using ok = logic::all_t<_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
}
private:
template <typename Assignment>
void _add_impl(Assignment assignment, const std::true_type&)
{
_data._dynamic_columns.emplace_back(simple_column_t<lhs_t<Assignment>>{assignment._lhs});
_data._dynamic_values.emplace_back(assignment._rhs);
}
template <typename Assignment>
void _add_impl(Assignment assignment, const std::false_type&);
public:
_data_t _data;
};
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = insert_list_data_t<Database, Assignments...>;
_impl_t<Policies> insert_list;
_impl_t<Policies>& operator()()
{
return insert_list;
}
const _impl_t<Policies>& operator()() const
{
return insert_list;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.insert_list)
{
return t.insert_list;
}
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<insert_list_t>::value,
consistent_t,
assert_no_unknown_tables_in_insert_assignments_t>::type;
};
};
template <typename... Columns>
struct column_list_data_t
{
column_list_data_t(Columns... cols) : _columns(simple_column_t<Columns>{cols}...)
{
}
column_list_data_t(const column_list_data_t&) = default;
column_list_data_t(column_list_data_t&&) = default;
column_list_data_t& operator=(const column_list_data_t&) = default;
column_list_data_t& operator=(column_list_data_t&&) = default;
~column_list_data_t() = default;
using _value_tuple_t = std::tuple<insert_value_t<Columns>...>;
std::tuple<simple_column_t<Columns>...> _columns;
std::vector<_value_tuple_t> _insert_values;
};
struct assert_no_unknown_tables_in_column_list_t
{
using type = std::false_type;
template <typename T = void>
static void _()
{
static_assert(wrong_t<T>::value,
"at least one column requires a table which is otherwise not known in the statement");
}
};
template <typename... Columns>
struct column_list_t
{
using _traits = make_traits<no_value_t, tag::is_column_list>;
using _nodes = detail::type_vector<Columns...>;
using _value_tuple_t = typename column_list_data_t<Columns...>::_value_tuple_t;
// Data
using _data_t = column_list_data_t<Columns...>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template <typename... Assignments>
void add(Assignments... 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 _args_correct = std::is_same<_arg_value_tuple, _value_tuple_t>;
static_assert(_args_correct::value, "add_values() arguments do not match columns() arguments");
using ok = logic::all_t<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
}
private:
template <typename... Assignments>
void _add_impl(const std::true_type&, Assignments... assignments)
{
return _data._insert_values.emplace_back(insert_value_t<lhs_t<Assignments>>{assignments._rhs}...);
}
template <typename... Assignments>
void _add_impl(const std::false_type&, Assignments... assignments);
public:
_data_t _data;
};
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = column_list_data_t<Columns...>;
_impl_t<Policies> values;
_impl_t<Policies>& operator()()
{
return values;
}
const _impl_t<Policies>& operator()() const
{
return values;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.values)
{
return t.values;
}
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<column_list_t>::value,
consistent_t,
assert_no_unknown_tables_in_column_list_t>::type;
};
};
struct assert_insert_values_t
{
using type = std::false_type;
template <typename T = void>
static void _()
{
static_assert(wrong_t<T>::value, "insert values required, e.g. set(...) or default_values()");
}
};
// NO INSERT COLUMNS/VALUES YET
struct no_insert_value_list_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = no_data_t;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = no_data_t;
_impl_t<Policies> no_insert_values;
_impl_t<Policies>& operator()()
{
return no_insert_values;
}
const _impl_t<Policies>& operator()() const
{
return no_insert_values;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.no_insert_values)
{
return t.no_insert_values;
}
using _database_t = typename Policies::_database_t;
template <typename... T>
using _column_check = logic::all_t<is_column_t<T>::value...>;
template <typename... T>
using _assignment_check = logic::all_t<is_assignment_t<T>::value...>;
template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_insert_value_list_t, T>;
using _consistency_check = assert_insert_values_t;
auto default_values() const -> _new_statement_t<std::true_type, insert_default_values_t>
{
return {static_cast<const derived_statement_t<Policies>&>(*this), insert_default_values_data_t{}};
}
template <typename... Columns>
auto columns(Columns... cols) const -> _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(sizeof...(Columns), "at least one column required in columns()");
return _columns_impl(_column_check<Columns...>{}, cols...);
}
template <typename... Assignments>
auto set(Assignments... assignments) const
-> _new_statement_t<_assignment_check<Assignments...>, insert_list_t<void, Assignments...>>
{
static_assert(_assignment_check<Assignments...>::value, "at least one argument is not an assignment in set()");
static_assert(sizeof...(Assignments), "at least one assignment expression required in set()");
return _set_impl<void>(_assignment_check<Assignments...>{}, assignments...);
}
template <typename... Assignments>
auto dynamic_set(Assignments... assignments) const
-> _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(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...);
}
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
-> _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(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>...>;
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()");
return {static_cast<const derived_statement_t<Policies>&>(*this), column_list_data_t<Columns...>{cols...}};
}
template <typename Database, typename... Assignments>
auto _set_impl(const std::false_type&, Assignments... assignments) const -> bad_statement;
template <typename Database, typename... Assignments>
auto _set_impl(const std::true_type&, Assignments... assignments) const
-> _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(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>>...>;
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()");
return {static_cast<const derived_statement_t<Policies>&>(*this),
insert_list_data_t<Database, Assignments...>{assignments...}};
}
};
};
// Interpreters
template <typename Context>
struct serializer_t<Context, insert_default_values_data_t>
{
using _serialize_check = consistent_t;
using T = insert_default_values_data_t;
static Context& _(const T&, Context& context)
{
context << " DEFAULT VALUES";
return context;
}
};
template <typename Context, typename... Columns>
struct serializer_t<Context, column_list_data_t<Columns...>>
{
using _serialize_check = serialize_check_of<Context, Columns...>;
using T = column_list_data_t<Columns...>;
static Context& _(const T& t, Context& context)
{
context << " (";
interpret_tuple(t._columns, ",", context);
context << ")";
context << " VALUES ";
bool first = true;
for (const auto& row : t._insert_values)
{
if (not first)
context << ',';
else
first = false;
context << '(';
interpret_tuple(row, ",", context);
context << ')';
}
return context;
}
};
template <typename Context, typename Database, typename... Assignments>
struct serializer_t<Context, insert_list_data_t<Database, Assignments...>>
{
using _serialize_check = serialize_check_of<Context, Assignments...>;
using T = insert_list_data_t<Database, Assignments...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Assignments) + t._dynamic_columns.size() == 0)
{
serialize(insert_default_values_data_t(), context);
}
else
{
context << " (";
interpret_tuple(t._columns, ",", context);
if (sizeof...(Assignments) and not t._dynamic_columns.empty())
context << ',';
interpret_list(t._dynamic_columns, ',', context);
context << ") VALUES(";
interpret_tuple(t._values, ",", context);
if (sizeof...(Assignments) and not t._dynamic_values.empty())
context << ',';
interpret_list(t._dynamic_values, ',', context);
context << ")";
}
return context;
}
};
}
#endif

View File

@ -37,293 +37,291 @@
namespace sqlpp
{
// integral value type
struct integral
{
using _traits = make_traits<integral, tag::is_value_type>;
using _tag = tag::is_integral;
using _cpp_value_type = int64_t;
// integral value type
struct integral
{
using _traits = make_traits<integral, tag::is_value_type>;
using _tag = tag::is_integral;
using _cpp_value_type = int64_t;
template<typename T>
using _is_valid_operand = is_numeric_t<T>;
};
template <typename T>
using _is_valid_operand = is_numeric_t<T>;
};
// integral parameter value
template<>
struct parameter_value_t<integral>
{
using _value_type = integral;
using _cpp_value_type = typename _value_type::_cpp_value_type;
// integral parameter value
template <>
struct parameter_value_t<integral>
{
using _value_type = integral;
using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t():
_value(0),
_is_null(true)
{}
parameter_value_t() : _value(0), _is_null(true)
{
}
explicit parameter_value_t(const _cpp_value_type& val):
_value(val),
_is_null(false)
{}
explicit parameter_value_t(const _cpp_value_type& val) : _value(val), _is_null(false)
{
}
parameter_value_t& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_t& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_t& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = 0;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
parameter_value_t& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = 0;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
void set_null()
{
_value = 0;
_is_null = true;
}
void set_null()
{
_value = 0;
_is_null = true;
}
bool is_null() const
{
return _is_null;
}
bool is_null() const
{
return _is_null;
}
const _cpp_value_type& value() const
{
return _value;
}
const _cpp_value_type& value() const
{
return _value;
}
operator _cpp_value_type() const { return _value; }
operator _cpp_value_type() const
{
return _value;
}
template<typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_integral_parameter(index, &_value, _is_null);
}
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_integral_parameter(index, &_value, _is_null);
}
private:
_cpp_value_type _value;
bool _is_null;
};
private:
_cpp_value_type _value;
bool _is_null;
};
// integral expression operators
template<typename Base>
struct expression_operators<Base, integral>: public basic_expression_operators<Base, integral>
{
template<typename T>
using _is_valid_operand = is_valid_operand<integral, T>;
// integral expression operators
template <typename Base>
struct expression_operators<Base, integral> : public basic_expression_operators<Base, integral>
{
template <typename T>
using _is_valid_operand = is_valid_operand<integral, T>;
template<typename T>
plus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator +(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
plus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator+(T t) const
{
using rhs = wrap_operand_t<T>;
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>
minus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator -(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
minus_t<Base, value_type_t<T>, wrap_operand_t<T>> operator-(T t) const
{
using rhs = wrap_operand_t<T>;
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>
multiplies_t<Base, value_type_t<T>, wrap_operand_t<T>> operator *(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
multiplies_t<Base, value_type_t<T>, wrap_operand_t<T>> operator*(T t) const
{
using rhs = wrap_operand_t<T>;
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>
divides_t<Base, wrap_operand_t<T>> operator /(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
divides_t<Base, wrap_operand_t<T>> operator/(T t) const
{
using rhs = wrap_operand_t<T>;
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>
modulus_t<Base, wrap_operand_t<T>> operator %(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
modulus_t<Base, wrap_operand_t<T>> operator%(T t) const
{
using rhs = wrap_operand_t<T>;
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
{
return { *static_cast<const Base*>(this) };
}
unary_plus_t<integral, Base> operator+() const
{
return {*static_cast<const Base*>(this)};
}
unary_minus_t<integral, Base> operator -() const
{
return { *static_cast<const Base*>(this) };
}
unary_minus_t<integral, Base> operator-() const
{
return {*static_cast<const Base*>(this)};
}
template<typename T>
bitwise_and_t<Base, value_type_t<T>, wrap_operand_t<T>> operator &(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
bitwise_and_t<Base, value_type_t<T>, wrap_operand_t<T>> operator&(T t) const
{
using rhs = wrap_operand_t<T>;
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>
bitwise_or_t<Base, value_type_t<T>, wrap_operand_t<T>> operator |(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
template <typename T>
bitwise_or_t<Base, value_type_t<T>, wrap_operand_t<T>> operator|(T t) const
{
using rhs = wrap_operand_t<T>;
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
template <typename Base>
struct column_operators<Base, integral>
{
template <typename T>
using _is_valid_operand = is_valid_operand<integral, T>;
// integral column operators
template<typename Base>
struct column_operators<Base, integral>
{
template<typename T>
using _is_valid_operand = is_valid_operand<integral, T>;
template <typename 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>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
template<typename 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>;
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>
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>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
template<typename 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>;
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>
auto operator/=(T t) const -> assignment_t<Base, divides_t<Base, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
template<typename T>
auto operator /=(T t) const -> assignment_t<Base, divides_t<Base, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
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>
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>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
template<typename 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>;
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
template <typename Db, typename 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");
using _cpp_value_type = typename integral::_cpp_value_type;
// integral result field
template<typename Db, typename 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");
using _cpp_value_type = typename integral::_cpp_value_type;
result_field_t() : _is_valid(false), _is_null(true), _value(0)
{
}
result_field_t():
_is_valid(false),
_is_null(true),
_value(0)
{}
void _invalidate()
{
_is_valid = false;
_is_null = true;
_value = 0;
}
void _invalidate()
{
_is_valid = false;
_is_null = true;
_value = 0;
}
void _validate()
{
_is_valid = true;
}
void _validate()
{
_is_valid = true;
}
bool is_null() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return _is_null;
}
bool is_null() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return _is_null;
}
bool _is_trivial() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
bool _is_trivial() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return value() == 0;
}
return value() == 0;
}
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
if (_is_null)
{
if (enforce_null_result_treatment_t<Db>::value and not null_is_trivial_value_t<FieldSpec>::value)
{
throw exception("accessing value of NULL field");
}
else
{
return 0;
}
}
return _value;
}
if (_is_null)
{
if (enforce_null_result_treatment_t<Db>::value and not null_is_trivial_value_t<FieldSpec>::value)
{
throw exception("accessing value of NULL field");
}
else
{
return 0;
}
}
return _value;
}
template <typename Target>
void _bind(Target& target, size_t i)
{
target._bind_integral_result(i, &_value, &_is_null);
}
template<typename Target>
void _bind(Target& target, size_t i)
{
target._bind_integral_result(i, &_value, &_is_null);
}
private:
bool _is_valid;
bool _is_null;
_cpp_value_type _value;
};
private:
bool _is_valid;
bool _is_null;
_cpp_value_type _value;
};
// ostream operator for integral result field
template<typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<integral, Db, FieldSpec>& e)
{
return serialize(e, os);
}
using tinyint = integral;
using smallint = integral;
using integer = integral;
using bigint = integral;
// ostream operator for integral result field
template <typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<integral, Db, FieldSpec>& e)
{
return serialize(e, os);
}
using tinyint = integral;
using smallint = integral;
using integer = integral;
using bigint = integral;
}
#endif

View File

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

View File

@ -34,45 +34,50 @@
namespace sqlpp
{
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)
{
if (index)
context << separator;
if (UseBraces::value)
serialize_operand(element, context);
else
serialize(element, context);
}
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)
{
if (index)
context << separator;
if (UseBraces::value)
serialize_operand(element, context);
else
serialize(element, context);
}
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...>&)
-> 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.
// See for example: "http://en.cppreference.com/w/cpp/utility/integer_sequence"
// 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
using swallow = int[];
(void) swallow{
0, //workaround against -Wpedantic GCC warning "zero-size array 'int [0]'"
(interpret_tuple_element(std::get<Is>(t), separator, context, useBraces, Is), 0)...};
return context;
}
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...>&) -> 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.
// See for example: "http://en.cppreference.com/w/cpp/utility/integer_sequence"
// 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
using swallow = int[];
(void)swallow{0, // workaround against -Wpedantic GCC warning "zero-size array 'int [0]'"
(interpret_tuple_element(std::get<Is>(t), separator, context, useBraces, Is), 0)...};
return context;
}
template<typename Tuple, typename Separator, typename Context>
auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context)
-> Context&
{
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>
auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) -> Context &
{
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>
auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context)
-> Context&
{
return interpret_tuple_impl(t, separator, context, std::false_type{}, detail::make_index_sequence<std::tuple_size<Tuple>::value>{});
}
template <typename Tuple, typename Separator, typename Context>
auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context) -> Context &
{
return interpret_tuple_impl(t, separator, context, std::false_type{},
detail::make_index_sequence<std::tuple_size<Tuple>::value>{});
}
}
#endif

View File

@ -35,106 +35,106 @@
namespace sqlpp
{
template<typename Db>
struct interpretable_t
{
using _serializer_context_t = typename Db::_serializer_context_t;
using _interpreter_context_t = typename Db::_interpreter_context_t;
template <typename Db>
struct interpretable_t
{
using _serializer_context_t = typename Db::_serializer_context_t;
using _interpreter_context_t = typename Db::_interpreter_context_t;
template<typename T>
interpretable_t(T t):
_requires_braces(requires_braces_t<T>::value),
_impl(std::make_shared<_impl_t<T>>(t))
{}
template <typename T>
interpretable_t(T t)
: _requires_braces(requires_braces_t<T>::value), _impl(std::make_shared<_impl_t<T>>(t))
{
}
interpretable_t(const interpretable_t&) = default;
interpretable_t(interpretable_t&&) = default;
interpretable_t& operator=(const interpretable_t&) = default;
interpretable_t& operator=(interpretable_t&&) = default;
~interpretable_t() = default;
interpretable_t(const interpretable_t&) = default;
interpretable_t(interpretable_t&&) = default;
interpretable_t& operator=(const interpretable_t&) = default;
interpretable_t& operator=(interpretable_t&&) = default;
~interpretable_t() = default;
serializer_context_t& serialize(serializer_context_t& context) const
{
return _impl->serialize(context);
}
serializer_context_t& serialize(serializer_context_t& context) const
{
return _impl->serialize(context);
}
// This method only exists if Db::_serializer_context_t and serializer_context_t are not the same
template<typename Context>
auto serialize(Context& context) const
-> typename std::enable_if<std::is_same<Context, _serializer_context_t>::value
and not std::is_same<Context, serializer_context_t>::value, Context&>::type
{
return _impl->db_serialize(context);
}
// This method only exists if Db::_serializer_context_t and serializer_context_t are not the same
template <typename Context>
auto serialize(Context& context) const ->
typename std::enable_if<std::is_same<Context, _serializer_context_t>::value and
not std::is_same<Context, serializer_context_t>::value,
Context&>::type
{
return _impl->db_serialize(context);
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
return _impl->interpret(context);
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
return _impl->interpret(context);
}
bool _requires_braces;
bool _requires_braces;
private:
struct _impl_base
{
virtual serializer_context_t& serialize(serializer_context_t& context) const = 0;
virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0;
virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0;
};
private:
struct _impl_base
{
virtual serializer_context_t& serialize(serializer_context_t& context) const = 0;
virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0;
virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0;
};
template<typename T>
struct _impl_t: public _impl_base
{
static_assert(not make_parameter_list_t<T>::size::value, "parameters not supported in dynamic statement parts");
_impl_t(T t):
_t(t)
{}
template <typename T>
struct _impl_t : public _impl_base
{
static_assert(not make_parameter_list_t<T>::size::value, "parameters not supported in dynamic statement parts");
_impl_t(T t) : _t(t)
{
}
serializer_context_t& serialize(serializer_context_t& context) const
{
::sqlpp::serialize(_t, context);
return context;
}
serializer_context_t& serialize(serializer_context_t& context) const
{
::sqlpp::serialize(_t, context);
return context;
}
_serializer_context_t& db_serialize(_serializer_context_t& context) const
{
Db::_serialize_interpretable(_t, context);
return context;
}
_serializer_context_t& db_serialize(_serializer_context_t& context) const
{
Db::_serialize_interpretable(_t, context);
return context;
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
Db::_interpret_interpretable(_t, context);
return context;
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
Db::_interpret_interpretable(_t, context);
return context;
}
T _t;
};
T _t;
};
std::shared_ptr<const _impl_base> _impl;
};
std::shared_ptr<const _impl_base> _impl;
};
template<typename Context, typename Database>
struct serializer_t<Context, interpretable_t<Database>>
{
using _serialize_check = consistent_t;
using T = interpretable_t<Database>;
template <typename Context, typename Database>
struct serializer_t<Context, interpretable_t<Database>>
{
using _serialize_check = consistent_t;
using T = interpretable_t<Database>;
static Context& _(const T& t, Context& context)
{
if (t._requires_braces)
{
context << '(';
t.serialize(context);
context << ')';
}
else
t.serialize(context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
if (t._requires_braces)
{
context << '(';
t.serialize(context);
context << ')';
}
else
t.serialize(context);
return context;
}
};
}
#endif

View File

@ -32,85 +32,82 @@
namespace sqlpp
{
template<typename Db>
struct interpretable_list_t
{
std::vector<interpretable_t<Db>> _serializables;
template <typename Db>
struct interpretable_list_t
{
std::vector<interpretable_t<Db>> _serializables;
std::size_t size() const
{
return _serializables.size();
}
std::size_t size() const
{
return _serializables.size();
}
bool empty() const
{
return _serializables.empty();
}
bool empty() const
{
return _serializables.empty();
}
template<typename Expr>
void emplace_back(Expr expr)
{
_serializables.emplace_back(expr);
}
template <typename Expr>
void emplace_back(Expr expr)
{
_serializables.emplace_back(expr);
}
};
};
template <>
struct interpretable_list_t<void>
{
static constexpr std::size_t size()
{
return 0;
}
template<>
struct interpretable_list_t<void>
{
static constexpr std::size_t size()
{
return 0;
}
static constexpr bool empty()
{
return true;
}
};
static constexpr bool empty()
{
return true;
}
template <typename Context, typename List>
struct serializable_list_interpreter_t
{
using T = List;
};
template <typename Separator>
static Context& _(const T& t, const Separator& separator, Context& context)
{
bool first = true;
for (const auto entry : t._serializables)
{
if (not first)
{
context << separator;
}
first = false;
serialize(entry, context);
}
return context;
}
};
template<typename Context, typename List>
struct serializable_list_interpreter_t
{
using T = List;
template <typename Context>
struct serializable_list_interpreter_t<Context, interpretable_list_t<void>>
{
using T = interpretable_list_t<void>;
template<typename Separator>
static Context& _(const T& t, const Separator& separator, Context& context)
{
bool first = true;
for (const auto entry : t._serializables)
{
if (not first)
{
context << separator;
}
first = false;
serialize(entry, context);
}
return context;
}
};
template<typename Context>
struct serializable_list_interpreter_t<Context, interpretable_list_t<void>>
{
using T = interpretable_list_t<void>;
template<typename Separator>
static Context& _(const T&, const Separator& /* separator */, Context& context)
{
return context;
}
};
template<typename T, typename Separator, typename Context>
auto interpret_list(const T& t, const Separator& separator, Context& context)
-> decltype(serializable_list_interpreter_t<Context, T>::_(t, separator, context))
{
return serializable_list_interpreter_t<Context, T>::_(t, separator, context);
}
template <typename Separator>
static Context& _(const T&, const Separator& /* separator */, Context& context)
{
return context;
}
};
template <typename T, typename Separator, typename Context>
auto interpret_list(const T& t, const Separator& separator, Context& context)
-> decltype(serializable_list_interpreter_t<Context, T>::_(t, separator, context))
{
return serializable_list_interpreter_t<Context, T>::_(t, separator, context);
}
}
#endif

View File

@ -31,15 +31,14 @@
namespace sqlpp
{
template<typename Context, typename T, typename Enable = void>
struct interpreter_t
{
static void _(const T&, Context&)
{
static_assert(wrong_t<interpreter_t>::value, "missing interpreter specialization");
}
};
template <typename Context, typename T, typename Enable = void>
struct interpreter_t
{
static void _(const T&, Context&)
{
static_assert(wrong_t<interpreter_t>::value, "missing interpreter specialization");
}
};
}
#endif

View File

@ -37,159 +37,171 @@
namespace sqlpp
{
// A SINGLE TABLE DATA
template<typename Database, typename Table>
struct into_data_t
{
into_data_t(Table table):
_table(table)
{}
// A SINGLE TABLE DATA
template <typename Database, typename Table>
struct into_data_t
{
into_data_t(Table table) : _table(table)
{
}
into_data_t(const into_data_t&) = default;
into_data_t(into_data_t&&) = default;
into_data_t& operator=(const into_data_t&) = default;
into_data_t& operator=(into_data_t&&) = default;
~into_data_t() = default;
into_data_t(const into_data_t&) = default;
into_data_t(into_data_t&&) = default;
into_data_t& operator=(const into_data_t&) = default;
into_data_t& operator=(into_data_t&&) = default;
~into_data_t() = default;
Table _table;
};
Table _table;
};
// A SINGLE TABLE
template<typename Database, typename Table>
struct into_t
{
using _traits = make_traits<no_value_t, tag::is_into>;
using _nodes = detail::type_vector<Table>;
// A SINGLE TABLE
template <typename Database, typename Table>
struct into_t
{
using _traits = make_traits<no_value_t, tag::is_into>;
using _nodes = detail::type_vector<Table>;
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
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = into_data_t<Database, Table>;
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = into_data_t<Database, Table>;
_impl_t<Policies> into;
_impl_t<Policies>& operator()() { return into; }
const _impl_t<Policies>& operator()() const { return into; }
_impl_t<Policies> into;
_impl_t<Policies>& operator()()
{
return into;
}
const _impl_t<Policies>& operator()() const
{
return into;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.into)
{
return t.into;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.into)
{
return t.into;
}
using _consistency_check = consistent_t;
};
using _consistency_check = consistent_t;
};
};
};
struct assert_into_t
{
using type = std::false_type;
struct assert_into_t
{
using type = std::false_type;
template <typename T = void>
static void _()
{
static_assert(wrong_t<T>::value, "into() required");
}
};
template<typename T = void>
static void _()
{
static_assert(wrong_t<T>::value, "into() required");
}
};
// NO INTO YET
struct no_into_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// NO INTO YET
struct no_into_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = no_data_t;
// Data
using _data_t = no_data_t;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = no_data_t;
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = no_data_t;
_impl_t<Policies> no_into;
_impl_t<Policies>& operator()()
{
return no_into;
}
const _impl_t<Policies>& operator()() const
{
return no_into;
}
_impl_t<Policies> no_into;
_impl_t<Policies>& operator()() { return no_into; }
const _impl_t<Policies>& operator()() const { return no_into; }
template <typename T>
static auto _get_member(T t) -> decltype(t.no_into)
{
return t.no_into;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.no_into)
{
return t.no_into;
}
using _database_t = typename Policies::_database_t;
using _database_t = typename Policies::_database_t;
template <typename T>
using _check = logic::all_t<is_raw_table_t<T>::value>;
template<typename T>
using _check = logic::all_t<is_raw_table_t<T>::value>;
template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_into_t, T>;
template<typename Check, typename 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>
auto into(Table table) const -> _new_statement_t<_check<Table>, into_t<void, Table>>
{
static_assert(_check<Table>::value, "argument is not a raw table in into()");
return _into_impl<void>(_check<Table>{}, table);
}
template<typename Table>
auto into(Table table) const
-> _new_statement_t<_check<Table>, into_t<void, Table>>
{
static_assert(_check<Table>::value, "argument is not a raw table in into()");
return _into_impl<void>(_check<Table>{}, table);
}
private:
template <typename Database, typename Table>
auto _into_impl(const std::false_type&, Table table) const -> bad_statement;
private:
template<typename Database, typename Table>
auto _into_impl(const std::false_type&, Table table) const
-> bad_statement;
template <typename Database, typename Table>
auto _into_impl(const std::true_type&, Table table) const
-> _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()");
template<typename Database, typename Table>
auto _into_impl(const std::true_type&, Table table) const
-> _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()");
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
template <typename Context, typename Database, typename Table>
struct serializer_t<Context, into_data_t<Database, Table>>
{
using _serialize_check = serialize_check_of<Context, Table>;
using T = into_data_t<Database, Table>;
// Interpreters
template<typename Context, typename Database, typename Table>
struct serializer_t<Context, into_data_t<Database, Table>>
{
using _serialize_check = serialize_check_of<Context, Table>;
using T = into_data_t<Database, Table>;
static Context& _(const T& t, Context& context)
{
context << " INTO ";
serialize(t._table, context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << " INTO ";
serialize(t._table, context);
return context;
}
};
template<typename 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));
}
template <typename 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));
}
}
#endif

View File

@ -34,57 +34,55 @@
namespace sqlpp
{
struct is_not_null_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "is_not_null_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T is_not_null;
};
};
};
struct is_not_null_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "is_not_null_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T is_not_null;
};
};
};
template<typename Operand>
struct is_not_null_t:
public expression_operators<is_not_null_t<Operand>, boolean>,
public alias_operators<is_not_null_t<Operand>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand>;
template <typename Operand>
struct is_not_null_t : public expression_operators<is_not_null_t<Operand>, boolean>,
public alias_operators<is_not_null_t<Operand>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand>;
using _auto_alias_t = is_not_null_alias_t;
using _auto_alias_t = is_not_null_alias_t;
is_not_null_t(Operand operand):
_operand(operand)
{}
is_not_null_t(Operand operand) : _operand(operand)
{
}
is_not_null_t(const is_not_null_t&) = default;
is_not_null_t(is_not_null_t&&) = default;
is_not_null_t& operator=(const is_not_null_t&) = default;
is_not_null_t& operator=(is_not_null_t&&) = default;
~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& operator=(const is_not_null_t&) = default;
is_not_null_t& operator=(is_not_null_t&&) = default;
~is_not_null_t() = default;
Operand _operand;
};
Operand _operand;
};
template<typename Context, typename Operand>
struct serializer_t<Context, is_not_null_t<Operand>>
{
using _serialize_check = serialize_check_of<Context, Operand>;
using T = is_not_null_t<Operand>;
static Context& _(const T& t, Context& context)
{
serialize_operand(t._operand, context);
context << " IS NOT NULL";
return context;
}
};
template <typename Context, typename Operand>
struct serializer_t<Context, is_not_null_t<Operand>>
{
using _serialize_check = serialize_check_of<Context, Operand>;
using T = is_not_null_t<Operand>;
static Context& _(const T& t, Context& context)
{
serialize_operand(t._operand, context);
context << " IS NOT NULL";
return context;
}
};
}
#endif

View File

@ -34,57 +34,55 @@
namespace sqlpp
{
struct is_null_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "is_null_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T is_null;
};
};
};
struct is_null_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "is_null_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T is_null;
};
};
};
template<typename Operand>
struct is_null_t:
public expression_operators<is_null_t<Operand>, boolean>,
public alias_operators<is_null_t<Operand>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand>;
template <typename Operand>
struct is_null_t : public expression_operators<is_null_t<Operand>, boolean>,
public alias_operators<is_null_t<Operand>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand>;
using _auto_alias_t = is_null_alias_t;
using _auto_alias_t = is_null_alias_t;
is_null_t(Operand operand):
_operand(operand)
{}
is_null_t(Operand operand) : _operand(operand)
{
}
is_null_t(const is_null_t&) = default;
is_null_t(is_null_t&&) = default;
is_null_t& operator=(const is_null_t&) = default;
is_null_t& operator=(is_null_t&&) = default;
~is_null_t() = default;
is_null_t(const is_null_t&) = default;
is_null_t(is_null_t&&) = default;
is_null_t& operator=(const is_null_t&) = default;
is_null_t& operator=(is_null_t&&) = default;
~is_null_t() = default;
Operand _operand;
};
Operand _operand;
};
template<typename Context, typename Operand>
struct serializer_t<Context, is_null_t<Operand>>
{
using _serialize_check = serialize_check_of<Context, Operand>;
using T = is_null_t<Operand>;
static Context& _(const T& t, Context& context)
{
serialize_operand(t._operand, context);
context << " IS NULL";
return context;
}
};
template <typename Context, typename Operand>
struct serializer_t<Context, is_null_t<Operand>>
{
using _serialize_check = serialize_check_of<Context, Operand>;
using T = is_null_t<Operand>;
static Context& _(const T& t, Context& context)
{
serialize_operand(t._operand, context);
context << " IS NULL";
return context;
}
};
}
#endif

View File

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

View File

@ -33,125 +33,123 @@
namespace sqlpp
{
struct inner_join_t
{
template<typename Lhs, typename Rhs>
using _provided_outer_tables = detail::make_joined_set_t<provided_outer_tables_of<Lhs>, provided_outer_tables_of<Rhs>>;
struct inner_join_t
{
template <typename Lhs, typename 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 ";
};
struct outer_join_t
{
template<typename Lhs, typename Rhs>
using _provided_outer_tables = detail::make_joined_set_t<provided_tables_of<Lhs>, provided_tables_of<Rhs>>;
static constexpr const char* _name = " INNER ";
};
struct outer_join_t
{
template <typename Lhs, typename Rhs>
using _provided_outer_tables = detail::make_joined_set_t<provided_tables_of<Lhs>, provided_tables_of<Rhs>>;
static constexpr const char* _name = " OUTER ";
};
struct left_outer_join_t
{
template<typename Lhs, typename Rhs>
using _provided_outer_tables = detail::make_joined_set_t<provided_tables_of<Lhs>, provided_outer_tables_of<Rhs>>;
static constexpr const char* _name = " OUTER ";
};
struct left_outer_join_t
{
template <typename Lhs, typename 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 ";
};
struct right_outer_join_t
{
template<typename Lhs, typename Rhs>
using _provided_outer_tables = detail::make_joined_set_t<provided_outer_tables_of<Lhs>, provided_tables_of<Rhs>>;
static constexpr const char* _name = " LEFT OUTER ";
};
struct right_outer_join_t
{
template <typename Lhs, typename 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>
struct join_t
{
using _traits = make_traits<no_value_t, tag::is_table, tag::is_join>;
using _nodes = detail::type_vector<Lhs, Rhs>;
using _can_be_null = std::false_type;
template <typename JoinType, typename Lhs, typename Rhs, typename On = noop>
struct join_t
{
using _traits = make_traits<no_value_t, tag::is_table, tag::is_join>;
using _nodes = detail::type_vector<Lhs, Rhs>;
using _can_be_null = std::false_type;
static_assert(is_table_t<Lhs>::value, "lhs argument for join() has to be a table or join");
static_assert(is_table_t<Rhs>::value, "rhs argument for join() has to be a table");
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_table_t<Lhs>::value, "lhs argument for join() has to be a table or join");
static_assert(is_table_t<Rhs>::value, "rhs argument for join() has to be a table");
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(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>
using set_on_t = join_t<JoinType, Lhs, Rhs, OnT>;
template <typename OnT>
using set_on_t = join_t<JoinType, Lhs, Rhs, OnT>;
template<typename... Expr>
auto on(Expr... expr)
-> set_on_t<on_t<void, Expr...>>
{
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()");
template <typename... Expr>
auto on(Expr... expr) -> set_on_t<on_t<void, Expr...>>
{
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()");
return { _lhs,
_rhs,
{std::tuple<Expr...>{expr...}, {}}
};
}
return {_lhs, _rhs, {std::tuple<Expr...>{expr...}, {}}};
}
template<typename T>
join_t<inner_join_t, join_t, T> join(T t)
{
static_assert(not is_noop<On>::value, "join type requires on()");
return { *this, t, {} };
}
template <typename T>
join_t<inner_join_t, join_t, T> join(T t)
{
static_assert(not is_noop<On>::value, "join type requires on()");
return {*this, t, {}};
}
template<typename T>
join_t<inner_join_t, join_t, T> inner_join(T t)
{
static_assert(not is_noop<On>::value, "join type requires on()");
return { *this, t, {} };
}
template <typename T>
join_t<inner_join_t, join_t, T> inner_join(T t)
{
static_assert(not is_noop<On>::value, "join type requires on()");
return {*this, t, {}};
}
template<typename T>
join_t<outer_join_t, join_t, T> outer_join(T t)
{
static_assert(not is_noop<On>::value, "join type requires on()");
return { *this, t, {} };
}
template <typename T>
join_t<outer_join_t, join_t, T> outer_join(T t)
{
static_assert(not is_noop<On>::value, "join type requires on()");
return {*this, t, {}};
}
template<typename 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()");
return { *this, t, {} };
}
template <typename 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()");
return {*this, t, {}};
}
template<typename 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()");
return { *this, t, {} };
}
template <typename 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()");
return {*this, t, {}};
}
Lhs _lhs;
Rhs _rhs;
On _on;
};
Lhs _lhs;
Rhs _rhs;
On _on;
};
template<typename Context, typename JoinType, typename Lhs, typename Rhs, typename On>
struct serializer_t<Context, join_t<JoinType, Lhs, Rhs, On>>
{
using _serialize_check = serialize_check_of<Context, Lhs, Rhs, On>;
using T = join_t<JoinType, Lhs, Rhs, On>;
static Context& _(const T& t, Context& context)
{
static_assert(not is_noop<On>::value, "joined tables require on()");
serialize(t._lhs, context);
context << JoinType::_name;
context << " JOIN ";
serialize(t._rhs, context);
serialize(t._on, context);
return context;
}
};
template <typename Context, typename JoinType, typename Lhs, typename Rhs, typename On>
struct serializer_t<Context, join_t<JoinType, Lhs, Rhs, On>>
{
using _serialize_check = serialize_check_of<Context, Lhs, Rhs, On>;
using T = join_t<JoinType, Lhs, Rhs, On>;
static Context& _(const T& t, Context& context)
{
static_assert(not is_noop<On>::value, "joined tables require on()");
serialize(t._lhs, context);
context << JoinType::_name;
context << " JOIN ";
serialize(t._rhs, context);
serialize(t._on, context);
return context;
}
};
}
#endif

View File

@ -34,57 +34,61 @@
namespace sqlpp
{
template<typename Operand, typename Pattern>
struct like_t:
public expression_operators<like_t<Operand, Pattern>, boolean>,
public alias_operators<like_t<Operand, Pattern>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand, Pattern>;
template <typename Operand, typename Pattern>
struct like_t : public expression_operators<like_t<Operand, Pattern>, boolean>,
public alias_operators<like_t<Operand, Pattern>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand, Pattern>;
struct _alias_t
{
static constexpr const char _literal[] = "like_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T like;
T& operator()() { return like; }
const T& operator()() const { return like; }
};
};
struct _alias_t
{
static constexpr const char _literal[] = "like_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T like;
T& operator()()
{
return like;
}
const T& operator()() const
{
return like;
}
};
};
like_t(Operand operand, Pattern pattern):
_operand(operand),
_pattern(pattern)
{}
like_t(Operand operand, Pattern pattern) : _operand(operand), _pattern(pattern)
{
}
like_t(const like_t&) = default;
like_t(like_t&&) = default;
like_t& operator=(const like_t&) = default;
like_t& operator=(like_t&&) = default;
~like_t() = default;
like_t(const like_t&) = default;
like_t(like_t&&) = default;
like_t& operator=(const like_t&) = default;
like_t& operator=(like_t&&) = default;
~like_t() = default;
Operand _operand;
Pattern _pattern;
};
Operand _operand;
Pattern _pattern;
};
template<typename Context, typename Operand, typename Pattern>
struct serializer_t<Context, like_t<Operand, Pattern>>
{
using _serialize_check = serialize_check_of<Context, Operand, Pattern>;
using T = like_t<Operand, Pattern>;
template <typename Context, typename Operand, typename Pattern>
struct serializer_t<Context, like_t<Operand, Pattern>>
{
using _serialize_check = serialize_check_of<Context, Operand, Pattern>;
using T = like_t<Operand, Pattern>;
static Context& _(const T& t, Context& context)
{
serialize_operand(t._operand, context);
context << " LIKE(";
serialize(t._pattern, context);
context << ")";
return context;
}
};
static Context& _(const T& t, Context& context)
{
serialize_operand(t._operand, context);
context << " LIKE(";
serialize(t._pattern, context);
context << ")";
return context;
}
};
}
#endif

View File

@ -33,234 +33,246 @@
namespace sqlpp
{
// LIMIT DATA
template<typename Limit>
struct limit_data_t
{
limit_data_t(Limit value):
_value(value)
{}
// LIMIT DATA
template <typename Limit>
struct limit_data_t
{
limit_data_t(Limit value) : _value(value)
{
}
limit_data_t(const limit_data_t&) = default;
limit_data_t(limit_data_t&&) = default;
limit_data_t& operator=(const limit_data_t&) = default;
limit_data_t& operator=(limit_data_t&&) = default;
~limit_data_t() = default;
limit_data_t(const limit_data_t&) = default;
limit_data_t(limit_data_t&&) = default;
limit_data_t& operator=(const limit_data_t&) = default;
limit_data_t& operator=(limit_data_t&&) = default;
~limit_data_t() = default;
Limit _value;
};
Limit _value;
};
// LIMIT
template<typename Limit>
struct limit_t
{
using _traits = make_traits<no_value_t, tag::is_limit>;
using _nodes = detail::type_vector<Limit>;
// LIMIT
template <typename Limit>
struct limit_t
{
using _traits = make_traits<no_value_t, tag::is_limit>;
using _nodes = detail::type_vector<Limit>;
// Data
using _data_t = limit_data_t<Limit>;
// Data
using _data_t = limit_data_t<Limit>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = limit_data_t<Limit>;
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = limit_data_t<Limit>;
_impl_t<Policies> limit;
_impl_t<Policies>& operator()() { return limit; }
const _impl_t<Policies>& operator()() const { return limit; }
_impl_t<Policies> limit;
_impl_t<Policies>& operator()()
{
return limit;
}
const _impl_t<Policies>& operator()() const
{
return limit;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.limit)
{
return t.limit;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.limit)
{
return t.limit;
}
using _consistency_check = consistent_t;
};
};
using _consistency_check = consistent_t;
};
};
// DYNAMIC LIMIT DATA
template<typename Database>
struct dynamic_limit_data_t
{
dynamic_limit_data_t():
_value(noop())
{
}
// DYNAMIC LIMIT DATA
template <typename Database>
struct dynamic_limit_data_t
{
dynamic_limit_data_t() : _value(noop())
{
}
template<typename Limit>
dynamic_limit_data_t(Limit value):
_initialized(true),
_value(wrap_operand_t<Limit>(value))
{
}
template <typename Limit>
dynamic_limit_data_t(Limit value)
: _initialized(true), _value(wrap_operand_t<Limit>(value))
{
}
dynamic_limit_data_t(const dynamic_limit_data_t&) = default;
dynamic_limit_data_t(dynamic_limit_data_t&&) = default;
dynamic_limit_data_t& operator=(const dynamic_limit_data_t&) = default;
dynamic_limit_data_t& operator=(dynamic_limit_data_t&&) = default;
~dynamic_limit_data_t() = default;
dynamic_limit_data_t(const dynamic_limit_data_t&) = default;
dynamic_limit_data_t(dynamic_limit_data_t&&) = default;
dynamic_limit_data_t& operator=(const dynamic_limit_data_t&) = default;
dynamic_limit_data_t& operator=(dynamic_limit_data_t&&) = default;
~dynamic_limit_data_t() = default;
bool _initialized = false;
interpretable_t<Database> _value;
};
bool _initialized = false;
interpretable_t<Database> _value;
};
// DYNAMIC LIMIT
template<typename Database>
struct dynamic_limit_t
{
using _traits = make_traits<no_value_t, tag::is_limit>;
using _nodes = detail::type_vector<>;
// DYNAMIC LIMIT
template <typename Database>
struct dynamic_limit_t
{
using _traits = make_traits<no_value_t, tag::is_limit>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = dynamic_limit_data_t<Database>;
// Data
using _data_t = dynamic_limit_data_t<Database>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template<typename Limit>
void set(Limit value)
{
// FIXME: Make sure that Limit does not require external tables? Need to read up on SQL
using arg_t = wrap_operand_t<Limit>;
static_assert(is_integral_t<arg_t>::value, "limit requires an integral value or integral parameter");
_data._value = arg_t{value};
_data._initialized = true;
}
public:
_data_t _data;
};
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template <typename Limit>
void set(Limit value)
{
// FIXME: Make sure that Limit does not require external tables? Need to read up on SQL
using arg_t = wrap_operand_t<Limit>;
static_assert(is_integral_t<arg_t>::value, "limit requires an integral value or integral parameter");
_data._value = arg_t{value};
_data._initialized = true;
}
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = dynamic_limit_data_t<Database>;
public:
_data_t _data;
};
_impl_t<Policies> limit;
_impl_t<Policies>& operator()() { return limit; }
const _impl_t<Policies>& operator()() const { return limit; }
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = dynamic_limit_data_t<Database>;
template<typename T>
static auto _get_member(T t) -> decltype(t.limit)
{
return t.limit;
}
_impl_t<Policies> limit;
_impl_t<Policies>& operator()()
{
return limit;
}
const _impl_t<Policies>& operator()() const
{
return limit;
}
using _consistency_check = consistent_t;
};
};
template <typename T>
static auto _get_member(T t) -> decltype(t.limit)
{
return t.limit;
}
struct no_limit_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
using _consistency_check = consistent_t;
};
};
// Data
using _data_t = no_data_t;
struct no_limit_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Data
using _data_t = no_data_t;
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = no_data_t;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
_impl_t<Policies> no_limit;
_impl_t<Policies>& operator()() { return no_limit; }
const _impl_t<Policies>& operator()() const { return no_limit; }
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = no_data_t;
template<typename T>
static auto _get_member(T t) -> decltype(t.no_limit)
{
return t.no_limit;
}
_impl_t<Policies> no_limit;
_impl_t<Policies>& operator()()
{
return no_limit;
}
const _impl_t<Policies>& operator()() const
{
return no_limit;
}
using _database_t = typename Policies::_database_t;
template <typename T>
static auto _get_member(T t) -> decltype(t.no_limit)
{
return t.no_limit;
}
template<typename T>
using _check = is_integral_t<wrap_operand_t<T>>;
using _database_t = typename Policies::_database_t;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_limit_t, T>;
template <typename T>
using _check = is_integral_t<wrap_operand_t<T>>;
using _consistency_check = consistent_t;
template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_limit_t, T>;
template<typename Arg>
auto limit(Arg arg) const
-> _new_statement_t<_check<Arg>, limit_t<wrap_operand_t<Arg>>>
{
static_assert(_check<Arg>::value, "limit requires an integral value or integral parameter");
return _limit_impl(_check<Arg>{}, wrap_operand_t<Arg>{arg});
}
using _consistency_check = consistent_t;
auto dynamic_limit() const
-> _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>{} };
}
template <typename Arg>
auto limit(Arg arg) const -> _new_statement_t<_check<Arg>, limit_t<wrap_operand_t<Arg>>>
{
static_assert(_check<Arg>::value, "limit requires an integral value or integral parameter");
return _limit_impl(_check<Arg>{}, wrap_operand_t<Arg>{arg});
}
private:
template<typename Arg>
auto _limit_impl(const std::false_type&, Arg arg) const
-> bad_statement;
auto dynamic_limit() const -> _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>{}};
}
template<typename Arg>
auto _limit_impl(const std::true_type&, Arg arg) const
-> _new_statement_t<std::true_type, limit_t<Arg>>
{
return { static_cast<const derived_statement_t<Policies>&>(*this), limit_data_t<Arg>{arg} };
}
private:
template <typename Arg>
auto _limit_impl(const std::false_type&, Arg arg) const -> bad_statement;
};
};
template <typename Arg>
auto _limit_impl(const std::true_type&, Arg arg) const -> _new_statement_t<std::true_type, limit_t<Arg>>
{
return {static_cast<const derived_statement_t<Policies>&>(*this), limit_data_t<Arg>{arg}};
}
};
};
// Interpreters
template<typename Context, typename Database>
struct serializer_t<Context, dynamic_limit_data_t<Database>>
{
using _serialize_check = consistent_t;
using T = dynamic_limit_data_t<Database>;
// Interpreters
template <typename Context, typename Database>
struct serializer_t<Context, dynamic_limit_data_t<Database>>
{
using _serialize_check = consistent_t;
using T = dynamic_limit_data_t<Database>;
static Context& _(const T& t, Context& context)
{
if (t._initialized)
{
context << " LIMIT ";
serialize(t._value, context);
}
return context;
}
};
static Context& _(const T& t, Context& context)
{
if (t._initialized)
{
context << " LIMIT ";
serialize(t._value, context);
}
return context;
}
};
template<typename Context, typename Limit>
struct serializer_t<Context, limit_data_t<Limit>>
{
using _serialize_check = serialize_check_of<Context, Limit>;
using T = limit_data_t<Limit>;
template <typename Context, typename Limit>
struct serializer_t<Context, limit_data_t<Limit>>
{
using _serialize_check = serialize_check_of<Context, Limit>;
using T = limit_data_t<Limit>;
static Context& _(const T& t, Context& context)
{
context << " LIMIT ";
serialize_operand(t._value, context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << " LIMIT ";
serialize_operand(t._value, context);
return context;
}
};
}
#endif

View File

@ -27,56 +27,49 @@
#ifndef SQLPP_DETAIL_LOGIC_H
#define SQLPP_DETAIL_LOGIC_H
#include <ciso646> // Required for some compilers to use aliases for boolean operators
#include <ciso646> // Required for some compilers to use aliases for boolean operators
#include <type_traits>
namespace sqlpp
{
namespace logic
{
template<bool... B>
struct logic_helper;
namespace logic
{
template <bool... B>
struct logic_helper;
// see http://lists.boost.org/Archives/boost/2014/05/212946.php :-)
template<bool... B>
using all_t = std::integral_constant<
bool,
std::is_same<logic_helper<B...>, logic_helper<(true or B)...>>::value>;
// see http://lists.boost.org/Archives/boost/2014/05/212946.php :-)
template <bool... B>
using all_t = std::integral_constant<bool, std::is_same<logic_helper<B...>, logic_helper<(true or B)...>>::value>;
template<bool... B>
using any_t = std::integral_constant<
bool,
not std::is_same<logic_helper<B...>, logic_helper<(false and B)...>>::value>;
template <bool... B>
using any_t =
std::integral_constant<bool, not std::is_same<logic_helper<B...>, logic_helper<(false and B)...>>::value>;
template<bool... B>
using none_t = std::integral_constant<
bool,
std::is_same<logic_helper<B...>, logic_helper<(false and B)...>>::value>;
template <bool... B>
using none_t =
std::integral_constant<bool, std::is_same<logic_helper<B...>, logic_helper<(false and B)...>>::value>;
template<bool>
struct not_impl;
template <bool>
struct not_impl;
template<>
struct not_impl<true>
{
using type = std::false_type;
};
template <>
struct not_impl<true>
{
using type = std::false_type;
};
template<>
struct not_impl<false>
{
using type = std::true_type;
};
template <>
struct not_impl<false>
{
using type = std::true_type;
};
template <template <typename> class Predicate, typename... T>
using not_t = typename not_impl<Predicate<T>::value...>::type;
template<template<typename> class Predicate, typename... T>
using not_t = typename not_impl<Predicate<T>::value...>::type;
template<typename T>
using identity_t = T;
}
template <typename T>
using identity_t = T;
}
}
#endif

View File

@ -32,68 +32,72 @@
namespace sqlpp
{
struct max_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "max_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T max;
T& operator()() { return max; }
const T& operator()() const { return max; }
};
};
};
struct max_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "max_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T max;
T& operator()()
{
return max;
}
const T& operator()() const
{
return max;
}
};
};
};
template<typename Expr>
struct max_t:
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 _nodes = detail::type_vector<Expr, aggregate_function>;
template <typename Expr>
struct max_t : 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 _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):
_expr(expr)
{}
max_t(Expr expr) : _expr(expr)
{
}
max_t(const max_t&) = default;
max_t(max_t&&) = default;
max_t& operator=(const max_t&) = default;
max_t& operator=(max_t&&) = default;
~max_t() = default;
max_t(const max_t&) = default;
max_t(max_t&&) = default;
max_t& operator=(const max_t&) = default;
max_t& operator=(max_t&&) = default;
~max_t() = default;
Expr _expr;
};
Expr _expr;
};
template<typename Context, typename Expr>
struct serializer_t<Context, max_t<Expr>>
{
using _serialize_check = serialize_check_of<Context, Expr>;
using T = max_t<Expr>;
template <typename Context, typename Expr>
struct serializer_t<Context, max_t<Expr>>
{
using _serialize_check = serialize_check_of<Context, Expr>;
using T = max_t<Expr>;
static Context& _(const T& t, Context& context)
{
context << "MAX(";
serialize(t._expr, context);
context << ")";
return context;
}
};
template<typename 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(is_expression_t<wrap_operand_t<T>>::value, "max() requires an expression as argument");
return { t };
}
static Context& _(const T& t, Context& context)
{
context << "MAX(";
serialize(t._expr, context);
context << ")";
return context;
}
};
template <typename 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(is_expression_t<wrap_operand_t<T>>::value, "max() requires an expression as argument");
return {t};
}
}
#endif

View File

@ -32,68 +32,72 @@
namespace sqlpp
{
struct min_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "min_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T min;
T& operator()() { return min; }
const T& operator()() const { return min; }
};
};
};
struct min_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "min_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T min;
T& operator()()
{
return min;
}
const T& operator()() const
{
return min;
}
};
};
};
template<typename Expr>
struct min_t:
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 _nodes = detail::type_vector<Expr, aggregate_function>;
template <typename Expr>
struct min_t : 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 _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):
_expr(expr)
{}
min_t(Expr expr) : _expr(expr)
{
}
min_t(const min_t&) = default;
min_t(min_t&&) = default;
min_t& operator=(const min_t&) = default;
min_t& operator=(min_t&&) = default;
~min_t() = default;
min_t(const min_t&) = default;
min_t(min_t&&) = default;
min_t& operator=(const min_t&) = default;
min_t& operator=(min_t&&) = default;
~min_t() = default;
Expr _expr;
};
Expr _expr;
};
template<typename Context, typename Expr>
struct serializer_t<Context, min_t<Expr>>
{
using _serialize_check = serialize_check_of<Context, Expr>;
using T = min_t<Expr>;
template <typename Context, typename Expr>
struct serializer_t<Context, min_t<Expr>>
{
using _serialize_check = serialize_check_of<Context, Expr>;
using T = min_t<Expr>;
static Context& _(const T& t, Context& context)
{
context << "MIN(";
serialize(t._expr, context);
context << ")";
return context;
}
};
template<typename 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(is_expression_t<wrap_operand_t<T>>::value, "min() requires an expression as argument");
return { t };
}
static Context& _(const T& t, Context& context)
{
context << "MIN(";
serialize(t._expr, context);
context << ")";
return context;
}
};
template <typename 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(is_expression_t<wrap_operand_t<T>>::value, "min() requires an expression as argument");
return {t};
}
}
#endif

View File

@ -35,112 +35,110 @@
namespace sqlpp
{
template<typename AliasProvider, typename... Columns>
struct multi_column_alias_t;
template <typename AliasProvider, typename... Columns>
struct multi_column_alias_t;
template<typename Unused, typename... Columns>
struct multi_column_t
{
using _traits = make_traits<no_value_t>;
using _nodes = detail::type_vector<Columns...>;
template <typename Unused, typename... Columns>
struct multi_column_t
{
using _traits = make_traits<no_value_t>;
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):
_columns(columns)
{}
multi_column_t(std::tuple<Columns...> columns) : _columns(columns)
{
}
multi_column_t(Columns... columns):
_columns(columns...)
{}
multi_column_t(Columns... columns) : _columns(columns...)
{
}
multi_column_t(const multi_column_t&) = default;
multi_column_t(multi_column_t&&) = default;
multi_column_t& operator=(const multi_column_t&) = default;
multi_column_t& operator=(multi_column_t&&) = default;
~multi_column_t() = default;
multi_column_t(const multi_column_t&) = default;
multi_column_t(multi_column_t&&) = default;
multi_column_t& operator=(const multi_column_t&) = default;
multi_column_t& operator=(multi_column_t&&) = default;
~multi_column_t() = default;
template<typename AliasProvider>
multi_column_alias_t<AliasProvider, Columns...> as(const AliasProvider&)
{
return { *this };
}
template <typename AliasProvider>
multi_column_alias_t<AliasProvider, Columns...> as(const AliasProvider&)
{
return {*this};
}
std::tuple<Columns...> _columns;
};
std::tuple<Columns...> _columns;
};
template<typename AliasProvider, typename... Columns>
struct multi_column_alias_t
{
using _traits = make_traits<no_value_t, tag::is_alias, tag::is_multi_column, tag::is_selectable>;
using _nodes = detail::type_vector<Columns...>;
template <typename AliasProvider, typename... Columns>
struct multi_column_alias_t
{
using _traits = make_traits<no_value_t, tag::is_alias, tag::is_multi_column, tag::is_selectable>;
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):
_columns(multi_column._columns)
{}
multi_column_alias_t(multi_column_t<void, Columns...> multi_column) : _columns(multi_column._columns)
{
}
multi_column_alias_t(std::tuple<Columns...> columns):
_columns(columns)
{}
multi_column_alias_t(std::tuple<Columns...> columns) : _columns(columns)
{
}
multi_column_alias_t(Columns... columns):
_columns(columns...)
{}
multi_column_alias_t(Columns... columns) : _columns(columns...)
{
}
multi_column_alias_t(const multi_column_alias_t&) = default;
multi_column_alias_t(multi_column_alias_t&&) = default;
multi_column_alias_t& operator=(const multi_column_alias_t&) = default;
multi_column_alias_t& operator=(multi_column_alias_t&&) = default;
~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& operator=(const multi_column_alias_t&) = default;
multi_column_alias_t& operator=(multi_column_alias_t&&) = default;
~multi_column_alias_t() = default;
std::tuple<Columns...> _columns;
};
std::tuple<Columns...> _columns;
};
template<typename Context, typename... Columns>
struct serializer_t<Context, multi_column_t<void, Columns...>>
{
using _serialize_check = serialize_check_of<Context, Columns...>;
using T = multi_column_t<void, Columns...>;
template <typename Context, typename... Columns>
struct serializer_t<Context, multi_column_t<void, Columns...>>
{
using _serialize_check = serialize_check_of<Context, Columns...>;
using T = multi_column_t<void, Columns...>;
static void _(const T&, Context&)
{
static_assert(wrong_t<serializer_t>::value, "multi_column must be used with an alias");
}
};
static void _(const T&, Context&)
{
static_assert(wrong_t<serializer_t>::value, "multi_column must be used with an alias");
}
};
template<typename Context, typename AliasProvider, typename... Columns>
struct serializer_t<Context, multi_column_alias_t<AliasProvider, Columns...>>
{
using _serialize_check = serialize_check_of<Context, Columns...>;
using T = multi_column_alias_t<AliasProvider, Columns...>;
template <typename Context, typename AliasProvider, typename... Columns>
struct serializer_t<Context, multi_column_alias_t<AliasProvider, Columns...>>
{
using _serialize_check = serialize_check_of<Context, Columns...>;
using T = multi_column_alias_t<AliasProvider, Columns...>;
static Context& _(const T& t, Context& context)
{
interpret_tuple(t._columns, ',', context);
return context;
}
};
namespace detail
{
template<typename... Columns>
using make_multi_column_t =
copy_tuple_args_t<multi_column_t, void,
decltype(column_tuple_merge(std::declval<Columns>()...))>;
}
template<typename... Columns>
auto multi_column(Columns... columns)
-> detail::make_multi_column_t<Columns...>
{
return detail::make_multi_column_t<Columns...>(std::tuple_cat(detail::as_column_tuple<Columns>::_(columns)...));
}
static Context& _(const T& t, Context& context)
{
interpret_tuple(t._columns, ',', context);
return context;
}
};
namespace detail
{
template <typename... Columns>
using make_multi_column_t =
copy_tuple_args_t<multi_column_t, void, decltype(column_tuple_merge(std::declval<Columns>()...))>;
}
template <typename... Columns>
auto multi_column(Columns... columns) -> detail::make_multi_column_t<Columns...>
{
return detail::make_multi_column_t<Columns...>(std::tuple_cat(detail::as_column_tuple<Columns>::_(columns)...));
}
}
#endif

View File

@ -34,117 +34,117 @@
namespace sqlpp
{
template<typename Db>
struct named_interpretable_t
{
using _serializer_context_t = typename Db::_serializer_context_t;
using _interpreter_context_t = typename Db::_interpreter_context_t;
template <typename Db>
struct named_interpretable_t
{
using _serializer_context_t = typename Db::_serializer_context_t;
using _interpreter_context_t = typename Db::_interpreter_context_t;
template<typename T>
named_interpretable_t(T t):
_requires_braces(requires_braces_t<T>::value),
_impl(std::make_shared<_impl_t<T>>(t))
{}
template <typename T>
named_interpretable_t(T t)
: _requires_braces(requires_braces_t<T>::value), _impl(std::make_shared<_impl_t<T>>(t))
{
}
named_interpretable_t(const named_interpretable_t&) = default;
named_interpretable_t(named_interpretable_t&&) = default;
named_interpretable_t& operator=(const named_interpretable_t&) = default;
named_interpretable_t& operator=(named_interpretable_t&&) = default;
~named_interpretable_t() = default;
named_interpretable_t(const named_interpretable_t&) = default;
named_interpretable_t(named_interpretable_t&&) = default;
named_interpretable_t& operator=(const named_interpretable_t&) = default;
named_interpretable_t& operator=(named_interpretable_t&&) = default;
~named_interpretable_t() = default;
serializer_context_t& serialize(serializer_context_t& context) const
{
return _impl->serialize(context);
}
serializer_context_t& serialize(serializer_context_t& context) const
{
return _impl->serialize(context);
}
// This method only exists if Db::_serializer_context_t and serializer_context_t are not the same
template<typename Context>
auto serialize(Context& context) const
-> typename std::enable_if<std::is_same<Context, _serializer_context_t>::value
and not std::is_same<Context, serializer_context_t>::value, Context&>::type
{
return _impl->db_serialize(context);
}
// This method only exists if Db::_serializer_context_t and serializer_context_t are not the same
template <typename Context>
auto serialize(Context& context) const ->
typename std::enable_if<std::is_same<Context, _serializer_context_t>::value and
not std::is_same<Context, serializer_context_t>::value,
Context&>::type
{
return _impl->db_serialize(context);
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
return _impl->interpret(context);
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
return _impl->interpret(context);
}
std::string _get_name() const
{
return _impl->_get_name();
}
std::string _get_name() const
{
return _impl->_get_name();
}
bool _requires_braces;
bool _requires_braces;
private:
struct _impl_base
{
virtual serializer_context_t& serialize(serializer_context_t& context) const = 0;
virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0;
virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0;
virtual std::string _get_name() const = 0;
};
private:
struct _impl_base
{
virtual serializer_context_t& serialize(serializer_context_t& context) const = 0;
virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0;
virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0;
virtual std::string _get_name() const = 0;
};
template<typename T>
struct _impl_t: public _impl_base
{
static_assert(not make_parameter_list_t<T>::size::value, "parameters not supported in dynamic statement parts");
_impl_t(T t):
_t(t)
{}
template <typename T>
struct _impl_t : public _impl_base
{
static_assert(not make_parameter_list_t<T>::size::value, "parameters not supported in dynamic statement parts");
_impl_t(T t) : _t(t)
{
}
serializer_context_t& serialize(serializer_context_t& context) const
{
::sqlpp::serialize(_t, context);
return context;
}
serializer_context_t& serialize(serializer_context_t& context) const
{
::sqlpp::serialize(_t, context);
return context;
}
_serializer_context_t& db_serialize(_serializer_context_t& context) const
{
Db::_serialize_interpretable(_t, context);
return context;
}
_serializer_context_t& db_serialize(_serializer_context_t& context) const
{
Db::_serialize_interpretable(_t, context);
return context;
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
Db::_interpret_interpretable(_t, context);
return context;
}
_interpreter_context_t& interpret(_interpreter_context_t& context) const
{
Db::_interpret_interpretable(_t, context);
return context;
}
std::string _get_name() const
{
return name_of<T>::char_ptr();
}
std::string _get_name() const
{
return name_of<T>::char_ptr();
}
T _t;
};
T _t;
};
std::shared_ptr<const _impl_base> _impl;
};
std::shared_ptr<const _impl_base> _impl;
};
template<typename Context, typename Database>
struct serializer_t<Context, named_interpretable_t<Database>>
{
using _serialize_check = consistent_t;
using T = named_interpretable_t<Database>;
template <typename Context, typename Database>
struct serializer_t<Context, named_interpretable_t<Database>>
{
using _serialize_check = consistent_t;
using T = named_interpretable_t<Database>;
static Context& _(const T& t, Context& context)
{
if (t._requires_braces)
{
context << '(';
t.serialize(context);
context << ')';
}
else
t.serialize(context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
if (t._requires_braces)
{
context << '(';
t.serialize(context);
context << ')';
}
else
t.serialize(context);
return context;
}
};
}
#endif

View File

@ -32,18 +32,20 @@
namespace sqlpp
{
struct no_data_t {};
struct no_data_t
{
};
template<typename Context>
struct serializer_t<Context, no_data_t>
{
using _serialize_check = consistent_t;
using T = no_data_t;
template <typename Context>
struct serializer_t<Context, no_data_t>
{
using _serialize_check = consistent_t;
using T = no_data_t;
static Context& _(const T&, Context& context)
{
return context;
}
};
static Context& _(const T&, Context& context)
{
return context;
}
};
}
#endif

View File

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

View File

@ -34,67 +34,68 @@
namespace sqlpp
{
struct noop
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
struct noop
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
struct _alias_t {};
struct _alias_t
{
};
template<typename Statement>
struct _result_methods_t
{
using _statement_t = Statement;
template <typename Statement>
struct _result_methods_t
{
using _statement_t = Statement;
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
// Execute
template<typename Db, typename Composite>
auto _run(Db& db, const Composite& composite) const -> size_t
{
return db.execute(composite);
}
// Execute
template <typename Db, typename Composite>
auto _run(Db& db, const Composite& composite) const -> size_t
{
return db.execute(composite);
}
template<typename Db>
auto _run(Db& db) const -> size_t
{
return db.execute(_get_statement());
}
template <typename Db>
auto _run(Db& db) const -> size_t
{
return db.execute(_get_statement());
}
// Prepare
template<typename Db, typename Composite>
auto _prepare(Db& db, const Composite& composite) const
-> prepared_execute_t<Db, Composite>
{
return {{}, db.prepare_execute(composite)};
}
// Prepare
template <typename Db, typename Composite>
auto _prepare(Db& db, const Composite& composite) const -> prepared_execute_t<Db, Composite>
{
return {{}, db.prepare_execute(composite)};
}
template<typename Db>
auto _prepare(Db& db) const
-> prepared_execute_t<Db, _statement_t>
{
return {{}, db.prepare_execute(_get_statement())};
}
};
};
template <typename Db>
auto _prepare(Db& db) const -> prepared_execute_t<Db, _statement_t>
{
return {{}, db.prepare_execute(_get_statement())};
}
};
};
template<typename Context>
struct serializer_t<Context, noop>
{
using _serialize_check = consistent_t;
using T = noop;
template <typename Context>
struct serializer_t<Context, noop>
{
using _serialize_check = consistent_t;
using T = noop;
static Context& _(const T&, Context& context)
{
return context;
}
};
template<typename T>
struct is_noop: std::is_same<T, noop> {};
static Context& _(const T&, Context& context)
{
return context;
}
};
template <typename T>
struct is_noop : std::is_same<T, noop>
{
};
}
#endif

View File

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

View File

@ -35,94 +35,90 @@
namespace sqlpp
{
struct not_in_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "not_in_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T in;
};
};
};
struct not_in_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "not_in_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T in;
};
};
};
template<typename Operand, typename... Args>
struct not_in_t:
public expression_operators<not_in_t<Operand, Args...>, boolean>,
public alias_operators<not_in_t<Operand, Args...>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand, Args...>;
template <typename Operand, typename... Args>
struct not_in_t : public expression_operators<not_in_t<Operand, Args...>, boolean>,
public alias_operators<not_in_t<Operand, Args...>>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Operand, Args...>;
static_assert(sizeof...(Args) > 0, "not_in() requires at least one argument");
static_assert(sizeof...(Args) > 0, "not_in() requires at least one argument");
using _auto_alias_t = not_in_alias_t;
using _auto_alias_t = not_in_alias_t;
not_in_t(Operand operand, Args... args):
_operand(operand),
_args(args...)
{}
not_in_t(Operand operand, Args... args) : _operand(operand), _args(args...)
{
}
not_in_t(const not_in_t&) = default;
not_in_t(not_in_t&&) = default;
not_in_t& operator=(const not_in_t&) = default;
not_in_t& operator=(not_in_t&&) = default;
~not_in_t() = default;
not_in_t(const not_in_t&) = default;
not_in_t(not_in_t&&) = default;
not_in_t& operator=(const not_in_t&) = default;
not_in_t& operator=(not_in_t&&) = default;
~not_in_t() = default;
Operand _operand;
std::tuple<Args...> _args;
};
Operand _operand;
std::tuple<Args...> _args;
};
template<typename Context, typename Operand, typename... Args>
struct serializer_t<Context, not_in_t<Operand, Args...>>
{
using _serialize_check = serialize_check_of<Context, Args...>;
using T = not_in_t<Operand, Args...>;
template <typename Context, typename Operand, typename... Args>
struct serializer_t<Context, not_in_t<Operand, Args...>>
{
using _serialize_check = serialize_check_of<Context, Args...>;
using T = not_in_t<Operand, Args...>;
static Context& _(const T& t, Context& context)
{
serialize_operand(t._operand, context);
context << " NOT IN(";
if (sizeof...(Args) == 1)
serialize(std::get<0>(t._args), context);
else
interpret_tuple(t._args, ',', context);
context << ')';
return context;
}
};
static Context& _(const T& t, Context& context)
{
serialize_operand(t._operand, context);
context << " NOT IN(";
if (sizeof...(Args) == 1)
serialize(std::get<0>(t._args), context);
else
interpret_tuple(t._args, ',', context);
context << ')';
return context;
}
};
template<typename Container>
struct value_list_t;
template<typename Context, typename Operand, typename 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 T = not_in_t<Operand, value_list_t<Container>>;
static Context& _(const T& t, Context& context)
{
const auto& value_list = std::get<0>(t._args);
if (value_list._container.empty())
{
context << " 'operand not in empty list' != 'false' ";
}
else
{
serialize(t._operand, context);
context << " NOT IN(";
serialize(value_list, context);
context << ')';
}
return context;
}
};
template <typename Container>
struct value_list_t;
template <typename Context, typename Operand, typename 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 T = not_in_t<Operand, value_list_t<Container>>;
static Context& _(const T& t, Context& context)
{
const auto& value_list = std::get<0>(t._args);
if (value_list._container.empty())
{
context << " 'operand not in empty list' != 'false' ";
}
else
{
serialize(t._operand, context);
context << " NOT IN(";
serialize(value_list, context);
context << ')';
}
return context;
}
};
}
#endif

View File

@ -31,27 +31,26 @@
namespace sqlpp
{
struct null_t
{
using _traits = make_traits<no_value_t, tag::is_expression, tag::is_sql_null>;
using _nodes = detail::type_vector<>;
};
struct null_t
{
using _traits = make_traits<no_value_t, tag::is_expression, tag::is_sql_null>;
using _nodes = detail::type_vector<>;
};
template<typename Context>
struct serializer_t<Context, null_t>
{
using _serialize_check = consistent_t;
using Operand = null_t;
template <typename Context>
struct serializer_t<Context, null_t>
{
using _serialize_check = consistent_t;
using Operand = null_t;
static Context& _(const Operand&, Context& context)
{
context << "NULL";
return context;
}
};
constexpr null_t null = {};
static Context& _(const Operand&, Context& context)
{
context << "NULL";
return context;
}
};
constexpr null_t null = {};
}
#endif

View File

@ -33,249 +33,262 @@
namespace sqlpp
{
// OFFSET DATA
template<typename Offset>
struct offset_data_t
{
offset_data_t(Offset value):
_value(value)
{}
// OFFSET DATA
template <typename Offset>
struct offset_data_t
{
offset_data_t(Offset value) : _value(value)
{
}
offset_data_t(const offset_data_t&) = default;
offset_data_t(offset_data_t&&) = default;
offset_data_t& operator=(const offset_data_t&) = default;
offset_data_t& operator=(offset_data_t&&) = default;
~offset_data_t() = default;
offset_data_t(const offset_data_t&) = default;
offset_data_t(offset_data_t&&) = default;
offset_data_t& operator=(const offset_data_t&) = default;
offset_data_t& operator=(offset_data_t&&) = default;
~offset_data_t() = default;
Offset _value;
};
Offset _value;
};
// OFFSET
template<typename Offset>
struct offset_t
{
using _traits = make_traits<no_value_t, tag::is_offset>;
using _nodes = detail::type_vector<Offset>;
// OFFSET
template <typename Offset>
struct offset_t
{
using _traits = make_traits<no_value_t, tag::is_offset>;
using _nodes = detail::type_vector<Offset>;
static_assert(is_integral_t<Offset>::value, "offset requires an integral value or integral parameter");
static_assert(is_integral_t<Offset>::value, "offset requires an integral value or integral parameter");
// Data
using _data_t = offset_data_t<Offset>;
// Data
using _data_t = offset_data_t<Offset>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = offset_data_t<Offset>;
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = offset_data_t<Offset>;
_impl_t<Policies> offset;
_impl_t<Policies>& operator()() { return offset; }
const _impl_t<Policies>& operator()() const { return offset; }
_impl_t<Policies> offset;
_impl_t<Policies>& operator()()
{
return offset;
}
const _impl_t<Policies>& operator()() const
{
return offset;
}
template<typename T>
static auto _get_member(T t) -> decltype(t.offset)
{
return t.offset;
}
template <typename T>
static auto _get_member(T t) -> decltype(t.offset)
{
return t.offset;
}
using _consistency_check = consistent_t;
};
};
using _consistency_check = consistent_t;
};
};
// DYNAMIC OFFSET DATA
template<typename Database>
struct dynamic_offset_data_t
{
dynamic_offset_data_t():
_value(noop())
{
}
// DYNAMIC OFFSET DATA
template <typename Database>
struct dynamic_offset_data_t
{
dynamic_offset_data_t() : _value(noop())
{
}
template<typename Offset>
dynamic_offset_data_t(Offset value):
_initialized(true),
_value(wrap_operand_t<Offset>(value))
{
}
template <typename Offset>
dynamic_offset_data_t(Offset value)
: _initialized(true), _value(wrap_operand_t<Offset>(value))
{
}
dynamic_offset_data_t(const dynamic_offset_data_t&) = default;
dynamic_offset_data_t(dynamic_offset_data_t&&) = default;
dynamic_offset_data_t& operator=(const dynamic_offset_data_t&) = default;
dynamic_offset_data_t& operator=(dynamic_offset_data_t&&) = default;
~dynamic_offset_data_t() = default;
dynamic_offset_data_t(const dynamic_offset_data_t&) = default;
dynamic_offset_data_t(dynamic_offset_data_t&&) = default;
dynamic_offset_data_t& operator=(const dynamic_offset_data_t&) = default;
dynamic_offset_data_t& operator=(dynamic_offset_data_t&&) = default;
~dynamic_offset_data_t() = default;
bool _initialized = false;
interpretable_t<Database> _value;
};
bool _initialized = false;
interpretable_t<Database> _value;
};
// DYNAMIC OFFSET
template<typename Database>
struct dynamic_offset_t
{
using _traits = make_traits<no_value_t, tag::is_offset>;
using _nodes = detail::type_vector<>;
// DYNAMIC OFFSET
template <typename Database>
struct dynamic_offset_t
{
using _traits = make_traits<no_value_t, tag::is_offset>;
using _nodes = detail::type_vector<>;
// Data
using _data_t = dynamic_offset_data_t<Database>;
// Data
using _data_t = dynamic_offset_data_t<Database>;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template<typename Offset>
void set(Offset value)
{
// FIXME: Make sure that Offset does not require external tables? Need to read up on SQL
using arg_t = wrap_operand_t<Offset>;
static_assert(is_integral_t<arg_t>::value, "offset requires an integral value or integral parameter");
_data._value = arg_t{value};
_data._initialized = true;
}
public:
_data_t _data;
};
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template <typename Offset>
void set(Offset value)
{
// FIXME: Make sure that Offset does not require external tables? Need to read up on SQL
using arg_t = wrap_operand_t<Offset>;
static_assert(is_integral_t<arg_t>::value, "offset requires an integral value or integral parameter");
_data._value = arg_t{value};
_data._initialized = true;
}
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = dynamic_offset_data_t<Database>;
public:
_data_t _data;
};
_impl_t<Policies> offset;
_impl_t<Policies>& operator()() { return offset; }
const _impl_t<Policies>& operator()() const { return offset; }
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = dynamic_offset_data_t<Database>;
template<typename T>
static auto _get_member(T t) -> decltype(t.offset)
{
return t.offset;
}
_impl_t<Policies> offset;
_impl_t<Policies>& operator()()
{
return offset;
}
const _impl_t<Policies>& operator()() const
{
return offset;
}
using _consistency_check = consistent_t;
template <typename T>
static auto _get_member(T t) -> decltype(t.offset)
{
return t.offset;
}
template<typename Offset>
void set_offset(Offset value)
{
// FIXME: Make sure that Offset does not require external tables? Need to read up on SQL
using arg_t = wrap_operand_t<Offset>;
static_cast<derived_statement_t<Policies>*>(this)->_offset()._value = arg_t{value};
static_cast<derived_statement_t<Policies>*>(this)->_offset()._initialized = true;
}
};
using _consistency_check = consistent_t;
bool _initialized = false;
interpretable_t<Database> _value;
};
template <typename Offset>
void set_offset(Offset value)
{
// FIXME: Make sure that Offset does not require external tables? Need to read up on SQL
using arg_t = wrap_operand_t<Offset>;
static_cast<derived_statement_t<Policies>*>(this)->_offset()._value = arg_t{value};
static_cast<derived_statement_t<Policies>*>(this)->_offset()._initialized = true;
}
};
struct no_offset_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
bool _initialized = false;
interpretable_t<Database> _value;
};
// Data
using _data_t = no_data_t;
struct no_offset_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Data
using _data_t = no_data_t;
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = no_data_t;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
_impl_t<Policies> no_offset;
_impl_t<Policies>& operator()() { return no_offset; }
const _impl_t<Policies>& operator()() const { return no_offset; }
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = no_data_t;
template<typename T>
static auto _get_member(T t) -> decltype(t.no_offset)
{
return t.no_offset;
}
_impl_t<Policies> no_offset;
_impl_t<Policies>& operator()()
{
return no_offset;
}
const _impl_t<Policies>& operator()() const
{
return no_offset;
}
using _database_t = typename Policies::_database_t;
template <typename T>
static auto _get_member(T t) -> decltype(t.no_offset)
{
return t.no_offset;
}
template<typename T>
using _check = is_integral_t<wrap_operand_t<T>>;
using _database_t = typename Policies::_database_t;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_offset_t, T>;
template <typename T>
using _check = is_integral_t<wrap_operand_t<T>>;
using _consistency_check = consistent_t;
template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_offset_t, T>;
template<typename Arg>
auto offset(Arg arg) const
-> _new_statement_t<_check<Arg>, offset_t<wrap_operand_t<Arg>>>
{
static_assert(_check<Arg>::value, "offset requires an integral value or integral parameter");
return _offset_impl(_check<Arg>{}, wrap_operand_t<Arg>{arg});
}
using _consistency_check = consistent_t;
auto dynamic_offset() const
-> _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");
return { static_cast<const derived_statement_t<Policies>&>(*this), dynamic_offset_data_t<_database_t>{} };
}
template <typename Arg>
auto offset(Arg arg) const -> _new_statement_t<_check<Arg>, offset_t<wrap_operand_t<Arg>>>
{
static_assert(_check<Arg>::value, "offset requires an integral value or integral parameter");
return _offset_impl(_check<Arg>{}, wrap_operand_t<Arg>{arg});
}
private:
template<typename Arg>
auto _offset_impl(const std::false_type&, Arg arg) const
-> bad_statement;
auto dynamic_offset() const -> _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");
return {static_cast<const derived_statement_t<Policies>&>(*this), dynamic_offset_data_t<_database_t>{}};
}
template<typename Arg>
auto _offset_impl(const std::true_type&, Arg arg) const
-> _new_statement_t<std::true_type, offset_t<Arg>>
{
return { static_cast<const derived_statement_t<Policies>&>(*this), offset_data_t<Arg>{arg} };
}
private:
template <typename Arg>
auto _offset_impl(const std::false_type&, Arg arg) const -> bad_statement;
};
};
template <typename Arg>
auto _offset_impl(const std::true_type&, Arg arg) const -> _new_statement_t<std::true_type, offset_t<Arg>>
{
return {static_cast<const derived_statement_t<Policies>&>(*this), offset_data_t<Arg>{arg}};
}
};
};
// Interpreters
template<typename Context, typename Offset>
struct serializer_t<Context, offset_data_t<Offset>>
{
using _serialize_check = serialize_check_of<Context, Offset>;
using T = offset_data_t<Offset>;
// Interpreters
template <typename Context, typename Offset>
struct serializer_t<Context, offset_data_t<Offset>>
{
using _serialize_check = serialize_check_of<Context, Offset>;
using T = offset_data_t<Offset>;
static Context& _(const T& t, Context& context)
{
context << " OFFSET ";
serialize_operand(t._value, context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
context << " OFFSET ";
serialize_operand(t._value, context);
return context;
}
};
template<typename Context, typename Database>
struct serializer_t<Context, dynamic_offset_data_t<Database>>
{
using _serialize_check = consistent_t;
using T = dynamic_offset_data_t<Database>;
template <typename Context, typename Database>
struct serializer_t<Context, dynamic_offset_data_t<Database>>
{
using _serialize_check = consistent_t;
using T = dynamic_offset_data_t<Database>;
static Context& _(const T& t, Context& context)
{
if (t._initialized)
{
context << " OFFSET ";
serialize(t._value, context);
}
return context;
}
};
static Context& _(const T& t, Context& context)
{
if (t._initialized)
{
context << " OFFSET ";
serialize(t._value, context);
}
return context;
}
};
}
#endif

View File

@ -34,63 +34,62 @@
namespace sqlpp
{
template<typename Database, typename... Expressions>
struct on_t
{
using _traits = make_traits<no_value_t, tag::is_on>;
using _nodes = detail::type_vector<Expressions...>;
template <typename Database, typename... Expressions>
struct on_t
{
using _traits = make_traits<no_value_t, tag::is_on>;
using _nodes = detail::type_vector<Expressions...>;
using _is_dynamic = is_database<Database>;
using _is_dynamic = is_database<Database>;
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>
void add(Expr expr)
{
static_assert(_is_dynamic::value, "on::add() must not be called for static on()");
static_assert(is_expression_t<Expr>::value, "invalid expression argument in on::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expr>;
_serialize_check::_();
template <typename Expr>
void add(Expr expr)
{
static_assert(_is_dynamic::value, "on::add() must not be called for static on()");
static_assert(is_expression_t<Expr>::value, "invalid expression argument in on::add()");
using _serialize_check = sqlpp::serialize_check_t<typename Database::_serializer_context_t, Expr>;
_serialize_check::_();
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_expression_t<Expr>::value, _serialize_check::type::value>;
_add_impl(expr, ok()); // dispatch to prevent compile messages after the static_assert
}
_add_impl(expr, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Expr>
void _add_impl(Expr expr, const std::true_type&)
{
return _dynamic_expressions.emplace_back(expr);
}
private:
template <typename Expr>
void _add_impl(Expr expr, const std::true_type&)
{
return _dynamic_expressions.emplace_back(expr);
}
template<typename Expr>
void _add_impl(Expr expr, const std::false_type&);
template <typename Expr>
void _add_impl(Expr expr, const std::false_type&);
public:
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
public:
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
template<typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, on_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = on_t<Database, Expressions...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " ON ";
interpret_tuple(t._expressions, " AND ", context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
context << " AND ";
interpret_list(t._dynamic_expressions, " AND ", context);
return context;
}
};
template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, on_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = on_t<Database, Expressions...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " ON ";
interpret_tuple(t._expressions, " AND ", context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
context << " AND ";
interpret_list(t._dynamic_expressions, " AND ", context);
return context;
}
};
}
#endif

View File

@ -37,203 +37,220 @@
namespace sqlpp
{
// ORDER BY DATA
template<typename Database, typename... Expressions>
struct order_by_data_t
{
order_by_data_t(Expressions... expressions):
_expressions(expressions...)
{}
// ORDER BY DATA
template <typename Database, typename... Expressions>
struct order_by_data_t
{
order_by_data_t(Expressions... expressions) : _expressions(expressions...)
{
}
order_by_data_t(const order_by_data_t&) = default;
order_by_data_t(order_by_data_t&&) = default;
order_by_data_t& operator=(const order_by_data_t&) = default;
order_by_data_t& operator=(order_by_data_t&&) = default;
~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& operator=(const order_by_data_t&) = default;
order_by_data_t& operator=(order_by_data_t&&) = default;
~order_by_data_t() = default;
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
std::tuple<Expressions...> _expressions;
interpretable_list_t<Database> _dynamic_expressions;
};
struct assert_no_unknown_tables_in_order_by_t
{
using type = std::false_type;
struct assert_no_unknown_tables_in_order_by_t
{
using type = std::false_type;
template<typename T = 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");
}
};
template <typename T = 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");
}
};
// ORDER BY
template<typename Database, typename... Expressions>
struct order_by_t
{
using _traits = make_traits<no_value_t, tag::is_order_by>;
using _nodes = detail::type_vector<Expressions...>;
// ORDER BY
template <typename Database, typename... Expressions>
struct order_by_t
{
using _traits = make_traits<no_value_t, tag::is_order_by>;
using _nodes = detail::type_vector<Expressions...>;
using _is_dynamic = is_database<Database>;
using _is_dynamic = is_database<Database>;
// Data
using _data_t = order_by_data_t<Database, Expressions...>;
// Data
using _data_t = order_by_data_t<Database, Expressions...>;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
template<typename Expression>
void add_ntc(Expression expression)
{
add<Expression, std::false_type>(expression);
}
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
template <typename Expression>
void add_ntc(Expression expression)
{
add<Expression, std::false_type>(expression);
}
template<typename Expression, typename TableCheckRequired = std::true_type>
void add(Expression expression)
{
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(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>;
_serialize_check::_();
template <typename Expression, typename TableCheckRequired = std::true_type>
void add(Expression expression)
{
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(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>;
_serialize_check::_();
using ok = logic::all_t<_is_dynamic::value, is_sort_order_t<Expression>::value, _serialize_check::type::value>;
using ok = logic::all_t<_is_dynamic::value, is_sort_order_t<Expression>::value, _serialize_check::type::value>;
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
_add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert
}
private:
template<typename Expression>
void _add_impl(Expression expression, const std::true_type&)
{
return _data._dynamic_expressions.emplace_back(expression);
}
private:
template <typename Expression>
void _add_impl(Expression expression, const std::true_type&)
{
return _data._dynamic_expressions.emplace_back(expression);
}
template<typename Expression>
void _add_impl(Expression expression, const std::false_type&);
public:
_data_t _data;
};
template <typename Expression>
void _add_impl(Expression expression, const std::false_type&);
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = order_by_data_t<Database, Expressions...>;
public:
_data_t _data;
};
_impl_t<Policies> order_by;
_impl_t<Policies>& operator()() { return order_by; }
const _impl_t<Policies>& operator()() const { return order_by; }
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = order_by_data_t<Database, Expressions...>;
template<typename T>
static auto _get_member(T t) -> decltype(t.order_by)
{
return t.order_by;
}
_impl_t<Policies> order_by;
_impl_t<Policies>& operator()()
{
return order_by;
}
const _impl_t<Policies>& operator()() const
{
return order_by;
}
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<order_by_t>::value,
consistent_t,
assert_no_unknown_tables_in_order_by_t>::type;
};
};
template <typename T>
static auto _get_member(T t) -> decltype(t.order_by)
{
return t.order_by;
}
// NO ORDER BY YET
struct no_order_by_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<order_by_t>::value,
consistent_t,
assert_no_unknown_tables_in_order_by_t>::type;
};
};
// Data
using _data_t = no_data_t;
// NO ORDER BY YET
struct no_order_by_t
{
using _traits = make_traits<no_value_t, tag::is_noop>;
using _nodes = detail::type_vector<>;
// Member implementation with data and methods
template<typename Policies>
struct _impl_t
{
_data_t _data;
};
// Data
using _data_t = no_data_t;
// Base template to be inherited by the statement
template<typename Policies>
struct _base_t
{
using _data_t = no_data_t;
// Member implementation with data and methods
template <typename Policies>
struct _impl_t
{
_data_t _data;
};
_impl_t<Policies> no_order_by;
_impl_t<Policies>& operator()() { return no_order_by; }
const _impl_t<Policies>& operator()() const { return no_order_by; }
// Base template to be inherited by the statement
template <typename Policies>
struct _base_t
{
using _data_t = no_data_t;
template<typename T>
static auto _get_member(T t) -> decltype(t.no_order_by)
{
return t.no_order_by;
}
_impl_t<Policies> no_order_by;
_impl_t<Policies>& operator()()
{
return no_order_by;
}
const _impl_t<Policies>& operator()() const
{
return no_order_by;
}
using _database_t = typename Policies::_database_t;
template <typename T>
static auto _get_member(T t) -> decltype(t.no_order_by)
{
return t.no_order_by;
}
template<typename... T>
using _check = logic::all_t<is_sort_order_t<T>::value...>;
using _database_t = typename Policies::_database_t;
template<typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_order_by_t, T>;
template <typename... T>
using _check = logic::all_t<is_sort_order_t<T>::value...>;
using _consistency_check = consistent_t;
template <typename Check, typename T>
using _new_statement_t = new_statement_t<Check::value, Policies, no_order_by_t, T>;
template<typename... Expressions>
auto order_by(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, order_by_t<void, Expressions...>>
{
static_assert(sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()");
static_assert(_check<Expressions...>::value, "at least one argument is not a sort order in order_by()");
using _consistency_check = consistent_t;
return _order_by_impl<void>(_check<Expressions...>{}, expressions...);
}
template <typename... Expressions>
auto order_by(Expressions... expressions) const
-> _new_statement_t<_check<Expressions...>, order_by_t<void, Expressions...>>
{
static_assert(sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()");
static_assert(_check<Expressions...>::value, "at least one argument is not a sort order in order_by()");
template<typename... Expressions>
auto dynamic_order_by(Expressions... expressions) const
-> _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(_check<Expressions...>::value, "at least one argument is not a sort order in order_by()");
return _order_by_impl<void>(_check<Expressions...>{}, expressions...);
}
return _order_by_impl<_database_t>(_check<Expressions...>{}, expressions...);
}
template <typename... Expressions>
auto dynamic_order_by(Expressions... expressions) const
-> _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(_check<Expressions...>::value, "at least one argument is not a sort order in order_by()");
private:
template<typename Database, typename... Expressions>
auto _order_by_impl(const std::false_type&, Expressions... expressions) const
-> bad_statement;
return _order_by_impl<_database_t>(_check<Expressions...>{}, expressions...);
}
template<typename Database, typename... Expressions>
auto _order_by_impl(const std::true_type&, Expressions... expressions) const
-> _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()");
private:
template <typename Database, typename... Expressions>
auto _order_by_impl(const std::false_type&, Expressions... expressions) const -> bad_statement;
return { static_cast<const derived_statement_t<Policies>&>(*this), order_by_data_t<Database, Expressions...>{expressions...} };
}
};
};
template <typename Database, typename... Expressions>
auto _order_by_impl(const std::true_type&, Expressions... expressions) const
-> _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()");
// Interpreters
template<typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, order_by_data_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = order_by_data_t<Database, Expressions...>;
return {static_cast<const derived_statement_t<Policies>&>(*this),
order_by_data_t<Database, Expressions...>{expressions...}};
}
};
};
static Context& _(const T& t, Context& context)
{
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " ORDER BY ";
interpret_tuple(t._expressions, ',', context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
context << ',';
interpret_list(t._dynamic_expressions, ',', context);
return context;
}
};
// Interpreters
template <typename Context, typename Database, typename... Expressions>
struct serializer_t<Context, order_by_data_t<Database, Expressions...>>
{
using _serialize_check = serialize_check_of<Context, Expressions...>;
using T = order_by_data_t<Database, Expressions...>;
static Context& _(const T& t, Context& context)
{
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
return context;
context << " ORDER BY ";
interpret_tuple(t._expressions, ',', context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
context << ',';
interpret_list(t._dynamic_expressions, ',', context);
return context;
}
};
}
#endif

View File

@ -33,58 +33,55 @@
namespace sqlpp
{
template<typename ValueType, typename NameType>
struct parameter_t:
public expression_operators<parameter_t<ValueType, NameType>, ValueType>
{
using _traits = make_traits<ValueType, tag::is_parameter, tag::is_expression>;
template <typename ValueType, typename NameType>
struct parameter_t : public expression_operators<parameter_t<ValueType, NameType>, ValueType>
{
using _traits = make_traits<ValueType, tag::is_parameter, tag::is_expression>;
using _nodes = detail::type_vector<>;
using _parameters = detail::type_vector<parameter_t>;
using _can_be_null = std::true_type;
using _nodes = detail::type_vector<>;
using _parameters = detail::type_vector<parameter_t>;
using _can_be_null = std::true_type;
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(parameter_t&&) = default;
parameter_t& operator=(const parameter_t&) = default;
parameter_t& operator=(parameter_t&&) = default;
~parameter_t() = default;
};
parameter_t(const parameter_t&) = default;
parameter_t(parameter_t&&) = default;
parameter_t& operator=(const parameter_t&) = default;
parameter_t& operator=(parameter_t&&) = default;
~parameter_t() = default;
};
template<typename Context, typename ValueType, typename NameType>
struct serializer_t<Context, parameter_t<ValueType, NameType>>
{
using _serialize_check = consistent_t;
using T = parameter_t<ValueType, NameType>;
template <typename Context, typename ValueType, typename NameType>
struct serializer_t<Context, parameter_t<ValueType, NameType>>
{
using _serialize_check = consistent_t;
using T = parameter_t<ValueType, NameType>;
static Context& _(const T&, Context& context)
{
context << "?";
return context;
}
};
static Context& _(const T&, Context& context)
{
context << "?";
return context;
}
};
template<typename NamedExpr>
auto parameter(const NamedExpr&)
-> parameter_t<value_type_of<NamedExpr>, NamedExpr>
{
static_assert(is_selectable_t<NamedExpr>::value, "not a named expression");
return {};
}
template<typename ValueType, typename AliasProvider>
auto parameter(const ValueType&, const 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_alias_provider_t<AliasProvider>::value, "second argument is not an alias provider");
return {};
}
template <typename NamedExpr>
auto parameter(const NamedExpr&) -> parameter_t<value_type_of<NamedExpr>, NamedExpr>
{
static_assert(is_selectable_t<NamedExpr>::value, "not a named expression");
return {};
}
template <typename ValueType, typename AliasProvider>
auto parameter(const ValueType&, const 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_alias_provider_t<AliasProvider>::value, "second argument is not an alias provider");
return {};
}
}
#endif

View File

@ -34,39 +34,40 @@
namespace sqlpp
{
template<typename 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");
};
template <typename 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");
};
template<typename... Parameter>
struct parameter_list_t<detail::type_vector<Parameter...>>: public Parameter::_instance_t...
{
using _member_tuple_t = std::tuple<typename Parameter::_instance_t...>;
using size = std::integral_constant<std::size_t, sizeof...(Parameter)>;
template <typename... Parameter>
struct parameter_list_t<detail::type_vector<Parameter...>> : public Parameter::_instance_t...
{
using _member_tuple_t = std::tuple<typename Parameter::_instance_t...>;
using size = std::integral_constant<std::size_t, sizeof...(Parameter)>;
parameter_list_t()
{}
parameter_list_t()
{
}
template<typename Target>
void _bind(Target& target) const
{
_bind_impl(target, detail::make_index_sequence<size::value>{});
}
template <typename Target>
void _bind(Target& target) const
{
_bind_impl(target, detail::make_index_sequence<size::value>{});
}
private:
template<typename Target, size_t... Is>
void _bind_impl(Target& target, const detail::index_sequence<Is...>&) const
{
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)...};
}
};
template<typename Exp>
using make_parameter_list_t = parameter_list_t<parameters_of<Exp>>;
private:
template <typename Target, size_t... Is>
void _bind_impl(Target& target, const detail::index_sequence<Is...>&) const
{
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)...};
}
};
template <typename Exp>
using make_parameter_list_t = parameter_list_t<parameters_of<Exp>>;
}
#endif

View File

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

View File

@ -31,9 +31,9 @@
// enable the Clang support
#if defined(__clang__) && !BOOST_PP_VARIADICS
# undef BOOST_PP_VARIADICS
# define BOOST_PP_VARIADICS 1
#endif // defined(__clang__)
#undef BOOST_PP_VARIADICS
#define BOOST_PP_VARIADICS 1
#endif // defined(__clang__)
// boost.preprocessor
#include <boost/preprocessor/cat.hpp>
@ -78,130 +78,112 @@
/***************************************************************************/
// tools
#define SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
BOOST_PP_TUPLE_ELEM(0, BOOST_PP_EXPAND table)
#define SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) BOOST_PP_TUPLE_ELEM(0, BOOST_PP_EXPAND table)
#define SQLPP_DECLARE_TABLE_GET_TABLE_PROPS(table) \
SQLPP_BOOST_PP_TUPLE_POP_FRONT(BOOST_PP_EXPAND table)
#define SQLPP_DECLARE_TABLE_GET_TABLE_PROPS(table) SQLPP_BOOST_PP_TUPLE_POP_FRONT(BOOST_PP_EXPAND table)
#define SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(col) \
BOOST_PP_TUPLE_ELEM(0, col)
#define SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(col) BOOST_PP_TUPLE_ELEM(0, col)
#define SQLPP_DECLARE_TABLE_ENUM_COLUMNS(unused, table, elem) \
,table::SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)
#define SQLPP_DECLARE_TABLE_ENUM_COLUMNS(unused, table, elem) , table::SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)
/***************************************************************************/
// columns
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX(unused, size, idx, elem) \
BOOST_PP_CAT( \
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))
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX(unused, size, idx, elem) \
BOOST_PP_CAT(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))
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS(props) \
BOOST_PP_SEQ_FOR_EACH_I( \
SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX \
,BOOST_PP_TUPLE_SIZE(props) \
,BOOST_PP_TUPLE_TO_SEQ(props) \
)
BOOST_PP_SEQ_FOR_EACH_I(SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX, BOOST_PP_TUPLE_SIZE(props), BOOST_PP_TUPLE_TO_SEQ(props))
#define SQLPP_DECLARE_COLUMN(unused, data, elem) \
struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) { \
struct _alias_t { \
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>; \
\
template<typename T> \
struct _member_t { \
T SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \
\
T& operator()() { return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); } \
const T& operator()() const { return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); } \
}; /* struct _member_t */ \
}; /* struct _alias_t */ \
\
using _traits = sqlpp::make_traits< \
SQLPP_DECLARE_COLUMN_GEN_TRAITS(SQLPP_BOOST_PP_TUPLE_POP_FRONT(elem)) \
>; \
\
}; /* struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) */
#define SQLPP_DECLARE_COLUMN(unused, data, elem) \
struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) \
{ \
struct _alias_t \
{ \
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>; \
\
template <typename T> \
struct _member_t \
{ \
T SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \
\
T& operator()() \
{ \
return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \
} \
const T& operator()() const \
{ \
return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \
} \
}; /* struct _member_t */ \
}; /* struct _alias_t */ \
\
using _traits = sqlpp::make_traits<SQLPP_DECLARE_COLUMN_GEN_TRAITS(SQLPP_BOOST_PP_TUPLE_POP_FRONT(elem))>; \
\
}; /* struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) */
/***************************************************************************/
// table props
#define SQLPP_DECLARE_TABLE_GEN_PROPS_AUX(unused1, unused2, elem) \
BOOST_PP_CAT( \
SQLPP_DECLARE_TABLE_GEN_ \
,BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_PROC_LAZY_, elem) \
)(elem)
BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GEN_, BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_PROC_LAZY_, elem))(elem)
#define SQLPP_DECLARE_TABLE_GEN_PROPS(table) \
BOOST_PP_SEQ_FOR_EACH( \
SQLPP_DECLARE_TABLE_GEN_PROPS_AUX \
,~ \
,BOOST_PP_TUPLE_TO_SEQ(SQLPP_BOOST_PP_TUPLE_POP_FRONT(table)) \
)
#define SQLPP_DECLARE_TABLE_GEN_PROPS(table) \
BOOST_PP_SEQ_FOR_EACH(SQLPP_DECLARE_TABLE_GEN_PROPS_AUX, ~, \
BOOST_PP_TUPLE_TO_SEQ(SQLPP_BOOST_PP_TUPLE_POP_FRONT(table)))
/***************************************************************************/
// main
#define SQLPP_DECLARE_TABLE_IMPL(table, cols) \
namespace SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) { \
namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) { \
BOOST_PP_SEQ_FOR_EACH( \
SQLPP_DECLARE_COLUMN \
,~ \
,cols \
) \
} /* namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) */ \
\
struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
: sqlpp::table_t< \
SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
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_LESS(BOOST_PP_TUPLE_SIZE(table), 2) \
,BOOST_PP_TUPLE_EAT() \
,SQLPP_DECLARE_TABLE_GEN_PROPS \
)(BOOST_PP_EXPAND table) \
\
struct _alias_t { \
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>; \
\
template<typename T> \
struct _member_t { \
T SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \
\
T& operator()() { return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); } \
const T& operator()() const { return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); } \
\
}; /* struct _member_t */ \
\
}; /* struct _alias_t */ \
\
}; /* struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) */ \
\
}
#define SQLPP_DECLARE_TABLE_IMPL(table, cols) \
namespace SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
{ \
namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) \
{ \
BOOST_PP_SEQ_FOR_EACH(SQLPP_DECLARE_COLUMN, ~, cols) \
} /* namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) */ \
\
struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
: sqlpp::table_t<SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) 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_LESS(BOOST_PP_TUPLE_SIZE(table), 2), \
BOOST_PP_TUPLE_EAT(), \
SQLPP_DECLARE_TABLE_GEN_PROPS)(BOOST_PP_EXPAND table) \
\
struct _alias_t \
{ \
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>; \
\
template <typename T> \
struct _member_t \
{ \
T SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \
\
T& operator()() \
{ \
return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \
} \
const T& operator()() const \
{ \
return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \
} \
\
}; /* struct _member_t */ \
\
}; /* struct _alias_t */ \
\
}; /* struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) */ \
}
/***************************************************************************/
#define SQLPP_DECLARE_TABLE(table, cols) \
SQLPP_DECLARE_TABLE_IMPL( \
BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X table, 0) \
,BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X cols, 0) \
)
SQLPP_DECLARE_TABLE_IMPL(BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X table, 0), BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X cols, 0))
/***************************************************************************/
#endif // _sqlpp__ppgen_h
#endif // _sqlpp__ppgen_h

View File

@ -33,32 +33,30 @@
namespace sqlpp
{
template<typename Db, typename Statement>
struct prepared_execute_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
template <typename Db, typename Statement>
struct prepared_execute_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
using _parameter_list_t = make_parameter_list_t<Statement>;
using _prepared_statement_t = typename Db::_prepared_statement_t;
using _parameter_list_t = make_parameter_list_t<Statement>;
using _prepared_statement_t = typename Db::_prepared_statement_t;
using _run_check = consistent_t;
using _run_check = consistent_t;
auto _run(Db& db) const
-> size_t
{
return db.run_prepared_execute(*this);
}
auto _run(Db& db) const -> size_t
{
return db.run_prepared_execute(*this);
}
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
mutable _prepared_statement_t _prepared_statement;
};
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
mutable _prepared_statement_t _prepared_statement;
};
}
#endif

View File

@ -33,32 +33,30 @@
namespace sqlpp
{
template<typename Db, typename Insert>
struct prepared_insert_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
template <typename Db, typename Insert>
struct prepared_insert_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
using _parameter_list_t = make_parameter_list_t<Insert>;
using _prepared_statement_t = typename Db::_prepared_statement_t;
using _parameter_list_t = make_parameter_list_t<Insert>;
using _prepared_statement_t = typename Db::_prepared_statement_t;
using _run_check = consistent_t;
using _run_check = consistent_t;
auto _run(Db& db) const
-> size_t
{
return db.run_prepared_insert(*this);
}
auto _run(Db& db) const -> size_t
{
return db.run_prepared_insert(*this);
}
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
mutable _prepared_statement_t _prepared_statement;
};
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
mutable _prepared_statement_t _prepared_statement;
};
}
#endif

View File

@ -33,32 +33,30 @@
namespace sqlpp
{
template<typename Db, typename Remove>
struct prepared_remove_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
template <typename Db, typename Remove>
struct prepared_remove_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
using _parameter_list_t = make_parameter_list_t<Remove>;
using _prepared_statement_t = typename Db::_prepared_statement_t;
using _parameter_list_t = make_parameter_list_t<Remove>;
using _prepared_statement_t = typename Db::_prepared_statement_t;
using _run_check = consistent_t;
using _run_check = consistent_t;
auto _run(Db& db) const
-> size_t
{
return db.run_prepared_insert(*this);
}
auto _run(Db& db) const -> size_t
{
return db.run_prepared_insert(*this);
}
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
mutable _prepared_statement_t _prepared_statement;
};
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
mutable _prepared_statement_t _prepared_statement;
};
}
#endif

View File

@ -33,35 +33,33 @@
namespace sqlpp
{
template<typename Database, typename Statement, typename Composite = Statement>
struct prepared_select_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
template <typename Database, typename Statement, typename Composite = Statement>
struct prepared_select_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
using _result_row_t = typename Statement::template _result_row_t<Database>;
using _parameter_list_t = make_parameter_list_t<Composite>;
using _dynamic_names_t = typename Statement::_dynamic_names_t;
using _prepared_statement_t = typename Database::_prepared_statement_t;
using _result_row_t = typename Statement::template _result_row_t<Database>;
using _parameter_list_t = make_parameter_list_t<Composite>;
using _dynamic_names_t = typename Statement::_dynamic_names_t;
using _prepared_statement_t = typename Database::_prepared_statement_t;
using _run_check = consistent_t;
using _run_check = consistent_t;
auto _run(Database& db) const
-> result_t<decltype(db.run_prepared_select(*this)), _result_row_t>
{
return {db.run_prepared_select(*this), _dynamic_names};
}
auto _run(Database& db) const -> result_t<decltype(db.run_prepared_select(*this)), _result_row_t>
{
return {db.run_prepared_select(*this), _dynamic_names};
}
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
_dynamic_names_t _dynamic_names;
mutable _prepared_statement_t _prepared_statement;
};
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
_dynamic_names_t _dynamic_names;
mutable _prepared_statement_t _prepared_statement;
};
}
#endif

View File

@ -33,32 +33,30 @@
namespace sqlpp
{
template<typename Db, typename Update>
struct prepared_update_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
template <typename Db, typename Update>
struct prepared_update_t
{
using _traits = make_traits<no_value_t, tag::is_prepared_statement>;
using _nodes = detail::type_vector<>;
using _parameter_list_t = make_parameter_list_t<Update>;
using _prepared_statement_t = typename Db::_prepared_statement_t;
using _parameter_list_t = make_parameter_list_t<Update>;
using _prepared_statement_t = typename Db::_prepared_statement_t;
using _run_check = consistent_t;
using _run_check = consistent_t;
auto _run(Db& db) const
-> size_t
{
return db.run_prepared_insert(*this);
}
auto _run(Db& db) const -> size_t
{
return db.run_prepared_insert(*this);
}
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
mutable _prepared_statement_t _prepared_statement;
};
void _bind_params() const
{
params._bind(_prepared_statement);
}
_parameter_list_t params;
mutable _prepared_statement_t _prepared_statement;
};
}
#endif

View File

@ -40,105 +40,95 @@
namespace sqlpp
{
struct remove_name_t {};
struct remove_t: public statement_name_t<remove_name_t>
{
using _traits = make_traits<no_value_t, tag::is_return_value>;
struct _alias_t {};
struct remove_name_t
{
};
struct remove_t : public statement_name_t<remove_name_t>
{
using _traits = make_traits<no_value_t, tag::is_return_value>;
struct _alias_t
{
};
template<typename Statement>
struct _result_methods_t
{
using _statement_t = Statement;
template <typename Statement>
struct _result_methods_t
{
using _statement_t = Statement;
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
const _statement_t& _get_statement() const
{
return static_cast<const _statement_t&>(*this);
}
// Execute
template<typename Db, typename Composite>
auto _run(Db& db, const Composite& composite) const
-> decltype(db.remove(composite))
{
return db.remove(composite);
}
// Execute
template <typename Db, typename Composite>
auto _run(Db& db, const Composite& composite) const -> decltype(db.remove(composite))
{
return db.remove(composite);
}
template<typename Db>
auto _run(Db& db) const -> decltype(db.remove(this->_get_statement()))
{
return db.remove(_get_statement());
}
template <typename Db>
auto _run(Db& db) const -> decltype(db.remove(this->_get_statement()))
{
return db.remove(_get_statement());
}
// Prepare
template<typename Db, typename Composite>
auto _prepare(Db& db, const Composite& composite) const
-> prepared_remove_t<Db, Composite>
{
return {{}, db.prepare_remove(composite)};
}
// Prepare
template <typename Db, typename Composite>
auto _prepare(Db& db, const Composite& composite) const -> prepared_remove_t<Db, Composite>
{
return {{}, db.prepare_remove(composite)};
}
template<typename Db>
auto _prepare(Db& db) const
-> prepared_remove_t<Db, _statement_t>
{
return {{}, db.prepare_remove(_get_statement())};
}
};
};
template <typename Db>
auto _prepare(Db& db) const -> prepared_remove_t<Db, _statement_t>
{
return {{}, db.prepare_remove(_get_statement())};
}
};
};
template <typename Context>
struct serializer_t<Context, remove_name_t>
{
using _serialize_check = consistent_t;
using T = remove_name_t;
template<typename Context>
struct serializer_t<Context, remove_name_t>
{
using _serialize_check = consistent_t;
using T = remove_name_t;
static Context& _(const T&, Context& context)
{
context << "DELETE";
static Context& _(const T&, Context& context)
{
context << "DELETE";
return context;
}
};
return context;
}
};
template <typename Database>
using blank_remove_t = statement_t<Database, remove_t, no_from_t, no_using_t, no_extra_tables_t, no_where_t<true>>;
template<typename Database>
using blank_remove_t = statement_t<Database,
remove_t,
no_from_t,
no_using_t,
no_extra_tables_t,
no_where_t<true>
>;
inline auto remove() -> blank_remove_t<void>
{
return {blank_remove_t<void>()};
}
inline auto remove()
-> blank_remove_t<void>
{
return { blank_remove_t<void>() };
}
template <typename Table>
auto remove_from(Table table) -> decltype(blank_remove_t<void>().from(table))
{
return {blank_remove_t<void>().from(table)};
}
template<typename Table>
auto remove_from(Table table)
-> decltype(blank_remove_t<void>().from(table))
{
return { blank_remove_t<void>().from(table) };
}
template <typename Database>
auto dynamic_remove(const Database&) -> decltype(blank_remove_t<Database>())
{
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return {blank_remove_t<Database>()};
}
template<typename Database>
auto dynamic_remove(const Database&)
-> decltype(blank_remove_t<Database>())
{
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return { blank_remove_t<Database>() };
}
template<typename Database, typename Table>
auto dynamic_remove_from(const Database&, Table table)
-> decltype(blank_remove_t<Database>().from(table))
{
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return { blank_remove_t<Database>().from(table) };
}
template <typename Database, typename Table>
auto dynamic_remove_from(const Database&, Table table) -> decltype(blank_remove_t<Database>().from(table))
{
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return {blank_remove_t<Database>().from(table)};
}
}
#endif

View File

@ -30,98 +30,94 @@
// FIXME: include for move?
namespace sqlpp
{
template<typename DbResult, typename ResultRow>
class result_t
{
using db_result_t = DbResult;
using result_row_t = ResultRow;
template <typename DbResult, typename ResultRow>
class result_t
{
using db_result_t = DbResult;
using result_row_t = ResultRow;
db_result_t _result;
result_row_t _result_row;
db_result_t _end;
result_row_t _end_row;
db_result_t _result;
result_row_t _result_row;
db_result_t _end;
result_row_t _end_row;
public:
result_t() = default;
public:
result_t() = default;
template<typename DynamicNames>
result_t(db_result_t&& result, const DynamicNames& dynamic_names):
_result(std::move(result)),
_result_row(dynamic_names)
{
_result.next(_result_row);
}
template <typename DynamicNames>
result_t(db_result_t&& result, const DynamicNames& dynamic_names)
: _result(std::move(result)), _result_row(dynamic_names)
{
_result.next(_result_row);
}
result_t(const result_t&) = delete;
result_t(result_t&&) = default;
result_t& operator=(const result_t&) = delete;
result_t& operator=(result_t&&) = default;
result_t(const result_t&) = delete;
result_t(result_t&&) = default;
result_t& operator=(const result_t&) = delete;
result_t& operator=(result_t&&) = default;
// Iterator
class iterator
{
public:
iterator(db_result_t& result, result_row_t& result_row):
_result(result),
_result_row(result_row)
{
}
// Iterator
class iterator
{
public:
iterator(db_result_t& result, result_row_t& result_row) : _result(result), _result_row(result_row)
{
}
const result_row_t& operator*() const
{
return _result_row;
}
const result_row_t& operator*() const
{
return _result_row;
}
const result_row_t* operator->() const
{
return &_result_row;
}
const result_row_t* operator->() const
{
return &_result_row;
}
bool operator==(const iterator& rhs) const
{
return _result_row == rhs._result_row;
}
bool operator==(const iterator& rhs) const
{
return _result_row == rhs._result_row;
}
bool operator!=(const iterator& rhs) const
{
return not (operator==(rhs));
}
bool operator!=(const iterator& rhs) const
{
return not(operator==(rhs));
}
void operator++()
{
_result.next(_result_row);
}
void operator++()
{
_result.next(_result_row);
}
db_result_t& _result;
result_row_t& _result_row;
};
db_result_t& _result;
result_row_t& _result_row;
};
iterator begin()
{
return iterator(_result, _result_row);
}
iterator begin()
{
return iterator(_result, _result_row);
}
iterator end()
{
return iterator(_end, _end_row);
}
iterator end()
{
return iterator(_end, _end_row);
}
const result_row_t& front() const
{
return _result_row;
}
const result_row_t& front() const
{
return _result_row;
}
bool empty() const
{
return _result_row == _end_row;
}
bool empty() const
{
return _result_row == _end_row;
}
void pop_front()
{
_result.next(_result_row);
}
};
void pop_front()
{
_result.next(_result_row);
}
};
}
#endif

View File

@ -32,32 +32,30 @@
namespace sqlpp
{
template<typename ValueType, typename Db, typename FieldSpec>
struct 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>
struct serializer_t<Context, result_field_t<ValueType, Db, FieldSpec>>
{
using _serialize_check = consistent_t;
using T = result_field_t<ValueType, Db, FieldSpec>;
static Context& _(const T& t, Context& context)
{
if (t.is_null() and not null_is_trivial_value_t<T>::value)
{
context << "NULL";
}
else
{
context << t.value();
}
return context;
}
};
template <typename ValueType, typename Db, typename FieldSpec>
struct 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>
struct serializer_t<Context, result_field_t<ValueType, Db, FieldSpec>>
{
using _serialize_check = consistent_t;
using T = result_field_t<ValueType, Db, FieldSpec>;
static Context& _(const T& t, Context& context)
{
if (t.is_null() and not null_is_trivial_value_t<T>::value)
{
context << "NULL";
}
else
{
context << t.value();
}
return context;
}
};
}
#endif

View File

@ -32,58 +32,58 @@
namespace sqlpp
{
namespace detail
{
template<typename Field>
struct get_field_spec_impl
{
static_assert(wrong_t<get_field_spec_impl>::value, "Invalid argument for get_field_spec");
};
namespace detail
{
template <typename Field>
struct get_field_spec_impl
{
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>
struct get_field_spec_impl<Field<ValueType, Db, FieldSpec>>
{
using type = FieldSpec;
};
template <template <typename, typename, typename> class Field, typename ValueType, typename Db, typename FieldSpec>
struct get_field_spec_impl<Field<ValueType, Db, FieldSpec>>
{
using type = FieldSpec;
};
template<typename Field>
using get_field_spec_t = typename get_field_spec_impl<Field>::type;
}
template <typename Field>
using get_field_spec_t = typename get_field_spec_impl<Field>::type;
}
template<typename Field, typename Enable = void>
struct result_field_methods_base_t
{
using _field_spec_t = detail::get_field_spec_t<Field>;
static constexpr bool _null_is_trivial = true;
operator cpp_value_type_of<_field_spec_t>() const { return static_cast<const Field&>(*this).value(); }
};
template <typename Field, typename Enable = void>
struct result_field_methods_base_t
{
using _field_spec_t = detail::get_field_spec_t<Field>;
static constexpr bool _null_is_trivial = true;
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>
struct result_field_methods_base_t<
Field<ValueType, Db, FieldSpec>,
typename std::enable_if<enforce_null_result_treatment_t<Db>::value
and column_spec_can_be_null_t<FieldSpec>::value
and not null_is_trivial_value_t<FieldSpec>::value>::type>
{
using _field_spec_t = FieldSpec;
static constexpr bool _null_is_trivial = false;
};
template <template <typename, typename, typename> class Field, typename ValueType, typename Db, typename FieldSpec>
struct result_field_methods_base_t<Field<ValueType, Db, FieldSpec>,
typename std::enable_if<enforce_null_result_treatment_t<Db>::value and
column_spec_can_be_null_t<FieldSpec>::value and
not null_is_trivial_value_t<FieldSpec>::value>::type>
{
using _field_spec_t = FieldSpec;
static constexpr bool _null_is_trivial = false;
};
template<typename Field>
struct result_field_methods_t: public result_field_methods_base_t<Field>,
public alias_operators<Field>
{
using _base_t = result_field_methods_base_t<Field>;
using _field_spec_t = typename _base_t::_field_spec_t;
template <typename Field>
struct result_field_methods_t : public result_field_methods_base_t<Field>, public alias_operators<Field>
{
using _base_t = result_field_methods_base_t<Field>;
using _field_spec_t = typename _base_t::_field_spec_t;
using _traits = make_traits<value_type_of<_field_spec_t>,
tag::is_result_field,
tag::is_expression,
tag_if<tag::null_is_trivial_value, _base_t::_null_is_trivial>>;
using _nodes = detail::type_vector<>;
using _can_be_null = column_spec_can_be_null_t<_field_spec_t>;
};
using _traits = make_traits<value_type_of<_field_spec_t>,
tag::is_result_field,
tag::is_expression,
tag_if<tag::null_is_trivial_value, _base_t::_null_is_trivial>>;
using _nodes = detail::type_vector<>;
using _can_be_null = column_spec_can_be_null_t<_field_spec_t>;
};
}
#endif

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