diff --git a/include/sqlpp11/core/to_sql_string.h b/include/sqlpp11/core/to_sql_string.h index 7cb598f4..f0601e00 100644 --- a/include/sqlpp11/core/to_sql_string.h +++ b/include/sqlpp11/core/to_sql_string.h @@ -220,28 +220,21 @@ namespace sqlpp } template - auto to_sql_string(Context& context, const ::sqlpp::chrono::day_point& t) -> std::string + auto to_sql_string(Context& , const ::sqlpp::chrono::day_point& t) -> std::string { - const auto ymd = ::date::year_month_day{t}; - context << "DATE '" << ymd << "'"; - return context; + return date::format("DATE '%Y-%m-%d'", t); } template - auto to_sql_string(Context& context, const std::chrono::microseconds& t) -> std::string + auto to_sql_string(Context&, const std::chrono::microseconds& t) -> std::string { - context << '\'' << ::date::make_time(t) << '\''; - return context; + return date::format("'%H:%M:%S'", t); } template - auto to_sql_string(Context& context, const std::chrono::time_point& t) -> std::string + auto to_sql_string(Context&, const std::chrono::time_point& t) -> std::string { - const auto dp = ::sqlpp::chrono::floor<::date::days>(t); - const auto time = ::date::make_time(t - dp); - const auto ymd = ::date::year_month_day{dp}; - context << "TIMESTAMP '" << ymd << ' ' << time << "'"; - return context; + return date::format("TIMESTAMP '%Y-%m-%dT%H:%M:%S'", t); } template diff --git a/tests/core/types/CMakeLists.txt b/tests/core/types/CMakeLists.txt index 5a0b6677..710119f2 100644 --- a/tests/core/types/CMakeLists.txt +++ b/tests/core/types/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2016, Roland Bock +# Copyright (c) 2016, Roland Bock # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, @@ -26,10 +26,8 @@ function(test_compile name) set(target sqlpp11_${name}) add_executable(${target} ${name}.cpp) target_link_libraries(${target} PRIVATE sqlpp11::sqlpp11 sqlpp11_testing) - # conditionally bump to a higher C++ standard to test compatibility endfunction() -test_compile(case_when) test_compile(dynamic) test_compile(result_row) test_compile(select_as) diff --git a/tests/core/types/aggregate_function/avg.cpp b/tests/core/types/aggregate_function/avg.cpp index 3b0930c3..2fb69887 100644 --- a/tests/core/types/aggregate_function/avg.cpp +++ b/tests/core/types/aggregate_function/avg.cpp @@ -59,8 +59,8 @@ void test_avg(Value v) static_assert(sqlpp::has_name::value, ""); static_assert(sqlpp::has_name::value, ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("avg"), ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("avg"), ""); + static_assert(std::is_same, sqlpp::alias::_avg_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::alias::_avg_t::_sqlpp_name_tag>::value, ""); // avg enables OVER. static_assert(sqlpp::has_enabled_over::value, ""); diff --git a/tests/core/types/aggregate_function/count.cpp b/tests/core/types/aggregate_function/count.cpp index c68eb162..8aff7c02 100644 --- a/tests/core/types/aggregate_function/count.cpp +++ b/tests/core/types/aggregate_function/count.cpp @@ -57,8 +57,8 @@ void test_count(Value v) static_assert(sqlpp::has_name::value, ""); static_assert(sqlpp::has_name::value, ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("count"), ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("count"), ""); + static_assert(std::is_same, sqlpp::alias::_count_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::alias::_count_t::_sqlpp_name_tag>::value, ""); // count enables comparison member functions. static_assert(sqlpp::has_enabled_comparison::value, ""); diff --git a/tests/core/types/aggregate_function/max.cpp b/tests/core/types/aggregate_function/max.cpp index 936d34f7..fd02b67a 100644 --- a/tests/core/types/aggregate_function/max.cpp +++ b/tests/core/types/aggregate_function/max.cpp @@ -59,8 +59,8 @@ void test_max(Value v) static_assert(sqlpp::has_name::value, ""); static_assert(sqlpp::has_name::value, ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("max"), ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("max"), ""); + static_assert(std::is_same, sqlpp::alias::_max_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::alias::_max_t::_sqlpp_name_tag>::value, ""); // max enables comparison member functions. static_assert(sqlpp::has_enabled_comparison::value, ""); diff --git a/tests/core/types/aggregate_function/min.cpp b/tests/core/types/aggregate_function/min.cpp index c9af7df3..e6e26d5f 100644 --- a/tests/core/types/aggregate_function/min.cpp +++ b/tests/core/types/aggregate_function/min.cpp @@ -59,8 +59,8 @@ void test_min(Value v) static_assert(sqlpp::has_name::value, ""); static_assert(sqlpp::has_name::value, ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("min"), ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("min"), ""); + static_assert(std::is_same, sqlpp::alias::_min_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::alias::_min_t::_sqlpp_name_tag>::value, ""); // min enables comparison member functions. static_assert(sqlpp::has_enabled_comparison::value, ""); diff --git a/tests/core/types/aggregate_function/over.cpp b/tests/core/types/aggregate_function/over.cpp index 6f71f5e2..617fde60 100644 --- a/tests/core/types/aggregate_function/over.cpp +++ b/tests/core/types/aggregate_function/over.cpp @@ -63,9 +63,9 @@ void test_aggregate_functions(Value v) static_assert(sqlpp::has_name::value, ""); static_assert(sqlpp::has_name::value, ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("count"), ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("max"), ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("min"), ""); + static_assert(std::is_same, sqlpp::alias::_count_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::alias::_min_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::alias::_max_t::_sqlpp_name_tag>::value, ""); // Aggregate functions enable comparison member functions. static_assert(sqlpp::has_enabled_comparison::value, ""); @@ -110,8 +110,9 @@ void test_numeric_aggregate_functions(Value v) static_assert(sqlpp::has_name::value, ""); static_assert(sqlpp::has_name::value, ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("sum"), ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("avg"), ""); + static_assert(std::is_same, sqlpp::alias::_sum_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::alias::_avg_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::alias::_avg_t::_sqlpp_name_tag>::value, ""); // Aggregate functions enable OVER. static_assert(not sqlpp::has_enabled_over::value, ""); diff --git a/tests/core/types/aggregate_function/sum.cpp b/tests/core/types/aggregate_function/sum.cpp index 79cb2226..ad0bb0b9 100644 --- a/tests/core/types/aggregate_function/sum.cpp +++ b/tests/core/types/aggregate_function/sum.cpp @@ -60,8 +60,9 @@ void test_sum(Value v) static_assert(sqlpp::has_name::value, ""); static_assert(sqlpp::has_name::value, ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("sum"), ""); - static_assert(sqlpp::name_tag_of_t::name == sqlpp::string_view("sum"), ""); + static_assert(std::is_same, sqlpp::alias::_sum_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::alias::_sum_t::_sqlpp_name_tag>::value, ""); + // sum enables OVER. static_assert(sqlpp::has_enabled_over::value, ""); diff --git a/tests/core/types/case_when.cpp b/tests/core/types/case_when.cpp deleted file mode 100644 index 1c769af6..00000000 --- a/tests/core/types/case_when.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2024, 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 - -namespace -{ - template - using is_same_type = std::is_same, V>; - - SQLPP_ALIAS_PROVIDER(r_not_null); - SQLPP_ALIAS_PROVIDER(r_maybe_null); -} - -template -void test_case_when(Value v) -{ - using ValueType = sqlpp::value_type_of_t; - using OptValueType = sqlpp::value_type_of_t<::sqlpp::optional>; - - // Selectable values. - auto v_not_null = sqlpp::value(v); - const auto v_maybe_null = sqlpp::value(::sqlpp::make_optional(v)); - - // No value types for incomplete clauses - static_assert(is_same_type::value, ""); - static_assert(is_same_type::value, ""); - - // The value type is optional if either of the of the values is optional - static_assert(is_same_type::value, - ""); - static_assert( - is_same_type::value, ""); - static_assert( - is_same_type::value, ""); - static_assert( - is_same_type::value, ""); - - // The value type is always optional if the condition is optional - const auto opt_bool = ::sqlpp::make_optional(true); - static_assert( - is_same_type::value, ""); - -#warning: test can be aliased -#warning: test has comparison operators -#warning: test nodes -} - -int main() -{ - // boolean - test_case_when(bool{true}); - - // integral - test_case_when(int8_t{7}); - test_case_when(int16_t{7}); - test_case_when(int32_t{7}); - test_case_when(int64_t{7}); - - // unsigned integral - test_case_when(uint8_t{7}); - test_case_when(uint16_t{7}); - test_case_when(uint32_t{7}); - test_case_when(uint64_t{7}); - - // floating point - test_case_when(float{7.7}); - test_case_when(double{7.7}); - - // text - test_case_when('7'); - test_case_when("seven"); - test_case_when(std::string("seven")); - test_case_when(::sqlpp::string_view("seven")); - - // blob - test_case_when(std::vector{}); - - // date - test_case_when(::sqlpp::chrono::day_point{}); - - // timestamp - test_case_when(::sqlpp::chrono::microsecond_point{}); - using minute_point = std::chrono::time_point; - test_case_when(minute_point{}); - - // time_of_day - test_case_when(std::chrono::microseconds{}); -} - diff --git a/tests/core/types/clause/select_columns.cpp b/tests/core/types/clause/select_columns.cpp index 42084dfc..4098b99e 100644 --- a/tests/core/types/clause/select_columns.cpp +++ b/tests/core/types/clause/select_columns.cpp @@ -47,12 +47,13 @@ void test_select_columns() auto v = sqlpp::value("text"); auto col_int = test::TabFoo{}.id; auto col_txt = test::TabFoo{}.textNnD; + auto col_bool = test::TabFoo{}.boolN; using unknown = sqlpp::detail::type_vector<>; using knownInt = sqlpp::detail::type_vector; using knownTxt = sqlpp::detail::type_vector; - // Single column + // Single column. { using T = clause_of_t; static_assert(std::is_same, test::TabFoo_::Id::_sqlpp_name_tag>::value, ""); @@ -63,7 +64,7 @@ void test_select_columns() static_assert(not sqlpp::has_correct_aggregates::value, ""); } - // Single dynamic column + // Single dynamic column. { using T = clause_of_t; static_assert(std::is_same, test::TabFoo_::Id::_sqlpp_name_tag>::value, ""); @@ -74,7 +75,29 @@ void test_select_columns() static_assert(not sqlpp::has_correct_aggregates::value, ""); } - // Single declared group by column + // Single aggregate function. + { + using T = clause_of_t; + static_assert(std::is_same, sqlpp::alias::_avg_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::optional>::value, ""); + static_assert(sqlpp::is_result_clause::value, ""); + static_assert(sqlpp::has_correct_aggregates::value, ""); + static_assert(sqlpp::has_correct_aggregates::value, ""); + static_assert(sqlpp::has_correct_aggregates::value, ""); + } + + // Single dynamic aggregate function. + { + using T = clause_of_t; + static_assert(std::is_same, sqlpp::alias::_avg_t::_sqlpp_name_tag>::value, ""); + static_assert(std::is_same, sqlpp::optional>::value, ""); + static_assert(sqlpp::is_result_clause::value, ""); + static_assert(sqlpp::has_correct_aggregates::value, ""); + static_assert(sqlpp::has_correct_aggregates::value, ""); + static_assert(sqlpp::has_correct_aggregates::value, ""); + } + + // Single declared group by column. { using T = clause_of_t; static_assert(std::is_same, cheese_t::_sqlpp_name_tag>::value, ""); @@ -85,7 +108,7 @@ void test_select_columns() static_assert(sqlpp::has_correct_aggregates::value, ""); } - // Single dynamic declared group by column + // Single dynamic declared group by column. { using T = clause_of_t; static_assert(std::is_same, cheese_t::_sqlpp_name_tag>::value, ""); @@ -96,7 +119,29 @@ void test_select_columns() static_assert(sqlpp::has_correct_aggregates::value, ""); } -#warning: add actual tests here + // Mixed columns. + // The columns in group_by determine if aggregates are correct or not. + { + using T = clause_of_t; + static_assert(not sqlpp::has_name::value, ""); + static_assert(not sqlpp::has_value_type::value, ""); + static_assert(sqlpp::is_result_clause::value, ""); + static_assert(sqlpp::has_correct_aggregates::value, ""); + static_assert(not sqlpp::has_correct_aggregates::value, ""); // col_int is a known aggregate here. + static_assert(not sqlpp::has_correct_aggregates::value, ""); + } + + // Mixed columns. + // The columns in group_by determine if aggregates are correct or not. + { + using T = clause_of_t; + static_assert(not sqlpp::has_name::value, ""); + static_assert(not sqlpp::has_value_type::value, ""); + static_assert(sqlpp::is_result_clause::value, ""); + static_assert(not sqlpp::has_correct_aggregates::value, ""); + static_assert(sqlpp::has_correct_aggregates::value, ""); // col_int is a known aggregate here. + static_assert(not sqlpp::has_correct_aggregates::value, ""); + } }