mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-05 12:40:40 -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:
@@ -38,16 +38,16 @@ int With(int, char* [])
|
||||
|
||||
auto x = sqlpp::cte(sqlpp::alias::x).as(select(all_of(t)).from(t));
|
||||
|
||||
db(with(x)(select(x.alpha).from(x).where(true)));
|
||||
db(with(x)(select(x.alpha).from(x).unconditionally()));
|
||||
|
||||
auto y0 = sqlpp::cte(sqlpp::alias::y).as(select(all_of(t)).from(t));
|
||||
auto y = y0.union_all(select(all_of(y0)).from(y0).where(false));
|
||||
auto y = y0.union_all(select(all_of(y0)).from(y0).unconditionally());
|
||||
|
||||
std::cout << serialize(y, printer).str() << std::endl;
|
||||
printer.reset();
|
||||
std::cout << serialize(from_table(y), printer).str() << std::endl;
|
||||
|
||||
db(with(y)(select(y.alpha).from(y).where(true)));
|
||||
db(with(y)(select(y.alpha).from(y).unconditionally()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user