From 7f59918a0942b5fdb3650d6e9f5b23a1c362fa34 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sat, 10 Aug 2024 21:35:23 +0200 Subject: [PATCH] Serialize tests compile and pass again --- include/sqlpp11/core/basic/column.h | 6 +- include/sqlpp11/core/basic/join.h | 4 +- include/sqlpp11/core/basic/on.h | 8 +-- include/sqlpp11/core/basic/parameter.h | 5 +- .../core/basic/parameterized_verbatim.h | 5 +- include/sqlpp11/core/basic/pre_join.h | 6 +- include/sqlpp11/core/basic/table.h | 3 +- include/sqlpp11/core/basic/table_alias.h | 4 +- include/sqlpp11/core/basic/verbatim.h | 5 +- include/sqlpp11/core/basic/verbatim_table.h | 10 +-- include/sqlpp11/core/clause/for_update.h | 5 +- include/sqlpp11/core/clause/from.h | 4 +- include/sqlpp11/core/clause/group_by.h | 4 +- include/sqlpp11/core/clause/having.h | 4 +- include/sqlpp11/core/clause/insert.h | 6 +- include/sqlpp11/core/clause/insert_value.h | 8 +-- .../sqlpp11/core/clause/insert_value_list.h | 36 +++++----- include/sqlpp11/core/clause/into.h | 5 +- include/sqlpp11/core/clause/limit.h | 4 +- include/sqlpp11/core/clause/offset.h | 5 +- include/sqlpp11/core/clause/order_by.h | 4 +- include/sqlpp11/core/clause/remove.h | 6 +- include/sqlpp11/core/clause/select.h | 2 +- include/sqlpp11/core/clause/select_as.h | 10 +-- .../sqlpp11/core/clause/select_flag_list.h | 7 +- include/sqlpp11/core/clause/select_flags.h | 16 ++--- include/sqlpp11/core/clause/simple_column.h | 3 +- include/sqlpp11/core/clause/single_table.h | 3 +- include/sqlpp11/core/clause/update.h | 5 +- include/sqlpp11/core/clause/update_list.h | 4 +- include/sqlpp11/core/clause/where.h | 8 +-- .../core/detail/float_safe_ostringstream.h | 72 ------------------- include/sqlpp11/core/function/lower.h | 5 +- include/sqlpp11/core/function/trim.h | 5 +- include/sqlpp11/core/function/upper.h | 5 +- include/sqlpp11/core/hidden.h | 4 +- include/sqlpp11/core/interpret_tuple.h | 9 +-- include/sqlpp11/core/no_data.h | 2 +- include/sqlpp11/core/noop.h | 4 +- .../sqlpp11/core/operator/bit_expression.h | 2 +- include/sqlpp11/core/operator/in_expression.h | 2 +- .../core/operator/logical_expression.h | 8 +-- .../core/operator/sort_order_expression.h | 2 +- include/sqlpp11/core/query/custom_query.h | 3 +- include/sqlpp11/core/query/dynamic.h | 18 ++--- include/sqlpp11/core/to_sql_string.h | 43 ++++++----- tests/core/serialize/Blob.cpp | 14 +--- tests/core/serialize/CustomQuery.cpp | 10 +-- tests/core/serialize/DynamicWhere.cpp | 4 +- tests/core/serialize/Float.cpp | 15 ++-- tests/core/serialize/From.cpp | 18 ++--- tests/core/serialize/Insert.cpp | 2 +- tests/core/serialize/Lower.cpp | 5 +- tests/core/serialize/Parameter.cpp | 2 +- tests/core/serialize/SelectFlags.cpp | 2 +- tests/core/serialize/Trim.cpp | 5 +- tests/core/serialize/Upper.cpp | 5 +- tests/core/serialize/Where.cpp | 22 +++--- .../core/serialize/operator/in_expression.cpp | 2 +- tests/core/usage/MockDb.h | 6 +- 60 files changed, 161 insertions(+), 340 deletions(-) delete mode 100644 include/sqlpp11/core/detail/float_safe_ostringstream.h diff --git a/include/sqlpp11/core/basic/column.h b/include/sqlpp11/core/basic/column.h index 4d0d521c..684b638b 100644 --- a/include/sqlpp11/core/basic/column.h +++ b/include/sqlpp11/core/basic/column.h @@ -116,10 +116,6 @@ namespace sqlpp { using T = column_t; - name_to_sql_string(context, name_tag_of_t::name); - context << '.'; - name_to_sql_string(context, name_tag_of_t::name); - - return context; + return name_to_sql_string(context, name_tag_of_t
::name) + "." + name_to_sql_string(context, name_tag_of_t::name); } } // namespace sqlpp diff --git a/include/sqlpp11/core/basic/join.h b/include/sqlpp11/core/basic/join.h index 76edcf32..ca3d9905 100644 --- a/include/sqlpp11/core/basic/join.h +++ b/include/sqlpp11/core/basic/join.h @@ -87,8 +87,6 @@ namespace sqlpp template auto to_sql_string(Context& context, const join_t& t) -> std::string { - to_sql_string(context, t._pre_join); - to_sql_string(context, t._on); - return context; + return to_sql_string(context, t._pre_join) + to_sql_string(context, t._on); } } // namespace sqlpp diff --git a/include/sqlpp11/core/basic/on.h b/include/sqlpp11/core/basic/on.h index 2aa13aba..dad05a16 100644 --- a/include/sqlpp11/core/basic/on.h +++ b/include/sqlpp11/core/basic/on.h @@ -61,16 +61,14 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const on_t&) -> std::string + auto to_sql_string(Context& , const on_t&) -> std::string { - return context; + return {}; } template auto to_sql_string(Context& context, const on_t& t) -> std::string { - context << " ON "; - to_sql_string(context, t._expression); - return context; + return " ON " + to_sql_string(context, t._expression); } } // namespace sqlpp diff --git a/include/sqlpp11/core/basic/parameter.h b/include/sqlpp11/core/basic/parameter.h index 53ea5eb7..2f26e167 100644 --- a/include/sqlpp11/core/basic/parameter.h +++ b/include/sqlpp11/core/basic/parameter.h @@ -64,10 +64,9 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const parameter_t&) -> std::string + auto to_sql_string(Context& , const parameter_t&) -> std::string { - context << "?"; - return context; + return "?"; } template diff --git a/include/sqlpp11/core/basic/parameterized_verbatim.h b/include/sqlpp11/core/basic/parameterized_verbatim.h index 11b2b485..1622c05d 100644 --- a/include/sqlpp11/core/basic/parameterized_verbatim.h +++ b/include/sqlpp11/core/basic/parameterized_verbatim.h @@ -71,10 +71,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const parameterized_verbatim_t& t) -> std::string { - context << t._verbatim_lhs; - to_sql_string(context, t._expr); - context << t._verbatim_rhs; - return context; + return t._verbatim_lhs + to_sql_string(context, t._expr) + t._verbatim_rhs; } template diff --git a/include/sqlpp11/core/basic/pre_join.h b/include/sqlpp11/core/basic/pre_join.h index 48af1451..0a635092 100644 --- a/include/sqlpp11/core/basic/pre_join.h +++ b/include/sqlpp11/core/basic/pre_join.h @@ -135,11 +135,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const pre_join_t& t) -> std::string { - to_sql_string(context, t._lhs); - context << JoinType::_name; - context << " JOIN "; - to_sql_string(context, t._rhs); - return context; + return to_sql_string(context, t._lhs) + JoinType::_name + " JOIN " + to_sql_string(context, t._rhs); } namespace detail diff --git a/include/sqlpp11/core/basic/table.h b/include/sqlpp11/core/basic/table.h index ce04615c..02f801a3 100644 --- a/include/sqlpp11/core/basic/table.h +++ b/include/sqlpp11/core/basic/table.h @@ -69,7 +69,6 @@ namespace sqlpp template auto to_sql_string(Context& context, const table_t& /*unused*/) -> std::string { - name_to_sql_string(context, name_tag_of_t::name); - return context; + return name_to_sql_string(context, name_tag_of_t::name); } } // namespace sqlpp diff --git a/include/sqlpp11/core/basic/table_alias.h b/include/sqlpp11/core/basic/table_alias.h index fc9c0283..93df5653 100644 --- a/include/sqlpp11/core/basic/table_alias.h +++ b/include/sqlpp11/core/basic/table_alias.h @@ -58,9 +58,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const table_alias_t&) -> std::string { - name_to_sql_string(context, name_tag_of_t::name); - context << " AS "; + return name_to_sql_string(context, name_tag_of_t::name) + " AS " + name_to_sql_string(context, name_tag_of_t::name); - return context; } } // namespace sqlpp diff --git a/include/sqlpp11/core/basic/verbatim.h b/include/sqlpp11/core/basic/verbatim.h index 2d8a3384..46712654 100644 --- a/include/sqlpp11/core/basic/verbatim.h +++ b/include/sqlpp11/core/basic/verbatim.h @@ -62,10 +62,9 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const verbatim_t& t) -> std::string + auto to_sql_string(Context& , const verbatim_t& t) -> std::string { - context << t._verbatim; - return context; + return t._verbatim; } template diff --git a/include/sqlpp11/core/basic/verbatim_table.h b/include/sqlpp11/core/basic/verbatim_table.h index 3b0392a5..22ab097d 100644 --- a/include/sqlpp11/core/basic/verbatim_table.h +++ b/include/sqlpp11/core/basic/verbatim_table.h @@ -57,10 +57,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const verbatim_table_alias_t& t) -> std::string { - context << t._representation; - context << " AS "; - name_to_sql_string(context, name_tag_of_t::name); - return context; + return t._representation + " AS " + name_to_sql_string(context, name_tag_of_t::name); } struct verbatim_table_t: public enable_join @@ -90,10 +87,9 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const verbatim_table_t& t) -> std::string + auto to_sql_string(Context& , const verbatim_table_t& t) -> std::string { - context << t._representation; - return context; + return t._representation; } inline verbatim_table_t verbatim_table(std::string name) diff --git a/include/sqlpp11/core/clause/for_update.h b/include/sqlpp11/core/clause/for_update.h index d4de4f99..4d3551fe 100644 --- a/include/sqlpp11/core/clause/for_update.h +++ b/include/sqlpp11/core/clause/for_update.h @@ -92,10 +92,9 @@ namespace sqlpp // Interpreters template - auto to_sql_string(Context& context, const for_update_data_t&) -> std::string + auto to_sql_string(Context& , const for_update_data_t&) -> std::string { - context << " FOR UPDATE "; - return context; + return " FOR UPDATE "; } inline auto for_update() -> decltype(statement_t().for_update()) diff --git a/include/sqlpp11/core/clause/from.h b/include/sqlpp11/core/clause/from.h index 97ae8fba..5bdf2490 100644 --- a/include/sqlpp11/core/clause/from.h +++ b/include/sqlpp11/core/clause/from.h @@ -143,9 +143,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const from_data_t
& t) -> std::string { - context << " FROM "; - to_sql_string(context, t._table); - return context; + return " FROM " + to_sql_string(context, t._table); } template diff --git a/include/sqlpp11/core/clause/group_by.h b/include/sqlpp11/core/clause/group_by.h index c911c4c5..98a42582 100644 --- a/include/sqlpp11/core/clause/group_by.h +++ b/include/sqlpp11/core/clause/group_by.h @@ -148,9 +148,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const group_by_data_t& t) -> std::string { - context << " GROUP BY "; - interpret_tuple(t._expressions, ',', context); - return context; + return " GROUP BY " + interpret_tuple(t._expressions, ',', context); } template diff --git a/include/sqlpp11/core/clause/having.h b/include/sqlpp11/core/clause/having.h index f7f16cce..72b4e0f1 100644 --- a/include/sqlpp11/core/clause/having.h +++ b/include/sqlpp11/core/clause/having.h @@ -173,9 +173,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const having_data_t& t) -> std::string { - context << " HAVING "; - to_sql_string(context, t._expression); - return context; + return " HAVING " + to_sql_string(context, t._expression); } template diff --git a/include/sqlpp11/core/clause/insert.h b/include/sqlpp11/core/clause/insert.h index a9551290..87866118 100644 --- a/include/sqlpp11/core/clause/insert.h +++ b/include/sqlpp11/core/clause/insert.h @@ -87,11 +87,9 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const insert_name_t&) -> std::string + auto to_sql_string(Context& , const insert_name_t&) -> std::string { - context << "INSERT"; - - return context; + return "INSERT"; } using blank_insert_t = statement_t; diff --git a/include/sqlpp11/core/clause/insert_value.h b/include/sqlpp11/core/clause/insert_value.h index 1d63457d..ac099c72 100644 --- a/include/sqlpp11/core/clause/insert_value.h +++ b/include/sqlpp11/core/clause/insert_value.h @@ -83,12 +83,8 @@ namespace sqlpp { if (t._is_default) { - context << "DEFAULT"; + return "DEFAULT"; } - else - { - operand_to_sql_string(context, t._value); - } - return context; + return operand_to_sql_string(context, t._value); } } // namespace sqlpp diff --git a/include/sqlpp11/core/clause/insert_value_list.h b/include/sqlpp11/core/clause/insert_value_list.h index 62696310..8eb6ebfc 100644 --- a/include/sqlpp11/core/clause/insert_value_list.h +++ b/include/sqlpp11/core/clause/insert_value_list.h @@ -395,49 +395,47 @@ namespace sqlpp // Interpreters template - auto to_sql_string(Context& context, const insert_default_values_data_t&) -> std::string + auto to_sql_string(Context& , const insert_default_values_data_t&) -> std::string { - context << " DEFAULT VALUES"; - return context; + return " DEFAULT VALUES"; } template auto to_sql_string(Context& context, const column_list_data_t& t) -> std::string { - context << " ("; - interpret_tuple(t._columns, ",", context); - context << ")"; + auto result = std::string{" ("}; + result += interpret_tuple(t._columns, ",", context); + result += ")"; bool first = true; for (const auto& row : t._insert_values) { if (first) { - context << " VALUES "; + result += " VALUES "; first = false; } else { - context << ','; + result += ','; } - context << '('; - interpret_tuple(row, ",", context); - context << ')'; + result += '('; + result += interpret_tuple(row, ",", context); + result += ')'; } - return context; + return result; } template auto to_sql_string(Context& context, const insert_list_data_t& t) -> std::string { - context << " ("; - interpret_tuple(t._columns, ",", context); - context << ")"; - context << " VALUES("; - interpret_tuple(t._values, ",", context); - context << ")"; - return context; + auto result = std::string{" ("}; + result += interpret_tuple(t._columns, ",", context); + result += ") VALUES("; + result += interpret_tuple(t._values, ",", context); + result += ")"; + return result; } template diff --git a/include/sqlpp11/core/clause/into.h b/include/sqlpp11/core/clause/into.h index 3c1a5bef..6f2c5725 100644 --- a/include/sqlpp11/core/clause/into.h +++ b/include/sqlpp11/core/clause/into.h @@ -140,13 +140,10 @@ namespace sqlpp }; }; - // Interpreters template auto to_sql_string(Context& context, const into_data_t
& t) -> std::string { - context << " INTO "; - to_sql_string(context, t._table); - return context; + return " INTO " + to_sql_string(context, t._table); } template diff --git a/include/sqlpp11/core/clause/limit.h b/include/sqlpp11/core/clause/limit.h index de5da714..68675899 100644 --- a/include/sqlpp11/core/clause/limit.h +++ b/include/sqlpp11/core/clause/limit.h @@ -130,9 +130,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const limit_data_t& t) -> std::string { - context << " LIMIT "; - operand_to_sql_string(context, t._value); - return context; + return " LIMIT " + operand_to_sql_string(context, t._value); } template diff --git a/include/sqlpp11/core/clause/offset.h b/include/sqlpp11/core/clause/offset.h index 14fa34c2..acd008fb 100644 --- a/include/sqlpp11/core/clause/offset.h +++ b/include/sqlpp11/core/clause/offset.h @@ -138,13 +138,10 @@ namespace sqlpp }; }; - // Interpreters template auto to_sql_string(Context& context, const offset_data_t& t) -> std::string { - context << " OFFSET "; - operand_to_sql_string(context, t._value); - return context; + return " OFFSET " + operand_to_sql_string(context, t._value); } template diff --git a/include/sqlpp11/core/clause/order_by.h b/include/sqlpp11/core/clause/order_by.h index 468e4079..e9653839 100644 --- a/include/sqlpp11/core/clause/order_by.h +++ b/include/sqlpp11/core/clause/order_by.h @@ -148,9 +148,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const order_by_data_t& t) -> std::string { - context << " ORDER BY "; - interpret_tuple(t._expressions, ',', context); - return context; + return " ORDER BY " + interpret_tuple(t._expressions, ',', context); } template diff --git a/include/sqlpp11/core/clause/remove.h b/include/sqlpp11/core/clause/remove.h index c0d86061..ee786267 100644 --- a/include/sqlpp11/core/clause/remove.h +++ b/include/sqlpp11/core/clause/remove.h @@ -86,11 +86,9 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const remove_name_t&) -> std::string + auto to_sql_string(Context& , const remove_name_t&) -> std::string { - context << "DELETE"; - - return context; + return "DELETE"; } using blank_remove_t = statement_t>; diff --git a/include/sqlpp11/core/clause/select.h b/include/sqlpp11/core/clause/select.h index bea78a3a..0d3d83c2 100644 --- a/include/sqlpp11/core/clause/select.h +++ b/include/sqlpp11/core/clause/select.h @@ -55,7 +55,7 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const select_name_t&) -> std::string + auto to_sql_string(Context& , const select_name_t&) -> std::string { return "SELECT "; } diff --git a/include/sqlpp11/core/clause/select_as.h b/include/sqlpp11/core/clause/select_as.h index 07090c93..dc53079c 100644 --- a/include/sqlpp11/core/clause/select_as.h +++ b/include/sqlpp11/core/clause/select_as.h @@ -54,10 +54,7 @@ namespace sqlpp { using T = pseudo_column_t; - name_to_sql_string(context, name_tag_of_t::name); - context << '.'; - name_to_sql_string(context, name_tag_of_t::name); - return context; + return name_to_sql_string(context, name_tag_of_t::name) + "."+ name_to_sql_string(context, name_tag_of_t::name); } template @@ -97,9 +94,6 @@ namespace sqlpp template auto to_sql_string(Context& context, const select_as_t& t) -> std::string { - operand_to_sql_string(context, t._select); - context << " AS "; - name_to_sql_string(context, name_tag_of_t::name); - return context; + return operand_to_sql_string(context, t._select) + " AS " +name_to_sql_string(context, name_tag_of_t::name); } } // namespace sqlpp diff --git a/include/sqlpp11/core/clause/select_flag_list.h b/include/sqlpp11/core/clause/select_flag_list.h index 55f6286c..1e78e640 100644 --- a/include/sqlpp11/core/clause/select_flag_list.h +++ b/include/sqlpp11/core/clause/select_flag_list.h @@ -137,12 +137,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const select_flag_list_data_t& t) -> std::string { - interpret_tuple(t._flags, ' ', context); - if (sizeof...(Flags) != 0u) - { - context << ' '; - } - return context; + return interpret_tuple(t._flags, "", context); } template diff --git a/include/sqlpp11/core/clause/select_flags.h b/include/sqlpp11/core/clause/select_flags.h index 011fc186..eaa18143 100644 --- a/include/sqlpp11/core/clause/select_flags.h +++ b/include/sqlpp11/core/clause/select_flags.h @@ -42,10 +42,9 @@ namespace sqlpp static constexpr all_t all = {}; template - auto to_sql_string(Context& context, const all_t&) -> std::string + auto to_sql_string(Context& , const all_t&) -> std::string { - context << "ALL"; - return context; + return "ALL "; } struct distinct_t @@ -56,10 +55,9 @@ namespace sqlpp static constexpr distinct_t distinct = {}; template - auto to_sql_string(Context& context, const distinct_t&) -> std::string + auto to_sql_string(Context& , const distinct_t&) -> std::string { - context << "DISTINCT"; - return context; + return "DISTINCT "; } struct straight_join_t @@ -69,10 +67,10 @@ namespace sqlpp }; static constexpr straight_join_t straight_join = {}; +#warning: Why is this in the select flags? template - auto to_sql_string(Context& context, const straight_join_t&) -> std::string + auto to_sql_string(Context& , const straight_join_t&) -> std::string { - context << "STRAIGHT_JOIN"; - return context; + return "STRAIGHT_JOIN"; } } // namespace sqlpp diff --git a/include/sqlpp11/core/clause/simple_column.h b/include/sqlpp11/core/clause/simple_column.h index 608d4efa..8542824f 100644 --- a/include/sqlpp11/core/clause/simple_column.h +++ b/include/sqlpp11/core/clause/simple_column.h @@ -49,8 +49,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const simple_column_t&) -> std::string { - context << name_tag_of_t::_column_t>::name; - return context; + return name_to_sql_string(context, name_tag_of_t::_column_t>::name); } template diff --git a/include/sqlpp11/core/clause/single_table.h b/include/sqlpp11/core/clause/single_table.h index 0a80235c..be72af24 100644 --- a/include/sqlpp11/core/clause/single_table.h +++ b/include/sqlpp11/core/clause/single_table.h @@ -145,7 +145,6 @@ namespace sqlpp template auto to_sql_string(Context& context, const single_table_data_t
& t) -> std::string { - to_sql_string(context, t._table); - return context; + return to_sql_string(context, t._table); } } // namespace sqlpp diff --git a/include/sqlpp11/core/clause/update.h b/include/sqlpp11/core/clause/update.h index 35bef702..61d69e1a 100644 --- a/include/sqlpp11/core/clause/update.h +++ b/include/sqlpp11/core/clause/update.h @@ -87,10 +87,9 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const update_name_t&) -> std::string + auto to_sql_string(Context& , const update_name_t&) -> std::string { - context << "UPDATE "; - return context; + return "UPDATE "; } using blank_update_t = statement_t>; diff --git a/include/sqlpp11/core/clause/update_list.h b/include/sqlpp11/core/clause/update_list.h index adc8d17c..6c727074 100644 --- a/include/sqlpp11/core/clause/update_list.h +++ b/include/sqlpp11/core/clause/update_list.h @@ -167,8 +167,6 @@ namespace sqlpp template auto to_sql_string(Context& context, const update_list_data_t& t) -> std::string { - context << " SET "; - interpret_tuple(t._assignments, ",", context); - return context; + return " SET " + interpret_tuple(t._assignments, ",", context); } } // namespace sqlpp diff --git a/include/sqlpp11/core/clause/where.h b/include/sqlpp11/core/clause/where.h index 8ab1c4d0..c8117d8a 100644 --- a/include/sqlpp11/core/clause/where.h +++ b/include/sqlpp11/core/clause/where.h @@ -194,15 +194,13 @@ namespace sqlpp template auto to_sql_string(Context& context, const where_data_t& t) -> std::string { - context << " WHERE "; - to_sql_string(context, t._expression); - return context; + return " WHERE " + to_sql_string(context, t._expression); } template - auto to_sql_string(Context& context, const where_data_t&) -> std::string + auto to_sql_string(Context& , const where_data_t&) -> std::string { - return context; + return {}; } template diff --git a/include/sqlpp11/core/detail/float_safe_ostringstream.h b/include/sqlpp11/core/detail/float_safe_ostringstream.h deleted file mode 100644 index 36ad878a..00000000 --- a/include/sqlpp11/core/detail/float_safe_ostringstream.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -/* - * 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 -#include -#include -#include - -#include - -namespace sqlpp -{ - namespace detail - { - template - struct float_safe_ostringstream_implementation - { - template - void operator()(std::ostringstream& os, U&& x) const - { - os << std::forward(x); - } - }; - - template - struct float_safe_ostringstream_implementation::value>> - { - template - void operator()(std::ostringstream& os, U&& x) const - { - auto const old_precision = os.precision(std::numeric_limits::max_digits10); - os << std::forward(x); - os.precision(old_precision); - } - }; - - struct float_safe_ostringstream : std::ostringstream - { - template - friend float_safe_ostringstream& operator<<(float_safe_ostringstream& os, T&& x) - { - float_safe_ostringstream_implementation::type>{}(os, x); - return os; - } - }; - } // namespace detail -} // namespace sqlpp diff --git a/include/sqlpp11/core/function/lower.h b/include/sqlpp11/core/function/lower.h index 4a7076c3..7adfbf72 100644 --- a/include/sqlpp11/core/function/lower.h +++ b/include/sqlpp11/core/function/lower.h @@ -54,10 +54,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const lower_t& t) -> std::string { - context << "LOWER("; - operand_to_sql_string(context, t._expr); - context << ")"; - return context; + return "LOWER("+ to_sql_string(context, t._expr) + ")"; } template diff --git a/include/sqlpp11/core/function/trim.h b/include/sqlpp11/core/function/trim.h index a2dacdff..075f6542 100644 --- a/include/sqlpp11/core/function/trim.h +++ b/include/sqlpp11/core/function/trim.h @@ -62,10 +62,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const trim_t& t) -> std::string { - context << "TRIM("; - operand_to_sql_string(context, t._expr); - context << ")"; - return context; + return "TRIM(" + to_sql_string(context, t._expr)+ ")"; } template diff --git a/include/sqlpp11/core/function/upper.h b/include/sqlpp11/core/function/upper.h index 3593a453..2818d899 100644 --- a/include/sqlpp11/core/function/upper.h +++ b/include/sqlpp11/core/function/upper.h @@ -54,10 +54,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const upper_t& t) -> std::string { - context << "UPPER("; - operand_to_sql_string(context, t._expr); - context << ")"; - return context; + return "UPPER(" + to_sql_string(context, t._expr) + ")"; } template diff --git a/include/sqlpp11/core/hidden.h b/include/sqlpp11/core/hidden.h index 86d7af30..b85147f0 100644 --- a/include/sqlpp11/core/hidden.h +++ b/include/sqlpp11/core/hidden.h @@ -43,9 +43,9 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const hidden_t&) -> std::string + auto to_sql_string(Context& , const hidden_t&) -> std::string { - return context; + return {}; } template diff --git a/include/sqlpp11/core/interpret_tuple.h b/include/sqlpp11/core/interpret_tuple.h index 67267273..84ffe8be 100644 --- a/include/sqlpp11/core/interpret_tuple.h +++ b/include/sqlpp11/core/interpret_tuple.h @@ -37,17 +37,14 @@ namespace sqlpp static auto interpret_tuple_element( const Element& element, const Separator& separator, Context& context, const UseBraces& /*unused*/, size_t index) -> std::string { - if (index) - { - return separator; - } + const auto prefix = index ? std::string{separator} : std::string{}; if (UseBraces::value) { - return operand_to_sql_string(context, element); + return prefix + operand_to_sql_string(context, element); } else { - return to_sql_string(context, element); + return prefix + to_sql_string(context, element); } } diff --git a/include/sqlpp11/core/no_data.h b/include/sqlpp11/core/no_data.h index 2ab4fc9b..06a66d56 100644 --- a/include/sqlpp11/core/no_data.h +++ b/include/sqlpp11/core/no_data.h @@ -34,7 +34,7 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const no_data_t&) -> std::string + auto to_sql_string(Context& , const no_data_t&) -> std::string { return {}; } diff --git a/include/sqlpp11/core/noop.h b/include/sqlpp11/core/noop.h index 5d9c8c52..455c1d62 100644 --- a/include/sqlpp11/core/noop.h +++ b/include/sqlpp11/core/noop.h @@ -81,9 +81,9 @@ namespace sqlpp }; template - auto to_sql_string(Context& context, const noop&) -> std::string + auto to_sql_string(Context& , const noop&) -> std::string { - return context; + return {}; } template diff --git a/include/sqlpp11/core/operator/bit_expression.h b/include/sqlpp11/core/operator/bit_expression.h index cfc2cf3c..6c227329 100644 --- a/include/sqlpp11/core/operator/bit_expression.h +++ b/include/sqlpp11/core/operator/bit_expression.h @@ -77,7 +77,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const bit_expression& t) -> std::string { - return to_sql_string(context, simple_column(t._l)) + Operator::symbol + operand_to_sql_string(context, t._r); + return operand_to_sql_string(context, t._l) + Operator::symbol + operand_to_sql_string(context, t._r); } struct bit_and diff --git a/include/sqlpp11/core/operator/in_expression.h b/include/sqlpp11/core/operator/in_expression.h index 06be608a..b51447c3 100644 --- a/include/sqlpp11/core/operator/in_expression.h +++ b/include/sqlpp11/core/operator/in_expression.h @@ -128,7 +128,7 @@ namespace sqlpp else { #warning: interpret_tuple arguments should take Context first, too - interpret_tuple(t._r, ", ", context); + result += interpret_tuple(t._r, ", ", context); } result += ")"; return result; diff --git a/include/sqlpp11/core/operator/logical_expression.h b/include/sqlpp11/core/operator/logical_expression.h index 283cf46b..0004af04 100644 --- a/include/sqlpp11/core/operator/logical_expression.h +++ b/include/sqlpp11/core/operator/logical_expression.h @@ -84,9 +84,9 @@ namespace sqlpp #warning: rename template - auto serialize_impl(Context& context, const logical_expression& t) -> Context& + auto serialize_impl(Context& context, const logical_expression& t) -> std::string { - return operand_to_sql_string(context, simple_column(t._l)) + Operator::symbol + operand_to_sql_string(context, t._r); + return operand_to_sql_string(context, t._l) + Operator::symbol + operand_to_sql_string(context, t._r); } template @@ -97,14 +97,14 @@ namespace sqlpp template auto to_sql_string(Context& context, - const logical_expression, Operator, R2>& t) -> Context& + const logical_expression, Operator, R2>& t) -> std::string { return to_sql_string(context, t._l) + Operator::symbol + operand_to_sql_string(context, t._r); } template auto to_sql_string(Context& context, - const logical_expression, Operator, dynamic_t>& t) -> Context& + const logical_expression, Operator, dynamic_t>& t) -> std::string { if (t._r._condition) { diff --git a/include/sqlpp11/core/operator/sort_order_expression.h b/include/sqlpp11/core/operator/sort_order_expression.h index b3db9a1a..957d8765 100644 --- a/include/sqlpp11/core/operator/sort_order_expression.h +++ b/include/sqlpp11/core/operator/sort_order_expression.h @@ -67,7 +67,7 @@ namespace sqlpp struct is_sort_order> : std::true_type {}; template - auto to_sql_string(Context& context, const sort_type& t) -> std::string + auto to_sql_string(Context& , const sort_type& t) -> std::string { switch (t) { diff --git a/include/sqlpp11/core/query/custom_query.h b/include/sqlpp11/core/query/custom_query.h index b0defda3..de49bd1a 100644 --- a/include/sqlpp11/core/query/custom_query.h +++ b/include/sqlpp11/core/query/custom_query.h @@ -124,8 +124,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const custom_query_t& t) -> std::string { - interpret_tuple_without_braces(t._parts, " ", context); - return context; + return interpret_tuple_without_braces(t._parts, " ", context); } template diff --git a/include/sqlpp11/core/query/dynamic.h b/include/sqlpp11/core/query/dynamic.h index dd9ca8c6..69b8e22c 100644 --- a/include/sqlpp11/core/query/dynamic.h +++ b/include/sqlpp11/core/query/dynamic.h @@ -79,27 +79,19 @@ namespace sqlpp { if (t._condition) { - to_sql_string(context, t._expr); + return to_sql_string(context, t._expr); } - else - { - to_sql_string(context, ::sqlpp::nullopt); - } - return context; + return to_sql_string(context, ::sqlpp::nullopt); } template - Context& operand_to_sql_string(Context& context, const dynamic_t& t) -> std::string { if (t._condition) { - operand_to_sql_string(context, t._expr); + return operand_to_sql_string(context, t._expr); } - else - { - to_sql_string(context, ::sqlpp::nullopt); - } - return context; + return to_sql_string(context, ::sqlpp::nullopt); } template diff --git a/include/sqlpp11/core/to_sql_string.h b/include/sqlpp11/core/to_sql_string.h index 7500229b..7cb598f4 100644 --- a/include/sqlpp11/core/to_sql_string.h +++ b/include/sqlpp11/core/to_sql_string.h @@ -47,73 +47,73 @@ namespace sqlpp } template - auto to_sql_string(Context& context, const bool& t) -> std::string + auto to_sql_string(Context& , const bool& t) -> std::string { return std::to_string(t); } template - auto to_sql_string(Context& context, const int8_t& t) -> std::string + auto to_sql_string(Context& , const int8_t& t) -> std::string { return std::to_string(t); } template - auto to_sql_string(Context& context, const int16_t& t) -> std::string + auto to_sql_string(Context& , const int16_t& t) -> std::string { return std::to_string(t); } template - auto to_sql_string(Context& context, const int32_t& t) -> std::string + auto to_sql_string(Context& , const int32_t& t) -> std::string { return std::to_string(t); } template - auto to_sql_string(Context& context, const int64_t& t) -> std::string + auto to_sql_string(Context& , const int64_t& t) -> std::string { return std::to_string(t); } template - auto to_sql_string(Context& context, const uint8_t& t) -> std::string + auto to_sql_string(Context& , const uint8_t& t) -> std::string { return std::to_string(t); } template - auto to_sql_string(Context& context, const uint16_t& t) -> std::string + auto to_sql_string(Context& , const uint16_t& t) -> std::string { return std::to_string(t); } template - auto to_sql_string(Context& context, const uint32_t& t) -> std::string + auto to_sql_string(Context& , const uint32_t& t) -> std::string { return std::to_string(t); } template - auto to_sql_string(Context& context, const uint64_t& t) -> std::string + auto to_sql_string(Context& , const uint64_t& t) -> std::string { return std::to_string(t); } template - auto nan_to_sql_string(Context& context) -> std::string + auto nan_to_sql_string(Context& ) -> std::string { throw ::sqlpp::exception("Serialization of NaN is not supported by this connector"); } template - auto inf_to_sql_string(Context& context) -> std::string + auto inf_to_sql_string(Context& ) -> std::string { throw ::sqlpp::exception("Serialization of Infinity is not supported by this connector"); } template - auto neg_inf_to_sql_string(Context& context) -> std::string + auto neg_inf_to_sql_string(Context& ) -> std::string { throw ::sqlpp::exception("Serialization of Infinity is not supported by this connector"); } @@ -133,7 +133,7 @@ namespace sqlpp { // TODO: Once gcc and clang support to_chars, try that auto oss = std::ostringstream{}; - oss << std::setprecision(std::numeric_limits::digits10 + 1) << f; + oss << std::setprecision(std::numeric_limits::max_digits10) << f; return oss.str(); } } @@ -141,26 +141,23 @@ namespace sqlpp template auto to_sql_string(Context& context, const float& t) -> std::string { - context << t; - return context; + return float_to_sql_string(context, t); } template auto to_sql_string(Context& context, const double& t) -> std::string { - context << t; - return context; + return float_to_sql_string(context, t); } template auto to_sql_string(Context& context, const long double& t) -> std::string { - context << t; - return context; + return float_to_sql_string(context, t); } template - auto to_sql_string(Context& context, const ::sqlpp::string_view& t) -> std::string + auto to_sql_string(Context& , const ::sqlpp::string_view& t) -> std::string { auto result = std::string{"'"}; result.reserve(t.size() * 2); @@ -194,7 +191,7 @@ namespace sqlpp } template - auto to_sql_string(Context& context, const ::sqlpp::span& t) -> std::string + auto to_sql_string(Context& , const ::sqlpp::span& t) -> std::string { constexpr char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; auto result = std::string{"x'"}; @@ -248,7 +245,7 @@ namespace sqlpp } template - auto to_sql_string(Context& context, const ::sqlpp::nullopt_t&) -> std::string + auto to_sql_string(Context&, const ::sqlpp::nullopt_t&) -> std::string { return "NULL"; } @@ -274,7 +271,7 @@ namespace sqlpp } template - auto name_to_sql_string(Context& context, const char* t) -> std::string + auto name_to_sql_string(Context& , const char* t) -> std::string { #warning: We used to have a version of SQLPP_ALIAS_PROVIDER that escaped the name diff --git a/tests/core/serialize/Blob.cpp b/tests/core/serialize/Blob.cpp index fb4fcd16..fb43535d 100644 --- a/tests/core/serialize/Blob.cpp +++ b/tests/core/serialize/Blob.cpp @@ -32,18 +32,10 @@ namespace { - /* - auto getTrue() -> std::string - { - MockDb::_serializer_context_t printer = {}; - return to_sql_string(sqlpp::value(true), printer).str(); - } - */ - auto getFalse() -> std::string { MockDb::_serializer_context_t printer = {}; - return to_sql_string(printer, sqlpp::value(false)).str(); + return to_sql_string(printer, sqlpp::value(false)); } auto toByteVector(const std::string& s) -> std::vector @@ -59,11 +51,11 @@ int Blob(int, char*[]) // Unconditionally 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')"); + "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'}}; 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')"); + "SELECT tab_foo.blob_n FROM tab_foo WHERE tab_foo.blob_n = x'6A6F686E20646F65'"); #warning: This should go somewhere else // Never diff --git a/tests/core/serialize/CustomQuery.cpp b/tests/core/serialize/CustomQuery.cpp index 5ba50a90..48c217f5 100644 --- a/tests/core/serialize/CustomQuery.cpp +++ b/tests/core/serialize/CustomQuery.cpp @@ -46,8 +46,8 @@ int CustomQuery(int, char*[]) 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 " + "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 @@ -56,8 +56,8 @@ int CustomQuery(int, char*[]) 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 " + "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 @@ -73,7 +73,7 @@ int CustomQuery(int, char*[]) .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)))"); + "WHERE NOT EXISTS (SELECT tab_foo.double_n FROM tab_foo WHERE tab_foo.double_n = 17)"); #warning : reactivate #if 0 diff --git a/tests/core/serialize/DynamicWhere.cpp b/tests/core/serialize/DynamicWhere.cpp index 963a671f..eb7182b8 100644 --- a/tests/core/serialize/DynamicWhere.cpp +++ b/tests/core/serialize/DynamicWhere.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019, Roland Bock + * Copyright (c) 2016, Roland Bock * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, @@ -38,7 +38,7 @@ int DynamicWhere(int, char*[]) SQLPP_COMPARE(sqlpp::unconditionally(), ""); SQLPP_COMPARE(where(bar.boolNn), " 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(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/Float.cpp b/tests/core/serialize/Float.cpp index 019d50c7..0e94508b 100644 --- a/tests/core/serialize/Float.cpp +++ b/tests/core/serialize/Float.cpp @@ -23,7 +23,6 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include "compare.h" @@ -43,11 +42,11 @@ namespace } template - void float_safe_ostringstream_serializes_in_deserializable_format(int line, T value) + void to_sql_string_serializes_in_deserializable_format(int line, T value) { - sqlpp::detail::float_safe_ostringstream os; - os << value; - std::istringstream is{os.str()}; + MockDb::_serializer_context_t printer = {}; + const auto serialized = sqlpp::to_sql_string(printer, value); + std::istringstream is{serialized}; T deserialized; is >> deserialized; assert_equal(line, deserialized, value); @@ -73,9 +72,9 @@ namespace int Float(int, char*[]) { #warning: document that connectors need to use float_safe_ostringstream or similar. - float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086f); - float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086); - float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086l); + to_sql_string_serializes_in_deserializable_format(__LINE__, 10.0000086f); + to_sql_string_serializes_in_deserializable_format(__LINE__, 10.0000086); + to_sql_string_serializes_in_deserializable_format(__LINE__, 10.0000086l); SQLPP_COMPARE(10.0000114, "10.0000114"); SQLPP_COMPARE(10.0000086f, string_for_10_0000086()); diff --git a/tests/core/serialize/From.cpp b/tests/core/serialize/From.cpp index 9e577202..677790b2 100644 --- a/tests/core/serialize/From.cpp +++ b/tests/core/serialize/From.cpp @@ -47,29 +47,29 @@ int From(int, char* []) // Static joins 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)"); + " FROM tab_foo INNER JOIN tab_bar ON tab_foo.double_n > tab_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)"); + " FROM tab_foo INNER JOIN tab_bar ON tab_foo.double_n > tab_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)"); + " FROM tab_foo OUTER JOIN tab_bar ON tab_foo.double_n > tab_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)"); + " FROM tab_foo LEFT OUTER JOIN tab_bar ON tab_foo.double_n > tab_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)"); + " FROM tab_foo RIGHT OUTER JOIN tab_bar ON tab_foo.double_n > tab_bar.id"); 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)"); + " FROM tab_foo AS a INNER JOIN tab_foo AS b ON a.double_n > b.double_n"); 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)"); + " 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"); SQLPP_COMPARE(from(foo.join(bar).unconditionally()), " FROM tab_foo INNER JOIN tab_bar"); // Static joins involving verbatim tables 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)"); + " FROM tab_foo AS a INNER JOIN unknown_table ON a.double_n > unknown_table.column_x"); 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)"); + " FROM unknown_table INNER JOIN tab_foo AS a ON a.double_n > unknown_table.column_x"); SQLPP_COMPARE(from(sqlpp::verbatim_table("unknown_table") .as(sqlpp::alias::a) .join(sqlpp::verbatim_table("another_table")) diff --git a/tests/core/serialize/Insert.cpp b/tests/core/serialize/Insert.cpp index 4d1ddb1d..7fce7a48 100644 --- a/tests/core/serialize/Insert.cpp +++ b/tests/core/serialize/Insert.cpp @@ -34,7 +34,7 @@ namespace auto getTrue() -> std::string { MockDb::_serializer_context_t printer = {}; - return to_sql_string(printer, sqlpp::value(true)).str(); + return to_sql_string(printer, sqlpp::value(true)); } } diff --git a/tests/core/serialize/Lower.cpp b/tests/core/serialize/Lower.cpp index 2424d9fb..248d834b 100644 --- a/tests/core/serialize/Lower.cpp +++ b/tests/core/serialize/Lower.cpp @@ -35,11 +35,10 @@ int Lower(int, char* []) SQLPP_COMPARE(lower(bar.textN), "LOWER(tab_bar.text_n)"); // Expression. -#warning: Note that the inner parens aren't necessary. - SQLPP_COMPARE(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. - SQLPP_COMPARE(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/Parameter.cpp b/tests/core/serialize/Parameter.cpp index 363d4c66..ecdf1cfd 100644 --- a/tests/core/serialize/Parameter.cpp +++ b/tests/core/serialize/Parameter.cpp @@ -33,7 +33,7 @@ int Parameter(int, char*[]) const auto bar = test::TabBar{}; SQLPP_COMPARE(parameter(foo.doubleN), "?"); - SQLPP_COMPARE(bar.id > parameter(foo.doubleN), "(tab_bar.id > ?)"); + 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/SelectFlags.cpp b/tests/core/serialize/SelectFlags.cpp index 9ebd3581..65ebefff 100644 --- a/tests/core/serialize/SelectFlags.cpp +++ b/tests/core/serialize/SelectFlags.cpp @@ -39,7 +39,7 @@ int SelectFlags(int, char*[]) #warning: This should work //SQLPP_COMPARE(sqlpp::select_flags(), ""); - // No flags + // One flag SQLPP_COMPARE(select(foo.doubleN).flags(sqlpp::distinct), "SELECT DISTINCT tab_foo.double_n"); // One flag diff --git a/tests/core/serialize/Trim.cpp b/tests/core/serialize/Trim.cpp index 9942c7f0..1e4d0629 100644 --- a/tests/core/serialize/Trim.cpp +++ b/tests/core/serialize/Trim.cpp @@ -35,11 +35,10 @@ int Trim(int, char* []) SQLPP_COMPARE(trim(bar.textN), "TRIM(tab_bar.text_n)"); // Expression. -#warning: Note that the inner parens aren't necessary. - SQLPP_COMPARE(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. - SQLPP_COMPARE(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 00839a1d..efb657bb 100644 --- a/tests/core/serialize/Upper.cpp +++ b/tests/core/serialize/Upper.cpp @@ -35,11 +35,10 @@ int Upper(int, char* []) SQLPP_COMPARE(upper(bar.textN), "UPPER(tab_bar.text_n)"); // Expression. -#warning: Note that the inner parens aren't necessary. - SQLPP_COMPARE(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. - SQLPP_COMPARE(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 33fd3053..8d46e583 100644 --- a/tests/core/serialize/Where.cpp +++ b/tests/core/serialize/Where.cpp @@ -34,13 +34,13 @@ namespace auto getTrue() -> std::string { MockDb::_serializer_context_t printer = {}; - return to_sql_string(printer, sqlpp::value(true)).str(); + return to_sql_string(printer, sqlpp::value(true)); } auto getFalse() -> std::string { MockDb::_serializer_context_t printer = {}; - return to_sql_string(printer, sqlpp::value(false)).str(); + return to_sql_string(printer, sqlpp::value(false)); } } // namespace @@ -74,23 +74,23 @@ int Where(int, char*[]) // Sometimes 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(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')"); + " WHERE tab_bar.text_n IS NOT DISTINCT FROM 'SQL'"); SQLPP_COMPARE(where(is_not_distinct_from(bar.textN, ::sqlpp::nullopt)), - " WHERE (tab_bar.text_n IS NOT DISTINCT FROM NULL)"); + " WHERE tab_bar.text_n IS NOT DISTINCT FROM NULL"); SQLPP_COMPARE(where(bar.textN.is_not_distinct_from(::sqlpp::make_optional("SQL"))), - " WHERE (tab_bar.text_n IS NOT DISTINCT FROM 'SQL')"); + " WHERE tab_bar.text_n IS NOT DISTINCT FROM 'SQL'"); SQLPP_COMPARE(where(bar.textN.is_not_distinct_from(::sqlpp::nullopt)), - " WHERE (tab_bar.text_n IS NOT DISTINCT FROM NULL)"); + " WHERE tab_bar.text_n IS NOT DISTINCT FROM NULL"); // string argument - SQLPP_COMPARE(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 - SQLPP_COMPARE(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/operator/in_expression.cpp b/tests/core/serialize/operator/in_expression.cpp index 12984426..d158ffcf 100644 --- a/tests/core/serialize/operator/in_expression.cpp +++ b/tests/core/serialize/operator/in_expression.cpp @@ -44,7 +44,7 @@ int main(int, char* []) SQLPP_COMPARE(val.not_in(select(val.as(v))), "17 NOT IN (SELECT 17 AS v)"); // IN expressions with multiple arguments require inner parentheses. - SQLPP_COMPARE(val.in(1, select(val.as(v))), "17 IN (1, (SELECT 17 AS v))"); + SQLPP_COMPARE(val.in(1, select(val.as(v)), 23), "17 IN (1, (SELECT 17 AS v), 23)"); SQLPP_COMPARE(val.in(std::vector{17, 18, 19}), "17 IN (17, 18, 19)"); SQLPP_COMPARE(val.in(std::vector{expr, expr, expr}), "17 IN ((17 + 4), (17 + 4), (17 + 4))"); diff --git a/tests/core/usage/MockDb.h b/tests/core/usage/MockDb.h index defa1435..00166472 100644 --- a/tests/core/usage/MockDb.h +++ b/tests/core/usage/MockDb.h @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -48,7 +47,7 @@ struct MockDb : public sqlpp::connection struct _serializer_context_t { - ::sqlpp::detail::float_safe_ostringstream _os; + ::std::ostringstream _os; _serializer_context_t() = default; _serializer_context_t(const _serializer_context_t& rhs) @@ -66,8 +65,9 @@ struct MockDb : public sqlpp::connection _os.str(""); } +#warning This can be removed, I guess template - ::sqlpp::detail::float_safe_ostringstream& operator<<(T t) + ::std::ostringstream& operator<<(T t) { return _os << t; }