From bb77cc14591c8f2dc4b40d09def57eb76ec95ae8 Mon Sep 17 00:00:00 2001 From: rbock Date: Wed, 9 Oct 2019 07:25:24 +0200 Subject: [PATCH] Fix missing space for operator- --- include/sqlpp11/expression_fwd.h | 12 +++++++++++- test_serializer/As.cpp | 12 ++++++------ test_serializer/Where.cpp | 6 ++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/sqlpp11/expression_fwd.h b/include/sqlpp11/expression_fwd.h index 220ab439..a4b55700 100644 --- a/include/sqlpp11/expression_fwd.h +++ b/include/sqlpp11/expression_fwd.h @@ -98,7 +98,17 @@ namespace sqlpp struct minus { using _traits = make_traits; - static constexpr const char* _name = "-"; + // The trailing space is necessary to prevent + // ``` + // t.id - -1 + // ``` + // from turning into + // ``` + // tab_sample.id--1 + // ``` + // (-- starts a comment in SQL) + // See https://github.com/rbock/sqlpp11/issues/294 + static constexpr const char* _name = " - "; }; template diff --git a/test_serializer/As.cpp b/test_serializer/As.cpp index 86352257..25f6783f 100644 --- a/test_serializer/As.cpp +++ b/test_serializer/As.cpp @@ -31,18 +31,18 @@ SQLPP_ALIAS_PROVIDER(cheese) -int As(int, char* []) +int As(int, char*[]) { const auto foo = test::TabFoo{}; const auto bar = test::TabBar{}; compare(__LINE__, foo.omega.as(cheese), "tab_foo.omega AS cheese"); compare(__LINE__, (foo.omega + 17).as(cheese), "(tab_foo.omega+17) AS cheese"); - compare(__LINE__, (foo.omega - 17).as(cheese), "(tab_foo.omega-17) AS cheese"); - compare(__LINE__, (foo.omega - uint32_t(17)).as(cheese), "(tab_foo.omega-17) AS cheese"); - compare(__LINE__, (foo.omega - bar.alpha).as(cheese), "(tab_foo.omega-tab_bar.alpha) AS cheese"); - compare(__LINE__, (count(foo.omega) - bar.alpha).as(cheese), "(COUNT(tab_foo.omega)-tab_bar.alpha) AS cheese"); - compare(__LINE__, (count(foo.omega) - uint32_t(17)).as(cheese), "(COUNT(tab_foo.omega)-17) AS cheese"); + compare(__LINE__, (foo.omega - 17).as(cheese), "(tab_foo.omega - 17) AS cheese"); + compare(__LINE__, (foo.omega - uint32_t(17)).as(cheese), "(tab_foo.omega - 17) AS cheese"); + compare(__LINE__, (foo.omega - bar.alpha).as(cheese), "(tab_foo.omega - tab_bar.alpha) AS cheese"); + compare(__LINE__, (count(foo.omega) - bar.alpha).as(cheese), "(COUNT(tab_foo.omega) - tab_bar.alpha) AS cheese"); + compare(__LINE__, (count(foo.omega) - uint32_t(17)).as(cheese), "(COUNT(tab_foo.omega) - 17) AS cheese"); // Auto alias compare(__LINE__, select(max(bar.alpha)), "SELECT MAX(tab_bar.alpha) AS max_"); diff --git a/test_serializer/Where.cpp b/test_serializer/Where.cpp index ff369a99..6e568196 100644 --- a/test_serializer/Where.cpp +++ b/test_serializer/Where.cpp @@ -42,9 +42,9 @@ namespace MockDb::_serializer_context_t printer = {}; return serialize(sqlpp::value(false), printer).str(); } -} +} // namespace -int Where(int, char* []) +int Where(int, char*[]) { const auto foo = test::TabFoo{}; const auto bar = test::TabBar{}; @@ -53,6 +53,8 @@ int Where(int, char* []) compare(__LINE__, select(foo.omega).from(foo).unconditionally(), "SELECT tab_foo.omega FROM tab_foo"); compare(__LINE__, remove_from(foo).unconditionally(), "DELETE FROM tab_foo"); compare(__LINE__, update(foo).set(foo.omega = 42).unconditionally(), "UPDATE tab_foo SET omega=42"); + compare(__LINE__, update(foo).set(foo.omega = foo.omega - -1).unconditionally(), + "UPDATE tab_foo SET omega=(tab_foo.omega - -1)"); compare(__LINE__, where(sqlpp::value(true)), " WHERE " + getTrue()); // Never