From 6cd8b9f561b912f264ba4f723845935c40a3cb95 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 21 Jun 2013 10:39:59 +0200 Subject: Add support for running tests in dynamic multi-database mode Only possible in the development build system at this stage. --- common/schema/embedded/basics/driver.cxx | 11 ++++------- common/schema/embedded/basics/makefile | 28 +++++++++++++--------------- common/schema/embedded/order/driver.cxx | 20 +++++++++----------- common/schema/embedded/order/makefile | 28 +++++++++++++--------------- common/schema/namespace/makefile | 29 +++++++++++++---------------- common/schema/namespace/test.hxx | 2 ++ 6 files changed, 54 insertions(+), 64 deletions(-) (limited to 'common/schema') diff --git a/common/schema/embedded/basics/driver.cxx b/common/schema/embedded/basics/driver.cxx index 5a14149..a67529c 100644 --- a/common/schema/embedded/basics/driver.cxx +++ b/common/schema/embedded/basics/driver.cxx @@ -13,7 +13,6 @@ #include #include -#include // DATABASE_XXX #include #include "test.hxx" @@ -36,9 +35,8 @@ main (int argc, char* argv[]) // Temporarily disable foreign key constraints for SQLite. // -#if defined(DATABASE_SQLITE) - c->execute ("PRAGMA foreign_keys=OFF"); -#endif + if (db->id () == odb::id_sqlite) + c->execute ("PRAGMA foreign_keys=OFF"); assert (schema_catalog::exists (*db, "test")); assert (!schema_catalog::exists (*db, "test1")); @@ -48,9 +46,8 @@ main (int argc, char* argv[]) schema_catalog::create_schema (*db, "test"); t.commit (); -#if defined(DATABASE_SQLITE) - c->execute ("PRAGMA foreign_keys=ON"); -#endif + if (db->id () == odb::id_sqlite) + c->execute ("PRAGMA foreign_keys=ON"); } } catch (const odb::exception& e) diff --git a/common/schema/embedded/basics/makefile b/common/schema/embedded/basics/makefile index 96e987a..07a246f 100644 --- a/common/schema/embedded/basics/makefile +++ b/common/schema/embedded/basics/makefile @@ -6,17 +6,14 @@ 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)) +genf := $(call odb-gen,$(odb_hdr)) +gen := $(addprefix $(out_base)/,$(genf)) +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) $(filter %.o,$(gen:.cxx=.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,\ @@ -29,9 +26,6 @@ $(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 += --generate-schema \ @@ -39,7 +33,11 @@ $(gen) $(dist): export odb_options += --generate-schema \ $(gen): cpp_options := -I$(src_base) $(gen): $(common.l.cpp-options) +ifneq ($(db_id),common) $(gen): odb_options += --database $(db_id) +else +$(gen): odb_options += --multi-database dynamic +endif $(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) @@ -66,11 +64,11 @@ $(dist): # Test. # -$(test): $(driver) $(src_base)/test.std - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).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) +ifneq ($(db_id),common) +$(eval $(call test-schemaless-rule)) +else +$(foreach d,$(databases),$(eval $(call test-schemaless-rule,$d))) +endif # Clean. # @@ -78,7 +76,7 @@ $(clean): \ $(driver).o.clean \ $(addsuffix .cxx.clean,$(cxx_obj)) \ $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(addsuffix .hxx.clean,$(filter %.cxx,$(gen))) $(call message,,rm -f $(out_base)/test.out) # Generated .gitignore. diff --git a/common/schema/embedded/order/driver.cxx b/common/schema/embedded/order/driver.cxx index 685693d..0545442 100644 --- a/common/schema/embedded/order/driver.cxx +++ b/common/schema/embedded/order/driver.cxx @@ -13,7 +13,6 @@ #include #include -#include // DATABASE_XXX #include #include "test1.hxx" @@ -31,6 +30,7 @@ main (int argc, char* argv[]) try { auto_ptr db (create_database (argc, argv, false)); + odb::database_id db_id (db->id ()); // Create the database schema. // @@ -41,21 +41,19 @@ main (int argc, char* argv[]) // For MySQL we can actually create the tables in any order. It is // dropping them that's the problem (there is no IF EXISTS). // -#if defined(DATABASE_MYSQL) - c->execute ("SET FOREIGN_KEY_CHECKS=0"); -#elif defined(DATABASE_SQLITE) - c->execute ("PRAGMA foreign_keys=OFF"); -#endif + if (db_id == odb::id_mysql) + c->execute ("SET FOREIGN_KEY_CHECKS=0"); + else if (db_id == odb::id_sqlite) + c->execute ("PRAGMA foreign_keys=OFF"); transaction t (c->begin ()); schema_catalog::create_schema (*db); t.commit (); -#if defined(DATABASE_MYSQL) - c->execute ("SET FOREIGN_KEY_CHECKS=1"); -#elif defined(DATABASE_SQLITE) - c->execute ("PRAGMA foreign_keys=ON"); -#endif + if (db_id == odb::id_mysql) + c->execute ("SET FOREIGN_KEY_CHECKS=1"); + else if (db_id == odb::id_sqlite) + c->execute ("PRAGMA foreign_keys=ON"); } } catch (const odb::exception& e) diff --git a/common/schema/embedded/order/makefile b/common/schema/embedded/order/makefile index e8897d5..10242cf 100644 --- a/common/schema/embedded/order/makefile +++ b/common/schema/embedded/order/makefile @@ -6,17 +6,14 @@ 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)) +genf := $(call odb-gen,$(odb_hdr)) +gen := $(addprefix $(out_base)/,$(genf)) +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) $(filter %.o,$(gen:.cxx=.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,\ @@ -29,9 +26,6 @@ $(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 += --generate-schema \ @@ -43,7 +37,11 @@ $(gen): $(common.l.cpp-options) # $(gen): $(addprefix $(src_base)/,$(odb_hdr)) +ifneq ($(db_id),common) $(gen): odb_options += --database $(db_id) +else +$(gen): odb_options += --multi-database dynamic +endif $(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) @@ -71,11 +69,11 @@ $(dist): # Test. # -$(test): $(driver) $(src_base)/test.std - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).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) +ifneq ($(db_id),common) +$(eval $(call test-schemaless-rule)) +else +$(foreach d,$(databases),$(eval $(call test-schemaless-rule,$d))) +endif # Clean. # @@ -83,7 +81,7 @@ $(clean): \ $(driver).o.clean \ $(addsuffix .cxx.clean,$(cxx_obj)) \ $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(addsuffix .hxx.clean,$(filter %.cxx,$(gen))) $(call message,,rm -f $(out_base)/test.out) # Generated .gitignore. diff --git a/common/schema/namespace/makefile b/common/schema/namespace/makefile index 38f6be1..8d34d43 100644 --- a/common/schema/namespace/makefile +++ b/common/schema/namespace/makefile @@ -6,17 +6,14 @@ 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)) +genf := $(call odb-gen,$(odb_hdr)) +gen := $(addprefix $(out_base)/,$(genf)) +cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o)) $(filter %.o,$(gen:.cxx=.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,\ @@ -29,9 +26,6 @@ $(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 += --generate-schema --generate-query \ @@ -39,7 +33,11 @@ $(gen) $(dist): export odb_options += --generate-schema --generate-query \ $(gen): cpp_options := -I$(src_base) $(gen): $(common.l.cpp-options) +ifneq ($(db_id),common) $(gen): odb_options += --database $(db_id) +else +$(gen): odb_options += --multi-database dynamic +endif $(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) @@ -66,12 +64,11 @@ $(dist): # Test. # -$(test): $(driver) $(src_base)/test.std - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).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) +ifneq ($(db_id),common) +$(eval $(call test-rule)) +else +$(foreach d,$(databases),$(eval $(call test-rule,$d))) +endif # Clean. # @@ -79,7 +76,7 @@ $(clean): \ $(driver).o.clean \ $(addsuffix .cxx.clean,$(cxx_obj)) \ $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) + $(addsuffix .hxx.clean,$(filter %.cxx,$(gen))) $(call message,,rm -f $(out_base)/test.out) # Generated .gitignore. diff --git a/common/schema/namespace/test.hxx b/common/schema/namespace/test.hxx index 351b574..dfaaf19 100644 --- a/common/schema/namespace/test.hxx +++ b/common/schema/namespace/test.hxx @@ -92,6 +92,8 @@ struct type # define DB_SCHEMA "" #elif defined(ODB_DATABASE_MSSQL) # define DB_SCHEMA "dbo" +#elif defined(ODB_DATABASE_COMMON) +# define DB_SCHEMA "dummy" #else # error unknown database #endif -- cgit v1.1