mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 12:51:13 +08:00
Add test triggered by #604
This commit is contained in:
parent
38fca31790
commit
0341d56075
@ -256,6 +256,8 @@ namespace sqlpp
|
|||||||
template <typename T, typename Context>
|
template <typename T, typename Context>
|
||||||
auto operand_to_sql_string(Context& context, const T& t) -> std::string
|
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)
|
if (requires_parentheses<T>::value)
|
||||||
{
|
{
|
||||||
return "(" + to_sql_string(context, t) + ")";
|
return "(" + to_sql_string(context, t) + ")";
|
||||||
|
@ -62,7 +62,7 @@ int main(int, char* [])
|
|||||||
// NOT is not chained gracefully, but hey, don't do that anyways.
|
// NOT is not chained gracefully, but hey, don't do that anyways.
|
||||||
SQLPP_COMPARE(not not not val, "NOT (NOT (NOT 1))");
|
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, val), "1 AND 1");
|
||||||
SQLPP_COMPARE(val and dynamic(true, expr), "1 AND (17 > 15)");
|
SQLPP_COMPARE(val and dynamic(true, expr), "1 AND (17 > 15)");
|
||||||
SQLPP_COMPARE(expr and dynamic(true, val), "(17 > 15) AND 1");
|
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(true, val) or expr, "1 OR 1 OR (17 > 15)");
|
||||||
SQLPP_COMPARE(val or dynamic(false, val) or expr, "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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user