mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-06 05:00:37 -06:00
Added a .where(bool) to choose all or no row
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
23
include/sqlpp11/vendor/where.h
vendored
23
include/sqlpp11/vendor/where.h
vendored
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user