From f221c0a4f291646a1e698a8de2909043e7d0313d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 14 Jan 2013 18:02:32 +0200 Subject: Fix bug in handling polymorphic derived classes without any value members --- common/inheritance/polymorphism/driver.cxx | 50 ++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'common/inheritance/polymorphism/driver.cxx') diff --git a/common/inheritance/polymorphism/driver.cxx b/common/inheritance/polymorphism/driver.cxx index 20007e4..4f18c15 100644 --- a/common/inheritance/polymorphism/driver.cxx +++ b/common/inheritance/polymorphism/driver.cxx @@ -27,6 +27,7 @@ #include "test10.hxx" #include "test11.hxx" #include "test12.hxx" +#include "test13.hxx" #include "test1-odb.hxx" #include "test2-odb.hxx" @@ -40,6 +41,7 @@ #include "test10-odb.hxx" #include "test11-odb.hxx" #include "test12-odb.hxx" +#include "test13-odb.hxx" using namespace std; using namespace odb::core; @@ -1871,6 +1873,54 @@ main (int argc, char* argv[]) assert (*pd == d); } } + + // Test 13: polymorphic derived without any non-container data members + // (which results in an empty SELECT statement). + // + { + using namespace test13; + + base b; + b.nums.push_back (123); + derived d; + d.nums.push_back (123); + d.strs.push_back ("abc"); + + base1 b1; + + // Persist. + // + { + transaction t (db->begin ()); + db->persist (b); + db->persist (d); + db->persist (b1); + t.commit (); + } + + // Load. + // + { + transaction t (db->begin ()); + auto_ptr pbr (db->load (b.id)); + auto_ptr pdr (db->load (d.id)); + auto_ptr pdb (db->load (d.id)); + auto_ptr pb1r (db->load (b1.id)); + t.commit (); + + base& rb (static_cast (*pbr)); + derived& rd1 (static_cast (*pdr)); + derived& rd2 (static_cast (*pdb)); + base1 rb1 (static_cast (*pb1r)); + + assert (rb.id == b.id && rb.nums == b.nums); + assert (rd1.id == d.id && rd1.nums == rd1.nums && + rd1.strs == rd1.strs); + assert (rd2.id == d.id && rd2.nums == rd2.nums && + rd2.strs == rd2.strs); + assert (rb1.id == b1.id); + } + } } catch (const odb::exception& e) { -- cgit v1.1