From 2ca4828d303fdd27c573429910f7a25fd1e3727c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 5 Feb 2015 14:17:07 +0200 Subject: Implement result modifiers in view query condition --- doc/manual.xhtml | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'doc/manual.xhtml') diff --git a/doc/manual.xhtml b/doc/manual.xhtml index f91a4af..3e941dc 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -10366,10 +10366,12 @@ t.commit ();

As another example, consider a query that loads the employer objects using some condition based on its employees. For instance, we want to find all the employers that employ people over 65 years old. - We can use this object loading view to implement such a query:

+ We can use this object loading view to implement such a query (notice + the distinct result modifier discussed later in + Section 10.5, "View Query Conditions"):

-#pragma db view object(employer) object(employee)
+#pragma db view object(employer) object(employee) query(distinct)
 struct employer_view
 {
   shared_ptr<employer> er;
@@ -10382,7 +10384,7 @@ struct employer_view
   
 typedef odb::query<employee_employer> query;
 
-db.query<employer_view> ((query::employee::age > 65) + distinct))
+db.query<employer_view> (query::employee::age > 65)
   

We can even use object loading views to load completely unrelated @@ -11020,7 +11022,7 @@ struct employee_vacation

 #pragma db view object(employee) object(employer) \
-  query ((?) + "GROUP BY" + employer::name_)
+  query((?) + "GROUP BY" + employer::name_)
 struct employer_age
 {
   #pragma db column(employer::name_)
@@ -11034,6 +11036,36 @@ struct employer_age
 };
   
+

The query condition can be optionally followed (or replaced, + if no constant query expression is needed) by one or more + result modifiers. Currently supported result modifiers + are distinct (which is translated to SELECT + DISTINCT) and for_update (which is translated + to FOR UPDATE or equivalent for database systems + that support it). As an example, consider a view that + allows us to get some information about employers ordered + by the object id and without any duplicates:

+ +
+#pragma db view object(employer) object(employee) \
+  query((?) + "ORDER BY" + employer::name_, distinct)
+struct employer_info
+{
+  ...
+};
+  
+ +

If we don't require ordering, then this view can be re-implemented + like this:

+ +
+#pragma db view object(employer) object(employee) query(distinct)
+struct employer_info
+{
+  ...
+};
+  
+

10.6 Native Views

The last kind of view supported by ODB is a native view. Native @@ -15006,12 +15038,13 @@ class employer

14.2.3 query

The query specifier specifies a query condition - for an object or table view or a native SQL query for a native - view. An empty query specifier indicates that a - native SQL query is provided at runtime. For more information - on query conditions refer to Section 10.5, "View - Query Conditions". For more information on native SQL queries, - refer to Section 10.6, "Native Views".

+ and, optionally, result modifiers for an object or table view + or a native SQL query for a native view. An empty query + specifier indicates that a native SQL query is provided at runtime. + For more information on query conditions refer to + Section 10.5, "View Query Conditions". For + more information on native SQL queries, refer to + Section 10.6, "Native Views".

14.2.4 pointer

-- cgit v1.1