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/view/driver.cxx | 84 +++++++++++++++++++++++++++----------------------- common/view/makefile | 29 ++++++++--------- 2 files changed, 58 insertions(+), 55 deletions(-) (limited to 'common/view') diff --git a/common/view/driver.cxx b/common/view/driver.cxx index b8a8f3e..2c5c65c 100644 --- a/common/view/driver.cxx +++ b/common/view/driver.cxx @@ -58,11 +58,11 @@ view2_test (const auto_ptr& db) } { -#ifndef DATABASE_ORACLE - result r (db->query ("age < 31")); -#else - result r (db->query ("\"age\" < 31")); -#endif + result r; + if (db->id () != odb::id_oracle) + r = db->query ("age < 31"); + else + r = db->query ("\"age\" < 31"); iterator i (r.begin ()); assert (i != r.end ()); @@ -90,11 +90,11 @@ view4_test (const auto_ptr& db) transaction t (db->begin ()); { -#ifndef DATABASE_ORACLE - result r (db->query ((query::person::age > 30) + "ORDER BY age")); -#else - result r (db->query ((query::person::age > 30) + "ORDER BY \"age\"")); -#endif + result r; + if (db->id () != odb::id_oracle) + r = db->query ((query::person::age > 30) + "ORDER BY age"); + else + r = db->query ((query::person::age > 30) + "ORDER BY \"age\""); iterator i (r.begin ()); @@ -237,20 +237,22 @@ main (int argc, char* argv[]) } { -#ifndef DATABASE_ORACLE - result r (db->query ("ORDER BY age")); -#else - result r (db->query ("ORDER BY \"age\"")); -#endif + result r; + if (db->id () != odb::id_oracle) + r = db->query ("ORDER BY age"); + else + r = db->query ("ORDER BY \"age\""); + assert (size (r) == 4); } { -#ifndef DATABASE_ORACLE - result r (db->query ("age < 31 ORDER BY age")); -#else - result r (db->query ("\"age\" < 31 ORDER BY \"age\"")); -#endif + result r; + if (db->id () != odb::id_oracle) + r = db->query ("age < 31 ORDER BY age"); + else + r = db->query ("\"age\" < 31 ORDER BY \"age\""); + view1_check (r); } @@ -289,6 +291,9 @@ main (int argc, char* argv[]) t.commit (); } + // No native parameter support in dynamic multi-database mode. + // +#ifndef DATABASE_COMMON { transaction t (db->begin ()); @@ -306,6 +311,7 @@ main (int argc, char* argv[]) t.commit (); } +#endif } } @@ -317,20 +323,15 @@ main (int argc, char* argv[]) { transaction t (db->begin ()); -#ifndef DATABASE_ORACLE - result r ( - db->query ( - "SELECT first, last, age " - "FROM t_view_person " - "WHERE age < 31 ORDER BY age")); -#else - result r ( - db->query ( - "SELECT \"first\", \"last\", \"age\" " - "FROM \"t_view_person\" " - "WHERE \"age\" < 31 ORDER BY \"age\"")); -#endif - + result r; + if (db->id () != odb::id_oracle) + r = db->query ("SELECT first, last, age " + "FROM t_view_person " + "WHERE age < 31 ORDER BY age"); + else + r = db->query ("SELECT \"first\", \"last\", \"age\" " + "FROM \"t_view_person\" " + "WHERE \"age\" < 31 ORDER BY \"age\""); view1_check (r); t.commit (); @@ -346,11 +347,12 @@ main (int argc, char* argv[]) transaction t (db->begin ()); { -#ifndef DATABASE_ORACLE - result r (db->query ("age < 31 ORDER BY age")); -#else - result r (db->query ("\"age\" < 31 ORDER BY \"age\"")); -#endif + result r; + if (db->id () != odb::id_oracle) + r = db->query ("age < 31 ORDER BY age"); + else + r = db->query ("\"age\" < 31 ORDER BY \"age\""); + view1_check (r); } @@ -466,12 +468,16 @@ main (int argc, char* argv[]) view6_test ( db, odb::query::employer::name == "Simple Tech, Inc"); + // No native parameter support in dynamic multi-database mode. + // +#ifndef DATABASE_COMMON view6_test ( #ifndef DATABASE_ORACLE db, "e.name = " + odb::query::_val ("Simple Tech, Inc")); #else db, "\"e\".\"name\" = " + odb::query::_val ("Simple Tech, Inc")); #endif +#endif // view7 // diff --git a/common/view/makefile b/common/view/makefile index 6aad221..d13e7c6 100644 --- a/common/view/makefile +++ b/common/view/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. -- cgit v1.1