diff options
-rw-r--r-- | odb/relational/source.cxx | 2 | ||||
-rw-r--r-- | odb/relational/source.hxx | 20 |
2 files changed, 16 insertions, 6 deletions
diff --git a/odb/relational/source.cxx b/odb/relational/source.cxx index 5dfc15a..fe23ac9 100644 --- a/odb/relational/source.cxx +++ b/odb/relational/source.cxx @@ -499,7 +499,7 @@ namespace relational if (tt == CPP_CLOSE_PAREN) { - r += 'q'; + r += "q.empty () ? query_base_type::true_expr : q"; *placeholder = true; } else diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx index fbe9b1c..4d120db 100644 --- a/odb/relational/source.hxx +++ b/odb/relational/source.hxx @@ -3082,8 +3082,8 @@ namespace relational if (p != string::npos) { ph = true; - os << strlit (string (vq.literal, 0, p + 1)) - << " + q + " + os << strlit (string (vq.literal, 0, p + 1)) << " +" << endl + << "(q.empty () ? query_base_type::true_expr : q) +" << endl << strlit (string (vq.literal, p + 2)); } else @@ -3564,14 +3564,17 @@ namespace relational if (p != string::npos) { ph = true; - os << strlit (string (vq.literal, 0, p + 1)) - << " + q + " + os << strlit (string (vq.literal, 0, p + 1))<< " +" << endl + << "(q.empty () ? query_base_type::true_expr : q) +" << endl << strlit (string (vq.literal, p + 2)); } else os << strlit (vq.literal); + + os << ");"; } else + { // Output the pragma location for easier error tracking. // os << "// From " << @@ -3581,7 +3584,14 @@ namespace relational << translate_expression ( c, vq.expr, vq.scope, vq.loc, "query", &ph).value; - os << ");"; + os << ");"; + + // Optimize the query if it had a placeholder. This gets + // rid of useless clauses like WHERE TRUE. + // + if (ph) + os << "c.optimize ();"; + } if (!ph) os << "c += q;"; |