From f6ae27b0fe18f288dee803d209f7d5d68c382022 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 17 Aug 2014 20:45:27 +0200 Subject: [PATCH 01/52] Made "where" non-mandatory if there are no tables involved. --- include/sqlpp11/where.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index cd2b924b..dfcf0260 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -181,7 +181,7 @@ namespace sqlpp }; // NO WHERE YET - template + template struct no_where_t { using _traits = make_traits; @@ -224,7 +224,9 @@ namespace sqlpp static void _check_consistency() { - static_assert(Required ? wrong_t<_methods_t>::value : true, "where expression required, e.g. where(true)"); + static constexpr bool _tables_provided = (Policies::_all_provided_tables::size::value > 0); + static constexpr bool _required = WhereRequired and _tables_provided; + static_assert(not _required, "where expression required, e.g. where(true)"); } template From d0d5e94bf193f1edc00c0200a847973b20b3bc33 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 18 Aug 2014 10:46:24 +0200 Subject: [PATCH 02/52] Added eval function for both strings and expressions. eval wraps whatever you give to it into a select call, sends it to the database and returns the value as a result field. --- include/sqlpp11/eval.h | 62 ++++++++++++++++++++++++++++ include/sqlpp11/functions.h | 42 ++----------------- include/sqlpp11/result_field.h | 2 +- include/sqlpp11/verbatim.h | 75 ++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 40 deletions(-) create mode 100644 include/sqlpp11/eval.h create mode 100644 include/sqlpp11/verbatim.h diff --git a/include/sqlpp11/eval.h b/include/sqlpp11/eval.h new file mode 100644 index 00000000..116b19f0 --- /dev/null +++ b/include/sqlpp11/eval.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013-2014, 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 + * 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. + */ + +#ifndef SQLPP_EVAL_H +#define SQLPP_EVAL_H + +#include +#include +#include +#include + +namespace sqlpp +{ + template + struct eval_t + { + static_assert(is_database::value, "Db parameter of eval has to be a database connection"); + static_assert(is_expression_t::value, "Expression parameter of eval has to be an sqlpp expression or a string"); + static_assert(required_tables_of::size::value == 0, "Expression cannot be used in eval because it requires tables"); + using _name_type = alias::a_t::_name_t; + using _value_type = value_type_of; + using _field_spec = field_spec_t<_name_type, _value_type, true, false>; + using type = result_field_t<_value_type, Db, _field_spec>; + }; + + template::value, int>::type = 0> + auto eval(Db& db, Expr expr) -> typename eval_t::type + { + return db(select(expr.as(alias::a))).front().a; + } + + template + auto eval(Db& db, std::string sql_code) -> decltype(eval(db, verbatim(sql_code))) + { + return eval(db, verbatim(sql_code)); + } +} + +#endif diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 65fabab0..ca32b9b4 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -41,8 +41,10 @@ #include #include #include -#include // Csaba Csoma suggests: unsafe_sql instead of verbatim +#include // Csaba Csoma suggests: unsafe_sql instead of verbatim +#include #include +#include namespace sqlpp { @@ -53,44 +55,6 @@ namespace sqlpp return { t }; } - template // Csaba Csoma suggests: unsafe_sql instead of verbatim - struct verbatim_t: public ValueType::template expression_operators>, - public alias_operators> - { - using _traits = make_traits; - struct _recursive_traits : public make_recursive_traits<> - { - using _can_be_null = std::true_type; // since we do not know what's going on inside the verbatim, we assume it can be null - }; - - verbatim_t(std::string verbatim): _verbatim(verbatim) {} - verbatim_t(const verbatim_t&) = default; - verbatim_t(verbatim_t&&) = default; - verbatim_t& operator=(const verbatim_t&) = default; - verbatim_t& operator=(verbatim_t&&) = default; - ~verbatim_t() = default; - - std::string _verbatim; - }; - - template - struct serializer_t> - { - using T = verbatim_t; - - static Context& _(const T& t, Context& context) - { - context << t._verbatim; - return context; - } - }; - - template - auto verbatim(StringType s) -> verbatim_t - { - return { s }; - } - template auto flatten(const Expression& exp, Db& db) -> verbatim_t> { diff --git a/include/sqlpp11/result_field.h b/include/sqlpp11/result_field.h index e78b3938..476ca3ea 100644 --- a/include/sqlpp11/result_field.h +++ b/include/sqlpp11/result_field.h @@ -32,7 +32,7 @@ namespace sqlpp { - template + template struct result_field_t { static_assert(wrong_t::value, "Missing specialization for result_field_t"); diff --git a/include/sqlpp11/verbatim.h b/include/sqlpp11/verbatim.h new file mode 100644 index 00000000..a148519b --- /dev/null +++ b/include/sqlpp11/verbatim.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013-2014, 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 + * 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. + */ + +#ifndef SQLPP_VERBATIM_H +#define SQLPP_VERBATIM_H + +#include +#include + +namespace sqlpp +{ + template // Csaba Csoma suggests: unsafe_sql instead of verbatim + struct verbatim_t: public ValueType::template expression_operators>, + public alias_operators> + { + using _traits = make_traits; + struct _recursive_traits : public make_recursive_traits<> + { + using _can_be_null = std::true_type; // since we do not know what's going on inside the verbatim, we assume it can be null + }; + + verbatim_t(std::string verbatim): _verbatim(verbatim) {} + verbatim_t(const verbatim_t&) = default; + verbatim_t(verbatim_t&&) = default; + verbatim_t& operator=(const verbatim_t&) = default; + verbatim_t& operator=(verbatim_t&&) = default; + ~verbatim_t() = default; + + std::string _verbatim; + }; + + template + struct serializer_t> + { + using T = verbatim_t; + + static Context& _(const T& t, Context& context) + { + context << t._verbatim; + return context; + } + }; + + template + auto verbatim(StringType s) -> verbatim_t + { + return { s }; + } + +} + +#endif From 13c1b5d8f3da48cad2e81edb01457c3be1a64286 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 18 Aug 2014 15:09:27 +0200 Subject: [PATCH 03/52] Fix to make sqlpp11 compile with clang-3.1 --- include/sqlpp11/select_column_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index f986a6fd..b2609987 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -310,7 +310,7 @@ namespace sqlpp { _statement_t::_check_consistency(); - return {{}, get_dynamic_names(), db.prepare_select(_get_statement())}; + return {make_parameter_list_t<_statement_t>{}, get_dynamic_names(), db.prepare_select(_get_statement())}; } }; From f859f7fe4a95d4261c9a526d4ad9eb6410a80220 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 18 Aug 2014 19:17:59 +0200 Subject: [PATCH 04/52] Added must_not_update-test --- test_constraints/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test_constraints/CMakeLists.txt b/test_constraints/CMakeLists.txt index bdb60f10..6b4693d5 100644 --- a/test_constraints/CMakeLists.txt +++ b/test_constraints/CMakeLists.txt @@ -22,10 +22,10 @@ function(test_constraint name pattern) add_dependencies(test_sqlpp_constraints test_${name}) -endfunction(testconstraint) - +endfunction(test_constraint) test_constraint(no_conversion_operator_if_null_not_trivial "int i = row.alpha") test_constraint(require_insert "required column is missing") test_constraint(must_not_insert "one assignment is prohibited") +test_constraint(must_not_update "one assignment is prohibited") From e5e97d10b66fa6e8dcb3ee12303d6a2dd8cb559d Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 18 Aug 2014 21:10:58 +0200 Subject: [PATCH 05/52] Added alias operators to wrapped value operands --- include/sqlpp11/basic_expression_operators.h | 2 +- include/sqlpp11/wrap_operand.h | 17 ++++----- include/sqlpp11/wrap_operand_fwd.h | 40 ++++++++++++++++++++ tests/SelectTest.cpp | 2 + 4 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 include/sqlpp11/wrap_operand_fwd.h diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 710ea844..fc54a876 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include namespace sqlpp diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index ffab6e94..f4b28022 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -28,8 +28,10 @@ #define SQLPP_DETAIL_WRAP_OPERAND_H #include +#include #include #include +#include namespace sqlpp { @@ -38,7 +40,7 @@ namespace sqlpp struct floating_point; struct text; - struct boolean_operand + struct boolean_operand: public alias_operators { using _traits = make_traits<::sqlpp::boolean, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; @@ -76,7 +78,7 @@ namespace sqlpp } }; - struct integral_operand + struct integral_operand: public alias_operators { using _traits = make_traits<::sqlpp::integral, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; @@ -115,7 +117,7 @@ namespace sqlpp }; - struct floating_point_operand + struct floating_point_operand: public alias_operators { using _traits = make_traits<::sqlpp::floating_point, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; @@ -153,7 +155,7 @@ namespace sqlpp } }; - struct text_operand + struct text_operand: public alias_operators { using _traits = make_traits<::sqlpp::text, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; using _recursive_traits = make_recursive_traits<>; @@ -191,7 +193,7 @@ namespace sqlpp } }; - template + template struct wrap_operand { using type = T; @@ -221,11 +223,6 @@ namespace sqlpp using type = text_operand; }; - // FIXME: Need to allow std::ref arguments - - template - using wrap_operand_t = typename wrap_operand::type; - } #endif diff --git a/include/sqlpp11/wrap_operand_fwd.h b/include/sqlpp11/wrap_operand_fwd.h new file mode 100644 index 00000000..f7f60def --- /dev/null +++ b/include/sqlpp11/wrap_operand_fwd.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013-2014, 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 + * 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. + */ + +#ifndef SQLPP_DETAIL_WRAP_OPERAND_FWD_H +#define SQLPP_DETAIL_WRAP_OPERAND_FWD_H + +namespace sqlpp +{ + template + struct wrap_operand; + + template + using wrap_operand_t = typename wrap_operand::type; + +} + +#endif diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 1e97562c..9fd040af 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -92,5 +92,7 @@ int main() printer.reset(); std::cerr << serialize(stat, printer).str() << std::endl; + select(sqlpp::value(7).as(t.alpha)); + return 0; } From 73973f0f488bb81ea51f622c37cd9b83eec9146a Mon Sep 17 00:00:00 2001 From: Johan Date: Wed, 20 Aug 2014 21:58:57 +0200 Subject: [PATCH 06/52] Fix cygwin-gcc and cmake problems Fixed warning in CMake Fixed problem with tuples creation Fixed problem of stream copy constructor usage --- CMakeLists.txt | 4 ++++ include/sqlpp11/insert_value_list.h | 2 +- test_constraints/CMakeLists.txt | 2 +- tests/MockDb.h | 6 ++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32fd43cc..556cdf06 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,10 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. cmake_minimum_required(VERSION 2.6) + +# Cygwin does not define WIN32 and warn if not use with this flag +set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required + project (sqlpp11) enable_testing() diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 768e789b..fdf34fe5 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -105,7 +105,7 @@ namespace sqlpp insert_list_data_t(Assignments... assignments): _assignments(assignments...), _columns({assignments._lhs}...), - _values({assignments._rhs}...) + _values(assignments._rhs...) {} insert_list_data_t(const insert_list_data_t&) = default; diff --git a/test_constraints/CMakeLists.txt b/test_constraints/CMakeLists.txt index bdb60f10..4870883d 100644 --- a/test_constraints/CMakeLists.txt +++ b/test_constraints/CMakeLists.txt @@ -22,7 +22,7 @@ function(test_constraint name pattern) add_dependencies(test_sqlpp_constraints test_${name}) -endfunction(testconstraint) +endfunction(test_constraint) test_constraint(no_conversion_operator_if_null_not_trivial "int i = row.alpha") diff --git a/tests/MockDb.h b/tests/MockDb.h index d6a55365..5ef1f110 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -41,6 +41,12 @@ struct MockDbT: public sqlpp::connection { std::ostringstream _os; + _serializer_context_t() = default; + _serializer_context_t(const _serializer_context_t& rhs) + { + _os << rhs._os.str(); + } + std::string str() const { return _os.str(); From a235f3ddae4302ab0967dea9cef64c27d2086f65 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 21 Aug 2014 11:09:50 +0200 Subject: [PATCH 07/52] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f25797ba..0b8d6ebe 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ sqlpp11 makes heavy use of C++11 and requires a recent compiler and STL. The fol * clang-3.2 on Ubuntu-12.4 * clang-3.4 on Ubuntu-12.4 * g++-4.8 on Ubuntu-12.4 + * g++-4.8 on cygwin 64bit * g++-4.9 on Debian Unstable __Database Connector:__ From 4974d136005ec9ab6f62e10e6ce5e514a8d0d678 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 21 Aug 2014 11:44:07 +0200 Subject: [PATCH 08/52] Fixed all_of(table_alias) --- include/sqlpp11/table_alias.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index 7cc58a9f..821412f6 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -54,7 +54,7 @@ namespace sqlpp static_assert(required_tables_of::size::value == 0, "table aliases must not depend on external tables"); using _name_t = typename AliasProvider::_name_t; - using _column_tuple_t = std::tuple...>; + using _column_tuple_t = std::tuple...>; table_alias_t(Table table): _table(table) From a9339b54ad462462b837c3eeb8d6dad301bcf719 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 21 Aug 2014 13:00:40 +0200 Subject: [PATCH 09/52] Fixed all_of(alias_table) For real this time, I hope :-) --- include/sqlpp11/table_alias.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index 821412f6..94ea6716 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -54,7 +54,7 @@ namespace sqlpp static_assert(required_tables_of
::size::value == 0, "table aliases must not depend on external tables"); using _name_t = typename AliasProvider::_name_t; - using _column_tuple_t = std::tuple...>; + using _column_tuple_t = std::tuple...>; table_alias_t(Table table): _table(table) From 10853abb0a8a03525c712087b8bf211752388366 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 21 Aug 2014 13:21:27 +0200 Subject: [PATCH 10/52] fixed static_assert message wording --- include/sqlpp11/column.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 9f9a089a..1ecbeb73 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -90,7 +90,7 @@ namespace sqlpp auto operator =(T t) const -> assignment_t> { using rhs = wrap_operand_t; - static_assert(_is_valid_operand::value, "invalid rhs operand assignment operand"); + static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); return { *this, {rhs{t}} }; } From 15c778844b7be6fa2a48262ca4d6152d265e5001 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 21 Aug 2014 13:21:49 +0200 Subject: [PATCH 11/52] Added a few missing const qualifiers --- include/sqlpp11/basic_expression_operators.h | 6 +++--- include/sqlpp11/table.h | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index fc54a876..7c7d3ec8 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -115,12 +115,12 @@ namespace sqlpp return { *static_cast(this) }; } - sort_order_t asc() + sort_order_t asc() const { return { *static_cast(this) }; } - sort_order_t desc() + sort_order_t desc() const { return { *static_cast(this) }; } @@ -145,7 +145,7 @@ namespace sqlpp struct alias_operators { template - expression_alias_t as(const alias_provider&) + expression_alias_t as(const alias_provider&) const { return { *static_cast(this) }; } diff --git a/include/sqlpp11/table.h b/include/sqlpp11/table.h index 52f747f3..06a1c2f5 100644 --- a/include/sqlpp11/table.h +++ b/include/sqlpp11/table.h @@ -62,31 +62,31 @@ namespace sqlpp template - join_t join(T t) + join_t join(T t) const { return { *static_cast(this), t }; } template - join_t inner_join(T t) + join_t inner_join(T t) const { return { *static_cast(this), t }; } template - join_t outer_join(T t) + join_t outer_join(T t) const { return { *static_cast(this), t }; } template - join_t left_outer_join(T t) + join_t left_outer_join(T t) const { return { *static_cast(this), t }; } template - join_t right_outer_join(T t) + join_t right_outer_join(T t) const { return { *static_cast(this), t }; } From fd054d8a5aa0440ab12cdb6501470588eb7f6afb Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 22 Aug 2014 12:26:48 +0200 Subject: [PATCH 12/52] Fixed operators += et al --- include/sqlpp11/integral.h | 8 ++++---- include/sqlpp11/text.h | 2 +- tests/MockDb.h | 4 ---- tests/UpdateTest.cpp | 2 ++ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index ecb9b14d..0e509bbf 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -205,7 +205,7 @@ namespace sqlpp using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; + return { *static_cast(this), {{*static_cast(this), rhs{t}}}}; } template @@ -214,7 +214,7 @@ namespace sqlpp using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; + return { *static_cast(this), {{*static_cast(this), rhs{t}}}}; } template @@ -223,7 +223,7 @@ namespace sqlpp using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; + return { *static_cast(this), {{*static_cast(this), rhs{t}}}}; } template @@ -232,7 +232,7 @@ namespace sqlpp using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; + return { *static_cast(this), {{*static_cast(this), rhs{t}}}}; } }; }; diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index d707d5a1..7dda39a8 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -150,7 +150,7 @@ namespace sqlpp using rhs = wrap_operand_t; static_assert(_is_valid_operand::value, "invalid rhs assignment operand"); - return { *static_cast(this), { *static_cast(this), rhs{t} } }; + return { *static_cast(this), concat_t>{ *static_cast(this), rhs{t} } }; } }; }; diff --git a/tests/MockDb.h b/tests/MockDb.h index 5ef1f110..0586c04c 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -165,8 +165,6 @@ struct MockDbT: public sqlpp::connection template size_t run_prepared_insert(const PreparedInsert& x) { - _serializer_context_t context; - ::sqlpp::serialize(x, context); return 0; } @@ -181,8 +179,6 @@ struct MockDbT: public sqlpp::connection template result_t run_prepared_select(PreparedSelect& x) { - _serializer_context_t context; - ::sqlpp::serialize(x, context); return {}; } diff --git a/tests/UpdateTest.cpp b/tests/UpdateTest.cpp index 04f73024..e12224ec 100644 --- a/tests/UpdateTest.cpp +++ b/tests/UpdateTest.cpp @@ -68,6 +68,8 @@ int main() db(update(t).set(t.delta = sqlpp::null).where(true)); db(update(t).set(t.delta = sqlpp::default_value).where(true)); + db(update(t).set(t.delta += t.alpha * 2, t.beta += " and cake").where(true)); + return 0; } From 404a8301a919664a3c7b367cd91376549f73c8ed Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 22 Aug 2014 22:18:04 +0200 Subject: [PATCH 13/52] Added missing file --- test_constraints/must_not_update.cpp | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test_constraints/must_not_update.cpp diff --git a/test_constraints/must_not_update.cpp b/test_constraints/must_not_update.cpp new file mode 100644 index 00000000..42f9ac04 --- /dev/null +++ b/test_constraints/must_not_update.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2013-2014, 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 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. + */ + +#include "Sample.h" +#include "MockDb.h" +#include + +MockDb db; + +int main() +{ + test::TabBar t; + + update(t).set(t.alpha = 7, t.gamma = false, t.beta = "alpha must not be set"); +} From e88a868d067dcfd76ec9a8af07aca890fa02dbdf Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 24 Aug 2014 09:34:01 +0200 Subject: [PATCH 14/52] Started to integrate with Travis CI --- .travis.yml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..24216e08 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,48 @@ +language: cpp + +os: + - linux + - osx + +compiler: + - clang + - gcc + +matrix: + # This excludes OSX builds from the build matrix for gcc + exclude: + - os: osx + compiler: gcc + +notifications: + email: + on_success: change + on_failure: always + +before_install: + - "if [ $CC = 'gcc' ]; then export CXX=g++; fi" + - "if [ $CC = 'clang' ]; then export CXX=clang++; fi" + - "if [ ${TRAVIS_OS_NAME:-'linux'} = 'osx' ]; then brew install cmake; fi" + # Install cpp-coveralls for reporting test coverage under only linux, see https://github.com/eddyxu/cpp-coveralls + #- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then sudo pip install cpp-coveralls; fi" + +install: + - "mkdir -p $TRAVIS_BUILD_DIR/build/scripts" + - "cd $TRAVIS_BUILD_DIR/build/scripts" + # Enable test coverage for travis-ci build + #- "cmake $TRAVIS_BUILD_DIR/src -DNTA_COV_ENABLED=ON" + - "cmake $TRAVIS_BUILD_DIR/src" + +script: + - "cd $TRAVIS_BUILD_DIR/build/scripts" + - "make -j3" + # test compile-time constraints + - "make test_sqlpp_constraints" + +after_success: + - "cd $TRAVIS_BUILD_DIR" + # Send test coverage report to http://coveralls.io under only linux + # - "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then coveralls --exclude external --exclude doc --exclude src/test; fi" + + + From 5188a82980a4f26e7af334a5884b830461d30eda Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 24 Aug 2014 09:34:01 +0200 Subject: [PATCH 15/52] Started to integrate with Travis CI --- .travis.yml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..24216e08 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,48 @@ +language: cpp + +os: + - linux + - osx + +compiler: + - clang + - gcc + +matrix: + # This excludes OSX builds from the build matrix for gcc + exclude: + - os: osx + compiler: gcc + +notifications: + email: + on_success: change + on_failure: always + +before_install: + - "if [ $CC = 'gcc' ]; then export CXX=g++; fi" + - "if [ $CC = 'clang' ]; then export CXX=clang++; fi" + - "if [ ${TRAVIS_OS_NAME:-'linux'} = 'osx' ]; then brew install cmake; fi" + # Install cpp-coveralls for reporting test coverage under only linux, see https://github.com/eddyxu/cpp-coveralls + #- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then sudo pip install cpp-coveralls; fi" + +install: + - "mkdir -p $TRAVIS_BUILD_DIR/build/scripts" + - "cd $TRAVIS_BUILD_DIR/build/scripts" + # Enable test coverage for travis-ci build + #- "cmake $TRAVIS_BUILD_DIR/src -DNTA_COV_ENABLED=ON" + - "cmake $TRAVIS_BUILD_DIR/src" + +script: + - "cd $TRAVIS_BUILD_DIR/build/scripts" + - "make -j3" + # test compile-time constraints + - "make test_sqlpp_constraints" + +after_success: + - "cd $TRAVIS_BUILD_DIR" + # Send test coverage report to http://coveralls.io under only linux + # - "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then coveralls --exclude external --exclude doc --exclude src/test; fi" + + + From 9f78ec9ee32654fd7e56f22cbda05f6142975bdc Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 24 Aug 2014 09:37:13 +0200 Subject: [PATCH 16/52] Limit Travis CI to master and develop --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 24216e08..38c0324a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,11 @@ matrix: - os: osx compiler: gcc +branches: + only: + - master + - develop + notifications: email: on_success: change From cadc7bdb3ab8513d96e4a72a426b830035222713 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 24 Aug 2014 09:57:17 +0200 Subject: [PATCH 17/52] Updated credits a bit --- CREDITS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CREDITS b/CREDITS index 6ad7db8e..3675cef0 100644 --- a/CREDITS +++ b/CREDITS @@ -7,8 +7,12 @@ This library evolved through several stages and would probably not exist without * Peter Knoblach: Initial ideas * Ulrich Küttler: Feedback and extensions + * Metafeed GmbH: Production code using a forerunner version * PPRO Financial Ltd: Production code using sqlpp11 and a forerunner version + * The boost community: Invaluable suggestions and critiques + + * Meeting C++ Munich: Hosted the first talk about sqlpp11 If you miss your name of this list, please let me know. From 411022469f34c3f90bb90041993a417cb7fbb282 Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 24 Aug 2014 09:59:55 +0200 Subject: [PATCH 18/52] Bugfix in Travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 24216e08..2088c77a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ install: - "cd $TRAVIS_BUILD_DIR/build/scripts" # Enable test coverage for travis-ci build #- "cmake $TRAVIS_BUILD_DIR/src -DNTA_COV_ENABLED=ON" - - "cmake $TRAVIS_BUILD_DIR/src" + - "cmake $TRAVIS_BUILD_DIR" script: - "cd $TRAVIS_BUILD_DIR/build/scripts" From 3c3abfab41193a39ed831552a3787b68ab6b7729 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sun, 24 Aug 2014 10:20:49 +0200 Subject: [PATCH 19/52] Exclude clang from Travis and use g++-4.8 clang is missing libc++ (might add that later) --- .travis.yml | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2088c77a..904ed15a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,35 +2,23 @@ language: cpp os: - linux - - osx compiler: - - clang + # - clang # disabled clang due to missing libc++ - gcc -matrix: - # This excludes OSX builds from the build matrix for gcc - exclude: - - os: osx - compiler: gcc - notifications: email: on_success: change on_failure: always before_install: - - "if [ $CC = 'gcc' ]; then export CXX=g++; fi" - - "if [ $CC = 'clang' ]; then export CXX=clang++; fi" - - "if [ ${TRAVIS_OS_NAME:-'linux'} = 'osx' ]; then brew install cmake; fi" - # Install cpp-coveralls for reporting test coverage under only linux, see https://github.com/eddyxu/cpp-coveralls - #- "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then sudo pip install cpp-coveralls; fi" + - if [ "$CXX" == "g++" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi + - if [ "$CXX" == "g++" ]; then sudo apt-get install -qq g++-4.8; fi install: - "mkdir -p $TRAVIS_BUILD_DIR/build/scripts" - "cd $TRAVIS_BUILD_DIR/build/scripts" - # Enable test coverage for travis-ci build - #- "cmake $TRAVIS_BUILD_DIR/src -DNTA_COV_ENABLED=ON" - "cmake $TRAVIS_BUILD_DIR" script: @@ -39,10 +27,3 @@ script: # test compile-time constraints - "make test_sqlpp_constraints" -after_success: - - "cd $TRAVIS_BUILD_DIR" - # Send test coverage report to http://coveralls.io under only linux - # - "if [ ${TRAVIS_OS_NAME:-'linux'} = 'linux' ]; then coveralls --exclude external --exclude doc --exclude src/test; fi" - - - From facff35d0a1fcc2529019355b2c0df5692106ade Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sun, 24 Aug 2014 10:31:14 +0200 Subject: [PATCH 20/52] Next attempt to use g++-4.8 with Travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 904ed15a..0e1cef62 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,7 @@ notifications: on_failure: always before_install: - - if [ "$CXX" == "g++" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi - - if [ "$CXX" == "g++" ]; then sudo apt-get install -qq g++-4.8; fi + - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi install: - "mkdir -p $TRAVIS_BUILD_DIR/build/scripts" From 2f979ff263c012eb2757779fb84c6424c416ed7d Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sun, 24 Aug 2014 10:40:14 +0200 Subject: [PATCH 21/52] Yet another try to get Travis CI going with g++-4.8 --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0e1cef62..39ee5821 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,12 @@ notifications: on_failure: always before_install: + - sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y + - sudo apt-get update + - if [ "$CXX" = "g++" ]; then sudo apt-get install g++-4.8; fi - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi + install: - "mkdir -p $TRAVIS_BUILD_DIR/build/scripts" - "cd $TRAVIS_BUILD_DIR/build/scripts" From 342a42758ad13b5b6613bc96d396856908b44127 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sun, 24 Aug 2014 10:46:08 +0200 Subject: [PATCH 22/52] Fixed test_sqlpp_test_constraints to work with out of source build --- test_constraints/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_constraints/CMakeLists.txt b/test_constraints/CMakeLists.txt index 6b4693d5..aec592e4 100644 --- a/test_constraints/CMakeLists.txt +++ b/test_constraints/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories(${CMAKE_BINARY_DIR}/tests) +include_directories(${CMAKE_SOURCE_DIR}/tests) add_custom_target(test_sqlpp_constraints COMMAND true) From 83fd052cf5415890176f13ee97d1fabea8ba546f Mon Sep 17 00:00:00 2001 From: rbock Date: Sun, 24 Aug 2014 12:28:49 +0200 Subject: [PATCH 23/52] Fixed duplicate column detection in insert and update --- include/sqlpp11/insert_value_list.h | 2 +- include/sqlpp11/update_list.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index fdf34fe5..d80feea4 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -387,8 +387,8 @@ namespace sqlpp auto _set_impl(Assignments... assignments) -> _new_statement_t> { - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate column detected in set()"); static_assert(sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); using _column_required_tables = ::sqlpp::detail::make_joined_set_t...>; diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 1ee40173..57252940 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -193,8 +193,8 @@ namespace sqlpp auto _set_impl(Assignments... assignments) -> _new_statement_t> { - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate column detected in set()"); static_assert(::sqlpp::detail::none_t::value...>::value, "at least one assignment is prohibited by its column definition in set()"); using _column_required_tables = ::sqlpp::detail::make_joined_set_t...>; From 8d8b3580920ae33b959c97de41f8f5646ddf3b11 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 25 Aug 2014 06:05:42 +0200 Subject: [PATCH 24/52] Removed obsolete tags from value types --- include/sqlpp11/boolean.h | 2 +- include/sqlpp11/floating_point.h | 2 +- include/sqlpp11/integral.h | 2 +- include/sqlpp11/text.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index 20a663ac..848f2acf 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -40,7 +40,7 @@ namespace sqlpp // boolean value type struct boolean { - using _traits = make_traits; + using _traits = make_traits; using _tag = ::sqlpp::tag::is_boolean; using _cpp_value_type = bool; diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index 9f61c251..400eceeb 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -38,7 +38,7 @@ namespace sqlpp // floating_point value type struct floating_point { - using _traits = make_traits; + using _traits = make_traits; using _tag = ::sqlpp::tag::is_floating_point; using _cpp_value_type = double; diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 0e509bbf..feef4446 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -40,7 +40,7 @@ namespace sqlpp // integral value type struct integral { - using _traits = make_traits; + using _traits = make_traits; using _tag = ::sqlpp::tag::is_integral; using _cpp_value_type = int64_t; diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index 7dda39a8..258603aa 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -39,7 +39,7 @@ namespace sqlpp // text value type struct text { - using _traits = make_traits; + using _traits = make_traits; using _tag = ::sqlpp::tag::is_text; using _cpp_value_type = std::string; From 2c23769cdfc52c6b4d8da357af5f9168bc7d1fd6 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 25 Aug 2014 08:43:42 +0200 Subject: [PATCH 25/52] Moved operator and parameter templates out of value classes, added member template These templates are nicer when used. --- include/sqlpp11/avg.h | 5 +- include/sqlpp11/basic_expression_operators.h | 59 ++-- include/sqlpp11/boolean.h | 79 +++-- include/sqlpp11/boolean_expression.h | 2 +- include/sqlpp11/column.h | 7 +- include/sqlpp11/concat.h | 5 +- include/sqlpp11/count.h | 5 +- include/sqlpp11/exists.h | 5 +- include/sqlpp11/expression.h | 25 +- include/sqlpp11/floating_point.h | 138 ++++---- include/sqlpp11/in.h | 5 +- include/sqlpp11/integral.h | 341 ++++++++++--------- include/sqlpp11/is_null.h | 5 +- include/sqlpp11/like.h | 5 +- include/sqlpp11/max.h | 5 +- include/sqlpp11/min.h | 5 +- include/sqlpp11/no_value.h | 26 +- include/sqlpp11/parameter.h | 5 +- include/sqlpp11/statement.h | 2 +- include/sqlpp11/sum.h | 5 +- include/sqlpp11/table.h | 5 +- include/sqlpp11/text.h | 80 ++--- include/sqlpp11/type_traits.h | 3 + include/sqlpp11/value_type_fwd.h | 65 ++++ include/sqlpp11/verbatim.h | 5 +- tests/PreparedTest.cpp | 12 +- 26 files changed, 509 insertions(+), 395 deletions(-) create mode 100644 include/sqlpp11/value_type_fwd.h diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h index 8e3baaf5..27a61bcf 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/avg.h @@ -32,8 +32,9 @@ namespace sqlpp { template - struct avg_t: public floating_point::template expression_operators>, - public alias_operators> + struct avg_t: + public expression_operators, floating_point>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; diff --git a/include/sqlpp11/basic_expression_operators.h b/include/sqlpp11/basic_expression_operators.h index 7c7d3ec8..e3bfb5e4 100644 --- a/include/sqlpp11/basic_expression_operators.h +++ b/include/sqlpp11/basic_expression_operators.h @@ -27,6 +27,7 @@ #ifndef SQLPP_DETAIL_BASIC_EXPRESSION_OPERATORS_H #define SQLPP_DETAIL_BASIC_EXPRESSION_OPERATORS_H +#include #include #include #include @@ -38,7 +39,7 @@ namespace sqlpp { // basic operators - template class IsCorrectValueType> + template struct basic_expression_operators { template @@ -47,107 +48,107 @@ namespace sqlpp 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 IsCorrectValueType::value // the correct value type is required, of course + and ValueType::template _is_valid_operand::value // the correct value type is required, of course ; }; template - equal_to_t> operator==(T t) const + 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 + 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 + 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 + 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 + 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 + 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 + is_null_t is_null() const { - return { *static_cast(this) }; + return { *static_cast(this) }; } - is_null_t is_not_null() const + is_null_t is_not_null() const { - return { *static_cast(this) }; + return { *static_cast(this) }; } - sort_order_t asc() const + sort_order_t asc() const { - return { *static_cast(this) }; + return { *static_cast(this) }; } - sort_order_t desc() const + sort_order_t desc() const { - return { *static_cast(this) }; + return { *static_cast(this) }; } // Hint: use value_list wrapper for containers... template - in_t...> in(T... t) const + in_t...> in(T... t) const { static_assert(detail::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}... }; + return { *static_cast(this), wrap_operand_t{t}... }; } template - in_t...> not_in(T... t) const + in_t...> not_in(T... t) const { static_assert(detail::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}... }; + return { *static_cast(this), wrap_operand_t{t}... }; } }; - template + template struct alias_operators { template - expression_alias_t as(const alias_provider&) const + expression_alias_t as(const alias_provider&) const { - return { *static_cast(this) }; + return { *static_cast(this) }; } }; diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index 848f2acf..c96ea101 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -44,28 +44,34 @@ namespace sqlpp using _tag = ::sqlpp::tag::is_boolean; using _cpp_value_type = bool; - struct _parameter_t + template + using _is_valid_operand = is_boolean_t; + }; + + template<> + struct parameter_value_t { using _value_type = boolean; // FIXME + using _cpp_value_type = typename _value_type::_cpp_value_type; - _parameter_t(): + parameter_value_t(): _value(false), _is_null(true) {} - _parameter_t(const _cpp_value_type& value): + parameter_value_t(const _cpp_value_type& value): _value(value), _is_null(false) {} - _parameter_t& operator=(const _cpp_value_type& value) + parameter_value_t& operator=(const _cpp_value_type& value) { _value = value; _is_null = false; return *this; } - _parameter_t& operator=(const tvin_t>& t) + parameter_value_t& operator=(const tvin_t>& t) { if (t._is_trivial()) { @@ -80,7 +86,7 @@ namespace sqlpp return *this; } - _parameter_t& operator=(const std::nullptr_t&) + parameter_value_t& operator=(const std::nullptr_t&) { _value = false; _is_null = true; @@ -110,48 +116,41 @@ namespace sqlpp bool _is_null; }; + template + struct expression_operators: public basic_expression_operators + { template - struct _is_valid_operand + using _is_valid_operand = is_valid_operand; + + template + logical_and_t> operator and(T t) const { - static constexpr bool value = - is_expression_t::value // expressions are OK - and is_boolean_t::value // the correct value type is required, of course - ; - }; + using rhs = wrap_operand_t; + static_assert(_is_valid_operand::value, "invalid rhs operand"); - template - struct expression_operators: public basic_expression_operators - { - 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} }; - } - - 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} }; - } - - logical_not_t operator not() const - { - return { *static_cast(this) }; + return { *static_cast(this), rhs{t} }; } - }; - template - struct column_operators + 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} }; + } + + logical_not_t operator not() const + { + return { *static_cast(this) }; + } }; + template + struct column_operators + { + }; + template struct result_field_t: public result_field_methods_t> { diff --git a/include/sqlpp11/boolean_expression.h b/include/sqlpp11/boolean_expression.h index 5463f94f..5c8716f3 100644 --- a/include/sqlpp11/boolean_expression.h +++ b/include/sqlpp11/boolean_expression.h @@ -33,7 +33,7 @@ namespace sqlpp { template - struct boolean_expression_t: public boolean::template expression_operators> + struct boolean_expression_t: public expression_operators, boolean> { using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 1ecbeb73..65700813 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -42,8 +42,9 @@ namespace sqlpp { template - struct column_t: public value_type_of::template expression_operators>, - public value_type_of::template column_operators> + struct column_t: + public expression_operators, value_type_of>, + public column_operators, value_type_of> { struct _traits { @@ -66,7 +67,7 @@ namespace sqlpp using _name_t = typename _spec_t::_name_t; template - using _is_valid_operand = typename value_type_of::template _is_valid_operand; + using _is_valid_operand = is_valid_operand, T>; column_t() = default; column_t(const column_t&) = default; diff --git a/include/sqlpp11/concat.h b/include/sqlpp11/concat.h index 5e337f7b..19d3a819 100644 --- a/include/sqlpp11/concat.h +++ b/include/sqlpp11/concat.h @@ -36,8 +36,9 @@ namespace sqlpp { // FIXME: Remove First, inherit from text_t template - struct concat_t: public value_type_of::template expression_operators>, - public alias_operators> + struct concat_t: + public expression_operators, value_type_of>, + public alias_operators> { using _traits = make_traits, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_named_expression>; using _recursive_traits = make_recursive_traits; diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 814dcf22..78aa258f 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -33,8 +33,9 @@ namespace sqlpp { template - struct count_t: public sqlpp::integral::template expression_operators>, - public alias_operators> + struct count_t: + public expression_operators, integral>, + public alias_operators> { using _traits = make_traits<::sqlpp::integral, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_named_expression>; using _recursive_traits = make_recursive_traits; diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h index 867933cf..7a1cc982 100644 --- a/include/sqlpp11/exists.h +++ b/include/sqlpp11/exists.h @@ -32,8 +32,9 @@ namespace sqlpp { template - struct exists_t: public boolean::template expression_operators>, - public alias_operators> + struct exists_t: + public expression_operators, boolean>, + public alias_operators> { using _traits = make_traits; using _recursive_traits = make_recursive_traits; struct _name_t diff --git a/include/sqlpp11/assignment.h b/include/sqlpp11/assignment.h index a16c1abf..1471488a 100644 --- a/include/sqlpp11/assignment.h +++ b/include/sqlpp11/assignment.h @@ -40,7 +40,7 @@ namespace sqlpp template struct assignment_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _lhs_t = Lhs; diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h index 27a61bcf..4b879ef8 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/avg.h @@ -36,10 +36,10 @@ namespace sqlpp public expression_operators, floating_point>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; - static_assert(is_noop::value or std::is_same::value, "avg() used with flag other than 'distinct'"); + 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"); struct _name_t @@ -75,7 +75,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { context << "AVG("; - if (std::is_same::value) + if (std::is_same::value) { serialize(Flag(), context); context << ' '; @@ -94,7 +94,7 @@ namespace sqlpp } template - auto avg(const sqlpp::distinct_t&, T t) -> avg_t> + auto avg(const distinct_t&, T t) -> avg_t> { static_assert(is_numeric_t>::value, "avg() requires a value expression as argument"); return { t }; diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index 26f84070..d324d665 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -40,8 +40,8 @@ namespace sqlpp // boolean value type struct boolean { - using _traits = make_traits; - using _tag = ::sqlpp::tag::is_boolean; + using _traits = make_traits; + using _tag = tag::is_boolean; using _cpp_value_type = bool; template diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 65700813..31c9382b 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -96,17 +96,17 @@ namespace sqlpp return { *this, {rhs{t}} }; } - auto operator =(sqlpp::null_t) const - ->assignment_t + auto operator =(null_t) const + ->assignment_t { static_assert(can_be_null_t::value, "column cannot be null"); - return { *this, sqlpp::null_t{} }; + return { *this, null_t{} }; } - auto operator =(sqlpp::default_value_t) const - ->assignment_t + auto operator =(default_value_t) const + ->assignment_t { - return { *this, sqlpp::default_value_t{} }; + return { *this, default_value_t{} }; } }; diff --git a/include/sqlpp11/concat.h b/include/sqlpp11/concat.h index 19d3a819..d75f4a39 100644 --- a/include/sqlpp11/concat.h +++ b/include/sqlpp11/concat.h @@ -40,11 +40,11 @@ namespace sqlpp public expression_operators, value_type_of>, public alias_operators> { - using _traits = make_traits, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_named_expression>; + using _traits = make_traits, tag::is_expression, tag::is_named_expression>; using _recursive_traits = make_recursive_traits; static_assert(sizeof...(Args) > 0, "concat requires two arguments at least"); - static_assert(sqlpp::detail::all_t::value, is_text_t::value...>::value, "at least one non-text argument detected in concat()"); + static_assert(detail::all_t::value, is_text_t::value...>::value, "at least one non-text argument detected in concat()"); struct _name_t { static constexpr const char* _get_name() { return "CONCAT"; } diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 78aa258f..2ed9766d 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -37,10 +37,10 @@ namespace sqlpp public expression_operators, integral>, public alias_operators> { - using _traits = make_traits<::sqlpp::integral, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_named_expression>; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; - 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'"); static_assert(is_expression_t::value, "count() requires a sql expression as argument"); struct _name_t @@ -76,7 +76,7 @@ namespace sqlpp static Context& _(const T& t, Context& context) { context << "COUNT("; - if (std::is_same::value) + if (std::is_same::value) { serialize(Flag(), context); context << ' '; @@ -95,7 +95,7 @@ namespace sqlpp } template - auto count(const sqlpp::distinct_t&, T t) -> count_t> + auto count(const distinct_t&, T t) -> count_t> { static_assert(is_expression_t>::value, "count() requires an expression as argument"); return { t }; diff --git a/include/sqlpp11/detail/copy_tuple_args.h b/include/sqlpp11/detail/copy_tuple_args.h index 32631e01..fafabe7b 100644 --- a/include/sqlpp11/detail/copy_tuple_args.h +++ b/include/sqlpp11/detail/copy_tuple_args.h @@ -43,9 +43,9 @@ namespace sqlpp }; template - struct as_tuple<::sqlpp::all_of_t> + struct as_tuple> { - static typename ::sqlpp::all_of_t::_column_tuple_t _(::sqlpp::all_of_t) { return { }; } + static typename all_of_t::_column_tuple_t _(all_of_t) { return { }; } }; template diff --git a/include/sqlpp11/detail/type_set.h b/include/sqlpp11/detail/type_set.h index 4f6f1ef4..51e732f5 100644 --- a/include/sqlpp11/detail/type_set.h +++ b/include/sqlpp11/detail/type_set.h @@ -73,7 +73,7 @@ namespace sqlpp template struct is_element_of { - static_assert(::sqlpp::wrong_t::value, "SET has to be a type set"); + static_assert(wrong_t::value, "SET has to be a type set"); }; template @@ -85,7 +85,7 @@ namespace sqlpp template struct joined_set { - static_assert(::sqlpp::wrong_t::value, "L and R have to be type sets"); + static_assert(wrong_t::value, "L and R have to be type sets"); }; template @@ -100,7 +100,7 @@ namespace sqlpp template struct is_superset_of { - static_assert(::sqlpp::wrong_t::value, "L and R have to be type sets"); + static_assert(wrong_t::value, "L and R have to be type sets"); }; template @@ -118,7 +118,7 @@ namespace sqlpp template struct is_disjunct_from { - static_assert(::sqlpp::wrong_t::value, "invalid argument for is_disjunct_from"); + static_assert(wrong_t::value, "invalid argument for is_disjunct_from"); }; template @@ -174,7 +174,7 @@ namespace sqlpp template struct make_joined_set { - static_assert(::sqlpp::wrong_t::value, "invalid argument for joined set"); + static_assert(wrong_t::value, "invalid argument for joined set"); }; template<> @@ -197,7 +197,7 @@ namespace sqlpp template struct make_difference_set { - static_assert(::sqlpp::wrong_t::value, "invalid argument for difference set"); + static_assert(wrong_t::value, "invalid argument for difference set"); }; template @@ -214,7 +214,7 @@ namespace sqlpp template struct make_intersect_set { - static_assert(::sqlpp::wrong_t::value, "invalid argument for intersect set"); + static_assert(wrong_t::value, "invalid argument for intersect set"); }; template @@ -232,7 +232,7 @@ namespace sqlpp template class Transformation, typename T> struct transform_set { - static_assert(::sqlpp::wrong_t::value, "invalid argument for transform_set"); + static_assert(wrong_t::value, "invalid argument for transform_set"); }; template class Transformation, typename... E> diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h index 7a1cc982..33e02fd7 100644 --- a/include/sqlpp11/exists.h +++ b/include/sqlpp11/exists.h @@ -36,7 +36,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits::value, "exists() requires a select expression as argument"); diff --git a/include/sqlpp11/expression.h b/include/sqlpp11/expression.h index 2743502d..c467c603 100644 --- a/include/sqlpp11/expression.h +++ b/include/sqlpp11/expression.h @@ -43,7 +43,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _lhs_t = Lhs; using _rhs_t = rhs_wrap_t, trivial_value_is_null_t<_lhs_t>::value>; @@ -91,7 +91,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _lhs_t = Lhs; using _rhs_t = rhs_wrap_t, trivial_value_is_null_t<_lhs_t>::value>; @@ -139,7 +139,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; unary_expression_t(Rhs rhs): @@ -184,7 +184,7 @@ namespace sqlpp public expression_operators, value_type_of>, public alias_operators> { - using _traits = make_traits, sqlpp::tag::is_expression>; + using _traits = make_traits, tag::is_expression>; using _recursive_traits = make_recursive_traits; binary_expression_t(Lhs lhs, Rhs rhs): @@ -223,7 +223,7 @@ namespace sqlpp public expression_operators, value_type_of>, public alias_operators> { - using _traits = make_traits, sqlpp::tag::is_expression>; + using _traits = make_traits, tag::is_expression>; using _recursive_traits = make_recursive_traits; unary_expression_t(Rhs rhs): diff --git a/include/sqlpp11/expression_fwd.h b/include/sqlpp11/expression_fwd.h index 73e10072..5e5396a5 100644 --- a/include/sqlpp11/expression_fwd.h +++ b/include/sqlpp11/expression_fwd.h @@ -37,53 +37,53 @@ namespace sqlpp { struct less { - using _traits = make_traits<::sqlpp::boolean>; + using _traits = make_traits; static constexpr const char* _name = "<"; }; struct less_equal { - using _traits = make_traits<::sqlpp::boolean>; + using _traits = make_traits; static constexpr const char* _name = "<="; }; struct equal_to { - using _traits = make_traits<::sqlpp::boolean>; + using _traits = make_traits; }; struct not_equal_to { - using _traits = make_traits<::sqlpp::boolean>; + using _traits = make_traits; }; struct greater_equal { - using _traits = make_traits<::sqlpp::boolean>; + using _traits = make_traits; static constexpr const char* _name = ">="; }; struct greater { - using _traits = make_traits<::sqlpp::boolean>; + using _traits = make_traits; static constexpr const char* _name = ">"; }; struct logical_or { - using _traits = make_traits<::sqlpp::boolean>; + using _traits = make_traits; static constexpr const char* _name = " OR "; }; struct logical_and { - using _traits = make_traits<::sqlpp::boolean>; + using _traits = make_traits; static constexpr const char* _name = " AND "; }; struct logical_not { - using _traits = make_traits<::sqlpp::boolean>; + using _traits = make_traits; }; template @@ -109,13 +109,13 @@ namespace sqlpp struct divides { - using _traits = make_traits<::sqlpp::floating_point>; + using _traits = make_traits; static constexpr const char* _name = "/"; }; struct modulus { - using _traits = make_traits<::sqlpp::integral>; + using _traits = make_traits; static constexpr const char* _name = "%"; }; diff --git a/include/sqlpp11/extra_tables.h b/include/sqlpp11/extra_tables.h index 507c0ef9..22623b0d 100644 --- a/include/sqlpp11/extra_tables.h +++ b/include/sqlpp11/extra_tables.h @@ -51,22 +51,22 @@ namespace sqlpp template struct extra_tables_t { - using _traits = make_traits; + using _traits = make_traits; struct _recursive_traits { using _parameters = std::tuple<>; - using _required_tables = ::sqlpp::detail::type_set<>; - using _provided_outer_tables = ::sqlpp::detail::type_set<>; - using _provided_tables = ::sqlpp::detail::type_set<>; - using _extra_tables = ::sqlpp::detail::type_set; + using _required_tables = detail::type_set<>; + using _provided_outer_tables = detail::type_set<>; + using _provided_tables = detail::type_set<>; + using _extra_tables = detail::type_set; using _can_be_null = std::false_type; }; // FIXME: extra_tables must not require tables! static_assert(sizeof...(Tables), "at least one table or join argument required in extra_tables()"); - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in extra_tables()"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in extra_tables()"); + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in extra_tables()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not a table or join in extra_tables()"); // Data using _data_t = extra_tables_data_t; @@ -106,7 +106,7 @@ namespace sqlpp // NO EXTRA TABLES YET struct no_extra_tables_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index 0dde778b..ac0915a0 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -38,8 +38,8 @@ namespace sqlpp // floating_point value type struct floating_point { - using _traits = make_traits; - using _tag = ::sqlpp::tag::is_floating_point; + using _traits = make_traits; + using _tag = tag::is_floating_point; using _cpp_value_type = double; template diff --git a/include/sqlpp11/from.h b/include/sqlpp11/from.h index 4c9f583a..d5a41cf7 100644 --- a/include/sqlpp11/from.h +++ b/include/sqlpp11/from.h @@ -59,7 +59,7 @@ namespace sqlpp template struct from_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = is_database; @@ -79,7 +79,7 @@ namespace sqlpp using _known_table_names = detail::transform_set_t; static_assert(not detail::is_element_of::value, "Must not use the same table name twice in from()"); - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; + using ok = detail::all_t<_is_dynamic::value, is_table_t
::value>; _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert } @@ -125,7 +125,7 @@ namespace sqlpp struct no_from_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data @@ -186,7 +186,7 @@ namespace sqlpp auto _from_impl(Tables... tables) const -> _new_statement_t> { - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a table or join in from()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not a table or join in from()"); static_assert(required_tables_of>::size::value == 0, "at least one table depends on another table"); static constexpr std::size_t _number_of_tables = detail::sum(provided_tables_of::size::value...); diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index ca32b9b4..75eacd90 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -79,7 +79,7 @@ namespace sqlpp template struct value_list_t // to be used in .in() method { - using _traits = make_traits, ::sqlpp::tag::is_expression>; + using _traits = make_traits, tag::is_expression>; using _recursive_traits = make_recursive_traits<>; using _container_t = Container; diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index f39c7210..89792311 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -59,16 +59,16 @@ namespace sqlpp template struct group_by_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = is_database; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in group_by()"); - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in group_by()"); + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in group_by()"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in group_by()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not an expression in group_by()"); // Data using _data_t = group_by_data_t; @@ -90,7 +90,7 @@ namespace sqlpp static_assert(is_expression_t::value, "invalid expression argument in group_by::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in group_by::add()"); - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_expression_t::value>; _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } @@ -135,7 +135,7 @@ namespace sqlpp // NO GROUP BY YET struct no_group_by_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index 41cce83f..cd412c7c 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -58,13 +58,13 @@ namespace sqlpp template struct having_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = is_database; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in having()"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in having()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not an expression in having()"); // Data using _data_t = having_data_t; @@ -86,7 +86,7 @@ namespace sqlpp static_assert(is_expression_t::value, "invalid expression argument in having::add()"); static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in having::add()"); - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_expression_t::value>; _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } @@ -133,7 +133,7 @@ namespace sqlpp // NO HAVING YET struct no_having_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/in.h b/include/sqlpp11/in.h index 59b5d792..57d1e228 100644 --- a/include/sqlpp11/in.h +++ b/include/sqlpp11/in.h @@ -39,7 +39,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static constexpr bool _inverted = not NotInverted; diff --git a/include/sqlpp11/insert_value.h b/include/sqlpp11/insert_value.h index 899db8bc..061bbd82 100644 --- a/include/sqlpp11/insert_value.h +++ b/include/sqlpp11/insert_value.h @@ -49,7 +49,7 @@ namespace sqlpp { struct type { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; }; }; diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 953c2fe9..7de1aa17 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -124,7 +124,7 @@ namespace sqlpp template struct insert_list_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits..., rhs_t...>; using _is_dynamic = is_database; @@ -157,7 +157,7 @@ namespace sqlpp static_assert(not must_not_insert_t>::value, "add() argument must not be used in insert"); static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "add() contains a column from a foreign table"); - using ok = ::sqlpp::detail::all_t< + using ok = detail::all_t< _is_dynamic::value, is_assignment_t::value>; @@ -225,7 +225,7 @@ namespace sqlpp template struct column_list_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _value_tuple_t = typename column_list_data_t::_value_tuple_t; @@ -241,13 +241,13 @@ namespace sqlpp template void add(Assignments... assignments) { - static_assert(::sqlpp::detail::all_t::value...>::value, "add_values() arguments have to be assignments"); + static_assert(detail::all_t::value...>::value, "add_values() arguments have to be assignments"); using _arg_value_tuple = std::tuple>...>; using _args_correct = std::is_same<_arg_value_tuple, _value_tuple_t>; static_assert(_args_correct::value, "add_values() arguments do not match columns() arguments"); - using ok = ::sqlpp::detail::all_t< - ::sqlpp::detail::all_t::value...>::value, + using ok = detail::all_t< + detail::all_t::value...>::value, _args_correct::value>; _add_impl(ok(), assignments...); // dispatch to prevent compile messages after the static_assert @@ -294,7 +294,7 @@ namespace sqlpp // NO INSERT COLUMNS/VALUES YET struct no_insert_value_list_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data @@ -347,10 +347,10 @@ namespace sqlpp -> _new_statement_t> { static_assert(sizeof...(Columns), "at least one column required in columns()"); - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in columns()"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a column in columns()"); - static_assert(::sqlpp::detail::none_t::value...>::value, "at least one column argument has a must_not_insert tag in its definition"); - using _column_required_tables = ::sqlpp::detail::make_joined_set_t...>; + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in columns()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not a column in columns()"); + static_assert(detail::none_t::value...>::value, "at least one column argument has a must_not_insert tag in its definition"); + using _column_required_tables = detail::make_joined_set_t...>; static_assert(_column_required_tables::size::value == 1, "columns() contains columns from several tables"); using _table = typename detail::first_arg_t::_table; @@ -366,7 +366,7 @@ namespace sqlpp -> _new_statement_t> { static_assert(sizeof...(Assignments), "at least one assignment expression required in set()"); - static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); using _table = typename lhs_t>::_table; using required_columns = typename _table::_required_insert_columns; @@ -387,11 +387,11 @@ namespace sqlpp auto _set_impl(Assignments... assignments) const -> _new_statement_t> { - static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); - static_assert(not ::sqlpp::detail::has_duplicates...>::value, "at least one duplicate column detected in set()"); - static_assert(sqlpp::detail::none_t>::value...>::value, "at least one assignment is prohibited by its column definition in set()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); + static_assert(not detail::has_duplicates...>::value, "at least one duplicate column detected in set()"); + static_assert(detail::none_t>::value...>::value, "at least one assignment is prohibited by its column definition in set()"); - using _column_required_tables = ::sqlpp::detail::make_joined_set_t>...>; + using _column_required_tables = detail::make_joined_set_t>...>; static_assert(sizeof...(Assignments) ? (_column_required_tables::size::value == 1) : true, "set() contains assignments for columns from several tables"); return { static_cast&>(*this), insert_list_data_t{assignments...} }; diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 0cf251e6..e5123f45 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -40,8 +40,8 @@ namespace sqlpp // integral value type struct integral { - using _traits = make_traits; - using _tag = ::sqlpp::tag::is_integral; + using _traits = make_traits; + using _tag = tag::is_integral; using _cpp_value_type = int64_t; template diff --git a/include/sqlpp11/interpret_tuple.h b/include/sqlpp11/interpret_tuple.h index 04ac5d4a..4edb2631 100644 --- a/include/sqlpp11/interpret_tuple.h +++ b/include/sqlpp11/interpret_tuple.h @@ -47,7 +47,7 @@ namespace sqlpp } template - auto interpret_tuple_impl(const Tuple& t, const Separator& separator, Context& context, const ::sqlpp::detail::index_sequence&) + auto interpret_tuple_impl(const Tuple& t, const Separator& separator, Context& context, const detail::index_sequence&) -> Context& { // Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init] paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4. @@ -63,7 +63,7 @@ namespace sqlpp auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) -> Context& { - return interpret_tuple_impl(t, separator, context, ::sqlpp::detail::make_index_sequence::value>{}); + return interpret_tuple_impl(t, separator, context, detail::make_index_sequence::value>{}); } } diff --git a/include/sqlpp11/interpretable.h b/include/sqlpp11/interpretable.h index c93bcaea..d89075be 100644 --- a/include/sqlpp11/interpretable.h +++ b/include/sqlpp11/interpretable.h @@ -52,16 +52,16 @@ namespace sqlpp interpretable_t& operator=(interpretable_t&&) = default; ~interpretable_t() = default; - sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const + serializer_context_t& serialize(serializer_context_t& context) const { return _impl->serialize(context); } - // This method only exists if Db::_serializer_context_t and sqlpp::serializer_context_t are not the same + // This method only exists if Db::_serializer_context_t and serializer_context_t are not the same template auto serialize(Context& context) const -> typename std::enable_if::value - and not std::is_same::value, Context&>::type + and not std::is_same::value, Context&>::type { return _impl->db_serialize(context); } @@ -74,7 +74,7 @@ namespace sqlpp private: struct _impl_base { - virtual sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const = 0; + virtual serializer_context_t& serialize(serializer_context_t& context) const = 0; virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0; virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0; }; @@ -87,9 +87,9 @@ namespace sqlpp _t(t) {} - sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const + serializer_context_t& serialize(serializer_context_t& context) const { - sqlpp::serialize(_t, context); + ::sqlpp::serialize(_t, context); return context; } diff --git a/include/sqlpp11/into.h b/include/sqlpp11/into.h index 454ef2ff..cff8fb35 100644 --- a/include/sqlpp11/into.h +++ b/include/sqlpp11/into.h @@ -57,7 +57,7 @@ namespace sqlpp template struct into_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits
; static_assert(is_table_t
::value, "argument has to be a table"); @@ -103,7 +103,7 @@ namespace sqlpp // NO INTO YET struct no_into_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/is_null.h b/include/sqlpp11/is_null.h index fbc2ef03..f975507f 100644 --- a/include/sqlpp11/is_null.h +++ b/include/sqlpp11/is_null.h @@ -38,7 +38,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static constexpr bool _inverted = not NotInverted; @@ -72,9 +72,9 @@ namespace sqlpp }; template - struct serializer_t> + struct serializer_t> { - using T = ::sqlpp::is_null_t; + using T = is_null_t; static Context& _(const T& t, Context& context) { diff --git a/include/sqlpp11/join.h b/include/sqlpp11/join.h index 6e90ca37..30a3db7b 100644 --- a/include/sqlpp11/join.h +++ b/include/sqlpp11/join.h @@ -82,7 +82,7 @@ namespace sqlpp static_assert(not is_join_t::value, "rhs argument for join must not be a join"); static_assert(is_noop::value or is_on_t::value, "invalid on expression in join().on()"); - static_assert(::sqlpp::detail::is_disjunct_from, provided_tables_of>::value, "joined tables must not be identical"); + static_assert(detail::is_disjunct_from, provided_tables_of>::value, "joined tables must not be identical"); static_assert(_recursive_traits::_required_tables::size::value == 0, "joined tables must not depend on other tables"); diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index d6bede32..061e9789 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -38,7 +38,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static_assert(is_text_t::value, "Operand for like() has to be a text"); diff --git a/include/sqlpp11/limit.h b/include/sqlpp11/limit.h index 375285ec..40b756ce 100644 --- a/include/sqlpp11/limit.h +++ b/include/sqlpp11/limit.h @@ -54,7 +54,7 @@ namespace sqlpp template struct limit_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static_assert(is_integral_t::value, "limit requires an integral value or integral parameter"); @@ -123,7 +123,7 @@ namespace sqlpp template struct dynamic_limit_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data @@ -172,7 +172,7 @@ namespace sqlpp struct no_limit_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index 8edce697..8f0f8fb3 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -36,7 +36,7 @@ namespace sqlpp public expression_operators, value_type_of>, public alias_operators> { - using _traits = make_traits, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_named_expression>; + using _traits = make_traits, tag::is_expression, tag::is_named_expression>; using _recursive_traits = make_recursive_traits; static_assert(is_expression_t::value, "max() requires a value expression as argument"); diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index 1aac755f..7846d763 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -36,7 +36,7 @@ namespace sqlpp public expression_operators, value_type_of>, public alias_operators> { - using _traits = make_traits, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_named_expression>; + using _traits = make_traits, tag::is_expression, tag::is_named_expression>; using _recursive_traits = make_recursive_traits; static_assert(is_expression_t::value, "min() requires a value expression as argument"); diff --git a/include/sqlpp11/named_interpretable.h b/include/sqlpp11/named_interpretable.h index dcbffbdb..5ba0f044 100644 --- a/include/sqlpp11/named_interpretable.h +++ b/include/sqlpp11/named_interpretable.h @@ -50,16 +50,16 @@ namespace sqlpp named_interpretable_t& operator=(named_interpretable_t&&) = default; ~named_interpretable_t() = default; - sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const + serializer_context_t& serialize(serializer_context_t& context) const { return _impl->serialize(context); } - // This method only exists if Db::_serializer_context_t and sqlpp::serializer_context_t are not the same + // This method only exists if Db::_serializer_context_t and serializer_context_t are not the same template auto serialize(Context& context) const -> typename std::enable_if::value - and not std::is_same::value, Context&>::type + and not std::is_same::value, Context&>::type { return _impl->db_serialize(context); } @@ -77,7 +77,7 @@ namespace sqlpp private: struct _impl_base { - virtual sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const = 0; + virtual serializer_context_t& serialize(serializer_context_t& context) const = 0; virtual _serializer_context_t& db_serialize(_serializer_context_t& context) const = 0; virtual _interpreter_context_t& interpret(_interpreter_context_t& context) const = 0; virtual std::string _get_name() const = 0; @@ -91,9 +91,9 @@ namespace sqlpp _t(t) {} - sqlpp::serializer_context_t& serialize(sqlpp::serializer_context_t& context) const + serializer_context_t& serialize(serializer_context_t& context) const { - sqlpp::serialize(_t, context); + ::sqlpp::serialize(_t, context); return context; } diff --git a/include/sqlpp11/noop.h b/include/sqlpp11/noop.h index b5873b5b..5d6afae2 100644 --- a/include/sqlpp11/noop.h +++ b/include/sqlpp11/noop.h @@ -35,7 +35,7 @@ namespace sqlpp { struct noop { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; struct _name_t {}; diff --git a/include/sqlpp11/offset.h b/include/sqlpp11/offset.h index f230c4b2..5d0b4b3b 100644 --- a/include/sqlpp11/offset.h +++ b/include/sqlpp11/offset.h @@ -54,7 +54,7 @@ namespace sqlpp template struct offset_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static_assert(is_integral_t::value, "offset requires an integral value or integral parameter"); @@ -123,7 +123,7 @@ namespace sqlpp template struct dynamic_offset_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data @@ -183,7 +183,7 @@ namespace sqlpp struct no_offset_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index c55ea3a9..8d761989 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -59,16 +59,16 @@ namespace sqlpp template struct order_by_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = is_database; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression (e.g. a column) required in order_by()"); - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in order_by()"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not an expression in order_by()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not an expression in order_by()"); // Data using _data_t = order_by_data_t; @@ -90,7 +90,7 @@ namespace sqlpp static_assert(is_expression_t::value, "invalid expression argument in order_by::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in order_by::add()"); - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_expression_t::value>; _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } @@ -135,7 +135,7 @@ namespace sqlpp // NO ORDER BY YET struct no_order_by_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/parameter_list.h b/include/sqlpp11/parameter_list.h index 89d75d33..c4aeba51 100644 --- a/include/sqlpp11/parameter_list.h +++ b/include/sqlpp11/parameter_list.h @@ -52,12 +52,12 @@ namespace sqlpp template void _bind(Target& target) const { - _bind_impl(target, ::sqlpp::detail::make_index_sequence{}); + _bind_impl(target, detail::make_index_sequence{}); } private: template - void _bind_impl(Target& target, const ::sqlpp::detail::index_sequence&) const + void _bind_impl(Target& target, const detail::index_sequence&) const { using swallow = int[]; // see interpret_tuple.h (void) swallow{(static_cast::type&>(*this)()._bind(target, Is), 0)...}; diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 42b266f5..d0d4026d 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -152,17 +152,17 @@ namespace sqlpp template struct select_column_list_t { - using _traits = typename ::sqlpp::detail::select_traits::_traits; + using _traits = typename detail::select_traits::_traits; using _recursive_traits = make_recursive_traits; - using _name_t = typename ::sqlpp::detail::select_traits::_name_t; + using _name_t = typename detail::select_traits::_name_t; using _is_dynamic = is_database; static_assert(_is_dynamic::value or sizeof...(Columns), "at least one select expression required"); - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected"); - static_assert(::sqlpp::detail::all_t<(is_named_expression_t::value or is_multi_column_t::value)...>::value, "at least one argument is not a named expression"); - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate name detected"); + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected"); + static_assert(detail::all_t<(is_named_expression_t::value or is_multi_column_t::value)...>::value, "at least one argument is not a named expression"); + static_assert(not detail::has_duplicates::value, "at least one duplicate name detected"); struct _column_type {}; @@ -185,10 +185,10 @@ namespace sqlpp static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column"); static_assert(is_named_expression_t::value, "invalid named expression argument in selected_columns::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "named expression uses tables unknown to this statement in selected_columns::add()"); - using column_names = ::sqlpp::detail::make_type_set_t; - static_assert(not ::sqlpp::detail::is_element_of::value, "a column of this name is present in the select already"); + using column_names = detail::make_type_set_t; + static_assert(not detail::is_element_of::value, "a column of this name is present in the select already"); - using ok = ::sqlpp::detail::all_t< + using ok = detail::all_t< _is_dynamic::value, is_named_expression_t::value >; @@ -278,7 +278,7 @@ namespace sqlpp _alias_t as(const AliasProvider& aliasProvider) const { static_assert(Policies::_can_be_used_as_table::value, "statement cannot be used as table, e.g. due to missing tables"); - static_assert(::sqlpp::detail::none_t::value...>::value, "cannot use multi-columns in sub selects"); + static_assert(detail::none_t::value...>::value, "cannot use multi-columns in sub selects"); return _table_t(_get_statement()).as(aliasProvider); } @@ -326,7 +326,7 @@ namespace sqlpp struct no_select_column_list_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; struct _name_t {}; @@ -370,17 +370,17 @@ namespace sqlpp template auto columns(Args... args) const - -> _new_statement_t<::sqlpp::detail::make_select_column_list_t> + -> _new_statement_t> { - return { static_cast&>(*this), typename ::sqlpp::detail::make_select_column_list_t::_data_t{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; + return { static_cast&>(*this), typename detail::make_select_column_list_t::_data_t{std::tuple_cat(detail::as_tuple::_(args)...)} }; } template auto dynamic_columns(Args... args) const - -> _new_statement_t<::sqlpp::detail::make_select_column_list_t<_database_t, Args...>> + -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_columns must not be called in a static statement"); - return { static_cast&>(*this), typename ::sqlpp::detail::make_select_column_list_t<_database_t, Args...>::_data_t{std::tuple_cat(::sqlpp::detail::as_tuple::_(args)...)} }; + return { static_cast&>(*this), typename detail::make_select_column_list_t<_database_t, Args...>::_data_t{std::tuple_cat(detail::as_tuple::_(args)...)} }; } }; }; diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index fdc61735..5864816d 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -59,14 +59,14 @@ namespace sqlpp template struct select_flag_list_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = is_database; - static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); + static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in select flag list"); - static_assert(::sqlpp::detail::all_t::value...>::value, "at least one argument is not a select flag in select flag list"); + static_assert(detail::all_t::value...>::value, "at least one argument is not a select flag in select flag list"); // Data using _data_t = select_flag_list_data_t; @@ -88,7 +88,7 @@ namespace sqlpp static_assert(is_select_flag_t::value, "invalid select flag argument in select_flags::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "flag uses tables unknown to this statement in select_flags::add()"); - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_select_flag_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_select_flag_t::value>; _add_impl(flag, ok()); // dispatch to prevent compile messages after the static_assert } @@ -134,7 +134,7 @@ namespace sqlpp struct no_select_flag_list_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/select_pseudo_table.h b/include/sqlpp11/select_pseudo_table.h index e803fa59..75f8dbf0 100644 --- a/include/sqlpp11/select_pseudo_table.h +++ b/include/sqlpp11/select_pseudo_table.h @@ -51,7 +51,7 @@ namespace sqlpp typename Select, typename... NamedExpr > - struct select_pseudo_table_t: public sqlpp::table_t, select_column_spec_t...> { diff --git a/include/sqlpp11/simple_column.h b/include/sqlpp11/simple_column.h index c85ed67c..dd1769c6 100644 --- a/include/sqlpp11/simple_column.h +++ b/include/sqlpp11/simple_column.h @@ -37,7 +37,7 @@ namespace sqlpp { Column _column; - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; }; diff --git a/include/sqlpp11/single_table.h b/include/sqlpp11/single_table.h index fcdc7ba3..ca6566cb 100644 --- a/include/sqlpp11/single_table.h +++ b/include/sqlpp11/single_table.h @@ -57,7 +57,7 @@ namespace sqlpp template struct single_table_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits
; static_assert(is_table_t
::value, "argument has to be a table"); @@ -103,7 +103,7 @@ namespace sqlpp // NO INTO YET struct no_single_table_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/some.h b/include/sqlpp11/some.h index f8f41f5e..00dfb755 100644 --- a/include/sqlpp11/some.h +++ b/include/sqlpp11/some.h @@ -35,7 +35,7 @@ namespace sqlpp template struct some_t { - using _traits = make_traits, ::sqlpp::tag::is_multi_expression>; + using _traits = make_traits, tag::is_multi_expression>; using _recursive_traits = make_recursive_traits
::value, "invalid table argument in add()"); - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_table_t
::value>; + using ok = detail::all_t<_is_dynamic::value, is_table_t
::value>; _add_impl(table, ok()); // dispatch to prevent compile messages after the static_assert } @@ -128,7 +128,7 @@ namespace sqlpp // NO USING YET struct no_using_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/verbatim.h b/include/sqlpp11/verbatim.h index 21322564..0ea6c61a 100644 --- a/include/sqlpp11/verbatim.h +++ b/include/sqlpp11/verbatim.h @@ -37,7 +37,7 @@ namespace sqlpp public expression_operators, ValueType>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; struct _recursive_traits : public make_recursive_traits<> { using _can_be_null = std::true_type; // since we do not know what's going on inside the verbatim, we assume it can be null diff --git a/include/sqlpp11/verbatim_table.h b/include/sqlpp11/verbatim_table.h index e0c248cd..fc53af7f 100644 --- a/include/sqlpp11/verbatim_table.h +++ b/include/sqlpp11/verbatim_table.h @@ -46,9 +46,9 @@ namespace sqlpp }; } - struct verbatim_table_t: public sqlpp::table_t + struct verbatim_table_t: public table_t { - struct _recursive_traits: public sqlpp::table_t::_recursive_traits + struct _recursive_traits: public table_t::_recursive_traits { using _provided_outer_tables = detail::type_set; }; diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 5d5a113d..7fb09551 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -58,14 +58,14 @@ namespace sqlpp template struct where_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; using _is_dynamic = is_database; static_assert(_is_dynamic::value or sizeof...(Expressions), "at least one expression argument required in where()"); - static_assert(sqlpp::detail::none_t::value...>::value, "at least one argument is an assignment in where()"); - static_assert(sqlpp::detail::all_t::value...>::value, "at least one argument is not valid expression in where()"); + static_assert(detail::none_t::value...>::value, "at least one argument is an assignment in where()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not valid expression in where()"); // Data using _data_t = where_data_t; @@ -87,7 +87,7 @@ namespace sqlpp static_assert(is_expression_t::value, "invalid expression argument in where::add()"); static_assert(not TableCheckRequired::value or Policies::template _no_unknown_tables::value, "expression uses tables unknown to this statement in where::add()"); - using ok = ::sqlpp::detail::all_t<_is_dynamic::value, is_expression_t::value>; + using ok = detail::all_t<_is_dynamic::value, is_expression_t::value>; _add_impl(expression, ok()); // dispatch to prevent compile messages after the static_assert } @@ -141,7 +141,7 @@ namespace sqlpp template<> struct where_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data @@ -184,7 +184,7 @@ namespace sqlpp template struct no_where_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; // Data diff --git a/include/sqlpp11/wrap_operand.h b/include/sqlpp11/wrap_operand.h index f4b28022..7be274c2 100644 --- a/include/sqlpp11/wrap_operand.h +++ b/include/sqlpp11/wrap_operand.h @@ -42,7 +42,7 @@ namespace sqlpp struct boolean_operand: public alias_operators { - using _traits = make_traits<::sqlpp::boolean, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; using _value_t = bool; @@ -80,7 +80,7 @@ namespace sqlpp struct integral_operand: public alias_operators { - using _traits = make_traits<::sqlpp::integral, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; using _value_t = int64_t; @@ -119,7 +119,7 @@ namespace sqlpp struct floating_point_operand: public alias_operators { - using _traits = make_traits<::sqlpp::floating_point, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; using _value_t = double; @@ -157,7 +157,7 @@ namespace sqlpp struct text_operand: public alias_operators { - using _traits = make_traits<::sqlpp::text, ::sqlpp::tag::is_expression, ::sqlpp::tag::is_wrapped_value>; + using _traits = make_traits; using _recursive_traits = make_recursive_traits<>; using _value_t = std::string; From d75862365b09ff1e63f248f22338f0e0a33f1219 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 27 Aug 2014 21:32:00 +0200 Subject: [PATCH 36/52] Cleanup in generated code --- scripts/ddl2cpp | 1 - tests/Sample.h | 2 -- 2 files changed, 3 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 9fbeabb2..dd09cf86 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -175,7 +175,6 @@ for tableCreation in tableCreations: print(' struct ' + tableClass + ': ' + NAMESPACE + '::table_t<' + tableTemplateParameters + '>', file=header) print(' {', file=header) - print(' using _value_type = ' + NAMESPACE + '::no_value_t;', file=header) print(' struct _name_t', file=header) print(' {', file=header) print(' static constexpr const char* _get_name() { return "' + sqlTableName + '"; }', file=header) diff --git a/tests/Sample.h b/tests/Sample.h index 4ba3774d..5f1bf1de 100644 --- a/tests/Sample.h +++ b/tests/Sample.h @@ -60,7 +60,6 @@ namespace test TabFoo_::Epsilon, TabFoo_::Omega> { - using _value_type = sqlpp::no_value_t; struct _name_t { static constexpr const char* _get_name() { return "tab_foo"; } @@ -143,7 +142,6 @@ namespace test TabBar_::Gamma, TabBar_::Delta> { - using _value_type = sqlpp::no_value_t; struct _name_t { static constexpr const char* _get_name() { return "tab_bar"; } From 2dcd2918d338edd579476147052bfdf473c8654b Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 27 Aug 2014 22:53:22 +0200 Subject: [PATCH 37/52] Added operators to the 'like' member_t --- include/sqlpp11/like.h | 2 ++ tests/ResultTest.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index 061e9789..d20d8691 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -51,6 +51,8 @@ namespace sqlpp struct _member_t { T like; + T& operator()() { return like; } + const T& operator()() const { return like; } }; }; diff --git a/tests/ResultTest.cpp b/tests/ResultTest.cpp index 7add38fa..21ca2f82 100644 --- a/tests/ResultTest.cpp +++ b/tests/ResultTest.cpp @@ -43,7 +43,7 @@ int main() static_assert(not sqlpp::null_is_trivial_value_t::value, "t.alpha does not say null_is_trivial"); // Using a non-enforcing db - for (const auto& row : db(select(all_of(t)).from(t).where(true))) + for (const auto& row : db(select(all_of(t), t.beta.like("")).from(t).where(true))) { static_assert(sqlpp::can_be_null_t::value, "row.alpha can be null"); static_assert(sqlpp::null_is_trivial_value_t::value, "row.alpha interprets null_is_trivial"); From b15fa64c55f71da26ffbd12dd930ca09a524e4db Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 1 Sep 2014 12:08:47 +0200 Subject: [PATCH 38/52] Added missing include --- include/sqlpp11/insert_value_list.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index 7de1aa17..8f07b51e 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace sqlpp { @@ -380,6 +381,7 @@ namespace sqlpp -> _new_statement_t> { static_assert(not std::is_same<_database_t, void>::value, "dynamic_set must not be called in a static statement"); + static_assert(detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); return _set_impl<_database_t>(assignments...); } private: @@ -387,7 +389,6 @@ namespace sqlpp auto _set_impl(Assignments... assignments) const -> _new_statement_t> { - static_assert(detail::all_t::value...>::value, "at least one argument is not an assignment in set()"); static_assert(not detail::has_duplicates...>::value, "at least one duplicate column detected in set()"); static_assert(detail::none_t>::value...>::value, "at least one assignment is prohibited by its column definition in set()"); From c227d46cf462cb8e15b12962867a30150d9ce51f Mon Sep 17 00:00:00 2001 From: Markus Elfring Date: Mon, 1 Sep 2014 19:17:03 +0200 Subject: [PATCH 39/52] Bug #14: Completed quoting for parameters of some CMake commands A wiki article pointed out that whitespace will only be preserved for parameters in CMake commands if passed strings will be appropriately quoted or escaped. http://cmake.org/Wiki/CMake/Language_Syntax#CMake_splits_arguments_unless_you_use_quotation_marks_or_escapes. Quoting was added so that more places should also handle file names correctly which contain space characters or semicolons eventually. Signed-off-by: Markus Elfring --- CMakeLists.txt | 4 ++-- test_constraints/CMakeLists.txt | 20 ++++++++++---------- tests/CMakeLists.txt | 15 +++++++-------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 556cdf06..34d69400 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,8 +38,8 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") endif () set(include_dir "${PROJECT_SOURCE_DIR}/include") -file(GLOB_RECURSE sqlpp_headers ${include_dir}/*.h) -include_directories(${include_dir}) +file(GLOB_RECURSE sqlpp_headers "${include_dir}/*.h") +include_directories("${include_dir}") add_subdirectory(tests) add_subdirectory(test_constraints) diff --git a/test_constraints/CMakeLists.txt b/test_constraints/CMakeLists.txt index aec592e4..55255498 100644 --- a/test_constraints/CMakeLists.txt +++ b/test_constraints/CMakeLists.txt @@ -1,26 +1,26 @@ -include_directories(${CMAKE_SOURCE_DIR}/tests) +include_directories("${CMAKE_SOURCE_DIR}/tests") add_custom_target(test_sqlpp_constraints COMMAND true) function(test_constraint name pattern) add_executable( - ${name} + "${name}" EXCLUDE_FROM_ALL - ${name}.cpp + "${name}.cpp" ) - add_custom_command(OUTPUT ${name}.out - COMMAND ${CMAKE_MAKE_PROGRAM} ${name} > ${CMAKE_CURRENT_BINARY_DIR}/${name}.out 2>&1 || true - COMMAND grep ${pattern} ${CMAKE_CURRENT_BINARY_DIR}/${name}.out > /dev/null - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp + add_custom_command(OUTPUT "${name}.out" + COMMAND "${CMAKE_MAKE_PROGRAM}" "${name}" > "${CMAKE_CURRENT_BINARY_DIR}/${name}.out" 2>&1 || true + COMMAND grep "${pattern}" "${CMAKE_CURRENT_BINARY_DIR}/${name}.out" > /dev/null + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp" COMMENT "${name}" - ) + VERBATIM) - add_custom_target(test_${name} DEPENDS ${name}.out COMMAND true) + add_custom_target("test_${name}" DEPENDS "${name}.out" COMMAND true) - add_dependencies(test_sqlpp_constraints test_${name}) + add_dependencies(test_sqlpp_constraints "test_${name}") endfunction(test_constraint) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6582425b..86462e61 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,9 +1,9 @@ macro (build_and_run arg) # Add headers to sources to enable file browsing in IDEs - include_directories(${CMAKE_BINARY_DIR}/tests) - add_executable(${arg} ${arg}.cpp ${sqlpp_headers} ${CMAKE_CURRENT_LIST_DIR}/Sample.h) - add_test(${arg} ${arg}) + include_directories("${CMAKE_BINARY_DIR}/tests") + add_executable("${arg}" "${arg}.cpp" ${sqlpp_headers} "${CMAKE_CURRENT_LIST_DIR}/Sample.h") + add_test("${arg}" "${arg}") endmacro () build_and_run(BooleanExpressionTest) @@ -21,8 +21,7 @@ build_and_run(ResultTest) # if you want to use the generator, you can do something like this: #find_package(PythonInterp REQUIRED) #add_custom_command( -# OUTPUT ${CMAKE_CURRENT_LIST_DIR}/Sample.h -# COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/ddl2cpp ${CMAKE_CURRENT_LIST_DIR}/sample.sql Sample test -# DEPENDS ${CMAKE_CURRENT_LIST_DIR}/sample.sql -# ) - +# OUTPUT "${CMAKE_CURRENT_LIST_DIR}/Sample.h" +# COMMAND "${PYTHON_EXECUTABLE}" "${CMAKE_SOURCE_DIR}/scripts/ddl2cpp" "${CMAKE_CURRENT_LIST_DIR}/sample.sql" Sample test +# DEPENDS "${CMAKE_CURRENT_LIST_DIR}/sample.sql" +# VERBATIM) From f31d28d413ce4f5a8f30024c158e8a848f8c932c Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 4 Sep 2014 22:50:55 +0200 Subject: [PATCH 40/52] Added open content --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b8d6ebe..7e3020ed 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,11 @@ A type safe embedded domain specific language for SQL queries and results in C++ Extensive documentation is found in the wiki, https://github.com/rbock/sqlpp11/wiki -Upcoming talks at +Upcoming talks/workshops) at * CppCon (Bellevue, Washington, USA): http://cppcon.org - * 2014-09-11: http://sched.co/1r4lue3 + * 2014-09-08: http://sched.co/1qhngYK (Workshop Part 1) + * 2014-09-11: http://sched.co/1r4lue3 (Talk) + * 2014-09-12: http://sched.co/Wi8aWM (Workshop Part 2) * MeetingC++ (Berlin, Germany): http://meetingcpp.com/index.php/mcpp2014.html * 2014-12-05:http://meetingcpp.com/index.php/tv14/items/4.html From 10fa8693ccec3410ab396eb6a8e5d1e7e952c36b Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 6 Sep 2014 04:16:22 +0200 Subject: [PATCH 41/52] Minor fix (less error spew for 'like') --- include/sqlpp11/like.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index d20d8691..8125e602 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -41,9 +41,6 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits; - static_assert(is_text_t::value, "Operand for like() has to be a text"); - static_assert(is_text_t::value, "Pattern for like() has to be a text"); - struct _name_t { static constexpr const char* _get_name() { return "LIKE"; } From 9c048786fd82ca0bb0d1bf5f031dead78d6d005a Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 6 Sep 2014 04:18:15 +0200 Subject: [PATCH 42/52] Added a few examples --- CMakeLists.txt | 1 + examples/CMakeLists.txt | 22 +++++ examples/Sample.h | 142 ++++++++++++++++++++++++++++++++ examples/TabSample.h | 177 ++++++++++++++++++++++++++++++++++++++++ examples/insert.cpp | 52 ++++++++++++ examples/remove.cpp | 40 +++++++++ examples/sample.cpp | 59 ++++++++++++++ examples/sample.sql | 40 +++++++++ examples/select.cpp | 134 ++++++++++++++++++++++++++++++ examples/update.cpp | 38 +++++++++ 10 files changed, 705 insertions(+) create mode 100644 examples/CMakeLists.txt create mode 100644 examples/Sample.h create mode 100644 examples/TabSample.h create mode 100644 examples/insert.cpp create mode 100644 examples/remove.cpp create mode 100644 examples/sample.cpp create mode 100644 examples/sample.sql create mode 100644 examples/select.cpp create mode 100644 examples/update.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 556cdf06..a31fbbc7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ file(GLOB_RECURSE sqlpp_headers ${include_dir}/*.h) include_directories(${include_dir}) add_subdirectory(tests) add_subdirectory(test_constraints) +add_subdirectory(examples) install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/sqlpp11" DESTINATION include) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 00000000..2633d91f --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,22 @@ + +macro (build arg) + # Add headers to sources to enable file browsing in IDEs + include_directories("${CMAKE_BINARY_DIR}/tests") + add_executable("Sqlpp11Example${arg}" "${arg}.cpp" ${sqlpp_headers} "${CMAKE_SOURCE_DIR}/tests/MockDb.h" "${CMAKE_CURRENT_LIST_DIR}/Sample.h") + add_test("${arg}" "${arg}") +endmacro () + +#build(sample) +build(insert) +build(update) +build(remove) +build(select) + +#find_package(PythonInterp REQUIRED) + +#add_custom_command( +# OUTPUT ${CMAKE_CURRENT_LIST_DIR}/Sample.h +# COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/ddl2cpp ${CMAKE_CURRENT_LIST_DIR}/sample.sql Sample test +# DEPENDS ${CMAKE_CURRENT_LIST_DIR}/sample.sql +# ) + diff --git a/examples/Sample.h b/examples/Sample.h new file mode 100644 index 00000000..43aa3dc2 --- /dev/null +++ b/examples/Sample.h @@ -0,0 +1,142 @@ +#ifndef TEST_SAMPLE_H +#define TEST_SAMPLE_H + +#include +#include + +namespace test +{ + namespace TabPerson_ + { + struct Id + { + struct _name_t + { + static constexpr const char* _get_name() { return "id"; } + template + struct _member_t + { + T id; + T& operator()() { return id; } + const T& operator()() const { return id; } + }; + }; + using _traits = sqlpp::make_traits; + }; + struct Name + { + struct _name_t + { + static constexpr const char* _get_name() { return "name"; } + template + struct _member_t + { + T name; + T& operator()() { return name; } + const T& operator()() const { return name; } + }; + }; + using _traits = sqlpp::make_traits; + }; + struct Feature + { + struct _name_t + { + static constexpr const char* _get_name() { return "feature"; } + template + struct _member_t + { + T feature; + T& operator()() { return feature; } + const T& operator()() const { return feature; } + }; + }; + using _traits = sqlpp::make_traits; + }; + } + + struct TabPerson: sqlpp::table_t + { + struct _name_t + { + static constexpr const char* _get_name() { return "tab_person"; } + template + struct _member_t + { + T tabPerson; + T& operator()() { return tabPerson; } + const T& operator()() const { return tabPerson; } + }; + }; + }; + namespace TabFeature_ + { + struct Id + { + struct _name_t + { + static constexpr const char* _get_name() { return "id"; } + template + struct _member_t + { + T id; + T& operator()() { return id; } + const T& operator()() const { return id; } + }; + }; + using _traits = sqlpp::make_traits; + }; + struct Name + { + struct _name_t + { + static constexpr const char* _get_name() { return "name"; } + template + struct _member_t + { + T name; + T& operator()() { return name; } + const T& operator()() const { return name; } + }; + }; + using _traits = sqlpp::make_traits; + }; + struct Fatal + { + struct _name_t + { + static constexpr const char* _get_name() { return "fatal"; } + template + struct _member_t + { + T fatal; + T& operator()() { return fatal; } + const T& operator()() const { return fatal; } + }; + }; + using _traits = sqlpp::make_traits; + }; + } + + struct TabFeature: sqlpp::table_t + { + struct _name_t + { + static constexpr const char* _get_name() { return "tab_feature"; } + template + struct _member_t + { + T tabFeature; + T& operator()() { return tabFeature; } + const T& operator()() const { return tabFeature; } + }; + }; + }; +} +#endif diff --git a/examples/TabSample.h b/examples/TabSample.h new file mode 100644 index 00000000..377f9c2f --- /dev/null +++ b/examples/TabSample.h @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2013-2014, 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 + * 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. + */ + +#ifndef SQLPP_TAB_SAMPLE_H +#define SQLPP_TAB_SAMPLE_H + +#include +#include + + +namespace TabFoo_ +{ + struct Omega + { + struct _name_t + { + static constexpr const char* _get_name() { return "omega"; } + }; + template + struct _member_t + { + /* + template + _name_t(TT&&... t): omega(std::forward(t)...) {} + + template + _name_t& operator=(TT&& t) { omega = std::forward(t); return *this; } + */ + + T omega; + }; + using _value_type = sqlpp::bigint; + struct _column_type + { + }; + }; +} + +struct TabFoo: sqlpp::table_base_t< + TabFoo, + TabFoo_::Omega + > +{ + using _value_type = sqlpp::no_value_t; + struct _name_t + { + static constexpr const char* _get_name() { return "tab_foo"; } + }; + template + struct _member_t + { + T tabFoo; + }; + template + void serialize(std::ostream& os, Db& db) const + { + os << _name_t::_get_name(); + } +}; + +namespace TabSample_ +{ + struct Alpha + { + struct _name_t + { + static constexpr const char* _get_name() { return "alpha"; } + }; + template + struct _member_t + { + /* + template + _name_t(TT&&... t): alpha(std::forward(t)...) {} + + template + _name_t& operator=(TT&& t) { alpha = std::forward(t); return *this; } + */ + + T alpha; + }; + using _value_type = sqlpp::bigint; + struct _column_type + { + using _must_not_insert = sqlpp::tag_yes; + using _must_not_update = sqlpp::tag_yes; + using _can_be_null = sqlpp::tag_yes; + using _foreign_key = decltype(TabFoo::omega); + }; + }; + + struct Beta + { + struct _name_t + { + static constexpr const char* _get_name() { return "beta"; } + }; + template + struct _member_t + { + T beta; + }; + using _value_type = sqlpp::varchar; + struct _column_type + { + using _can_be_null = sqlpp::tag_yes; + using _must_not_update = sqlpp::tag_yes; + }; + }; + + struct Gamma + { + struct _name_t + { + static constexpr const char* _get_name() { return "gamma"; } + }; + template + struct _member_t + { + T gamma; + }; + using _value_type = sqlpp::boolean; + struct _column_type + { + using _require_insert = sqlpp::tag_yes; + }; + }; +} + +struct TabSample: sqlpp::table_base_t< + TabSample, + TabSample_::Alpha, + TabSample_::Beta, + TabSample_::Gamma + > +{ + using _value_type = sqlpp::no_value_t; + struct _name_t + { + static constexpr const char* _get_name() { return "tab_sample"; } + }; + template + struct _member_t + { + T tabSample; + }; + template + void serialize(std::ostream& os, Db& db) const + { + os << _name_t::_get_name(); + } +}; + +#endif diff --git a/examples/insert.cpp b/examples/insert.cpp new file mode 100644 index 00000000..70bf3109 --- /dev/null +++ b/examples/insert.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2014, 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 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. + */ + +#include "Sample.h" +#include "MockDb.h" +#include + +MockDb db; + +test::TabPerson p; +test::TabFeature f; + +int main() +{ + db(insert_into(f).set(f.name = "loves c++", f.fatal = false)); + + 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 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); +} diff --git a/examples/remove.cpp b/examples/remove.cpp new file mode 100644 index 00000000..49b93799 --- /dev/null +++ b/examples/remove.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014, 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 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. + */ + +#include "Sample.h" +#include "MockDb.h" +#include + +MockDb db; + +test::TabPerson p; +test::TabFeature q; + +int main() +{ + db(remove_from(p) + .using_(p, q) + .where(p.feature == q.id and q.fatal == true)); +} diff --git a/examples/sample.cpp b/examples/sample.cpp new file mode 100644 index 00000000..5328df05 --- /dev/null +++ b/examples/sample.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014, 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 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. + */ + +#include "Sample.h" +#include "MockDb.h" +#include + +MockDb db; + +test::TabPerson p; +test::TabFeature f; + +int main() +{ + db(insert_into(f).set(f.name = "Loves C++", p.fatal = false)); + + 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 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/sample.sql b/examples/sample.sql new file mode 100644 index 00000000..adc255d6 --- /dev/null +++ b/examples/sample.sql @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013, 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 + * 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. + */ + +CREATE TABLE tab_person +( + id int AUTO_INCREMENT PRIMARY KEY, + name varchar(255) NOT NULL, + feature int NOT NULL +); + +CREATE TABLE tab_feature +( + id int AUTO_INCREMENT PRIMARY KEY, + name varchar(255) NULL DEFAULT "", + fatal bool NOT NULL +); + diff --git a/examples/select.cpp b/examples/select.cpp new file mode 100644 index 00000000..b56ba61b --- /dev/null +++ b/examples/select.cpp @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2014, 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 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. + */ + +#if defined(__clang__) +#pragma clang diagnostic ignored "-Wunused-variable" +#endif +#if defined(__GNUC__) +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif + +#include "Sample.h" +#include "MockDb.h" +#include + + +MockDb db; + +test::TabPerson p; +test::TabFeature f; + +int main() +{ + for (const auto& row : db(select(all_of(p)).from(p).where(true))) + { + int64_t id = row.id; + std::string name = row.name; + int64_t feature = row.feature; + } + + +#if 0 + for (const auto& row : db(select(p.name).from(p).where(true))) + { + int64_t id = row.id; + std::string name = row.name; + int64_t feature = row.feature; + } +#endif + + + +#if 0 + for (const auto& row : db(select(p.name, f.name).from(p,f).where(true))) + { + //int64_t id = row.id; + //std::string a = row.a; + std::string name = row.name; + //int64_t feature = row.feature; + } +#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))) + { + //int64_t id = row.id; + //std::string a = row.a; + std::string name = row.tabPerson.name; + std::string name1 = row.tabFeature.name; + //int64_t feature = row.feature; + } +#endif + + + + + + + +#if 0 + auto s = select(all_of(p)) + .from(p, f) + .where(p.name == any(select(f.name) + .from(f) + .where(true))) + .group_by(f.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; + } +#endif + + + + + + + + + + + + + + + + + + + + + +} diff --git a/examples/update.cpp b/examples/update.cpp new file mode 100644 index 00000000..82ffa37e --- /dev/null +++ b/examples/update.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2014, 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 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. + */ + +#include "Sample.h" +#include "MockDb.h" +#include + +MockDb db; + +test::TabPerson p; +test::TabFeature q; + +int main() +{ + db(update(p).set(p.feature = 7).where(p.id == 23)); +} From 400f79b79c0fef035aa3092dd507415176784048 Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 6 Sep 2014 06:14:44 +0200 Subject: [PATCH 43/52] Added a few bad examples (commented) --- examples/insert.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples/insert.cpp b/examples/insert.cpp index 70bf3109..5c79d5f9 100644 --- a/examples/insert.cpp +++ b/examples/insert.cpp @@ -36,6 +36,21 @@ int main() { 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.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(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.name = "loves c++")); + + db(insert_into(f).default_values()); auto i = insert_into(p).columns(p.name, p.feature); From 88bd56ff2dc8590547504d92707ce1a227932bd7 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sat, 6 Sep 2014 06:18:18 +0200 Subject: [PATCH 44/52] Fixed include path --- examples/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2633d91f..1ab2fd65 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,7 +1,7 @@ macro (build arg) # Add headers to sources to enable file browsing in IDEs - include_directories("${CMAKE_BINARY_DIR}/tests") + include_directories("${CMAKE_SOURCE_DIR}/tests") add_executable("Sqlpp11Example${arg}" "${arg}.cpp" ${sqlpp_headers} "${CMAKE_SOURCE_DIR}/tests/MockDb.h" "${CMAKE_CURRENT_LIST_DIR}/Sample.h") add_test("${arg}" "${arg}") endmacro () From 3cab459077a1419a106f57810827ec97864c0c76 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 17 Sep 2014 22:22:45 +0200 Subject: [PATCH 45/52] Added tag to indicate that an expression contains an aggregate function --- examples/select.cpp | 11 ++- include/sqlpp11/avg.h | 4 +- include/sqlpp11/column.h | 4 +- include/sqlpp11/count.h | 14 ++- include/sqlpp11/extra_tables.h | 2 +- include/sqlpp11/join.h | 4 +- include/sqlpp11/max.h | 3 +- include/sqlpp11/min.h | 3 +- include/sqlpp11/on.h | 1 - include/sqlpp11/parameter.h | 2 +- include/sqlpp11/result_field_methods.h | 4 +- include/sqlpp11/statement.h | 16 ++-- include/sqlpp11/sum.h | 4 +- include/sqlpp11/table.h | 2 +- include/sqlpp11/table_alias.h | 2 +- include/sqlpp11/type_traits.h | 125 +++++++++++-------------- include/sqlpp11/verbatim.h | 2 +- test_constraints/CMakeLists.txt | 1 + test_constraints/count_of_count.cpp | 38 ++++++++ 19 files changed, 147 insertions(+), 95 deletions(-) create mode 100644 test_constraints/count_of_count.cpp diff --git a/examples/select.cpp b/examples/select.cpp index b56ba61b..3bcba136 100644 --- a/examples/select.cpp +++ b/examples/select.cpp @@ -34,6 +34,7 @@ #include "MockDb.h" #include +SQLPP_ALIAS_PROVIDER(cheesecake); MockDb db; @@ -42,7 +43,7 @@ test::TabFeature f; int main() { - for (const auto& row : db(select(all_of(p)).from(p).where(true))) + 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; @@ -51,7 +52,7 @@ int main() #if 0 - for (const auto& row : db(select(p.name).from(p).where(true))) + for (const auto& row : db(select(p.name).from(p).where(p.name.like("Herb%")))) { int64_t id = row.id; std::string name = row.name; @@ -62,12 +63,12 @@ int main() #if 0 - for (const auto& row : db(select(p.name, f.name).from(p,f).where(true))) + for (const auto& row : db(select(p.name, f.name.as(cheesecake)).from(p,f).where(p.id > 7 and p.feature == 3))) { //int64_t id = row.id; //std::string a = row.a; std::string name = row.name; - //int64_t feature = row.feature; + std::string feature = row.cheesecake; } #endif @@ -90,7 +91,7 @@ int main() -#if 0 +#if !0 auto s = select(all_of(p)) .from(p, f) .where(p.name == any(select(f.name) diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h index 4b879ef8..52ae5652 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/avg.h @@ -37,7 +37,7 @@ namespace sqlpp public alias_operators> { using _traits = make_traits; - using _recursive_traits = make_recursive_traits; + using _recursive_traits = make_recursive_traits; 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"); @@ -89,6 +89,7 @@ namespace sqlpp 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 }; } @@ -96,6 +97,7 @@ namespace sqlpp 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 }; } diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 31c9382b..22b5d977 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -59,7 +59,9 @@ namespace sqlpp using _provided_outer_tables = detail::type_set<>; using _required_tables = detail::type_set
; using _extra_tables = detail::type_set<>; - using _can_be_null = column_spec_can_be_null_t; + using _tags = typename std::conditional::value, + detail::type_set, + detail::type_set<>>::type; }; using _spec_t = ColumnSpec; diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 2ed9766d..3dee29ac 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -38,7 +38,17 @@ namespace sqlpp public alias_operators> { using _traits = make_traits; - using _recursive_traits = make_recursive_traits; + struct _recursive_traits + { + using _required_tables = required_tables_of; + using _provided_tables = provided_tables_of; + using _provided_outer_tables = provided_outer_tables_of; + using _extra_tables = extra_tables_of; + using _parameters = parameters_of; + using _tags = detail::make_difference_set_t, recursive_tags_of>, + detail::type_set>; + }; + static_assert(is_noop::value or std::is_same::value, "count() used with flag other than 'distinct'"); static_assert(is_expression_t::value, "count() requires a sql expression as argument"); @@ -90,6 +100,7 @@ namespace sqlpp 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 }; } @@ -97,6 +108,7 @@ namespace sqlpp 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 }; } diff --git a/include/sqlpp11/extra_tables.h b/include/sqlpp11/extra_tables.h index 22623b0d..d2fe8a73 100644 --- a/include/sqlpp11/extra_tables.h +++ b/include/sqlpp11/extra_tables.h @@ -59,7 +59,7 @@ namespace sqlpp using _provided_outer_tables = detail::type_set<>; using _provided_tables = detail::type_set<>; using _extra_tables = detail::type_set; - using _can_be_null = std::false_type; + using _tags = detail::type_set<>; }; // FIXME: extra_tables must not require tables! diff --git a/include/sqlpp11/join.h b/include/sqlpp11/join.h index 30a3db7b..e7b444a7 100644 --- a/include/sqlpp11/join.h +++ b/include/sqlpp11/join.h @@ -73,7 +73,7 @@ namespace sqlpp using _provided_outer_tables = typename JoinType::template _provided_outer_tables; using _extra_tables = detail::make_joined_set_t, extra_tables_of>; using _parameters = detail::make_parameter_tuple_t, parameters_of>; - using _can_be_null = std::false_type; + using _tags = detail::type_set<>; }; @@ -94,6 +94,8 @@ namespace sqlpp -> set_on_t> { static_assert(is_noop::value, "cannot call on() twice for a single join()"); + static_assert(detail::all_t::value...>::value, "at least one argument is not an expression in on()"); + return { _lhs, _rhs, {std::tuple{expr...}} diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index 8f0f8fb3..95b182a5 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -37,7 +37,7 @@ namespace sqlpp public alias_operators> { using _traits = make_traits, tag::is_expression, tag::is_named_expression>; - using _recursive_traits = make_recursive_traits; + using _recursive_traits = make_recursive_traits; static_assert(is_expression_t::value, "max() requires a value expression as argument"); @@ -83,6 +83,7 @@ namespace sqlpp template auto max(T t) -> max_t> { + static_assert(not contains_aggregate_function_t>::value, "max() cannot be used on an aggregate function"); static_assert(is_expression_t>::value, "max() requires a value expression as argument"); return { t }; } diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index 7846d763..27c923ad 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -37,7 +37,7 @@ namespace sqlpp public alias_operators> { using _traits = make_traits, tag::is_expression, tag::is_named_expression>; - using _recursive_traits = make_recursive_traits; + using _recursive_traits = make_recursive_traits; static_assert(is_expression_t::value, "min() requires a value expression as argument"); @@ -83,6 +83,7 @@ namespace sqlpp template auto min(T t) -> min_t> { + static_assert(not contains_aggregate_function_t>::value, "min() cannot be used on an aggregate function"); static_assert(is_expression_t>::value, "min() requires a value expression as argument"); return { t }; } diff --git a/include/sqlpp11/on.h b/include/sqlpp11/on.h index 945d90ec..2a88eafb 100644 --- a/include/sqlpp11/on.h +++ b/include/sqlpp11/on.h @@ -43,7 +43,6 @@ namespace sqlpp using _is_dynamic = is_database; static_assert(_is_dynamic::value or sizeof...(Expr), "at least one expression argument required in on()"); - static_assert(detail::all_t::value...>::value, "at least one argument is not an expression in on()"); template void add(E expr) diff --git a/include/sqlpp11/parameter.h b/include/sqlpp11/parameter.h index a789f56f..38f100c1 100644 --- a/include/sqlpp11/parameter.h +++ b/include/sqlpp11/parameter.h @@ -45,7 +45,7 @@ namespace sqlpp using _provided_outer_tables = detail::type_set<>; using _required_tables = detail::type_set<>; using _extra_tables = detail::type_set<>; - using _can_be_null = std::true_type; + using _tags = detail::type_set; }; using _instance_t = member_t>; diff --git a/include/sqlpp11/result_field_methods.h b/include/sqlpp11/result_field_methods.h index 54492a38..5829ba91 100644 --- a/include/sqlpp11/result_field_methods.h +++ b/include/sqlpp11/result_field_methods.h @@ -88,7 +88,9 @@ namespace sqlpp using _provided_outer_tables = detail::type_set<>; using _required_tables = detail::type_set<>; using _extra_tables = detail::type_set<>; - using _can_be_null = column_spec_can_be_null_t<_field_spec_t>; + using _tags = typename std::conditional::value, + detail::type_set, + detail::type_set<>>::type; }; }; diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index e7a3778e..81c376ea 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -98,6 +98,13 @@ namespace sqlpp no_value_t // if a required statement part is missing (e.g. columns in a select), then the statement cannot be used as a value >::type; + using _can_be_null = detail::any_t< + can_be_null_t<_result_type_provider>::value, + detail::make_intersect_set_t< + required_tables_of<_result_type_provider>, + _all_provided_outer_tables + >::size::value != 0>; + using _traits = make_traits<_value_type, tag_if::value>>; struct _recursive_traits @@ -107,12 +114,9 @@ namespace sqlpp using _provided_outer_tables = detail::type_set<>; using _extra_tables = detail::type_set<>; using _parameters = detail::make_parameter_tuple_t...>; - using _can_be_null = detail::any_t< - can_be_null_t<_result_type_provider>::value, - detail::make_intersect_set_t< - required_tables_of<_result_type_provider>, - provided_outer_tables_of - >::size::value != 0>; + using _tags = typename std::conditional<_can_be_null::value, + detail::type_set, + detail::type_set<>>::type; }; }; } diff --git a/include/sqlpp11/sum.h b/include/sqlpp11/sum.h index 468ac230..0a5679a1 100644 --- a/include/sqlpp11/sum.h +++ b/include/sqlpp11/sum.h @@ -37,7 +37,7 @@ namespace sqlpp public alias_operators> { using _traits = make_traits, tag::is_expression, tag::is_named_expression>; - using _recursive_traits = make_recursive_traits; + using _recursive_traits = make_recursive_traits; static_assert(is_noop::value or std::is_same::value, "sum() used with flag other than 'distinct'"); static_assert(is_numeric_t::value, "sum() requires a numeric expression as argument"); @@ -89,6 +89,7 @@ namespace sqlpp template auto sum(T t) -> sum_t> { + static_assert(not contains_aggregate_function_t>::value, "sum() cannot be used on an aggregate function"); static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); return { t }; } @@ -96,6 +97,7 @@ namespace sqlpp template auto sum(const distinct_t&, T t) -> sum_t> { + static_assert(not contains_aggregate_function_t>::value, "sum() cannot be used on an aggregate function"); static_assert(is_numeric_t>::value, "sum() requires a numeric expression as argument"); return { t }; } diff --git a/include/sqlpp11/table.h b/include/sqlpp11/table.h index 3c370279..a90605be 100644 --- a/include/sqlpp11/table.h +++ b/include/sqlpp11/table.h @@ -53,7 +53,7 @@ namespace sqlpp using _provided_tables = detail::type_set
; using _provided_outer_tables = detail::type_set<>; using _extra_tables = detail::type_set<>; - using _can_be_null = std::false_type; + using _tags = detail::type_set<>; }; static_assert(sizeof...(ColumnSpec), "at least one column required per table"); diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index aa95cd83..28425f10 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -49,7 +49,7 @@ namespace sqlpp using _provided_tables = detail::type_set; using _provided_outer_tables = detail::type_set<>; using _extra_tables = detail::type_set<>; - using _can_be_null = std::false_type; + using _tags = detail::type_set<>; }; static_assert(required_tables_of
::size::value == 0, "table aliases must not depend on external tables"); diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index 99d12c22..cfc54987 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -32,28 +32,40 @@ namespace sqlpp { + namespace tag + { + struct can_be_null{}; + struct contains_aggregate_function{}; + }; + namespace detail { template struct can_be_null_impl { using type = std::false_type; }; template - struct can_be_null_impl::type> { using type = std::true_type; }; + struct can_be_null_impl::value>::type> { using type = std::true_type; }; } template using can_be_null_t = typename detail::can_be_null_impl::type; - namespace tag\ - {\ - struct can_be_null{};\ - };\ - namespace detail\ - {\ - template\ - struct column_spec_can_be_null_impl { using type = std::false_type; };\ - template\ - struct column_spec_can_be_null_impl::value>::type> { using type = std::true_type; };\ - }\ - template\ + namespace detail + { + template + struct contains_aggregate_function_impl { using type = std::false_type; }; + template + struct contains_aggregate_function_impl::value>::type> { using type = std::true_type; }; + } + template + using contains_aggregate_function_t = typename detail::contains_aggregate_function_impl::type; + + namespace detail + { + template + struct column_spec_can_be_null_impl { using type = std::false_type; }; + template + struct column_spec_can_be_null_impl::value>::type> { using type = std::true_type; }; + } + template using column_spec_can_be_null_t = typename detail::column_spec_can_be_null_impl::type; #define SQLPP_VALUE_TRAIT_GENERATOR(name) \ @@ -140,80 +152,35 @@ namespace sqlpp namespace detail { - template - struct value_type_of_impl - { - using type = typename T::_traits::_value_type; - }; - - template - struct required_table_of_impl - { - using type = typename T::_recursive_traits::_required_tables; - }; - - template - struct provided_table_of_impl - { - using type = typename T::_recursive_traits::_provided_tables; - }; - - template - struct provided_outer_table_of_impl - { - using type = typename T::_recursive_traits::_provided_outer_tables; - }; - - template - struct extra_table_of_impl - { - using type = typename T::_recursive_traits::_extra_tables; - }; - - template - struct parameters_of_impl - { - using type = typename T::_recursive_traits::_parameters; - }; - - template - struct name_of_impl - { - using type = typename T::_name_t; - }; - template - struct make_parameter_tuple_impl - { - using type = decltype(std::tuple_cat(std::declval()...)); - }; - - template - using make_parameter_tuple_t = typename make_parameter_tuple_impl::type; + using make_parameter_tuple_t = decltype(std::tuple_cat(std::declval()...)); } template - using value_type_of = typename detail::value_type_of_impl::type; + using value_type_of = typename T::_traits::_value_type; template using cpp_value_type_of = typename value_type_of::_cpp_value_type; template - using required_tables_of = typename detail::required_table_of_impl::type; + using required_tables_of = typename T::_recursive_traits::_required_tables; template - using provided_tables_of = typename detail::provided_table_of_impl::type; + using provided_tables_of = typename T::_recursive_traits::_provided_tables; template - using provided_outer_tables_of = typename detail::provided_outer_table_of_impl::type; + using provided_outer_tables_of = typename T::_recursive_traits::_provided_outer_tables; template - using extra_tables_of = typename detail::extra_table_of_impl::type; + using extra_tables_of = typename T::_recursive_traits::_extra_tables; template - using parameters_of = typename detail::parameters_of_impl::type; + using parameters_of = typename T::_recursive_traits::_parameters; template - using name_of = typename detail::name_of_impl::type; + using recursive_tags_of = typename T::_recursive_traits::_tags; + + template + using name_of = typename T::_name_t; template struct make_traits @@ -221,6 +188,7 @@ namespace sqlpp using _value_type = ValueType; using _tags = detail::make_type_set_t; }; + template struct make_recursive_traits { @@ -229,9 +197,26 @@ namespace sqlpp using _provided_outer_tables = detail::make_joined_set_t...>; using _extra_tables = detail::make_joined_set_t...>; using _parameters = detail::make_parameter_tuple_t...>; - using _can_be_null = detail::any_t::value...>; + using _tags = detail::make_joined_set_t...>; }; + template + struct recursive_tags + { + using _required_tables = detail::type_set<>; + using _provided_tables = detail::type_set<>; + using _provided_outer_tables = detail::type_set<>; + using _extra_tables = detail::type_set<>; + using _parameters = std::tuple<>; + using _tags = detail::type_set; + }; + + struct aggregate_function + { + struct _traits { using _value_type = void; using _tags = detail::type_set<>; }; + using _recursive_traits = recursive_tags; + }; + template using member_t = typename NameProvider::_name_t::template _member_t; diff --git a/include/sqlpp11/verbatim.h b/include/sqlpp11/verbatim.h index 0ea6c61a..d1b43006 100644 --- a/include/sqlpp11/verbatim.h +++ b/include/sqlpp11/verbatim.h @@ -40,7 +40,7 @@ namespace sqlpp using _traits = make_traits; struct _recursive_traits : public make_recursive_traits<> { - using _can_be_null = std::true_type; // since we do not know what's going on inside the verbatim, we assume it can be null + using _tags = detail::type_set; // since we do not know what's going on inside the verbatim, we assume it can be null }; verbatim_t(std::string verbatim): _verbatim(verbatim) {} diff --git a/test_constraints/CMakeLists.txt b/test_constraints/CMakeLists.txt index aec592e4..cfa55c46 100644 --- a/test_constraints/CMakeLists.txt +++ b/test_constraints/CMakeLists.txt @@ -24,6 +24,7 @@ function(test_constraint name pattern) endfunction(test_constraint) +test_constraint(count_of_count "cannot be used on an aggregate function") test_constraint(no_conversion_operator_if_null_not_trivial "int i = row.alpha") test_constraint(require_insert "required column is missing") test_constraint(must_not_insert "one assignment is prohibited") diff --git a/test_constraints/count_of_count.cpp b/test_constraints/count_of_count.cpp new file mode 100644 index 00000000..95f089db --- /dev/null +++ b/test_constraints/count_of_count.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013-2014, 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 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. + */ + +#include "Sample.h" +#include "MockDb.h" +#include +#include + +MockDb db; + +int main() +{ + test::TabBar t; + + count(count(t.alpha)); +} From 6dbdd39ce18bb096dfe9f024e6aff0e169f5c44d Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 17 Sep 2014 23:03:51 +0200 Subject: [PATCH 46/52] Ensure that expression do not contain aggregate functions --- include/sqlpp11/count.h | 3 --- include/sqlpp11/max.h | 5 +---- include/sqlpp11/min.h | 5 +---- include/sqlpp11/type_traits.h | 18 +++++++++++++++- test_constraints/CMakeLists.txt | 3 ++- test_constraints/max_of_max.cpp | 38 +++++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 test_constraints/max_of_max.cpp diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index 3dee29ac..c937120f 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -51,7 +51,6 @@ namespace sqlpp static_assert(is_noop::value or std::is_same::value, "count() used with flag other than 'distinct'"); - static_assert(is_expression_t::value, "count() requires a sql expression as argument"); struct _name_t { @@ -100,7 +99,6 @@ namespace sqlpp 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 }; } @@ -108,7 +106,6 @@ namespace sqlpp 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 }; } diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index 95b182a5..fbe971da 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -39,8 +39,6 @@ namespace sqlpp using _traits = make_traits, tag::is_expression, tag::is_named_expression>; using _recursive_traits = make_recursive_traits; - static_assert(is_expression_t::value, "max() requires a value expression as argument"); - struct _name_t { static constexpr const char* _get_name() { return "MAX"; } @@ -83,8 +81,7 @@ namespace sqlpp template auto max(T t) -> max_t> { - static_assert(not contains_aggregate_function_t>::value, "max() cannot be used on an aggregate function"); - static_assert(is_expression_t>::value, "max() requires a value expression as argument"); + static_assert(is_expression_t>::value, "max() requires an expression as argument"); return { t }; } diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index 27c923ad..356a6763 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -39,8 +39,6 @@ namespace sqlpp using _traits = make_traits, tag::is_expression, tag::is_named_expression>; using _recursive_traits = make_recursive_traits; - static_assert(is_expression_t::value, "min() requires a value expression as argument"); - struct _name_t { static constexpr const char* _get_name() { return "MIN"; } @@ -83,8 +81,7 @@ namespace sqlpp template auto min(T t) -> min_t> { - static_assert(not contains_aggregate_function_t>::value, "min() cannot be used on an aggregate function"); - static_assert(is_expression_t>::value, "min() requires a value expression as argument"); + static_assert(is_expression_t>::value, "min() requires an expression as argument"); return { t }; } diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index cfc54987..a75e4329 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -68,6 +68,23 @@ namespace sqlpp template using column_spec_can_be_null_t = typename detail::column_spec_can_be_null_impl::type; + namespace tag + { + struct is_expression{}; + }; + namespace detail + { + template + struct is_expression_impl { using type = std::false_type; }; + template + struct is_expression_impl::value + and not detail::is_element_of::value + >::type> { using type = std::true_type; }; + } + template + using is_expression_t = typename detail::is_expression_impl::type; + #define SQLPP_VALUE_TRAIT_GENERATOR(name) \ namespace tag\ {\ @@ -94,7 +111,6 @@ namespace sqlpp detail::is_element_of::value>; SQLPP_VALUE_TRAIT_GENERATOR(is_text); SQLPP_VALUE_TRAIT_GENERATOR(is_wrapped_value); - SQLPP_VALUE_TRAIT_GENERATOR(is_expression); SQLPP_VALUE_TRAIT_GENERATOR(is_named_expression); SQLPP_VALUE_TRAIT_GENERATOR(is_multi_expression); SQLPP_VALUE_TRAIT_GENERATOR(is_alias); diff --git a/test_constraints/CMakeLists.txt b/test_constraints/CMakeLists.txt index cfa55c46..61634af7 100644 --- a/test_constraints/CMakeLists.txt +++ b/test_constraints/CMakeLists.txt @@ -24,7 +24,8 @@ function(test_constraint name pattern) endfunction(test_constraint) -test_constraint(count_of_count "cannot be used on an aggregate function") +test_constraint(count_of_count "requires an expression as argument") +test_constraint(max_of_max "requires an expression as argument") test_constraint(no_conversion_operator_if_null_not_trivial "int i = row.alpha") test_constraint(require_insert "required column is missing") test_constraint(must_not_insert "one assignment is prohibited") diff --git a/test_constraints/max_of_max.cpp b/test_constraints/max_of_max.cpp new file mode 100644 index 00000000..96483e9b --- /dev/null +++ b/test_constraints/max_of_max.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2013-2014, 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 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. + */ + +#include "Sample.h" +#include "MockDb.h" +#include +#include + +MockDb db; + +int main() +{ + test::TabBar t; + + max(max(t.alpha)); +} From 49eb21e7092962048452687396a1db78e21b1d99 Mon Sep 17 00:00:00 2001 From: rbock Date: Thu, 18 Sep 2014 09:40:54 +0200 Subject: [PATCH 47/52] Added test which selects count() --- tests/SelectTest.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index 9fd040af..bbf9a3e5 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -69,6 +69,11 @@ int main() std::cout << row.alpha << std::endl; } + for (const auto& row : db(select(count(t.alpha), avg(t.alpha)).from(t).where(true))) + { + std::cout << row.count << std::endl; + } + auto stat = sqlpp::select().columns(all_of(t)).flags(sqlpp::all).from(t).extra_tables(f,t).where(t.alpha > 0).group_by(t.alpha).order_by(t.gamma.asc()).having(t.gamma).limit(7).offset(19); auto s = dynamic_select(db).dynamic_columns(all_of(t)).dynamic_flags().dynamic_from(t).extra_tables(f,t).dynamic_where().dynamic_group_by(t.alpha).dynamic_order_by().dynamic_having(t.gamma).dynamic_limit().dynamic_offset(); From 7c80a2a6e00d358be4981c3ad55d9f4631417102 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 26 Sep 2014 09:03:26 +0200 Subject: [PATCH 48/52] Renamed named_expression to selectable --- include/sqlpp11/alias.h | 2 +- include/sqlpp11/avg.h | 2 +- include/sqlpp11/column.h | 2 +- include/sqlpp11/concat.h | 2 +- include/sqlpp11/count.h | 2 +- include/sqlpp11/exists.h | 2 +- include/sqlpp11/in.h | 2 +- include/sqlpp11/is_null.h | 7 +- include/sqlpp11/like.h | 2 +- include/sqlpp11/max.h | 2 +- include/sqlpp11/min.h | 2 +- include/sqlpp11/multi_column.h | 8 +- include/sqlpp11/parameter.h | 2 +- include/sqlpp11/select_column_list.h | 8 +- include/sqlpp11/statement.h | 2 +- include/sqlpp11/sum.h | 2 +- include/sqlpp11/table_alias.h | 2 +- include/sqlpp11/type_traits.h | 2 +- tests/FunctionTest.cpp | 116 +++++++++++++-------------- tests/SelectTypeTest.cpp | 30 +++---- 20 files changed, 97 insertions(+), 102 deletions(-) diff --git a/include/sqlpp11/alias.h b/include/sqlpp11/alias.h index 99909bb5..61cccb04 100644 --- a/include/sqlpp11/alias.h +++ b/include/sqlpp11/alias.h @@ -35,7 +35,7 @@ namespace sqlpp template struct expression_alias_t { - using _traits = make_traits, tag::is_named_expression, tag::is_alias>; + using _traits = make_traits, tag::is_selectable, tag::is_alias>; using _recursive_traits = make_recursive_traits; static_assert(is_expression_t::value, "invalid argument for an expression alias"); diff --git a/include/sqlpp11/avg.h b/include/sqlpp11/avg.h index 52ae5652..7fa58409 100644 --- a/include/sqlpp11/avg.h +++ b/include/sqlpp11/avg.h @@ -36,7 +36,7 @@ namespace sqlpp public expression_operators, floating_point>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static_assert(is_noop::value or std::is_same::value, "avg() used with flag other than 'distinct'"); diff --git a/include/sqlpp11/column.h b/include/sqlpp11/column.h index 22b5d977..65f3d88f 100644 --- a/include/sqlpp11/column.h +++ b/include/sqlpp11/column.h @@ -49,7 +49,7 @@ namespace sqlpp struct _traits { using _value_type = value_type_of; - using _tags = detail::make_joined_set_t, typename ColumnSpec::_traits::_tags>; + using _tags = detail::make_joined_set_t, typename ColumnSpec::_traits::_tags>; }; struct _recursive_traits diff --git a/include/sqlpp11/concat.h b/include/sqlpp11/concat.h index d75f4a39..3c37977c 100644 --- a/include/sqlpp11/concat.h +++ b/include/sqlpp11/concat.h @@ -40,7 +40,7 @@ namespace sqlpp public expression_operators, value_type_of>, public alias_operators> { - using _traits = make_traits, tag::is_expression, tag::is_named_expression>; + using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _recursive_traits = make_recursive_traits; static_assert(sizeof...(Args) > 0, "concat requires two arguments at least"); diff --git a/include/sqlpp11/count.h b/include/sqlpp11/count.h index c937120f..95f30467 100644 --- a/include/sqlpp11/count.h +++ b/include/sqlpp11/count.h @@ -37,7 +37,7 @@ namespace sqlpp public expression_operators, integral>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; struct _recursive_traits { using _required_tables = required_tables_of; diff --git a/include/sqlpp11/exists.h b/include/sqlpp11/exists.h index 33e02fd7..d1fe3d89 100644 --- a/include/sqlpp11/exists.h +++ b/include/sqlpp11/exists.h @@ -36,7 +36,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits::value, "exists() requires a select expression as argument"); diff --git a/include/sqlpp11/in.h b/include/sqlpp11/in.h index 57d1e228..e3bf0915 100644 --- a/include/sqlpp11/in.h +++ b/include/sqlpp11/in.h @@ -39,7 +39,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static constexpr bool _inverted = not NotInverted; diff --git a/include/sqlpp11/is_null.h b/include/sqlpp11/is_null.h index f975507f..ecc06bd5 100644 --- a/include/sqlpp11/is_null.h +++ b/include/sqlpp11/is_null.h @@ -38,16 +38,11 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; static constexpr bool _inverted = not NotInverted; - struct _value_type: public boolean - { - using _is_named_expression = std::true_type; - }; - struct _name_t { static constexpr const char* _get_name() { return _inverted ? "IS NOT NULL" : "IS NULL"; } diff --git a/include/sqlpp11/like.h b/include/sqlpp11/like.h index 8125e602..2a73baa3 100644 --- a/include/sqlpp11/like.h +++ b/include/sqlpp11/like.h @@ -38,7 +38,7 @@ namespace sqlpp public expression_operators, boolean>, public alias_operators> { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; struct _name_t diff --git a/include/sqlpp11/max.h b/include/sqlpp11/max.h index fbe971da..440d1f31 100644 --- a/include/sqlpp11/max.h +++ b/include/sqlpp11/max.h @@ -36,7 +36,7 @@ namespace sqlpp public expression_operators, value_type_of>, public alias_operators> { - using _traits = make_traits, tag::is_expression, tag::is_named_expression>; + using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _recursive_traits = make_recursive_traits; struct _name_t diff --git a/include/sqlpp11/min.h b/include/sqlpp11/min.h index 356a6763..e5387d37 100644 --- a/include/sqlpp11/min.h +++ b/include/sqlpp11/min.h @@ -36,7 +36,7 @@ namespace sqlpp public expression_operators, value_type_of>, public alias_operators> { - using _traits = make_traits, tag::is_expression, tag::is_named_expression>; + using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _recursive_traits = make_recursive_traits; struct _name_t diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 5b7763a9..4050968f 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -44,7 +44,7 @@ namespace sqlpp using _traits = make_traits; using _recursive_traits = make_recursive_traits; - static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); + static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); multi_column_t(std::tuple columns): _columns(columns) @@ -76,10 +76,10 @@ namespace sqlpp template struct multi_column_alias_t { - using _traits = make_traits; + using _traits = make_traits; using _recursive_traits = make_recursive_traits; - static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); + static_assert(detail::all_t::value...>::value, "multi_column parameters need to be named expressions"); using _name_t = typename AliasProvider::_name_t; @@ -103,7 +103,7 @@ namespace sqlpp struct _value_type: public no_value_t { - using _is_named_expression = std::true_type; + using _is_selectable = std::true_type; }; using _is_multi_column = std::true_type; diff --git a/include/sqlpp11/parameter.h b/include/sqlpp11/parameter.h index 38f100c1..687096b3 100644 --- a/include/sqlpp11/parameter.h +++ b/include/sqlpp11/parameter.h @@ -76,7 +76,7 @@ namespace sqlpp auto parameter(const NamedExpr&) -> parameter_t, NamedExpr> { - static_assert(is_named_expression_t::value, "not a named expression"); + static_assert(is_selectable_t::value, "not a named expression"); return {}; } diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index d0d4026d..0b77b021 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -54,7 +54,7 @@ namespace sqlpp template struct select_traits { - using _traits = make_traits, tag::is_select_column_list, tag::is_return_value, tag::is_expression, tag::is_named_expression>; + using _traits = make_traits, tag::is_select_column_list, tag::is_return_value, tag::is_expression, tag::is_selectable>; using _name_t = typename Column::_name_t; }; } @@ -161,7 +161,7 @@ namespace sqlpp static_assert(_is_dynamic::value or sizeof...(Columns), "at least one select expression required"); static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected"); - static_assert(detail::all_t<(is_named_expression_t::value or is_multi_column_t::value)...>::value, "at least one argument is not a named expression"); + static_assert(detail::all_t<(is_selectable_t::value or is_multi_column_t::value)...>::value, "at least one argument is not a named expression"); static_assert(not detail::has_duplicates::value, "at least one duplicate name detected"); struct _column_type {}; @@ -183,14 +183,14 @@ namespace sqlpp void add(NamedExpression namedExpression) { static_assert(_is_dynamic::value, "selected_columns::add() can only be called for dynamic_column"); - static_assert(is_named_expression_t::value, "invalid named expression argument in selected_columns::add()"); + static_assert(is_selectable_t::value, "invalid named expression argument in selected_columns::add()"); static_assert(TableCheckRequired::value or Policies::template _no_unknown_tables::value, "named expression uses tables unknown to this statement in selected_columns::add()"); using column_names = detail::make_type_set_t; static_assert(not detail::is_element_of::value, "a column of this name is present in the select already"); using ok = detail::all_t< _is_dynamic::value, - is_named_expression_t::value + is_selectable_t::value >; _add_impl(namedExpression, ok()); // dispatch to prevent compile messages after the static_assert diff --git a/include/sqlpp11/statement.h b/include/sqlpp11/statement.h index 81c376ea..0ba602f6 100644 --- a/include/sqlpp11/statement.h +++ b/include/sqlpp11/statement.h @@ -135,7 +135,7 @@ namespace sqlpp using _traits = make_traits, tag::is_select, tag_if::value>, - tag_if::value>, + tag_if::value>, tag::requires_braces>; using _recursive_traits = typename _policies_t::_recursive_traits; using _used_outer_tables = typename _policies_t::_all_provided_outer_tables; diff --git a/include/sqlpp11/sum.h b/include/sqlpp11/sum.h index 0a5679a1..6a5bf1be 100644 --- a/include/sqlpp11/sum.h +++ b/include/sqlpp11/sum.h @@ -36,7 +36,7 @@ namespace sqlpp public expression_operators, value_type_of>, public alias_operators> { - using _traits = make_traits, tag::is_expression, tag::is_named_expression>; + using _traits = make_traits, tag::is_expression, tag::is_selectable>; using _recursive_traits = make_recursive_traits; static_assert(is_noop::value or std::is_same::value, "sum() used with flag other than 'distinct'"); diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index 28425f10..d35245be 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -40,7 +40,7 @@ namespace sqlpp public member_t>... { //FIXME: Need to add join functionality - using _traits = make_traits, tag::is_table, tag::is_alias, tag_if::value>>; + using _traits = make_traits, tag::is_table, tag::is_alias, tag_if::value>>; struct _recursive_traits { diff --git a/include/sqlpp11/type_traits.h b/include/sqlpp11/type_traits.h index a75e4329..a0714bdc 100644 --- a/include/sqlpp11/type_traits.h +++ b/include/sqlpp11/type_traits.h @@ -111,7 +111,7 @@ namespace sqlpp detail::is_element_of::value>; SQLPP_VALUE_TRAIT_GENERATOR(is_text); SQLPP_VALUE_TRAIT_GENERATOR(is_wrapped_value); - SQLPP_VALUE_TRAIT_GENERATOR(is_named_expression); + SQLPP_VALUE_TRAIT_GENERATOR(is_selectable); SQLPP_VALUE_TRAIT_GENERATOR(is_multi_expression); SQLPP_VALUE_TRAIT_GENERATOR(is_alias); SQLPP_VALUE_TRAIT_GENERATOR(is_select_flag); diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp index 374a7c20..b0026480 100644 --- a/tests/FunctionTest.cpp +++ b/tests/FunctionTest.cpp @@ -50,15 +50,15 @@ int main() using TI = decltype(t.alpha.in(1, 2, 3)); using TF = decltype(f.omega.in(1.0, 2.0, 3.0)); using TT = decltype(t.beta.in("a", "b", "c")); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); @@ -69,15 +69,15 @@ int main() using TI = decltype(t.alpha.in(sqlpp::value_list(std::vector({1, 2, 3})))); using TF = decltype(f.omega.in(sqlpp::value_list(std::vector({1.0, 2.0, 3.0})))); using TT = decltype(t.beta.in(sqlpp::value_list(std::vector({"a", "b", "c"})))); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); @@ -88,15 +88,15 @@ int main() using TI = decltype(t.alpha.not_in(1, 2, 3)); using TF = decltype(f.omega.not_in(1.0, 2.0, 3.0)); using TT = decltype(t.beta.not_in("a", "b", "c")); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); @@ -107,15 +107,15 @@ int main() using TI = decltype(t.alpha.not_in(sqlpp::value_list(std::vector({1, 2, 3})))); using TF = decltype(f.omega.not_in(sqlpp::value_list(std::vector({1.0, 2.0, 3.0})))); using TT = decltype(t.beta.not_in(sqlpp::value_list(std::vector({"a", "b", "c"})))); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); @@ -124,7 +124,7 @@ int main() // Test like { using TT = decltype(t.beta.like("%c%")); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); @@ -141,15 +141,15 @@ int main() static_assert(std::is_same::value, "type requirement"); static_assert(std::is_same::value, "type requirement"); static_assert(std::is_same::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); @@ -166,15 +166,15 @@ int main() static_assert(std::is_same::value, "type requirement"); static_assert(std::is_same::value, "type requirement"); static_assert(std::is_same::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); @@ -187,11 +187,11 @@ int main() { using TI = decltype(exists(select(t.alpha).from(t))); using TT = decltype(exists(select(t.beta).from(t))); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); @@ -206,17 +206,17 @@ int main() using TI = decltype(any(select(t.alpha).from(t))); using TT = decltype(any(select(t.beta).from(t))); using TF = decltype(any(select(f.omega).from(f))); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "tFpe requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_integral_t::value, "type requirement"); @@ -229,18 +229,18 @@ int main() using TI = decltype(some(select(t.alpha).from(t))); using TT = decltype(some(select(t.beta).from(t))); using TF = decltype(some(select(f.omega).from(f))); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); static_assert(not sqlpp::is_text_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_multi_expression_t::value, "type requirement"); static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); @@ -254,11 +254,11 @@ int main() { using TI = decltype(avg(t.alpha)); using TF = decltype(avg(f.omega)); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); @@ -269,15 +269,15 @@ int main() using TI = decltype(count(t.alpha)); using TT = decltype(count(t.beta)); using TF = decltype(count(f.omega)); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); @@ -288,15 +288,15 @@ int main() using TI = decltype(max(t.alpha)); using TF = decltype(max(f.omega)); using TT = decltype(max(t.beta)); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_text_t::value, "type requirement"); } @@ -306,15 +306,15 @@ int main() using TI = decltype(min(t.alpha)); using TF = decltype(min(f.omega)); using TT = decltype(min(t.beta)); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_text_t::value, "type requirement"); } @@ -323,11 +323,11 @@ int main() { using TI = decltype(sum(t.alpha)); using TF = decltype(sum(f.omega)); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); @@ -342,13 +342,13 @@ int main() using TI = decltype(sqlpp::value(7)); using TF = decltype(sqlpp::value(1.5)); using TT = decltype(sqlpp::value("cheesecake")); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_text_t::value, "type requirement"); } @@ -358,13 +358,13 @@ int main() using TI = decltype(flatten(t.alpha, db)); using TF = decltype(flatten(f.omega, db)); using TT = decltype(flatten(t.beta, db)); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_text_t::value, "type requirement"); } @@ -382,13 +382,13 @@ int main() static_assert(std::is_same::value, "type_requirement"); static_assert(std::is_same::value, "type_requirement"); static_assert(std::is_same::value, "type_requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_text_t::value, "type requirement"); } @@ -398,20 +398,20 @@ int main() using TI = decltype(sqlpp::verbatim("42")); using TF = decltype(sqlpp::verbatim("1.5")); using TT = decltype(sqlpp::verbatim("cheesecake")); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_boolean_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_integral_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(sqlpp::is_text_t::value, "type requirement"); } // test verbatim_table { using T = decltype(sqlpp::verbatim_table("cheesecake")); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::is_expression_t::value, "type requirement"); static_assert(sqlpp::is_table_t::value, "type requirement"); } @@ -419,7 +419,7 @@ int main() // test verbatim_table alias { using T = decltype(sqlpp::verbatim_table("cheesecake").as(kaesekuchen)); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::is_expression_t::value, "type requirement"); static_assert(sqlpp::is_table_t::value, "type requirement"); static_assert(sqlpp::is_alias_t::value, "type requirement"); diff --git a/tests/SelectTypeTest.cpp b/tests/SelectTypeTest.cpp index 6a8f931e..00c0d882 100644 --- a/tests/SelectTypeTest.cpp +++ b/tests/SelectTypeTest.cpp @@ -56,7 +56,7 @@ int main() static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); static_assert(not sqlpp::is_expression_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -74,7 +74,7 @@ int main() static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); static_assert(not sqlpp::is_expression_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -92,7 +92,7 @@ int main() static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(sqlpp::must_not_insert_t::value, "type requirement"); static_assert(sqlpp::must_not_update_t::value, "type requirement"); @@ -111,7 +111,7 @@ int main() static_assert(sqlpp::is_integral_t::value, "type requirement"); static_assert(not sqlpp::is_floating_point_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(sqlpp::must_not_insert_t::value, "type requirement"); static_assert(sqlpp::must_not_update_t::value, "type requirement"); @@ -129,7 +129,7 @@ int main() static_assert(not sqlpp::is_integral_t::value, "type requirement"); static_assert(sqlpp::is_floating_point_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -145,7 +145,7 @@ int main() using T = decltype(t.alpha.as(alias::a)); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_expression_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -161,7 +161,7 @@ int main() using T = decltype(select(t.alpha)); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -179,7 +179,7 @@ int main() //static_assert(sqlpp::is_from_t::value, "Must not be noop"); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -195,7 +195,7 @@ int main() using T = decltype(select(t.alpha.as(alias::a)).from(t)); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -211,7 +211,7 @@ int main() using T = decltype(select(t.alpha).from(t).as(alias::b)); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_expression_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -227,7 +227,7 @@ int main() using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b)); static_assert(not sqlpp::is_numeric_t::value, "type requirement"); static_assert(not sqlpp::is_expression_t::value, "type requirement"); - static_assert(not sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(not sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_insert_t::value, "type requirement"); static_assert(not sqlpp::must_not_update_t::value, "type requirement"); @@ -243,7 +243,7 @@ int main() using T = decltype(select(t.alpha).from(t).as(alias::b).alpha); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(sqlpp::must_not_insert_t::value, "type requirement"); static_assert(sqlpp::must_not_update_t::value, "type requirement"); @@ -259,7 +259,7 @@ int main() using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b).a); static_assert(sqlpp::is_numeric_t::value, "type requirement"); static_assert(sqlpp::is_expression_t::value, "type requirement"); - static_assert(sqlpp::is_named_expression_t::value, "type requirement"); + static_assert(sqlpp::is_selectable_t::value, "type requirement"); static_assert(not sqlpp::require_insert_t::value, "type requirement"); static_assert(sqlpp::must_not_insert_t::value, "type requirement"); static_assert(sqlpp::must_not_update_t::value, "type requirement"); @@ -364,8 +364,8 @@ int main() static_assert(sqlpp::must_not_insert_t::value, "alpha must not be inserted"); serialize(t.alpha, printer).str(); std::cerr << "\n" << sizeof(test::TabBar) << std::endl; - static_assert(sqlpp::is_named_expression_t::value, "alpha should be a named expression"); - static_assert(sqlpp::is_named_expression_t::value, "an alias of alpha should be a named expression"); + static_assert(sqlpp::is_selectable_t::value, "alpha should be a named expression"); + static_assert(sqlpp::is_selectable_t::value, "an alias of alpha should be a named expression"); static_assert(sqlpp::is_alias_t::value, "an alias of alpha should be an alias"); auto l = t.as(alias::left); From ef0672a97af8f3af74f29fd1a9cdc557b9ec75bd Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 26 Sep 2014 16:33:47 +0200 Subject: [PATCH 49/52] Minor cleanup --- include/sqlpp11/multi_column.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/include/sqlpp11/multi_column.h b/include/sqlpp11/multi_column.h index 4050968f..44288b83 100644 --- a/include/sqlpp11/multi_column.h +++ b/include/sqlpp11/multi_column.h @@ -66,10 +66,6 @@ namespace sqlpp return { *this }; } - - using _value_type = no_value_t; - using _is_multi_column = std::true_type; - std::tuple _columns; }; @@ -101,12 +97,6 @@ namespace sqlpp multi_column_alias_t& operator=(multi_column_alias_t&&) = default; ~multi_column_alias_t() = default; - struct _value_type: public no_value_t - { - using _is_selectable = std::true_type; - }; - using _is_multi_column = std::true_type; - std::tuple _columns; }; From a4721ff31efec91e1138e636ca3b9f2882f1ed96 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 29 Sep 2014 12:05:35 +0200 Subject: [PATCH 50/52] Fixed serialization of multiple dynamic query elements. --- include/sqlpp11/interpretable_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/sqlpp11/interpretable_list.h b/include/sqlpp11/interpretable_list.h index e3641972..59457bd5 100644 --- a/include/sqlpp11/interpretable_list.h +++ b/include/sqlpp11/interpretable_list.h @@ -84,8 +84,8 @@ namespace sqlpp if (not first) { context << separator; - first = false; } + first = false; serialize(entry, context); } return context; From 11950bc0c7a2d1987f580a50f4ccdbeedae18928 Mon Sep 17 00:00:00 2001 From: rbock Date: Mon, 29 Sep 2014 13:45:29 +0200 Subject: [PATCH 51/52] Added static assert to give clearer error message for dynamic_xy --- include/sqlpp11/insert.h | 3 +++ include/sqlpp11/remove.h | 3 +++ include/sqlpp11/select.h | 3 +++ include/sqlpp11/update.h | 3 ++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/insert.h b/include/sqlpp11/insert.h index 408225da..d6e1bc3a 100644 --- a/include/sqlpp11/insert.h +++ b/include/sqlpp11/insert.h @@ -28,6 +28,7 @@ #define SQLPP_INSERT_H #include +#include #include #include #include @@ -111,6 +112,7 @@ namespace sqlpp constexpr auto dynamic_insert(const Database&) -> decltype(blank_insert_t()) { + static_assert(std::is_base_of::value, "Invalid database parameter"); return { blank_insert_t() }; } @@ -118,6 +120,7 @@ namespace sqlpp constexpr auto dynamic_insert_into(const Database&, Table table) -> decltype(blank_insert_t().into(table)) { + static_assert(std::is_base_of::value, "Invalid database parameter"); return { blank_insert_t().into(table) }; } } diff --git a/include/sqlpp11/remove.h b/include/sqlpp11/remove.h index 0225af13..c607b847 100644 --- a/include/sqlpp11/remove.h +++ b/include/sqlpp11/remove.h @@ -28,6 +28,7 @@ #define SQLPP_REMOVE_H #include +#include #include #include #include @@ -115,6 +116,7 @@ namespace sqlpp auto dynamic_remove(const Database&) -> decltype(blank_remove_t()) { + static_assert(std::is_base_of::value, "Invalid database parameter"); return { blank_remove_t() }; } @@ -122,6 +124,7 @@ namespace sqlpp auto dynamic_remove_from(const Database&, Table table) -> decltype(blank_remove_t().from(table)) { + static_assert(std::is_base_of::value, "Invalid database parameter"); return { blank_remove_t().from(table) }; } } diff --git a/include/sqlpp11/select.h b/include/sqlpp11/select.h index c7e92c4a..3a2556a5 100644 --- a/include/sqlpp11/select.h +++ b/include/sqlpp11/select.h @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -94,6 +95,7 @@ namespace sqlpp template blank_select_t dynamic_select(const Database&) { + static_assert(std::is_base_of::value, "Invalid database parameter"); return { }; } @@ -101,6 +103,7 @@ namespace sqlpp auto dynamic_select(const Database&, Columns... columns) -> decltype(blank_select_t().columns(columns...)) { + static_assert(std::is_base_of::value, "Invalid database parameter"); return blank_select_t().columns(columns...); } diff --git a/include/sqlpp11/update.h b/include/sqlpp11/update.h index 09eb71a3..492f0791 100644 --- a/include/sqlpp11/update.h +++ b/include/sqlpp11/update.h @@ -28,7 +28,7 @@ #define SQLPP_UPDATE_H #include - +#include #include #include #include @@ -109,6 +109,7 @@ namespace sqlpp constexpr auto dynamic_update(const Database&, Table table) -> decltype(blank_update_t().from(table)) { + static_assert(std::is_base_of::value, "Invalid database parameter"); return { blank_update_t().from(table) }; } } From b3ef68101fe924ece0557b6f4706baf1317e4d97 Mon Sep 17 00:00:00 2001 From: rbock Date: Fri, 3 Oct 2014 08:51:27 +0200 Subject: [PATCH 52/52] Fixed bug in in() serialization in(select(...)) did have an extra set of braces, which lead to different behaviour. Thanks to Thomas Marsh for finding the bug --- include/sqlpp11/in.h | 6 +++++- tests/InterpretTest.cpp | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/sqlpp11/in.h b/include/sqlpp11/in.h index e3bf0915..3d8a98a0 100644 --- a/include/sqlpp11/in.h +++ b/include/sqlpp11/in.h @@ -79,7 +79,11 @@ namespace sqlpp { serialize(t._operand, context); context << (t._inverted ? " NOT IN(" : " IN("); - interpret_tuple(t._args, ',', context); + if (sizeof...(Args) == 1) + serialize(std::get<0>(t._args), context); // FIXME: this is a bit of a hack until there is a better overall strategy for using braces + // see https://github.com/rbock/sqlpp11/issues/18 + else + interpret_tuple(t._args, ',', context); context << ')'; return context; } diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index 6d0943ac..c3813a24 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -179,6 +179,9 @@ int main() printer.reset(); std::cerr << serialize(x, printer).str() << std::endl; + printer.reset(); + std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in(select(f.epsilon).from(f).where(true))), printer).str() << std::endl; + return 0;