From 2ca4828d303fdd27c573429910f7a25fd1e3727c Mon Sep 17 00:00:00 2001
From: Boris Kolpackov 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: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_viewtypedef 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 toSELECT + DISTINCT
) andfor_update
(which is translated + toFOR 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
+ and, optionally, result modifiers for an object or table view + or a native SQL query for a native view. An emptyquery
specifier specifies a query condition - for an object or table view or a native SQL query for a native - view. An emptyquery
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".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
-- cgit v1.1pointer