From 0bcac7dde58c0538b9d06f866a0ebd3d60d4001d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 28 Sep 2012 14:42:23 +0200 Subject: Make sure size() can still be called once we reached the end of result set --- common/query/driver.cxx | 45 +++++++++++++++++++++++++++++++++++++++++++++ common/query/test.std | 1 + 2 files changed, 46 insertions(+) diff --git a/common/query/driver.cxx b/common/query/driver.cxx index cc92f41..3c3c753 100644 --- a/common/query/driver.cxx +++ b/common/query/driver.cxx @@ -542,6 +542,51 @@ main (int argc, char* argv[]) t.commit (); } } + + // Test size() validity at the beginning/middle/end of result set. + // + cout << "test 019" << endl; +#if !defined(DATABASE_SQLITE) && \ + !defined(DATABASE_ORACLE) && \ + !defined(DATABASE_MSSQL) + { + { + transaction t (db->begin ()); + result r (db->query ()); + assert (r.size () == 4); + result::iterator i (r.begin ()); + assert (r.size () == 4); + ++i; + ++i; + ++i; + assert (r.size () == 4); + ++i; + assert (r.size () == 4); + } + + { + transaction t (db->begin ()); + result r (db->query (false)); + result::iterator i (r.begin ()); + ++i; + ++i; + r.cache (); + assert (r.size () == 4); + ++i; + assert (r.size () == 4); + ++i; + assert (r.size () == 4); + } + + { + transaction t (db->begin ()); + result r (db->query (query::last_name == "None")); + assert (r.size () == 0); + for (result::iterator i (r.begin ()); i != r.end (); ++i) ; + assert (r.size () == 0); + } + } +#endif } catch (const odb::exception& e) { diff --git a/common/query/test.std b/common/query/test.std index e4ed7a0..0548968 100644 --- a/common/query/test.std +++ b/common/query/test.std @@ -99,3 +99,4 @@ Jane Doe 29 married test 016 test 017 test 018 +test 019 -- cgit v1.1