aboutsummaryrefslogtreecommitdiff
path: root/evolution/combined
diff options
context:
space:
mode:
Diffstat (limited to 'evolution/combined')
-rw-r--r--evolution/combined/driver.cxx54
-rw-r--r--evolution/combined/makefile9
-rw-r--r--evolution/combined/model.hxx33
3 files changed, 77 insertions, 19 deletions
diff --git a/evolution/combined/driver.cxx b/evolution/combined/driver.cxx
index c87b14e..9cb2853 100644
--- a/evolution/combined/driver.cxx
+++ b/evolution/combined/driver.cxx
@@ -11,6 +11,7 @@
#include <odb/database.hxx>
#include <odb/transaction.hxx>
+#include <odb/schema-catalog.hxx>
#include <common/common.hxx>
@@ -27,7 +28,8 @@ main (int argc, char* argv[])
{
try
{
- auto_ptr<database> db (create_database (argc, argv));
+ auto_ptr<database> db (create_database (argc, argv, false));
+ bool embedded (schema_catalog::exists (*db, "test2"));
// 1 - base version
// 2 - migration
@@ -41,21 +43,35 @@ main (int argc, char* argv[])
{
using namespace v2;
+ if (embedded)
+ {
+ transaction t (db->begin ());
+ schema_catalog::create_schema (*db, "test2");
+ schema_catalog::create_schema (*db, "test1");
+ schema_catalog::migrate_schema (*db, 2, "test2");
+ t.commit ();
+ }
+
object o ("1");
o.dui = 1;
- o.dfk = new object1 (1);
- o.acn = 1;
o.anui = 1;
o.dnui = 1;
o.dt.push_back (1);
+ o.aui = 1;
+
+#ifndef DATABASE_SQLITE
+ o.dfk = new object1 (1);
+ o.acn = 1;
o.dc = 1;
o.acnn.reset ();
o.afk = 1;
- o.aui = 1;
+#endif
{
transaction t (db->begin ());
+#ifndef DATABASE_SQLITE
db->persist (o.dfk);
+#endif
db->persist (o);
t.commit ();
}
@@ -65,26 +81,44 @@ main (int argc, char* argv[])
{
using namespace v3;
+ if (embedded)
+ {
+ transaction t (db->begin ());
+ schema_catalog::migrate_schema_pre (*db, 3, "test2");
+ t.commit ();
+ }
+
{
transaction t (db->begin ());
auto_ptr<object> p (db->load<object> ("1"));
assert (p->ac1 == 999);
assert (!p->ac2);
- assert (!p->ac3);
+#ifndef DATABASE_SQLITE
+ assert (!p->ac3);
+#endif
// Migrate.
//
- p->dfk = 999;
p->at.push_back ("abc");
+
+#ifndef DATABASE_SQLITE
+ p->dfk = 999;
p->ac3 = 1;
p->acn.reset ();
p->acnn = 1;
-
+#endif
db->update (*p);
t.commit ();
}
+
+ if (embedded)
+ {
+ transaction t (db->begin ());
+ schema_catalog::migrate_schema_post (*db, 3, "test2");
+ t.commit ();
+ }
break;
}
case 3:
@@ -97,12 +131,14 @@ main (int argc, char* argv[])
// Check post-migration.
//
- assert (p->dfk == 999);
assert (p->at[0] == "abc");
+
+#ifndef DATABASE_SQLITE
+ assert (p->dfk == 999);
assert (*p->ac3 == 1);
assert (!p->acn);
assert (*p->acnn == 1);
-
+#endif
t.commit ();
}
break;
diff --git a/evolution/combined/makefile b/evolution/combined/makefile
index 493f022..a489287 100644
--- a/evolution/combined/makefile
+++ b/evolution/combined/makefile
@@ -29,15 +29,16 @@ $(driver): $(cxx_obj) $(common.l)
$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base)
$(cxx_obj) $(cxx_od): $(common.l.cpp-options)
-genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx test1.sql model.xml
+genf1 := test1-odb.hxx test1-odb.ixx test1-odb.cxx model.xml
gen1 := $(addprefix $(out_base)/,$(genf1))
-genf2 := test2-odb.hxx test2-odb.ixx test2-odb.cxx test2.sql \
-test2-002-pre.sql test2-002-post.sql test2-003-pre.sql test2-003-post.sql
+genf2 := test2-odb.hxx test2-odb.ixx test2-odb.cxx
gen2 := $(addprefix $(out_base)/,$(genf2))
genf := $(genf1) $(genf2)
gen := $(gen1) $(gen2)
+gens := test1.sql test2.sql test2-002-pre.sql test2-002-post.sql \
+test2-003-pre.sql test2-003-post.sql
$(gen): $(odb)
$(gen): odb := $(odb)
@@ -113,7 +114,7 @@ $(clean): \
ifeq ($(out_base),$(src_base))
$(driver): | $(out_base)/.gitignore
-$(out_base)/.gitignore: files := driver $(genf)
+$(out_base)/.gitignore: files := driver $(genf) $(gens)
$(clean): $(out_base)/.gitignore.clean
$(call include,$(bld_root)/git/gitignore.make)
diff --git a/evolution/combined/model.hxx b/evolution/combined/model.hxx
index 2aede90..2cdc9d7 100644
--- a/evolution/combined/model.hxx
+++ b/evolution/combined/model.hxx
@@ -12,6 +12,8 @@
#include <odb/core.hxx>
#include <odb/nullable.hxx>
+#include <common/config.hxx> // DATABASE_XXX
+
#pragma db model version(1, MODEL_VERSION)
#define MODEL_NAMESPACE_IMPL(V) v##V
@@ -45,14 +47,16 @@ namespace MODEL_NAMESPACE(MODEL_VERSION)
#endif
unsigned long dui;
- // Alter table drop foreign key.
+ // Alter table drop foreign key. Not supported by SQLite.
//
+#ifndef DATABASE_SQLITE
#if MODEL_VERSION == 2
object1* dfk;
#else
#pragma db null
unsigned long dfk;
#endif
+#endif
// Add table.
//
@@ -68,17 +72,23 @@ namespace MODEL_NAMESPACE(MODEL_VERSION)
odb::nullable<unsigned long> ac2;
- #pragma db not_null // Initially added as NULL, converted to NOT NULL.
+ // Initially added as NULL, converted to NOT NULL. Not supported by SQLite.
+ //
+#ifndef DATABASE_SQLITE
+ #pragma db not_null
odb::nullable<unsigned long> ac3;
#endif
+#endif
- // Alter column NULL.
+ // Alter column NULL. Not supported by SQLite.
//
+#ifndef DATABASE_SQLITE
#if MODEL_VERSION == 2
unsigned long acn;
#else
odb::nullable<unsigned long> acn;
#endif
+#endif
//
// Pre pass 2.
@@ -112,27 +122,33 @@ namespace MODEL_NAMESPACE(MODEL_VERSION)
std::vector<unsigned long> dt;
#endif
- // Drop column.
+ // Drop column. Not supported by SQLite.
//
+#ifndef DATABASE_SQLITE
#if MODEL_VERSION == 2
unsigned long dc;
#endif
+#endif
- // Alter column NOT NULL.
+ // Alter column NOT NULL. Not supported by SQLite.
//
+#ifndef DATABASE_SQLITE
#if MODEL_VERSION == 3
#pragma db not_null
#endif
odb::nullable<unsigned long> acnn;
+#endif
- // Alter table add foreign key.
+ // Alter table add foreign key. Not supported by SQLite.
//
+#ifndef DATABASE_SQLITE
#if MODEL_VERSION == 2
#pragma db null
unsigned long afk;
#else
object1* afk;
#endif
+#endif
// Add unique index.
//
@@ -142,13 +158,18 @@ namespace MODEL_NAMESPACE(MODEL_VERSION)
unsigned long aui;
public:
+#ifndef DATABASE_SQLITE
#if MODEL_VERSION == 2
+
object (std::string id = ""): id_ (id), dfk (0) {}
~object () {delete dfk;}
#else
object (std::string id = ""): id_ (id), afk (0) {}
~object () {delete afk;}
#endif
+#else
+ object (std::string id = ""): id_ (id) {}
+#endif
};
}