From b434d9d0245aa03879155fb830613f471af12976 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 21 Sep 2011 13:00:34 +0200 Subject: Rework const object handling Now objects are always loaded as non-const and the object cache in session treats all objects as non-const. --- common/const/driver.cxx | 24 +++++++++++------------- common/view/driver.cxx | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/common/const/driver.cxx b/common/const/driver.cxx index 17c2edc..dd0a2b6 100644 --- a/common/const/driver.cxx +++ b/common/const/driver.cxx @@ -77,7 +77,7 @@ main (int argc, char* argv[]) { transaction t (db->begin ()); auto_ptr a (db->load (1)); - auto_ptr ca (db->load (2)); + auto_ptr ca (db->load (2)); t.commit (); assert (a->o1->id == 2); @@ -121,13 +121,15 @@ main (int argc, char* argv[]) { transaction t (db->begin ()); - result1 r1 (db->query (query1::id < 3)); + result1 r1 (db->query (query1::id < 3)); + // odb::result ur (r1); // error size_t n1 (0); for (result1::iterator i (r1.begin ()); i != r1.end (); ++i) { // i->f (); // error i->cf (); + // obj1* p (i.load ()); // error const obj1* p (i.load ()); obj1 o (0); i.load (o); @@ -138,13 +140,14 @@ main (int argc, char* argv[]) assert (n1 == 2); - result2 r2 (db->query (query2::id < 3)); + result2 r2 (db->query (query2::id < 3)); size_t n2 (0); for (result2::iterator i (r2.begin ()); i != r2.end (); ++i) { // i->f (); // error i->cf (); + // auto_ptr p (i.load ()); // error auto_ptr p (i.load ()); obj2 o (0); i.load (o); @@ -191,17 +194,12 @@ main (int argc, char* argv[]) { session s; transaction t (db->begin ()); - const obj1 o1 (1); - db->persist (o1); - try - { - db->load (1); - assert (false); - } - catch (const odb::const_object&) - { - } + obj1 o1 (1); + const obj1& co1 (o1); + db->persist (co1); + + assert (db->load (1) == &o1); t.commit (); } diff --git a/common/view/driver.cxx b/common/view/driver.cxx index 847d21b..7d921cd 100644 --- a/common/view/driver.cxx +++ b/common/view/driver.cxx @@ -323,7 +323,7 @@ main (int argc, char* argv[]) // { typedef odb::query query; - typedef odb::result result; + typedef odb::result result; // Test const result. { transaction t (db->begin ()); -- cgit v1.1