aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2013-09-15 12:46:09 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2013-09-17 12:04:03 +0200
commit8803508751837d96fd0beff60c952fb2044d073f (patch)
tree7b14fdc13d2d9ef67c7731f6bce68e18f6956cca
parent86a83893351adef44574514c303aa880cf3b6d54 (diff)
Cleanup polymorphic base tables when dropping derived one
-rw-r--r--common/changelog/add-table-mssql-diff.xml2
-rw-r--r--common/changelog/add-table-mssql-patch.xml2
-rw-r--r--common/changelog/add-table-mysql-diff.xml2
-rw-r--r--common/changelog/add-table-mysql-patch.xml2
-rw-r--r--common/changelog/add-table-oracle-diff.xml2
-rw-r--r--common/changelog/add-table-oracle-patch.xml2
-rw-r--r--common/changelog/add-table-pgsql-diff.xml2
-rw-r--r--common/changelog/add-table-pgsql-patch.xml2
-rw-r--r--common/changelog/add-table-sqlite-diff.xml2
-rw-r--r--common/changelog/add-table-sqlite-patch.xml2
-rw-r--r--common/changelog/drop-table-mssql-diff.xml2
-rw-r--r--common/changelog/drop-table-mysql-diff.xml2
-rw-r--r--common/changelog/drop-table-oracle-diff.xml2
-rw-r--r--common/changelog/drop-table-pgsql-diff.xml2
-rw-r--r--common/changelog/drop-table-sqlite-diff.xml2
-rw-r--r--common/changelog/model-mssql.xml2
-rw-r--r--common/changelog/model-mysql.xml2
-rw-r--r--common/changelog/model-oracle.xml2
-rw-r--r--common/changelog/model-pgsql.xml2
-rw-r--r--common/changelog/model-sqlite.xml2
-rw-r--r--evolution/drop-table/driver.cxx58
-rw-r--r--evolution/drop-table/model.hxx51
22 files changed, 113 insertions, 36 deletions
diff --git a/common/changelog/add-table-mssql-diff.xml b/common/changelog/add-table-mssql-diff.xml
index 1173f1e..5468cc9 100644
--- a/common/changelog/add-table-mssql-diff.xml
+++ b/common/changelog/add-table-mssql-diff.xml
@@ -14,7 +14,7 @@
</references>
</foreign-key>
</add-table>
- <add-table name="object_nums">
+ <add-table name="object_nums" kind="container">
<column name="object_id" type="INT" null="false"/>
<column name="index" type="BIGINT" null="false"/>
<column name="value" type="INT" null="false"/>
diff --git a/common/changelog/add-table-mssql-patch.xml b/common/changelog/add-table-mssql-patch.xml
index 55ac287..1b62efc 100644
--- a/common/changelog/add-table-mssql-patch.xml
+++ b/common/changelog/add-table-mssql-patch.xml
@@ -21,7 +21,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="INT" null="false"/>
<column name="index" type="BIGINT" null="false"/>
<column name="value" type="INT" null="false"/>
diff --git a/common/changelog/add-table-mysql-diff.xml b/common/changelog/add-table-mysql-diff.xml
index f899cb2..bbe5a1f 100644
--- a/common/changelog/add-table-mysql-diff.xml
+++ b/common/changelog/add-table-mysql-diff.xml
@@ -14,7 +14,7 @@
</references>
</foreign-key>
</add-table>
- <add-table name="object_nums" options="ENGINE=InnoDB">
+ <add-table name="object_nums" options="ENGINE=InnoDB" kind="container">
<column name="object_id" type="INT" null="false"/>
<column name="index" type="BIGINT UNSIGNED" null="false"/>
<column name="value" type="INT" null="false"/>
diff --git a/common/changelog/add-table-mysql-patch.xml b/common/changelog/add-table-mysql-patch.xml
index 4d0af47..199cf19 100644
--- a/common/changelog/add-table-mysql-patch.xml
+++ b/common/changelog/add-table-mysql-patch.xml
@@ -21,7 +21,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums" options="ENGINE=InnoDB">
+ <table name="object_nums" options="ENGINE=InnoDB" kind="container">
<column name="object_id" type="INT" null="false"/>
<column name="index" type="BIGINT UNSIGNED" null="false"/>
<column name="value" type="INT" null="false"/>
diff --git a/common/changelog/add-table-oracle-diff.xml b/common/changelog/add-table-oracle-diff.xml
index dd394a9..e7fd0fd 100644
--- a/common/changelog/add-table-oracle-diff.xml
+++ b/common/changelog/add-table-oracle-diff.xml
@@ -14,7 +14,7 @@
</references>
</foreign-key>
</add-table>
- <add-table name="object_nums">
+ <add-table name="object_nums" kind="container">
<column name="object_id" type="NUMBER(10)" null="false"/>
<column name="index" type="NUMBER(20)" null="false"/>
<column name="value" type="NUMBER(10)" null="false"/>
diff --git a/common/changelog/add-table-oracle-patch.xml b/common/changelog/add-table-oracle-patch.xml
index 78f555a..5c6c766 100644
--- a/common/changelog/add-table-oracle-patch.xml
+++ b/common/changelog/add-table-oracle-patch.xml
@@ -21,7 +21,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="NUMBER(10)" null="false"/>
<column name="index" type="NUMBER(20)" null="false"/>
<column name="value" type="NUMBER(10)" null="false"/>
diff --git a/common/changelog/add-table-pgsql-diff.xml b/common/changelog/add-table-pgsql-diff.xml
index 1c498f8..5c96338 100644
--- a/common/changelog/add-table-pgsql-diff.xml
+++ b/common/changelog/add-table-pgsql-diff.xml
@@ -14,7 +14,7 @@
</references>
</foreign-key>
</add-table>
- <add-table name="object_nums">
+ <add-table name="object_nums" kind="container">
<column name="object_id" type="INTEGER" null="false"/>
<column name="index" type="BIGINT" null="false"/>
<column name="value" type="INTEGER" null="false"/>
diff --git a/common/changelog/add-table-pgsql-patch.xml b/common/changelog/add-table-pgsql-patch.xml
index cb26141..8c8d7d3 100644
--- a/common/changelog/add-table-pgsql-patch.xml
+++ b/common/changelog/add-table-pgsql-patch.xml
@@ -21,7 +21,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="INTEGER" null="false"/>
<column name="index" type="BIGINT" null="false"/>
<column name="value" type="INTEGER" null="false"/>
diff --git a/common/changelog/add-table-sqlite-diff.xml b/common/changelog/add-table-sqlite-diff.xml
index d2abe2f..44ca569 100644
--- a/common/changelog/add-table-sqlite-diff.xml
+++ b/common/changelog/add-table-sqlite-diff.xml
@@ -14,7 +14,7 @@
</references>
</foreign-key>
</add-table>
- <add-table name="object_nums">
+ <add-table name="object_nums" kind="container">
<column name="object_id" type="INTEGER" null="false"/>
<column name="index" type="INTEGER" null="false"/>
<column name="value" type="INTEGER" null="false"/>
diff --git a/common/changelog/add-table-sqlite-patch.xml b/common/changelog/add-table-sqlite-patch.xml
index 868fbab..9eb4a3b 100644
--- a/common/changelog/add-table-sqlite-patch.xml
+++ b/common/changelog/add-table-sqlite-patch.xml
@@ -21,7 +21,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="INTEGER" null="false"/>
<column name="index" type="INTEGER" null="false"/>
<column name="value" type="INTEGER" null="false"/>
diff --git a/common/changelog/drop-table-mssql-diff.xml b/common/changelog/drop-table-mssql-diff.xml
index d905b2f..535c3a2 100644
--- a/common/changelog/drop-table-mssql-diff.xml
+++ b/common/changelog/drop-table-mssql-diff.xml
@@ -19,7 +19,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="INT" null="false"/>
<column name="index" type="BIGINT" null="false"/>
<column name="value" type="INT" null="false"/>
diff --git a/common/changelog/drop-table-mysql-diff.xml b/common/changelog/drop-table-mysql-diff.xml
index 5fd5a97..c94eee3 100644
--- a/common/changelog/drop-table-mysql-diff.xml
+++ b/common/changelog/drop-table-mysql-diff.xml
@@ -19,7 +19,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums" options="ENGINE=InnoDB">
+ <table name="object_nums" options="ENGINE=InnoDB" kind="container">
<column name="object_id" type="INT" null="false"/>
<column name="index" type="BIGINT UNSIGNED" null="false"/>
<column name="value" type="INT" null="false"/>
diff --git a/common/changelog/drop-table-oracle-diff.xml b/common/changelog/drop-table-oracle-diff.xml
index 39ed9be..4aa67e2 100644
--- a/common/changelog/drop-table-oracle-diff.xml
+++ b/common/changelog/drop-table-oracle-diff.xml
@@ -19,7 +19,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="NUMBER(10)" null="false"/>
<column name="index" type="NUMBER(20)" null="false"/>
<column name="value" type="NUMBER(10)" null="false"/>
diff --git a/common/changelog/drop-table-pgsql-diff.xml b/common/changelog/drop-table-pgsql-diff.xml
index 5cb9551..8facd2d 100644
--- a/common/changelog/drop-table-pgsql-diff.xml
+++ b/common/changelog/drop-table-pgsql-diff.xml
@@ -19,7 +19,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="INTEGER" null="false"/>
<column name="index" type="BIGINT" null="false"/>
<column name="value" type="INTEGER" null="false"/>
diff --git a/common/changelog/drop-table-sqlite-diff.xml b/common/changelog/drop-table-sqlite-diff.xml
index a91d643..85bf64a 100644
--- a/common/changelog/drop-table-sqlite-diff.xml
+++ b/common/changelog/drop-table-sqlite-diff.xml
@@ -19,7 +19,7 @@
</references>
</foreign-key>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="INTEGER" null="false"/>
<column name="index" type="INTEGER" null="false"/>
<column name="value" type="INTEGER" null="false"/>
diff --git a/common/changelog/model-mssql.xml b/common/changelog/model-mssql.xml
index 8a32d25..9bd1e4a 100644
--- a/common/changelog/model-mssql.xml
+++ b/common/changelog/model-mssql.xml
@@ -26,7 +26,7 @@
<column name="v_y"/>
</index>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="INT" null="false"/>
<column name="index" type="BIGINT" null="false"/>
<column name="value" type="INT" null="false"/>
diff --git a/common/changelog/model-mysql.xml b/common/changelog/model-mysql.xml
index 9398955..b4b2e14 100644
--- a/common/changelog/model-mysql.xml
+++ b/common/changelog/model-mysql.xml
@@ -26,7 +26,7 @@
<column name="v_y"/>
</index>
</table>
- <table name="object_nums" options="ENGINE=InnoDB">
+ <table name="object_nums" options="ENGINE=InnoDB" kind="container">
<column name="object_id" type="INT" null="false"/>
<column name="index" type="BIGINT UNSIGNED" null="false"/>
<column name="value" type="INT" null="false"/>
diff --git a/common/changelog/model-oracle.xml b/common/changelog/model-oracle.xml
index bbe2660..1b4db54 100644
--- a/common/changelog/model-oracle.xml
+++ b/common/changelog/model-oracle.xml
@@ -26,7 +26,7 @@
<column name="v_y"/>
</index>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="NUMBER(10)" null="false"/>
<column name="index" type="NUMBER(20)" null="false"/>
<column name="value" type="NUMBER(10)" null="false"/>
diff --git a/common/changelog/model-pgsql.xml b/common/changelog/model-pgsql.xml
index dd6b2d6..050a7c5 100644
--- a/common/changelog/model-pgsql.xml
+++ b/common/changelog/model-pgsql.xml
@@ -26,7 +26,7 @@
<column name="v_y"/>
</index>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="INTEGER" null="false"/>
<column name="index" type="BIGINT" null="false"/>
<column name="value" type="INTEGER" null="false"/>
diff --git a/common/changelog/model-sqlite.xml b/common/changelog/model-sqlite.xml
index 4b1b473..e2cf7cf 100644
--- a/common/changelog/model-sqlite.xml
+++ b/common/changelog/model-sqlite.xml
@@ -26,7 +26,7 @@
<column name="v_y"/>
</index>
</table>
- <table name="object_nums">
+ <table name="object_nums" kind="container">
<column name="object_id" type="INTEGER" null="false"/>
<column name="index" type="INTEGER" null="false"/>
<column name="value" type="INTEGER" null="false"/>
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
}