mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 12:51:13 +08:00
Fixed a few broken tests
This commit is contained in:
parent
125a372c32
commit
3c36b1d025
@ -58,7 +58,7 @@ int CustomQuery(int, char*[])
|
|||||||
sqlpp::limit(7u), sqlpp::offset(3u)),
|
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 "
|
"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 "
|
"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");
|
"ASC, tab_foo.u_int_n DESC LIMIT 7 OFFSET 3");
|
||||||
|
|
||||||
// A pragma query/query for sqlite
|
// A pragma query/query for sqlite
|
||||||
SQLPP_COMPARE(
|
SQLPP_COMPARE(
|
||||||
|
@ -51,7 +51,7 @@ int From(int, char* [])
|
|||||||
SQLPP_COMPARE(from(foo.inner_join(bar).on(foo.doubleN > 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.full_outer_join(bar).on(foo.doubleN > bar.id)),
|
SQLPP_COMPARE(from(foo.full_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 FULL 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)),
|
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)),
|
SQLPP_COMPARE(from(foo.right_outer_join(bar).on(foo.doubleN > bar.id)),
|
||||||
|
@ -44,14 +44,14 @@ int Insert(int, char* [])
|
|||||||
|
|
||||||
SQLPP_COMPARE(insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES");
|
SQLPP_COMPARE(insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES");
|
||||||
SQLPP_COMPARE(insert_into(bar).set(bar.textN = "cheesecake", bar.boolNn = true),
|
SQLPP_COMPARE(insert_into(bar).set(bar.textN = "cheesecake", bar.boolNn = true),
|
||||||
"INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")");
|
"INSERT INTO tab_bar (text_n, bool_nn) VALUES('cheesecake', " + getTrue() + ")");
|
||||||
SQLPP_COMPARE(insert_into(bar).set(bar.textN = ::sqlpp::nullopt, bar.boolNn = true),
|
SQLPP_COMPARE(insert_into(bar).set(bar.textN = ::sqlpp::nullopt, bar.boolNn = true),
|
||||||
"INSERT INTO tab_bar (text_n,bool_nn) VALUES(NULL," + getTrue() + ")");
|
"INSERT INTO tab_bar (text_n, bool_nn) VALUES(NULL, " + getTrue() + ")");
|
||||||
::sqlpp::string_view cheeseCake = "cheesecake";
|
::sqlpp::string_view cheeseCake = "cheesecake";
|
||||||
SQLPP_COMPARE(insert_into(bar).set(bar.textN = std::string(cheeseCake), bar.boolNn = true),
|
SQLPP_COMPARE(insert_into(bar).set(bar.textN = std::string(cheeseCake), bar.boolNn = true),
|
||||||
"INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")");
|
"INSERT INTO tab_bar (text_n, bool_nn) VALUES('cheesecake', " + getTrue() + ")");
|
||||||
SQLPP_COMPARE(insert_into(bar).set(bar.textN = ::sqlpp::string_view(cheeseCake), bar.boolNn = true),
|
SQLPP_COMPARE(insert_into(bar).set(bar.textN = ::sqlpp::string_view(cheeseCake), bar.boolNn = true),
|
||||||
"INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")");
|
"INSERT INTO tab_bar (text_n, bool_nn) VALUES('cheesecake', " + getTrue() + ")");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ int SelectAs(int, char*[])
|
|||||||
#warning: The select itself should not offer an "as" that yields a value.
|
#warning: The select itself should not offer an "as" that yields a value.
|
||||||
#warning: The id_count should offer the alias that offers the value.
|
#warning: The id_count should offer the alias that offers the value.
|
||||||
SQLPP_COMPARE(select(foo.doubleN, select(count(bar.id).as(id_count)).from(bar).unconditionally().as(cheese)),
|
SQLPP_COMPARE(select(foo.doubleN, select(count(bar.id).as(id_count)).from(bar).unconditionally().as(cheese)),
|
||||||
"SELECT tab_foo.double_n,(SELECT COUNT(tab_bar.id) AS id_count FROM tab_bar) AS cheese");
|
"SELECT tab_foo.double_n, (SELECT COUNT(tab_bar.id) AS id_count FROM tab_bar) AS cheese");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -38,30 +38,30 @@ int SelectColumns(int, char*[])
|
|||||||
SQLPP_COMPARE(select(foo.doubleN), "SELECT tab_foo.double_n");
|
SQLPP_COMPARE(select(foo.doubleN), "SELECT tab_foo.double_n");
|
||||||
|
|
||||||
// Two columns
|
// Two columns
|
||||||
SQLPP_COMPARE(select(foo.doubleN, bar.id), "SELECT tab_foo.double_n,tab_bar.id");
|
SQLPP_COMPARE(select(foo.doubleN, bar.id), "SELECT tab_foo.double_n, tab_bar.id");
|
||||||
|
|
||||||
// All columns of a table
|
// All columns of a table
|
||||||
SQLPP_COMPARE(select(all_of(foo)),
|
SQLPP_COMPARE(select(all_of(foo)),
|
||||||
"SELECT tab_foo.id,tab_foo.text_nn_d,tab_foo.int_n,tab_foo.double_n,tab_foo.u_int_n,tab_foo.blob_n,tab_foo.bool_n");
|
"SELECT tab_foo.id, tab_foo.text_nn_d, tab_foo.int_n, tab_foo.double_n, tab_foo.u_int_n, tab_foo.blob_n, tab_foo.bool_n");
|
||||||
|
|
||||||
// All columns of a table plus one more
|
// All columns of a table plus one more
|
||||||
SQLPP_COMPARE(select(all_of(foo), bar.id),
|
SQLPP_COMPARE(select(all_of(foo), bar.id),
|
||||||
"SELECT tab_foo.id,tab_foo.text_nn_d,tab_foo.int_n,tab_foo.double_n,tab_foo.u_int_n,tab_foo.blob_n,tab_foo.bool_n,tab_bar.id");
|
"SELECT tab_foo.id, tab_foo.text_nn_d, tab_foo.int_n, tab_foo.double_n, tab_foo.u_int_n, tab_foo.blob_n, tab_foo.bool_n, tab_bar.id");
|
||||||
|
|
||||||
// One more, plus all columns of a table
|
// One more, plus all columns of a table
|
||||||
SQLPP_COMPARE(select(bar.id, all_of(foo)),
|
SQLPP_COMPARE(select(bar.id, all_of(foo)),
|
||||||
"SELECT tab_bar.id,tab_foo.id,tab_foo.text_nn_d,tab_foo.int_n,tab_foo.double_n,tab_foo.u_int_n,tab_foo.blob_n,tab_foo.bool_n");
|
"SELECT tab_bar.id, tab_foo.id, tab_foo.text_nn_d, tab_foo.int_n, tab_foo.double_n, tab_foo.u_int_n, tab_foo.blob_n, tab_foo.bool_n");
|
||||||
|
|
||||||
// Column and aggregate function
|
// Column and aggregate function
|
||||||
SQLPP_COMPARE(select(foo.doubleN, count(bar.id).as(id_count)), "SELECT tab_foo.double_n,COUNT(tab_bar.id) AS id_count");
|
SQLPP_COMPARE(select(foo.doubleN, count(bar.id).as(id_count)), "SELECT tab_foo.double_n, COUNT(tab_bar.id) AS id_count");
|
||||||
|
|
||||||
// Column aliases
|
// Column aliases
|
||||||
SQLPP_COMPARE(select(foo.doubleN.as(sqlpp::alias::o), count(bar.id).as(sqlpp::alias::a)),
|
SQLPP_COMPARE(select(foo.doubleN.as(sqlpp::alias::o), count(bar.id).as(sqlpp::alias::a)),
|
||||||
"SELECT tab_foo.double_n AS o,COUNT(tab_bar.id) AS a");
|
"SELECT tab_foo.double_n AS o, COUNT(tab_bar.id) AS a");
|
||||||
|
|
||||||
// Optional column manually
|
// Optional column manually
|
||||||
SQLPP_COMPARE(select(dynamic(true, bar.id)), "SELECT tab_bar.id");
|
SQLPP_COMPARE(select(dynamic(true, bar.id)), "SELECT tab_bar.id");
|
||||||
SQLPP_COMPARE(select(dynamic(false, bar.id)), "SELECT NULL as id");
|
SQLPP_COMPARE(select(dynamic(false, bar.id)), "SELECT NULL AS id");
|
||||||
|
|
||||||
#warning: add more optional column tests
|
#warning: add more optional column tests
|
||||||
|
|
||||||
|
@ -64,7 +64,8 @@ int main(int, char* [])
|
|||||||
|
|
||||||
// Single declared column
|
// Single declared column
|
||||||
SQLPP_COMPARE(group_by(declare_group_by_column(val)), " GROUP BY 17");
|
SQLPP_COMPARE(group_by(declare_group_by_column(val)), " GROUP BY 17");
|
||||||
SQLPP_COMPARE(group_by(declare_group_by_column(foo.id + 17)), " GROUP BY tab_foo.id + 17");
|
#warning: Do we really want these extra parentheses?
|
||||||
|
SQLPP_COMPARE(group_by(declare_group_by_column(foo.id + 17)), " GROUP BY (tab_foo.id + 17)");
|
||||||
|
|
||||||
// Mixed declared column
|
// Mixed declared column
|
||||||
SQLPP_COMPARE(group_by(foo.id, declare_group_by_column(val)), " GROUP BY tab_foo.id, 17");
|
SQLPP_COMPARE(group_by(foo.id, declare_group_by_column(val)), " GROUP BY tab_foo.id, 17");
|
||||||
|
@ -40,19 +40,19 @@ void test_group_by()
|
|||||||
using J = decltype(foo.join(bar).on(foo.id == bar.id));
|
using J = decltype(foo.join(bar).on(foo.id == bar.id));
|
||||||
static_assert(sqlpp::is_table<J>::value, "");
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<sqlpp::table_t<test::TabFoo_>, sqlpp::table_t<test::TabBar_>>>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_set<>>::value, "");
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
||||||
#warning: test the provided dynamic tables of?
|
#warning: test the provided dynamic tables of?
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
using J = decltype(foo.outer_join(bar).on(foo.id == bar.id));
|
using J = decltype(foo.full_outer_join(bar).on(foo.id == bar.id));
|
||||||
static_assert(sqlpp::is_table<J>::value, "");
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<sqlpp::table_t<test::TabFoo_>, sqlpp::table_t<test::TabBar_>>>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<sqlpp::table_t<test::TabFoo_>, sqlpp::table_t<test::TabBar_>>>::value, "");
|
||||||
#warning: test the provided dynamic tables of?
|
#warning: test the provided dynamic tables of?
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,15 +61,17 @@ void test_group_by()
|
|||||||
using J = decltype(foo.join(dynamic(true, bar)).on(foo.id == bar.id));
|
using J = decltype(foo.join(dynamic(true, bar)).on(foo.id == bar.id));
|
||||||
static_assert(sqlpp::is_table<J>::value, "");
|
static_assert(sqlpp::is_table<J>::value, "");
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_set<test::TabFoo, test::TabBar>>::value, "");
|
std::is_same<sqlpp::provided_tables_of_t<J>, sqlpp::detail::type_vector<test::TabFoo, test::TabBar>>::value, "");
|
||||||
#warning: OUTER is the wrong term. In a left-outer join, the *right* table is the one with optional rows.
|
#warning: OUTER is the wrong term. In a left-outer join, the *right* table is the one with optional rows.
|
||||||
static_assert(
|
static_assert(
|
||||||
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_set<>>::value, "");
|
std::is_same<sqlpp::provided_optional_tables_of_t<J>, sqlpp::detail::type_vector<>>::value, "");
|
||||||
#warning: test the provided dynamic tables of?
|
#warning: test the provided dynamic tables of?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#warning: Need to add tests all join types!
|
#warning: Need to add tests all join types!
|
||||||
|
#warning: Need to add tests with table_as
|
||||||
|
#warning: Need to add tests with verbatim tables
|
||||||
#warning: Need to add tests with 3 tables
|
#warning: Need to add tests with 3 tables
|
||||||
|
|
||||||
#warning: Need to add tests with CTEs
|
#warning: Need to add tests with CTEs
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include "Sample.h"
|
#include "Sample.h"
|
||||||
#include "MockDb.h"
|
#include "MockDb.h"
|
||||||
#include <sqlpp11/sqlpp11.h>
|
#include <sqlpp11/sqlpp11.h>
|
||||||
#include <sqlpp11/core/query/query/custom_query.h>
|
|
||||||
#include "../../include/test_helpers.h"
|
#include "../../include/test_helpers.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user