aboutsummaryrefslogtreecommitdiff
path: root/evolution/drop-table
diff options
context:
space:
mode:
Diffstat (limited to 'evolution/drop-table')
-rw-r--r--evolution/drop-table/driver.cxx58
-rw-r--r--evolution/drop-table/model.hxx51
2 files changed, 93 insertions, 16 deletions
diff --git a/evolution/drop-table/driver.cxx b/evolution/drop-table/driver.cxx
index 0a005b5..9f60214 100644
--- a/evolution/drop-table/driver.cxx
+++ b/evolution/drop-table/driver.cxx
@@ -41,8 +41,6 @@ main (int argc, char* argv[])
{
case 1:
{
- using namespace v2;
-
if (embedded)
{
transaction t (db->begin ());
@@ -53,19 +51,45 @@ main (int argc, char* argv[])
t.commit ();
}
- object1 o1;
- o1.o = new object (1);
- o1.o->str = "abc";
- o1.nums.push_back (1);
- o1.nums.push_back (2);
- o1.nums.push_back (3);
+ {
+ using namespace v2;
+
+ object1 o1;
+ o1.o = new object (1);
+ o1.o->str = "abc";
+ o1.nums.push_back (1);
+ o1.nums.push_back (2);
+ o1.nums.push_back (3);
+
+ {
+ transaction t (db->begin ());
+ db->persist (o1.o);
+ db->persist (o1);
+ t.commit ();
+ }
+ }
+ // Polymorphism test.
+ //
{
- transaction t (db->begin ());
- db->persist (o1.o);
- db->persist (o1);
- t.commit ();
+ // We have to use v3 here because the discriminator includes
+ // the namespace.
+ //
+ using namespace v3;
+
+ base b (123, "abc");
+ derived d1 (234, "bcd");
+ derived d2 (345, "cde");
+
+ {
+ transaction t (db->begin ());
+ db->persist (b);
+ db->persist (d1);
+ db->persist (d2);
+ t.commit ();
+ }
}
+
break;
}
case 2:
@@ -104,6 +128,7 @@ main (int argc, char* argv[])
schema_catalog::migrate_schema_post (*db, 3);
t.commit ();
}
+
break;
}
case 3:
@@ -119,6 +144,15 @@ main (int argc, char* argv[])
t.commit ();
}
+ // Polymorphism test.
+ //
+ {
+ transaction t (db->begin ());
+ assert (size (db->query<root> ()) == 1);
+ assert (size (db->query<base> ()) == 1);
+ t.commit ();
+ }
+
break;
}
default:
diff --git a/evolution/drop-table/model.hxx b/evolution/drop-table/model.hxx
index 64022bb..55035e6 100644
--- a/evolution/drop-table/model.hxx
+++ b/evolution/drop-table/model.hxx
@@ -29,11 +29,7 @@ namespace MODEL_NAMESPACE(MODEL_VERSION)
std::string str;
};
-#if MODEL_VERSION > 1
#pragma db object
-#if MODEL_VERSION == 3
- #pragma db deleted(3)
-#endif
struct object1
{
object1 (): o (0) {}
@@ -45,6 +41,53 @@ namespace MODEL_NAMESPACE(MODEL_VERSION)
object* o;
std::vector<int> nums;
};
+
+#if MODEL_VERSION == 3
+ #pragma db object(object1) deleted(3)
+#endif
+
+ // Make sure we also clean up base tables when dropping a
+ // table corresponding to the polymorphic derived object.
+ //
+ #pragma db value
+ struct value
+ {
+ value (unsigned long n = 0, const std::string& s = ""): num (n), str (s) {}
+
+ unsigned long num;
+ std::string str;
+ };
+
+ #pragma db object polymorphic
+ struct root
+ {
+ root (unsigned long n = 0, const std::string& s = ""): id (n, s) {}
+ virtual ~root () {}
+
+ #pragma db id
+ value id;
+ };
+
+ #pragma db object
+ struct base: root
+ {
+ base (unsigned long n = 0, const std::string& s = "")
+ : root (n, s), num (n) {}
+
+ unsigned long num;
+ };
+
+ #pragma db object
+ struct derived: base
+ {
+ derived (unsigned long n = 0, const std::string& s = "")
+ : base (n, s), str (s) {}
+
+ std::string str;
+ };
+
+#if MODEL_VERSION == 3
+ #pragma db object(derived) deleted(3)
#endif
}