diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2013-06-21 10:39:59 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2013-06-21 10:39:59 +0200 |
commit | 6cd8b9f561b912f264ba4f723845935c40a3cb95 (patch) | |
tree | 5983e0af3d2ee621242ca6707a58c89b9914d8f0 /common/query | |
parent | 236cd9bb1dd022e64d690c9b0080d1a15c5f61c7 (diff) |
Add support for running tests in dynamic multi-database mode
Only possible in the development build system at this stage.
Diffstat (limited to 'common/query')
-rw-r--r-- | common/query/array/driver.cxx | 34 | ||||
-rw-r--r-- | common/query/array/makefile | 29 | ||||
-rw-r--r-- | common/query/array/test.hxx | 3 | ||||
-rw-r--r-- | common/query/basics/driver.cxx | 88 | ||||
-rw-r--r-- | common/query/basics/makefile | 29 |
5 files changed, 118 insertions, 65 deletions
diff --git a/common/query/array/driver.cxx b/common/query/array/driver.cxx index c449566..5b0d378 100644 --- a/common/query/array/driver.cxx +++ b/common/query/array/driver.cxx @@ -32,6 +32,7 @@ const odb::pgsql::database_type_id bt = odb::pgsql::id_bytea; const odb::oracle::database_type_id bt = odb::oracle::id_raw; #elif defined(DATABASE_MSSQL) const odb::mssql::database_type_id bt = odb::mssql::id_binary; +#elif defined(DATABASE_COMMON) #else # error unknown database #endif @@ -66,57 +67,78 @@ main (int argc, char* argv[]) // string // +#ifndef DATABASE_COMMON assert (size (db->query<object> (query::s == "abc")) == 1); assert (size (db->query<object> (query::s == query::_val ("bcd"))) == 1); assert (size (db->query<object> ("s = " + query::_val ("bcd"))) == 1); assert (size (db->query<object> ("s = " + query::_ref ("bcd"))) == 1); +#endif { char a[] = "bcd"; char* ra = a; +#ifndef DATABASE_COMMON assert (size (db->query<object> (query::s == a)) == 1); assert (size (db->query<object> (query::s == query::_val (a))) == 1); +#endif assert (size (db->query<object> (query::s == query::_ref (ra))) == 1); +#ifndef DATABASE_COMMON assert (size (db->query<object> ("s = " + query::_val (a))) == 1); assert (size (db->query<object> ("s = " + query::_ref (a))) == 1); +#endif } { const char a[] = "bcd"; const char* ra = a; +#ifndef DATABASE_COMMON assert (size (db->query<object> (query::s == a)) == 1); assert (size (db->query<object> (query::s == query::_val (a))) == 1); +#endif assert (size (db->query<object> (query::s == query::_ref (ra))) == 1); +#ifndef DATABASE_COMMON assert (size (db->query<object> ("s = " + query::_val (a))) == 1); assert (size (db->query<object> ("s = " + query::_ref (a))) == 1); +#endif } { const char* p = "cde"; +#ifndef DATABASE_COMMON assert (size (db->query<object> (query::s == p)) == 1); assert (size (db->query<object> (query::s == query::_val (p))) == 1); +#endif assert (size (db->query<object> (query::s == query::_ref (p))) == 1); +#ifndef DATABASE_COMMON assert (size (db->query<object> ("s = " + query::_val (p))) == 1); assert (size (db->query<object> ("s = " + query::_ref (p))) == 1); +#endif } { char a[] = "cde"; char* p = a; +#ifndef DATABASE_COMMON assert (size (db->query<object> (query::s == p)) == 1); assert (size (db->query<object> (query::s == query::_val (p))) == 1); +#endif assert (size (db->query<object> (query::s == query::_ref (p))) == 1); +#ifndef DATABASE_COMMON assert (size (db->query<object> ("s = " + query::_val (p))) == 1); assert (size (db->query<object> ("s = " + query::_ref (p))) == 1); +#endif } +#ifndef DATABASE_COMMON string s ("abc"); //assert (size (db->query<object> (query::s == s)) == 1); assert (size (db->query<object> (query::s == s.c_str ())) == 1); //assert (size (db->query<object> (query::s == query::_val (s))) == 1); assert (size (db->query<object> (query::s == query::_val (s.c_str ()))) == 1); + assert (size (db->query<object> ("s = " + query::_val (s))) == 1); assert (size (db->query<object> ("s = " + query::_ref (s))) == 1); +#endif assert (size (db->query<object> (query::s == query::s1)) == 3); @@ -126,12 +148,16 @@ main (int argc, char* argv[]) array<char, 17> a; strcpy (a.data (), "abc"); +#ifndef DATABASE_COMMON assert (size (db->query<object> (query::a == a)) == 1); assert (size (db->query<object> (query::a == query::_val (a))) == 1); +#endif assert (size (db->query<object> (query::a == query::_ref (a))) == 1); +#ifndef DATABASE_COMMON assert (size (db->query<object> ("a = " + query::_val (a))) == 1); assert (size (db->query<object> ("a = " + query::_ref (a))) == 1); #endif +#endif // char // @@ -141,18 +167,26 @@ main (int argc, char* argv[]) assert (size (db->query<object> (query::c == query::_val (c))) == 1); assert (size (db->query<object> (query::c == query::_ref (c))) == 1); +#ifndef DATABASE_COMMON assert (size (db->query<object> ("c = " + query::_val ('c'))) == 1); assert (size (db->query<object> ("c = " + query::_ref (c))) == 1); +#endif assert (size (db->query<object> (query::c == query::c1)) == 3); // buffer // +#ifndef DATABASE_COMMON assert (size (db->query<object> (query::b == buf)) == 3); assert (size (db->query<object> (query::b == query::_val (buf))) == 3); +#endif + assert (size (db->query<object> (query::b == query::_ref (buf))) == 3); + +#ifndef DATABASE_COMMON assert (size (db->query<object> ("b = " + query::_val<bt> (buf))) == 3); assert (size (db->query<object> ("b = " + query::_ref<bt> (buf))) == 3); +#endif t.commit (); } diff --git a/common/query/array/makefile b/common/query/array/makefile index 3708b9d..d8fa45b 100644 --- a/common/query/array/makefile +++ b/common/query/array/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/query/array/test.hxx b/common/query/array/test.hxx index e086a44..e9cbd15 100644 --- a/common/query/array/test.hxx +++ b/common/query/array/test.hxx @@ -46,6 +46,8 @@ struct object # pragma db type("VARCHAR(16)") # elif defined(ODB_DATABASE_SQLITE) # pragma db type("TEXT") +# elif defined(ODB_DATABASE_COMMON) +# pragma db type("DYMMU") // Necessary to make it a value. # else # error unknown database # endif @@ -67,6 +69,7 @@ struct object # pragma db type("RAW(16)") # elif defined(ODB_DATABASE_MSSQL) # pragma db type("BINARY(16)") +# elif defined(ODB_DATABASE_COMMON) # else # error unknown database # endif 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<database> db (create_database (argc, argv)); + odb::database_id db_id (db->id ()); typedef odb::query<person> query; typedef odb::result<person> 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<person> ("age >= 30 AND last = 'Doe'")); -#else - result r (db->query<person> ("\"age\" >= 30 AND \"last\" = 'Doe'")); -#endif + + result r; + if (db_id != odb::id_oracle) + r = db->query<person> ("age >= 30 AND last = 'Doe'"); + else + r = db->query<person> ("\"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<person> ( - "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<person> ( - "\"age\" >= " + query::_ref (30) + "AND" + + "\"age\" >= " + query::_val (30) + "AND" + "\"last\" = " + query::_val (name))); +#else + result r ( + db->query<person> ( + "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<person> (query::age == query::_ref (name)); db->query<person> (query::last_name == "Doe"); db->query<person> (query::last_name == name); +#ifndef DATABASE_COMMON db->query<person> (query::last_name == query::_val ("Doe")); +#endif db->query<person> (query::last_name == query::_val (name)); db->query<person> (query::last_name == query::_ref (name)); //db->query<person> (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<person> (query::public_key == key2); + if (db_id != odb::id_oracle) + { + r = db->query<person> (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<person> (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. |