From b79afa6dbea19905b2a035365274616dd1dae2b1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 22 Aug 2011 11:47:55 +0200 Subject: Add database::erase_query() function New test: common/erase-query. Documentation is in Section 3.9, "Deleting Persistent Objects". The current implementation does not work well with the session (no removal of the erased objects from the cache). --- doc/manual.xhtml | 48 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) (limited to 'doc') diff --git a/doc/manual.xhtml b/doc/manual.xhtml index 246f4af..e5c7419 100644 --- a/doc/manual.xhtml +++ b/doc/manual.xhtml @@ -2657,10 +2657,10 @@ transfer (database& db,

3.9 Deleting Persistent Objects

To delete a persistent object's state from the database we use the - database::erase() function template. If the application - still has an instance of the erased object, this instance becomes - transient. The erase() function has the following - overloaded versions:

+ database::erase() or database::erase_query() + function templates. If the application still has an instance of the + erased object, this instance becomes transient. The erase() + function has the following overloaded versions:

   template <typename T>
@@ -2709,6 +2709,43 @@ db.erase<person> (joe_id);
 t.commit ();
   
+

The erase_query() function allows us to delete + the state of multiple objects matching certain criteria. It uses + the query expression of the database::query() function + (Chapter 4, "Querying the Database") and, + because the ODB query facility is optional, it is only available + if the --generate-query ODB compiler option was + specified. The erase_query() function has the + following overloaded versions:

+ +
+  template <typename T>
+  unsigned long long
+  erase_query ();
+
+  template <typename T>
+  unsigned long long
+  erase_query (const odb::query<T>&);
+  
+ +

The first erase_query() function is used to delete + the state of all the persistent objects of a given type stored + in the database. The second function uses the passed query instance + to only delete the state of objects matching the query criteria. + Both functions return the number of objects erased. When calling + the erase_query() function, we have to explicitly + specify the object type we are erasing. For example:

+ +
+typedef odb::query<person> query;
+
+transaction t (db.begin ());
+
+db.erase_query<person> (query::last == "Doe" && query::are < 30);
+
+t.commit ();
+  
+

3.10 Executing Native SQL Statements

In some situations we may need to execute native SQL statements @@ -8926,7 +8963,8 @@ class person

If foreign key constraints checking is disabled or not available, then inconsistencies in object relationships will not be detected. - Furthermore, using the erase_query() function (@@ ref) + Furthermore, using the erase_query() function + (Section 3.9, "Deleting Persistent Objects") to delete persistent objects that contain containers will not work correctly. Container data for such objects will not be deleted.

-- cgit v1.1