diff options
Diffstat (limited to 'evolution/drop-column')
-rw-r--r-- | evolution/drop-column/driver.cxx | 11 | ||||
-rw-r--r-- | evolution/drop-column/makefile | 2 | ||||
-rw-r--r-- | evolution/drop-column/model.hxx | 42 |
3 files changed, 31 insertions, 24 deletions
diff --git a/evolution/drop-column/driver.cxx b/evolution/drop-column/driver.cxx index 4078c58..6e72f7d 100644 --- a/evolution/drop-column/driver.cxx +++ b/evolution/drop-column/driver.cxx @@ -29,10 +29,6 @@ main (int argc, char* argv[]) try { auto_ptr<database> db (create_database (argc, argv, false)); - - // SQLite doesn't support dropping of columns. - // -#ifndef DATABASE_SQLITE bool embedded (schema_catalog::exists (*db)); // 1 - base version @@ -60,9 +56,11 @@ main (int argc, char* argv[]) object o (1); o.str = "abc"; o.num = 123; + o.ptr = new object1 (1, 2); { transaction t (db->begin ()); + db->persist (*o.ptr); db->persist (o); t.commit (); } @@ -87,6 +85,7 @@ main (int argc, char* argv[]) assert (p->str == "abc"); assert (p->num == 123); + assert (p->ptr->id.x == 1 && p->ptr->id.y == 2); t.commit (); } @@ -108,7 +107,8 @@ main (int argc, char* argv[]) { transaction t (db->begin ()); auto_ptr<object> p (db->load<object> (1)); - assert (p->str == ""); + assert (p->str == "" && p->ptr == 0); + db->erase<object1> (value (1, 2)); // SQLite logical delete test. t.commit (); } break; @@ -119,7 +119,6 @@ main (int argc, char* argv[]) return 1; } } -#endif // DATABASE_SQLITE } catch (const odb::exception& e) { diff --git a/evolution/drop-column/makefile b/evolution/drop-column/makefile index 135c3fc..f22097e 100644 --- a/evolution/drop-column/makefile +++ b/evolution/drop-column/makefile @@ -37,7 +37,7 @@ $(cxx_obj) $(cxx_od): $(common.l.cpp-options) $(gen): $(odb) $(gen): odb := $(odb) $(gen) $(dist): odb_common_options = --generate-query \ ---generate-schema --at-once --table-prefix evo_drop_c_ +--generate-schema --at-once --sqlite-override-null --table-prefix evo_drop_c_ $(gen): odb_common_options += --database $(db_id) $(gen1) $(dist): export odb_options1 = $(odb_common_options) --init-changelog $(gen2) $(dist): export odb_options2 = $(odb_common_options) --omit-create \ diff --git a/evolution/drop-column/model.hxx b/evolution/drop-column/model.hxx index feff041..b69cd0d 100644 --- a/evolution/drop-column/model.hxx +++ b/evolution/drop-column/model.hxx @@ -11,8 +11,6 @@ #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 @@ -20,32 +18,42 @@ namespace MODEL_NAMESPACE(MODEL_VERSION) { + #pragma db value + struct value + { + value (int x_ = 0, int y_ = 0): x (x_), y (y_) {} + int x; + int y; + }; + + #pragma db object + struct object1 + { + object1 (int x = 0, int y = 0): id (x, y) {} + + #pragma db id + value id; + }; + #pragma db object struct object { - object (unsigned long id = 0): id_ (id) {} + object (unsigned long id = 0): id_ (id), ptr (0) {} + ~object () {delete ptr;} #pragma db id unsigned long id_; - // SQLite doesn't support dropping of columns. - // -#ifndef DATABASE_SQLITE -#if MODEL_VERSION >= 2 - -#if MODEL_VERSION == 3 - #pragma db deleted(3) -#endif std::string str; - -#if MODEL_VERSION == 3 - #pragma db deleted(3) -#endif unsigned long num; + object1* ptr; + }; +#if MODEL_VERSION == 3 + #pragma db member(object::str) deleted(3) + #pragma db member(object::num) deleted(3) + #pragma db member(object::ptr) deleted(3) #endif -#endif - }; } #undef MODEL_NAMESPACE |