0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 12:51:13 +08:00

Replace test column names with clearer names

This commit is contained in:
Roland Bock 2024-06-14 20:04:08 +02:00
parent 0eac55c377
commit d7c54c949f
58 changed files with 896 additions and 944 deletions

View File

@ -39,5 +39,5 @@ int main()
{
const auto t = test::TabBar{};
count(count(t.alpha));
count(count(t.id));
}

View File

@ -39,5 +39,5 @@ int main()
{
const auto t = test::TabBar{};
max(max(t.alpha));
max(max(t.id));
}

View File

@ -39,5 +39,5 @@ int main()
{
const auto t = test::TabBar{};
insert_into(t).set(t.alpha = 7, t.gamma = false, t.beta = "alpha must not be set");
insert_into(t).set(t.id = 7, t.boolNn = false, t.textN = "id must not be set");
}

View File

@ -38,5 +38,5 @@ int main()
{
const auto t = test::TabBar{};
update(t).set(t.alpha = 7, t.gamma = false, t.beta = "alpha must not be set");
update(t).set(t.id = 7, t.boolNn = false, t.textN = "id must not be set");
}

View File

@ -39,5 +39,5 @@ int main()
{
const auto t = test::TabBar{};
insert_into(t).set(t.beta = "need also to insert gamma");
insert_into(t).set(t.textN = "need also to insert boolNn");
}

View File

@ -32,8 +32,8 @@ int Any(int, char* [])
const auto bar = test::TabBar{};
// With sub select.
compare(__LINE__, any(select(bar.alpha).from(bar).where(bar.alpha > 17)), "ANY(SELECT tab_bar.alpha FROM tab_bar WHERE (tab_bar.alpha>17))");
compare(__LINE__, bar.delta == any(select(bar.alpha).from(bar).where(bar.alpha > 17)), "(tab_bar.delta=ANY(SELECT tab_bar.alpha FROM tab_bar WHERE (tab_bar.alpha>17)))");
compare(__LINE__, any(select(bar.id).from(bar).where(bar.id > 17)), "ANY(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id>17))");
compare(__LINE__, bar.intN == any(select(bar.id).from(bar).where(bar.id > 17)), "(tab_bar.int_n=ANY(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id>17)))");
return 0;
}

View File

@ -37,20 +37,20 @@ int As(int, char*[])
const auto bar = test::TabBar{};
compare(__LINE__, foo, "tab_foo");
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.doubleN.as(cheese), "tab_foo.double_n AS cheese");
compare(__LINE__, (foo.doubleN + 17).as(cheese), "(tab_foo.double_n+17) AS cheese");
compare(__LINE__, (foo.doubleN - 17).as(cheese), "(tab_foo.double_n - 17) AS cheese");
compare(__LINE__, (foo.doubleN - uint32_t(17)).as(cheese), "(tab_foo.double_n - 17) AS cheese");
compare(__LINE__, (foo.doubleN - bar.id).as(cheese), "(tab_foo.double_n - tab_bar.id) AS cheese");
compare(__LINE__, (count(foo.doubleN) - bar.id).as(cheese), "(COUNT(tab_foo.double_n) - tab_bar.id) AS cheese");
compare(__LINE__, (count(foo.doubleN) - uint32_t(17)).as(cheese), "(COUNT(tab_foo.double_n) - 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)).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_");
compare(__LINE__, select(max(bar.id)), "SELECT MAX(tab_bar.id) AS max_");
compare(__LINE__, select(max(bar.id).as(cheese)), "SELECT MAX(tab_bar.id) AS cheese");
compare(__LINE__, select(max(bar.id)).from(bar).unconditionally().as(cheese),
"(SELECT MAX(tab_bar.id) AS max_ FROM tab_bar) AS cheese");
compare(__LINE__, select(max(bar.id)).from(bar).unconditionally().as(cheese).max, "cheese.max_");
return 0;
}

View File

@ -32,13 +32,13 @@ int Avg(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, avg(bar.alpha), "AVG(tab_bar.alpha)");
compare(__LINE__, avg(sqlpp::distinct, bar.alpha), "AVG(DISTINCT tab_bar.alpha)");
compare(__LINE__, avg(bar.id), "AVG(tab_bar.id)");
compare(__LINE__, avg(sqlpp::distinct, bar.id), "AVG(DISTINCT tab_bar.id)");
// Expression.
// Note that the inner parens aren't necessary.
compare(__LINE__, avg(bar.alpha + 7), "AVG((tab_bar.alpha+7))");
compare(__LINE__, avg(sqlpp::distinct, bar.alpha + 7), "AVG(DISTINCT (tab_bar.alpha+7))");
compare(__LINE__, avg(bar.id + 7), "AVG((tab_bar.id+7))");
compare(__LINE__, avg(sqlpp::distinct, bar.id + 7), "AVG(DISTINCT (tab_bar.id+7))");
// With sub select.
compare(__LINE__, avg(select(sqlpp::value(7).as(sqlpp::alias::a))), "AVG((SELECT 7 AS a))");

View File

@ -58,12 +58,12 @@ int Blob(int, char*[])
// const auto bar = test::TabBar{};
// Unconditionally
compare(__LINE__, select(foo.book).from(foo).where(foo.book == toByteVector("john doe")),
"SELECT tab_foo.book FROM tab_foo WHERE (tab_foo.book=x'6A6F686E20646F65')");
compare(__LINE__, 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')");
std::array<uint8_t, 8> arr{{'j', 'o', 'h', 'n', ' ', 'd', 'o', 'e'}};
compare(__LINE__, select(foo.book).from(foo).where(foo.book == arr),
"SELECT tab_foo.book FROM tab_foo WHERE (tab_foo.book=x'6A6F686E20646F65')");
compare(__LINE__, select(foo.blobN).from(foo).where(foo.blobN == arr),
"SELECT tab_foo.blob_n FROM tab_foo WHERE (tab_foo.blob_n=x'6A6F686E20646F65')");
// Never
compare(__LINE__, where(sqlpp::value(false)), " WHERE " + getFalse());

View File

@ -32,13 +32,13 @@ int Count(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, count(bar.alpha), "COUNT(tab_bar.alpha)");
compare(__LINE__, count(sqlpp::distinct, bar.alpha), "COUNT(DISTINCT tab_bar.alpha)");
compare(__LINE__, count(bar.id), "COUNT(tab_bar.id)");
compare(__LINE__, count(sqlpp::distinct, bar.id), "COUNT(DISTINCT tab_bar.id)");
// Expression.
// Note that the inner parens aren't necessary.
compare(__LINE__, count(bar.alpha + 7), "COUNT((tab_bar.alpha+7))");
compare(__LINE__, count(sqlpp::distinct, bar.alpha + 7), "COUNT(DISTINCT (tab_bar.alpha+7))");
compare(__LINE__, count(bar.id + 7), "COUNT((tab_bar.id+7))");
compare(__LINE__, count(sqlpp::distinct, bar.id + 7), "COUNT(DISTINCT (tab_bar.id+7))");
// With sub select.
compare(__LINE__, count(select(sqlpp::value(7).as(sqlpp::alias::a))), "COUNT((SELECT 7 AS a))");

View File

@ -38,30 +38,30 @@ int CustomQuery(int, char*[])
// Unconditionally
compare(__LINE__,
custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega), from(foo),
custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN), from(foo),
sqlpp::unconditionally()),
"SELECT DISTINCT tab_foo.omega FROM tab_foo ");
"SELECT DISTINCT tab_foo.double_n 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 "
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 "
"LIMIT 10 OFFSET 100");
// 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(), foo.psi.order(sqlpp::sort_type::desc)),
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(), foo.uIntN.order(sqlpp::sort_type::desc)),
sqlpp::limit(7u), sqlpp::offset(3u)),
"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 LIMIT 7 OFFSET 3");
"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 for sqlite
compare(__LINE__,
@ -71,20 +71,20 @@ int CustomQuery(int, char*[])
// An insert from select for postgresql
const auto x = 17;
compare(__LINE__,
custom_query(insert_into(foo).columns(foo.omega),
select(sqlpp::value(x).as(foo.omega))
custom_query(insert_into(foo).columns(foo.doubleN),
select(sqlpp::value(x).as(foo.doubleN))
.from(foo)
.where(not exists(select(foo.omega).from(foo).where(foo.omega == x)))),
"INSERT INTO tab_foo (omega) "
"SELECT 17 AS omega FROM tab_foo "
"WHERE (NOT EXISTS(SELECT tab_foo.omega FROM tab_foo WHERE (tab_foo.omega=17)))");
.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)))");
// A multi-row "insert or ignore"
auto batch = insert_columns(bar.beta, bar.gamma);
batch.add_values(bar.beta = "sample", bar.gamma = true);
batch.add_values(bar.beta = "ample", bar.gamma = false);
auto batch = insert_columns(bar.textN, bar.boolNn);
batch.add_values(bar.textN = "sample", bar.boolNn = true);
batch.add_values(bar.textN = "ample", bar.boolNn = false);
compare(__LINE__, custom_query(sqlpp::insert(), sqlpp::verbatim(" OR IGNORE"), into(bar), batch),
"INSERT OR IGNORE INTO tab_bar (beta,gamma) VALUES ('sample',1),('ample',0)");
"INSERT OR IGNORE INTO tab_bar (text_n,bool_nn) VALUES ('sample',1),('ample',0)");
return 0;
}

View File

@ -35,7 +35,7 @@ int DynamicWhere(int, char*[])
auto db = MockDb{};
compare(__LINE__, sqlpp::unconditionally(), "");
compare(__LINE__, where(bar.gamma), " WHERE tab_bar.gamma");
compare(__LINE__, where(bar.boolNn), " WHERE tab_bar.bool_nn");
#warning add tests with optional expressions
return 0;

View File

@ -32,9 +32,9 @@ int Exists(int, char* [])
const auto bar = test::TabBar{};
// With sub select.
compare(__LINE__, exists(select(bar.alpha).from(bar).where(bar.alpha > 17)), "EXISTS(SELECT tab_bar.alpha FROM tab_bar WHERE (tab_bar.alpha>17))");
compare(__LINE__, bar.beta == "" and exists(select(bar.alpha).from(bar).where(bar.alpha > 17)),
"((tab_bar.beta='') AND EXISTS(SELECT tab_bar.alpha FROM tab_bar WHERE (tab_bar.alpha>17)))");
compare(__LINE__, exists(select(bar.id).from(bar).where(bar.id > 17)), "EXISTS(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id>17))");
compare(__LINE__, bar.textN == "" and exists(select(bar.id).from(bar).where(bar.id > 17)),
"((tab_bar.text_n='') AND EXISTS(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id>17)))");
return 0;
}

View File

@ -52,8 +52,8 @@ int ForUpdate(int, char* [])
// const auto bar = test::TabBar{};
// Unconditionally
compare(__LINE__, select(foo.omega).from(foo).unconditionally().for_update(),
"SELECT tab_foo.omega FROM tab_foo FOR UPDATE ");
compare(__LINE__, select(foo.doubleN).from(foo).unconditionally().for_update(),
"SELECT tab_foo.double_n FROM tab_foo FOR UPDATE ");
// Never
compare(__LINE__, where(sqlpp::value(false)), " WHERE " + getFalse());

View File

@ -46,31 +46,31 @@ int From(int, char* [])
// Static joins
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)");
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)");
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)");
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)");
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)");
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)");
compare(__LINE__, from(foo.join(bar).on(foo.doubleN > bar.id)),
" FROM tab_foo INNER JOIN tab_bar ON (tab_foo.double_n>tab_bar.id)");
compare(__LINE__, 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)");
compare(__LINE__, 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)");
compare(__LINE__, 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)");
compare(__LINE__, 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)");
compare(__LINE__, 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)");
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)");
__LINE__, 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)");
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<sqlpp::floating_point>("unknown_table.column_x"))),
" FROM tab_foo AS a INNER JOIN unknown_table ON (a.omega>unknown_table.column_x)");
.on(aFoo.doubleN > sqlpp::verbatim<sqlpp::floating_point>("unknown_table.column_x"))),
" FROM tab_foo AS a INNER JOIN unknown_table ON (a.double_n>unknown_table.column_x)");
compare(__LINE__, from(sqlpp::verbatim_table("unknown_table")
.join(aFoo)
.on(aFoo.omega > sqlpp::verbatim<sqlpp::floating_point>("unknown_table.column_x"))),
" FROM unknown_table INNER JOIN tab_foo AS a ON (a.omega>unknown_table.column_x)");
.on(aFoo.doubleN > sqlpp::verbatim<sqlpp::floating_point>("unknown_table.column_x"))),
" FROM unknown_table INNER JOIN tab_foo AS a ON (a.double_n>unknown_table.column_x)");
compare(__LINE__, from(sqlpp::verbatim_table("unknown_table")
.as(sqlpp::alias::a)
.join(sqlpp::verbatim_table("another_table"))

View File

@ -44,21 +44,21 @@ 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.doubleN.in(17), "tab_foo.double_n IN(17)");
compare(__LINE__, foo.doubleN.in(17, bar.id), "tab_foo.double_n IN(17,tab_bar.id)");
compare(__LINE__, foo.doubleN.in(17, bar.id, sqlpp::value(19)), "tab_foo.double_n IN(17,tab_bar.id,19)");
// Lists
compare(__LINE__, foo.omega.in(sqlpp::value_list(std::vector<float>{1.75f, 2.5f, 17.f, 0.f})),
"tab_foo.omega IN(1.75,2.5,17,0)");
compare(__LINE__, foo.doubleN.in(sqlpp::value_list(std::vector<float>{1.75f, 2.5f, 17.f, 0.f})),
"tab_foo.double_n IN(1.75,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)");
compare(__LINE__, foo.doubleN.in(select(bar.id).from(bar).unconditionally()),
"tab_foo.double_n IN(SELECT tab_bar.id FROM tab_bar)");
// Empty lists (not normally covered by SQL)
compare(__LINE__, foo.omega.in(), getFalse());
compare(__LINE__, foo.omega.in(sqlpp::value_list(std::vector<int>{})), getFalse());
compare(__LINE__, foo.doubleN.in(), getFalse());
compare(__LINE__, foo.doubleN.in(sqlpp::value_list(std::vector<int>{})), getFalse());
return 0;
}

View File

@ -43,15 +43,15 @@ 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).set(bar.beta = "cheesecake", bar.gamma = true),
"INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")");
compare(__LINE__, insert_into(bar).set(bar.beta = ::sqlpp::null, bar.gamma = true),
"INSERT INTO tab_bar (beta,gamma) VALUES(NULL," + getTrue() + ")");
compare(__LINE__, insert_into(bar).set(bar.textN = "cheesecake", bar.boolNn = true),
"INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")");
compare(__LINE__, insert_into(bar).set(bar.textN = ::sqlpp::null, bar.boolNn = true),
"INSERT INTO tab_bar (text_n,bool_nn) VALUES(NULL," + getTrue() + ")");
sqlpp::compat::string_view cheeseCake = "cheesecake";
compare(__LINE__, insert_into(bar).set(bar.beta = std::string(cheeseCake), bar.gamma = true),
"INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")");
compare(__LINE__, insert_into(bar).set(bar.beta = sqlpp::compat::string_view(cheeseCake), bar.gamma = true),
"INSERT INTO tab_bar (beta,gamma) VALUES('cheesecake'," + getTrue() + ")");
compare(__LINE__, insert_into(bar).set(bar.textN = std::string(cheeseCake), bar.boolNn = true),
"INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")");
compare(__LINE__, insert_into(bar).set(bar.textN = sqlpp::compat::string_view(cheeseCake), bar.boolNn = true),
"INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")");
return 0;
}

View File

@ -32,17 +32,17 @@ int IsNotNull(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, is_not_null(bar.beta), "tab_bar.beta IS NOT NULL");
compare(__LINE__, is_not_null(bar.textN), "tab_bar.text_n IS NOT NULL");
// Expression.
compare(__LINE__, is_not_null(bar.beta + "suffix"), "(tab_bar.beta||'suffix') IS NOT NULL");
compare(__LINE__, is_not_null(bar.textN + "suffix"), "(tab_bar.text_n||'suffix') IS NOT NULL");
// With sub select.
compare(__LINE__, is_not_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "(SELECT 'something' AS a) IS NOT NULL");
// Requires parens.
compare(__LINE__, is_not_null(bar.beta) or bar.beta == "", "((tab_bar.beta IS NOT NULL) OR (tab_bar.beta=''))");
compare(__LINE__, bar.beta == "" or is_not_null(bar.beta), "((tab_bar.beta='') OR (tab_bar.beta IS NOT NULL))");
compare(__LINE__, is_not_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NOT NULL) OR (tab_bar.text_n=''))");
compare(__LINE__, bar.textN == "" or is_not_null(bar.textN), "((tab_bar.text_n='') OR (tab_bar.text_n IS NOT NULL))");
return 0;
}

View File

@ -32,17 +32,17 @@ int IsNull(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, is_null(bar.beta), "tab_bar.beta IS NULL");
compare(__LINE__, is_null(bar.textN), "tab_bar.text_n IS NULL");
// Expression.
compare(__LINE__, is_null(bar.beta + "suffix"), "(tab_bar.beta||'suffix') IS NULL");
compare(__LINE__, is_null(bar.textN + "suffix"), "(tab_bar.text_n||'suffix') IS NULL");
// With sub select.
compare(__LINE__, is_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "(SELECT 'something' AS a) IS NULL");
// Requires parens.
compare(__LINE__, is_null(bar.beta) or bar.beta == "", "((tab_bar.beta IS NULL) OR (tab_bar.beta=''))");
compare(__LINE__, bar.beta == "" or is_null(bar.beta), "((tab_bar.beta='') OR (tab_bar.beta IS NULL))");
compare(__LINE__, is_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NULL) OR (tab_bar.text_n=''))");
compare(__LINE__, bar.textN == "" or is_null(bar.textN), "((tab_bar.text_n='') OR (tab_bar.text_n IS NULL))");
return 0;
}

View File

@ -32,11 +32,11 @@ int Lower(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, lower(bar.beta), "LOWER(tab_bar.beta)");
compare(__LINE__, lower(bar.textN), "LOWER(tab_bar.text_n)");
// Expression.
// Note that the inner parens aren't necessary.
compare(__LINE__, lower(bar.beta + "suffix"), "LOWER((tab_bar.beta||'suffix'))");
compare(__LINE__, lower(bar.textN + "suffix"), "LOWER((tab_bar.text_n||'suffix'))");
// With sub select.
compare(__LINE__, lower(select(sqlpp::value("something").as(sqlpp::alias::a))), "LOWER((SELECT 'something' AS a))");

View File

@ -32,13 +32,13 @@ int Max(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, max(bar.alpha), "MAX(tab_bar.alpha)");
compare(__LINE__, max(sqlpp::distinct, bar.alpha), "MAX(DISTINCT tab_bar.alpha)");
compare(__LINE__, max(bar.id), "MAX(tab_bar.id)");
compare(__LINE__, max(sqlpp::distinct, bar.id), "MAX(DISTINCT tab_bar.id)");
// Expression.
// Note that the inner parens aren't necessary.
compare(__LINE__, max(bar.alpha + 7), "MAX((tab_bar.alpha+7))");
compare(__LINE__, max(sqlpp::distinct, bar.alpha + 7), "MAX(DISTINCT (tab_bar.alpha+7))");
compare(__LINE__, max(bar.id + 7), "MAX((tab_bar.id+7))");
compare(__LINE__, max(sqlpp::distinct, bar.id + 7), "MAX(DISTINCT (tab_bar.id+7))");
// With sub select.
compare(__LINE__, max(select(sqlpp::value(7).as(sqlpp::alias::a))), "MAX((SELECT 7 AS a))");

View File

@ -32,13 +32,13 @@ int Min(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, min(bar.alpha), "MIN(tab_bar.alpha)");
compare(__LINE__, min(sqlpp::distinct, bar.alpha), "MIN(DISTINCT tab_bar.alpha)");
compare(__LINE__, min(bar.id), "MIN(tab_bar.id)");
compare(__LINE__, min(sqlpp::distinct, bar.id), "MIN(DISTINCT tab_bar.id)");
// Expression.
// Note that the inner parens aren't necessary.
compare(__LINE__, min(bar.alpha + 7), "MIN((tab_bar.alpha+7))");
compare(__LINE__, min(sqlpp::distinct, bar.alpha + 7), "MIN(DISTINCT (tab_bar.alpha+7))");
compare(__LINE__, min(bar.id + 7), "MIN((tab_bar.id+7))");
compare(__LINE__, min(sqlpp::distinct, bar.id + 7), "MIN(DISTINCT (tab_bar.id+7))");
// With sub select.
compare(__LINE__, min(select(sqlpp::value(7).as(sqlpp::alias::a))), "MIN((SELECT 7 AS a))");

View File

@ -35,24 +35,24 @@ int Operator(int, char* [])
const auto bar = test::TabBar{};
// Plus
compare(__LINE__, bar.alpha + 3u, "(tab_bar.alpha+3)");
compare(__LINE__, sqlpp::value(3) + foo.psi, "(3+tab_foo.psi)");
compare(__LINE__, bar.id + 3u, "(tab_bar.id+3)");
compare(__LINE__, sqlpp::value(3) + foo.uIntN, "(3+tab_foo.u_int_n)");
// Shift left
compare(__LINE__, sqlpp::value(3) << foo.psi, "(3<<tab_foo.psi)");
compare(__LINE__, bar.alpha << 3u, "(tab_bar.alpha<<3)");
compare(__LINE__, sqlpp::value(3) << foo.uIntN, "(3<<tab_foo.u_int_n)");
compare(__LINE__, bar.id << 3u, "(tab_bar.id<<3)");
// Shift right
compare(__LINE__, sqlpp::value(3) >> foo.psi, "(3>>tab_foo.psi)");
compare(__LINE__, bar.alpha >> 3u, "(tab_bar.alpha>>3)");
compare(__LINE__, sqlpp::value(3) >> foo.uIntN, "(3>>tab_foo.u_int_n)");
compare(__LINE__, bar.id >> 3u, "(tab_bar.id>>3)");
// Comparison
compare(__LINE__, bar.alpha < 3u, "(tab_bar.alpha<3)");
compare(__LINE__, bar.alpha <= 3u, "(tab_bar.alpha<=3)");
compare(__LINE__, bar.alpha == 3u, "(tab_bar.alpha=3)");
compare(__LINE__, bar.alpha != 3u, "(tab_bar.alpha<>3)");
compare(__LINE__, bar.alpha >= 3u, "(tab_bar.alpha>=3)");
compare(__LINE__, bar.alpha > 3u, "(tab_bar.alpha>3)");
compare(__LINE__, bar.id < 3u, "(tab_bar.id<3)");
compare(__LINE__, bar.id <= 3u, "(tab_bar.id<=3)");
compare(__LINE__, bar.id == 3u, "(tab_bar.id=3)");
compare(__LINE__, bar.id != 3u, "(tab_bar.id<>3)");
compare(__LINE__, bar.id >= 3u, "(tab_bar.id>=3)");
compare(__LINE__, bar.id > 3u, "(tab_bar.id>3)");
return 0;
}

View File

@ -33,18 +33,18 @@ int Over(int, char* []) {
auto const foo = test::TabFoo{};
// no/auto alias (wrapped in select so alias is applied)
compare(__LINE__, select(avg(foo.omega).over()), "SELECT AVG(tab_foo.omega) OVER() AS avg_");
compare(__LINE__, select(count(foo.omega).over()), "SELECT COUNT(tab_foo.omega) OVER() AS count_");
compare(__LINE__, select(max(foo.omega).over()), "SELECT MAX(tab_foo.omega) OVER() AS max_");
compare(__LINE__, select(min(foo.omega).over()), "SELECT MIN(tab_foo.omega) OVER() AS min_");
compare(__LINE__, select(sum(foo.omega).over()), "SELECT SUM(tab_foo.omega) OVER() AS sum_");
compare(__LINE__, select(avg(foo.doubleN).over()), "SELECT AVG(tab_foo.double_n) OVER() AS avg_");
compare(__LINE__, select(count(foo.doubleN).over()), "SELECT COUNT(tab_foo.double_n) OVER() AS count_");
compare(__LINE__, select(max(foo.doubleN).over()), "SELECT MAX(tab_foo.double_n) OVER() AS max_");
compare(__LINE__, select(min(foo.doubleN).over()), "SELECT MIN(tab_foo.double_n) OVER() AS min_");
compare(__LINE__, select(sum(foo.doubleN).over()), "SELECT SUM(tab_foo.double_n) OVER() AS sum_");
// alias
compare(__LINE__, avg(foo.omega).over().as(dueutil), "AVG(tab_foo.omega) OVER() AS dueutil");
compare(__LINE__, count(foo.omega).over().as(dueutil), "COUNT(tab_foo.omega) OVER() AS dueutil");
compare(__LINE__, max(foo.omega).over().as(dueutil), "MAX(tab_foo.omega) OVER() AS dueutil");
compare(__LINE__, min(foo.omega).over().as(dueutil), "MIN(tab_foo.omega) OVER() AS dueutil");
compare(__LINE__, sum(foo.omega).over().as(dueutil), "SUM(tab_foo.omega) OVER() AS dueutil");
compare(__LINE__, avg(foo.doubleN).over().as(dueutil), "AVG(tab_foo.double_n) OVER() AS dueutil");
compare(__LINE__, count(foo.doubleN).over().as(dueutil), "COUNT(tab_foo.double_n) OVER() AS dueutil");
compare(__LINE__, max(foo.doubleN).over().as(dueutil), "MAX(tab_foo.double_n) OVER() AS dueutil");
compare(__LINE__, min(foo.doubleN).over().as(dueutil), "MIN(tab_foo.double_n) OVER() AS dueutil");
compare(__LINE__, sum(foo.doubleN).over().as(dueutil), "SUM(tab_foo.double_n) OVER() AS dueutil");
return 0;
}

View File

@ -37,7 +37,7 @@ int SelectAs(int, char*[])
const auto bar = test::TabBar{};
// SELECT...AS as selectable column
compare(__LINE__, select(foo.omega, select(count(bar.alpha)).from(bar).unconditionally().as(cheese)), "SELECT tab_foo.omega,(SELECT COUNT(tab_bar.alpha) AS count_ FROM tab_bar) AS cheese");
compare(__LINE__, select(foo.doubleN, select(count(bar.id)).from(bar).unconditionally().as(cheese)), "SELECT tab_foo.double_n,(SELECT COUNT(tab_bar.id) AS count_ FROM tab_bar) AS cheese");
return 0;
}

View File

@ -33,25 +33,25 @@ int SelectColumns(int, char*[])
const auto bar = test::TabBar{};
// Single column
compare(__LINE__, select(foo.omega), "SELECT tab_foo.omega");
compare(__LINE__, select(foo.doubleN), "SELECT tab_foo.double_n");
// Two columns
compare(__LINE__, select(foo.omega, bar.alpha), "SELECT tab_foo.omega,tab_bar.alpha");
compare(__LINE__, select(foo.doubleN, bar.id), "SELECT tab_foo.double_n,tab_bar.id");
// All columns of a table
compare(__LINE__, select(all_of(foo)), "SELECT tab_foo.delta,tab_foo.epsilon,tab_foo.omega,tab_foo.psi,tab_foo.book");
compare(__LINE__, 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");
// All columns of a table plus one more
compare(__LINE__, select(all_of(foo), bar.alpha), "SELECT tab_foo.delta,tab_foo.epsilon,tab_foo.omega,tab_foo.psi,tab_foo.book,tab_bar.alpha");
compare(__LINE__, 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_bar.id");
// One more, plus all columns of a table
compare(__LINE__, select(bar.alpha, all_of(foo)), "SELECT tab_bar.alpha,tab_foo.delta,tab_foo.epsilon,tab_foo.omega,tab_foo.psi,tab_foo.book");
compare(__LINE__, 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");
// Column and aggregate function
compare(__LINE__, select(foo.omega, count(bar.alpha)), "SELECT tab_foo.omega,COUNT(tab_bar.alpha) AS count_");
compare(__LINE__, select(foo.doubleN, count(bar.id)), "SELECT tab_foo.double_n,COUNT(tab_bar.id) AS count_");
// Column aliases
compare(__LINE__, select(foo.omega.as(sqlpp::alias::o), count(bar.alpha).as(sqlpp::alias::a)), "SELECT tab_foo.omega AS o,COUNT(tab_bar.alpha) AS a");
compare(__LINE__, 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");
#warning: add optional column tests

View File

@ -33,14 +33,14 @@ int SelectFlags(int, char*[])
const auto bar = test::TabBar{};
// No flags
compare(__LINE__, select(foo.omega), "SELECT tab_foo.omega");
compare(__LINE__, select(foo.doubleN), "SELECT tab_foo.double_n");
// No flags
#warning: This should work
//compare(__LINE__, sqlpp::select_flags(), "");
// No flags
compare(__LINE__, select(foo.omega).flags(sqlpp::distinct), "SELECT DISTINCT tab_foo.omega");
compare(__LINE__, select(foo.doubleN).flags(sqlpp::distinct), "SELECT DISTINCT tab_foo.double_n");
// One flag
compare(__LINE__, select_flags(sqlpp::distinct), "DISTINCT ");

View File

@ -32,8 +32,8 @@ int Some(int, char* [])
const auto bar = test::TabBar{};
// With sub select.
compare(__LINE__, some(select(bar.alpha).from(bar).where(bar.alpha > 17)), "SOME(SELECT tab_bar.alpha FROM tab_bar WHERE (tab_bar.alpha>17))");
compare(__LINE__, bar.delta == some(select(bar.alpha).from(bar).where(bar.alpha > 17)), "(tab_bar.delta=SOME(SELECT tab_bar.alpha FROM tab_bar WHERE (tab_bar.alpha>17)))");
compare(__LINE__, some(select(bar.id).from(bar).where(bar.id > 17)), "SOME(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id>17))");
compare(__LINE__, bar.intN == some(select(bar.id).from(bar).where(bar.id > 17)), "(tab_bar.int_n=SOME(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id>17)))");
return 0;
}

View File

@ -32,13 +32,13 @@ int Sum(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, sum(bar.alpha), "SUM(tab_bar.alpha)");
compare(__LINE__, sum(sqlpp::distinct, bar.alpha), "SUM(DISTINCT tab_bar.alpha)");
compare(__LINE__, sum(bar.id), "SUM(tab_bar.id)");
compare(__LINE__, sum(sqlpp::distinct, bar.id), "SUM(DISTINCT tab_bar.id)");
// Expression.
// Note that the inner parens aren't necessary.
compare(__LINE__, sum(bar.alpha + 7), "SUM((tab_bar.alpha+7))");
compare(__LINE__, sum(sqlpp::distinct, bar.alpha + 7), "SUM(DISTINCT (tab_bar.alpha+7))");
compare(__LINE__, sum(bar.id + 7), "SUM((tab_bar.id+7))");
compare(__LINE__, sum(sqlpp::distinct, bar.id + 7), "SUM(DISTINCT (tab_bar.id+7))");
// With sub select.
compare(__LINE__, sum(select(sqlpp::value(7).as(sqlpp::alias::a))), "SUM((SELECT 7 AS a))");

View File

@ -38,13 +38,13 @@ int TableAlias(int, char* [])
// Individual values
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");
compare(__LINE__, select(foo.doubleN).from(foo).unconditionally().as(bar),
"(SELECT tab_foo.double_n FROM tab_foo) AS tab_bar");
// Table alias
const auto tab = foo.as(sample);
compare(__LINE__, select(tab.omega).from(tab).unconditionally(),
"SELECT sample.omega FROM tab_foo AS sample");
compare(__LINE__, select(tab.doubleN).from(tab).unconditionally(),
"SELECT sample.double_n FROM tab_foo AS sample");
return 0;
}

View File

@ -32,11 +32,11 @@ int Trim(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, trim(bar.beta), "TRIM(tab_bar.beta)");
compare(__LINE__, trim(bar.textN), "TRIM(tab_bar.text_n)");
// Expression.
// Note that the inner parens aren't necessary.
compare(__LINE__, trim(bar.beta + "suffix"), "TRIM((tab_bar.beta||'suffix'))");
compare(__LINE__, trim(bar.textN + "suffix"), "TRIM((tab_bar.text_n||'suffix'))");
// With sub select.
compare(__LINE__, trim(select(sqlpp::value("something").as(sqlpp::alias::a))), "TRIM((SELECT 'something' AS a))");

View File

@ -32,11 +32,11 @@ int Upper(int, char* [])
const auto bar = test::TabBar{};
// Single column.
compare(__LINE__, upper(bar.beta), "UPPER(tab_bar.beta)");
compare(__LINE__, upper(bar.textN), "UPPER(tab_bar.text_n)");
// Expression.
// Note that the inner parens aren't necessary.
compare(__LINE__, upper(bar.beta + "suffix"), "UPPER((tab_bar.beta||'suffix'))");
compare(__LINE__, upper(bar.textN + "suffix"), "UPPER((tab_bar.text_n||'suffix'))");
// With sub select.
compare(__LINE__, upper(select(sqlpp::value("something").as(sqlpp::alias::a))), "UPPER((SELECT 'something' AS a))");

View File

@ -50,30 +50,30 @@ 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__, select(foo.doubleN).from(foo).unconditionally(), "SELECT tab_foo.double_n 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__, update(foo).set(foo.doubleN = 42).unconditionally(), "UPDATE tab_foo SET double_n=42");
compare(__LINE__, update(foo).set(foo.doubleN = foo.doubleN - -1).unconditionally(),
"UPDATE tab_foo SET double_n=(tab_foo.double_n - -1)");
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.is_null()), " WHERE tab_bar.beta IS NULL");
compare(__LINE__, where(bar.beta == "SQL"), " WHERE (tab_bar.beta='SQL')");
compare(__LINE__, where(is_equal_to_or_null(bar.beta, ::sqlpp::value_or_null("SQL"))), " WHERE (tab_bar.beta='SQL')");
compare(__LINE__, where(is_equal_to_or_null(bar.beta, ::sqlpp::value_or_null<sqlpp::text>(::sqlpp::null))),
" WHERE tab_bar.beta IS NULL");
compare(__LINE__, where(bar.boolNn), " WHERE tab_bar.bool_nn");
compare(__LINE__, where(bar.boolNn == false), " WHERE (tab_bar.bool_nn=" + getFalse() + ")");
compare(__LINE__, where(bar.textN.is_null()), " WHERE tab_bar.text_n IS NULL");
compare(__LINE__, where(bar.textN == "SQL"), " WHERE (tab_bar.text_n='SQL')");
compare(__LINE__, where(is_equal_to_or_null(bar.textN, ::sqlpp::value_or_null("SQL"))), " WHERE (tab_bar.text_n='SQL')");
compare(__LINE__, where(is_equal_to_or_null(bar.textN, ::sqlpp::value_or_null<sqlpp::text>(::sqlpp::null))),
" WHERE tab_bar.text_n IS NULL");
// string argument
compare(__LINE__, where(bar.beta == std::string("SQL")), " WHERE (tab_bar.beta='SQL')");
compare(__LINE__, where(bar.textN == std::string("SQL")), " WHERE (tab_bar.text_n='SQL')");
// string_view argument
compare(__LINE__, where(bar.beta == sqlpp::compat::string_view("SQL")), " WHERE (tab_bar.beta='SQL')");
compare(__LINE__, where(bar.textN == sqlpp::compat::string_view("SQL")), " WHERE (tab_bar.text_n='SQL')");
return 0;
}

View File

@ -61,8 +61,8 @@ namespace
void no_group_by()
{
static_run_check<sqlpp::consistent_t>(select(all_of(t)).from(t).unconditionally());
static_run_check<sqlpp::consistent_t>(select(t.alpha).from(t).unconditionally());
static_run_check<sqlpp::consistent_t>(select(count(t.alpha)).from(t).unconditionally());
static_run_check<sqlpp::consistent_t>(select(t.id).from(t).unconditionally());
static_run_check<sqlpp::consistent_t>(select(count(t.id)).from(t).unconditionally());
}
// If there is a dynamic group_by, we can still select whatever we want
@ -70,53 +70,53 @@ namespace
void dynamic_group_by()
{
static_run_check<sqlpp::consistent_t>(select(all_of(t)).from(t).unconditionally());
static_run_check<sqlpp::consistent_t>(select(t.alpha).from(t).unconditionally());
static_run_check<sqlpp::consistent_t>(select(count(t.alpha)).from(t).unconditionally());
static_run_check<sqlpp::consistent_t>(select(t.id).from(t).unconditionally());
static_run_check<sqlpp::consistent_t>(select(count(t.id)).from(t).unconditionally());
}
// If there is a static group_by, selected columns must be made of group_by expressions, or aggregate expression (e.g.
// count(t.id)) or values to be valid
void static_group_by_ok()
{
static_run_check<sqlpp::consistent_t>(select(t.alpha).from(t).unconditionally().group_by(t.alpha));
static_run_check<sqlpp::consistent_t>(select(t.id).from(t).unconditionally().group_by(t.id));
static_run_check<sqlpp::consistent_t>(
select((t.alpha + 42).as(whatever)).from(t).unconditionally().group_by(t.alpha));
select((t.id + 42).as(whatever)).from(t).unconditionally().group_by(t.id));
static_run_check<sqlpp::consistent_t>(
select((t.alpha + 42).as(whatever)).from(t).unconditionally().group_by(t.alpha, t.alpha + t.delta * 17));
static_run_check<sqlpp::consistent_t>(select((t.alpha + t.delta * 17).as(whatever))
select((t.id + 42).as(whatever)).from(t).unconditionally().group_by(t.id, t.id + t.intN * 17));
static_run_check<sqlpp::consistent_t>(select((t.id + t.intN * 17).as(whatever))
.from(t)
.unconditionally()
.group_by(t.alpha, t.alpha + t.delta * 17));
.group_by(t.id, t.id + t.intN * 17));
static_run_check<sqlpp::consistent_t>(
select((t.beta + "fortytwo").as(whatever)).from(t).unconditionally().group_by(t.beta));
select((t.textN + "fortytwo").as(whatever)).from(t).unconditionally().group_by(t.textN));
static_run_check<sqlpp::consistent_t>(select(avg(t.alpha)).from(t).unconditionally().group_by(t.beta));
static_run_check<sqlpp::consistent_t>(select(count(t.alpha)).from(t).unconditionally().group_by(t.beta));
static_run_check<sqlpp::consistent_t>(select(max(t.alpha)).from(t).unconditionally().group_by(t.beta));
static_run_check<sqlpp::consistent_t>(select(min(t.alpha)).from(t).unconditionally().group_by(t.beta));
static_run_check<sqlpp::consistent_t>(select(sum(t.alpha)).from(t).unconditionally().group_by(t.beta));
static_run_check<sqlpp::consistent_t>(select(avg(t.id)).from(t).unconditionally().group_by(t.textN));
static_run_check<sqlpp::consistent_t>(select(count(t.id)).from(t).unconditionally().group_by(t.textN));
static_run_check<sqlpp::consistent_t>(select(max(t.id)).from(t).unconditionally().group_by(t.textN));
static_run_check<sqlpp::consistent_t>(select(min(t.id)).from(t).unconditionally().group_by(t.textN));
static_run_check<sqlpp::consistent_t>(select(sum(t.id)).from(t).unconditionally().group_by(t.textN));
static_run_check<sqlpp::consistent_t>(
select((t.alpha + count(t.delta)).as(whatever)).from(t).unconditionally().group_by(t.alpha));
select((t.id + count(t.intN)).as(whatever)).from(t).unconditionally().group_by(t.id));
static_run_check<sqlpp::consistent_t>(
select(sqlpp::value(1).as(whatever)).from(t).unconditionally().group_by(t.alpha));
select(sqlpp::value(1).as(whatever)).from(t).unconditionally().group_by(t.id));
static_run_check<sqlpp::consistent_t>(
select(sqlpp::value("whatever").as(whatever)).from(t).unconditionally().group_by(t.alpha));
select(sqlpp::value("whatever").as(whatever)).from(t).unconditionally().group_by(t.id));
}
// Failures with static group_by and selected non-aggregates or incorrect aggregates
void static_group_by_nok()
{
static_run_check<sqlpp::assert_no_unknown_aggregates_t>(select(t.beta).from(t).unconditionally().group_by(t.alpha));
static_run_check<sqlpp::assert_no_unknown_aggregates_t>(select(t.textN).from(t).unconditionally().group_by(t.id));
static_run_check<sqlpp::assert_no_aggregate_mix_t>(
select(t.alpha, t.delta).from(t).unconditionally().group_by(t.alpha));
select(t.id, t.intN).from(t).unconditionally().group_by(t.id));
static_run_check<sqlpp::assert_no_aggregate_mix_t>(
select(t.alpha, t.beta).from(t).unconditionally().group_by(t.alpha));
select(t.id, t.textN).from(t).unconditionally().group_by(t.id));
static_run_check<sqlpp::assert_no_aggregate_mix_t>(
select((t.alpha + t.delta).as(whatever)).from(t).unconditionally().group_by(t.alpha));
select((t.id + t.intN).as(whatever)).from(t).unconditionally().group_by(t.id));
static_run_check<sqlpp::assert_no_aggregate_mix_t>(
select((t.alpha + t.delta).as(whatever)).from(t).unconditionally().group_by(t.alpha, t.alpha + t.delta * 17));
select((t.id + t.intN).as(whatever)).from(t).unconditionally().group_by(t.id, t.id + t.intN * 17));
}
}

View File

@ -88,15 +88,15 @@ namespace
void when()
{
// OK
when_check<sqlpp::consistent_t>(t.gamma);
when_check<sqlpp::consistent_t>(t.gamma == true);
when_check<sqlpp::consistent_t>(count(t.alpha) > 0);
when_check<sqlpp::consistent_t>(t.boolNn);
when_check<sqlpp::consistent_t>(t.boolNn == true);
when_check<sqlpp::consistent_t>(count(t.id) > 0);
// Try assignment as "when"
when_check<sqlpp::assert_case_when_boolean_expression_t>(t.gamma = true);
when_check<sqlpp::assert_case_when_boolean_expression_t>(t.boolNn = true);
// Try non-boolean expression as "when"
when_check<sqlpp::assert_case_when_boolean_expression_t>(t.alpha);
when_check<sqlpp::assert_case_when_boolean_expression_t>(t.id);
// Try some other types as "when"
when_check<sqlpp::assert_case_when_boolean_expression_t>("true");
@ -108,46 +108,46 @@ namespace
when_check<sqlpp::assert_case_when_boolean_expression_t>(t);
// Try to use an alias as "when"
when_check<sqlpp::assert_case_when_boolean_expression_t>(t.gamma.as(t.beta));
when_check<sqlpp::assert_case_when_boolean_expression_t>(t.boolNn.as(t.textN));
}
void then()
{
// OK
then_check<sqlpp::consistent_t>(t.gamma, t.gamma);
then_check<sqlpp::consistent_t>(t.gamma, t.gamma == true);
then_check<sqlpp::consistent_t>(t.gamma, count(t.alpha) > 0);
then_check<sqlpp::consistent_t>(t.gamma, t.alpha);
then_check<sqlpp::consistent_t>(t.gamma, "true");
then_check<sqlpp::consistent_t>(t.gamma, 42);
then_check<sqlpp::consistent_t>(t.gamma, 'c');
then_check<sqlpp::consistent_t>(t.gamma, nullptr);
then_check<sqlpp::consistent_t>(t.boolNn, t.boolNn);
then_check<sqlpp::consistent_t>(t.boolNn, t.boolNn == true);
then_check<sqlpp::consistent_t>(t.boolNn, count(t.id) > 0);
then_check<sqlpp::consistent_t>(t.boolNn, t.id);
then_check<sqlpp::consistent_t>(t.boolNn, "true");
then_check<sqlpp::consistent_t>(t.boolNn, 42);
then_check<sqlpp::consistent_t>(t.boolNn, 'c');
then_check<sqlpp::consistent_t>(t.boolNn, nullptr);
// Try to use an assignment as "then"
then_check<sqlpp::assert_case_then_expression_t>(t.gamma, t.gamma = true);
then_check<sqlpp::assert_case_then_expression_t>(t.boolNn, t.boolNn = true);
// Try to use a table as "then"
then_check<sqlpp::assert_case_then_expression_t>(t.gamma, t);
then_check<sqlpp::assert_case_then_expression_t>(t.boolNn, t);
// Try to use an alias as "then"
then_check<sqlpp::assert_case_then_expression_t>(t.gamma, t.alpha.as(t.beta));
then_check<sqlpp::assert_case_then_expression_t>(t.boolNn, t.id.as(t.textN));
}
void else_()
{
// OK
else_check<sqlpp::consistent_t>(t.gamma, t.gamma, t.gamma);
else_check<sqlpp::consistent_t>(t.gamma, t.alpha, 42);
else_check<sqlpp::consistent_t>(t.gamma, t.beta, "twentyseven");
else_check<sqlpp::consistent_t>(t.boolNn, t.boolNn, t.boolNn);
else_check<sqlpp::consistent_t>(t.boolNn, t.id, 42);
else_check<sqlpp::consistent_t>(t.boolNn, t.textN, "twentyseven");
// Try to use an assignment as "else"
else_check<sqlpp::assert_case_else_expression_t>(t.gamma, t.alpha, t.alpha = 7);
else_check<sqlpp::assert_case_else_expression_t>(t.boolNn, t.id, t.id = 7);
// Try to use a table as "else"
else_check<sqlpp::assert_case_else_expression_t>(t.gamma, t.alpha, t);
else_check<sqlpp::assert_case_else_expression_t>(t.boolNn, t.id, t);
// Try to use an alias as "else"
else_check<sqlpp::assert_case_else_expression_t>(t.gamma, t.alpha, t.alpha.as(t.beta));
else_check<sqlpp::assert_case_else_expression_t>(t.boolNn, t.id, t.id.as(t.textN));
}
}

View File

@ -52,7 +52,7 @@ namespace
print_type_on_error<CheckResult>(ExpectedCheckResult{});
static_assert(ExpectedCheckResult::value, "Unexpected check result");
using ReturnType = decltype(select(t.alpha).from(expression));
using ReturnType = decltype(select(t.id).from(expression));
using ExpectedReturnType = sqlpp::logic::all_t<Assert::value xor std::is_same<ReturnType, Assert>::value>;
print_type_on_error<ReturnType>(ExpectedReturnType{});
static_assert(ExpectedReturnType::value, "Unexpected return type");
@ -63,14 +63,14 @@ namespace
// OK
from_static_check<sqlpp::consistent_t>(t);
from_static_check<sqlpp::consistent_t>(t.cross_join(f));
from_static_check<sqlpp::consistent_t>(t.join(f).on(t.alpha > f.omega));
from_static_check<sqlpp::consistent_t>(t.join(f).on(t.id > f.doubleN));
// Try a bunch of non-tables
from_static_check<sqlpp::assert_from_table_t>(7);
from_static_check<sqlpp::assert_from_table_t>(t.alpha);
from_static_check<sqlpp::assert_from_table_t>(t.beta);
from_static_check<sqlpp::assert_from_table_t>(t.gamma);
from_static_check<sqlpp::assert_from_table_t>(t.delta);
from_static_check<sqlpp::assert_from_table_t>(t.id);
from_static_check<sqlpp::assert_from_table_t>(t.textN);
from_static_check<sqlpp::assert_from_table_t>(t.boolNn);
from_static_check<sqlpp::assert_from_table_t>(t.intN);
// Try cross joins (missing condition)
from_static_check<sqlpp::assert_from_not_pre_join_t>(t.join(f));

View File

@ -52,7 +52,7 @@ namespace
print_type_on_error<CheckResult>(ExpectedCheckResult{});
static_assert(ExpectedCheckResult::value, "Unexpected check result");
using ReturnType = decltype(select(all_of(t)).from(t).unconditionally().group_by(t.alpha).having(expression));
using ReturnType = decltype(select(all_of(t)).from(t).unconditionally().group_by(t.id).having(expression));
using ExpectedReturnType = sqlpp::logic::all_t<Assert::value xor std::is_same<ReturnType, Assert>::value>;
print_type_on_error<ReturnType>(ExpectedReturnType{});
static_assert(ExpectedReturnType::value, "Unexpected return type");
@ -61,19 +61,19 @@ namespace
auto static_having() -> void
{
// OK
having_static_check<sqlpp::consistent_t>(t.gamma);
having_static_check<sqlpp::consistent_t>(t.gamma == true);
having_static_check<sqlpp::consistent_t>(t.boolNn);
having_static_check<sqlpp::consistent_t>(t.boolNn == true);
// OK using aggregate functions in having
having_static_check<sqlpp::consistent_t>(count(t.alpha) > 0);
having_static_check<sqlpp::consistent_t>(t.gamma and count(t.alpha) > 0);
having_static_check<sqlpp::consistent_t>(case_when(count(t.alpha) > 0).then(t.gamma).else_(not t.gamma));
having_static_check<sqlpp::consistent_t>(count(t.id) > 0);
having_static_check<sqlpp::consistent_t>(t.boolNn and count(t.id) > 0);
having_static_check<sqlpp::consistent_t>(case_when(count(t.id) > 0).then(t.boolNn).else_(not t.boolNn));
// Try assignment as condition
having_static_check<sqlpp::assert_having_boolean_expression_t>(t.gamma = true);
having_static_check<sqlpp::assert_having_boolean_expression_t>(t.boolNn = true);
// Try non-boolean expression
having_static_check<sqlpp::assert_having_boolean_expression_t>(t.alpha);
having_static_check<sqlpp::assert_having_boolean_expression_t>(t.id);
// Try builtin bool
having_static_check<sqlpp::assert_having_not_cpp_bool_t>(true);
@ -84,7 +84,7 @@ namespace
having_static_check<sqlpp::assert_having_boolean_expression_t>(17);
having_static_check<sqlpp::assert_having_boolean_expression_t>('c');
having_static_check<sqlpp::assert_having_boolean_expression_t>(nullptr);
having_static_check<sqlpp::assert_having_boolean_expression_t>(t.alpha.as(t.beta));
having_static_check<sqlpp::assert_having_boolean_expression_t>(t.id.as(t.textN));
}
template <typename Assert, typename Statement, typename HavingCondition>
@ -101,31 +101,31 @@ namespace
const auto select_without_group_by = select(all_of(t)).from(t).unconditionally();
// OK
static_consistency_check<sqlpp::consistent_t>(select_without_group_by, avg(t.alpha) > 17);
static_consistency_check<sqlpp::consistent_t>(select_without_group_by, avg(t.alpha) > parameter(t.alpha));
static_consistency_check<sqlpp::consistent_t>(select_without_group_by, avg(t.id) > 17);
static_consistency_check<sqlpp::consistent_t>(select_without_group_by, avg(t.id) > parameter(t.id));
// Try non aggregate
static_consistency_check<sqlpp::assert_having_all_aggregates_t>(select_without_group_by, t.alpha > 17);
static_consistency_check<sqlpp::assert_having_all_aggregates_t>(select_without_group_by, t.id > 17);
static_consistency_check<sqlpp::assert_having_all_aggregates_t>(select_without_group_by,
count(t.alpha) > 3 and t.alpha > 17);
count(t.id) > 3 and t.id > 17);
// Try foreign table
static_consistency_check<sqlpp::assert_having_no_unknown_tables_t>(select_without_group_by, f.omega > 17);
static_consistency_check<sqlpp::assert_having_no_unknown_tables_t>(select_without_group_by, f.doubleN > 17);
const auto select_with_group_by = select(t.alpha).from(t).unconditionally().group_by(t.alpha);
const auto select_with_group_by = select(t.id).from(t).unconditionally().group_by(t.id);
// OK
static_consistency_check<sqlpp::consistent_t>(select_with_group_by, avg(t.alpha) > 17);
static_consistency_check<sqlpp::consistent_t>(select_with_group_by, t.alpha > 17);
static_consistency_check<sqlpp::consistent_t>(select_with_group_by, count(t.alpha) > 3 and t.alpha > 17);
static_consistency_check<sqlpp::consistent_t>(select_with_group_by, avg(t.id) > 17);
static_consistency_check<sqlpp::consistent_t>(select_with_group_by, t.id > 17);
static_consistency_check<sqlpp::consistent_t>(select_with_group_by, count(t.id) > 3 and t.id > 17);
// Try non aggregate
static_consistency_check<sqlpp::assert_having_all_aggregates_t>(select_with_group_by, t.beta > "17");
static_consistency_check<sqlpp::assert_having_all_aggregates_t>(select_with_group_by, t.textN > "17");
static_consistency_check<sqlpp::assert_having_all_aggregates_t>(select_with_group_by,
count(t.beta) > 3 and t.beta > "17");
count(t.textN) > 3 and t.textN > "17");
// Try foreign table
static_consistency_check<sqlpp::assert_having_no_unknown_tables_t>(select_with_group_by, f.omega > 17);
static_consistency_check<sqlpp::assert_having_no_unknown_tables_t>(select_with_group_by, f.doubleN > 17);
}
}

View File

@ -58,44 +58,44 @@ namespace
static_assert(ExpectedReturnType::value, "Unexpected return type");
}
// column alpha is not allowed, column gamma is required
// column id is not allowed, column boolNn is required
void static_set()
{
// OK
set_static_check<sqlpp::consistent_t>(t.gamma = true);
set_static_check<sqlpp::consistent_t>(t.beta = "fortytwo", t.gamma = true);
set_static_check<sqlpp::consistent_t>(t.beta = "fortytwo", t.gamma = true, t.delta = 42);
set_static_check<sqlpp::consistent_t>(t.delta = 42, t.beta = "fortytwo", t.gamma = true);
set_static_check<sqlpp::consistent_t>(t.delta = 42, t.gamma = true, t.beta = "fortytwo");
set_static_check<sqlpp::consistent_t>(t.gamma = true, t.delta = 42, t.beta = "fortytwo");
set_static_check<sqlpp::consistent_t>(t.boolNn = true);
set_static_check<sqlpp::consistent_t>(t.textN = "fortytwo", t.boolNn = true);
set_static_check<sqlpp::consistent_t>(t.textN = "fortytwo", t.boolNn = true, t.intN = 42);
set_static_check<sqlpp::consistent_t>(t.intN = 42, t.textN = "fortytwo", t.boolNn = true);
set_static_check<sqlpp::consistent_t>(t.intN = 42, t.boolNn = true, t.textN = "fortytwo");
set_static_check<sqlpp::consistent_t>(t.boolNn = true, t.intN = 42, t.textN = "fortytwo");
// Try setting alpha
set_static_check<sqlpp::assert_insert_set_allowed_t>(t.alpha = 17, t.beta = "whatever");
set_static_check<sqlpp::assert_insert_set_allowed_t>(t.beta = "whatever", t.alpha = 17);
// Try setting id
set_static_check<sqlpp::assert_insert_set_allowed_t>(t.id = 17, t.textN = "whatever");
set_static_check<sqlpp::assert_insert_set_allowed_t>(t.textN = "whatever", t.id = 17);
// Try omitting gamma
set_static_check<sqlpp::assert_insert_static_set_all_required_t>(t.delta = 42);
set_static_check<sqlpp::assert_insert_static_set_all_required_t>(t.beta = "whatever");
// Try omitting boolNn
set_static_check<sqlpp::assert_insert_static_set_all_required_t>(t.intN = 42);
set_static_check<sqlpp::assert_insert_static_set_all_required_t>(t.textN = "whatever");
// Try no arguments
set_static_check<sqlpp::assert_insert_static_set_count_args_t>();
// Try none-assignment arguments
set_static_check<sqlpp::assert_insert_set_assignments_t>(t.delta == 42, t.delta = 42, t.beta = "fortytwo",
t.gamma = true);
set_static_check<sqlpp::assert_insert_set_assignments_t>(17, t.delta = 42, t.beta = "fortytwo", t.gamma = true);
set_static_check<sqlpp::assert_insert_set_assignments_t>(t.delta = 42, t.beta = "fortytwo", t.gamma = true, "EEEK");
set_static_check<sqlpp::assert_insert_set_assignments_t>(t.intN == 42, t.intN = 42, t.textN = "fortytwo",
t.boolNn = true);
set_static_check<sqlpp::assert_insert_set_assignments_t>(17, t.intN = 42, t.textN = "fortytwo", t.boolNn = true);
set_static_check<sqlpp::assert_insert_set_assignments_t>(t.intN = 42, t.textN = "fortytwo", t.boolNn = true, "EEEK");
// Try duplicates
set_static_check<sqlpp::assert_insert_set_no_duplicates_t>(t.delta = 41, t.delta = 42, t.beta = "fortytwo",
t.gamma = true);
set_static_check<sqlpp::assert_insert_set_no_duplicates_t>(t.beta = "fortyone", t.delta = 41, t.beta = "fortytwo",
t.gamma = true);
set_static_check<sqlpp::assert_insert_set_no_duplicates_t>(t.gamma = false, t.delta = 41, t.beta = "fortytwo",
t.gamma = true);
set_static_check<sqlpp::assert_insert_set_no_duplicates_t>(t.intN = 41, t.intN = 42, t.textN = "fortytwo",
t.boolNn = true);
set_static_check<sqlpp::assert_insert_set_no_duplicates_t>(t.textN = "fortyone", t.intN = 41, t.textN = "fortytwo",
t.boolNn = true);
set_static_check<sqlpp::assert_insert_set_no_duplicates_t>(t.boolNn = false, t.intN = 41, t.textN = "fortytwo",
t.boolNn = true);
// Try multiple tables
set_static_check<sqlpp::assert_insert_set_single_table_t>(f.omega = 41, t.gamma = true);
set_static_check<sqlpp::assert_insert_set_single_table_t>(f.doubleN = 41, t.boolNn = true);
}
}

View File

@ -117,16 +117,16 @@ namespace
// Try a bunch of non-tables
join_static_check<sqlpp::assert_pre_join_rhs_table_t>(t, 7);
join_static_check<sqlpp::assert_pre_join_rhs_table_t>(t, t.alpha);
join_static_check<sqlpp::assert_pre_join_rhs_table_t>(t, t.beta);
join_static_check<sqlpp::assert_pre_join_rhs_table_t>(t, t.gamma);
join_static_check<sqlpp::assert_pre_join_rhs_table_t>(t, t.delta);
join_static_check<sqlpp::assert_pre_join_rhs_table_t>(t, t.id);
join_static_check<sqlpp::assert_pre_join_rhs_table_t>(t, t.textN);
join_static_check<sqlpp::assert_pre_join_rhs_table_t>(t, t.boolNn);
join_static_check<sqlpp::assert_pre_join_rhs_table_t>(t, t.intN);
join_static_check<sqlpp::assert_pre_join_lhs_table_t>(7, t);
join_static_check<sqlpp::assert_pre_join_lhs_table_t>(t.alpha, t);
join_static_check<sqlpp::assert_pre_join_lhs_table_t>(t.beta, t);
join_static_check<sqlpp::assert_pre_join_lhs_table_t>(t.gamma, t);
join_static_check<sqlpp::assert_pre_join_lhs_table_t>(t.delta, t);
join_static_check<sqlpp::assert_pre_join_lhs_table_t>(t.id, t);
join_static_check<sqlpp::assert_pre_join_lhs_table_t>(t.textN, t);
join_static_check<sqlpp::assert_pre_join_lhs_table_t>(t.boolNn, t);
join_static_check<sqlpp::assert_pre_join_lhs_table_t>(t.intN, t);
// Try to join with join (rhs)
join_static_check<sqlpp::assert_pre_join_rhs_no_join_t>(t, j);
@ -151,11 +151,11 @@ namespace
const auto f_f = join(fa, fb);
// OK join.on()
on_static_check<sqlpp::consistent_t>(t_f, t.alpha > f.omega);
on_static_check<sqlpp::consistent_t>(f_t, t.alpha < f.omega);
on_static_check<sqlpp::consistent_t>(f_f, fa.omega == fb.omega);
on_static_check<sqlpp::consistent_t>(t_t, ta.alpha == tb.alpha);
on_static_check<sqlpp::consistent_t>(t_f, t.gamma);
on_static_check<sqlpp::consistent_t>(t_f, t.id > f.doubleN);
on_static_check<sqlpp::consistent_t>(f_t, t.id < f.doubleN);
on_static_check<sqlpp::consistent_t>(f_f, fa.doubleN == fb.doubleN);
on_static_check<sqlpp::consistent_t>(t_t, ta.id == tb.id);
on_static_check<sqlpp::consistent_t>(t_f, t.boolNn);
// Try join.on(non-expression)
on_static_check<sqlpp::assert_on_is_expression_t>(t_f, true);
@ -163,14 +163,14 @@ namespace
on_static_check<sqlpp::assert_on_is_expression_t>(t_f, t);
// Try join.on(non-boolean)
on_static_check<sqlpp::assert_on_is_boolean_expression_t>(t_f, t.alpha);
on_static_check<sqlpp::assert_on_is_boolean_expression_t>(t_f, t.beta);
on_static_check<sqlpp::assert_on_is_boolean_expression_t>(t_f, f.omega);
on_static_check<sqlpp::assert_on_is_boolean_expression_t>(t_f, t.id);
on_static_check<sqlpp::assert_on_is_boolean_expression_t>(t_f, t.textN);
on_static_check<sqlpp::assert_on_is_boolean_expression_t>(t_f, f.doubleN);
// Try join.on(foreign-table)
on_static_check<sqlpp::assert_join_on_no_foreign_table_dependencies_t>(t_f, ta.alpha != 0);
on_static_check<sqlpp::assert_join_on_no_foreign_table_dependencies_t>(t_t, t.gamma);
on_static_check<sqlpp::assert_join_on_no_foreign_table_dependencies_t>(f_f, f.omega > fa.omega);
on_static_check<sqlpp::assert_join_on_no_foreign_table_dependencies_t>(t_f, ta.id != 0);
on_static_check<sqlpp::assert_join_on_no_foreign_table_dependencies_t>(t_t, t.boolNn);
on_static_check<sqlpp::assert_join_on_no_foreign_table_dependencies_t>(f_f, f.doubleN > fa.doubleN);
}
}

View File

@ -89,20 +89,20 @@ namespace
void boolean()
{
and_check<sqlpp::consistent_t>(t.gamma, t.gamma);
and_check<sqlpp::assert_valid_operands>(t.gamma, true);
// and_check<sqlpp::assert_valid_operands>(true, t.gamma); // Cannot currently do that
and_check<sqlpp::consistent_t>(t.boolNn, t.boolNn);
and_check<sqlpp::assert_valid_operands>(t.boolNn, true);
// and_check<sqlpp::assert_valid_operands>(true, t.boolNn); // Cannot currently do that
or_check<sqlpp::consistent_t>(t.gamma, t.gamma);
or_check<sqlpp::assert_valid_operands>(t.gamma, true);
// or_check<sqlpp::assert_valid_operands>(true, t.gamma); // Cannot currently do that
or_check<sqlpp::consistent_t>(t.boolNn, t.boolNn);
or_check<sqlpp::assert_valid_operands>(t.boolNn, true);
// or_check<sqlpp::assert_valid_operands>(true, t.boolNn); // Cannot currently do that
not_check<sqlpp::consistent_t>(t.gamma);
not_check<sqlpp::consistent_t>(t.boolNn);
}
void where()
{
where_check<sqlpp::consistent_t>(t.gamma);
where_check<sqlpp::consistent_t>(t.boolNn);
where_check<sqlpp::assert_where_arg_is_not_cpp_bool_t>(true);
}
}

View File

@ -61,24 +61,24 @@ namespace
void static_update_set()
{
// OK
update_set_static_check<sqlpp::consistent_t>(t.gamma = true);
update_set_static_check<sqlpp::consistent_t>(t.gamma = true, t.beta = "");
update_set_static_check<sqlpp::consistent_t>(t.boolNn = true);
update_set_static_check<sqlpp::consistent_t>(t.boolNn = true, t.textN = "");
// Try to update nothing
update_set_static_check<sqlpp::assert_update_set_count_args_t>();
// Try condition as assignment
update_set_static_check<sqlpp::assert_update_set_assignments_t>(t.gamma == true);
update_set_static_check<sqlpp::assert_update_set_assignments_t>(t.boolNn == true);
// Try duplicate columns
update_set_static_check<sqlpp::assert_update_set_no_duplicates_t>(t.gamma = true, t.gamma = false);
update_set_static_check<sqlpp::assert_update_set_no_duplicates_t>(t.gamma = true, t.beta = "", t.gamma = false);
update_set_static_check<sqlpp::assert_update_set_no_duplicates_t>(t.boolNn = true, t.boolNn = false);
update_set_static_check<sqlpp::assert_update_set_no_duplicates_t>(t.boolNn = true, t.textN = "", t.boolNn = false);
// Try to update prohibited columns
update_set_static_check<sqlpp::assert_update_set_allowed_t>(t.alpha = 42);
update_set_static_check<sqlpp::assert_update_set_allowed_t>(t.id = 42);
// Try to update multiple tables at once
update_set_static_check<sqlpp::assert_update_set_single_table_t>(t.gamma = true, f.omega = 7);
update_set_static_check<sqlpp::assert_update_set_single_table_t>(t.boolNn = true, f.doubleN = 7);
}
}

View File

@ -60,14 +60,14 @@ namespace
void static_where()
{
// OK
where_static_check<sqlpp::consistent_t>(t.gamma);
where_static_check<sqlpp::consistent_t>(t.gamma == true);
where_static_check<sqlpp::consistent_t>(t.boolNn);
where_static_check<sqlpp::consistent_t>(t.boolNn == true);
// Try assignment as condition
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.gamma = true);
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.boolNn = true);
// Try non-boolean expression
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.alpha);
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.id);
// Try builtin bool
where_static_check<sqlpp::assert_where_arg_is_not_cpp_bool_t>(true);
@ -78,13 +78,13 @@ namespace
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(17);
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>('c');
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(nullptr);
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.alpha.as(t.beta));
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.id.as(t.textN));
// Try using aggregate functions in where
where_static_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(count(t.alpha) > 0);
where_static_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(t.gamma and count(t.alpha) > 0);
where_static_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(count(t.id) > 0);
where_static_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(t.boolNn and count(t.id) > 0);
where_static_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(
case_when(count(t.alpha) > 0).then(t.gamma).else_(not t.gamma));
case_when(count(t.id) > 0).then(t.boolNn).else_(not t.boolNn));
}
}

View File

@ -34,10 +34,10 @@ namespace
constexpr auto bar = test::TabBar{};
constexpr auto foo = test::TabFoo{};
static_assert(sqlpp::can_be_null_t<decltype(bar.alpha)>::value, "");
static_assert(sqlpp::can_be_null_t<decltype(foo.omega)>::value, "");
static_assert(not sqlpp::can_be_null_t<decltype(foo.delta)>::value, "");
static_assert(not sqlpp::can_be_null_t<decltype(bar.gamma)>::value, "");
static_assert(not sqlpp::can_be_null_t<decltype(bar.id)>::value, "");
static_assert(sqlpp::can_be_null_t<decltype(foo.doubleN)>::value, "");
static_assert(not sqlpp::can_be_null_t<decltype(foo.textNnD)>::value, "");
static_assert(not sqlpp::can_be_null_t<decltype(bar.boolNn)>::value, "");
const auto seven = sqlpp::value(7).as(sqlpp::alias::s);
static_assert(not sqlpp::can_be_null_t<decltype(seven)>::value, "");
@ -47,10 +47,10 @@ namespace
{
{
// result fields are as nullable as the expressions they represent
const auto rows = db(select(bar.alpha, bar.gamma, seven).from(bar).unconditionally());
const auto rows = db(select(bar.id, bar.boolNn, seven).from(bar).unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "");
static_assert(not is_optional<decltype(x.gamma)>::value, "");
static_assert(not is_optional<decltype(x.id)>::value, "");
static_assert(not is_optional<decltype(x.boolNn)>::value, "");
static_assert(not is_optional<decltype(x.s)>::value, "");
}
}
@ -59,29 +59,29 @@ namespace
{
// Join
{
const auto rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(foo.join(bar).on(foo.omega > bar.alpha))
const auto rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(foo.join(bar).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.delta)>::value, "left side of (inner) join cannot be null");
static_assert(not is_optional<decltype(x.gamma)>::value, "right side of (inner) join cannot be null");
static_assert(not is_optional<decltype(x.id)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.textNnD)>::value, "left side of (inner) join cannot be null");
static_assert(not is_optional<decltype(x.boolNn)>::value, "right side of (inner) join cannot be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
{
const auto& rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(bar.join(foo).on(foo.omega > bar.alpha))
const auto& rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(bar.join(foo).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.gamma)>::value, "left side of (inner) join cannot be null");
static_assert(not is_optional<decltype(x.delta)>::value, "right side of (inner) join cannot be null");
static_assert(not is_optional<decltype(x.id)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.boolNn)>::value, "left side of (inner) join cannot be null");
static_assert(not is_optional<decltype(x.textNnD)>::value, "right side of (inner) join cannot be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
{
MockSizeDb db2;
auto&& result = db2(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(bar.join(foo).on(foo.omega > bar.alpha))
auto&& result = db2(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(bar.join(foo).on(foo.doubleN > bar.id))
.unconditionally());
result.size();
static_assert(std::is_same<size_t, decltype(result.size())>::value, "MockSizeDb size() isn't size_t");
@ -89,111 +89,111 @@ namespace
// Inner join
{
const auto rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(foo.inner_join(bar).on(foo.omega > bar.alpha))
const auto rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(foo.inner_join(bar).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.delta)>::value, "left side of inner join cannot be null");
static_assert(not is_optional<decltype(x.gamma)>::value, "right side of inner join cannot be null");
static_assert(not is_optional<decltype(x.id)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.textNnD)>::value, "left side of inner join cannot be null");
static_assert(not is_optional<decltype(x.boolNn)>::value, "right side of inner join cannot be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
{
const auto rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(bar.inner_join(foo).on(foo.omega > bar.alpha))
const auto rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(bar.inner_join(foo).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.gamma)>::value, "left side of inner join cannot be null");
static_assert(not is_optional<decltype(x.delta)>::value, "right side of inner join cannot be null");
static_assert(not is_optional<decltype(x.id)>::value, "primary key cannot be null");
static_assert(not is_optional<decltype(x.boolNn)>::value, "left side of inner join cannot be null");
static_assert(not is_optional<decltype(x.textNnD)>::value, "right side of inner join cannot be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
// Left outer join
{
const auto rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(foo.left_outer_join(bar).on(foo.omega > bar.alpha))
const auto rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(foo.left_outer_join(bar).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.delta)>::value, "left side of left outer join cannot be null");
static_assert(is_optional<decltype(x.gamma)>::value, "right side of left outer join can be null");
static_assert(is_optional<decltype(x.id)>::value, "outer primary key can be null");
static_assert(not is_optional<decltype(x.textNnD)>::value, "left side of left outer join cannot be null");
static_assert(is_optional<decltype(x.boolNn)>::value, "right side of left outer join can be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
{
const auto rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(bar.left_outer_join(foo).on(foo.omega > bar.alpha))
const auto rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(bar.left_outer_join(foo).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.gamma)>::value, "left side of left outer join cannot be null");
static_assert(is_optional<decltype(x.delta)>::value, "right side of left outer join can be null");
static_assert(not is_optional<decltype(x.id)>::value, "primary key cannot be null");
static_assert(not is_optional<decltype(x.boolNn)>::value, "left side of left outer join cannot be null");
static_assert(is_optional<decltype(x.textNnD)>::value, "right side of left outer join can be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
// Right outer join
{
const auto rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(foo.right_outer_join(bar).on(foo.omega > bar.alpha))
const auto rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(foo.right_outer_join(bar).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(is_optional<decltype(x.delta)>::value, "left side of right outer join can be null");
static_assert(not is_optional<decltype(x.gamma)>::value,
static_assert(not is_optional<decltype(x.id)>::value, "primary key cannot be null");
static_assert(is_optional<decltype(x.textNnD)>::value, "left side of right outer join can be null");
static_assert(not is_optional<decltype(x.boolNn)>::value,
"right side of right outer join cannot be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
{
const auto rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(bar.right_outer_join(foo).on(foo.omega > bar.alpha))
const auto rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(bar.right_outer_join(foo).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(is_optional<decltype(x.gamma)>::value, "left side of right outer join can be null");
static_assert(not is_optional<decltype(x.delta)>::value,
static_assert(is_optional<decltype(x.id)>::value, "left side of right outer join can be null");
static_assert(is_optional<decltype(x.boolNn)>::value, "left side of right outer join can be null");
static_assert(not is_optional<decltype(x.textNnD)>::value,
"right side of right outer join cannot be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
// Outer join
{
const auto rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(foo.outer_join(bar).on(foo.omega > bar.alpha))
const auto rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(foo.outer_join(bar).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(is_optional<decltype(x.delta)>::value, "left side of outer join can be null");
static_assert(is_optional<decltype(x.gamma)>::value, "right side of outer join can be null");
static_assert(is_optional<decltype(x.id)>::value, "left side of outer join can be null");
static_assert(is_optional<decltype(x.textNnD)>::value, "left side of outer join can be null");
static_assert(is_optional<decltype(x.boolNn)>::value, "right side of outer join can be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
{
const auto rows = db(select(bar.alpha, foo.delta, bar.gamma, seven)
.from(bar.outer_join(foo).on(foo.omega > bar.alpha))
const auto rows = db(select(bar.id, foo.textNnD, bar.boolNn, seven)
.from(bar.outer_join(foo).on(foo.doubleN > bar.id))
.unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(is_optional<decltype(x.gamma)>::value, "left side of outer join can be null");
static_assert(is_optional<decltype(x.delta)>::value, "right side of outer join can be null");
static_assert(is_optional<decltype(x.id)>::value, "left side of outer join can be null");
static_assert(is_optional<decltype(x.boolNn)>::value, "left side of outer join can be null");
static_assert(is_optional<decltype(x.textNnD)>::value, "right side of outer join can be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
// Cross join
{
const auto rows =
db(select(bar.alpha, foo.delta, bar.gamma, seven).from(foo.cross_join(bar)).unconditionally());
db(select(bar.id, foo.textNnD, bar.boolNn, seven).from(foo.cross_join(bar)).unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.delta)>::value, "left side of cross join cannot be null");
static_assert(not is_optional<decltype(x.gamma)>::value, "right side of cross join cannot be null");
static_assert(not is_optional<decltype(x.id)>::value, "primary key cannot be null");
static_assert(not is_optional<decltype(x.textNnD)>::value, "left side of cross join cannot be null");
static_assert(not is_optional<decltype(x.boolNn)>::value, "right side of cross join cannot be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
{
const auto rows =
db(select(bar.alpha, foo.delta, bar.gamma, seven).from(bar.cross_join(foo)).unconditionally());
db(select(bar.id, foo.textNnD, bar.boolNn, seven).from(bar.cross_join(foo)).unconditionally());
auto& x = rows.front();
static_assert(is_optional<decltype(x.alpha)>::value, "nullable value can always be null");
static_assert(not is_optional<decltype(x.gamma)>::value, "left side of cross join cannot be null");
static_assert(not is_optional<decltype(x.delta)>::value, "right side of cross join cannot be null");
static_assert(not is_optional<decltype(x.id)>::value, "primary key cannot be null");
static_assert(not is_optional<decltype(x.boolNn)>::value, "left side of cross join cannot be null");
static_assert(not is_optional<decltype(x.textNnD)>::value, "right side of cross join cannot be null");
static_assert(not is_optional<decltype(x.s)>::value, "constant non-null value can not be null");
}
}
@ -202,9 +202,10 @@ namespace
{
{
// aggregates of nullable values
const auto a = bar.alpha;
static_assert(sqlpp::can_be_null_t<decltype(bar.alpha)>::value, "");
static_assert(sqlpp::can_be_null_t<decltype(a)>::value, "");
#warning use a nullable value
const auto a = bar.id;
static_assert(not sqlpp::can_be_null_t<decltype(bar.id)>::value, "");
static_assert(not sqlpp::can_be_null_t<decltype(a)>::value, "");
const auto rows = db(select(count(a), avg(a), max(a), min(a), sum(a)).from(bar).unconditionally());
auto& x = rows.front();
static_assert(not is_optional<decltype(x.count)>::value, "");
@ -215,8 +216,8 @@ namespace
}
{
// aggregates of nullable values
const auto o = foo.omega;
static_assert(sqlpp::can_be_null_t<decltype(foo.omega)>::value, "");
const auto o = foo.doubleN;
static_assert(sqlpp::can_be_null_t<decltype(foo.doubleN)>::value, "");
static_assert(sqlpp::can_be_null_t<decltype(o)>::value, "");
const auto rows = db(select(count(o), avg(o), max(o), min(o), sum(o)).from(foo).unconditionally());
auto& x = rows.front();

View File

@ -72,8 +72,8 @@ int CustomQuery(int, char*[])
// A void custom query
printer.reset();
auto x =
//select(t.alpha).from(t).where(t.alpha > 7).group_by(t.alpha).having(max(t.alpha) > 13).order_by(t.beta.desc());
update(t).set(t.beta = "eight", t.gamma = true);
//select(t.id).from(t).where(t.id > 7).group_by(t.id).having(max(t.id) > 13).order_by(t.textN.desc());
update(t).set(t.textN = "eight", t.boolNn = true);
std::cerr << serialize(x, printer).str() << std::endl;
#if 0
db(x);
@ -85,26 +85,26 @@ int CustomQuery(int, char*[])
// A prepared custom select
// The return type of the custom query is determined from the first argument which does have a return type, in this
// case the select
auto p = db.prepare(custom_query(select(all_of(t)).from(t), where(t.alpha > sqlpp::parameter(t.alpha))));
p.params.alpha = 8;
auto p = db.prepare(custom_query(select(all_of(t)).from(t), where(t.id > sqlpp::parameter(t.id))));
p.params.id = 8;
for (const auto& row : db(p))
{
std::cerr << row.alpha << std::endl;
std::cerr << row.id << std::endl;
}
// Create a custom "insert or ignore"
db(custom_query(sqlpp::insert(), sqlpp::verbatim(" OR IGNORE"), into(t),
insert_set(t.beta = "sample", t.gamma = true)));
insert_set(t.textN = "sample", t.boolNn = true)));
// Create a custom mulit-row "insert or ignore"
auto batch = insert_columns(t.beta, t.gamma);
batch.add_values(t.beta = "sample", t.gamma = true);
batch.add_values(t.beta = "ample", t.gamma = false);
auto batch = insert_columns(t.textN, t.boolNn);
batch.add_values(t.textN = "sample", t.boolNn = true);
batch.add_values(t.textN = "ample", t.boolNn = false);
db(custom_query(sqlpp::insert(), sqlpp::verbatim(" OR IGNORE"), into(t), batch));
// Create a MYSQL style custom "insert on duplicate update"
db(custom_query(sqlpp::insert_into(t).set(t.beta = "sample", t.gamma = true),
on_duplicate_key_update(db, t.beta = "sample")(db, t.gamma = false).get()));
db(custom_query(sqlpp::insert_into(t).set(t.textN = "sample", t.boolNn = true),
on_duplicate_key_update(db, t.textN = "sample")(db, t.boolNn = false).get()));
// A custom (select ... into) with adjusted return type
// The first argument with a return type is the select, but the custom query is really an insert. Thus, we tell it so.
@ -121,7 +121,7 @@ int CustomQuery(int, char*[])
for (const auto& row :
db(custom_query(sqlpp::verbatim("PRAGMA user_version")).with_result_type_of(select(all_of(t)))))
{
(void)row.alpha;
(void)row.id;
}
#endif

View File

@ -51,36 +51,36 @@ int DateTime(int, char*[])
}
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
{
std::cout << row.colDayPoint;
std::cout << row.colTimePoint;
const auto tp = std::chrono::system_clock::time_point{row.colTimePoint.value()};
std::cout << row.dayPointN;
std::cout << row.timePointN;
const auto tp = std::chrono::system_clock::time_point{row.timePointN.value()};
std::cout << std::chrono::system_clock::to_time_t(tp);
}
printer.reset();
std::cerr << serialize(::sqlpp::value(std::chrono::system_clock::now()), printer).str() << std::endl;
db(insert_into(t).set(t.colDayPoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())));
db(insert_into(t).set(t.colTimePoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())));
db(insert_into(t).set(t.colTimePoint = std::chrono::system_clock::now()));
db(insert_into(t).set(t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())));
db(insert_into(t).set(t.dayPointN = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())));
db(insert_into(t).set(t.timePointN = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())));
db(insert_into(t).set(t.timePointN = std::chrono::system_clock::now()));
db(insert_into(t).set(t.timeOfDayN = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())));
db(update(t)
.set(t.colDayPoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()))
.where(t.colDayPoint < std::chrono::system_clock::now()));
.set(t.dayPointN = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()))
.where(t.dayPointN < std::chrono::system_clock::now()));
db(update(t)
.set(t.colTimePoint = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()),
t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now()))
.where(t.colDayPoint < std::chrono::system_clock::now()));
.set(t.timePointN = floor<::sqlpp::chrono::days>(std::chrono::system_clock::now()),
t.timeOfDayN = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now()))
.where(t.dayPointN < std::chrono::system_clock::now()));
db(update(t)
.set(t.colTimePoint = std::chrono::system_clock::now(),
t.colTimeOfDay = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now()))
.where(t.colDayPoint < std::chrono::system_clock::now()));
.set(t.timePointN = std::chrono::system_clock::now(),
t.timeOfDayN = ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now()))
.where(t.dayPointN < std::chrono::system_clock::now()));
db(remove_from(t).where(t.colDayPoint == floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())));
db(remove_from(t).where(t.colDayPoint == std::chrono::system_clock::now()));
db(remove_from(t).where(t.colTimePoint == floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())));
db(remove_from(t).where(t.colTimePoint == std::chrono::system_clock::now()));
db(remove_from(t).where(t.colTimeOfDay == ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())));
db(remove_from(t).where(t.dayPointN == floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())));
db(remove_from(t).where(t.dayPointN == std::chrono::system_clock::now()));
db(remove_from(t).where(t.timePointN == floor<::sqlpp::chrono::days>(std::chrono::system_clock::now())));
db(remove_from(t).where(t.timePointN == std::chrono::system_clock::now()));
db(remove_from(t).where(t.timeOfDayN == ::sqlpp::chrono::time_of_day(std::chrono::system_clock::now())));
return 0;
}

View File

@ -41,16 +41,16 @@ int Function(int, char* [])
const auto f = test::TabFoo{};
const auto t = test::TabBar{};
// f.omega + 4 *= "";
// f.doubleN + 4 *= "";
// MEMBER FUNCTIONS
// ----------------
// Test in
{
using TI = decltype(t.alpha.in(1, 2, 3));
using TF = decltype(f.omega.in(1.0, 2.0, 3.0));
using TT = decltype(t.beta.in("a", "b", "c"));
using TI = decltype(t.id.in(1, 2, 3));
using TF = decltype(f.doubleN.in(1.0, 2.0, 3.0));
using TT = decltype(t.textN.in("a", "b", "c"));
static_assert(sqlpp::is_selectable_t<TI>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement");
@ -67,9 +67,9 @@ int Function(int, char* [])
// Test in with value list
{
using TI = decltype(t.alpha.in(sqlpp::value_list(std::vector<int>({1, 2, 3}))));
using TF = decltype(f.omega.in(sqlpp::value_list(std::vector<float>({1.0, 2.0, 3.0}))));
using TT = decltype(t.beta.in(sqlpp::value_list(std::vector<std::string>({"a", "b", "c"}))));
using TI = decltype(t.id.in(sqlpp::value_list(std::vector<int>({1, 2, 3}))));
using TF = decltype(f.doubleN.in(sqlpp::value_list(std::vector<float>({1.0, 2.0, 3.0}))));
using TT = decltype(t.textN.in(sqlpp::value_list(std::vector<std::string>({"a", "b", "c"}))));
static_assert(sqlpp::is_selectable_t<TI>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement");
@ -86,9 +86,9 @@ int Function(int, char* [])
// Test not_in
{
using TI = decltype(t.alpha.not_in(1, 2, 3));
using TF = decltype(f.omega.not_in(1.0, 2.0, 3.0));
using TT = decltype(t.beta.not_in("a", "b", "c"));
using TI = decltype(t.id.not_in(1, 2, 3));
using TF = decltype(f.doubleN.not_in(1.0, 2.0, 3.0));
using TT = decltype(t.textN.not_in("a", "b", "c"));
static_assert(sqlpp::is_selectable_t<TI>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement");
@ -105,9 +105,9 @@ int Function(int, char* [])
// Test not in with value list
{
using TI = decltype(t.alpha.not_in(sqlpp::value_list(std::vector<int>({1, 2, 3}))));
using TF = decltype(f.omega.not_in(sqlpp::value_list(std::vector<float>({1.0, 2.0, 3.0}))));
using TT = decltype(t.beta.not_in(sqlpp::value_list(std::vector<std::string>({"a", "b", "c"}))));
using TI = decltype(t.id.not_in(sqlpp::value_list(std::vector<int>({1, 2, 3}))));
using TF = decltype(f.doubleN.not_in(sqlpp::value_list(std::vector<float>({1.0, 2.0, 3.0}))));
using TT = decltype(t.textN.not_in(sqlpp::value_list(std::vector<std::string>({"a", "b", "c"}))));
static_assert(sqlpp::is_selectable_t<TI>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement");
@ -124,7 +124,7 @@ int Function(int, char* [])
// Test like
{
using TT = decltype(t.beta.like("%c%"));
using TT = decltype(t.textN.like("%c%"));
static_assert(sqlpp::is_selectable_t<TT>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement");
@ -133,12 +133,12 @@ int Function(int, char* [])
// Test is_null
{
using TI = decltype(t.alpha.is_null());
using TF = decltype(f.omega.is_null());
using TT = decltype(t.beta.is_null());
using TTI = decltype(is_null(t.alpha));
using TTF = decltype(is_null(f.omega));
using TTT = decltype(is_null(t.beta));
using TI = decltype(t.id.is_null());
using TF = decltype(f.doubleN.is_null());
using TT = decltype(t.textN.is_null());
using TTI = decltype(is_null(t.id));
using TTF = decltype(is_null(f.doubleN));
using TTT = decltype(is_null(t.textN));
static_assert(std::is_same<TI, TTI>::value, "type requirement");
static_assert(std::is_same<TF, TTF>::value, "type requirement");
static_assert(std::is_same<TT, TTT>::value, "type requirement");
@ -158,12 +158,12 @@ int Function(int, char* [])
// Test is_not_null
{
using TI = decltype(t.alpha.is_not_null());
using TF = decltype(f.omega.is_not_null());
using TT = decltype(t.beta.is_not_null());
using TTI = decltype(is_not_null(t.alpha));
using TTF = decltype(is_not_null(f.omega));
using TTT = decltype(is_not_null(t.beta));
using TI = decltype(t.id.is_not_null());
using TF = decltype(f.doubleN.is_not_null());
using TT = decltype(t.textN.is_not_null());
using TTI = decltype(is_not_null(t.id));
using TTF = decltype(is_not_null(f.doubleN));
using TTT = decltype(is_not_null(t.textN));
static_assert(std::is_same<TI, TTI>::value, "type requirement");
static_assert(std::is_same<TF, TTF>::value, "type requirement");
static_assert(std::is_same<TT, TTT>::value, "type requirement");
@ -186,8 +186,8 @@ int Function(int, char* [])
// Test exists
{
using TI = decltype(exists(select(t.alpha).from(t)));
using TT = decltype(exists(select(t.beta).from(t)));
using TI = decltype(exists(select(t.id).from(t)));
using TT = decltype(exists(select(t.textN).from(t)));
static_assert(sqlpp::is_selectable_t<TI>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_numeric_t<TI>::value, "type requirement");
@ -197,19 +197,19 @@ int Function(int, char* [])
static_assert(not sqlpp::is_numeric_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_text_t<TT>::value, "type requirement");
if (false and db(select(exists(select(t.alpha).from(t).unconditionally()))).front().exists)
if (false and db(select(exists(select(t.id).from(t).unconditionally()))).front().exists)
{ /* do something */
}
}
// Test any
{
using S = decltype(select(t.alpha).from(t));
using S = decltype(select(t.id).from(t));
static_assert(sqlpp::is_numeric_t<S>::value, "type requirement");
using TI = decltype(any(select(t.alpha).from(t)));
using TT = decltype(any(select(t.beta).from(t)));
using TF = decltype(any(select(f.omega).from(f)));
using TI = decltype(any(select(t.id).from(t)));
using TT = decltype(any(select(t.textN).from(t)));
using TF = decltype(any(select(f.doubleN).from(f)));
static_assert(not sqlpp::is_selectable_t<TI>::value, "type requirement");
static_assert(sqlpp::is_multi_expression_t<TI>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
@ -230,9 +230,9 @@ int Function(int, char* [])
// Test some
{
using TI = decltype(some(select(t.alpha).from(t)));
using TT = decltype(some(select(t.beta).from(t)));
using TF = decltype(some(select(f.omega).from(f)));
using TI = decltype(some(select(t.id).from(t)));
using TT = decltype(some(select(t.textN).from(t)));
using TF = decltype(some(select(f.doubleN).from(f)));
static_assert(not sqlpp::is_selectable_t<TI>::value, "type requirement");
static_assert(sqlpp::is_multi_expression_t<TI>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
@ -256,8 +256,8 @@ int Function(int, char* [])
// Test avg
{
using TI = decltype(avg(t.alpha));
using TF = decltype(avg(f.omega));
using TI = decltype(avg(t.id));
using TF = decltype(avg(f.doubleN));
static_assert(sqlpp::has_auto_alias_t<TI>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
static_assert(not sqlpp::is_integral_t<TI>::value, "type requirement");
@ -270,9 +270,9 @@ int Function(int, char* [])
// Test count
{
using TI = decltype(count(t.alpha));
using TT = decltype(count(t.beta));
using TF = decltype(count(f.omega));
using TI = decltype(count(t.id));
using TT = decltype(count(t.textN));
using TF = decltype(count(f.doubleN));
static_assert(sqlpp::has_auto_alias_t<TI>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
@ -286,16 +286,16 @@ int Function(int, char* [])
static_assert(sqlpp::is_integral_t<TT>::value, "type requirement");
static_assert(not sqlpp::is_floating_point_t<TT>::value, "type requirement");
if (false and db(select(count(t.alpha)).from(t).unconditionally()).front().count > 0)
if (false and db(select(count(t.id)).from(t).unconditionally()).front().count > 0)
{ /* do something */
}
}
// Test max
{
using TI = decltype(max(t.alpha));
using TF = decltype(max(f.omega));
using TT = decltype(max(t.beta));
using TI = decltype(max(t.id));
using TF = decltype(max(f.doubleN));
using TT = decltype(max(t.textN));
static_assert(sqlpp::has_auto_alias_t<TI>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
@ -311,9 +311,9 @@ int Function(int, char* [])
// Test min
{
using TI = decltype(min(t.alpha));
using TF = decltype(min(f.omega));
using TT = decltype(min(t.beta));
using TI = decltype(min(t.id));
using TF = decltype(min(f.doubleN));
using TT = decltype(min(t.textN));
static_assert(sqlpp::has_auto_alias_t<TI>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
@ -329,8 +329,8 @@ int Function(int, char* [])
// Test sum
{
using TI = decltype(sum(t.alpha));
using TF = decltype(sum(f.omega));
using TI = decltype(sum(t.id));
using TF = decltype(sum(f.doubleN));
static_assert(sqlpp::has_auto_alias_t<TF>::value, "type requirement");
static_assert(sqlpp::is_numeric_t<TI>::value, "type requirement");
static_assert(sqlpp::is_integral_t<TI>::value, "type requirement");
@ -362,10 +362,10 @@ int Function(int, char* [])
// test flatten
{
using TB = decltype(flatten(t.gamma, db));
using TI = decltype(flatten(t.alpha, db));
using TF = decltype(flatten(f.omega, db));
using TT = decltype(flatten(t.beta, db));
using TB = decltype(flatten(t.boolNn, db));
using TI = decltype(flatten(t.id, db));
using TF = decltype(flatten(f.doubleN, db));
using TT = decltype(flatten(t.textN, db));
static_assert(not sqlpp::is_selectable_t<TB>::value, "type requirement");
static_assert(sqlpp::is_boolean_t<TB>::value, "type requirement");
static_assert(not sqlpp::is_selectable_t<TI>::value, "type requirement");

View File

@ -46,63 +46,63 @@ int Insert(int, char*[])
}
{
using T = decltype(insert_into(t).set(t.beta = "kirschauflauf"));
using T = decltype(insert_into(t).set(t.textN = "kirschauflauf"));
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
db(insert_into(t).default_values());
db(insert_into(t).set(t.gamma = true, t.beta = "kirschauflauf"));
db(insert_into(t).set(t.gamma = sqlpp::default_value, t.beta = sqlpp::value_or_null("pie"),
t.delta = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null)));
db(insert_into(t).set(t.boolNn = true, t.textN = "kirschauflauf"));
db(insert_into(t).set(t.boolNn = sqlpp::default_value, t.textN = sqlpp::value_or_null("pie"),
t.intN = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null)));
serialize(insert_into(t).default_values(), printer).str();
serialize(insert_into(t), printer).str();
serialize(insert_into(t).set(t.gamma = true, t.beta = "kirschauflauf"), printer).str();
serialize(insert_into(t).columns(t.gamma, t.beta), printer).str();
auto multi_insert = insert_into(t).columns(t.gamma, t.beta, t.delta);
multi_insert.add_values(t.gamma = true, t.beta = "cheesecake", t.delta = 1);
multi_insert.add_values(t.gamma = sqlpp::default_value, t.beta = sqlpp::default_value,
t.delta = sqlpp::default_value);
multi_insert.add_values(t.gamma = sqlpp::value_or_null(true), t.beta = sqlpp::value_or_null("pie"),
t.delta = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null));
serialize(insert_into(t).set(t.boolNn = true, t.textN = "kirschauflauf"), printer).str();
serialize(insert_into(t).columns(t.boolNn, t.textN), printer).str();
auto multi_insert = insert_into(t).columns(t.boolNn, t.textN, t.intN);
multi_insert.add_values(t.boolNn = true, t.textN = "cheesecake", t.intN = 1);
multi_insert.add_values(t.boolNn = sqlpp::default_value, t.textN = sqlpp::default_value,
t.intN = sqlpp::default_value);
multi_insert.add_values(t.boolNn = sqlpp::value_or_null(true), t.textN = sqlpp::value_or_null("pie"),
t.intN = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null));
printer.reset();
std::cerr << serialize(multi_insert, printer).str() << std::endl;
// Beware, you need exact types for inserted values in multi_insert
insert_into(tabDateTime)
.set(tabDateTime.colTimePoint = std::chrono::system_clock::now());
.set(tabDateTime.timePointN = std::chrono::system_clock::now());
auto multi_time_insert = insert_into(tabDateTime).columns(tabDateTime.colTimePoint);
multi_time_insert.add_values(tabDateTime.colTimePoint = std::chrono::time_point_cast<std::chrono::microseconds>(
auto multi_time_insert = insert_into(tabDateTime).columns(tabDateTime.timePointN);
multi_time_insert.add_values(tabDateTime.timePointN = std::chrono::time_point_cast<std::chrono::microseconds>(
std::chrono::system_clock::now()));
#warning add tests with optional
db(multi_insert);
auto values = [&t]() { return std::make_tuple(t.gamma = true, t.beta = sqlpp::null); };
auto values = [&t]() { return std::make_tuple(t.boolNn = true, t.textN = sqlpp::null); };
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::verbatim<sqlpp::integer>("17+4")));
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::null));
db(insert_into(t).set(t.gamma = true, t.delta = sqlpp::default_value));
db(insert_into(t).set(t.gamma = true, t.delta = 0));
db(insert_into(t).set(t.boolNn = true, t.intN = sqlpp::verbatim<sqlpp::integer>("17+4")));
db(insert_into(t).set(t.boolNn = true, t.intN = sqlpp::null));
db(insert_into(t).set(t.boolNn = true, t.intN = sqlpp::default_value));
db(insert_into(t).set(t.boolNn = true, t.intN = 0));
db(insert_into(t).set(values()));
db(insert_into(t).set(t.gamma = true, t.delta = 0, t.beta = select(u.delta).from(u).unconditionally()));
db(insert_into(t).set(t.boolNn = true, t.intN = 0, t.textN = select(u.textNnD).from(u).unconditionally()));
auto prepared_insert = db.prepare(insert_into(t).set(t.gamma = parameter(t.gamma), t.delta = parameter(t.delta)));
prepared_insert.params.gamma = true;
prepared_insert.params.delta = sqlpp::null;
prepared_insert.params.delta = 17;
prepared_insert.params.delta = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null);
prepared_insert.params.delta = sqlpp::value_or_null(17);
auto prepared_insert = db.prepare(insert_into(t).set(t.boolNn = parameter(t.boolNn), t.intN = parameter(t.intN)));
prepared_insert.params.boolNn = true;
prepared_insert.params.intN = sqlpp::null;
prepared_insert.params.intN = 17;
prepared_insert.params.intN = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null);
prepared_insert.params.intN = sqlpp::value_or_null(17);
db(prepared_insert);
auto prepared_insert_sv = db.prepare(insert_into(t).set(t.gamma = parameter(t.gamma), t.delta = parameter(t.delta), t.beta = parameter(t.beta)));
prepared_insert_sv.params.gamma = true;
prepared_insert_sv.params.delta = 17;
prepared_insert_sv.params.beta = sqlpp::compat::string_view("string_view");;
auto prepared_insert_sv = db.prepare(insert_into(t).set(t.boolNn = parameter(t.boolNn), t.intN = parameter(t.intN), t.textN = parameter(t.textN)));
prepared_insert_sv.params.boolNn = true;
prepared_insert_sv.params.intN = 17;
prepared_insert_sv.params.textN = sqlpp::compat::string_view("string_view");;
db(prepared_insert_sv);
return 0;

View File

@ -36,71 +36,69 @@ int Interpret(int, char* [])
const auto f = test::TabFoo{};
const auto t = test::TabBar{};
select(t.alpha.as(t.beta));
select(t.id.as(t.textN));
serialize(insert_into(t).columns(t.beta, t.gamma), printer).str();
serialize(insert_into(t).columns(t.textN, t.boolNn), printer).str();
{
auto i = insert_into(t).columns(t.gamma, t.beta);
i.add_values(t.gamma = true, t.beta = "cheesecake");
auto i = insert_into(t).columns(t.boolNn, t.textN);
i.add_values(t.boolNn = true, t.textN = "cheesecake");
serialize(i, printer).str();
i.add_values(t.gamma = sqlpp::default_value, t.beta = sqlpp::null);
i.add_values(t.boolNn = sqlpp::default_value, t.textN = sqlpp::null);
serialize(i, printer).str();
}
serialize(t.alpha = sqlpp::null, printer).str();
serialize(t.alpha = sqlpp::default_value, printer).str();
serialize(t.alpha, printer).str();
serialize(-t.alpha, printer).str();
serialize(+t.alpha, printer).str();
serialize(-(t.alpha + 7), printer).str();
serialize(t.alpha = 0, printer).str();
serialize(t.alpha == 0, printer).str();
serialize(t.alpha != 0, printer).str();
serialize(t.alpha == 7, printer).str();
serialize(t.beta + "kaesekuchen", printer).str();
serialize(t.id, printer).str();
serialize(-t.id, printer).str();
serialize(+t.id, printer).str();
serialize(-(t.id + 7), printer).str();
serialize(t.id = 0, printer).str();
serialize(t.id == 0, printer).str();
serialize(t.id != 0, printer).str();
serialize(t.id == 7, printer).str();
serialize(t.textN + "kaesekuchen", printer).str();
serialize(sqlpp::select(), printer).str();
serialize(sqlpp::select().flags(sqlpp::distinct), printer).str();
serialize(select(t.alpha, t.beta).flags(sqlpp::distinct), printer).str();
serialize(select(t.alpha, t.beta), printer).str();
serialize(select(t.alpha, t.beta).from(t), printer).str();
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3), printer).str();
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma), printer).str();
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")),
serialize(select(t.id, t.textN).flags(sqlpp::distinct), printer).str();
serialize(select(t.id, t.textN), printer).str();
serialize(select(t.id, t.textN).from(t), printer).str();
serialize(select(t.id, t.textN).from(t).where(t.id == 3), printer).str();
serialize(select(t.id, t.textN).from(t).where(t.id == 3).group_by(t.boolNn), printer).str();
serialize(select(t.id, t.textN).from(t).where(t.id == 3).group_by(t.boolNn).having(t.textN.like("%kuchen")),
printer)
.str();
serialize(select(t.alpha, t.beta)
serialize(select(t.id, t.textN)
.from(t)
.where(t.alpha == 3)
.group_by(t.gamma)
.having(t.beta.like("%kuchen"))
.order_by(t.beta.asc()),
.where(t.id == 3)
.group_by(t.boolNn)
.having(t.textN.like("%kuchen"))
.order_by(t.textN.asc()),
printer)
.str();
serialize(select(t.alpha, t.beta)
serialize(select(t.id, t.textN)
.from(t)
.where(t.alpha == 3)
.group_by(t.gamma)
.having(t.beta.like("%kuchen"))
.order_by(t.beta.asc())
.where(t.id == 3)
.group_by(t.boolNn)
.having(t.textN.like("%kuchen"))
.order_by(t.textN.asc())
.limit(17u)
.offset(3u),
printer)
.str();
serialize(parameter(sqlpp::bigint(), t.alpha), printer).str();
serialize(parameter(t.alpha), printer).str();
serialize(t.alpha == parameter(t.alpha), printer).str();
serialize(t.alpha == parameter(t.alpha) and (t.beta + "gimmick").like(parameter(t.beta)), printer).str();
serialize(parameter(sqlpp::bigint(), t.id), printer).str();
serialize(parameter(t.id), printer).str();
serialize(t.id == parameter(t.id), printer).str();
serialize(t.id == parameter(t.id) and (t.textN + "gimmick").like(parameter(t.textN)), printer).str();
serialize(insert_into(t), printer).str();
serialize(insert_into(f).default_values(), printer).str();
serialize(insert_into(t).set(t.gamma = true), printer).str();
serialize(insert_into(t).set(t.boolNn = true), printer).str();
serialize(update(t), printer).str();
serialize(update(t).set(t.gamma = true), printer).str();
serialize(update(t).set(t.gamma = true).where(t.beta.in("kaesekuchen", "cheesecake")), printer).str();
serialize(update(t).set(t.gamma = true).where(t.beta.in()), printer).str();
serialize(update(t).set(t.boolNn = true), printer).str();
serialize(update(t).set(t.boolNn = true).where(t.textN.in("kaesekuchen", "cheesecake")), printer).str();
serialize(update(t).set(t.boolNn = true).where(t.textN.in()), printer).str();
serialize(remove_from(t), printer).str();
serialize(remove_from(t).using_(t), printer).str();
@ -109,66 +107,66 @@ int Interpret(int, char* [])
serialize(sqlpp::value(7), printer).str();
serialize(sqlpp::verbatim<sqlpp::integral>("irgendwas integrales"), printer).str();
serialize(sqlpp::value_list(std::vector<int>({1, 2, 3, 4, 5, 6, 8})), printer).str();
serialize(exists(select(t.alpha).from(t)), printer).str();
serialize(any(select(t.alpha).from(t)), printer).str();
serialize(some(select(t.alpha).from(t)), printer).str();
serialize(count(t.alpha), printer).str();
serialize(min(t.alpha), printer).str();
serialize(max(t.alpha), printer).str();
serialize(avg(t.alpha), printer).str();
serialize(sum(t.alpha), printer).str();
serialize(exists(select(t.id).from(t)), printer).str();
serialize(any(select(t.id).from(t)), printer).str();
serialize(some(select(t.id).from(t)), printer).str();
serialize(count(t.id), printer).str();
serialize(min(t.id), printer).str();
serialize(max(t.id), printer).str();
serialize(avg(t.id), printer).str();
serialize(sum(t.id), printer).str();
serialize(sqlpp::verbatim_table("whatever"), printer).str();
// alias
serialize(t.as(t.alpha), printer).str();
serialize(t.as(t.alpha).beta, printer).str();
serialize(t.as(t.id), printer).str();
serialize(t.as(t.id).textN, printer).str();
// select alias
serialize(select(t.alpha).from(t).where(t.beta > "kaesekuchen").as(t.gamma), printer).str();
serialize(select(t.id).from(t).where(t.textN > "kaesekuchen").as(t.boolNn), printer).str();
// Comparison to null
static_assert(sqlpp::can_be_null_t<decltype(t.alpha)>::value, "expected alpha can be null");
static_assert(not sqlpp::can_be_null_t<decltype(f.delta)>::value, "expected delta cannot be null");
serialize(t.alpha.is_null(), printer).str();
serialize(f.delta.is_null(), printer).str();
static_assert(not sqlpp::can_be_null_t<decltype(t.id)>::value, "expected id cannot be null");
static_assert(not sqlpp::can_be_null_t<decltype(f.textNnD)>::value, "expected intN cannot be null");
serialize(t.id.is_null(), printer).str();
serialize(f.textNnD.is_null(), printer).str();
// join
serialize(t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta), printer).str();
serialize(t.inner_join(t.as(t.id)).on(t.textN == t.as(t.id).textN), printer).str();
{
auto inner = t.inner_join(t.as(t.alpha)).on(t.beta == t.as(t.alpha).beta);
serialize(select(t.alpha).from(inner), printer).str();
auto inner = t.inner_join(t.as(t.id)).on(t.textN == t.as(t.id).textN);
serialize(select(t.id).from(inner), printer).str();
}
// distinct aggregate
serialize(count(sqlpp::distinct, t.alpha % 7), printer).str();
serialize(avg(sqlpp::distinct, t.alpha - 7), printer).str();
serialize(sum(sqlpp::distinct, t.alpha + 7), printer).str();
serialize(count(sqlpp::distinct, t.id % 7), printer).str();
serialize(avg(sqlpp::distinct, t.id - 7), printer).str();
serialize(sum(sqlpp::distinct, t.id + 7), printer).str();
serialize(select(all_of(t)).from(t).unconditionally(), printer).str();
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
{
serialize(t.alpha == row.alpha.value(), printer);
serialize(t.beta == row.beta.value(), printer);
serialize(t.gamma == row.gamma, printer);
serialize(t.id == row.id, printer);
serialize(t.textN == row.textN.value(), printer);
serialize(t.boolNn == row.boolNn, printer);
}
get_sql_name(t);
get_sql_name(t.alpha);
get_sql_name(t.id);
flatten(t.alpha == 7, db);
flatten(t.id == 7, db);
printer.reset();
std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in(select(f.epsilon).from(f).unconditionally())),
std::cerr << serialize(select(all_of(t)).from(t).where(t.id.in(select(f.intN).from(f).unconditionally())),
printer)
.str()
<< std::endl;
printer.reset();
std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in()), printer).str() << std::endl;
std::cerr << serialize(select(all_of(t)).from(t).where(t.id.in()), printer).str() << std::endl;
printer.reset();
std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.not_in()), printer).str() << std::endl;
std::cerr << serialize(select(all_of(t)).from(t).where(t.id.not_in()), printer).str() << std::endl;
auto schema = db.attach("lorem");
auto s = schema_qualified_table(schema, t).as(sqlpp::alias::x);
@ -177,7 +175,7 @@ int Interpret(int, char* [])
std::cerr << serialize(select(all_of(s)).from(s).unconditionally(), printer).str() << std::endl;
printer.reset();
std::cerr << serialize(sqlpp::case_when(true).then(t.alpha).else_(t.alpha + 1).as(t.beta), printer).str()
std::cerr << serialize(sqlpp::case_when(true).then(t.id).else_(t.id + 1).as(t.textN), printer).str()
<< std::endl;
return 0;

View File

@ -38,111 +38,111 @@ int Prepared(int, char* [])
// empty parameter lists
{
using P = sqlpp::make_parameter_list_t<decltype(t.alpha)>;
using P = sqlpp::make_parameter_list_t<decltype(t.id)>;
static_assert(P::size::value == 0, "type requirement");
}
// single parameter
{
using P = sqlpp::make_parameter_list_t<decltype(parameter(t.alpha))>;
using P = sqlpp::make_parameter_list_t<decltype(parameter(t.id))>;
static_assert(P::size::value == 1, "type requirement");
auto p = P{};
p.alpha = 7;
p.id = 7;
}
// single parameter
{
using P = sqlpp::make_parameter_list_t<decltype(parameter(t.beta))>;
using P = sqlpp::make_parameter_list_t<decltype(parameter(t.textN))>;
static_assert(P::size::value == 1, "type requirement");
auto p = P{};
p.beta = "cheesecake";
p.textN = "cheesecake";
}
// single parameter in expression
{
using P = sqlpp::make_parameter_list_t<decltype(t.alpha == parameter(t.alpha))>;
using P = sqlpp::make_parameter_list_t<decltype(t.id == parameter(t.id))>;
static_assert(P::size::value == 1, "type requirement");
auto p = P{};
p.alpha = 7;
p.id = 7;
}
// single parameter in larger expression
{
using P = sqlpp::make_parameter_list_t<decltype((t.beta.like("%") and t.alpha == parameter(t.alpha)) or
t.gamma != false)>;
using P = sqlpp::make_parameter_list_t<decltype((t.textN.like("%") and t.id == parameter(t.id)) or
t.boolNn != false)>;
static_assert(P::size::value == 1, "type requirement");
auto p = P{};
p.alpha = 7;
p.id = 7;
}
// three parameters in expression
{
using P = sqlpp::parameters_of<decltype((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or
t.gamma != parameter(t.gamma))>;
using P = sqlpp::parameters_of<decltype((t.textN.like(parameter(t.textN)) and t.id == parameter(t.id)) or
t.boolNn != parameter(t.boolNn))>;
// FIXME: make some test, that does not depend on detail namespace, but still checks the correct order of the
// parameters
static_assert(std::is_same<P, sqlpp::detail::type_vector<decltype(parameter(t.beta)), decltype(parameter(t.alpha)),
decltype(parameter(t.gamma))>>::value,
static_assert(std::is_same<P, sqlpp::detail::type_vector<decltype(parameter(t.textN)), decltype(parameter(t.id)),
decltype(parameter(t.boolNn))>>::value,
"type requirement");
}
// OK, fine, now create a named parameter list from an expression
{
using Exp =
decltype((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or t.gamma != parameter(t.gamma));
decltype((t.textN.like(parameter(t.textN)) and t.id == parameter(t.id)) or t.boolNn != parameter(t.boolNn));
using P = sqlpp::make_parameter_list_t<Exp>;
P npl;
static_assert(
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.alpha)>>, decltype(npl.alpha)>::value,
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.id)>>, decltype(npl.id)>::value,
"type requirement");
static_assert(
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.beta)>>, decltype(npl.beta)>::value,
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.textN)>>, decltype(npl.textN)>::value,
"type requirement");
static_assert(
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.gamma)>>, decltype(npl.gamma)>::value,
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.boolNn)>>, decltype(npl.boolNn)>::value,
"type requirement");
}
// Wonderful, now take a look at the parameter list of a select
{
auto s = select(all_of(t)).from(t).where((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or
t.gamma != parameter(t.gamma));
auto s = select(all_of(t)).from(t).where((t.textN.like(parameter(t.textN)) and t.id == parameter(t.id)) or
t.boolNn != parameter(t.boolNn));
auto p = db.prepare(s);
p.params.alpha = 7;
p.params.id = 7;
using S = decltype(s);
using P = sqlpp::make_parameter_list_t<S>;
P npl;
static_assert(
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.alpha)>>, decltype(npl.alpha)>::value,
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.id)>>, decltype(npl.id)>::value,
"type requirement");
static_assert(
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.beta)>>, decltype(npl.beta)>::value,
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.textN)>>, decltype(npl.textN)>::value,
"type requirement");
static_assert(
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.gamma)>>, decltype(npl.gamma)>::value,
std::is_same<sqlpp::parameter_value_t<sqlpp::value_type_of<decltype(t.boolNn)>>, decltype(npl.boolNn)>::value,
"type requirement");
npl.alpha = 7;
npl.id = 7;
auto x = npl;
x = npl;
std::cerr << x.alpha << std::endl;
std::cerr << x.id << std::endl;
x = decltype(npl)();
std::cerr << x.alpha << std::endl;
std::cerr << x.id << std::endl;
}
// Can we prepare a query without parameters?
{
auto ps = db.prepare(select(all_of(t)).from(t).where((t.beta.like("%"))));
auto ps = db.prepare(select(all_of(t)).from(t).where((t.textN.like("%"))));
for (const auto& row : db(ps))
{
std::cerr << row.alpha << std::endl;
std::cerr << row.id << std::endl;
}
}
// Check that a prepared select is default-constructable
{
auto s = select(all_of(t)).from(t).where((t.beta.like(parameter(t.beta)) and t.alpha == parameter(t.alpha)) or
t.gamma != parameter(t.gamma));
auto s = select(all_of(t)).from(t).where((t.textN.like(parameter(t.textN)) and t.id == parameter(t.id)) or
t.boolNn != parameter(t.boolNn));
using P = decltype(db.prepare(s));
P p;
}

View File

@ -43,22 +43,22 @@ int Remove(int, char* [])
}
{
using T = decltype(remove_from(t).where(t.beta != "transparent"));
auto x = remove_from(t).where(t.beta != "transparent");
using T = decltype(remove_from(t).where(t.textN != "transparent"));
auto x = remove_from(t).where(t.textN != "transparent");
T y(x);
T z(std::move(x));
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
serialize(remove_from(t), printer).str();
serialize(remove_from(t).where(t.beta != "transparent"), printer).str();
serialize(remove_from(t).where(t.textN != "transparent"), printer).str();
serialize(remove_from(t).using_(t), printer).str();
serialize(remove_from(t).using_(f), printer).str();
#warning: add tests with optional using and optional where
printer.reset();
std::cerr << serialize(remove_from(t).unconditionally(), printer).str() << std::endl;
remove_from(t).where(t.beta.in(select(f.delta).from(f).unconditionally()));
remove_from(t).where(t.textN.in(select(f.textNnD).from(f).unconditionally()));
return 0;
}

View File

@ -37,32 +37,32 @@ int Result(int, char* [])
const auto t = test::TabBar{};
static_assert(sqlpp::can_be_null_t<decltype(t.alpha)>::value, "t.alpha can be null");
static_assert(not sqlpp::can_be_null_t<decltype(t.id)>::value, "t.id cannot be null");
// Using a non-enforcing db
for (const auto& row : db(select(all_of(t), t.beta.like("")).from(t).unconditionally()))
for (const auto& row : db(select(all_of(t), t.textN.like("")).from(t).unconditionally()))
{
static_assert(is_optional<decltype(row.alpha)>::value, "row.alpha can be null");
static_assert(not is_optional<decltype(row.id)>::value, "row.id cannot be null");
for (const auto& sub : db(select(all_of(t)).from(t).where(t.alpha == row.alpha.value())))
for (const auto& sub : db(select(all_of(t)).from(t).where(t.id == row.id)))
{
std::cerr << sub.alpha << std::endl;
std::cerr << sub.id << std::endl;
}
db(insert_into(t).set(t.beta = row.beta.value(), t.gamma = false));
db(insert_into(t).set(t.textN = row.textN.value(), t.boolNn = false));
}
sqlpp::select((t.alpha + 1).as(t.alpha)).flags(sqlpp::all).from(t);
sqlpp::select((t.id + 1).as(t.id)).flags(sqlpp::all).from(t);
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
{
static_assert(is_optional<decltype(row.alpha)>::value, "row.alpha can be null");
static_assert(not is_optional<decltype(row.id)>::value, "row.id cannot be null");
}
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
{
static_assert(is_optional<decltype(row.alpha)>::value, "row.alpha can be null");
static_assert(not is_optional<decltype(row.id)>::value, "row.id cannot be null");
}
sqlpp::select((t.alpha + 1).as(t.alpha)).flags(sqlpp::all).from(t);
sqlpp::select((t.id + 1).as(t.id)).flags(sqlpp::all).from(t);
return 0;
}

View File

@ -1,5 +1,7 @@
#pragma once
// generated by ./scripts/ddl2cpp tests/core/usage/sample.sql tests/core/usage/Sample test
#include <sqlpp11/table.h>
#include <sqlpp11/data_types.h>
#include <sqlpp11/char_sequence.h>
@ -8,343 +10,297 @@ namespace test
{
namespace TabFoo_
{
struct Delta
struct Id
{
struct _alias_t
{
static constexpr const char _literal[] = "delta";
static constexpr const char _literal[] = "id";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T delta;
T& operator()()
{
return delta;
}
const T& operator()() const
{
return delta;
}
};
T id;
T& operator()() { return id; }
const T& operator()() const { return id; }
};
};
using _traits = sqlpp::make_traits<sqlpp::varchar>;
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>;
};
struct Epsilon
struct TextNnD
{
struct _alias_t
{
static constexpr const char _literal[] = "epsilon";
static constexpr const char _literal[] = "text_nn_d";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T epsilon;
T& operator()()
{
return epsilon;
}
const T& operator()() const
{
return epsilon;
}
};
T textNnD;
T& operator()() { return textNnD; }
const T& operator()() const { return textNnD; }
};
};
using _traits = sqlpp::make_traits<sqlpp::bigint, sqlpp::tag::can_be_null>;
using _traits = sqlpp::make_traits<sqlpp::text>;
};
struct Omega
struct IntN
{
struct _alias_t
{
static constexpr const char _literal[] = "omega";
static constexpr const char _literal[] = "int_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T omega;
T& operator()()
{
return omega;
}
const T& operator()() const
T intN;
T& operator()() { return intN; }
const T& operator()() const { return intN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::can_be_null>;
};
struct DoubleN
{
struct _alias_t
{
static constexpr const char _literal[] = "double_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
return omega;
}
};
T doubleN;
T& operator()() { return doubleN; }
const T& operator()() const { return doubleN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::floating_point, sqlpp::tag::can_be_null>;
};
struct Psi
struct UIntN
{
struct _alias_t
{
static constexpr const char _literal[] = "psi";
static constexpr const char _literal[] = "u_int_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T psi;
T& operator()()
{
return psi;
}
const T& operator()() const
{
return psi;
}
};
T uIntN;
T& operator()() { return uIntN; }
const T& operator()() const { return uIntN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::bigint_unsigned, sqlpp::tag::can_be_null>;
using _traits = sqlpp::make_traits<sqlpp::integer_unsigned, sqlpp::tag::can_be_null>;
};
struct Book
struct BlobN
{
struct _alias_t
{
static constexpr const char _literal[] = "book";
static constexpr const char _literal[] = "blob_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T book;
T& operator()()
{
return book;
}
const T& operator()() const
{
return book;
}
};
T blobN;
T& operator()() { return blobN; }
const T& operator()() const { return blobN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::blob, sqlpp::tag::can_be_null>;
};
} // namespace TabFoo_
} // namespace TabFoo_
struct TabFoo : sqlpp::table_t<TabFoo, TabFoo_::Delta, TabFoo_::Epsilon, TabFoo_::Omega, TabFoo_::Psi, TabFoo_::Book>
struct TabFoo: sqlpp::table_t<TabFoo,
TabFoo_::Id,
TabFoo_::TextNnD,
TabFoo_::IntN,
TabFoo_::DoubleN,
TabFoo_::UIntN,
TabFoo_::BlobN>
{
struct _alias_t
{
static constexpr const char _literal[] = "tab_foo";
static constexpr const char _literal[] = "tab_foo";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T tabFoo;
T& operator()()
{
return tabFoo;
}
const T& operator()() const
{
return tabFoo;
}
T& operator()() { return tabFoo; }
const T& operator()() const { return tabFoo; }
};
};
};
namespace TabBar_
{
struct Alpha
struct Id
{
struct _alias_t
{
static constexpr const char _literal[] = "alpha";
static constexpr const char _literal[] = "id";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T alpha;
T& operator()()
{
return alpha;
}
const T& operator()() const
{
return alpha;
}
};
T id;
T& operator()() { return id; }
const T& operator()() const { return id; }
};
};
using _traits = sqlpp::
make_traits<sqlpp::bigint, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update, sqlpp::tag::can_be_null>;
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>;
};
struct Beta
struct TextN
{
struct _alias_t
{
static constexpr const char _literal[] = "beta";
static constexpr const char _literal[] = "text_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T beta;
T& operator()()
{
return beta;
}
const T& operator()() const
{
return beta;
}
};
T textN;
T& operator()() { return textN; }
const T& operator()() const { return textN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::varchar, sqlpp::tag::can_be_null>;
using _traits = sqlpp::make_traits<sqlpp::text, sqlpp::tag::can_be_null>;
};
struct Gamma
struct BoolNn
{
struct _alias_t
{
static constexpr const char _literal[] = "gamma";
static constexpr const char _literal[] = "bool_nn";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T gamma;
T& operator()()
{
return gamma;
}
const T& operator()() const
{
return gamma;
}
};
T boolNn;
T& operator()() { return boolNn; }
const T& operator()() const { return boolNn; }
};
};
using _traits = sqlpp::make_traits<sqlpp::boolean, sqlpp::tag::require_insert>;
};
struct Delta
struct IntN
{
struct _alias_t
{
static constexpr const char _literal[] = "delta";
static constexpr const char _literal[] = "int_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T delta;
T& operator()()
{
return delta;
}
const T& operator()() const
{
return delta;
}
};
T intN;
T& operator()() { return intN; }
const T& operator()() const { return intN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::can_be_null>;
};
} // namespace TabBar_
} // namespace TabBar_
struct TabBar : sqlpp::table_t<TabBar, TabBar_::Alpha, TabBar_::Beta, TabBar_::Gamma, TabBar_::Delta>
struct TabBar: sqlpp::table_t<TabBar,
TabBar_::Id,
TabBar_::TextN,
TabBar_::BoolNn,
TabBar_::IntN>
{
struct _alias_t
{
static constexpr const char _literal[] = "tab_bar";
static constexpr const char _literal[] = "tab_bar";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T tabBar;
T& operator()()
{
return tabBar;
}
const T& operator()() const
{
return tabBar;
}
T& operator()() { return tabBar; }
const T& operator()() const { return tabBar; }
};
};
};
namespace TabDateTime_
{
struct ColDayPoint
struct Id
{
struct _alias_t
{
static constexpr const char _literal[] = "col_day_point";
static constexpr const char _literal[] = "id";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T colDayPoint;
T& operator()()
{
return colDayPoint;
}
const T& operator()() const
T id;
T& operator()() { return id; }
const T& operator()() const { return id; }
};
};
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update>;
};
struct DayPointN
{
struct _alias_t
{
static constexpr const char _literal[] = "day_point_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
return colDayPoint;
}
};
T dayPointN;
T& operator()() { return dayPointN; }
const T& operator()() const { return dayPointN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::day_point, sqlpp::tag::can_be_null>;
};
struct ColTimePoint
struct TimePointN
{
struct _alias_t
{
static constexpr const char _literal[] = "col_time_point";
static constexpr const char _literal[] = "time_point_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T colTimePoint;
T& operator()()
{
return colTimePoint;
}
const T& operator()() const
{
return colTimePoint;
}
};
T timePointN;
T& operator()() { return timePointN; }
const T& operator()() const { return timePointN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::time_point, sqlpp::tag::can_be_null>;
};
struct ColTimeOfDay
struct TimeOfDayN
{
struct _alias_t
{
static constexpr const char _literal[] = "col_time_of_day";
static constexpr const char _literal[] = "time_of_day_n";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T colTimeOfDay;
T& operator()()
{
return colTimeOfDay;
}
const T& operator()() const
{
return colTimeOfDay;
}
};
T timeOfDayN;
T& operator()() { return timeOfDayN; }
const T& operator()() const { return timeOfDayN; }
};
};
using _traits = sqlpp::make_traits<sqlpp::time_of_day, sqlpp::tag::can_be_null>;
};
} // namespace TabDateTime_
} // namespace TabDateTime_
struct TabDateTime
: sqlpp::table_t<TabDateTime, TabDateTime_::ColDayPoint, TabDateTime_::ColTimePoint, TabDateTime_::ColTimeOfDay>
struct TabDateTime: sqlpp::table_t<TabDateTime,
TabDateTime_::Id,
TabDateTime_::DayPointN,
TabDateTime_::TimePointN,
TabDateTime_::TimeOfDayN>
{
struct _alias_t
{
static constexpr const char _literal[] = "tab_date_time";
static constexpr const char _literal[] = "tab_date_time";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
template<typename T>
struct _member_t
{
T tabDateTime;
T& operator()()
{
return tabDateTime;
}
const T& operator()() const
{
return tabDateTime;
}
T& operator()() { return tabDateTime; }
const T& operator()() const { return tabDateTime; }
};
};
};
} // namespace test
} // namespace test

View File

@ -35,16 +35,6 @@
#include <sqlpp11/without_table_check.h>
#include "../../include/test_helpers.h"
template <typename Db, typename Column>
int64_t getColumn(Db&& db, const Column& column)
{
auto result = db(select(column.as(sqlpp::alias::a)).from(column.table()).unconditionally());
if (not result.empty() and result.front().a.has_value())
return result.front().a.value();
else
return 0;
}
struct to_cerr
{
template <typename Field>
@ -57,8 +47,8 @@ struct to_cerr
template <typename Row>
void print_row(Row const& row)
{
const sqlpp::compat::optional<int64_t> a = row.alpha;
const sqlpp::compat::optional<sqlpp::compat::string_view> b = row.beta;
const sqlpp::compat::optional<int64_t> a = row.id;
const sqlpp::compat::optional<sqlpp::compat::string_view> b = row.textN;
std::cout << a << ", " << b << std::endl;
}
@ -73,8 +63,7 @@ int Select(int, char*[])
const auto t = test::TabBar{};
const auto tab_a = f.as(sqlpp::alias::a);
getColumn(db, t.alpha);
select(count(t.alpha));
select(count(t.id));
std::cerr << serialize(select(sqlpp::value(false).as(sqlpp::alias::a)), printer).str() << std::endl;
for (const auto& row : db(select(sqlpp::value(false).as(sqlpp::alias::a))))
@ -91,39 +80,39 @@ int Select(int, char*[])
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
{
const sqlpp::compat::optional<int64_t> a = row.alpha;
const sqlpp::compat::optional<sqlpp::compat::string_view> b = row.beta;
const sqlpp::compat::optional<int64_t> a = row.id;
const sqlpp::compat::optional<sqlpp::compat::string_view> b = row.textN;
std::cout << a << ", " << b << std::endl;
}
for (const auto& row :
db(select(all_of(t), t.gamma.as(t)).from(t).where(t.alpha > 7 and trim(t.beta) == "test").for_update()))
db(select(all_of(t), t.boolNn.as(t)).from(t).where(t.id > 7 and trim(t.textN) == "test").for_update()))
{
const sqlpp::compat::optional<int64_t> a = row.alpha;
const sqlpp::compat::optional<sqlpp::compat::string_view> b = row.beta;
const sqlpp::compat::optional<int64_t> a = row.id;
const sqlpp::compat::optional<sqlpp::compat::string_view> b = row.textN;
const bool g = row.tabBar;
std::cout << a << ", " << b << ", " << g << std::endl;
}
for (const auto& row :
db(select(all_of(t), all_of(f)).from(t.join(f).on(t.alpha > f.omega and not t.gamma)).unconditionally()))
db(select(all_of(t), f.textNnD).from(t.join(f).on(t.id > f.doubleN and not t.boolNn)).unconditionally()))
{
std::cout << row.alpha << std::endl;
std::cout << row.id << std::endl;
}
for (const auto& row : db(select(all_of(t), all_of(f))
.from(t.join(f).on(t.alpha > f.omega).join(tab_a).on(t.alpha == tab_a.omega))
for (const auto& row : db(select(all_of(t), f.textNnD)
.from(t.join(f).on(t.id > f.doubleN).join(tab_a).on(t.id == tab_a.doubleN))
.unconditionally()))
{
std::cout << row.alpha << std::endl;
std::cout << row.id << std::endl;
}
for (const auto& row : db(select(count(t.alpha), avg(t.alpha)).from(t).unconditionally()))
for (const auto& row : db(select(count(t.id), avg(t.id)).from(t).unconditionally()))
{
std::cout << row.count << std::endl;
}
for (const auto& row : db(select(count(t.alpha), avg(t.alpha)).from(t).where(t.alpha == 0)))
for (const auto& row : db(select(count(t.id), avg(t.id)).from(t).where(t.id == 0)))
{
std::cout << row.count << std::endl;
}
@ -132,41 +121,41 @@ int Select(int, char*[])
.columns(all_of(t))
.flags(sqlpp::all)
.from(t)
.where(t.alpha > 0)
.group_by(t.alpha)
.order_by(t.gamma.asc())
.having(t.gamma)
.where(t.id > 0)
.group_by(t.id)
.order_by(t.boolNn.asc())
.having(t.boolNn)
.offset(19u)
.limit(7u);
printer.reset();
std::cerr << serialize(stat, printer).str() << std::endl;
auto s = sqlpp::select()
.columns(t.alpha)
.columns(t.id)
.flags(sqlpp::distinct)
.from(t)
.where(t.alpha > 3)
.group_by(t.alpha)
.order_by(t.beta.asc())
.having(sum(t.alpha) > parameter(t.delta))
.where(t.id > 3)
.group_by(t.id)
.order_by(t.textN.asc())
.having(sum(t.id) > parameter(t.intN))
.limit(32u)
.offset(7u);
#warning add tests for optional everything
for (const auto& row : db(db.prepare(s)))
{
const sqlpp::compat::optional<int64_t> a = row.alpha;
const sqlpp::compat::optional<int64_t> a = row.id;
std::cout << a << std::endl;
}
printer.reset();
std::cerr << serialize(s, printer).str() << std::endl;
select(sqlpp::value(7).as(t.alpha));
select(sqlpp::value(7).as(t.id));
for (const auto& row :
db(select(sqlpp::case_when(true).then(t.beta).else_(sqlpp::null).as(t.beta)).from(t).unconditionally()))
db(select(sqlpp::case_when(true).then(t.textN).else_(sqlpp::null).as(t.textN)).from(t).unconditionally()))
{
std::cerr << row.beta << std::endl;
std::cerr << row.textN << std::endl;
}
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
@ -191,9 +180,9 @@ int Select(int, char*[])
}
for (const auto& row :
db(select(f.omega, select(count(t.alpha)).from(t).unconditionally().as(cheese)).from(f).unconditionally()))
db(select(f.doubleN, select(count(t.id)).from(t).unconditionally().as(cheese)).from(f).unconditionally()))
{
std::cout << row.omega << " " << row.cheese << std::endl;
std::cout << row.doubleN << " " << row.cheese << std::endl;
}
return 0;

View File

@ -88,7 +88,7 @@ int SelectType(int, char*[])
// Test an integral column of an alias of table
{
using T = decltype(t.as(alias::a).alpha);
using T = decltype(t.as(alias::a).id);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_integral_t<T>::value, "type requirement");
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
@ -106,7 +106,7 @@ int SelectType(int, char*[])
// Test an integral table column
{
using T = decltype(t.alpha);
using T = decltype(t.id);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_integral_t<T>::value, "type requirement");
static_assert(not sqlpp::is_unsigned_integral_t<T>::value, "type requirement");
@ -125,7 +125,7 @@ int SelectType(int, char*[])
// Test an unsigned integral table column
{
using T = decltype(f.psi);
using T = decltype(f.uIntN);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
static_assert(sqlpp::is_unsigned_integral_t<T>::value, "type requirement");
@ -176,7 +176,7 @@ int SelectType(int, char*[])
// Test a floating point table column
{
using T = decltype(f.omega);
using T = decltype(f.doubleN);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
static_assert(sqlpp::is_floating_point_t<T>::value, "type requirement");
@ -194,7 +194,7 @@ int SelectType(int, char*[])
// Test a an alias of a numeric table column
{
using T = decltype(t.alpha.as(alias::a));
using T = decltype(t.id.as(alias::a));
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
@ -210,7 +210,7 @@ int SelectType(int, char*[])
// Test a select of a single column without a from
{
using T = decltype(select(t.alpha));
using T = decltype(select(t.id));
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
@ -226,7 +226,7 @@ int SelectType(int, char*[])
// Test a select of a single numeric table column
{
using T = decltype(select(t.alpha).from(t));
using T = decltype(select(t.id).from(t));
// static_assert(sqlpp::is_select_column_list_t<decltype(T::_column_list)>::value, "Must not be noop");
// static_assert(sqlpp::is_from_t<decltype(T::_from)>::value, "Must not be noop");
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
@ -244,7 +244,7 @@ int SelectType(int, char*[])
// Test a select of an alias of a single numeric table column
{
using T = decltype(select(t.alpha.as(alias::a)).from(t));
using T = decltype(select(t.id.as(alias::a)).from(t));
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
@ -260,7 +260,7 @@ int SelectType(int, char*[])
// Test an alias of a select of a single numeric table column
{
using T = decltype(select(t.alpha).from(t).as(alias::b));
using T = decltype(select(t.id).from(t).as(alias::b));
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
@ -276,7 +276,7 @@ int SelectType(int, char*[])
// Test the column of an alias of a select of an alias of a single numeric table column
{
using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b));
using T = decltype(select(t.id.as(alias::a)).from(t).as(alias::b));
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
@ -292,7 +292,7 @@ int SelectType(int, char*[])
// Test the column of an alias of a select of a single numeric table column
{
using T = decltype(select(t.alpha).from(t).as(alias::b).alpha);
using T = decltype(select(t.id).from(t).as(alias::b).id);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
@ -308,7 +308,7 @@ int SelectType(int, char*[])
// Test an alias of a select of an alias of a single numeric table column
{
using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b).a);
using T = decltype(select(t.id.as(alias::a)).from(t).as(alias::b).a);
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
@ -325,28 +325,31 @@ int SelectType(int, char*[])
// Test that all_of(tab) is expanded in select
{
auto a = select(all_of(t));
auto b = select(t.alpha, t.beta, t.gamma, t.delta);
auto b = select(t.id, t.textN, t.boolNn, t.intN);
// auto c = select(t);
static_assert(std::is_same<decltype(a), decltype(b)>::value, "all_of(t) has to be expanded by select()");
// static_assert(std::is_same<decltype(b), decltype(c)>::value, "t has to be expanded by select()");
}
// Test that result sets with identical name/value combinations have identical types
#warning: reactivate after renaming concluded
#if 0
{
auto a = select(t.alpha);
auto b = select(f.epsilon.as(t.alpha));
auto a = select(t.id);
auto b = select(f.intN.as(t.id));
using A = typename decltype(a)::_result_row_t<MockDb>;
using B = typename decltype(b)::_result_row_t<MockDb>;
static_assert(
std::is_same<sqlpp::value_type_of<decltype(t.alpha)>, sqlpp::value_type_of<decltype(f.epsilon)>>::value,
std::is_same<sqlpp::value_type_of<decltype(t.id)>, sqlpp::value_type_of<decltype(f.intN)>>::value,
"Two bigint columns must have identical base_value_type");
static_assert(std::is_same<A, B>::value,
"select with identical columns(name/value_type) need to have identical result_types");
}
#endif
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
{
const auto a = row.alpha;
const auto a = row.id;
std::cout << a << std::endl;
}
@ -354,8 +357,8 @@ int SelectType(int, char*[])
/*
{
auto s = dynamic_select(db, all_of(t)).dynamic_from(t).dynamic_where().dynamic_limit().dynamic_offset();
s.from.add(dynamic_join(f).on(f.omega > t.alpha));
s.where.add(without_table_check(f.omega > 7 and t.alpha == any(select(t.alpha).from(t).where(t.alpha < 3))));
s.from.add(dynamic_join(f).on(f.doubleN > t.id));
s.where.add(without_table_check(f.doubleN > 7 and t.id == any(select(t.id).from(t).where(t.id < 3))));
s.limit.set(30u);
s.limit.set(3u);
std::cerr << "------------------------\n";
@ -368,20 +371,20 @@ int SelectType(int, char*[])
// Test that select can be called with zero columns if it is used with dynamic columns.
{
auto s = dynamic_select(db).dynamic_columns();
s.selected_columns.add(without_table_check(t.alpha));
s.selected_columns.add(without_table_check(t.id));
serialize(s, printer).str();
}
{
auto find_query = sqlpp::dynamic_select(db).dynamic_columns(t.alpha.as(alias::a)).dynamic_from(t).unconditionally();
find_query.from.add(sqlpp::dynamic_join(f).on(t.alpha == f.omega));
find_query.selected_columns.add(sqlpp::without_table_check(f.omega.as(alias::b)));
auto find_query = sqlpp::dynamic_select(db).dynamic_columns(t.id.as(alias::a)).dynamic_from(t).unconditionally();
find_query.from.add(sqlpp::dynamic_join(f).on(t.id == f.doubleN));
find_query.selected_columns.add(sqlpp::without_table_check(f.doubleN.as(alias::b)));
}
*/
// Test that verbatim_table compiles
{
auto s = select(t.alpha).from(sqlpp::verbatim_table("my_unknown_table"));
auto s = select(t.id).from(sqlpp::verbatim_table("my_unknown_table"));
serialize(s, printer).str();
}
@ -390,33 +393,33 @@ int SelectType(int, char*[])
static_assert(sqlpp::is_regular<T>::value, "type requirement");
static_assert(sqlpp::is_expression_t<T>::value, "T has to be an expression");
static_assert(sqlpp::is_numeric_t<T>::value, "T has to be numeric");
static_assert(sqlpp::is_numeric_t<decltype(t.alpha)>::value, "TabBar.alpha has to be a numeric");
((t.alpha + 7) + 4).asc();
static_assert(sqlpp::is_boolean_t<decltype(t.gamma != not(t.gamma))>::value,
static_assert(sqlpp::is_numeric_t<decltype(t.id)>::value, "TabBar.id has to be a numeric");
((t.id + 7) + 4).asc();
static_assert(sqlpp::is_boolean_t<decltype(t.boolNn != not(t.boolNn))>::value,
"Comparison expression have to be boolean");
!t.gamma;
serialize(t.beta < "kaesekuchen", printer).str();
serialize(t.beta + "hallenhalma", printer).str();
static_assert(sqlpp::must_not_insert_t<decltype(t.alpha)>::value, "alpha must not be inserted");
serialize(t.alpha, printer).str();
!t.boolNn;
serialize(t.textN < "kaesekuchen", printer).str();
serialize(t.textN + "hallenhalma", printer).str();
static_assert(sqlpp::must_not_insert_t<decltype(t.id)>::value, "id must not be inserted");
serialize(t.id, printer).str();
std::cerr << "\n" << sizeof(test::TabBar) << std::endl;
static_assert(sqlpp::is_selectable_t<decltype(t.alpha)>::value, "alpha should be a named expression");
static_assert(sqlpp::is_selectable_t<decltype(t.alpha.as(alias::a))>::value,
"an alias of alpha should be a named expression");
static_assert(sqlpp::is_alias_t<decltype(t.alpha.as(alias::a))>::value, "an alias of alpha should be an alias");
static_assert(sqlpp::is_selectable_t<decltype(t.id)>::value, "id should be a named expression");
static_assert(sqlpp::is_selectable_t<decltype(t.id.as(alias::a))>::value,
"an alias of id should be a named expression");
static_assert(sqlpp::is_alias_t<decltype(t.id.as(alias::a))>::value, "an alias of id should be an alias");
auto l = t.as(alias::left);
auto r = select(t.gamma.as(alias::a)).from(t).where(t.gamma == true).as(alias::right);
static_assert(sqlpp::is_boolean_t<decltype(select(t.gamma).from(t))>::value, "select(bool) has to be a bool");
auto r = select(t.boolNn.as(alias::a)).from(t).where(t.boolNn == true).as(alias::right);
static_assert(sqlpp::is_boolean_t<decltype(select(t.boolNn).from(t))>::value, "select(bool) has to be a bool");
static_assert(sqlpp::is_boolean_t<decltype(select(r.a).from(r))>::value, "select(bool) has to be a bool");
auto s1 = sqlpp::select()
.flags(sqlpp::distinct, sqlpp::straight_join)
.columns(l.gamma, r.a)
.columns(l.boolNn, r.a)
.from(r.cross_join(t).cross_join(l))
.where(t.beta == "hello world" and select(t.gamma).from(t)) // .as(alias::right))
.group_by(l.gamma, r.a)
.where(t.textN == "hello world" and select(t.boolNn).from(t)) // .as(alias::right))
.group_by(l.boolNn, r.a)
.having(r.a != true)
.order_by(l.beta.asc())
.order_by(l.textN.asc())
.limit(17u)
.offset(3u)
.as(alias::a);

View File

@ -31,8 +31,8 @@
namespace greek
{
SQLPP_ALIAS_PROVIDER(alpha)
SQLPP_ALIAS_PROVIDER(beta)
SQLPP_ALIAS_PROVIDER(id)
SQLPP_ALIAS_PROVIDER(textN)
}
int Union(int, char* [])
@ -43,32 +43,35 @@ int Union(int, char* [])
const auto t = test::TabBar{};
const auto f = test::TabFoo{};
db(select(t.alpha).from(t).unconditionally().union_distinct(select(f.epsilon.as(t.alpha)).from(f).unconditionally()));
db(select(t.alpha).from(t).unconditionally().union_all(select(f.epsilon.as(t.alpha)).from(f).unconditionally()));
#warning: reactive after renaming
#if 0
db(select(t.id).from(t).unconditionally().union_distinct(select(f.intN.as(t.id)).from(f).unconditionally()));
db(select(t.id).from(t).unconditionally().union_all(select(f.intN.as(t.id)).from(f).unconditionally()));
// t.alpha can be null, a given value cannot
db(select(t.alpha).from(t).unconditionally().union_all(select(sqlpp::value(1).as(t.alpha))));
db(select(t.alpha).from(t).unconditionally().union_all(select(sqlpp::value(1).as(greek::alpha))));
// t.id can be null, a given value cannot
db(select(t.id).from(t).unconditionally().union_all(select(sqlpp::value(1).as(t.id))));
db(select(t.id).from(t).unconditionally().union_all(select(sqlpp::value(1).as(greek::id))));
// t.beta can be null, f.delta cannot
static_assert(sqlpp::can_be_null_t<decltype(t.beta)>::value, "");
static_assert(!sqlpp::can_be_null_t<decltype(f.delta)>::value, "");
db(select(t.beta).from(t).unconditionally().union_all(select(f.delta.as(greek::beta)).from(f).unconditionally()));
// t.textN can be null, f.textNnD cannot
static_assert(sqlpp::can_be_null_t<decltype(t.textN)>::value, "");
static_assert(!sqlpp::can_be_null_t<decltype(f.textNnD)>::value, "");
db(select(t.textN).from(t).unconditionally().union_all(select(f.textNnD.as(greek::textN)).from(f).unconditionally()));
auto u = select(t.alpha)
auto u = select(t.id)
.from(t)
.unconditionally()
.union_all(select(f.epsilon.as(t.alpha)).from(f).unconditionally())
.union_all(select(f.intN.as(t.id)).from(f).unconditionally())
.as(sqlpp::alias::u);
db(select(all_of(u)).from(u).unconditionally().union_all(select(t.delta.as(t.alpha)).from(t).unconditionally()));
db(select(u.alpha).from(u).unconditionally().union_all(select(t.delta.as(t.alpha)).from(t).unconditionally()));
db(select(all_of(u)).from(u).unconditionally().union_all(select(t.intN.as(t.id)).from(t).unconditionally()));
db(select(u.id).from(u).unconditionally().union_all(select(t.intN.as(t.id)).from(t).unconditionally()));
db(select(t.alpha)
db(select(t.id)
.from(t)
.unconditionally()
.union_all(select(t.alpha).from(t).unconditionally())
.union_all(select(t.alpha).from(t).unconditionally()));
.union_all(select(t.id).from(t).unconditionally())
.union_all(select(t.id).from(t).unconditionally()));
#endif
return 0;
}

View File

@ -42,26 +42,26 @@ int Update(int, char*[])
}
{
using T = decltype(update(t).set(t.gamma = false).where(t.beta != "transparent"));
using T = decltype(update(t).set(t.boolNn = false).where(t.textN != "transparent"));
static_assert(sqlpp::is_regular<T>::value, "type requirement");
}
serialize(update(t), printer).str();
serialize(update(t).set(t.gamma = false), printer).str();
serialize(update(t).set(t.gamma = false).where(t.beta != "transparent"), printer).str();
serialize(update(t).set(t.beta = "opaque").where(t.beta != t.beta + "this is nonsense"), printer).str();
auto values = [&t]() { return std::make_tuple(t.delta += t.alpha, t.beta = "no cake this time"); };
serialize(update(t).set(t.boolNn = false), printer).str();
serialize(update(t).set(t.boolNn = false).where(t.textN != "transparent"), printer).str();
serialize(update(t).set(t.textN = "opaque").where(t.textN != t.textN + "this is nonsense"), printer).str();
auto values = [&t]() { return std::make_tuple(t.intN += t.id, t.textN = "no cake this time"); };
#warning add tests with dynamic set and dynamic where
db(update(t).set(t.delta = sqlpp::verbatim<sqlpp::integer>("17+4")).unconditionally());
db(update(t).set(t.intN = sqlpp::verbatim<sqlpp::integer>("17+4")).unconditionally());
db(update(t)
.set(t.delta = sqlpp::verbatim<sqlpp::integer>("17+4"))
.set(t.intN = sqlpp::verbatim<sqlpp::integer>("17+4"))
.where(sqlpp::verbatim<sqlpp::text>("'hansi'") == "hansi"));
db(update(t).set(t.delta = sqlpp::null).unconditionally());
db(update(t).set(t.delta = sqlpp::default_value).unconditionally());
db(update(t).set(t.intN = sqlpp::null).unconditionally());
db(update(t).set(t.intN = sqlpp::default_value).unconditionally());
db(update(t).set(t.delta += t.alpha * 2, t.beta += " and cake").unconditionally());
db(update(t).set(t.intN += t.id * 2, t.textN += " and cake").unconditionally());
db(update(t).set(values()).unconditionally());
return 0;
}

View File

@ -39,7 +39,7 @@ int With(int, char*[])
auto x = sqlpp::cte(sqlpp::alias::x).as(select(all_of(t)).from(t));
db(with(x)(select(x.alpha).from(x).unconditionally()));
db(with(x)(select(x.id).from(x).unconditionally()));
auto y0 = sqlpp::cte(sqlpp::alias::y).as(select(all_of(t)).from(t));
auto y = y0.union_all(select(all_of(y0)).from(y0).unconditionally());
@ -48,21 +48,21 @@ int With(int, char*[])
printer.reset();
std::cout << serialize(from_table(y), printer).str() << std::endl;
db(with(y)(select(y.alpha).from(y).unconditionally()));
db(with(y)(select(y.id).from(y).unconditionally()));
using ::sqlpp::alias::a;
using ::sqlpp::alias::b;
const auto c =
sqlpp::cte(b).as(select(t.alpha.as(a)).from(t).unconditionally().union_all(select(sqlpp::value(123).as(a))));
sqlpp::cte(b).as(select(t.id.as(a)).from(t).unconditionally().union_all(select(sqlpp::value(123).as(a))));
db(with(c)(select(all_of(c)).from(c).unconditionally()));
// recursive CTE with join
{
const auto selectBase = select(t.alpha, t.delta).from(t).where(t.alpha > 17);
const auto selectBase = select(t.id, t.intN).from(t).where(t.id > 17);
const auto initialCte = ::sqlpp::cte(sqlpp::alias::a).as(selectBase);
const auto recursiveCte = initialCte.union_all(
select(t.alpha, t.delta).from(t.join(initialCte).on(t.alpha == initialCte.delta)).unconditionally());
const auto query = with(recursiveCte)(select(recursiveCte.alpha).from(recursiveCte).unconditionally());
select(t.id, t.intN).from(t.join(initialCte).on(t.id == initialCte.intN)).unconditionally());
const auto query = with(recursiveCte)(select(recursiveCte.id).from(recursiveCte).unconditionally());
printer.reset();
const auto serializedQuery = serialize(query, printer).str();
@ -70,7 +70,7 @@ int With(int, char*[])
for (const auto& row : db(query))
{
std::cout << row.alpha;
std::cout << row.id;
}
}

View File

@ -26,25 +26,27 @@
CREATE TABLE IF NOT EXISTS tab_foo
(
delta varchar(255) NOT NULL DEFAULT "",
epsilon bigint,
omega double,
psi bigint UNSIGNED,
book BLOB
id bigint AUTO_INCREMENT PRIMARY KEY,
text_nn_d varchar(255) NOT NULL DEFAULT "",
int_n bigint,
double_n double,
u_int_n bigint UNSIGNED,
blob_n BLOB
);
CREATE TABLE tab_bar
(
alpha bigint AUTO_INCREMENT,
beta varchar(255) NULL DEFAULT "",
gamma bool NOT NULL,
delta int
id bigint AUTO_INCREMENT PRIMARY KEY,
text_n varchar(255) NULL DEFAULT "",
bool_nn bool NOT NULL,
int_n int
);
CREATE TABLE tab_date_time
(
col_day_point date,
col_time_point datetime,
col_time_of_day time
id bigint AUTO_INCREMENT PRIMARY KEY,
day_point_n date,
time_point_n datetime,
time_of_day_n time
);