diff --git a/include/sqlpp11/core/basic/value.h b/include/sqlpp11/core/basic/value.h index 05b34fd4..8fa034cc 100644 --- a/include/sqlpp11/core/basic/value.h +++ b/include/sqlpp11/core/basic/value.h @@ -60,9 +60,7 @@ namespace sqlpp auto to_sql_string(Context& context, const value_t& t) -> std::string { #warning: Untested - to_sql_string(context, t._value); - - return context; + return to_sql_string(context, t._value); } template > diff --git a/include/sqlpp11/core/clause/select.h b/include/sqlpp11/core/clause/select.h index 6dd52b8b..bea78a3a 100644 --- a/include/sqlpp11/core/clause/select.h +++ b/include/sqlpp11/core/clause/select.h @@ -57,9 +57,7 @@ namespace sqlpp template auto to_sql_string(Context& context, const select_name_t&) -> std::string { - context << "SELECT "; - - return context; + return "SELECT "; } using blank_select_t = statement_t auto to_sql_string(Context& context, const std::tuple& t) -> std::string { - interpret_tuple(t, ',', context); - return context; + return interpret_tuple(t, ",", context); } template diff --git a/include/sqlpp11/core/interpret_tuple.h b/include/sqlpp11/core/interpret_tuple.h index f3ae6a64..67267273 100644 --- a/include/sqlpp11/core/interpret_tuple.h +++ b/include/sqlpp11/core/interpret_tuple.h @@ -34,20 +34,20 @@ namespace sqlpp { template - static void interpret_tuple_element( - const Element& element, const Separator& separator, Context& context, const UseBraces& /*unused*/, size_t index) + static auto interpret_tuple_element( + const Element& element, const Separator& separator, Context& context, const UseBraces& /*unused*/, size_t index) -> std::string { if (index) { - context << separator; + return separator; } if (UseBraces::value) { - operand_to_sql_string(context, element); + return operand_to_sql_string(context, element); } else { - to_sql_string(context, element); + return to_sql_string(context, element); } } @@ -57,7 +57,7 @@ namespace sqlpp Context& context, const UseBraces& useBraces, const ::sqlpp::index_sequence & - /*unused*/) -> Context& + /*unused*/) -> std::string { // Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init] // paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4. @@ -65,21 +65,22 @@ namespace sqlpp // See also: "http://stackoverflow.com/questions/6245735/pretty-print-stdtuple/6245777#6245777" // Beware of gcc-bug: "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253", otherwise an empty swallow struct could // be used + auto result = std::string{}; using swallow = int[]; (void)swallow{0, // workaround against -Wpedantic GCC warning "zero-size array 'int [0]'" - (interpret_tuple_element(std::get(t), separator, context, useBraces, Is), 0)...}; - return context; + (result += interpret_tuple_element(std::get(t), separator, context, useBraces, Is), 0)...}; + return result; } template - auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) -> Context& + auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) -> std::string { return interpret_tuple_impl(t, separator, context, std::true_type{}, ::sqlpp::make_index_sequence::value>{}); } template - auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context) -> Context& + auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context) -> std::string { return interpret_tuple_impl(t, separator, context, std::false_type{}, ::sqlpp::make_index_sequence::value>{}); diff --git a/include/sqlpp11/core/no_data.h b/include/sqlpp11/core/no_data.h index 02fe9f9e..2ab4fc9b 100644 --- a/include/sqlpp11/core/no_data.h +++ b/include/sqlpp11/core/no_data.h @@ -36,6 +36,6 @@ namespace sqlpp template auto to_sql_string(Context& context, const no_data_t&) -> std::string { - return context; + return {}; } } // namespace sqlpp diff --git a/include/sqlpp11/core/query/statement.h b/include/sqlpp11/core/query/statement.h index 0cfbd4e1..102cfac6 100644 --- a/include/sqlpp11/core/query/statement.h +++ b/include/sqlpp11/core/query/statement.h @@ -281,10 +281,13 @@ namespace sqlpp { using P = detail::statement_policies_t; + auto result = std::string{}; using swallow = int[]; - (void)swallow{0, (to_sql_string(context, static_cast&>(t)._data), 0)...}; + (void)swallow{ + 0, + (result += to_sql_string(context, static_cast&>(t)._data), 0)...}; - return context; + return result; } template diff --git a/include/sqlpp11/core/to_sql_string.h b/include/sqlpp11/core/to_sql_string.h index 8d7de43b..7500229b 100644 --- a/include/sqlpp11/core/to_sql_string.h +++ b/include/sqlpp11/core/to_sql_string.h @@ -26,6 +26,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include +#include +#include + +#include +#include +#include #include #include @@ -156,7 +164,7 @@ namespace sqlpp { auto result = std::string{"'"}; result.reserve(t.size() * 2); - for (const auto c : s) + for (const auto c : t) { if (c == '\'') result.push_back(c); // Escaping diff --git a/tests/core/serialize/compare.h b/tests/core/serialize/compare.h index a6740b99..277f7a90 100644 --- a/tests/core/serialize/compare.h +++ b/tests/core/serialize/compare.h @@ -33,8 +33,8 @@ { \ MockDb::_serializer_context_t printer = {}; \ \ - using sqlpp::serialize; \ - const auto result = to_sql_string(printer, expr).str(); \ + using sqlpp::to_sql_string; \ + const auto result = to_sql_string(printer, expr); \ \ if (result != expected_string) \ { \