diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-02-05 14:17:07 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-02-05 14:17:07 +0200 |
commit | 2ca4828d303fdd27c573429910f7a25fd1e3727c (patch) | |
tree | d2637c11861d44a634ecc09bbe88c3a3ff350b16 /odb/pragma.cxx | |
parent | 8e69f40ab32dc8604b68f360ae30fa961ba036ee (diff) |
Implement result modifiers in view query condition
Diffstat (limited to 'odb/pragma.cxx')
-rw-r--r-- | odb/pragma.cxx | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/odb/pragma.cxx b/odb/pragma.cxx index 7a3d6ec..618df67 100644 --- a/odb/pragma.cxx +++ b/odb/pragma.cxx @@ -176,8 +176,8 @@ parse_expression (cxx_lexer& l, cxx_tokens& ts, string const& prag) { - // Keep reading tokens until we see a matching ')' while keeping track - // of their balance. + // Keep reading tokens until we see a mis-matching ')' or ',' while + // keeping track of the '()' balance. // size_t balance (0); @@ -201,6 +201,13 @@ parse_expression (cxx_lexer& l, balance--; break; } + case CPP_COMMA: + { + if (balance == 0) + done = true; + else + break; + } case CPP_STRING: { ct.literal = tl; @@ -1584,6 +1591,55 @@ handle_pragma (cxx_lexer& l, return; // Diagnostics has already been issued. } + // Disallow query(, distinct). + // + if (tt == CPP_COMMA && vq.expr.empty ()) + { + error (l) << "query expression expected in db pragma " << p << endl; + return; + } + + // The query expression can be omitted with the modifier in its + // place. Handle this case. + // + if (vq.expr.size () == 1 && vq.expr.front ().type == CPP_NAME) + { + string const& n (vq.expr.front ().literal); + + if (n == "distinct") + vq.distinct = true; + else if (n == "for_update") + vq.for_update = true; + + if (vq.distinct || vq.for_update) + vq.expr.clear (); + } + + if (tt == CPP_COMMA) + { + do + { + if (l.next (tl, &tn) != CPP_NAME) + { + error (l) << "result modifier expected in db pragma " << p << endl; + return; + } + + if (tl == "distinct") + vq.distinct = true; + else if (tl == "for_update") + vq.for_update = true; + else + { + error (l) << "unknown result modifier '" << tl << "'" << endl; + return; + } + + tt = l.next (tl, &tn); + + } while (tt == CPP_COMMA); + } + if (tt != CPP_CLOSE_PAREN) { error (l) << "')' expected at the end of db pragma " << p << endl; |