diff --git a/include/sqlpp11/core/aggregate_function/avg.h b/include/sqlpp11/core/aggregate_function/avg.h index 3a74a8c4..073bbff0 100644 --- a/include/sqlpp11/core/aggregate_function/avg.h +++ b/include/sqlpp11/core/aggregate_function/avg.h @@ -80,6 +80,20 @@ namespace sqlpp using type = sqlpp::force_optional_t; }; + template + Context& serialize(Context& context, const avg_t& t) + { + context << "MAX("; + if (std::is_same::value) + { + serialize(context, Flag()); + context << ' '; + } + serialize_operand(context, t._expr); + context << ")"; + return context; + } + template using check_avg_arg = ::sqlpp::enable_if_t<(is_numeric::value or is_boolean::value) and not contains_aggregate_function_t::value>; diff --git a/include/sqlpp11/core/basic/column.h b/include/sqlpp11/core/basic/column.h index 7a71f270..3a78b7e4 100644 --- a/include/sqlpp11/core/basic/column.h +++ b/include/sqlpp11/core/basic/column.h @@ -116,8 +116,10 @@ namespace sqlpp { using T = column_t; - context << name_tag_of_t::_name_t::template char_ptr() << '.' - << name_tag_of_t::_name_t::template char_ptr(); + serialize_name(context, name_tag_of_t
::name); + context << '.'; + serialize_name(context, name_tag_of_t::name); + return context; } } // namespace sqlpp diff --git a/include/sqlpp11/core/basic/parameterized_verbatim.h b/include/sqlpp11/core/basic/parameterized_verbatim.h index ec8d5a76..2d764163 100644 --- a/include/sqlpp11/core/basic/parameterized_verbatim.h +++ b/include/sqlpp11/core/basic/parameterized_verbatim.h @@ -1,7 +1,7 @@ #pragma once /* - * Copyright (c) 2013-2020, Roland Bock, MacDue + * Copyright (c) 2013, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, diff --git a/include/sqlpp11/core/basic/table.h b/include/sqlpp11/core/basic/table.h index a96b2fa5..63d045bf 100644 --- a/include/sqlpp11/core/basic/table.h +++ b/include/sqlpp11/core/basic/table.h @@ -69,7 +69,7 @@ namespace sqlpp template Context& serialize(Context& context, const table_t& /*unused*/) { - context << name_tag_of_t::_name_t::template char_ptr(); + serialize_name(context, name_tag_of_t::name); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/core/basic/table_alias.h b/include/sqlpp11/core/basic/table_alias.h index b31e9a2b..03e8951a 100644 --- a/include/sqlpp11/core/basic/table_alias.h +++ b/include/sqlpp11/core/basic/table_alias.h @@ -58,8 +58,9 @@ namespace sqlpp template Context& serialize(Context& context, const table_alias_t&) { - context << name_tag_of_t::_name_t::template char_ptr(); - context << " AS " << name_tag_of_t::_name_t::template char_ptr(); + serialize_name(context, name_tag_of_t::name); + context << " AS "; + serialize_name(context, name_tag_of_t::name); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/core/basic/verbatim_table.h b/include/sqlpp11/core/basic/verbatim_table.h index d2f22db3..d6176d23 100644 --- a/include/sqlpp11/core/basic/verbatim_table.h +++ b/include/sqlpp11/core/basic/verbatim_table.h @@ -58,7 +58,8 @@ namespace sqlpp Context& serialize(Context& context, const verbatim_table_alias_t& t) { context << t._representation; - context << " AS " << name_tag_of_t::_name_t::template char_ptr(); + context << " AS "; + serialize_name(context, name_tag_of_t::name); return context; } diff --git a/include/sqlpp11/core/clause/select_as.h b/include/sqlpp11/core/clause/select_as.h index 9d974612..b2fd0518 100644 --- a/include/sqlpp11/core/clause/select_as.h +++ b/include/sqlpp11/core/clause/select_as.h @@ -54,8 +54,9 @@ namespace sqlpp { using T = pseudo_column_t; - context << name_tag_of_t::_name_t::template char_ptr() << '.' - << name_tag_of_t::_name_t::template char_ptr(); + serialize_name(context, name_tag_of_t::name); + context << '.'; + serialize_name(context, name_tag_of_t::name); return context; } @@ -97,7 +98,8 @@ namespace sqlpp auto serialize(Context& context, const select_as_t& t) -> Context& { serialize_operand(context, t._select); - context << " AS " << name_tag_of_t::_name_t::template char_ptr(); + context << " AS "; + serialize_name(context, name_tag_of_t::name); return context; } } // namespace sqlpp diff --git a/include/sqlpp11/core/compat/string_view.h b/include/sqlpp11/core/compat/string_view.h index 408e6412..90a2f2b5 100644 --- a/include/sqlpp11/core/compat/string_view.h +++ b/include/sqlpp11/core/compat/string_view.h @@ -62,16 +62,17 @@ namespace sqlpp { } - string_view(const char* data) : _data(data), _size(std::char_traits::length(data)) +#warning: Can we make char_traits::length constexpr + constexpr string_view(const char* data) : _data(data), _size(std::char_traits::length(data)) { } - const char* data() const + constexpr const char* data() const { return _data; } - size_t size() const + constexpr size_t size() const { return _size; } @@ -104,3 +105,4 @@ namespace sqlpp } // namespace sqlpp #endif + diff --git a/include/sqlpp11/core/detail/type_set.h b/include/sqlpp11/core/detail/type_set.h index a70f3012..edbaff95 100644 --- a/include/sqlpp11/core/detail/type_set.h +++ b/include/sqlpp11/core/detail/type_set.h @@ -30,6 +30,7 @@ #include #include #include +#include #include namespace sqlpp @@ -270,7 +271,8 @@ namespace sqlpp template struct make_name_of_set> { - using type = make_type_set_t::_sqlpp_name_tag::_name_t...>; + using type = + make_type_set_t::name), sqlpp::name_tag_of_t::name>...>; }; template diff --git a/include/sqlpp11/core/name/alias_provider.h b/include/sqlpp11/core/name/alias_provider.h index 8f150b9c..9005a5f9 100644 --- a/include/sqlpp11/core/name/alias_provider.h +++ b/include/sqlpp11/core/name/alias_provider.h @@ -1,7 +1,7 @@ #pragma once /* - * Copyright (c) 2013-2016, Roland Bock + * Copyright (c) 2013, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -30,7 +30,7 @@ #include #define SQLPP_NAME_TAG_GUTS(SQL_NAME, CPP_NAME) \ - static constexpr auto name = sqlpp::string_view{#SQL_NAME}; \ + static constexpr const char name[] = #SQL_NAME;\ template \ struct _member_t \ { \ diff --git a/include/sqlpp11/core/name/char_sequence.h b/include/sqlpp11/core/name/char_sequence.h index 3225db7b..6999aa4a 100644 --- a/include/sqlpp11/core/name/char_sequence.h +++ b/include/sqlpp11/core/name/char_sequence.h @@ -27,37 +27,14 @@ */ #include +#warning: move index_sequence into compat #include namespace sqlpp { - template - std::integral_constant get_quote_left(const Context&); - - template - std::integral_constant get_quote_right(const Context&); - template struct char_sequence { - template - static const char* char_ptr() - { - static char s[] = {Cs..., '\0'}; - return s; - } - }; - - template - struct char_sequence<'!', Cs...> - { - template - static const char* char_ptr() - { - static char s[] = {decltype(get_quote_left(std::declval()))::value, Cs..., - decltype(get_quote_right(std::declval()))::value, '\0'}; - return s; - } }; template diff --git a/include/sqlpp11/core/noop.h b/include/sqlpp11/core/noop.h index 443c628e..544c8c1c 100644 --- a/include/sqlpp11/core/noop.h +++ b/include/sqlpp11/core/noop.h @@ -27,6 +27,7 @@ */ #include +#include #include namespace sqlpp @@ -80,7 +81,7 @@ namespace sqlpp }; template - Context& serialize(Context& context, const noop&) + auto serialize(Context& context, const noop&) -> Context& { return context; } diff --git a/include/sqlpp11/core/operator/as_expression.h b/include/sqlpp11/core/operator/as_expression.h index dc07b970..9d9e5f19 100644 --- a/include/sqlpp11/core/operator/as_expression.h +++ b/include/sqlpp11/core/operator/as_expression.h @@ -64,7 +64,7 @@ namespace sqlpp { serialize_operand(context, t._expression); context << " AS "; - context << name_tag_of_t::name; + serialize_name(context, name_tag_of_t::name); return context; } template diff --git a/include/sqlpp11/core/operator/logical_expression.h b/include/sqlpp11/core/operator/logical_expression.h index 79ec1d28..be21ccb7 100644 --- a/include/sqlpp11/core/operator/logical_expression.h +++ b/include/sqlpp11/core/operator/logical_expression.h @@ -107,6 +107,22 @@ namespace sqlpp return context; } + template + auto serialize(Context& context, + const logical_expression, Operator, dynamic_t>& t) -> Context& + { + if (t._r._condition) + { + serialize(context, t._l); + context << Operator::symbol; + serialize_operand(context, t._r); + return context; + } + + // If the dynamic part is inactive ignore it. + return serialize(context, t._l); + } + template auto serialize(Context& context, const logical_expression>& t) -> Context& { diff --git a/include/sqlpp11/core/serialize.h b/include/sqlpp11/core/serialize.h index d9efe50a..45573cd5 100644 --- a/include/sqlpp11/core/serialize.h +++ b/include/sqlpp11/core/serialize.h @@ -234,4 +234,14 @@ namespace sqlpp return context; } + template + auto serialize_name(Context& context, const T& t) -> Context& + { +#warning: We used to have a version of SQLPP_ALIAS_PROVIDER that escaped the name + + context << t; + + return context; + } + } // namespace sqlpp diff --git a/tests/core/serialize/As.cpp b/tests/core/serialize/As.cpp deleted file mode 100644 index 2e9df078..00000000 --- a/tests/core/serialize/As.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2016-2016, 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 "compare.h" -#include "Sample.h" -#include - -#include - -SQLPP_ALIAS_PROVIDER(cheese); -SQLPP_ALIAS_PROVIDER(maxId); - -int As(int, char*[]) -{ - const auto foo = test::TabFoo{}; - const auto bar = test::TabBar{}; - - compare(__LINE__, foo, "tab_foo"); - compare(__LINE__, foo.doubleN.as(cheese), "tab_foo.double_n AS cheese"); - compare(__LINE__, (foo.doubleN + 17).as(cheese), "(tab_foo.double_n + 17) AS cheese"); - compare(__LINE__, (foo.doubleN - 17).as(cheese), "(tab_foo.double_n - 17) AS cheese"); - compare(__LINE__, (foo.doubleN - uint32_t(17)).as(cheese), "(tab_foo.double_n - 17) AS cheese"); - compare(__LINE__, (foo.doubleN - bar.id).as(cheese), "(tab_foo.double_n - tab_bar.id) AS cheese"); - compare(__LINE__, (count(foo.doubleN) - bar.id).as(cheese), "(COUNT(tab_foo.double_n) - tab_bar.id) AS cheese"); - compare(__LINE__, (count(foo.doubleN) - uint32_t(17)).as(cheese), "(COUNT(tab_foo.double_n) - 17) AS cheese"); - - compare(__LINE__, select(max(bar.id).as(maxId)), "SELECT MAX(tab_bar.id) AS maxId"); - compare(__LINE__, select(max(bar.id).as(cheese)), "SELECT MAX(tab_bar.id) AS cheese"); - compare(__LINE__, select(max(bar.id).as(maxId)).from(bar).unconditionally().as(cheese), - "(SELECT MAX(tab_bar.id) AS maxId FROM tab_bar) AS cheese"); - compare(__LINE__, select(max(bar.id).as(maxId)).from(bar).unconditionally().as(cheese).maxId, "cheese.maxId"); - - return 0; -} diff --git a/tests/core/serialize/Avg.cpp b/tests/core/serialize/Avg.cpp index 7eacb4eb..2d88ef2c 100644 --- a/tests/core/serialize/Avg.cpp +++ b/tests/core/serialize/Avg.cpp @@ -32,17 +32,17 @@ int Avg(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, avg(bar.id), "AVG(tab_bar.id)"); - compare(__LINE__, avg(sqlpp::distinct, bar.id), "AVG(DISTINCT tab_bar.id)"); + SQLPP_COMPARE(avg(bar.id), "AVG(tab_bar.id)"); + SQLPP_COMPARE(avg(sqlpp::distinct, bar.id), "AVG(DISTINCT tab_bar.id)"); // Expression. #warning: Note that the inner parens aren't necessary. - compare(__LINE__, avg(bar.id + 7), "AVG((tab_bar.id + 7))"); - compare(__LINE__, avg(sqlpp::distinct, bar.id + 7), "AVG(DISTINCT (tab_bar.id + 7))"); + SQLPP_COMPARE(avg(bar.id + 7), "AVG((tab_bar.id + 7))"); + SQLPP_COMPARE(avg(sqlpp::distinct, bar.id + 7), "AVG(DISTINCT (tab_bar.id + 7))"); // With sub select. - compare(__LINE__, avg(select(sqlpp::value(7).as(sqlpp::alias::a))), "AVG((SELECT 7 AS a))"); - compare(__LINE__, avg(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "AVG(DISTINCT (SELECT 7 AS a))"); + SQLPP_COMPARE(avg(select(sqlpp::value(7).as(sqlpp::alias::a))), "AVG((SELECT 7 AS a))"); + SQLPP_COMPARE(avg(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "AVG(DISTINCT (SELECT 7 AS a))"); return 0; } diff --git a/tests/core/serialize/Blob.cpp b/tests/core/serialize/Blob.cpp index 6dad5e10..80c3299e 100644 --- a/tests/core/serialize/Blob.cpp +++ b/tests/core/serialize/Blob.cpp @@ -58,17 +58,17 @@ int Blob(int, char*[]) // const auto bar = test::TabBar{}; // Unconditionally - compare(__LINE__, select(foo.blobN).from(foo).where(foo.blobN == toByteVector("john doe")), + SQLPP_COMPARE(select(foo.blobN).from(foo).where(foo.blobN == toByteVector("john doe")), "SELECT tab_foo.blob_n FROM tab_foo WHERE (tab_foo.blob_n = x'6A6F686E20646F65')"); std::array arr{{'j', 'o', 'h', 'n', ' ', 'd', 'o', 'e'}}; - compare(__LINE__, select(foo.blobN).from(foo).where(foo.blobN == arr), + SQLPP_COMPARE(select(foo.blobN).from(foo).where(foo.blobN == arr), "SELECT tab_foo.blob_n FROM tab_foo WHERE (tab_foo.blob_n = x'6A6F686E20646F65')"); #warning: This should go somewhere else // Never - compare(__LINE__, where(sqlpp::value(false)), " WHERE " + getFalse()); - compare(__LINE__, sqlpp::where(false), " WHERE " + getFalse()); + SQLPP_COMPARE(where(sqlpp::value(false)), " WHERE " + getFalse()); + SQLPP_COMPARE(sqlpp::where(false), " WHERE " + getFalse()); return 0; } diff --git a/tests/core/serialize/CMakeLists.txt b/tests/core/serialize/CMakeLists.txt index 794ccb8a..4ba89a4f 100644 --- a/tests/core/serialize/CMakeLists.txt +++ b/tests/core/serialize/CMakeLists.txt @@ -23,25 +23,20 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. set(test_files - logical_expression.cpp - As.cpp Avg.cpp Blob.cpp Count.cpp CustomQuery.cpp DynamicWhere.cpp - Exists.cpp Float.cpp ForUpdate.cpp From.cpp - In.cpp Insert.cpp IsNotNull.cpp IsNull.cpp Lower.cpp Max.cpp Min.cpp - Operator.cpp Over.cpp Parameter.cpp ParameterizedVerbatim.cpp diff --git a/tests/core/serialize/Count.cpp b/tests/core/serialize/Count.cpp index 88953feb..6cca2e6d 100644 --- a/tests/core/serialize/Count.cpp +++ b/tests/core/serialize/Count.cpp @@ -32,17 +32,17 @@ int Count(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, count(bar.id), "COUNT(tab_bar.id)"); - compare(__LINE__, count(sqlpp::distinct, bar.id), "COUNT(DISTINCT tab_bar.id)"); + SQLPP_COMPARE(count(bar.id), "COUNT(tab_bar.id)"); + SQLPP_COMPARE(count(sqlpp::distinct, bar.id), "COUNT(DISTINCT tab_bar.id)"); // Expression. #warning: Note that the inner parens aren't necessary. - compare(__LINE__, count(bar.id + 7), "COUNT((tab_bar.id + 7))"); - compare(__LINE__, count(sqlpp::distinct, bar.id + 7), "COUNT(DISTINCT (tab_bar.id + 7))"); + SQLPP_COMPARE(count(bar.id + 7), "COUNT((tab_bar.id + 7))"); + SQLPP_COMPARE(count(sqlpp::distinct, bar.id + 7), "COUNT(DISTINCT (tab_bar.id + 7))"); // With sub select. - compare(__LINE__, count(select(sqlpp::value(7).as(sqlpp::alias::a))), "COUNT((SELECT 7 AS a))"); - compare(__LINE__, count(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "COUNT(DISTINCT (SELECT 7 AS a))"); + SQLPP_COMPARE(count(select(sqlpp::value(7).as(sqlpp::alias::a))), "COUNT((SELECT 7 AS a))"); + SQLPP_COMPARE(count(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "COUNT(DISTINCT (SELECT 7 AS a))"); return 0; } diff --git a/tests/core/serialize/CustomQuery.cpp b/tests/core/serialize/CustomQuery.cpp index 2fe643b4..5ba50a90 100644 --- a/tests/core/serialize/CustomQuery.cpp +++ b/tests/core/serialize/CustomQuery.cpp @@ -29,7 +29,7 @@ #include -SQLPP_ALIAS_PROVIDER(pragma) +SQLPP_ALIAS_PROVIDER(pragma); int CustomQuery(int, char*[]) { @@ -37,55 +37,51 @@ int CustomQuery(int, char*[]) const auto bar = test::TabBar{}; // Unconditionally - compare(__LINE__, - custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN), from(foo), - sqlpp::unconditionally()), - "SELECT DISTINCT tab_foo.double_n FROM tab_foo "); + SQLPP_COMPARE(custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN), from(foo), + sqlpp::unconditionally()), + "SELECT DISTINCT tab_foo.double_n FROM tab_foo "); // A full select statement made individual clauses - compare(__LINE__, - custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN), - from(foo.join(bar).on(foo.doubleN == bar.id)), where(bar.id > 17), group_by(foo.doubleN), - having(avg(bar.id) > 19), order_by(foo.doubleN.asc()), sqlpp::limit(10u), sqlpp::offset(100u)), - "SELECT DISTINCT tab_foo.double_n FROM tab_foo INNER JOIN tab_bar ON (tab_foo.double_n = tab_bar.id) WHERE " - "(tab_bar.id > 17) GROUP BY tab_foo.double_n HAVING (AVG(tab_bar.id) > 19) ORDER BY tab_foo.double_n ASC " - "LIMIT 10 OFFSET 100"); - - // A full select statement made individual clauses - compare( - __LINE__, + SQLPP_COMPARE( custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN), - from(foo.join(bar).on(foo.doubleN == bar.id)), where(bar.id > 17), - group_by(foo.doubleN), having(avg(bar.id) > 19), - order_by(foo.doubleN.asc(), foo.uIntN.order(sqlpp::sort_type::desc)), + from(foo.join(bar).on(foo.doubleN == bar.id)), where(bar.id > 17), group_by(foo.doubleN), + having(avg(bar.id) > 19), order_by(foo.doubleN.asc()), sqlpp::limit(10u), sqlpp::offset(100u)), + "SELECT DISTINCT tab_foo.double_n FROM tab_foo INNER JOIN tab_bar ON (tab_foo.double_n = tab_bar.id) WHERE " + "(tab_bar.id > 17) GROUP BY tab_foo.double_n HAVING (AVG(tab_bar.id) > 19) ORDER BY tab_foo.double_n ASC " + "LIMIT 10 OFFSET 100"); + + // A full select statement made individual clauses + SQLPP_COMPARE( + custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN), + from(foo.join(bar).on(foo.doubleN == bar.id)), where(bar.id > 17), group_by(foo.doubleN), + having(avg(bar.id) > 19), order_by(foo.doubleN.asc(), foo.uIntN.order(sqlpp::sort_type::desc)), sqlpp::limit(7u), sqlpp::offset(3u)), "SELECT DISTINCT tab_foo.double_n FROM tab_foo INNER JOIN tab_bar ON (tab_foo.double_n = tab_bar.id) WHERE " "(tab_bar.id > 17) GROUP BY tab_foo.double_n HAVING (AVG(tab_bar.id) > 19) ORDER BY tab_foo.double_n " "ASC,tab_foo.u_int_n DESC LIMIT 7 OFFSET 3"); // A pragma query/query for sqlite - compare(__LINE__, - custom_query(sqlpp::verbatim("PRAGMA user_version")).with_result_type_of(select(sqlpp::value(1).as(pragma))), - " PRAGMA user_version"); + SQLPP_COMPARE( + custom_query(sqlpp::verbatim("PRAGMA user_version")).with_result_type_of(select(sqlpp::value(1).as(pragma))), + " PRAGMA user_version"); // An insert from select for postgresql const auto x = 17; - compare(__LINE__, - custom_query(insert_into(foo).columns(foo.doubleN), - select(sqlpp::value(x).as(foo.doubleN)) - .from(foo) - .where(not exists(select(foo.doubleN).from(foo).where(foo.doubleN == x)))), - "INSERT INTO tab_foo (double_n) " - "SELECT 17 AS double_n FROM tab_foo " - "WHERE (NOT EXISTS(SELECT tab_foo.double_n FROM tab_foo WHERE (tab_foo.double_n = 17)))"); + SQLPP_COMPARE(custom_query(insert_into(foo).columns(foo.doubleN), + select(sqlpp::value(x).as(foo.doubleN)) + .from(foo) + .where(not exists(select(foo.doubleN).from(foo).where(foo.doubleN == x)))), + "INSERT INTO tab_foo (double_n) " + "SELECT 17 AS double_n FROM tab_foo " + "WHERE (NOT EXISTS(SELECT tab_foo.double_n FROM tab_foo WHERE (tab_foo.double_n = 17)))"); -#warning: reactivate +#warning : reactivate #if 0 // A multi-row "insert or ignore" auto batch = insert_columns(bar.textN, bar.boolNn); batch.add_values(bar.textN = "sample", bar.boolNn = true); batch.add_values(bar.textN = "ample", bar.boolNn = false); - compare(__LINE__, custom_query(sqlpp::insert(), sqlpp::verbatim(" OR IGNORE"), into(bar), batch), + SQLPP_COMPARE( custom_query(sqlpp::insert(), sqlpp::verbatim(" OR IGNORE"), into(bar), batch), "INSERT OR IGNORE INTO tab_bar (text_n,bool_nn) VALUES ('sample',1),('ample',0)"); #endif diff --git a/tests/core/serialize/DynamicWhere.cpp b/tests/core/serialize/DynamicWhere.cpp index 8d21a091..963a671f 100644 --- a/tests/core/serialize/DynamicWhere.cpp +++ b/tests/core/serialize/DynamicWhere.cpp @@ -35,11 +35,11 @@ int DynamicWhere(int, char*[]) const auto bar = test::TabBar{}; auto db = MockDb{}; - compare(__LINE__, sqlpp::unconditionally(), ""); - compare(__LINE__, where(bar.boolNn), " WHERE tab_bar.bool_nn"); + SQLPP_COMPARE(sqlpp::unconditionally(), ""); + SQLPP_COMPARE(where(bar.boolNn), " WHERE tab_bar.bool_nn"); - compare(__LINE__, where(bar.boolNn and dynamic(true, foo.boolN)), " WHERE (tab_bar.bool_nn AND tab_foo.bool_n)"); - compare(__LINE__, where(bar.boolNn and dynamic(false, foo.boolN)), " WHERE tab_bar.bool_nn"); + SQLPP_COMPARE(where(bar.boolNn and dynamic(true, foo.boolN)), " WHERE (tab_bar.bool_nn AND tab_foo.bool_n)"); + SQLPP_COMPARE(where(bar.boolNn and dynamic(false, foo.boolN)), " WHERE tab_bar.bool_nn"); return 0; } diff --git a/tests/core/serialize/Exists.cpp b/tests/core/serialize/Exists.cpp deleted file mode 100644 index 8ebc76a1..00000000 --- a/tests/core/serialize/Exists.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2023, 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 "compare.h" -#include - -int Exists(int, char* []) -{ - const auto bar = test::TabBar{}; - - // With sub select. - compare(__LINE__, exists(select(bar.id).from(bar).where(bar.id > 17)), - "EXISTS(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id > 17))"); - compare(__LINE__, bar.textN == "" and exists(select(bar.id).from(bar).where(bar.id > 17)), - "((tab_bar.text_n = '') AND EXISTS(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id > 17)))"); - - return 0; -} diff --git a/tests/core/serialize/Float.cpp b/tests/core/serialize/Float.cpp index e8701da9..019d50c7 100644 --- a/tests/core/serialize/Float.cpp +++ b/tests/core/serialize/Float.cpp @@ -30,6 +30,18 @@ namespace { + template + void assert_equal(int lineNo, const Result& result, const Expected& expected) + { + if (result != expected) + { + std::cerr << __FILE__ << " " << lineNo << '\n' + << "Expected: -->|" << expected << "|<--\n" + << "Received: -->|" << result << "|<--\n"; + throw std::runtime_error("unexpected result"); + } + } + template void float_safe_ostringstream_serializes_in_deserializable_format(int line, T value) { @@ -65,11 +77,10 @@ int Float(int, char*[]) float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086); float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086l); - compare(__LINE__, 10.0000114, "10.0000114"); - compare(__LINE__, 10.0000086f, string_for_10_0000086()); - compare(__LINE__, 10.0000086, string_for_10_0000086()); - compare(__LINE__, 10.0000086l, string_for_10_0000086()); - + SQLPP_COMPARE(10.0000114, "10.0000114"); + SQLPP_COMPARE(10.0000086f, string_for_10_0000086()); + SQLPP_COMPARE(10.0000086, string_for_10_0000086()); + SQLPP_COMPARE(10.0000086l, string_for_10_0000086()); return 0; } diff --git a/tests/core/serialize/ForUpdate.cpp b/tests/core/serialize/ForUpdate.cpp index f4b90e71..24a2c4fd 100644 --- a/tests/core/serialize/ForUpdate.cpp +++ b/tests/core/serialize/ForUpdate.cpp @@ -31,10 +31,10 @@ int ForUpdate(int, char* []) { const auto foo = test::TabFoo{}; - compare(__LINE__, sqlpp::for_update(), + SQLPP_COMPARE(sqlpp::for_update(), " FOR UPDATE "); - compare(__LINE__, select(foo.doubleN).from(foo).unconditionally().for_update(), + SQLPP_COMPARE(select(foo.doubleN).from(foo).unconditionally().for_update(), "SELECT tab_foo.double_n FROM tab_foo FOR UPDATE "); return 0; diff --git a/tests/core/serialize/From.cpp b/tests/core/serialize/From.cpp index 249eac0e..9e577202 100644 --- a/tests/core/serialize/From.cpp +++ b/tests/core/serialize/From.cpp @@ -41,37 +41,36 @@ int From(int, char* []) const auto cFoo = foo.as(sqlpp::alias::c); // Single table - compare(__LINE__, from(foo), " FROM tab_foo"); - compare(__LINE__, from(bar), " FROM tab_bar"); + SQLPP_COMPARE(from(foo), " FROM tab_foo"); + SQLPP_COMPARE(from(bar), " FROM tab_bar"); // Static joins - compare(__LINE__, from(foo.cross_join(bar)), " FROM tab_foo CROSS JOIN tab_bar"); - compare(__LINE__, from(foo.join(bar).on(foo.doubleN > bar.id)), + SQLPP_COMPARE(from(foo.cross_join(bar)), " FROM tab_foo CROSS JOIN tab_bar"); + SQLPP_COMPARE(from(foo.join(bar).on(foo.doubleN > bar.id)), " FROM tab_foo INNER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)"); - compare(__LINE__, from(foo.inner_join(bar).on(foo.doubleN > bar.id)), + SQLPP_COMPARE(from(foo.inner_join(bar).on(foo.doubleN > bar.id)), " FROM tab_foo INNER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)"); - compare(__LINE__, from(foo.outer_join(bar).on(foo.doubleN > bar.id)), + SQLPP_COMPARE(from(foo.outer_join(bar).on(foo.doubleN > bar.id)), " FROM tab_foo OUTER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)"); - compare(__LINE__, from(foo.left_outer_join(bar).on(foo.doubleN > bar.id)), + SQLPP_COMPARE(from(foo.left_outer_join(bar).on(foo.doubleN > bar.id)), " FROM tab_foo LEFT OUTER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)"); - compare(__LINE__, from(foo.right_outer_join(bar).on(foo.doubleN > bar.id)), + SQLPP_COMPARE(from(foo.right_outer_join(bar).on(foo.doubleN > bar.id)), " FROM tab_foo RIGHT OUTER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)"); - compare(__LINE__, from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN)), + SQLPP_COMPARE(from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN)), " FROM tab_foo AS a INNER JOIN tab_foo AS b ON (a.double_n > b.double_n)"); - compare( - __LINE__, from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN).join(cFoo).on(bFoo.doubleN > cFoo.doubleN)), + SQLPP_COMPARE(from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN).join(cFoo).on(bFoo.doubleN > cFoo.doubleN)), " FROM tab_foo AS a INNER JOIN tab_foo AS b ON (a.double_n > b.double_n) INNER JOIN tab_foo AS c ON (b.double_n > c.double_n)"); - compare(__LINE__, from(foo.join(bar).unconditionally()), " FROM tab_foo INNER JOIN tab_bar"); + SQLPP_COMPARE(from(foo.join(bar).unconditionally()), " FROM tab_foo INNER JOIN tab_bar"); // Static joins involving verbatim tables - compare(__LINE__, from(aFoo.join(sqlpp::verbatim_table("unknown_table")) + SQLPP_COMPARE(from(aFoo.join(sqlpp::verbatim_table("unknown_table")) .on(aFoo.doubleN > sqlpp::verbatim("unknown_table.column_x"))), " FROM tab_foo AS a INNER JOIN unknown_table ON (a.double_n > unknown_table.column_x)"); - compare(__LINE__, from(sqlpp::verbatim_table("unknown_table") + SQLPP_COMPARE(from(sqlpp::verbatim_table("unknown_table") .join(aFoo) .on(aFoo.doubleN > sqlpp::verbatim("unknown_table.column_x"))), " FROM unknown_table INNER JOIN tab_foo AS a ON (a.double_n > unknown_table.column_x)"); - compare(__LINE__, from(sqlpp::verbatim_table("unknown_table") + SQLPP_COMPARE(from(sqlpp::verbatim_table("unknown_table") .as(sqlpp::alias::a) .join(sqlpp::verbatim_table("another_table")) .on(sqlpp::verbatim("a.column_x > another_table.x"))), diff --git a/tests/core/serialize/In.cpp b/tests/core/serialize/In.cpp deleted file mode 100644 index ed10e6d7..00000000 --- a/tests/core/serialize/In.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2016-2016, 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 "compare.h" -#include "Sample.h" -#include - -#include - -namespace -{ - auto getFalse() -> std::string - { - MockDb::_serializer_context_t printer = {}; - return serialize(printer, sqlpp::value(false)).str(); - } -} - -int In(int, char* []) -{ - const auto foo = test::TabFoo{}; - const auto bar = test::TabBar{}; - - // Individual values - compare(__LINE__, foo.doubleN.in(17), "tab_foo.double_n IN(17)"); - compare(__LINE__, foo.doubleN.in(17, bar.id), "tab_foo.double_n IN(17,tab_bar.id)"); - compare(__LINE__, foo.doubleN.in(17, bar.id, sqlpp::value(19)), "tab_foo.double_n IN(17,tab_bar.id,19)"); - - // Lists - compare(__LINE__, foo.doubleN.in(std::vector{1.75f, 2.5f, 17.f, 0.f}), - "tab_foo.double_n IN(1.75,2.5,17,0)"); - - // Sub select - compare(__LINE__, foo.doubleN.in(select(bar.id).from(bar).unconditionally()), - "tab_foo.double_n IN(SELECT tab_bar.id FROM tab_bar)"); - - // Empty list (not normally allowed by SQL) - compare(__LINE__, foo.doubleN.in(std::vector{}), getFalse()); - - return 0; -} diff --git a/tests/core/serialize/Insert.cpp b/tests/core/serialize/Insert.cpp index 70f82ee8..607c7f22 100644 --- a/tests/core/serialize/Insert.cpp +++ b/tests/core/serialize/Insert.cpp @@ -42,15 +42,15 @@ int Insert(int, char* []) { const auto bar = test::TabBar{}; - compare(__LINE__, insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES"); - compare(__LINE__, insert_into(bar).set(bar.textN = "cheesecake", bar.boolNn = true), + SQLPP_COMPARE(insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES"); + SQLPP_COMPARE(insert_into(bar).set(bar.textN = "cheesecake", bar.boolNn = true), "INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")"); - compare(__LINE__, insert_into(bar).set(bar.textN = ::::sqlpp::nullopt, bar.boolNn = true), + SQLPP_COMPARE(insert_into(bar).set(bar.textN = ::sqlpp::nullopt, bar.boolNn = true), "INSERT INTO tab_bar (text_n,bool_nn) VALUES(NULL," + getTrue() + ")"); ::sqlpp::string_view cheeseCake = "cheesecake"; - compare(__LINE__, insert_into(bar).set(bar.textN = std::string(cheeseCake), bar.boolNn = true), + SQLPP_COMPARE(insert_into(bar).set(bar.textN = std::string(cheeseCake), bar.boolNn = true), "INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")"); - compare(__LINE__, insert_into(bar).set(bar.textN = ::sqlpp::string_view(cheeseCake), bar.boolNn = true), + SQLPP_COMPARE(insert_into(bar).set(bar.textN = ::sqlpp::string_view(cheeseCake), bar.boolNn = true), "INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")"); return 0; diff --git a/tests/core/serialize/IsNotNull.cpp b/tests/core/serialize/IsNotNull.cpp index 904285ad..695e0f6c 100644 --- a/tests/core/serialize/IsNotNull.cpp +++ b/tests/core/serialize/IsNotNull.cpp @@ -32,17 +32,17 @@ int IsNotNull(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, is_not_null(bar.textN), "(tab_bar.text_n IS NOT NULL)"); + SQLPP_COMPARE(is_not_null(bar.textN), "(tab_bar.text_n IS NOT NULL)"); // Expression. - compare(__LINE__, is_not_null(bar.textN + "suffix"), "((tab_bar.text_n || 'suffix') IS NOT NULL)"); + SQLPP_COMPARE(is_not_null(bar.textN + "suffix"), "((tab_bar.text_n || 'suffix') IS NOT NULL)"); // With sub select. - compare(__LINE__, is_not_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "((SELECT 'something' AS a) IS NOT NULL)"); + SQLPP_COMPARE(is_not_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "((SELECT 'something' AS a) IS NOT NULL)"); // Requires parens. - compare(__LINE__, is_not_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NOT NULL) OR (tab_bar.text_n = ''))"); - compare(__LINE__, bar.textN == "" or is_not_null(bar.textN), "((tab_bar.text_n = '') OR (tab_bar.text_n IS NOT NULL))"); + SQLPP_COMPARE(is_not_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NOT NULL) OR (tab_bar.text_n = ''))"); + SQLPP_COMPARE(bar.textN == "" or is_not_null(bar.textN), "((tab_bar.text_n = '') OR (tab_bar.text_n IS NOT NULL))"); return 0; } diff --git a/tests/core/serialize/IsNull.cpp b/tests/core/serialize/IsNull.cpp index 10679d44..e5e5102f 100644 --- a/tests/core/serialize/IsNull.cpp +++ b/tests/core/serialize/IsNull.cpp @@ -32,17 +32,17 @@ int IsNull(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, is_null(bar.textN), "(tab_bar.text_n IS NULL)"); + SQLPP_COMPARE(is_null(bar.textN), "(tab_bar.text_n IS NULL)"); // Expression. - compare(__LINE__, is_null(bar.textN + "suffix"), "((tab_bar.text_n || 'suffix') IS NULL)"); + SQLPP_COMPARE(is_null(bar.textN + "suffix"), "((tab_bar.text_n || 'suffix') IS NULL)"); // With sub select. - compare(__LINE__, is_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "((SELECT 'something' AS a) IS NULL)"); + SQLPP_COMPARE(is_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "((SELECT 'something' AS a) IS NULL)"); // Requires parens. - compare(__LINE__, is_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NULL) OR (tab_bar.text_n = ''))"); - compare(__LINE__, bar.textN == "" or is_null(bar.textN), "((tab_bar.text_n = '') OR (tab_bar.text_n IS NULL))"); + SQLPP_COMPARE(is_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NULL) OR (tab_bar.text_n = ''))"); + SQLPP_COMPARE(bar.textN == "" or is_null(bar.textN), "((tab_bar.text_n = '') OR (tab_bar.text_n IS NULL))"); return 0; } diff --git a/tests/core/serialize/Lower.cpp b/tests/core/serialize/Lower.cpp index bf706a9d..2424d9fb 100644 --- a/tests/core/serialize/Lower.cpp +++ b/tests/core/serialize/Lower.cpp @@ -32,14 +32,14 @@ int Lower(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, lower(bar.textN), "LOWER(tab_bar.text_n)"); + SQLPP_COMPARE(lower(bar.textN), "LOWER(tab_bar.text_n)"); // Expression. #warning: Note that the inner parens aren't necessary. - compare(__LINE__, lower(bar.textN + "suffix"), "LOWER((tab_bar.text_n || 'suffix'))"); + SQLPP_COMPARE(lower(bar.textN + "suffix"), "LOWER((tab_bar.text_n || 'suffix'))"); // With sub select. - compare(__LINE__, lower(select(sqlpp::value("something").as(sqlpp::alias::a))), "LOWER((SELECT 'something' AS a))"); + SQLPP_COMPARE(lower(select(sqlpp::value("something").as(sqlpp::alias::a))), "LOWER((SELECT 'something' AS a))"); return 0; } diff --git a/tests/core/serialize/Max.cpp b/tests/core/serialize/Max.cpp index 602d68de..ecd7e5c1 100644 --- a/tests/core/serialize/Max.cpp +++ b/tests/core/serialize/Max.cpp @@ -32,17 +32,17 @@ int Max(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, max(bar.id), "MAX(tab_bar.id)"); - compare(__LINE__, max(sqlpp::distinct, bar.id), "MAX(DISTINCT tab_bar.id)"); + SQLPP_COMPARE(max(bar.id), "MAX(tab_bar.id)"); + SQLPP_COMPARE(max(sqlpp::distinct, bar.id), "MAX(DISTINCT tab_bar.id)"); // Expression. // Note that the inner parens aren't necessary. - compare(__LINE__, max(bar.id + 7), "MAX((tab_bar.id + 7))"); - compare(__LINE__, max(sqlpp::distinct, bar.id + 7), "MAX(DISTINCT (tab_bar.id + 7))"); + SQLPP_COMPARE(max(bar.id + 7), "MAX((tab_bar.id + 7))"); + SQLPP_COMPARE(max(sqlpp::distinct, bar.id + 7), "MAX(DISTINCT (tab_bar.id + 7))"); // With sub select. - compare(__LINE__, max(select(sqlpp::value(7).as(sqlpp::alias::a))), "MAX((SELECT 7 AS a))"); - compare(__LINE__, max(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "MAX(DISTINCT (SELECT 7 AS a))"); + SQLPP_COMPARE(max(select(sqlpp::value(7).as(sqlpp::alias::a))), "MAX((SELECT 7 AS a))"); + SQLPP_COMPARE(max(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "MAX(DISTINCT (SELECT 7 AS a))"); return 0; } diff --git a/tests/core/serialize/Min.cpp b/tests/core/serialize/Min.cpp index 82373a23..96806e0a 100644 --- a/tests/core/serialize/Min.cpp +++ b/tests/core/serialize/Min.cpp @@ -32,17 +32,17 @@ int Min(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, min(bar.id), "MIN(tab_bar.id)"); - compare(__LINE__, min(sqlpp::distinct, bar.id), "MIN(DISTINCT tab_bar.id)"); + SQLPP_COMPARE(min(bar.id), "MIN(tab_bar.id)"); + SQLPP_COMPARE(min(sqlpp::distinct, bar.id), "MIN(DISTINCT tab_bar.id)"); // Expression. // Note that the inner parens aren't necessary. - compare(__LINE__, min(bar.id + 7), "MIN((tab_bar.id + 7))"); - compare(__LINE__, min(sqlpp::distinct, bar.id + 7), "MIN(DISTINCT (tab_bar.id + 7))"); + SQLPP_COMPARE(min(bar.id + 7), "MIN((tab_bar.id + 7))"); + SQLPP_COMPARE(min(sqlpp::distinct, bar.id + 7), "MIN(DISTINCT (tab_bar.id + 7))"); // With sub select. - compare(__LINE__, min(select(sqlpp::value(7).as(sqlpp::alias::a))), "MIN((SELECT 7 AS a))"); - compare(__LINE__, min(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "MIN(DISTINCT (SELECT 7 AS a))"); + SQLPP_COMPARE(min(select(sqlpp::value(7).as(sqlpp::alias::a))), "MIN((SELECT 7 AS a))"); + SQLPP_COMPARE(min(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "MIN(DISTINCT (SELECT 7 AS a))"); return 0; } diff --git a/tests/core/serialize/Operator.cpp b/tests/core/serialize/Operator.cpp deleted file mode 100644 index cd4b9b40..00000000 --- a/tests/core/serialize/Operator.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2021-2021, 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 "compare.h" -#include - -#include - -int Operator(int, char* []) -{ - const auto foo = test::TabFoo{}; - const auto bar = test::TabBar{}; - - // Plus - compare(__LINE__, bar.id + 3u, "(tab_bar.id + 3)"); - compare(__LINE__, sqlpp::value(3) + foo.uIntN, "(3 + tab_foo.u_int_n)"); - - // Shift left - compare(__LINE__, sqlpp::value(3) << foo.uIntN, "(3 << tab_foo.u_int_n)"); - compare(__LINE__, bar.id << 3u, "(tab_bar.id << 3)"); - - // Shift right - compare(__LINE__, sqlpp::value(3) >> foo.uIntN, "(3 >> tab_foo.u_int_n)"); - compare(__LINE__, bar.id >> 3u, "(tab_bar.id >> 3)"); - - // Comparison - compare(__LINE__, bar.id < 3u, "(tab_bar.id < 3)"); - compare(__LINE__, bar.id <= 3u, "(tab_bar.id <= 3)"); - compare(__LINE__, bar.id == 3u, "(tab_bar.id = 3)"); - compare(__LINE__, bar.id != 3u, "(tab_bar.id <> 3)"); - compare(__LINE__, bar.id >= 3u, "(tab_bar.id >= 3)"); - compare(__LINE__, bar.id > 3u, "(tab_bar.id > 3)"); - - return 0; -} diff --git a/tests/core/serialize/Over.cpp b/tests/core/serialize/Over.cpp index 68ee4769..02dcc16a 100644 --- a/tests/core/serialize/Over.cpp +++ b/tests/core/serialize/Over.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020, Roland Bock, MacDue + * Copyright (c) 2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -27,16 +27,16 @@ #include "compare.h" #include -SQLPP_ALIAS_PROVIDER(dueutil) +SQLPP_ALIAS_PROVIDER(cheese); int Over(int, char* []) { auto const foo = test::TabFoo{}; - compare(__LINE__, select(avg(foo.doubleN).over().as(dueutil)), "SELECT AVG(tab_foo.double_n) OVER() AS dueutil"); - compare(__LINE__, select(count(foo.doubleN).over().as(dueutil)), "SELECT COUNT(tab_foo.double_n) OVER() AS dueutil"); - compare(__LINE__, select(max(foo.doubleN).over().as(dueutil)), "SELECT MAX(tab_foo.double_n) OVER() AS dueutil"); - compare(__LINE__, select(min(foo.doubleN).over().as(dueutil)), "SELECT MIN(tab_foo.double_n) OVER() AS dueutil"); - compare(__LINE__, select(sum(foo.doubleN).over().as(dueutil)), "SELECT SUM(tab_foo.double_n) OVER() AS dueutil"); + SQLPP_COMPARE(select(avg(foo.doubleN).over().as(cheese)), "SELECT AVG(tab_foo.double_n) OVER() AS cheese"); + SQLPP_COMPARE(select(count(foo.doubleN).over().as(cheese)), "SELECT COUNT(tab_foo.double_n) OVER() AS cheese"); + SQLPP_COMPARE(select(max(foo.doubleN).over().as(cheese)), "SELECT MAX(tab_foo.double_n) OVER() AS cheese"); + SQLPP_COMPARE(select(min(foo.doubleN).over().as(cheese)), "SELECT MIN(tab_foo.double_n) OVER() AS cheese"); + SQLPP_COMPARE(select(sum(foo.doubleN).over().as(cheese)), "SELECT SUM(tab_foo.double_n) OVER() AS cheese"); return 0; } diff --git a/tests/core/serialize/Parameter.cpp b/tests/core/serialize/Parameter.cpp index 8d206023..363d4c66 100644 --- a/tests/core/serialize/Parameter.cpp +++ b/tests/core/serialize/Parameter.cpp @@ -32,8 +32,8 @@ int Parameter(int, char*[]) const auto foo = test::TabFoo{}; const auto bar = test::TabBar{}; - compare(__LINE__, parameter(foo.doubleN), "?"); - compare(__LINE__, bar.id > parameter(foo.doubleN), "(tab_bar.id > ?)"); + SQLPP_COMPARE(parameter(foo.doubleN), "?"); + SQLPP_COMPARE(bar.id > parameter(foo.doubleN), "(tab_bar.id > ?)"); #warning: Need type tests for parameter, too (do they have the right value type and the right paramter type?) diff --git a/tests/core/serialize/ParameterizedVerbatim.cpp b/tests/core/serialize/ParameterizedVerbatim.cpp index e8aae6ba..edf59323 100644 --- a/tests/core/serialize/ParameterizedVerbatim.cpp +++ b/tests/core/serialize/ParameterizedVerbatim.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2020, Roland Bock, MacDue + * Copyright (c) 2013, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -29,7 +29,7 @@ #include -SQLPP_ALIAS_PROVIDER(quester_player_level) +SQLPP_ALIAS_PROVIDER(quester_player_level); int ParameterizedVerbatim(int, char* []) { @@ -37,7 +37,7 @@ int ParameterizedVerbatim(int, char* []) auto checking_value_in_range = sqlpp::parameterized_verbatim( "(quests.spawn_level_range @> CAST(", parameter(sqlpp::integral(), quester_player_level), " AS integer))"); - compare(__LINE__, checking_value_in_range, "(quests.spawn_level_range @> CAST(? AS integer))"); + SQLPP_COMPARE(checking_value_in_range, "(quests.spawn_level_range @> CAST(? AS integer))"); return 0; } diff --git a/tests/core/serialize/SelectAs.cpp b/tests/core/serialize/SelectAs.cpp index 101f3d47..4470df9e 100644 --- a/tests/core/serialize/SelectAs.cpp +++ b/tests/core/serialize/SelectAs.cpp @@ -29,8 +29,8 @@ #include -SQLPP_ALIAS_PROVIDER(id_count) -SQLPP_ALIAS_PROVIDER(cheese) +SQLPP_ALIAS_PROVIDER(id_count); +SQLPP_ALIAS_PROVIDER(cheese); using namespace sqlpp; @@ -41,7 +41,7 @@ int SelectAs(int, char*[]) #warning: The select itself should not offer an "as" that yields a value. #warning: The id_count should offer the alias that offers the value. - compare(__LINE__, select(foo.doubleN, select(count(bar.id).as(id_count)).from(bar).unconditionally().as(cheese)), + SQLPP_COMPARE(select(foo.doubleN, select(count(bar.id).as(id_count)).from(bar).unconditionally().as(cheese)), "SELECT tab_foo.double_n,(SELECT COUNT(tab_bar.id) AS id_count FROM tab_bar) AS cheese"); return 0; diff --git a/tests/core/serialize/SelectColumns.cpp b/tests/core/serialize/SelectColumns.cpp index fb3b62ee..e9d5824f 100644 --- a/tests/core/serialize/SelectColumns.cpp +++ b/tests/core/serialize/SelectColumns.cpp @@ -35,35 +35,33 @@ int SelectColumns(int, char*[]) const auto bar = test::TabBar{}; // Single column - compare(__LINE__, select(foo.doubleN), "SELECT tab_foo.double_n"); + SQLPP_COMPARE(select(foo.doubleN), "SELECT tab_foo.double_n"); // Two columns - compare(__LINE__, select(foo.doubleN, bar.id), "SELECT tab_foo.double_n,tab_bar.id"); + SQLPP_COMPARE(select(foo.doubleN, bar.id), "SELECT tab_foo.double_n,tab_bar.id"); // All columns of a table - compare(__LINE__, select(all_of(foo)), + SQLPP_COMPARE(select(all_of(foo)), "SELECT tab_foo.id,tab_foo.text_nn_d,tab_foo.int_n,tab_foo.double_n,tab_foo.u_int_n,tab_foo.blob_n,tab_foo.bool_n"); // All columns of a table plus one more - compare( - __LINE__, select(all_of(foo), bar.id), + SQLPP_COMPARE(select(all_of(foo), bar.id), "SELECT tab_foo.id,tab_foo.text_nn_d,tab_foo.int_n,tab_foo.double_n,tab_foo.u_int_n,tab_foo.blob_n,tab_foo.bool_n,tab_bar.id"); // One more, plus all columns of a table - compare( - __LINE__, select(bar.id, all_of(foo)), + SQLPP_COMPARE(select(bar.id, all_of(foo)), "SELECT tab_bar.id,tab_foo.id,tab_foo.text_nn_d,tab_foo.int_n,tab_foo.double_n,tab_foo.u_int_n,tab_foo.blob_n,tab_foo.bool_n"); // Column and aggregate function - compare(__LINE__, select(foo.doubleN, count(bar.id).as(id_count)), "SELECT tab_foo.double_n,COUNT(tab_bar.id) AS id_count"); + SQLPP_COMPARE(select(foo.doubleN, count(bar.id).as(id_count)), "SELECT tab_foo.double_n,COUNT(tab_bar.id) AS id_count"); // Column aliases - compare(__LINE__, select(foo.doubleN.as(sqlpp::alias::o), count(bar.id).as(sqlpp::alias::a)), + SQLPP_COMPARE(select(foo.doubleN.as(sqlpp::alias::o), count(bar.id).as(sqlpp::alias::a)), "SELECT tab_foo.double_n AS o,COUNT(tab_bar.id) AS a"); // Optional column manually - compare(__LINE__, select(dynamic(true, bar.id)), "SELECT tab_bar.id"); - compare(__LINE__, select(dynamic(false, bar.id)), "SELECT NULL"); + SQLPP_COMPARE(select(dynamic(true, bar.id)), "SELECT tab_bar.id"); + SQLPP_COMPARE(select(dynamic(false, bar.id)), "SELECT NULL"); #warning: add more optional column tests diff --git a/tests/core/serialize/SelectFlags.cpp b/tests/core/serialize/SelectFlags.cpp index eb244a07..9ebd3581 100644 --- a/tests/core/serialize/SelectFlags.cpp +++ b/tests/core/serialize/SelectFlags.cpp @@ -33,17 +33,17 @@ int SelectFlags(int, char*[]) const auto bar = test::TabBar{}; // No flags - compare(__LINE__, select(foo.doubleN), "SELECT tab_foo.double_n"); + SQLPP_COMPARE(select(foo.doubleN), "SELECT tab_foo.double_n"); // No flags #warning: This should work - //compare(__LINE__, sqlpp::select_flags(), ""); + //SQLPP_COMPARE(sqlpp::select_flags(), ""); // No flags - compare(__LINE__, select(foo.doubleN).flags(sqlpp::distinct), "SELECT DISTINCT tab_foo.double_n"); + SQLPP_COMPARE(select(foo.doubleN).flags(sqlpp::distinct), "SELECT DISTINCT tab_foo.double_n"); // One flag - compare(__LINE__, select_flags(sqlpp::distinct), "DISTINCT "); + SQLPP_COMPARE(select_flags(sqlpp::distinct), "DISTINCT "); #warning: Add tests for dynamic select flags diff --git a/tests/core/serialize/Sum.cpp b/tests/core/serialize/Sum.cpp index a9defdb8..e0adeda0 100644 --- a/tests/core/serialize/Sum.cpp +++ b/tests/core/serialize/Sum.cpp @@ -32,17 +32,17 @@ int Sum(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, sum(bar.id), "SUM(tab_bar.id)"); - compare(__LINE__, sum(sqlpp::distinct, bar.id), "SUM(DISTINCT tab_bar.id)"); + SQLPP_COMPARE(sum(bar.id), "SUM(tab_bar.id)"); + SQLPP_COMPARE(sum(sqlpp::distinct, bar.id), "SUM(DISTINCT tab_bar.id)"); // Expression. // Note that the inner parens aren't necessary. - compare(__LINE__, sum(bar.id + 7), "SUM((tab_bar.id + 7))"); - compare(__LINE__, sum(sqlpp::distinct, bar.id + 7), "SUM(DISTINCT (tab_bar.id + 7))"); + SQLPP_COMPARE(sum(bar.id + 7), "SUM((tab_bar.id + 7))"); + SQLPP_COMPARE(sum(sqlpp::distinct, bar.id + 7), "SUM(DISTINCT (tab_bar.id + 7))"); // With sub select. - compare(__LINE__, sum(select(sqlpp::value(7).as(sqlpp::alias::a))), "SUM((SELECT 7 AS a))"); - compare(__LINE__, sum(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "SUM(DISTINCT (SELECT 7 AS a))"); + SQLPP_COMPARE(sum(select(sqlpp::value(7).as(sqlpp::alias::a))), "SUM((SELECT 7 AS a))"); + SQLPP_COMPARE(sum(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "SUM(DISTINCT (SELECT 7 AS a))"); return 0; } diff --git a/tests/core/serialize/TableAlias.cpp b/tests/core/serialize/TableAlias.cpp index 52496db4..b22e9cf8 100644 --- a/tests/core/serialize/TableAlias.cpp +++ b/tests/core/serialize/TableAlias.cpp @@ -29,7 +29,7 @@ #include -SQLPP_ALIAS_PROVIDER(sample) +SQLPP_ALIAS_PROVIDER(sample); int TableAlias(int, char* []) { @@ -37,13 +37,13 @@ int TableAlias(int, char* []) const auto bar = test::TabBar{}; // Individual values - compare(__LINE__, foo.as(bar), "tab_foo AS tab_bar"); - compare(__LINE__, select(foo.doubleN).from(foo).unconditionally().as(bar), + SQLPP_COMPARE(foo.as(bar), "tab_foo AS tab_bar"); + SQLPP_COMPARE(select(foo.doubleN).from(foo).unconditionally().as(bar), "(SELECT tab_foo.double_n FROM tab_foo) AS tab_bar"); // Table alias const auto tab = foo.as(sample); - compare(__LINE__, select(tab.doubleN).from(tab).unconditionally(), + SQLPP_COMPARE(select(tab.doubleN).from(tab).unconditionally(), "SELECT sample.double_n FROM tab_foo AS sample"); return 0; diff --git a/tests/core/serialize/Trim.cpp b/tests/core/serialize/Trim.cpp index e4881147..9942c7f0 100644 --- a/tests/core/serialize/Trim.cpp +++ b/tests/core/serialize/Trim.cpp @@ -32,14 +32,14 @@ int Trim(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, trim(bar.textN), "TRIM(tab_bar.text_n)"); + SQLPP_COMPARE(trim(bar.textN), "TRIM(tab_bar.text_n)"); // Expression. #warning: Note that the inner parens aren't necessary. - compare(__LINE__, trim(bar.textN + "suffix"), "TRIM((tab_bar.text_n || 'suffix'))"); + SQLPP_COMPARE(trim(bar.textN + "suffix"), "TRIM((tab_bar.text_n || 'suffix'))"); // With sub select. - compare(__LINE__, trim(select(sqlpp::value("something").as(sqlpp::alias::a))), "TRIM((SELECT 'something' AS a))"); + SQLPP_COMPARE(trim(select(sqlpp::value("something").as(sqlpp::alias::a))), "TRIM((SELECT 'something' AS a))"); return 0; } diff --git a/tests/core/serialize/Upper.cpp b/tests/core/serialize/Upper.cpp index d88f0419..00839a1d 100644 --- a/tests/core/serialize/Upper.cpp +++ b/tests/core/serialize/Upper.cpp @@ -32,14 +32,14 @@ int Upper(int, char* []) const auto bar = test::TabBar{}; // Single column. - compare(__LINE__, upper(bar.textN), "UPPER(tab_bar.text_n)"); + SQLPP_COMPARE(upper(bar.textN), "UPPER(tab_bar.text_n)"); // Expression. #warning: Note that the inner parens aren't necessary. - compare(__LINE__, upper(bar.textN + "suffix"), "UPPER((tab_bar.text_n || 'suffix'))"); + SQLPP_COMPARE(upper(bar.textN + "suffix"), "UPPER((tab_bar.text_n || 'suffix'))"); // With sub select. - compare(__LINE__, upper(select(sqlpp::value("something").as(sqlpp::alias::a))), "UPPER((SELECT 'something' AS a))"); + SQLPP_COMPARE(upper(select(sqlpp::value("something").as(sqlpp::alias::a))), "UPPER((SELECT 'something' AS a))"); return 0; } diff --git a/tests/core/serialize/Where.cpp b/tests/core/serialize/Where.cpp index 77b54cbe..20db579a 100644 --- a/tests/core/serialize/Where.cpp +++ b/tests/core/serialize/Where.cpp @@ -50,9 +50,9 @@ int Where(int, char*[]) const auto bar = test::TabBar{}; // Unconditionally - compare(__LINE__, select(foo.doubleN).from(foo).unconditionally(), "SELECT tab_foo.double_n FROM tab_foo"); - compare(__LINE__, remove_from(foo).unconditionally(), "DELETE FROM tab_foo"); - compare(__LINE__, update(foo).set(foo.doubleN = 42).unconditionally(), "UPDATE tab_foo SET double_n = 42"); + SQLPP_COMPARE(select(foo.doubleN).from(foo).unconditionally(), "SELECT tab_foo.double_n FROM tab_foo"); + SQLPP_COMPARE(remove_from(foo).unconditionally(), "DELETE FROM tab_foo"); + SQLPP_COMPARE(update(foo).set(foo.doubleN = 42).unconditionally(), "UPDATE tab_foo SET double_n = 42"); static_assert( sqlpp::is_numeric::value, ""); @@ -65,32 +65,32 @@ int Where(int, char*[]) static_assert( sqlpp::values_are_comparable::value, ""); - compare(__LINE__, update(foo).set(foo.doubleN = foo.doubleN - -1).unconditionally(), + SQLPP_COMPARE(update(foo).set(foo.doubleN = foo.doubleN - -1).unconditionally(), "UPDATE tab_foo SET double_n = (tab_foo.double_n - -1)"); - compare(__LINE__, where(sqlpp::value(true)), " WHERE " + getTrue()); + SQLPP_COMPARE(where(sqlpp::value(true)), " WHERE " + getTrue()); // Never - compare(__LINE__, where(sqlpp::value(false)), " WHERE " + getFalse()); + SQLPP_COMPARE(where(sqlpp::value(false)), " WHERE " + getFalse()); // Sometimes - compare(__LINE__, where(bar.boolNn), " WHERE tab_bar.bool_nn"); - compare(__LINE__, where(bar.boolNn == false), " WHERE (tab_bar.bool_nn = " + getFalse() + ")"); - compare(__LINE__, where(bar.textN.is_null()), " WHERE (tab_bar.text_n IS NULL)"); - compare(__LINE__, where(bar.textN == "SQL"), " WHERE (tab_bar.text_n = 'SQL')"); - compare(__LINE__, where(is_not_distinct_from(bar.textN, ::sqlpp::make_optional("SQL"))), + SQLPP_COMPARE(where(bar.boolNn), " WHERE tab_bar.bool_nn"); + SQLPP_COMPARE(where(bar.boolNn == false), " WHERE (tab_bar.bool_nn = " + getFalse() + ")"); + SQLPP_COMPARE(where(bar.textN.is_null()), " WHERE (tab_bar.text_n IS NULL)"); + SQLPP_COMPARE(where(bar.textN == "SQL"), " WHERE (tab_bar.text_n = 'SQL')"); + SQLPP_COMPARE(where(is_not_distinct_from(bar.textN, ::sqlpp::make_optional("SQL"))), " WHERE (tab_bar.text_n IS NOT DISTINCT FROM 'SQL')"); - compare(__LINE__, where(is_not_distinct_from(bar.textN, ::sqlpp::nullopt)), + SQLPP_COMPARE(where(is_not_distinct_from(bar.textN, ::sqlpp::nullopt)), " WHERE (tab_bar.text_n IS NOT DISTINCT FROM NULL)"); - compare(__LINE__, where(bar.textN.is_not_distinct_from(::sqlpp::make_optional("SQL"))), + SQLPP_COMPARE(where(bar.textN.is_not_distinct_from(::sqlpp::make_optional("SQL"))), " WHERE (tab_bar.text_n IS NOT DISTINCT FROM 'SQL')"); - compare(__LINE__, where(bar.textN.is_not_distinct_from(::sqlpp::nullopt)), + SQLPP_COMPARE(where(bar.textN.is_not_distinct_from(::sqlpp::nullopt)), " WHERE (tab_bar.text_n IS NOT DISTINCT FROM NULL)"); // string argument - compare(__LINE__, where(bar.textN == std::string("SQL")), " WHERE (tab_bar.text_n = 'SQL')"); + SQLPP_COMPARE(where(bar.textN == std::string("SQL")), " WHERE (tab_bar.text_n = 'SQL')"); // string_view argument - compare(__LINE__, where(bar.textN == ::sqlpp::string_view("SQL")), " WHERE (tab_bar.text_n = 'SQL')"); + SQLPP_COMPARE(where(bar.textN == ::sqlpp::string_view("SQL")), " WHERE (tab_bar.text_n = 'SQL')"); return 0; } diff --git a/tests/core/serialize/compare.h b/tests/core/serialize/compare.h index 232d4f07..98fd8696 100644 --- a/tests/core/serialize/compare.h +++ b/tests/core/serialize/compare.h @@ -28,31 +28,6 @@ #include "MockDb.h" #include -namespace -{ - template - void assert_equal(const std::string& file, int lineNo, const Result& result, const Expected& expected) - { - if (result != expected) - { - std::cerr << file << " " << lineNo << '\n' << "Expected: -->|" << expected << "|<--\n" - << "Received: -->|" << result << "|<--\n"; - throw std::runtime_error("unexpected result"); - } - } - -#warning Drop compare and use SQLPP_COMPARE instead - template - void compare(int lineNo, const Expression& expr, const std::string& expected) - { - MockDb::_serializer_context_t printer = {}; - - using sqlpp::serialize; - const auto result = serialize(printer, expr).str(); - - assert_equal(lineNo, result, expected); - } - #warning: Maybe move this into the library/test_support together with MockDb #define SQLPP_COMPARE(expr, expected_string) \ { \ @@ -69,4 +44,3 @@ namespace return -1; \ } \ } -} diff --git a/tests/core/serialize/logical_expression.cpp b/tests/core/serialize/logical_expression.cpp deleted file mode 100644 index a34152b3..00000000 --- a/tests/core/serialize/logical_expression.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2021-2021, 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 "compare.h" -#include - -#include - -int logical_expression(int, char* []) -{ - const auto foo = test::TabFoo{}; - const auto bar = test::TabBar{}; - - // Basic logical expression. - compare(__LINE__, foo.boolN and bar.boolNn, "(tab_foo.bool_n AND tab_bar.bool_nn)"); - compare(__LINE__, foo.boolN or bar.boolNn, "(tab_foo.bool_n OR tab_bar.bool_nn)"); - compare(__LINE__, not foo.boolN, "(NOT tab_foo.bool_n)"); - - // With dynamic part. - compare(__LINE__, foo.boolN and dynamic(true, bar.boolNn), "(tab_foo.bool_n AND tab_bar.bool_nn)"); - compare(__LINE__, foo.boolN and dynamic(false, bar.boolNn), "tab_foo.bool_n"); - - compare(__LINE__, foo.boolN or dynamic(true, bar.boolNn), "(tab_foo.bool_n OR tab_bar.bool_nn)"); - compare(__LINE__, foo.boolN or dynamic(false, bar.boolNn), "tab_foo.bool_n"); - - // Advanced logical expression. - compare(__LINE__, not foo.boolN and not bar.boolNn, "((NOT tab_foo.bool_n) AND (NOT tab_bar.bool_nn))"); - compare(__LINE__, not foo.boolN or not bar.boolNn, "((NOT tab_foo.bool_n) OR (NOT tab_bar.bool_nn))"); - compare(__LINE__, not (foo.boolN and bar.boolNn), "(NOT (tab_foo.bool_n AND tab_bar.bool_nn))"); - compare(__LINE__, not (foo.boolN or bar.boolNn), "(NOT (tab_foo.bool_n OR tab_bar.bool_nn))"); - - // With dynamic part. - compare(__LINE__, not foo.boolN and dynamic(true, not bar.boolNn), "((NOT tab_foo.bool_n) AND (NOT tab_bar.bool_nn))"); - compare(__LINE__, not foo.boolN and dynamic(false, not bar.boolNn), "(NOT tab_foo.bool_n)"); - - compare(__LINE__, not foo.boolN or dynamic(true, not bar.boolNn), "((NOT tab_foo.bool_n) OR (NOT tab_bar.bool_nn))"); - compare(__LINE__, not foo.boolN or dynamic(false, not bar.boolNn), "(NOT tab_foo.bool_n)"); - -#warning: Consider reducing braces a bit as in sqlpp17 - - // Chained expression. - compare(__LINE__, foo.boolN and bar.boolNn and (bar.id > 17), - "((tab_foo.bool_n AND tab_bar.bool_nn) AND (tab_bar.id > 17))"); - compare(__LINE__, foo.boolN or bar.boolNn or (bar.id > 17), - "((tab_foo.bool_n OR tab_bar.bool_nn) OR (tab_bar.id > 17))"); - - compare(__LINE__, foo.boolN and bar.boolNn and dynamic(true, bar.id > 17), - "((tab_foo.bool_n AND tab_bar.bool_nn) AND (tab_bar.id > 17))"); - compare(__LINE__, foo.boolN and bar.boolNn and dynamic(false, bar.id > 17), - "(tab_foo.bool_n AND tab_bar.bool_nn)"); - compare(__LINE__, foo.boolN or bar.boolNn or dynamic(true, bar.id > 17), - "((tab_foo.bool_n OR tab_bar.bool_nn) OR (tab_bar.id > 17))"); - compare(__LINE__, foo.boolN or bar.boolNn or dynamic(false, bar.id > 17), - "(tab_foo.bool_n OR tab_bar.bool_nn)"); - - compare(__LINE__, foo.boolN and dynamic(true, bar.boolNn and (bar.id > 17)), - "(tab_foo.bool_n AND (tab_bar.bool_nn AND (tab_bar.id > 17)))"); - compare(__LINE__, foo.boolN and dynamic(false, bar.boolNn and (bar.id > 17)), - "tab_foo.bool_n"); - compare(__LINE__, foo.boolN or dynamic(true, bar.boolNn or (bar.id > 17)), - "(tab_foo.bool_n OR (tab_bar.bool_nn OR (tab_bar.id > 17)))"); - compare(__LINE__, foo.boolN or dynamic(false, bar.boolNn or (bar.id > 17)), - "tab_foo.bool_n"); - - return 0; -} diff --git a/tests/core/serialize/operator/as_expression.cpp b/tests/core/serialize/operator/as_expression.cpp index fe3b24d1..8585869b 100644 --- a/tests/core/serialize/operator/as_expression.cpp +++ b/tests/core/serialize/operator/as_expression.cpp @@ -35,12 +35,15 @@ int main(int, char* []) SQLPP_COMPARE(val.as(v), "17 AS v"); SQLPP_COMPARE(expr.as(v), "(17 + 4) AS v"); + SQLPP_COMPARE(count(val).as(v), "COUNT(17) AS v"); SQLPP_COMPARE(dynamic(true, val).as(v), "17 AS v"); SQLPP_COMPARE(dynamic(true, expr).as(v), "(17 + 4) AS v"); + SQLPP_COMPARE(dynamic(true, count(val)).as(v), "COUNT(17) AS v"); SQLPP_COMPARE(dynamic(false, val).as(v), "NULL AS v"); SQLPP_COMPARE(dynamic(false, expr).as(v), "NULL AS v"); + SQLPP_COMPARE(dynamic(false, count(val)).as(v), "NULL AS v"); return 0; } diff --git a/tests/core/serialize/operator/exists_expression.cpp b/tests/core/serialize/operator/exists_expression.cpp index 1a8f01ff..ccff1d0c 100644 --- a/tests/core/serialize/operator/exists_expression.cpp +++ b/tests/core/serialize/operator/exists_expression.cpp @@ -33,6 +33,8 @@ int main(int, char* []) const auto val = sqlpp::value(17); SQLPP_COMPARE(exists(select(val.as(v))), "EXISTS (SELECT 17 AS v)"); + SQLPP_COMPARE(true and exists(select(val.as(v))), "1 AND EXISTS (SELECT 17 AS v)"); + SQLPP_COMPARE(exists(select(val.as(v))) and true, "EXISTS (SELECT 17 AS v) AND 1"); return 0; } diff --git a/tests/core/serialize/operator/logical_expression.cpp b/tests/core/serialize/operator/logical_expression.cpp index b59d3e2c..7c98106c 100644 --- a/tests/core/serialize/operator/logical_expression.cpp +++ b/tests/core/serialize/operator/logical_expression.cpp @@ -45,6 +45,12 @@ int main(int, char* []) SQLPP_COMPARE(not val, "NOT 1"); SQLPP_COMPARE(not expr, "NOT (17 > 15)"); + // Combined logical expression. + SQLPP_COMPARE(not val and not expr, "(NOT 1) AND (NOT (17 > 15))"); + SQLPP_COMPARE(not val or not expr, "(NOT 1) OR (NOT (17 > 15))"); + SQLPP_COMPARE(not (val and expr), "NOT (1 AND (17 > 15))"); + SQLPP_COMPARE(not (val or expr), "NOT (1 OR (17 > 15))"); + // Chains are not nested in parentheses. SQLPP_COMPARE(val and val and val and val and val, "1 AND 1 AND 1 AND 1 AND 1"); SQLPP_COMPARE(val or val or val or val or val, "1 OR 1 OR 1 OR 1 OR 1"); diff --git a/tests/core/serialize/operator/sort_order_expression.cpp b/tests/core/serialize/operator/sort_order_expression.cpp index 14f98c39..edf3eef3 100644 --- a/tests/core/serialize/operator/sort_order_expression.cpp +++ b/tests/core/serialize/operator/sort_order_expression.cpp @@ -42,5 +42,6 @@ int main(int, char* []) SQLPP_COMPARE(expr.order(sqlpp::sort_type::asc), "(17 + 4) ASC"); SQLPP_COMPARE(expr.order(sqlpp::sort_type::desc), "(17 + 4) DESC"); +#warning: Make sure to test order_by with dynamic sort orders return 0; }