From 24b44fae654cc0921e6278810ecb1dc66d47743f Mon Sep 17 00:00:00 2001 From: rbock Date: Sat, 18 Jan 2014 20:58:51 +0100 Subject: [PATCH] Re-animated all tests --- include/sqlpp11/boolean.h | 13 ++-- include/sqlpp11/floating_point.h | 10 +-- include/sqlpp11/integral.h | 17 ++--- include/sqlpp11/serializer.h | 4 +- include/sqlpp11/sqlpp11.h | 1 + include/sqlpp11/text.h | 9 +-- include/sqlpp11/vendor/concat.h | 2 +- include/sqlpp11/vendor/insert_list.h | 6 +- include/sqlpp11/vendor/interpretable.h | 11 +-- include/sqlpp11/vendor/interpretable_list.h | 2 +- include/sqlpp11/vendor/like.h | 1 + include/sqlpp11/vendor/named_interpretable.h | 8 +-- .../sqlpp11/vendor/select_expression_list.h | 6 +- tests/CMakeLists.txt | 12 ++-- tests/FunctionTest.cpp | 3 +- tests/InsertTest.cpp | 7 +- tests/InterpretTest.cpp | 2 +- tests/MockDb.h | 60 ++--------------- tests/PreparedTest.cpp | 2 +- tests/RemoveTest.cpp | 9 +-- tests/SelectTest.cpp | 67 +++++++++++-------- tests/UpdateTest.cpp | 9 +-- 22 files changed, 105 insertions(+), 156 deletions(-) diff --git a/include/sqlpp11/boolean.h b/include/sqlpp11/boolean.h index 01dc1565..29253d4e 100644 --- a/include/sqlpp11/boolean.h +++ b/include/sqlpp11/boolean.h @@ -63,14 +63,9 @@ namespace sqlpp { using _value_type = boolean; - _parameter_t(const std::true_type&): + _parameter_t(): _value(false), - _is_null(false) - {} - - _parameter_t(const std::false_type&): - _value(false), - _is_null(false) + _is_null(true) {} _parameter_t(const _cpp_value_type& value): @@ -186,14 +181,14 @@ namespace sqlpp vendor::binary_expression_t::type> operator and(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template vendor::binary_expression_t::type> operator or(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } vendor::not_t operator not() const diff --git a/include/sqlpp11/floating_point.h b/include/sqlpp11/floating_point.h index d6a82867..c7b757e9 100644 --- a/include/sqlpp11/floating_point.h +++ b/include/sqlpp11/floating_point.h @@ -53,7 +53,7 @@ namespace sqlpp _parameter_t(): _value(0), - _is_null(false) + _is_null(true) {} _parameter_t(const _cpp_value_type& value): @@ -195,28 +195,28 @@ namespace sqlpp vendor::binary_expression_t::type> operator +(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template vendor::binary_expression_t::type> operator -(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template vendor::binary_expression_t::type> operator *(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template vendor::binary_expression_t::type> operator /(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template diff --git a/include/sqlpp11/integral.h b/include/sqlpp11/integral.h index 0a3afe4d..d6fb4e26 100644 --- a/include/sqlpp11/integral.h +++ b/include/sqlpp11/integral.h @@ -51,14 +51,9 @@ namespace sqlpp { using _value_type = integral; - _parameter_t(const std::true_type&): + _parameter_t(): _value(0), - _is_null(false) - {} - - _parameter_t(const std::false_type&): - _value(0), - _is_null(false) + _is_null(true) {} explicit _parameter_t(const _cpp_value_type& value): @@ -202,28 +197,28 @@ namespace sqlpp vendor::binary_expression_t, typename _constraint::type> operator +(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template vendor::binary_expression_t, typename _constraint::type> operator -(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template vendor::binary_expression_t, typename _constraint::type> operator *(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template vendor::binary_expression_t::type> operator /(T&& t) const { static_assert(not is_multi_expression_t::value, "multi-expression cannot be used as left hand side operand"); - return { *static_cast(this), std::forward(t) }; + return { *static_cast(this), {std::forward(t)} }; } template diff --git a/include/sqlpp11/serializer.h b/include/sqlpp11/serializer.h index 358c0aee..d8bbaaee 100644 --- a/include/sqlpp11/serializer.h +++ b/include/sqlpp11/serializer.h @@ -30,9 +30,9 @@ namespace sqlpp { - struct serializer + struct serializer_t { - serializer(std::ostream& os): + serializer_t(std::ostream& os): _os(os) {} diff --git a/include/sqlpp11/sqlpp11.h b/include/sqlpp11/sqlpp11.h index b03cba48..883b2eaa 100644 --- a/include/sqlpp11/sqlpp11.h +++ b/include/sqlpp11/sqlpp11.h @@ -27,6 +27,7 @@ #ifndef SQLPP_H #define SQLPP_H +#include #include #include #include diff --git a/include/sqlpp11/text.h b/include/sqlpp11/text.h index f2baaa8d..18aa3529 100644 --- a/include/sqlpp11/text.h +++ b/include/sqlpp11/text.h @@ -51,14 +51,9 @@ namespace sqlpp { using _value_type = integral; - _parameter_t(const std::true_type&): + _parameter_t(): _value(""), - _is_null(false) - {} - - _parameter_t(const std::false_type&): - _value(""), - _is_null(false) + _is_null(true) {} _parameter_t(const _cpp_value_type& value): diff --git a/include/sqlpp11/vendor/concat.h b/include/sqlpp11/vendor/concat.h index 01e7e752..0aa524b9 100644 --- a/include/sqlpp11/vendor/concat.h +++ b/include/sqlpp11/vendor/concat.h @@ -39,7 +39,7 @@ namespace sqlpp struct concat_t: public First::_value_type::template operators> { static_assert(sizeof...(Args) > 0, "concat requires two arguments at least"); - using _valid_args = typename detail::make_set_if_not::type; + using _valid_args = typename ::sqlpp::detail::make_set_if_not::type; static_assert(_valid_args::size::value == 0, "at least one non-text argument detected in concat()"); struct _value_type: public First::_value_type::_base_value_type diff --git a/include/sqlpp11/vendor/insert_list.h b/include/sqlpp11/vendor/insert_list.h index d8af1f49..a125dbc2 100644 --- a/include/sqlpp11/vendor/insert_list.h +++ b/include/sqlpp11/vendor/insert_list.h @@ -84,14 +84,14 @@ namespace sqlpp static_assert(_is_dynamic::value or sizeof...(Assignments), "at least one select expression required in set()"); // check for duplicate assignments - static_assert(not detail::has_duplicates::value, "at least one duplicate argument detected in set()"); + static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected in set()"); // check for invalid assignments - using _assignment_set = typename detail::make_set_if::type; + using _assignment_set = typename ::sqlpp::detail::make_set_if::type; static_assert(_assignment_set::size::value == sizeof...(Assignments), "at least one argument is not an assignment in set()"); // check for prohibited assignments - using _prohibited_assignment_set = typename detail::make_set_if::type; + using _prohibited_assignment_set = typename ::sqlpp::detail::make_set_if::type; static_assert(_prohibited_assignment_set::size::value == 0, "at least one assignment is prohibited by its column definition in set()"); insert_list_t(Assignments... assignment): diff --git a/include/sqlpp11/vendor/interpretable.h b/include/sqlpp11/vendor/interpretable.h index 3eb5265f..340b7caa 100644 --- a/include/sqlpp11/vendor/interpretable.h +++ b/include/sqlpp11/vendor/interpretable.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace sqlpp { @@ -38,7 +39,7 @@ namespace sqlpp template struct interpretable_t { - using _context_t = typename Db::context; + using _context_t = typename Db::_context_t; template interpretable_t(T t): @@ -51,7 +52,7 @@ namespace sqlpp interpretable_t& operator=(interpretable_t&&) = default; ~interpretable_t() = default; - sqlpp::serializer& interpret(sqlpp::serializer& context) const + sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const { return _impl->interpret(context); } @@ -64,8 +65,8 @@ namespace sqlpp private: struct _impl_base { - virtual sqlpp::serializer& interpret(sqlpp::serializer& context) const = 0; - virtual _context_t interpret(_context_t& context) const = 0; + virtual sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const = 0; + virtual _context_t& interpret(_context_t& context) const = 0; }; template @@ -80,7 +81,7 @@ namespace sqlpp _t(std::move(t)) {} - sqlpp::serializer& interpret(sqlpp::serializer& context) const + sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const { sqlpp::interpret(_t, context); return context; diff --git a/include/sqlpp11/vendor/interpretable_list.h b/include/sqlpp11/vendor/interpretable_list.h index 855951aa..37501247 100644 --- a/include/sqlpp11/vendor/interpretable_list.h +++ b/include/sqlpp11/vendor/interpretable_list.h @@ -91,7 +91,7 @@ namespace sqlpp context << separator; first = false; } - interpret(t, context); + interpret(entry, context); } return context; } diff --git a/include/sqlpp11/vendor/like.h b/include/sqlpp11/vendor/like.h index 08dba1f2..01cde753 100644 --- a/include/sqlpp11/vendor/like.h +++ b/include/sqlpp11/vendor/like.h @@ -40,6 +40,7 @@ namespace sqlpp { 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"); + using _parameter_tuple_t = std::tuple; struct _value_type: public boolean { diff --git a/include/sqlpp11/vendor/named_interpretable.h b/include/sqlpp11/vendor/named_interpretable.h index febea4db..2b535ce2 100644 --- a/include/sqlpp11/vendor/named_interpretable.h +++ b/include/sqlpp11/vendor/named_interpretable.h @@ -38,7 +38,7 @@ namespace sqlpp template struct named_interpretable_t { - using _context_t = typename Db::context; + using _context_t = typename Db::_context_t; template named_interpretable_t(T t): @@ -51,7 +51,7 @@ namespace sqlpp named_interpretable_t& operator=(named_interpretable_t&&) = default; ~named_interpretable_t() = default; - sqlpp::serializer& interpret(sqlpp::serializer& context) const + sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const { return _impl->interpret(context); } @@ -69,7 +69,7 @@ namespace sqlpp private: struct _impl_base { - virtual sqlpp::serializer& interpret(sqlpp::serializer& context) const = 0; + virtual sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const = 0; virtual _context_t& interpret(_context_t& context) const = 0; virtual std::string _get_name() const = 0; }; @@ -86,7 +86,7 @@ namespace sqlpp _t(std::move(t)) {} - sqlpp::serializer& interpret(sqlpp::serializer& context) const + sqlpp::serializer_t& interpret(sqlpp::serializer_t& context) const { sqlpp::interpret(_t, context); return context; diff --git a/include/sqlpp11/vendor/select_expression_list.h b/include/sqlpp11/vendor/select_expression_list.h index 6a1c7545..ab9d06f6 100644 --- a/include/sqlpp11/vendor/select_expression_list.h +++ b/include/sqlpp11/vendor/select_expression_list.h @@ -135,9 +135,6 @@ namespace sqlpp using _is_dynamic = typename std::conditional::value, std::false_type, std::true_type>::type; using _parameter_tuple_t = std::tuple; - // check for at least one expression - static_assert(_is_dynamic::value or sizeof...(NamedExpr), "at least one select expression required"); - // check for duplicate select expressions static_assert(not ::sqlpp::detail::has_duplicates::value, "at least one duplicate argument detected"); @@ -191,6 +188,9 @@ namespace sqlpp static Context& _(const T& t, Context& context) { + // check for at least one expression + static_assert(T::_is_dynamic::value or sizeof...(NamedExpr), "at least one select expression required"); + interpret_tuple(t._expressions, ',', context); if (sizeof...(NamedExpr) and not t._dynamic_expressions.empty()) context << ','; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8b9d19f2..695f12e2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,10 +4,10 @@ macro (build_and_run arg) endmacro () build_and_run(InterpretTest) -#build_and_run(InsertTest) -#build_and_run(RemoveTest) -#build_and_run(UpdateTest) -#build_and_run(SelectTest) -#build_and_run(FunctionTest) -#build_and_run(PreparedTest) +build_and_run(InsertTest) +build_and_run(RemoveTest) +build_and_run(UpdateTest) +build_and_run(SelectTest) +build_and_run(FunctionTest) +build_and_run(PreparedTest) diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp index f4b24e93..ce16ed37 100644 --- a/tests/FunctionTest.cpp +++ b/tests/FunctionTest.cpp @@ -25,6 +25,7 @@ #include "TabSample.h" #include "MockDb.h" +#include #include #include #include @@ -32,7 +33,7 @@ #include DbMock db = {}; -SQLPP_ALIAS_PROVIDER_GENERATOR(kaesekuchen); +SQLPP_ALIAS_PROVIDER(kaesekuchen); int main() { diff --git a/tests/InsertTest.cpp b/tests/InsertTest.cpp index f40dafbd..80760af4 100644 --- a/tests/InsertTest.cpp +++ b/tests/InsertTest.cpp @@ -30,6 +30,7 @@ #include DbMock db; +DbMock::_context_t printer(std::cerr); int main() { @@ -56,11 +57,11 @@ int main() static_assert(sqlpp::is_regular::value, "type requirement"); } - insert_into(t).serialize(std::cerr, db); std::cerr << "\n"; - insert_into(t).set(t.beta = "kirschauflauf").serialize(std::cerr, db); std::cerr << "\n"; + interpret(insert_into(t), printer).flush(); + interpret(insert_into(t).set(t.beta = "kirschauflauf"), printer).flush(); auto i = dynamic_insert_into(db, t).dynamic_set(); i = i.add_set(t.beta = "kirschauflauf"); - i.serialize(std::cerr, db); std::cerr << "\n"; + interpret(i, printer).flush(); return 0; } diff --git a/tests/InterpretTest.cpp b/tests/InterpretTest.cpp index 298524d3..eb8c137e 100644 --- a/tests/InterpretTest.cpp +++ b/tests/InterpretTest.cpp @@ -35,7 +35,7 @@ #include DbMock db = {}; -DbMock::context printer(std::cerr); +DbMock::_context_t printer(std::cerr); SQLPP_ALIAS_PROVIDER(kaesekuchen); int main() diff --git a/tests/MockDb.h b/tests/MockDb.h index 484116a9..7a9e5d37 100644 --- a/tests/MockDb.h +++ b/tests/MockDb.h @@ -27,66 +27,14 @@ #define SQLPP_MOCK_DB_H #include +#include -class DbMock: public sqlpp::connection +struct DbMock: public sqlpp::connection { -public: - struct context + struct _context_t : public sqlpp::serializer_t { - using _database_t = DbMock; - context(std::ostream& os): - _os(os) - {} - - template - std::ostream& operator<<(T t) - { - return _os << t; - } - - void flush() - { - _os << std::endl; - } - - std::string escape(std::string arg) - { - return arg; - } - - std::ostream& _os; + _context_t(std::ostream& os): sqlpp::serializer_t(os) {} }; - - // join types - static constexpr bool _supports_inner_join = true; - static constexpr bool _supports_outer_join = true; - static constexpr bool _supports_left_outer_join = true; - static constexpr bool _supports_right_outer_join = true; - - // functions - static constexpr bool _supports_avg = true; - static constexpr bool _supports_count = true; - static constexpr bool _supports_exists = true; - static constexpr bool _supports_like = true; - static constexpr bool _supports_in = true; - static constexpr bool _supports_max = true; - static constexpr bool _supports_min = true; - static constexpr bool _supports_not_in = true; - static constexpr bool _supports_sum = true; - - // select - static constexpr bool _supports_group_by = true; - static constexpr bool _supports_having = true; - static constexpr bool _supports_limit = true; - static constexpr bool _supports_order_by = true; - static constexpr bool _supports_select_as_table = true; - - static constexpr bool _supports_some = true; - static constexpr bool _supports_any = true; - static constexpr bool _use_concat_operator = true; - static constexpr bool _use_concat_function = true; - - const std::string& escape(const std::string& text) { return text; } }; #endif diff --git a/tests/PreparedTest.cpp b/tests/PreparedTest.cpp index 627bcf3a..f3c36cc1 100644 --- a/tests/PreparedTest.cpp +++ b/tests/PreparedTest.cpp @@ -87,7 +87,7 @@ int main() // Wonderful, now take a look at the parameter list of a select { - auto s = select(all_of(t)).from(t).where(t.beta.like(where_parameter(t.beta)) and t.alpha == where_parameter(t.alpha) or t.gamma != parameter(t.gamma)); + auto s = select(all_of(t)).from(t).where(t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha) or t.gamma != parameter(t.gamma)); using S = decltype(s); using T = sqlpp::make_parameter_list_t::type; T npl; diff --git a/tests/RemoveTest.cpp b/tests/RemoveTest.cpp index 64abc4a0..20785ddf 100644 --- a/tests/RemoveTest.cpp +++ b/tests/RemoveTest.cpp @@ -32,6 +32,7 @@ DbMock db; +DbMock::_context_t printer(std::cerr); int main() { @@ -56,13 +57,13 @@ int main() static_assert(sqlpp::is_regular::value, "type requirement"); } - remove_from(t).serialize(std::cerr, db); std::cerr << "\n"; - remove_from(t).where(t.beta != "transparent").serialize(std::cerr, db); std::cerr << "\n"; - remove_from(t).using_(t).serialize(std::cerr, db); std::cerr << "\n"; + interpret(remove_from(t), printer).flush(); + interpret(remove_from(t).where(t.beta != "transparent"), printer).flush(); + interpret(remove_from(t).using_(t), printer).flush(); auto r = dynamic_remove_from(db, t).dynamic_using_().dynamic_where(); r = r.add_using_(t); r = r.add_where(t.beta != "transparent"); - r.serialize(std::cerr, db); std::cerr << "\n"; + interpret(r, printer).flush(); return 0; } diff --git a/tests/SelectTest.cpp b/tests/SelectTest.cpp index c413509a..1a32b1f5 100644 --- a/tests/SelectTest.cpp +++ b/tests/SelectTest.cpp @@ -26,6 +26,7 @@ #include "TabSample.h" #include "MockDb.h" #include "is_regular.h" +#include #include #include #include @@ -33,6 +34,15 @@ #include DbMock db = {}; +DbMock::_context_t printer(std::cerr); + +namespace alias +{ + SQLPP_ALIAS_PROVIDER(a); + SQLPP_ALIAS_PROVIDER(b); + SQLPP_ALIAS_PROVIDER(left); + SQLPP_ALIAS_PROVIDER(right); +} int main() { @@ -59,7 +69,7 @@ int main() // Test an alias of table { - using T = decltype(t.as(sqlpp::alias::a)); + using T = decltype(t.as(alias::a)); static_assert(not sqlpp::is_numeric_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"); @@ -77,7 +87,7 @@ int main() // Test an integral column of an alias of table { - using T = decltype(t.as(sqlpp::alias::a).alpha); + using T = decltype(t.as(alias::a).alpha); 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"); @@ -132,7 +142,7 @@ int main() // Test a an alias of a numeric table column { - using T = decltype(t.alpha.as(sqlpp::alias::a)); + 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"); @@ -180,7 +190,7 @@ int main() // Test a select of an alias of a single numeric table column { - using T = decltype(select(t.alpha.as(sqlpp::alias::a)).from(t)); + 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"); @@ -196,7 +206,7 @@ int main() // Test an alias of a select of a single numeric table column { - using T = decltype(select(t.alpha).from(t).as(sqlpp::alias::b)); + 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"); @@ -212,7 +222,7 @@ int main() // Test the column of an alias of a select of an alias of a single numeric table column { - using T = decltype(select(t.alpha.as(sqlpp::alias::a)).from(t).as(sqlpp::alias::b)); + 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"); @@ -228,7 +238,7 @@ int main() // Test the column of an alias of a select of a single numeric table column { - using T = decltype(select(t.alpha).from(t).as(sqlpp::alias::b).alpha); + 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"); @@ -244,7 +254,7 @@ int main() // Test an alias of a select of an alias of a single numeric table column { - using T = decltype(select(t.alpha.as(sqlpp::alias::a)).from(t).as(sqlpp::alias::b).a); + 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"); @@ -269,22 +279,22 @@ int main() // Test that select(all_of(tab)) is expanded in multi_column { - auto a = multi_column(sqlpp::alias::a, all_of(t)); - auto b = multi_column(sqlpp::alias::a, t.alpha, t.beta, t.gamma); + auto a = multi_column(alias::a, all_of(t)); + auto b = multi_column(alias::a, t.alpha, t.beta, t.gamma); static_assert(std::is_same::value, "all_of(t) has to be expanded by multi_column"); } // Test that select(tab) is expanded in multi_column { - auto a = multi_column(sqlpp::alias::a, all_of(t)); - auto b = multi_column(sqlpp::alias::a, t.alpha, t.beta, t.gamma); + auto a = multi_column(alias::a, all_of(t)); + auto b = multi_column(alias::a, t.alpha, t.beta, t.gamma); static_assert(std::is_same::value, "t has to be expanded by multi_column"); } // Test that a multicolumn is not a value { - auto m = multi_column(sqlpp::alias::a, t.alpha, t.beta); - auto a = select(m).from(t).as(sqlpp::alias::b).a; + auto m = multi_column(alias::a, t.alpha, t.beta); + auto a = select(m).from(t).as(alias::b).a; static_assert(not sqlpp::is_value_t::value, "a multi_column is not a value"); } @@ -307,7 +317,7 @@ int main() s = s.set_limit(30); s = s.set_limit(3); std::cerr << "------------------------\n"; - s.serialize(std::cerr, db); + interpret(s, printer).flush(); std::cerr << "------------------------\n"; using T = decltype(s); static_assert(sqlpp::is_regular::value, "type requirement"); @@ -316,18 +326,18 @@ int main() // Test that select can be called with zero columns if it is used with dynamic columns. { auto s = dynamic_select(db).dynamic_columns().add_column(t.alpha); - s.serialize(std::cerr, db); std::cerr << "\n"; + interpret(s, printer).flush(); } // Test that verbatim_table compiles { auto s = select(t.alpha).from(sqlpp::verbatim_table("my_unknown_table")); - s.serialize(std::cerr, db); std::cerr << "\n"; + interpret(s, printer).flush(); } static_assert(sqlpp::is_select_flag_t::value, "sqlpp::all has to be a select_flag"); - using T = sqlpp::detail::wrap_operand::type; + using T = sqlpp::vendor::wrap_operand::type; static_assert(sqlpp::is_regular::value, "type requirement"); static_assert(T::_is_expression, "T has to be an expression"); static_assert(std::is_same::value, "T has to be a numeric"); @@ -339,29 +349,28 @@ int main() auto y = t.gamma and true and t.gamma; !t.gamma; t.beta < "kaesekuchen"; - (t.beta + "hallenhalma").serialize(std::cerr, db); - concat(t.beta, "hallenhalma").serialize(std::cerr, db); + interpret(t.beta + "hallenhalma", printer).flush(); static_assert(sqlpp::must_not_insert_t::value, "alpha must not be inserted"); - t.alpha.serialize(std::cerr, db); + interpret(t.alpha, printer).flush(); std::cerr << "\n" << sizeof(TabSample) << std::endl; static_assert(std::is_same::value, "alpha should be a named expression"); 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_alias_t::value, "an alias of alpha should be an alias"); + static_assert(sqlpp::is_named_expression_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 z = select(t.alpha) == 7; - auto l = t.as(sqlpp::alias::left); - auto r = select(t.gamma.as(sqlpp::alias::a)).from(t).where(t.gamma == true).as(sqlpp::alias::right); + auto l = t.as(alias::left); + auto r = select(t.gamma.as(alias::a)).from(t).where(t.gamma == true).as(alias::right); static_assert(sqlpp::is_boolean_t::value, "select(bool) has to be a bool"); - select(sqlpp::distinct, sqlpp::straight_join, l.alpha, l.beta, select(r.a).from(r)) + interpret(select(sqlpp::distinct, sqlpp::straight_join, l.alpha, l.beta, select(r.a).from(r)) .from(l, r) - .where(t.beta == "hello world" and select(t.gamma).from(t))// .as(sqlpp::alias::right)) + .where(t.beta == "hello world" and select(t.gamma).from(t))// .as(alias::right)) .group_by(l.gamma, r.a) .having(r.a != true) .order_by(l.beta.asc()) .limit(17) .offset(3) - .as(sqlpp::alias::a) - .serialize(std::cerr, db); + .as(alias::a) + , printer).flush(); return 0; } diff --git a/tests/UpdateTest.cpp b/tests/UpdateTest.cpp index 75053c31..c3f76f0b 100644 --- a/tests/UpdateTest.cpp +++ b/tests/UpdateTest.cpp @@ -30,6 +30,7 @@ #include "is_regular.h" DbMock db; +DbMock::_context_t printer(std::cerr); int main() { @@ -54,12 +55,12 @@ int main() static_assert(sqlpp::is_regular::value, "type requirement"); } - update(t).serialize(std::cerr, db); std::cerr << "\n"; - update(t).set(t.gamma = false).serialize(std::cerr, db); std::cerr << "\n"; - update(t).set(t.gamma = false).where(t.beta != "transparent").serialize(std::cerr, db); std::cerr << "\n"; + interpret(update(t), printer).flush(); + interpret(update(t).set(t.gamma = false), printer).flush(); + interpret(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).flush(); auto u = dynamic_update(db, t).dynamic_set(t.gamma = false).dynamic_where(); u = u.add_set(t.gamma = false); - u.serialize(std::cerr, db); std::cerr << "\n"; + interpret(u, printer).flush(); return 0; }