mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-15 20:31:16 +08:00
Added a bunch of table tests to select
And some hints regarding additional tests and how to turn them of for subselects
This commit is contained in:
parent
dba5c992ed
commit
6737bf901d
@ -44,6 +44,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
using _name_t = typename AliasProvider::_name_t;
|
||||
using _table_set = typename Expression::_table_set;
|
||||
|
||||
Expression _expression;
|
||||
};
|
||||
|
@ -391,9 +391,6 @@ namespace sqlpp
|
||||
return _column_list_t::static_size() + get_dynamic_names().size();
|
||||
}
|
||||
|
||||
template<typename Db>
|
||||
struct can_run_t
|
||||
{
|
||||
/*
|
||||
static_assert(column_list::_table_set::template is_subset_t<_from_t::_table_set>::value
|
||||
static_assert(detail::is_subset_of<column_list::_table_set, _from_t::_table_set>::value
|
||||
@ -406,8 +403,10 @@ namespace sqlpp
|
||||
//static_assert(is_where_t<Where>::value, "cannot run select without having a where condition, use .where(true) to select all rows");
|
||||
// FIXME: Check for missing aliases (if references are used)
|
||||
// FIXME: Check for missing tables, well, actually, check for missing tables at the where(), order_by(), etc.
|
||||
|
||||
static constexpr bool value = true;
|
||||
template<typename A>
|
||||
struct is_table_subset_of_from
|
||||
{
|
||||
static constexpr bool value = ::sqlpp::detail::is_subset_of<typename A::_table_set, typename From::_table_set>::value;
|
||||
};
|
||||
|
||||
// Execute
|
||||
@ -415,7 +414,16 @@ namespace sqlpp
|
||||
auto _run(Db& db) const
|
||||
-> result_t<decltype(db.select(*this)), _result_row_t<Db>>
|
||||
{
|
||||
static_assert(can_run_t<Db>::value, "Cannot execute select statement");
|
||||
#warning: need to check in add_xy method as well
|
||||
#warning: need add_wxy_without_table_check
|
||||
#warning: might want to add an .extra_tables() method to say which tables might also be used here, say via dynamic_from or because this is a subselect
|
||||
static_assert(is_table_subset_of_from<ColumnList>::value, "selected columns require additional tables in from()");
|
||||
static_assert(is_table_subset_of_from<Where>::value, "where() expression requires additional tables in from()");
|
||||
static_assert(is_table_subset_of_from<GroupBy>::value, "group_by() expression requires additional tables in from()");
|
||||
static_assert(is_table_subset_of_from<Having>::value, "having() expression requires additional tables in from()");
|
||||
static_assert(is_table_subset_of_from<OrderBy>::value, "order_by() expression requires additional tables in from()");
|
||||
static_assert(is_table_subset_of_from<Limit>::value, "limit() expression requires additional tables in from()");
|
||||
static_assert(is_table_subset_of_from<Offset>::value, "offset() expression requires additional tables in from()");
|
||||
static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead");
|
||||
return {db.select(*this), get_dynamic_names()};
|
||||
}
|
||||
@ -425,7 +433,6 @@ namespace sqlpp
|
||||
auto _prepare(Db& db) const
|
||||
-> prepared_select_t<Db, select_t>
|
||||
{
|
||||
static_assert(can_run_t<Db>::value, "Cannot prepare select statement");
|
||||
|
||||
return {{}, get_dynamic_names(), db.prepare_select(*this)};
|
||||
}
|
||||
|
2
include/sqlpp11/vendor/from.h
vendored
2
include/sqlpp11/vendor/from.h
vendored
@ -51,7 +51,7 @@ namespace sqlpp
|
||||
|
||||
static_assert(::sqlpp::detail::all_t<is_table_t, Tables...>::value, "at least one argument is not a table or join in from()");
|
||||
|
||||
using _table_set = typename ::sqlpp::detail::make_joined_set<typename Tables::_table_set...>;
|
||||
using _table_set = ::sqlpp::detail::make_joined_set_t<typename Tables::_table_set...>;
|
||||
|
||||
|
||||
from_t(Tables... tables):
|
||||
|
1
include/sqlpp11/vendor/group_by.h
vendored
1
include/sqlpp11/vendor/group_by.h
vendored
@ -78,6 +78,7 @@ namespace sqlpp
|
||||
struct no_group_by_t
|
||||
{
|
||||
using _is_noop = std::true_type;
|
||||
using _table_set = ::sqlpp::detail::type_set<>;
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
|
1
include/sqlpp11/vendor/having.h
vendored
1
include/sqlpp11/vendor/having.h
vendored
@ -75,6 +75,7 @@ namespace sqlpp
|
||||
struct no_having_t
|
||||
{
|
||||
using _is_noop = std::true_type;
|
||||
using _table_set = ::sqlpp::detail::type_set<>;
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
|
3
include/sqlpp11/vendor/limit.h
vendored
3
include/sqlpp11/vendor/limit.h
vendored
@ -29,6 +29,7 @@
|
||||
|
||||
#include <sqlpp11/type_traits.h>
|
||||
#include <sqlpp11/vendor/policy_update.h>
|
||||
#include <sqlpp11/detail/type_set.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
@ -40,6 +41,7 @@ namespace sqlpp
|
||||
{
|
||||
using _is_limit = std::true_type;
|
||||
static_assert(is_integral_t<Limit>::value, "limit requires an integral value or integral parameter");
|
||||
using _table_set = ::sqlpp::detail::type_set<>;
|
||||
|
||||
limit_t(Limit value):
|
||||
_value(value)
|
||||
@ -93,6 +95,7 @@ namespace sqlpp
|
||||
struct no_limit_t
|
||||
{
|
||||
using _is_noop = std::true_type;
|
||||
using _table_set = ::sqlpp::detail::type_set<>;
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
|
2
include/sqlpp11/vendor/offset.h
vendored
2
include/sqlpp11/vendor/offset.h
vendored
@ -29,6 +29,7 @@
|
||||
|
||||
#include <sqlpp11/type_traits.h>
|
||||
#include <sqlpp11/vendor/policy_update.h>
|
||||
#include <sqlpp11/detail/type_set.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
@ -93,6 +94,7 @@ namespace sqlpp
|
||||
struct no_offset_t
|
||||
{
|
||||
using _is_noop = std::true_type;
|
||||
using _table_set = ::sqlpp::detail::type_set<>;
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
|
2
include/sqlpp11/vendor/order_by.h
vendored
2
include/sqlpp11/vendor/order_by.h
vendored
@ -33,6 +33,7 @@
|
||||
#include <sqlpp11/vendor/interpretable.h>
|
||||
#include <sqlpp11/vendor/policy_update.h>
|
||||
#include <sqlpp11/detail/logic.h>
|
||||
#include <sqlpp11/detail/type_set.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
@ -75,6 +76,7 @@ namespace sqlpp
|
||||
struct no_order_by_t
|
||||
{
|
||||
using _is_noop = std::true_type;
|
||||
using _table_set = ::sqlpp::detail::type_set<>;
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
|
@ -61,13 +61,11 @@ int main()
|
||||
const std::string b = row.tabBar.beta;
|
||||
}
|
||||
|
||||
#warning this should fail because f is not in from()
|
||||
for (const auto& row : db(select(f.omega, all_of(t).as(t), t.gamma).from(t).where(true)))
|
||||
for (const auto& row : db(select(all_of(t).as(t), t.gamma).from(t).where(t.alpha > 7)))
|
||||
{
|
||||
int64_t a = row.tabBar.alpha;
|
||||
const std::string b = row.tabBar.beta;
|
||||
const bool g = row.gamma;
|
||||
const float o = row.omega;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user