From 7dbf58f9486fb3b3a021bbfab9df03af5a8f0fb3 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 7 Feb 2013 17:52:49 +0200 Subject: Use multi-pass table creation in MySQL This deals with table creation order and circular dependencies. Unfortunately, there doesn't seem to be a way in MySQL to drop a foreign key only if it exists without resorting to stored procedures. --- common/makefile | 3 +- common/schema/driver.cxx | 112 ----------------------- common/schema/embedded/order/driver.cxx | 60 ++++++++++++ common/schema/embedded/order/makefile | 119 ++++++++++++++++++++++++ common/schema/embedded/order/test.std | 0 common/schema/embedded/order/test1.hxx | 24 +++++ common/schema/embedded/order/test2.hxx | 18 ++++ common/schema/makefile | 115 ----------------------- common/schema/namespace/driver.cxx | 112 +++++++++++++++++++++++ common/schema/namespace/makefile | 115 +++++++++++++++++++++++ common/schema/namespace/test.hxx | 157 ++++++++++++++++++++++++++++++++ common/schema/namespace/test.std | 0 common/schema/test.hxx | 157 -------------------------------- common/schema/test.std | 0 14 files changed, 607 insertions(+), 385 deletions(-) delete mode 100644 common/schema/driver.cxx create mode 100644 common/schema/embedded/order/driver.cxx create mode 100644 common/schema/embedded/order/makefile create mode 100644 common/schema/embedded/order/test.std create mode 100644 common/schema/embedded/order/test1.hxx create mode 100644 common/schema/embedded/order/test2.hxx delete mode 100644 common/schema/makefile create mode 100644 common/schema/namespace/driver.cxx create mode 100644 common/schema/namespace/makefile create mode 100644 common/schema/namespace/test.hxx create mode 100644 common/schema/namespace/test.std delete mode 100644 common/schema/test.hxx delete mode 100644 common/schema/test.std diff --git a/common/makefile b/common/makefile index 883fe3f..551a0f8 100644 --- a/common/makefile +++ b/common/makefile @@ -39,7 +39,8 @@ query/array \ readonly \ relationship \ relationship-query \ -schema \ +schema/namespace \ +schema/embedded/order \ session/cache \ template \ transaction/basics \ diff --git a/common/schema/driver.cxx b/common/schema/driver.cxx deleted file mode 100644 index a47d1f6..0000000 --- a/common/schema/driver.cxx +++ /dev/null @@ -1,112 +0,0 @@ -// file : common/schema/driver.cxx -// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC -// license : GNU GPL v2; see accompanying LICENSE file - -// Test various aspects of database schema. -// - -#include // std::auto_ptr -#include -#include - -#include -#include - -#include - -#include "test.hxx" -#include "test-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - // Test database schema (aka database namespace). - // - using ns::object2; - - object2 o2; - o2.id = "aaa"; - o2.nums.push_back (1); - o2.nums.push_back (2); - o2.nums.push_back (3); - o2.obj1 = new object1; - o2.obj1->str = "aaa"; - - { - transaction t (db->begin ()); - db->persist (o2.obj1); - db->persist (o2); - t.commit (); - } - - { - transaction t (db->begin ()); - auto_ptr p2 (db->load ("aaa")); - t.commit (); - - assert (o2 == *p2); - } - - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - { - result r (db->query (query::id == "aaa")); - assert (size (r) == 1); - } - - { - result r (db->query (query::obj1->str == "aaa")); - assert (size (r) == 1); - } - - t.commit (); - } - - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - result r (db->query (query::object2::id == "aaa")); - - result::iterator i (r.begin ()); - assert (i != r.end ()); - assert (i->id2 == "aaa" && i->str == "aaa"); - assert (++i == r.end ()); - - t.commit (); - } - - { - typedef odb::result result; - - transaction t (db->begin ()); - - result r (db->query ()); - - result::iterator i (r.begin ()); - assert (i != r.end ()); - assert (i->str == "aaa"); - assert (++i == r.end ()); - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/common/schema/embedded/order/driver.cxx b/common/schema/embedded/order/driver.cxx new file mode 100644 index 0000000..7503cf5 --- /dev/null +++ b/common/schema/embedded/order/driver.cxx @@ -0,0 +1,60 @@ +// file : common/schema/embedded/order/driver.cxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test statement execution order in embedded schemas. +// + +#include // std::auto_ptr +#include +#include + +#include +#include +#include + +#include // DATABASE_XXX +#include + +#include "test1.hxx" +#include "test2.hxx" + +#include "test1-odb.hxx" +#include "test2-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr db (create_database (argc, argv)); + + // Create the database schema. + // + { + connection_ptr c (db->connection ()); + + // Temporarily disable foreign key constraints for SQLite. + // +#if defined(DATABASE_SQLITE) + c->execute ("PRAGMA foreign_keys=OFF"); +#endif + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + +#if defined(DATABASE_SQLITE) + c->execute ("PRAGMA foreign_keys=ON"); +#endif + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/common/schema/embedded/order/makefile b/common/schema/embedded/order/makefile new file mode 100644 index 0000000..b706345 --- /dev/null +++ b/common/schema/embedded/order/makefile @@ -0,0 +1,119 @@ +# file : common/schema/embedded/order/makefile +# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test2.hxx test1.hxx # Reverse order. +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +# Build. +# +$(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) + +genf := $(foreach f,$(odb_hdr:.hxx=),$(addprefix $f,-odb.hxx -odb.ixx -odb.cxx .sql)) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \ +--schema-format embedded --table-prefix schema_embd_ordr_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) + +# Extra dependecy for the ODB-generated code. +# +$(gen): $(addprefix $(src_base)/,$(odb_hdr)) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export odb_header_stem := $(basename $(odb_hdr)) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) $(call vc11projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../../../../template/Makefile.am) + $(call meta-vc9projs,../../../../template/template,$(name)) + $(call meta-vc10projs,../../../../template/template,$(name)) + $(call meta-vc11projs,../../../../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/vc11proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): odb_options += --std $(cxx_standard) +$(call include,$(odb_rules)) +endif + +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/common/schema/embedded/order/test.std b/common/schema/embedded/order/test.std new file mode 100644 index 0000000..e69de29 diff --git a/common/schema/embedded/order/test1.hxx b/common/schema/embedded/order/test1.hxx new file mode 100644 index 0000000..d7e0622 --- /dev/null +++ b/common/schema/embedded/order/test1.hxx @@ -0,0 +1,24 @@ +// file : common/schema/embedded/order/test1.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST1_HXX +#define TEST1_HXX + +#include + +#include + +#pragma db object polymorphic +struct base +{ + virtual + ~base () {} + + #pragma db auto id + unsigned long id; + + std::string str; +}; + +#endif // TEST1_HXX diff --git a/common/schema/embedded/order/test2.hxx b/common/schema/embedded/order/test2.hxx new file mode 100644 index 0000000..870ca51 --- /dev/null +++ b/common/schema/embedded/order/test2.hxx @@ -0,0 +1,18 @@ +// file : common/schema/embedded/order/test2.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST2_HXX +#define TEST2_HXX + +#include + +#include "test1.hxx" + +#pragma db object +struct derived: base +{ + int num; +}; + +#endif // TEST2_HXX diff --git a/common/schema/makefile b/common/schema/makefile deleted file mode 100644 index e7f03df..0000000 --- a/common/schema/makefile +++ /dev/null @@ -1,115 +0,0 @@ -# file : common/schema/makefile -# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := test.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -common.l := $(out_root)/libcommon/common/common.l -common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -# Build. -# -$(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) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \ ---generate-query --table-prefix schema_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(common.l.cpp-options) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base))) - -$(dist): db_id := @database@ -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): data_dist := test.std -$(dist): export name := $(name) -$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ -$(call vc10projs,$(name)) $(call vc11projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) $(data_dist)) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - -# Test. -# -$(test): $(driver) $(src_base)/test.std - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/db.options \ ->$(out_base)/test.out) - $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) - $(call message,,rm -f $(out_base)/test.out) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - $(call message,,rm -f $(out_base)/test.out) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - -# Dependencies. -# -$(call import,$(src_root)/libcommon/makefile) diff --git a/common/schema/namespace/driver.cxx b/common/schema/namespace/driver.cxx new file mode 100644 index 0000000..d74461c --- /dev/null +++ b/common/schema/namespace/driver.cxx @@ -0,0 +1,112 @@ +// file : common/schema/namespace/driver.cxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +// Test database schemas (aka database namespaces). +// + +#include // std::auto_ptr +#include +#include + +#include +#include + +#include + +#include "test.hxx" +#include "test-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + auto_ptr db (create_database (argc, argv)); + + // Test database schema (aka database namespace). + // + using ns::object2; + + object2 o2; + o2.id = "aaa"; + o2.nums.push_back (1); + o2.nums.push_back (2); + o2.nums.push_back (3); + o2.obj1 = new object1; + o2.obj1->str = "aaa"; + + { + transaction t (db->begin ()); + db->persist (o2.obj1); + db->persist (o2); + t.commit (); + } + + { + transaction t (db->begin ()); + auto_ptr p2 (db->load ("aaa")); + t.commit (); + + assert (o2 == *p2); + } + + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + + { + result r (db->query (query::id == "aaa")); + assert (size (r) == 1); + } + + { + result r (db->query (query::obj1->str == "aaa")); + assert (size (r) == 1); + } + + t.commit (); + } + + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + + result r (db->query (query::object2::id == "aaa")); + + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->id2 == "aaa" && i->str == "aaa"); + assert (++i == r.end ()); + + t.commit (); + } + + { + typedef odb::result result; + + transaction t (db->begin ()); + + result r (db->query ()); + + result::iterator i (r.begin ()); + assert (i != r.end ()); + assert (i->str == "aaa"); + assert (++i == r.end ()); + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/common/schema/namespace/makefile b/common/schema/namespace/makefile new file mode 100644 index 0000000..e15ee10 --- /dev/null +++ b/common/schema/namespace/makefile @@ -0,0 +1,115 @@ +# file : common/schema/namespace/makefile +# copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +# license : GNU GPL v2; see accompanying LICENSE file + +include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make + +cxx_tun := driver.cxx +odb_hdr := test.hxx +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) +cxx_od := $(cxx_obj:.o=.o.d) + +common.l := $(out_root)/libcommon/common/common.l +common.l.cpp-options := $(out_root)/libcommon/common/common.l.cpp-options + +driver := $(out_base)/driver +dist := $(out_base)/.dist +test := $(out_base)/.test +clean := $(out_base)/.clean + +# Import. +# +$(call import,\ + $(scf_root)/import/odb/stub.make,\ + odb: odb,odb-rules: odb_rules) + +# Build. +# +$(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) + +genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) +gen := $(addprefix $(out_base)/,$(genf)) + +$(gen): $(odb) +$(gen): odb := $(odb) +$(gen) $(dist): export odb_options += --database $(db_id) --generate-schema \ +--generate-query --table-prefix schema_ns_ +$(gen): cpp_options := -I$(src_base) +$(gen): $(common.l.cpp-options) + +$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) + +# Alias for default target. +# +$(out_base)/: $(driver) + +# Dist +# +name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base))) + +$(dist): db_id := @database@ +$(dist): sources := $(cxx_tun) +$(dist): headers := $(odb_hdr) +$(dist): data_dist := test.std +$(dist): export name := $(name) +$(dist): export extra_dist := $(data_dist) $(call vc9projs,$(name)) \ +$(call vc10projs,$(name)) $(call vc11projs,$(name)) +$(dist): + $(call dist-data,$(sources) $(headers) $(data_dist)) + $(call meta-automake,../../template/Makefile.am) + $(call meta-vc9projs,../../template/template,$(name)) + $(call meta-vc10projs,../../template/template,$(name)) + $(call meta-vc11projs,../../template/template,$(name)) + +# Test. +# +$(test): $(driver) $(src_base)/test.std + $(call schema) + $(call message,test $<,$< --options-file $(dcf_root)/db.options \ +>$(out_base)/test.out) + $(call message,,diff -u $(src_base)/test.std $(out_base)/test.out) + $(call message,,rm -f $(out_base)/test.out) + +# Clean. +# +$(clean): \ + $(driver).o.clean \ + $(addsuffix .cxx.clean,$(cxx_obj)) \ + $(addsuffix .cxx.clean,$(cxx_od)) \ + $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(call message,,rm -f $(out_base)/test.out) + +# Generated .gitignore. +# +ifeq ($(out_base),$(src_base)) +$(driver): | $(out_base)/.gitignore + +$(out_base)/.gitignore: files := driver $(genf) +$(clean): $(out_base)/.gitignore.clean + +$(call include,$(bld_root)/git/gitignore.make) +endif + +# How to. +# +$(call include,$(bld_root)/dist.make) +$(call include,$(bld_root)/meta/vc9proj.make) +$(call include,$(bld_root)/meta/vc10proj.make) +$(call include,$(bld_root)/meta/vc11proj.make) +$(call include,$(bld_root)/meta/automake.make) + +$(call include,$(bld_root)/cxx/standard.make) # cxx_standard +ifdef cxx_standard +$(gen): odb_options += --std $(cxx_standard) +$(call include,$(odb_rules)) +endif + +$(call include,$(bld_root)/cxx/cxx-d.make) +$(call include,$(bld_root)/cxx/cxx-o.make) +$(call include,$(bld_root)/cxx/o-e.make) + +# Dependencies. +# +$(call import,$(src_root)/libcommon/makefile) diff --git a/common/schema/namespace/test.hxx b/common/schema/namespace/test.hxx new file mode 100644 index 0000000..44d5c60 --- /dev/null +++ b/common/schema/namespace/test.hxx @@ -0,0 +1,157 @@ +// file : common/schema/namespace/test.hxx +// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef TEST_HXX +#define TEST_HXX + +#include +#include + +#include + +// Table names. +// +#pragma db object table("TABLE_EXPLICIT") +struct table_explicit +{ + #pragma db id + unsigned long id_; +}; + +#pragma db object +struct table_implicit +{ + #pragma db id + unsigned long id_; +}; + +// Column names. +// +#pragma db object +struct column +{ + #pragma db id + int m1; + + #pragma db column("foo") + int m2; + + int m_m3; + int _m4; + int m5_; + int m_; + int m__; +}; + +// Column types. +// +#pragma db object +struct type +{ + #pragma db id + std::string id; + + // Test default C++ to DB type mapping. + // + bool b; + char c; + signed char sc; + unsigned char uc; + short s; + unsigned short us; + int i; + unsigned int ui; + long l; + unsigned long ul; + long long ll; + unsigned long long ull; + float f; + double d; + std::string str; + + #pragma db type("INTEGER") + bool m1; + + #pragma db transient + char* m2; +}; + +// Test database schema (aka database namespace). +// +#ifdef ODB_COMPILER +#if defined (ODB_DATABASE_MYSQL) +//# define DB_SCHEMA "odb_test" +# define DB_SCHEMA "" +#elif defined (ODB_DATABASE_SQLITE) +# define DB_SCHEMA "main" +#elif defined (ODB_DATABASE_PGSQL) +# define DB_SCHEMA "public" +#elif defined (ODB_DATABASE_ORACLE) +//# define DB_SCHEMA "ODB_TEST" +# define DB_SCHEMA "" +#elif defined(ODB_DATABASE_MSSQL) +# define DB_SCHEMA "dbo" +#else +# error unknown database +#endif +#endif + +namespace ns {typedef int my_int;} // Original. + +#pragma db object table(DB_SCHEMA."object_1") +struct object1 +{ + #pragma db id auto + unsigned long id; + + #pragma db column("str") + std::string str; +}; + +inline bool +operator== (const object1& x, const object1& y) +{ + return x.id == y.id && x.str == y.str; +} + +#pragma db namespace schema(DB_SCHEMA) +namespace ns // Extension. +{ + #pragma db object + struct object2 + { + object2 (): obj1 (0) {} + ~object2 () {delete obj1;} + + #pragma db id + std::string id; + + std::vector nums; + object1* obj1; + }; + + inline bool + operator== (const object2& x, const object2& y) + { + return x.id == y.id && x.nums == y.nums && *x.obj1 == *y.obj1; + } +} + +#pragma db view object(object1) object(ns::object2) +struct object_view +{ + #pragma db column(ns::object2::id) + std::string id2; + + std::string str; +}; + +#pragma db view table(DB_SCHEMA."schema_object_1") +struct table_view +{ + #pragma db column(DB_SCHEMA."schema_object_1"."str") + std::string str; +}; + +#endif // TEST_HXX diff --git a/common/schema/namespace/test.std b/common/schema/namespace/test.std new file mode 100644 index 0000000..e69de29 diff --git a/common/schema/test.hxx b/common/schema/test.hxx deleted file mode 100644 index 5e30518..0000000 --- a/common/schema/test.hxx +++ /dev/null @@ -1,157 +0,0 @@ -// file : common/schema/test.hxx -// copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef TEST_HXX -#define TEST_HXX - -#include -#include - -#include - -// Table names. -// -#pragma db object table("TABLE_EXPLICIT") -struct table_explicit -{ - #pragma db id - unsigned long id_; -}; - -#pragma db object -struct table_implicit -{ - #pragma db id - unsigned long id_; -}; - -// Column names. -// -#pragma db object -struct column -{ - #pragma db id - int m1; - - #pragma db column("foo") - int m2; - - int m_m3; - int _m4; - int m5_; - int m_; - int m__; -}; - -// Column types. -// -#pragma db object -struct type -{ - #pragma db id - std::string id; - - // Test default C++ to DB type mapping. - // - bool b; - char c; - signed char sc; - unsigned char uc; - short s; - unsigned short us; - int i; - unsigned int ui; - long l; - unsigned long ul; - long long ll; - unsigned long long ull; - float f; - double d; - std::string str; - - #pragma db type("INTEGER") - bool m1; - - #pragma db transient - char* m2; -}; - -// Test database schema (aka database namespace). -// -#ifdef ODB_COMPILER -#if defined (ODB_DATABASE_MYSQL) -//# define DB_SCHEMA "odb_test" -# define DB_SCHEMA "" -#elif defined (ODB_DATABASE_SQLITE) -# define DB_SCHEMA "main" -#elif defined (ODB_DATABASE_PGSQL) -# define DB_SCHEMA "public" -#elif defined (ODB_DATABASE_ORACLE) -//# define DB_SCHEMA "ODB_TEST" -# define DB_SCHEMA "" -#elif defined(ODB_DATABASE_MSSQL) -# define DB_SCHEMA "dbo" -#else -# error unknown database -#endif -#endif - -namespace ns {typedef int my_int;} // Original. - -#pragma db object table(DB_SCHEMA."object_1") -struct object1 -{ - #pragma db id auto - unsigned long id; - - #pragma db column("str") - std::string str; -}; - -inline bool -operator== (const object1& x, const object1& y) -{ - return x.id == y.id && x.str == y.str; -} - -#pragma db namespace schema(DB_SCHEMA) -namespace ns // Extension. -{ - #pragma db object - struct object2 - { - object2 (): obj1 (0) {} - ~object2 () {delete obj1;} - - #pragma db id - std::string id; - - std::vector nums; - object1* obj1; - }; - - inline bool - operator== (const object2& x, const object2& y) - { - return x.id == y.id && x.nums == y.nums && *x.obj1 == *y.obj1; - } -} - -#pragma db view object(object1) object(ns::object2) -struct object_view -{ - #pragma db column(ns::object2::id) - std::string id2; - - std::string str; -}; - -#pragma db view table(DB_SCHEMA."schema_object_1") -struct table_view -{ - #pragma db column(DB_SCHEMA."schema_object_1"."str") - std::string str; -}; - -#endif // TEST_HXX diff --git a/common/schema/test.std b/common/schema/test.std deleted file mode 100644 index e69de29..0000000 -- cgit v1.1