diff --git a/include/sqlpp11/core/to_sql_string.h b/include/sqlpp11/core/to_sql_string.h index 0fab6144..895c5e2d 100644 --- a/include/sqlpp11/core/to_sql_string.h +++ b/include/sqlpp11/core/to_sql_string.h @@ -256,6 +256,8 @@ namespace sqlpp template 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::value) { return "(" + to_sql_string(context, t) + ")"; diff --git a/tests/core/serialize/operator/logical_expression.cpp b/tests/core/serialize/operator/logical_expression.cpp index 7c98106c..db4200ed 100644 --- a/tests/core/serialize/operator/logical_expression.cpp +++ b/tests/core/serialize/operator/logical_expression.cpp @@ -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"); @@ -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; }