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 ++++++++++++++++++++++++++++++ common/inheritance/polymorphism/makefile | 2 +- common/inheritance/polymorphism/test13.hxx | 47 ++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 common/inheritance/polymorphism/test13.hxx (limited to 'common/inheritance/polymorphism') 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) { diff --git a/common/inheritance/polymorphism/makefile b/common/inheritance/polymorphism/makefile index ec934f7..744c688 100644 --- a/common/inheritance/polymorphism/makefile +++ b/common/inheritance/polymorphism/makefile @@ -6,7 +6,7 @@ include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make cxx_tun := driver.cxx odb_hdr := test1.hxx test2.hxx test3.hxx test4.hxx test5.hxx test6.hxx \ -test7.hxx test8.hxx test9.hxx test10.hxx test11.hxx test12.hxx +test7.hxx test8.hxx test9.hxx test10.hxx test11.hxx test12.hxx test13.hxx cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) cxx_od := $(cxx_obj:.o=.o.d) diff --git a/common/inheritance/polymorphism/test13.hxx b/common/inheritance/polymorphism/test13.hxx new file mode 100644 index 0000000..8f80cdb --- /dev/null +++ b/common/inheritance/polymorphism/test13.hxx @@ -0,0 +1,47 @@ +// file : common/inheritance/polymorphism/test13.hxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST13_HXX +#define TEST13_HXX + +#include +#include + +#include + +// Test polymorphic derived without any non-container data members (which +// results in an empty SELECT statement). +// +#pragma db namespace table("t13_") +namespace test13 +{ + #pragma db object polymorphic + struct root + { + virtual ~root () {} + + #pragma db id auto + unsigned long id; + }; + + #pragma db object + struct base: root + { + std::vector nums; + }; + + #pragma db object + struct derived: base + { + std::vector strs; + }; + + #pragma db object + struct base1: root + { + // Nothing. + }; +} + +#endif // TEST13_HXX -- cgit v1.1