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/query/basics/driver.cxx | 88 ++++++++++++++++++++++++++---------------- common/query/basics/makefile | 29 +++++++------- 2 files changed, 68 insertions(+), 49 deletions(-) (limited to 'common/query/basics') diff --git a/common/query/basics/driver.cxx b/common/query/basics/driver.cxx index ee8e3b1..be45237 100644 --- a/common/query/basics/driver.cxx +++ b/common/query/basics/driver.cxx @@ -48,6 +48,7 @@ main (int argc, char* argv[]) try { auto_ptr db (create_database (argc, argv)); + odb::database_id db_id (db->id ()); typedef odb::query query; typedef odb::result result; @@ -70,8 +71,13 @@ main (int argc, char* argv[]) t.commit (); } + // + // Native queries. + // + // Compilation tests. // +#ifndef DATABASE_COMMON if (false) { string name; @@ -92,6 +98,7 @@ main (int argc, char* argv[]) query q1 (query::_val (name)); q1 += " = first"; } +#endif // Select-all query. // @@ -139,11 +146,13 @@ main (int argc, char* argv[]) cout << "test 003" << endl; { transaction t (db->begin ()); -#ifndef DATABASE_ORACLE - result r (db->query ("age >= 30 AND last = 'Doe'")); -#else - result r (db->query ("\"age\" >= 30 AND \"last\" = 'Doe'")); -#endif + + result r; + if (db_id != odb::id_oracle) + r = db->query ("age >= 30 AND last = 'Doe'"); + else + r = db->query ("\"age\" >= 30 AND \"last\" = 'Doe'"); + print (r); t.commit (); } @@ -156,16 +165,22 @@ main (int argc, char* argv[]) const char* name = "Doe"; -#ifndef DATABASE_ORACLE +#if defined(DATABASE_COMMON) result r ( db->query ( - "age >= " + query::_ref (30) + "AND" + - "last = " + query::_val (name))); -#else + query::age >= query::_val (30) && + query::last_name == query::_val (name))); + +#elif defined(DATABASE_ORACLE) result r ( db->query ( - "\"age\" >= " + query::_ref (30) + "AND" + + "\"age\" >= " + query::_val (30) + "AND" + "\"last\" = " + query::_val (name))); +#else + result r ( + db->query ( + "age >= " + query::_val (30) + "AND" + + "last = " + query::_val (name))); #endif print (r); @@ -181,12 +196,15 @@ main (int argc, char* argv[]) string name; unsigned short age; -#ifndef DATABASE_ORACLE - query q ("age >= " + query::_ref (age) + "AND" + - "last = " + query::_ref (name)); -#else +#if defined(DATABASE_COMMON) + query q (query::age >= query::_ref (age) && + query::last_name == query::_ref (name)); +#elif defined(DATABASE_ORACLE) query q ("\"age\" >= " + query::_ref (age) + "AND" + "\"last\" = " + query::_ref (name)); +#else + query q ("age >= " + query::_ref (age) + "AND" + + "last = " + query::_ref (name)); #endif name = "Doe"; @@ -232,7 +250,9 @@ main (int argc, char* argv[]) //db->query (query::age == query::_ref (name)); db->query (query::last_name == "Doe"); db->query (query::last_name == name); +#ifndef DATABASE_COMMON db->query (query::last_name == query::_val ("Doe")); +#endif db->query (query::last_name == query::_val (name)); db->query (query::last_name == query::_ref (name)); //db->query (query::last_name == 30); @@ -437,9 +457,8 @@ main (int argc, char* argv[]) // SQL Server does not support re-loading of an object with long data // from a query result. // -#ifndef DATABASE_MSSQL - assert (i->last_name_ == "Doe"); // Actual load. -#endif + if (db_id != odb::id_mssql) + assert (i->last_name_ == "Doe"); // Actual load. // Overwrite object image again. // @@ -470,18 +489,22 @@ main (int argc, char* argv[]) result r; result::iterator i; + // == + // + // Oracle does not support LOB comparisons. // #ifndef DATABASE_ORACLE - // == - // - r = db->query (query::public_key == key2); + if (db_id != odb::id_oracle) + { + r = db->query (query::public_key == key2); - i = r.begin (); - assert (i != r.end ()); + i = r.begin (); + assert (i != r.end ()); - assert (*i->public_key_ == key2); - assert (++i == r.end ()); + assert (*i->public_key_ == key2); + assert (++i == r.end ()); + } #endif // is_null @@ -549,9 +572,9 @@ main (int argc, char* argv[]) // Test size() validity at the beginning/middle/end of result set. // cout << "test 019" << endl; -#if !defined(DATABASE_SQLITE) && \ - !defined(DATABASE_ORACLE) && \ - !defined(DATABASE_MSSQL) + if (db_id != odb::id_sqlite && + db_id != odb::id_oracle && + db_id != odb::id_mssql) { { transaction t (db->begin ()); @@ -600,7 +623,6 @@ main (int argc, char* argv[]) assert (r.size () == 0); } } -#endif // Test like. // @@ -619,11 +641,11 @@ main (int argc, char* argv[]) // In Oracle one can only escape special characters (% and _). // -#if defined(DATABASE_ORACLE) - string v ("Ja%"); -#else - string v ("!Ja%"); -#endif + string v; + if (db_id != odb::id_oracle) + v = "!Ja%"; + else + v = "Ja%"; r = db->query (query::first_name.like (query::_ref (v), "!")); print (r); diff --git a/common/query/basics/makefile b/common/query/basics/makefile index ec63728..fc26133 100644 --- a/common/query/basics/makefile +++ b/common/query/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 --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