mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-05-22 04:08:34 -05: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);
|
||||
}
|
||||
|
||||
Vendored
+23
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ SQLPP_ALIAS_PROVIDER(kaesekuchen);
|
||||
int main()
|
||||
{
|
||||
TabSample t;
|
||||
TabFoo f;
|
||||
|
||||
interpret(t.alpha, printer).flush();
|
||||
interpret(-t.alpha, printer).flush();
|
||||
@@ -68,7 +69,7 @@ int main()
|
||||
interpret(t.alpha == parameter(t.alpha) and (t.beta + "gimmick").like(parameter(t.beta)), printer).flush();
|
||||
|
||||
interpret(insert_into(t), printer).flush();
|
||||
interpret(insert_into(t).default_values(), printer).flush();
|
||||
interpret(insert_into(f).default_values(), printer).flush();
|
||||
interpret(insert_into(t).set(t.gamma = true), printer).flush();
|
||||
interpret(insert_into(t).set(t.gamma = sqlpp::tvin(false)), printer).flush();
|
||||
|
||||
@@ -119,5 +120,8 @@ int main()
|
||||
interpret(avg(sqlpp::distinct, t.alpha - 7), printer).flush();
|
||||
interpret(sum(sqlpp::distinct, t.alpha + 7), printer).flush();
|
||||
|
||||
interpret(select(all_of(t)).from(t).where(true), printer).flush();
|
||||
interpret(select(all_of(t)).from(t).where(false), printer).flush();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user