diff --git a/.clang-format b/.clang-format index f94da0a4..1d9d0f26 100644 --- a/.clang-format +++ b/.clang-format @@ -14,7 +14,7 @@ BreakBeforeBinaryOperators: false BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false BinPackParameters: false -ColumnLimit: 160 +ColumnLimit: 120 ConstructorInitializerAllOnOneLineOrOnePerLine: true DerivePointerAlignment: false ExperimentalAutoDetectBinPacking: false diff --git a/connector_api/bind_result.h b/connector_api/bind_result.h index d14de772..c269b925 100644 --- a/connector_api/bind_result.h +++ b/connector_api/bind_result.h @@ -1,17 +1,17 @@ /* * Copyright (c) 2013-2015, Roland Bock * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - * + * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -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 - void next(ResultRow& result_row); + template + 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 diff --git a/connector_api/connection.h b/connector_api/connection.h index 9a23d8b7..dc2f81c2 100644 --- a/connector_api/connection.h +++ b/connector_api/connection.h @@ -1,17 +1,17 @@ /* * Copyright (c) 2013-2015, Roland Bock * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - * + * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -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 #include -#include // You may use char result or bind result or both -#include // to represent results of select and prepared select +#include // You may use char result or bind result or both +#include // 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 - 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 + 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 - <> select(const Select& s); + //! "direct" select + template + << bind_result_t >> + select(const Select& s); - //! prepared select - template - _prepared_statement_t prepare_select(Select& s); + //! prepared select + template + _prepared_statement_t prepare_select(Select& s); - template - <> run_prepared_select(const PreparedSelect& s); // call s._bind_params() + template + << bind_result_t >> + run_prepared_select(const PreparedSelect& s); // call s._bind_params() - //! "direct insert - template - size_t insert(const Insert& i); + //! "direct insert + template + size_t insert(const Insert& i); - //! prepared insert - template - _prepared_statement_t prepare_insert(Insert& i); + //! prepared insert + template + _prepared_statement_t prepare_insert(Insert& i); - template - size_t run_prepared_insert(const PreparedInsert& i); // call i._bind_params() + template + size_t run_prepared_insert(const PreparedInsert& i); // call i._bind_params() - //! "direct" update - template - size_t update(const Update& u); + //! "direct" update + template + size_t update(const Update& u); - //! "prepared" update - template - _prepared_statement_t prepare_update(Update& u); + //! "prepared" update + template + _prepared_statement_t prepare_update(Update& u); - template - size_t run_prepared_update(const PreparedUpdate& u); // call u._bind_params() + template + size_t run_prepared_update(const PreparedUpdate& u); // call u._bind_params() - //! "direct" remove - template - size_t remove(const Remove& r) + //! "direct" remove + template + size_t remove(const Remove& r) - //! prepared remove - template - _prepared_statement_t prepare_remove(Remove& r); + //! prepared remove + template + _prepared_statement_t prepare_remove(Remove& r); - template - size_t run_prepared_remove(const PreparedRemove& r); // call r._bind_params() + template + size_t run_prepared_remove(const PreparedRemove& r); // call r._bind_params() - //! call run on the argument - template - auto operator() (const T& t) -> decltype(t._run(*this)) - { - return t._run(*this); - } + //! call run on the argument + template + auto operator()(const T& t) -> decltype(t._run(*this)) + { + return t._run(*this); + } - //! call prepare on the argument - template - auto prepare(const T& t) -> decltype(t._prepare(*this)) - { - return t._prepare(*this); - } + //! call prepare on the argument + template + 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 diff --git a/connector_api/interpreter.h b/connector_api/interpreter.h index d59add96..fd694635 100644 --- a/connector_api/interpreter.h +++ b/connector_api/interpreter.h @@ -1,17 +1,17 @@ /* * Copyright (c) 2013-2015, Roland Bock * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - * + * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -31,32 +31,31 @@ #include /* - * sqlpp11 offers an interpreter that can be used to serialize the expression tree + * sqlpp11 offers an interpreter that can be used to serialize the expression tree * into a standard SQL string. * - * The connector library can specialize the interpreter template to partially or + * The connector library can specialize the interpreter template to partially or * completely change the way the expression tree is interpreted. * * For example, this specialization will produce indexed parameters instead of just '?' */ namespace sqlpp { - namespace vendor - { - template - struct interpreter_t> - { - using T = parameter_t; + namespace vendor + { + template + struct interpreter_t> + { + using T = parameter_t; - 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 diff --git a/connector_api/prepared_statement.h b/connector_api/prepared_statement.h index 1524e0f0..7a329788 100644 --- a/connector_api/prepared_statement.h +++ b/connector_api/prepared_statement.h @@ -1,17 +1,17 @@ /* * Copyright (c) 2013-2015, Roland Bock * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - * + * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -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 diff --git a/examples/Sample.h b/examples/Sample.h index 01e7d92d..a4512a88 100644 --- a/examples/Sample.h +++ b/examples/Sample.h @@ -5,6 +5,7 @@ #include #include +// clang-format off namespace test { namespace TabPerson_ diff --git a/examples/TabSample.h b/examples/TabSample.h index 09e7f1ea..9cadacf7 100644 --- a/examples/TabSample.h +++ b/examples/TabSample.h @@ -1,17 +1,17 @@ /* * Copyright (c) 2013-2015, Roland Bock * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - * + * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. - * + * * Redistributions in binary form must reproduce the above copyright notice, this * list of conditions and the following disclaimer in the documentation and/or * other materials provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -30,7 +30,7 @@ #include #include - +// clang-format off namespace TabFoo_ { struct Omega @@ -60,7 +60,7 @@ namespace TabFoo_ } struct TabFoo: sqlpp::table_base_t< - TabFoo, + TabFoo, TabFoo_::Omega > { @@ -151,8 +151,8 @@ namespace TabSample_ } struct TabSample: sqlpp::table_base_t< - TabSample, - TabSample_::Alpha, + TabSample, + TabSample_::Alpha, TabSample_::Beta, TabSample_::Gamma > diff --git a/examples/insert.cpp b/examples/insert.cpp index 107e806c..ab3d0bdb 100644 --- a/examples/insert.cpp +++ b/examples/insert.cpp @@ -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; } diff --git a/examples/ppgen.cpp b/examples/ppgen.cpp index 48ca5610..56374a22 100644 --- a/examples/ppgen.cpp +++ b/examples/ppgen.cpp @@ -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; } diff --git a/examples/remove.cpp b/examples/remove.cpp index 84cdb8b4..c2b41b1d 100644 --- a/examples/remove.cpp +++ b/examples/remove.cpp @@ -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; } diff --git a/examples/sample.cpp b/examples/sample.cpp index d3b71849..e506f443 100644 --- a/examples/sample.cpp +++ b/examples/sample.cpp @@ -1,25 +1,25 @@ /* * Copyright (c) 2014-2015 Roland Bock * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, + * + * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -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; + } } diff --git a/examples/select.cpp b/examples/select.cpp index 1b9849d4..77265d99 100644 --- a/examples/select.cpp +++ b/examples/select.cpp @@ -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; } diff --git a/examples/update.cpp b/examples/update.cpp index 887535f5..a6f0b0c5 100644 --- a/examples/update.cpp +++ b/examples/update.cpp @@ -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; } diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h index 18ecc1da..0a041a9e 100644 --- a/include/sqlpp11/alias.h +++ b/include/sqlpp11/alias.h @@ -32,45 +32,44 @@ namespace sqlpp { - template - struct expression_alias_t - { - using _traits = make_traits, tag::is_selectable, tag::is_alias>; - using _nodes = detail::type_vector; + template + struct expression_alias_t + { + using _traits = make_traits, tag::is_selectable, tag::is_alias>; + using _nodes = detail::type_vector; - static_assert(is_expression_t::value, "invalid argument for an expression alias"); - static_assert(not is_alias_t::value, "cannot create an alias of an alias"); + static_assert(is_expression_t::value, "invalid argument for an expression alias"); + static_assert(not is_alias_t::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 - struct serializer_t> - { - using _serialize_check = serialize_check_of; - using T = expression_alias_t; - - static Context& _(const T& t, Context& context) - { - serialize_operand(t._expression, context); - context << " AS "; - context << name_of::char_ptr(); - return context; - } - }; + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = expression_alias_t; + static Context& _(const T& t, Context& context) + { + serialize_operand(t._expression, context); + context << " AS "; + context << name_of::char_ptr(); + return context; + } + }; } #endif diff --git a/include/sqlpp11/alias_provider.h b/include/sqlpp11/alias_provider.h index cd59b2b2..38bbf528 100644 --- a/include/sqlpp11/alias_provider.h +++ b/include/sqlpp11/alias_provider.h @@ -30,69 +30,76 @@ #include #include -#define SQLPP_ALIAS_PROVIDER(name) \ - struct name##_t\ -{\ - struct _alias_t\ - {\ - static constexpr const char _literal[] = #name;\ - using _name_t = sqlpp::make_char_sequence;\ - template\ - 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; \ + template \ + struct _member_t \ + { \ + T name; \ + T& operator()() \ + { \ + return name; \ + } \ + const T& operator()() const \ + { \ + return name; \ + } \ + }; \ + }; \ + }; \ + constexpr name##_t name = {}; namespace sqlpp { - template - struct is_alias_provider_t - { - static constexpr bool value = false; - }; + template + struct is_alias_provider_t + { + static constexpr bool value = false; + }; - template - struct is_alias_provider_t>::value, void>::type> - { - static constexpr bool value = true; - }; + template + struct is_alias_provider_t< + T, + typename std::enable_if>::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 - diff --git a/include/sqlpp11/all_of.h b/include/sqlpp11/all_of.h index b8f59bed..4c4076cd 100644 --- a/include/sqlpp11/all_of.h +++ b/include/sqlpp11/all_of.h @@ -33,48 +33,46 @@ namespace sqlpp { - template - struct all_of_t - { - using _column_tuple_t = typename Table::_column_tuple_t; + template + struct all_of_t + { + using _column_tuple_t = typename Table::_column_tuple_t; - template - detail::copy_tuple_args_t as(const AliasProvider& alias) - { - return multi_column(_column_tuple_t{}).as(alias); - } - }; + template + detail::copy_tuple_args_t as(const AliasProvider& alias) + { + return multi_column(_column_tuple_t{}).as(alias); + } + }; - template - auto all_of(Table) -> all_of_t - { - return {}; - } + template + auto all_of(Table) -> all_of_t
+ { + 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 - static void _() - { - static_assert(wrong_t::value, "all_of(table) seems to be used outside of select"); - } - }; + template + static void _() + { + static_assert(wrong_t::value, "all_of(table) seems to be used outside of select"); + } + }; - template - struct serializer_t> - { - using _serialize_check = assert_no_stand_alone_all_of_t; - using T = all_of_t
; - - static Context& _(const T&, const Context&) - { - _serialize_check::_(); - } - }; + template + struct serializer_t> + { + using _serialize_check = assert_no_stand_alone_all_of_t; + using T = all_of_t
; + static Context& _(const T&, const Context&) + { + _serialize_check::_(); + } + }; } #endif - diff --git a/include/sqlpp11/any.h b/include/sqlpp11/any.h index daf92732..f7d7885b 100644 --- a/include/sqlpp11/any.h +++ b/include/sqlpp11/any.h @@ -33,49 +33,49 @@ namespace sqlpp { - template - struct any_t - { - using _traits = make_traits, tag::is_multi_expression>; - using _nodes = detail::type_vector; - 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 - struct serializer_t> - { - using _serialize_check = serialize_check_of; - using T = any_t; - static Context& _(const T& t, Context& context) - { - context << "ANY("; - serialize(t._select, context); - context << ")"; - return context; - } - }; - - template - auto any(T t) -> any_t> - { - static_assert(is_select_t>::value, "any() requires a select expression as argument"); - static_assert(is_expression_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 + auto any(T t) -> any_t> + { + static_assert(is_select_t>::value, "any() requires a select expression as argument"); + static_assert(is_expression_t>::value, + "any() requires a single column select expression as argument"); + // FIXME: can we accept non-values like NULL here? + return {t}; + } } #endif diff --git a/include/sqlpp11/assignment.h b/include/sqlpp11/assignment.h index 6e00160d..7517f8f5 100644 --- a/include/sqlpp11/assignment.h +++ b/include/sqlpp11/assignment.h @@ -37,46 +37,46 @@ namespace sqlpp { - template - struct assignment_t - { - using _traits = make_traits; - using _lhs_t = Lhs; - using _rhs_t = rhs_wrap_t, trivial_value_is_null_t<_lhs_t>::value>; - using _nodes = detail::type_vector<_lhs_t, _rhs_t>; + template + struct assignment_t + { + using _traits = make_traits; + using _lhs_t = Lhs; + using _rhs_t = rhs_wrap_t, 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 - struct serializer_t> - { - using T = assignment_t; - using _serialize_check = serialize_check_of; - - static Context& _(const T& t, Context& context) - { - serialize(simple_column(t._lhs), context); - context << "="; - serialize_operand(t._rhs, context); - return context; - } - }; + template + struct serializer_t> + { + using T = assignment_t; + using _serialize_check = serialize_check_of; + static Context& _(const T& t, Context& context) + { + serialize(simple_column(t._lhs), context); + context << "="; + serialize_operand(t._rhs, context); + return context; + } + }; } #endif diff --git a/include/sqlpp11/auto_alias.h b/include/sqlpp11/auto_alias.h index 7b2c9da9..43ce044c 100644 --- a/include/sqlpp11/auto_alias.h +++ b/include/sqlpp11/auto_alias.h @@ -31,36 +31,35 @@ namespace sqlpp { - template - struct has_auto_alias_t - { - static constexpr bool value = false; - }; + template + struct has_auto_alias_t + { + static constexpr bool value = false; + }; - template - struct has_auto_alias_t::value>::type> - { - static constexpr bool value = true; - }; + template + struct has_auto_alias_t::value>::type> + { + static constexpr bool value = true; + }; - namespace detail - { - template - struct auto_alias_impl - { - using type = T; - }; + namespace detail + { + template + struct auto_alias_impl + { + using type = T; + }; - template - struct auto_alias_impl::value>::type> - { - using type = expression_alias_t; - }; - } + template + struct auto_alias_impl::value>::type> + { + using type = expression_alias_t; + }; + } - template - using auto_alias_t = typename detail::auto_alias_impl::type; + template + using auto_alias_t = typename detail::auto_alias_impl::type; } - #endif diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h index 5a23a851..9a4aa642 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/avg.h @@ -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; - template - 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; + template + struct _member_t + { + T avg; + T& operator()() + { + return avg; + } + const T& operator()() const + { + return avg; + } + }; + }; + }; - template - struct avg_t: - public expression_operators, floating_point>, - public alias_operators> - { - using _traits = make_traits; - using _nodes = detail::type_vector; + template + struct avg_t : public expression_operators, floating_point>, + public alias_operators> + { + using _traits = make_traits; + using _nodes = detail::type_vector; - static_assert(is_noop::value or std::is_same::value, "avg() used with flag other than 'distinct'"); - static_assert(is_numeric_t::value, "avg() requires a value expression as argument"); + static_assert(is_noop::value or std::is_same::value, + "avg() used with flag other than 'distinct'"); + static_assert(is_numeric_t::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 - struct serializer_t> - { - using _serialize_check = serialize_check_of; - using T = avg_t; + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = avg_t; - static Context& _(const T& t, Context& context) - { - context << "AVG("; - if (std::is_same::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::value) + { + serialize(Flag(), context); + context << ' '; + serialize_operand(t._expr, context); + } + else + { + serialize(t._expr, context); + } + context << ")"; + return context; + } + }; - template - auto avg(T t) -> avg_t> - { - static_assert(not contains_aggregate_function_t>::value, "avg() cannot be used on an aggregate function"); - static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); - return { t }; - } - - template - auto avg(const distinct_t&, T t) -> avg_t> - { - static_assert(not contains_aggregate_function_t>::value, "avg() cannot be used on an aggregate function"); - static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); - return { t }; - } + template + auto avg(T t) -> avg_t> + { + static_assert(not contains_aggregate_function_t>::value, + "avg() cannot be used on an aggregate function"); + static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); + return {t}; + } + template + auto avg(const distinct_t&, T t) -> avg_t> + { + static_assert(not contains_aggregate_function_t>::value, + "avg() cannot be used on an aggregate function"); + static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); + return {t}; + } } #endif diff --git a/include/sqlpp11/bad_statement.h b/include/sqlpp11/bad_statement.h index 1151f287..03635a28 100644 --- a/include/sqlpp11/bad_statement.h +++ b/include/sqlpp11/bad_statement.h @@ -29,13 +29,13 @@ namespace sqlpp { - struct bad_statement - { - template - bad_statement(T&&...) {} - }; + struct bad_statement + { + template + bad_statement(T&&...) + { + } + }; } #endif - - diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 7d9ddda8..032ecd34 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -38,119 +38,122 @@ namespace sqlpp { - // basic operators - template - struct basic_expression_operators - { - template - struct _is_valid_comparison_operand - { - static constexpr bool value = - (is_expression_t::value // expressions are OK - or is_multi_expression_t::value) // multi-expressions like ANY are OK for comparisons, too - and ValueType::template _is_valid_operand::value // the correct value type is required, of course - ; - }; + // basic operators + template + struct basic_expression_operators + { + template + struct _is_valid_comparison_operand + { + static constexpr bool value = + (is_expression_t::value // expressions are OK + or + is_multi_expression_t::value) // multi-expressions like ANY are OK for comparisons, too + and + ValueType::template _is_valid_operand::value // the correct value type is required, of course + ; + }; - template - equal_to_t> operator==(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); + template + equal_to_t> operator==(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); - return { *static_cast(this), {rhs{t}} }; - } + return {*static_cast(this), {rhs{t}}}; + } - template - not_equal_to_t> operator!=(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); + template + not_equal_to_t> operator!=(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); - return { *static_cast(this), {rhs{t}} }; - } + return {*static_cast(this), {rhs{t}}}; + } - template - less_than_t> operator<(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); + template + less_than_t> operator<(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); - return { *static_cast(this), rhs{t} }; - } + return {*static_cast(this), rhs{t}}; + } - template - less_equal_t> operator<=(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); + template + less_equal_t> operator<=(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); - return { *static_cast(this), rhs{t} }; - } + return {*static_cast(this), rhs{t}}; + } - template - greater_than_t> operator>(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); + template + greater_than_t> operator>(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); - return { *static_cast(this), rhs{t} }; - } + return {*static_cast(this), rhs{t}}; + } - template - greater_equal_t> operator>=(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); + template + greater_equal_t> operator>=(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_comparison_operand::value, "invalid rhs operand in comparison"); - return { *static_cast(this), rhs{t} }; - } + return {*static_cast(this), rhs{t}}; + } - is_null_t is_null() const - { - return { *static_cast(this) }; - } + is_null_t is_null() const + { + return {*static_cast(this)}; + } - is_not_null_t is_not_null() const - { - return { *static_cast(this) }; - } + is_not_null_t is_not_null() const + { + return {*static_cast(this)}; + } - sort_order_t asc() const - { - return { *static_cast(this) }; - } + sort_order_t asc() const + { + return {*static_cast(this)}; + } - sort_order_t desc() const - { - return { *static_cast(this) }; - } + sort_order_t desc() const + { + return {*static_cast(this)}; + } - // Hint: use value_list wrapper for containers... - template - in_t...> in(T... t) const - { - static_assert(logic::all_t<_is_valid_comparison_operand>::value...>::value, "at least one operand of in() is not valid"); - return { *static_cast(this), wrap_operand_t{t}... }; - } + // Hint: use value_list wrapper for containers... + template + in_t...> in(T... t) const + { + static_assert(logic::all_t<_is_valid_comparison_operand>::value...>::value, + "at least one operand of in() is not valid"); + return {*static_cast(this), wrap_operand_t{t}...}; + } - template - not_in_t...> not_in(T... t) const - { - static_assert(logic::all_t<_is_valid_comparison_operand>::value...>::value, "at least one operand of in() is not valid"); - return { *static_cast(this), wrap_operand_t{t}... }; - } - }; - - template - struct alias_operators - { - template - expression_alias_t as(const alias_provider&) const - { - return { *static_cast(this) }; - } - }; + template + not_in_t...> not_in(T... t) const + { + static_assert(logic::all_t<_is_valid_comparison_operand>::value...>::value, + "at least one operand of in() is not valid"); + return {*static_cast(this), wrap_operand_t{t}...}; + } + }; + template + struct alias_operators + { + template + expression_alias_t as(const alias_provider&) const + { + return {*static_cast(this)}; + } + }; } #endif diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index d9a218b4..620c5715 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -37,199 +37,197 @@ namespace sqlpp { - // boolean value type - struct boolean - { - using _traits = make_traits; - using _tag = tag::is_boolean; - using _cpp_value_type = bool; + // boolean value type + struct boolean + { + using _traits = make_traits; + using _tag = tag::is_boolean; + using _cpp_value_type = bool; - template - using _is_valid_operand = is_boolean_t; - }; + template + using _is_valid_operand = is_boolean_t; + }; - // boolean parameter type - template<> - struct parameter_value_t - { - using _value_type = boolean; // FIXME - using _cpp_value_type = typename _value_type::_cpp_value_type; + // boolean parameter type + template <> + struct parameter_value_t + { + 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>& 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>& 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 - void _bind(Target& target, size_t index) const - { - target._bind_boolean_parameter(index, &_value, _is_null); - } + template + 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 - struct expression_operators: public basic_expression_operators - { - template - using _is_valid_operand = is_valid_operand; + // boolean expression operators + template + struct expression_operators : public basic_expression_operators + { + template + using _is_valid_operand = is_valid_operand; - template - logical_and_t> operator and(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + template + logical_and_t> operator and(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); - return { *static_cast(this), rhs{t} }; - } + return {*static_cast(this), rhs{t}}; + } - template - logical_or_t> operator or(T t) const - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand"); + template + logical_or_t> operator or(T t) const + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); - return { *static_cast(this), rhs{t} }; - } + return {*static_cast(this), rhs{t}}; + } - logical_not_t operator not() const - { - return { *static_cast(this) }; - } - }; + logical_not_t operator not() const + { + return {*static_cast(this)}; + } + }; - // boolean column operators - template - struct column_operators - { - }; + // boolean column operators + template + struct column_operators + { + }; - // boolean result field - template - struct result_field_t: public result_field_methods_t> - { - static_assert(std::is_same, boolean>::value, "field type mismatch"); - using _cpp_value_type = typename boolean::_cpp_value_type; + // boolean result field + template + struct result_field_t : public result_field_methods_t> + { + static_assert(std::is_same, 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::value and not null_is_trivial_value_t::value) - { - throw exception("accessing value of NULL field"); - } - else - { - return false; - } - } - return _value; - } + if (_is_null) + { + if (enforce_null_result_treatment_t::value and not null_is_trivial_value_t::value) + { + throw exception("accessing value of NULL field"); + } + else + { + return false; + } + } + return _value; + } - template - void _bind(Target& target, size_t i) - { - target._bind_boolean_result(i, &_value, &_is_null); - } + template + 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 - inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) - { - return serialize(e, os); - } + private: + bool _is_valid; + bool _is_null; + signed char _value; + }; + template + inline std::ostream& operator<<(std::ostream& os, const result_field_t& e) + { + return serialize(e, os); + } } #endif diff --git a/include/sqlpp11/boolean_expression.h b/include/sqlpp11/boolean_expression.h index cc79e9a2..a0652103 100644 --- a/include/sqlpp11/boolean_expression.h +++ b/include/sqlpp11/boolean_expression.h @@ -32,54 +32,53 @@ namespace sqlpp { - template - struct boolean_expression_t: public expression_operators, boolean> - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; + template + struct boolean_expression_t : public expression_operators, boolean> + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; - template - boolean_expression_t(Expr expr): - _expr(expr) - { - static_assert(is_expression_t::value, "boolean_expression requires a boolean expression argument"); - static_assert(is_boolean_t::value, "boolean_expression requires a boolean expression argument"); - } + template + boolean_expression_t(Expr expr) + : _expr(expr) + { + static_assert(is_expression_t::value, "boolean_expression requires a boolean expression argument"); + static_assert(is_boolean_t::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 _expr; - }; + interpretable_t _expr; + }; - template - boolean_expression_t boolean_expression(T t) - { - using Expr = wrap_operand_t; - return {Expr{t}}; - } + template + boolean_expression_t boolean_expression(T t) + { + using Expr = wrap_operand_t; + return {Expr{t}}; + } - template - boolean_expression_t boolean_expression(const Database&, T t) - { - return boolean_expression(t); - } + template + boolean_expression_t boolean_expression(const Database&, T t) + { + return boolean_expression(t); + } - template - struct serializer_t> - { - using _serialize_check = consistent_t; - using T = boolean_expression_t; - - static Context& _(const T& t, Context& context) - { - return serialize(t._expr, context); - } - }; + template + struct serializer_t> + { + using _serialize_check = consistent_t; + using T = boolean_expression_t; + static Context& _(const T& t, Context& context) + { + return serialize(t._expr, context); + } + }; } #endif diff --git a/include/sqlpp11/char_sequence.h b/include/sqlpp11/char_sequence.h index 5d7ee1c3..88920c22 100644 --- a/include/sqlpp11/char_sequence.h +++ b/include/sqlpp11/char_sequence.h @@ -31,26 +31,28 @@ namespace sqlpp { - template struct char_sequence - { - static const char* char_ptr() - { - static char s[] = {Cs...}; - return s; - }; - }; + template + struct char_sequence + { + static const char* char_ptr() + { + static char s[] = {Cs...}; + return s; + }; + }; - template - struct make_char_sequence_impl; + template + struct make_char_sequence_impl; - template - struct make_char_sequence_impl> - { - using type = char_sequence; - }; + template + struct make_char_sequence_impl> + { + using type = char_sequence; + }; - template - using make_char_sequence = typename make_char_sequence_impl>::type; + template + using make_char_sequence = + typename make_char_sequence_impl>::type; } #endif diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 4985735e..25d86233 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -41,84 +41,81 @@ namespace sqlpp { - template - struct column_t: - public expression_operators, value_type_of>, - public column_operators, value_type_of> - { - struct _traits - { - using _value_type = value_type_of; - using _tags = detail::make_joined_set_t, typename ColumnSpec::_traits::_tags>; - }; + template + struct column_t : public expression_operators, value_type_of>, + public column_operators, value_type_of> + { + struct _traits + { + using _value_type = value_type_of; + using _tags = detail::make_joined_set_t, + typename ColumnSpec::_traits::_tags>; + }; - using _nodes = detail::type_vector<>; - using _required_tables = detail::type_set
; - using _can_be_null = column_spec_can_be_null_t; + using _nodes = detail::type_vector<>; + using _required_tables = detail::type_set
; + using _can_be_null = column_spec_can_be_null_t; - 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 - using _is_valid_operand = is_valid_operand, T>; + template + using _is_valid_operand = is_valid_operand, 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 - auto table() const -> _table - { - static_assert(is_table_t::value, "cannot call get_table for columns of a sub-selects or cte"); - return _table{}; - } + template + auto table() const -> _table + { + static_assert(is_table_t::value, "cannot call get_table for columns of a sub-selects or cte"); + return _table{}; + } - template - expression_alias_t as(const alias_provider&) const - { - return { *this }; - } + template + expression_alias_t as(const alias_provider&) const + { + return {*this}; + } - template - auto operator =(T t) const -> assignment_t> - { - using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); + template + auto operator=(T t) const -> assignment_t> + { + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *this, {rhs{t}} }; - } + return {*this, {rhs{t}}}; + } - auto operator =(null_t) const - ->assignment_t - { - static_assert(can_be_null_t::value, "column cannot be null"); - return { *this, null_t{} }; - } + auto operator=(null_t) const -> assignment_t + { + static_assert(can_be_null_t::value, "column cannot be null"); + return {*this, null_t{}}; + } - auto operator =(default_value_t) const - ->assignment_t - { - return { *this, default_value_t{} }; - } - }; + auto operator=(default_value_t) const -> assignment_t + { + return {*this, default_value_t{}}; + } + }; - template - struct serializer_t> - { - using _serialize_check = consistent_t; - using T = column_t; - - static Context& _(const T&, Context& context) - { - context << name_of::char_ptr() << '.' << name_of::char_ptr(); - return context; - } - }; + template + struct serializer_t> + { + using _serialize_check = consistent_t; + using T = column_t; + static Context& _(const T&, Context& context) + { + context << name_of::char_ptr() << '.' << name_of::char_ptr(); + return context; + } + }; } #endif diff --git a/include/sqlpp11/column_fwd.h b/include/sqlpp11/column_fwd.h index c6899454..6eb4415f 100644 --- a/include/sqlpp11/column_fwd.h +++ b/include/sqlpp11/column_fwd.h @@ -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 - struct column_t; + template + struct column_t; } #endif diff --git a/include/sqlpp11/concat.h b/include/sqlpp11/concat.h index 5b2d3209..dba4cddc 100644 --- a/include/sqlpp11/concat.h +++ b/include/sqlpp11/concat.h @@ -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; - template - 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; + template + struct _member_t + { + T concat; + }; + }; + }; - template - struct concat_t: - public expression_operators, text>, - public alias_operators> - { - using _traits = make_traits; - using _nodes = detail::type_vector; + template + struct concat_t : public expression_operators, text>, public alias_operators> + { + using _traits = make_traits; + using _nodes = detail::type_vector; - 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; - }; + std::tuple _args; + }; - template - struct serializer_t> - { - using _serialize_check = serialize_check_of; - using T = concat_t; + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = concat_t; - 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 - auto concat(Args... args) - -> concat_t - { - static_assert(sizeof...(Args) >= 2, "concat requires two arguments at least"); - static_assert(logic::all_t>::value...>::value, "at least one non-text argument detected in concat()"); + template + auto concat(Args... args) -> concat_t + { + static_assert(sizeof...(Args) >= 2, "concat requires two arguments at least"); + static_assert(logic::all_t>::value...>::value, + "at least one non-text argument detected in concat()"); - return {args...}; - } + return {args...}; + } } #endif diff --git a/include/sqlpp11/connection.h b/include/sqlpp11/connection.h index fb405251..0b55fd52 100644 --- a/include/sqlpp11/connection.h +++ b/include/sqlpp11/connection.h @@ -29,8 +29,9 @@ namespace sqlpp { - struct connection {}; + struct connection + { + }; } #endif - diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 3d2ef33d..31353d21 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -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; - template - 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; + template + struct _member_t + { + T count; + T& operator()() + { + return count; + } + const T& operator()() const + { + return count; + } + }; + }; + }; - template - struct count_t: - public expression_operators, integral>, - public alias_operators> - { - using _traits = make_traits; + template + struct count_t : public expression_operators, integral>, + public alias_operators> + { + using _traits = make_traits; - using _nodes = detail::type_vector; - using _can_be_null = std::false_type; + using _nodes = detail::type_vector; + using _can_be_null = std::false_type; - static_assert(is_noop::value or std::is_same::value, "count() used with flag other than 'distinct'"); + static_assert(is_noop::value or std::is_same::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 - struct serializer_t> - { - using _serialize_check = serialize_check_of; - using T = count_t; + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = count_t; - static Context& _(const T& t, Context& context) - { - context << "COUNT("; - if (std::is_same::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::value) + { + serialize(Flag(), context); + context << ' '; + serialize_operand(t._expr, context); + } + else + { + serialize(t._expr, context); + } + context << ")"; + return context; + } + }; - template - auto count(T t) -> count_t> - { - static_assert(not contains_aggregate_function_t>::value, "count() cannot be used on an aggregate function"); - static_assert(is_expression_t>::value, "count() requires an expression as argument"); - return { t }; - } - - template - auto count(const distinct_t&, T t) -> count_t> - { - static_assert(not contains_aggregate_function_t>::value, "count() cannot be used on an aggregate function"); - static_assert(is_expression_t>::value, "count() requires an expression as argument"); - return { t }; - } + template + auto count(T t) -> count_t> + { + static_assert(not contains_aggregate_function_t>::value, + "count() cannot be used on an aggregate function"); + static_assert(is_expression_t>::value, "count() requires an expression as argument"); + return {t}; + } + template + auto count(const distinct_t&, T t) -> count_t> + { + static_assert(not contains_aggregate_function_t>::value, + "count() cannot be used on an aggregate function"); + static_assert(is_expression_t>::value, "count() requires an expression as argument"); + return {t}; + } } #endif diff --git a/include/sqlpp11/cte.h b/include/sqlpp11/cte.h index bc971bed..74bb7a1c 100644 --- a/include/sqlpp11/cte.h +++ b/include/sqlpp11/cte.h @@ -40,222 +40,226 @@ namespace sqlpp { - template - struct cte_union_t - { - using _nodes = detail::type_vector<>; - using _required_ctes = detail::make_joined_set_t, required_ctes_of>; - using _parameters = detail::type_vector_cat_t, parameters_of>; + template + struct cte_union_t + { + using _nodes = detail::type_vector<>; + using _required_ctes = detail::make_joined_set_t, required_ctes_of>; + using _parameters = detail::type_vector_cat_t, parameters_of>; - 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 - struct serializer_t> - { - using _serialize_check = serialize_check_of; - using T = cte_union_t; + // Interpreters + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = cte_union_t; - 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 - struct cte_t; + template + struct cte_t; - template - struct cte_ref_t; + template + struct cte_ref_t; - template - auto from_table(cte_t) -> cte_ref_t - { - return cte_ref_t{}; - } + template + auto from_table(cte_t) -> cte_ref_t + { + return cte_ref_t{}; + } - template - struct from_table_impl> - { - using type = cte_ref_t; - }; + template + struct from_table_impl> + { + using type = cte_ref_t; + }; + template + struct cte_column_spec_t + { + using _alias_t = typename FieldSpec::_alias_t; - template - struct cte_column_spec_t - { - using _alias_t = typename FieldSpec::_alias_t; + using _traits = make_traits, + tag::must_not_insert, + tag::must_not_update, + tag_if::value>>; + }; - using _traits = make_traits, - tag::must_not_insert, - tag::must_not_update, - tag_if::value> - >; - }; + template + struct make_cte_impl + { + using type = void; + }; - template - struct make_cte_impl - { - using type = void; - }; + template + struct make_cte_impl> + { + using type = cte_t; + }; - template - struct make_cte_impl> - { - using type = cte_t; - }; + template + using make_cte_t = typename make_cte_impl>::type; - template - using make_cte_t = typename make_cte_impl>::type; + template + struct cte_t + : public member_t, column_t>>... + { + using _traits = make_traits; // FIXME: is table? really? + using _nodes = detail::type_vector<>; + using _required_ctes = detail::make_joined_set_t, detail::type_set>; + using _parameters = parameters_of; - template - struct cte_t: public member_t, column_t>>... - { - using _traits = make_traits; // FIXME: is table? really? - using _nodes = detail::type_vector<>; - using _required_ctes = detail::make_joined_set_t, detail::type_set>; - using _parameters = parameters_of; + using _alias_t = typename AliasProvider::_alias_t; + constexpr static bool _is_recursive = detail::is_element_of>::value; - using _alias_t = typename AliasProvider::_alias_t; - constexpr static bool _is_recursive = detail::is_element_of>::value; + using _column_tuple_t = std::tuple>...>; - using _column_tuple_t = std::tuple>...>; + template + using _check = logic::all_t::value...>; - template - using _check = logic::all_t::value...>; + using _result_row_t = result_row_t; - using _result_row_t = result_row_t; + template + auto union_distinct(Rhs rhs) const -> + typename std::conditional<_check::value, + cte_t, FieldSpecs...>, + bad_statement>::type + { + static_assert(is_statement_t::value, "argument of union call has to be a statement"); + static_assert(has_policy_t::value, "argument of union call has to be a select"); + static_assert(has_result_row_t::value, "argument of a union has to be a (complete) select statement"); - template - auto union_distinct(Rhs rhs) const - -> typename std::conditional<_check::value, cte_t, FieldSpecs...>, bad_statement>::type - { - static_assert(is_statement_t::value, "argument of union call has to be a statement"); - static_assert(has_policy_t::value, "argument of union call has to be a select"); - static_assert(has_result_row_t::value, "argument of a union has to be a (complete) select statement"); + static_assert(std::is_same<_result_row_t, get_result_row_t>::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>::value, "both select statements in a union have to have the same result columns (type and name)"); + return _union_impl(_check{}, rhs); + } - return _union_impl(_check{}, rhs); - } + template + auto union_all(Rhs rhs) const -> + typename std::conditional<_check::value, + cte_t, FieldSpecs...>, + bad_statement>::type + { + static_assert(is_statement_t::value, "argument of union call has to be a statement"); + static_assert(has_policy_t::value, "argument of union call has to be a select"); + static_assert(has_result_row_t::value, "argument of a union has to be a (complete) select statement"); - template - auto union_all(Rhs rhs) const - -> typename std::conditional<_check::value, cte_t, FieldSpecs...>, bad_statement>::type - { - static_assert(is_statement_t::value, "argument of union call has to be a statement"); - static_assert(has_policy_t::value, "argument of union call has to be a select"); - static_assert(has_result_row_t::value, "argument of a union has to be a (complete) select statement"); + static_assert(std::is_same<_result_row_t, get_result_row_t>::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>::value, "both select statements in a union have to have the same result columns (type and name)"); + return _union_impl(_check{}, rhs); + } - return _union_impl(_check{}, rhs); - } + private: + template + auto _union_impl(const std::false_type&, Rhs rhs) const -> bad_statement; - private: - template - auto _union_impl(const std::false_type&, Rhs rhs) const - -> bad_statement; + template + auto _union_impl(const std::true_type&, Rhs rhs) const + -> cte_t, FieldSpecs...> + { + return cte_union_t{_statement, rhs}; + } - template - auto _union_impl(const std::true_type&, Rhs rhs) const - -> cte_t, FieldSpecs...> - { - return cte_union_t{_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 + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = cte_t; - Statement _statement; - }; + static Context& _(const T& t, Context& context) + { + context << name_of::char_ptr() << " AS ("; + serialize(t._statement, context); + context << ")"; + return context; + } + }; - template - struct serializer_t> - { - using _serialize_check = serialize_check_of; - using T = cte_t; + // 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 + struct cte_ref_t + { + using _traits = make_traits; // FIXME: is table? really? + using _nodes = detail::type_vector<>; + using _required_ctes = detail::make_type_set_t; + using _provided_tables = detail::type_set; - static Context& _(const T& t, Context& context) - { - context << name_of::char_ptr() << " AS ("; - serialize(t._statement, context); - context << ")"; - return context; - } - }; + using _alias_t = typename AliasProvider::_alias_t; + template + auto as(Statement statement) -> make_cte_t + { + static_assert(required_tables_of::size::value == 0, + "common table expression must not use unknown tables"); + static_assert(not detail::is_element_of>::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>::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 - struct cte_ref_t - { - using _traits = make_traits; // FIXME: is table? really? - using _nodes = detail::type_vector<>; - using _required_ctes = detail::make_type_set_t; - using _provided_tables = detail::type_set; + return {statement}; + } + }; - using _alias_t = typename AliasProvider::_alias_t; + template + struct serializer_t> + { + using _serialize_check = consistent_t; + using T = cte_ref_t; - template - auto as(Statement statement) - -> make_cte_t - { - static_assert(required_tables_of::size::value == 0, "common table expression must not use unknown tables"); - static_assert(not detail::is_element_of>::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>::value, "ctes must not have dynamically added columns"); - - return { statement }; - } - }; - - template - struct serializer_t> - { - using _serialize_check = consistent_t; - using T = cte_ref_t; - - static Context& _(const T&, Context& context) - { - context << name_of::char_ptr(); - return context; - } - }; - - template - auto cte(const AliasProvider&) - -> cte_ref_t - { - return {}; - } + static Context& _(const T&, Context& context) + { + context << name_of::char_ptr(); + return context; + } + }; + template + auto cte(const AliasProvider&) -> cte_ref_t + { + return {}; + } } #endif diff --git a/include/sqlpp11/custom_query.h b/include/sqlpp11/custom_query.h index 7548b255..efbe576d 100644 --- a/include/sqlpp11/custom_query.h +++ b/include/sqlpp11/custom_query.h @@ -34,111 +34,108 @@ namespace sqlpp { - template - struct custom_query_t; + template + struct custom_query_t; - namespace detail - { - template - struct custom_parts_t - { - using _custom_query_t = custom_query_t; - using _result_type_provider = detail::get_first_if; - using _result_methods_t = typename _result_type_provider::template _result_methods_t<_result_type_provider>; - }; - } + namespace detail + { + template + struct custom_parts_t + { + using _custom_query_t = custom_query_t; + using _result_type_provider = detail::get_first_if; + using _result_methods_t = typename _result_type_provider::template _result_methods_t<_result_type_provider>; + }; + } - template - struct custom_query_t: - private detail::custom_parts_t::_result_methods_t - { - using _methods_t = typename detail::custom_parts_t::_result_methods_t; - using _traits = make_traits; - using _nodes = detail::type_vector; + template + struct custom_query_t : private detail::custom_parts_t::_result_methods_t + { + using _methods_t = typename detail::custom_parts_t::_result_methods_t; + using _traits = make_traits; + using _nodes = detail::type_vector; - using _parameter_check = typename std::conditional>::value == 0, - consistent_t, assert_no_parameters_t>::type; - using _run_check = detail::get_first_if; - using _prepare_check = consistent_t; + using _parameter_check = + typename std::conditional>::value == 0, + consistent_t, + assert_no_parameters_t>::type; + using _run_check = detail::get_first_if; + 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) - {} + custom_query_t(std::tuple 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 - auto _run(Db& db) const -> decltype(std::declval<_methods_t>()._run(db, *this)) - { - _run_check::_(); - return _methods_t::_run(db, *this); - } + template + auto _run(Db& db) const -> decltype(std::declval<_methods_t>()._run(db, *this)) + { + _run_check::_(); + return _methods_t::_run(db, *this); + } - template - auto _prepare(Db& db) const -> decltype(std::declval<_methods_t>()._prepare(db, *this)) - { - _prepare_check::_(); - return _methods_t::_prepare(db, *this); - } + template + 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>::value; - } + static constexpr size_t _get_static_no_of_parameters() + { + return std::tuple_size>::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 - auto with_result_type_of(Part part) - -> custom_query_t - { - return {tuple_cat(std::make_tuple(part), _parts)}; - } + template + auto with_result_type_of(Part part) -> custom_query_t + { + return {tuple_cat(std::make_tuple(part), _parts)}; + } - std::tuple _parts; - }; + std::tuple _parts; + }; - template - struct serializer_t> - { - using _serialize_check = serialize_check_of; - using T = custom_query_t; + template + struct serializer_t> + { + using _serialize_check = serialize_check_of; + using T = custom_query_t; - 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 - auto custom_query(Parts... parts) - -> custom_query_t...> - { - static_assert(sizeof...(Parts) > 0, "custom query requires at least one argument"); - return custom_query_t...>(parts...); - } + template + auto custom_query(Parts... parts) -> custom_query_t...> + { + static_assert(sizeof...(Parts) > 0, "custom query requires at least one argument"); + return custom_query_t...>(parts...); + } - template - auto dynamic_custom_query(const Database&, Parts... parts) - -> custom_query_t...> - { - static_assert(sizeof...(Parts) > 0, "custom query requires at least one query argument"); - static_assert(std::is_base_of::value, "Invalid database parameter"); + template + auto dynamic_custom_query(const Database&, Parts... parts) -> custom_query_t...> + { + static_assert(sizeof...(Parts) > 0, "custom query requires at least one query argument"); + static_assert(std::is_base_of::value, "Invalid database parameter"); - return custom_query_t...>(parts...); - } + return custom_query_t...>(parts...); + } } #endif diff --git a/include/sqlpp11/default_value.h b/include/sqlpp11/default_value.h index da9b5dae..bee70bb2 100644 --- a/include/sqlpp11/default_value.h +++ b/include/sqlpp11/default_value.h @@ -31,29 +31,31 @@ namespace sqlpp { - struct default_value_t - { - using _traits = make_traits; - using _nodes = detail::type_vector<>; + struct default_value_t + { + using _traits = make_traits; + using _nodes = detail::type_vector<>; - static constexpr bool _is_trivial() { return false; } - }; + static constexpr bool _is_trivial() + { + return false; + } + }; - template - struct serializer_t - { - using _serialize_check = consistent_t; - using Operand = default_value_t; + template + struct serializer_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 diff --git a/include/sqlpp11/detail/copy_tuple_args.h b/include/sqlpp11/detail/copy_tuple_args.h index fdd70da6..9126ebbc 100644 --- a/include/sqlpp11/detail/copy_tuple_args.h +++ b/include/sqlpp11/detail/copy_tuple_args.h @@ -32,52 +32,59 @@ namespace sqlpp { - template - struct all_of_t; + template + struct all_of_t; - namespace detail - { - template - struct as_column_tuple - { - static std::tuple> _(T t) { return std::tuple>(auto_alias_t{t}); } - }; + namespace detail + { + template + struct as_column_tuple + { + static std::tuple> _(T t) + { + return std::tuple>(auto_alias_t{t}); + } + }; - template - struct as_column_tuple> - { - static typename all_of_t::_column_tuple_t _(all_of_t) { return { }; } - }; + template + struct as_column_tuple> + { + static typename all_of_t::_column_tuple_t _(all_of_t) + { + return {}; + } + }; - template - struct as_column_tuple> - { - static std::tuple...> _(std::tuple t) { return t; } - }; + template + struct as_column_tuple> + { + static std::tuple...> _(std::tuple t) + { + return t; + } + }; - template class Target, typename First, typename T> - struct copy_tuple_args_impl - { - static_assert(wrong_t::value, "copy_tuple_args must be called with a tuple"); - }; + template