0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Added portable static asserts

This commit is contained in:
rbock 2014-11-23 20:06:58 +01:00
parent 77d737b401
commit e1c007287c
5 changed files with 58 additions and 10 deletions

View File

@ -34,6 +34,9 @@
#include "MockDb.h"
#include <sqlpp11/sqlpp11.h>
static constexpr bool some_condition = true;
static constexpr bool some_other_condition = false;
SQLPP_ALIAS_PROVIDER(cheesecake);
MockDb db;
@ -91,8 +94,8 @@ int main()
#if !0
auto s = select(all_of(p))
#if 0
auto s = select(p.id, p.name, f.id.as(cheesecake))
.from(p, f)
.where(p.name == any(select(f.name)
.from(f)
@ -103,12 +106,32 @@ int main()
.limit(3).offset(7);
auto x = s.as(sqlpp::alias::x);
for (const auto& row : db(select(p.id, x.name)
.from(p.join(x).on(p.feature == x.feature))
for (const auto& row : db(select(p.id, p.name, all_of(x).as(x))
.from(p.join(x).on(p.feature == x.cheesecake))
.where(true)))
{
int id = row.id;
std::string name = row.name;
std::string x_name = row.x.name;
int cheesecake = row.x.cheesecake;
}
#endif
#if !0
auto dysel = dynamic_select(db).dynamic_columns(p.name).from(p).dynamic_where();
if (some_condition)
dysel.selected_columns.add(p.feature);
if (some_other_condition)
dysel.where.add(p.id > 17);
for (const auto& row : db(dysel))
{
std::string name = row.name;
std::string feature = row.at("feature");
}
#endif
@ -129,7 +152,5 @@ int main()
}

View File

@ -122,6 +122,17 @@ namespace sqlpp
interpretable_list_t<Database> _dynamic_values;
};
struct assert_no_unknown_tables_in_insert_assignments_t
{
using type = std::false_type;
template<typename T = void>
static void _()
{
static_assert(wrong_t<T>::value, "at least one insert assignment requires a table which is otherwise not known in the statement");
}
};
template<typename Database, typename... Assignments>
struct insert_list_t
{
@ -200,7 +211,9 @@ namespace sqlpp
template<typename Policies>
struct _methods_t
{
using _consistency_check = consistent_t;
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<insert_list_t>::value,
consistent_t,
assert_no_unknown_tables_in_insert_assignments_t>::type;
};
};

View File

@ -147,6 +147,17 @@ namespace sqlpp
dynamic_select_column_list<Database> _dynamic_columns;
};
struct assert_no_unknown_tables_in_selected_columns_t
{
using type = std::false_type;
template<typename T = void>
static void _()
{
static_assert(wrong_t<T>::value, "at least one selected column requires a table which is otherwise not known in the statement");
}
};
// SELECTED COLUMNS
template<typename Database, typename... Columns>
@ -231,7 +242,9 @@ namespace sqlpp
template<typename Policies>
struct _methods_t
{
using _consistency_check = consistent_t;
using _consistency_check = typename std::conditional<Policies::template _no_unknown_tables<select_column_list_t>::value,
consistent_t,
assert_no_unknown_tables_in_selected_columns_t>::type;
};
// Result methods

View File

@ -149,9 +149,9 @@ namespace sqlpp
consistent_t, assert_no_parameters_t>::type;
using _run_check = detail::get_first_if<is_inconsistent_t, consistent_t,
_table_check, _parameter_check, typename Policies::template _methods_t<statement_policies_t>::_consistency_check...>;
_parameter_check, typename Policies::template _methods_t<statement_policies_t>::_consistency_check..., _table_check>;
using _prepare_check = detail::get_first_if<is_inconsistent_t, consistent_t,
_table_check, typename Policies::template _methods_t<statement_policies_t>::_consistency_check...>;
typename Policies::template _methods_t<statement_policies_t>::_consistency_check..., _table_check>;
};
}

View File

@ -128,6 +128,7 @@ namespace sqlpp
template<typename Policies>
struct _methods_t
{
#warning: here and elsewhere: add check for missing tables (see select columns, for instance)
using _consistency_check = consistent_t;
};
};