From 617407a3353e5bfce0dc9144776015899d7a4e65 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 13 Jun 2013 18:25:00 +0200 Subject: Add support for native views that call stored procedures --- odb/relational/source.cxx | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'odb/relational/source.cxx') diff --git a/odb/relational/source.cxx b/odb/relational/source.cxx index ceb8538..8d7c913 100644 --- a/odb/relational/source.cxx +++ b/odb/relational/source.cxx @@ -3074,11 +3074,13 @@ traverse_view (type& c) << "query_statement (const query_base_type& q)" << "{"; - if (vq.kind == view_query::complete) + if (vq.kind == view_query::complete_select || + vq.kind == view_query::complete_execute) { os << "query_base_type r (" << endl; bool ph (false); + bool pred (vq.kind == view_query::complete_select); if (!vq.literal.empty ()) { @@ -3094,9 +3096,21 @@ traverse_view (type& c) if (p != string::npos) { ph = true; - os << strlit (string (vq.literal, 0, p + 1)) << " +" << endl - << "(q.empty () ? query_base_type::true_expr : q) +" << endl - << strlit (string (vq.literal, p + 2)); + // For the SELECT query we keep the parenthesis in (?) and + // also handle the case where the query expression is empty. + // + if (pred) + 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 (string (vq.literal, 0, p)) << " + q"; + + p += 3; + if (p != vq.literal.size ()) + os << strlit (string (vq.literal, p)); + } } else os << strlit (vq.literal); @@ -3110,7 +3124,7 @@ traverse_view (type& c) // os << "// From " << location_string (vq.loc, true) << endl << translate_expression ( - c, vq.expr, scope, vq.loc, "query", &ph).value; + c, vq.expr, scope, vq.loc, "query", &ph, pred).value; } os << ");"; @@ -4232,7 +4246,8 @@ namespace relational semantics::scope& scope, location_t loc, string const& prag, - bool* placeholder) + bool* placeholder, + bool predicate) { // This code is similar to translate() from context.cxx. // @@ -4427,8 +4442,19 @@ namespace relational if (tt == CPP_CLOSE_PAREN) { - r += "q.empty () ? query_base_type::true_expr : q"; *placeholder = true; + + // Predicate is true if this is a SELECT statement clause. + // Otherwise it is a stored procedure parameters. + // + if (predicate) + r += "q.empty () ? query_base_type::true_expr : q"; + else + { + r.resize (r.size () - 1); // Remove opening paren. + r += "q"; + break; // Skip the closing paren as well. + } } else { -- cgit v1.1