Added a .where(bool) to choose all or no row

This commit is contained in:
rbock
2014-01-22 22:53:23 +01:00
parent 6e55f8f6cd
commit 019a920739
5 changed files with 31 additions and 1 deletions

View File

@@ -150,6 +150,7 @@ namespace sqlpp
std::size_t run(Db& db) const
{
static_assert(_get_static_no_of_parameters() == 0, "cannot run remove directly with parameters, use prepare instead");
static_assert(is_where_t<Where>::value, "cannot run update without having a where condition, use .where(true) to remove all rows");
return db.remove(*this);
}

View File

@@ -620,6 +620,7 @@ namespace sqlpp
{
static_assert(not vendor::is_noop<ColumnList>::value, "cannot run select without having selected anything");
static_assert(is_from_t<From>::value, "cannot run select without a from()");
static_assert(is_where_t<Where>::value, "cannot run select without having a where condition, use .where(true) to select all rows");
static_assert(_get_static_no_of_parameters() == 0, "cannot run select directly with parameters, use prepare instead");
// 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.

View File

@@ -149,6 +149,7 @@ namespace sqlpp
std::size_t run(Db& db) const
{
static_assert(not vendor::is_noop<Assignments>::value, "calling set() required before running update");
static_assert(is_where_t<Where>::value, "cannot run update without having a where condition, use .where(true) to update all rows");
static_assert(_get_static_no_of_parameters() == 0, "cannot run update directly with parameters, use prepare instead");
return db.update(*this);
}

View File

@@ -82,6 +82,29 @@ namespace sqlpp
}
};
template<>
struct where_t<void, bool>
{
using _is_where = std::true_type;
using _is_dynamic = std::false_type;
using _parameter_tuple_t = std::tuple<>;
std::tuple<bool> _condition;
};
template<typename Context>
struct interpreter_t<Context, where_t<void, bool>>
{
using T = where_t<void, bool>;
static Context& _(const T& t, Context& context)
{
if (not std::get<0>(t._condition))
context << " WHERE NULL";
return context;
}
};
}
}