aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/query.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-10-02 17:07:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-10-02 17:07:19 +0200
commitd3da494f32febfdf900812ea59db9ae1ce5a76cf (patch)
tree579f736fac20289f822322dbc9d75bdf14357633 /odb/mysql/query.hxx
parentf2fcf90f47cf3ee8b1fc93ddd3d340279bf1d369 (diff)
If query substituting placeholder is empty, pass true expression instead
This allows uniform usage of views both with and without any extra conditions. Also optimize some common cases so that we don't have useless WHERE TRUE clauses or (...) AND (TRUE) expressions.
Diffstat (limited to 'odb/mysql/query.hxx')
-rw-r--r--odb/mysql/query.hxx62
1 files changed, 31 insertions, 31 deletions
diff --git a/odb/mysql/query.hxx b/odb/mysql/query.hxx
index 4314938..0ca91e5 100644
--- a/odb/mysql/query.hxx
+++ b/odb/mysql/query.hxx
@@ -91,14 +91,17 @@ namespace odb
{
column,
param,
- native
+ native,
+ boolean
};
clause_part (kind_type k): kind (k) {}
clause_part (kind_type k, const std::string& p): kind (k), part (p) {}
+ clause_part (bool p): kind (boolean), bool_part (p) {}
kind_type kind;
std::string part;
+ bool bool_part;
};
query ()
@@ -112,8 +115,7 @@ namespace odb
query (bool v)
: binding_ (0, 0)
{
- clause_.push_back (
- clause_part (clause_part::native, v ? "TRUE" : "FALSE"));
+ clause_.push_back (clause_part (v));
}
explicit
@@ -171,6 +173,26 @@ namespace odb
parameters_binding () const;
public:
+ bool
+ empty () const
+ {
+ return clause_.empty ();
+ }
+
+ static const query true_expr;
+
+ bool
+ const_true () const
+ {
+ return clause_.size () == 1 &&
+ clause_.front ().kind == clause_part::boolean &&
+ clause_.front ().bool_part;
+ }
+
+ void
+ optimize ();
+
+ public:
template <typename T>
static val_bind<T>
_val (const T& x)
@@ -341,36 +363,14 @@ namespace odb
return r;
}
- inline query
- operator&& (const query& x, const query& y)
- {
- query r ("(");
- r += x;
- r += ") AND (";
- r += y;
- r += ")";
- return r;
- }
+ query
+ operator&& (const query& x, const query& y);
- inline query
- operator|| (const query& x, const query& y)
- {
- query r ("(");
- r += x;
- r += ") OR (";
- r += y;
- r += ")";
- return r;
- }
+ query
+ operator|| (const query& x, const query& y);
- inline query
- operator! (const query& x)
- {
- query r ("!(");
- r += x;
- r += ")";
- return r;
- }
+ query
+ operator! (const query& x);
// query_column
//