diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-01-14 18:02:32 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-01-14 18:02:32 +0200 |
commit | f221c0a4f291646a1e698a8de2909043e7d0313d (patch) | |
tree | 7574e32ac4e28ab04fd46c163e88e592a76eddac /common/inheritance | |
parent | 23a537ac98066dc3994100548890112aa6e8d8ac (diff) |
Fix bug in handling polymorphic derived classes without any value members
Diffstat (limited to 'common/inheritance')
-rw-r--r-- | common/inheritance/polymorphism/driver.cxx | 50 | ||||
-rw-r--r-- | common/inheritance/polymorphism/makefile | 2 | ||||
-rw-r--r-- | common/inheritance/polymorphism/test13.hxx | 47 |
3 files changed, 98 insertions, 1 deletions
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<root> pbr (db->load<root> (b.id)); + auto_ptr<root> pdr (db->load<root> (d.id)); + auto_ptr<base> pdb (db->load<base> (d.id)); + auto_ptr<root> pb1r (db->load<root> (b1.id)); + t.commit (); + + base& rb (static_cast<base&> (*pbr)); + derived& rd1 (static_cast<derived&> (*pdr)); + derived& rd2 (static_cast<derived&> (*pdb)); + base1 rb1 (static_cast<base1&> (*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 <string> +#include <vector> + +#include <odb/core.hxx> + +// 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<int> nums; + }; + + #pragma db object + struct derived: base + { + std::vector<std::string> strs; + }; + + #pragma db object + struct base1: root + { + // Nothing. + }; +} + +#endif // TEST13_HXX |