From b0a5059b59d60c56860f2313980ec81cc3967752 Mon Sep 17 00:00:00 2001 From: Serge Robyns Date: Sun, 19 Mar 2017 18:24:09 +0100 Subject: [PATCH] with working tests --- test_serializer/As.cpp | 22 +++++++-------- test_serializer/CustomQuery.cpp | 12 ++++---- test_serializer/From.cpp | 50 ++++++++++++++++----------------- test_serializer/In.cpp | 10 +++---- test_serializer/Insert.cpp | 4 +-- test_serializer/TableAlias.cpp | 4 +-- test_serializer/Where.cpp | 12 ++++---- 7 files changed, 57 insertions(+), 57 deletions(-) diff --git a/test_serializer/As.cpp b/test_serializer/As.cpp index 709148c1..c5dd7162 100644 --- a/test_serializer/As.cpp +++ b/test_serializer/As.cpp @@ -36,20 +36,20 @@ 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.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\""); // Auto alias - compare(__LINE__, select(max(bar.alpha)), "SELECT MAX(tab_bar.alpha) AS max_"); - compare(__LINE__, select(max(bar.alpha).as(cheese)), "SELECT MAX(tab_bar.alpha) AS cheese"); + compare(__LINE__, select(max(bar.alpha)), "SELECT MAX(\"tab_bar\".\"alpha\") AS \"max_\""); + compare(__LINE__, select(max(bar.alpha).as(cheese)), "SELECT MAX(\"tab_bar\".\"alpha\") AS \"cheese\""); compare(__LINE__, select(max(bar.alpha)).from(bar).unconditionally().as(cheese), - "(SELECT MAX(tab_bar.alpha) AS max_ FROM tab_bar) AS cheese"); - compare(__LINE__, select(max(bar.alpha)).from(bar).unconditionally().as(cheese).max, "cheese.max_"); + "(SELECT MAX(\"tab_bar\".\"alpha\") AS \"max_\" FROM \"tab_bar\") AS \"cheese\""); + compare(__LINE__, select(max(bar.alpha)).from(bar).unconditionally().as(cheese).max, "\"cheese\".\"max_\""); return 0; } diff --git a/test_serializer/CustomQuery.cpp b/test_serializer/CustomQuery.cpp index 4c00aec5..3db65d69 100644 --- a/test_serializer/CustomQuery.cpp +++ b/test_serializer/CustomQuery.cpp @@ -40,15 +40,15 @@ int CustomQuery(int, char* []) // Unconditionally compare(__LINE__, custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), from(foo), sqlpp::unconditionally()), - "SELECT DISTINCT tab_foo.omega FROM tab_foo "); + "SELECT DISTINCT \"tab_foo\".\"omega\" FROM \"tab_foo\" "); // A full select statement made individual clauses compare(__LINE__, custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), from(foo.join(bar).on(foo.omega == bar.alpha)), where(bar.alpha > 17), group_by(foo.omega), having(avg(bar.alpha) > 19), order_by(foo.omega.asc()), sqlpp::limit(10u), sqlpp::offset(100u)), - "SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE " - "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC " + "SELECT DISTINCT \"tab_foo\".\"omega\" FROM \"tab_foo\" INNER JOIN \"tab_bar\" ON (\"tab_foo\".\"omega\"=\"tab_bar\".\"alpha\") WHERE " + "(\"tab_bar\".\"alpha\">17) GROUP BY \"tab_foo\".\"omega\" HAVING (AVG(\"tab_bar\".\"alpha\")>19) ORDER BY \"tab_foo\".\"omega\" ASC " "LIMIT 10 OFFSET 100"); // A full select statement made individual clauses @@ -59,9 +59,9 @@ int CustomQuery(int, char* []) dynamic_group_by(db, foo.omega), dynamic_having(db, avg(bar.alpha) > 19), dynamic_order_by(db, foo.omega.asc(), foo.psi.order(sqlpp::sort_type::desc)), sqlpp::dynamic_limit(db), sqlpp::dynamic_offset(db)), - "SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE " - "(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega " - "ASC,tab_foo.psi DESC "); + "SELECT DISTINCT \"tab_foo\".\"omega\" FROM \"tab_foo\" INNER JOIN \"tab_bar\" ON (\"tab_foo\".\"omega\"=\"tab_bar\".\"alpha\") WHERE " + "(\"tab_bar\".\"alpha\">17) GROUP BY \"tab_foo\".\"omega\" HAVING (AVG(\"tab_bar\".\"alpha\")>19) ORDER BY \"tab_foo\".\"omega\" " + "ASC,\"tab_foo\".\"psi\" DESC "); // A pragma query for sqlite compare(__LINE__, diff --git a/test_serializer/From.cpp b/test_serializer/From.cpp index 7ea8126f..f47a3548 100644 --- a/test_serializer/From.cpp +++ b/test_serializer/From.cpp @@ -41,86 +41,86 @@ 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"); + compare(__LINE__, from(foo), " FROM \"tab_foo\""); + compare(__LINE__, 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.cross_join(bar)), " FROM \"tab_foo\" CROSS JOIN \"tab_bar\""); compare(__LINE__, from(foo.join(bar).on(foo.omega > bar.alpha)), - " FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega>tab_bar.alpha)"); + " FROM \"tab_foo\" INNER JOIN \"tab_bar\" ON (\"tab_foo\".\"omega\">\"tab_bar\".\"alpha\")"); compare(__LINE__, from(foo.inner_join(bar).on(foo.omega > bar.alpha)), - " FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega>tab_bar.alpha)"); + " FROM \"tab_foo\" INNER JOIN \"tab_bar\" ON (\"tab_foo\".\"omega\">\"tab_bar\".\"alpha\")"); compare(__LINE__, from(foo.outer_join(bar).on(foo.omega > bar.alpha)), - " FROM tab_foo OUTER JOIN tab_bar ON (tab_foo.omega>tab_bar.alpha)"); + " FROM \"tab_foo\" OUTER JOIN \"tab_bar\" ON (\"tab_foo\".\"omega\">\"tab_bar\".\"alpha\")"); compare(__LINE__, from(foo.left_outer_join(bar).on(foo.omega > bar.alpha)), - " FROM tab_foo LEFT OUTER JOIN tab_bar ON (tab_foo.omega>tab_bar.alpha)"); + " FROM \"tab_foo\" LEFT OUTER JOIN \"tab_bar\" ON (\"tab_foo\".\"omega\">\"tab_bar\".\"alpha\")"); compare(__LINE__, from(foo.right_outer_join(bar).on(foo.omega > bar.alpha)), - " FROM tab_foo RIGHT OUTER JOIN tab_bar ON (tab_foo.omega>tab_bar.alpha)"); + " FROM \"tab_foo\" RIGHT OUTER JOIN \"tab_bar\" ON (\"tab_foo\".\"omega\">\"tab_bar\".\"alpha\")"); compare(__LINE__, from(aFoo.join(bFoo).on(aFoo.omega > bFoo.omega)), - " FROM tab_foo AS a INNER JOIN tab_foo AS b ON (a.omega>b.omega)"); + " FROM \"tab_foo\" AS \"a\" INNER JOIN \"tab_foo\" AS \"b\" ON (\"a\".\"omega\">\"b\".\"omega\")"); compare( __LINE__, from(aFoo.join(bFoo).on(aFoo.omega > bFoo.omega).join(cFoo).on(bFoo.omega > cFoo.omega)), - " FROM tab_foo AS a INNER JOIN tab_foo AS b ON (a.omega>b.omega) INNER JOIN tab_foo AS c ON (b.omega>c.omega)"); - compare(__LINE__, from(foo.join(bar).unconditionally()), " FROM tab_foo INNER JOIN tab_bar"); + " FROM \"tab_foo\" AS \"a\" INNER JOIN \"tab_foo\" AS \"b\" ON (\"a\".\"omega\">\"b\".\"omega\") INNER JOIN \"tab_foo\" AS \"c\" ON (\"b\".\"omega\">\"c\".\"omega\")"); + compare(__LINE__, 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")) .on(aFoo.omega > sqlpp::verbatim("unknown_table.column_x"))), - " FROM tab_foo AS a INNER JOIN unknown_table ON (a.omega>unknown_table.column_x)"); + " FROM \"tab_foo\" AS \"a\" INNER JOIN unknown_table ON (\"a\".\"omega\">unknown_table.column_x)"); compare(__LINE__, from(sqlpp::verbatim_table("unknown_table") .join(aFoo) .on(aFoo.omega > sqlpp::verbatim("unknown_table.column_x"))), - " FROM unknown_table INNER JOIN tab_foo AS a ON (a.omega>unknown_table.column_x)"); + " FROM unknown_table INNER JOIN \"tab_foo\" AS \"a\" ON (\"a\".\"omega\">unknown_table.column_x)"); compare(__LINE__, 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"))), - " FROM unknown_table AS a INNER JOIN another_table ON a.column_x>another_table.x"); + " FROM unknown_table AS \"a\" INNER JOIN another_table ON a.column_x>another_table.x"); // Dynamic joins const auto df = dynamic_from(db, foo); - compare(__LINE__, df, " FROM tab_foo"); + compare(__LINE__, df, " FROM \"tab_foo\""); { auto dfa = df; dfa.from.add(dynamic_cross_join(bar)); - compare(__LINE__, dfa, " FROM tab_foo CROSS JOIN tab_bar"); + compare(__LINE__, dfa, " FROM \"tab_foo\" CROSS JOIN \"tab_bar\""); } { auto dfa = df; dfa.from.add(dynamic_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); + compare(__LINE__, dfa, " FROM \"tab_foo\" INNER JOIN \"tab_bar\" ON (\"tab_bar\".\"alpha\">\"tab_foo\".\"omega\")"); } { auto dfa = df; dfa.from.add(dynamic_inner_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); + compare(__LINE__, dfa, " FROM \"tab_foo\" INNER JOIN \"tab_bar\" ON (\"tab_bar\".\"alpha\">\"tab_foo\".\"omega\")"); } { auto dfa = df; dfa.from.add(dynamic_outer_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo OUTER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); + compare(__LINE__, dfa, " FROM \"tab_foo\" OUTER JOIN \"tab_bar\" ON (\"tab_bar\".\"alpha\">\"tab_foo\".\"omega\")"); } { auto dfa = df; dfa.from.add(dynamic_left_outer_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo LEFT OUTER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); + compare(__LINE__, dfa, " FROM \"tab_foo\" LEFT OUTER JOIN \"tab_bar\" ON (\"tab_bar\".\"alpha\">\"tab_foo\".\"omega\")"); } { auto dfa = df; dfa.from.add(dynamic_right_outer_join(bar).on(bar.alpha > foo.omega)); - compare(__LINE__, dfa, " FROM tab_foo RIGHT OUTER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)"); + compare(__LINE__, dfa, " FROM \"tab_foo\" RIGHT OUTER JOIN \"tab_bar\" ON (\"tab_bar\".\"alpha\">\"tab_foo\".\"omega\")"); } { auto dfa = df; dfa.from.add(dynamic_join(bar).unconditionally()); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN tab_bar"); + compare(__LINE__, dfa, " FROM \"tab_foo\" INNER JOIN \"tab_bar\""); } { auto dfa = df; dfa.from.add(dynamic_inner_join(bar).on(bar.alpha > foo.omega)); dfa.from.add(dynamic_outer_join(aFoo).on(without_table_check(bar.alpha > aFoo.omega))); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega) OUTER JOIN tab_foo AS a " - "ON (tab_bar.alpha>a.omega)"); + compare(__LINE__, dfa, " FROM \"tab_foo\" INNER JOIN \"tab_bar\" ON (\"tab_bar\".\"alpha\">\"tab_foo\".\"omega\") OUTER JOIN \"tab_foo\" AS \"a\" " + "ON (\"tab_bar\".\"alpha\">\"a\".\"omega\")"); } // Dynamic joins involving verbatim table @@ -129,7 +129,7 @@ int From(int, char* []) dfa.from.add( dynamic_inner_join(sqlpp::verbatim_table("unknown_table")) .on(without_table_check(bar.alpha > sqlpp::verbatim("unknown_table.column_x")))); - compare(__LINE__, dfa, " FROM tab_foo INNER JOIN unknown_table ON (tab_bar.alpha>unknown_table.column_x)"); + compare(__LINE__, dfa, " FROM \"tab_foo\" INNER JOIN unknown_table ON (\"tab_bar\".\"alpha\">unknown_table.column_x)"); } return 0; diff --git a/test_serializer/In.cpp b/test_serializer/In.cpp index 89fc09c7..adc79239 100644 --- a/test_serializer/In.cpp +++ b/test_serializer/In.cpp @@ -44,17 +44,17 @@ int In(int, char* []) const auto bar = test::TabBar{}; // Individual values - compare(__LINE__, foo.omega.in(17), "tab_foo.omega IN(17)"); - compare(__LINE__, foo.omega.in(17, bar.alpha), "tab_foo.omega IN(17,tab_bar.alpha)"); - compare(__LINE__, foo.omega.in(17, bar.alpha, sqlpp::value(19)), "tab_foo.omega IN(17,tab_bar.alpha,19)"); + compare(__LINE__, foo.omega.in(17), "\"tab_foo\".\"omega\" IN(17)"); + compare(__LINE__, foo.omega.in(17, bar.alpha), "\"tab_foo\".\"omega\" IN(17,\"tab_bar\".\"alpha\")"); + compare(__LINE__, foo.omega.in(17, bar.alpha, sqlpp::value(19)), "\"tab_foo\".\"omega\" IN(17,\"tab_bar\".\"alpha\",19)"); // Lists compare(__LINE__, foo.omega.in(sqlpp::value_list(std::vector{1.7f, 2.5f, 17.f, 0.f})), - "tab_foo.omega IN(1.7,2.5,17,0)"); + "\"tab_foo\".\"omega\" IN(1.7,2.5,17,0)"); // Sub select compare(__LINE__, foo.omega.in(select(bar.alpha).from(bar).unconditionally()), - "tab_foo.omega IN(SELECT tab_bar.alpha FROM tab_bar)"); + "\"tab_foo\".\"omega\" IN(SELECT \"tab_bar\".\"alpha\" FROM \"tab_bar\")"); // Empty lists (not normally covered by SQL) compare(__LINE__, foo.omega.in(), getFalse()); diff --git a/test_serializer/Insert.cpp b/test_serializer/Insert.cpp index e145cf7d..7e5a7c1f 100644 --- a/test_serializer/Insert.cpp +++ b/test_serializer/Insert.cpp @@ -42,9 +42,9 @@ 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).default_values(), "INSERT INTO \"tab_bar\" DEFAULT VALUES"); compare(__LINE__, insert_into(bar).set(bar.beta = "cheesecake", bar.gamma = true), - "INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")"); + "INSERT INTO \"tab_bar\" (\"beta\",\"gamma\") VALUES('cheesecake'," + getTrue() + ")"); return 0; } diff --git a/test_serializer/TableAlias.cpp b/test_serializer/TableAlias.cpp index aef0b57b..a4e636dc 100644 --- a/test_serializer/TableAlias.cpp +++ b/test_serializer/TableAlias.cpp @@ -35,9 +35,9 @@ int TableAlias(int, char* []) const auto bar = test::TabBar{}; // Individual values - compare(__LINE__, foo.as(bar), "tab_foo AS tab_bar"); + compare(__LINE__, foo.as(bar), "\"tab_foo\" AS \"tab_bar\""); compare(__LINE__, select(foo.omega).from(foo).unconditionally().as(bar), - "(SELECT tab_foo.omega FROM tab_foo) AS tab_bar"); + "(SELECT \"tab_foo\".\"omega\" FROM \"tab_foo\") AS \"tab_bar\""); return 0; } diff --git a/test_serializer/Where.cpp b/test_serializer/Where.cpp index a4e80112..63c9bdba 100644 --- a/test_serializer/Where.cpp +++ b/test_serializer/Where.cpp @@ -50,18 +50,18 @@ int Where(int, char* []) const auto bar = test::TabBar{}; // Unconditionally - 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__, 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__, where(sqlpp::value(true)), " WHERE " + getTrue()); // Never compare(__LINE__, where(sqlpp::value(false)), " WHERE " + getFalse()); // Sometimes - compare(__LINE__, where(bar.gamma), " WHERE tab_bar.gamma"); - compare(__LINE__, where(bar.gamma == false), " WHERE (tab_bar.gamma=" + getFalse() + ")"); - compare(__LINE__, where(bar.beta == "SQL"), " WHERE (tab_bar.beta='SQL')"); + compare(__LINE__, where(bar.gamma), " WHERE \"tab_bar\".\"gamma\""); + compare(__LINE__, where(bar.gamma == false), " WHERE (\"tab_bar\".\"gamma\"=" + getFalse() + ")"); + compare(__LINE__, where(bar.beta == "SQL"), " WHERE (\"tab_bar\".\"beta\"='SQL')"); return 0; }