mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-04 20:20:59 -06:00
Prevent unconditional joins, and naked bool in where() or boolean expressions
- `.from(t1, t2)` produces an unconditional join if you forget to add a condition in the .where() sqlpp11 therefore now deprecates unconditional joins. - more often than not, writing something like `where(name == "doe")`, you meant to write `where(t.name == "doe")`. It is hard to find bugs when the former expression compiles because you happen to have a variable `name` in the current scope as well. sqlpp11 therefore now deprecates `.where(bool)` and disallows raw bool values boolean expression like `something and bool` wrap bools in sqlpp::value(), if you REALLY want a bool value here
This commit is contained in:
@@ -298,7 +298,7 @@ int SelectType(int, char* [])
|
||||
t.alpha.as(alias::a) // index 12
|
||||
)
|
||||
.from(t)
|
||||
.where(true)); // next index is 13
|
||||
.unconditionally()); // next index is 13
|
||||
using ResultRow = typename Select::_result_methods_t<Select>::template _result_row_t<MockDb>;
|
||||
using IndexSequence = ResultRow::_field_index_sequence;
|
||||
static_assert(std::is_same<IndexSequence, sqlpp::detail::field_index_sequence<13, 0, 1, 2, 3, 4, 8, 12>>::value,
|
||||
@@ -318,15 +318,16 @@ int SelectType(int, char* [])
|
||||
"select with identical columns(name/value_type) need to have identical result_types");
|
||||
}
|
||||
|
||||
for (const auto& row : db(select(all_of(t)).from(t).where(true)))
|
||||
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
|
||||
{
|
||||
int64_t a = row.alpha;
|
||||
std::cout << a << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
auto s = dynamic_select(db, all_of(t)).dynamic_from().dynamic_where().dynamic_limit().dynamic_offset();
|
||||
s.from.add(t);
|
||||
auto s = dynamic_select(db, all_of(t)).dynamic_from(t).dynamic_where().dynamic_limit().dynamic_offset();
|
||||
#warning : Need to test the deprecated stuff
|
||||
s.from.add(dynamic_join(f).on(f.omega > t.alpha));
|
||||
s.where.add_ntc(t.alpha > 7 and t.alpha == any(select(t.alpha).from(t).where(t.alpha < 3)));
|
||||
s.limit.set(30);
|
||||
s.limit.set(3);
|
||||
@@ -376,7 +377,7 @@ int SelectType(int, char* [])
|
||||
auto s1 = sqlpp::select()
|
||||
.flags(sqlpp::distinct, sqlpp::straight_join)
|
||||
.columns(l.gamma, r.a)
|
||||
.from(r, t, l)
|
||||
.from(r.join(t).unconditionally().join(l).unconditionally())
|
||||
.where(t.beta == "hello world" and select(t.gamma).from(t)) // .as(alias::right))
|
||||
.group_by(l.gamma, r.a)
|
||||
.having(r.a != true)
|
||||
|
||||
Reference in New Issue
Block a user