From 3b27ca96f2f4c2b76f65675a988482e19220fa66 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 26 Nov 2010 15:48:28 +0200 Subject: Postpone fetching of the data for cached results This way if an object of the same type is loaded in between iteration, the fetched image won't be messed up. --- common/query/driver.cxx | 18 ++++++++++++++++++ common/query/test.std | 1 + 2 files changed, 19 insertions(+) (limited to 'common/query') diff --git a/common/query/driver.cxx b/common/query/driver.cxx index 9ff596b..5a77ae9 100644 --- a/common/query/driver.cxx +++ b/common/query/driver.cxx @@ -383,6 +383,24 @@ main (int argc, char* argv[]) print (r); t.commit (); } + + // Test that loading of the same object type during iteration does + // not invalidate the result. + // + cout << "test 014" << endl; + { + transaction t (db->begin ()); + result r (db->query (query::last_name == "Doe")); + + assert (r.size () == 2); + + result::iterator i (r.begin ()); + i++; + auto_ptr joe (db->load (3)); + assert (i->last_name_ == "Doe"); + + t.commit (); + } } catch (const odb::exception& e) { diff --git a/common/query/test.std b/common/query/test.std index e065765..14f3205 100644 --- a/common/query/test.std +++ b/common/query/test.std @@ -91,3 +91,4 @@ Johansen J Johansen 32 single test 013 Joe Squeaky Dirt 31 single +test 014 -- cgit v1.1