Skip to content

Commit

Permalink
Add test triggered by #604
Browse files Browse the repository at this point in the history
  • Loading branch information
rbock committed Sep 28, 2024
1 parent 38fca31 commit 0341d56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/sqlpp11/core/to_sql_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ namespace sqlpp
template <typename T, typename Context>
auto operand_to_sql_string(Context& context, const T& t) -> std::string
{
#warning: For expressions with dynamic components this needs to be dynamic, e.g.
#warning: `A and dynamic(false, B)` would require parenthesis if and only if A requires parentheses
if (requires_parentheses<T>::value)
{
return "(" + to_sql_string(context, t) + ")";
Expand Down
9 changes: 8 additions & 1 deletion tests/core/serialize/operator/logical_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int, char* [])
// NOT is not chained gracefully, but hey, don't do that anyways.
SQLPP_COMPARE(not not not val, "NOT (NOT (NOT 1))");

// Operands are enclosed in parenheses where required or completely dropped if inactive
// Operands are enclosed in parentheses where required or completely dropped if inactive
SQLPP_COMPARE(val and dynamic(true, val), "1 AND 1");
SQLPP_COMPARE(val and dynamic(true, expr), "1 AND (17 > 15)");
SQLPP_COMPARE(expr and dynamic(true, val), "(17 > 15) AND 1");
Expand Down Expand Up @@ -90,5 +90,12 @@ int main(int, char* [])
SQLPP_COMPARE(val or dynamic(true, val) or expr, "1 OR 1 OR (17 > 15)");
SQLPP_COMPARE(val or dynamic(false, val) or expr, "1 OR (17 > 15)");

// More complex expressions
SQLPP_COMPARE((val and dynamic(true, expr)) or dynamic(true, val), "(1 AND (17 > 15)) OR 1");
#warning: Remove paretheses!
SQLPP_COMPARE((val and dynamic(false, expr)) or dynamic(true, val), "(1) OR 1");
SQLPP_COMPARE((val and dynamic(true, expr)) or dynamic(false, val), "1 AND (17 > 15)");
SQLPP_COMPARE((val and dynamic(false, expr)) or dynamic(false, val), "1")

return 0;
}

0 comments on commit 0341d56

Please sign in to comment.