diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-09-16 16:03:25 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-09-16 16:03:25 +0200 |
commit | 02aed5f059797cd5e53a9fe6dde13714f86332d4 (patch) | |
tree | b2bfce8921184f8767dddba221032792b1cb3214 /odb/sqlite/query.cxx | |
parent | a8b1a89c291ab5bd170568eab3d7666631adf035 (diff) |
Support for views; integrated part
Diffstat (limited to 'odb/sqlite/query.cxx')
-rw-r--r-- | odb/sqlite/query.cxx | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/odb/sqlite/query.cxx b/odb/sqlite/query.cxx index ab158bb..16d8cc2 100644 --- a/odb/sqlite/query.cxx +++ b/odb/sqlite/query.cxx @@ -197,6 +197,47 @@ namespace odb parameters_->add (p); } + const char* query:: + clause_prefix () const + { + if (!clause_.empty ()) + { + const clause_part& p (clause_.front ()); + + if (p.kind == clause_part::native) + { + const string& s (p.part); + string::size_type n; + + // It is easier to compare to upper and lower-case versions + // rather than getting involved with the portable case- + // insensitive string comparison mess. + // + if (s.compare (0, (n = 5), "WHERE") == 0 || + s.compare (0, (n = 5), "where") == 0 || + s.compare (0, (n = 6), "SELECT") == 0 || + s.compare (0, (n = 6), "select") == 0 || + s.compare (0, (n = 8), "ORDER BY") == 0 || + s.compare (0, (n = 8), "order by") == 0 || + s.compare (0, (n = 8), "GROUP BY") == 0 || + s.compare (0, (n = 8), "group by") == 0 || + s.compare (0, (n = 6), "HAVING") == 0 || + s.compare (0, (n = 6), "having") == 0) + { + // It either has to be an exact match, or there should be + // a whitespace following the keyword. + // + if (s.size () == n || s[n] == ' ' || s[n] =='\t') + return ""; + } + } + + return "WHERE "; + } + + return ""; + } + string query:: clause () const { @@ -243,14 +284,7 @@ namespace odb } } - if (r.empty () || - r.compare (0, 6, "WHERE ") == 0 || - r.compare (0, 9, "ORDER BY ") == 0 || - r.compare (0, 9, "GROUP BY ") == 0 || - r.compare (0, 7, "HAVING ") == 0) - return r; - else - return "WHERE " + r; + return clause_prefix () + r; } } } |