diff options
Diffstat (limited to 'common/threads')
-rw-r--r-- | common/threads/driver.cxx | 18 | ||||
-rw-r--r-- | common/threads/makefile | 29 |
2 files changed, 25 insertions, 22 deletions
diff --git a/common/threads/driver.cxx b/common/threads/driver.cxx index 0714d4a..3114072 100644 --- a/common/threads/driver.cxx +++ b/common/threads/driver.cxx @@ -17,10 +17,10 @@ #include <odb/details/shared-ptr.hxx> #include <odb/details/thread.hxx> -#include <common/config.hxx> // DATABASE_SQLITE +#include <common/config.hxx> // DATABASE_* #include <common/common.hxx> -#ifdef DATABASE_SQLITE +#if defined(DATABASE_SQLITE) || defined(DATABASE_COMMON) # include <odb/sqlite/database.hxx> #endif @@ -70,7 +70,7 @@ struct task { try { -#ifndef DATABASE_SQLITE +#if !defined(DATABASE_SQLITE) && !defined(DATABASE_COMMON) transaction t (db_.begin ()); #else // SQLite has a peculiar table locking mode (shared cache) @@ -79,10 +79,16 @@ struct task // perspective. One way to work around this problem is to // start a "write" transaction as such right away. // - transaction t ( - static_cast<odb::sqlite::database&> (db_).begin_immediate ()); -#endif + transaction t; + if (db_.id () != odb::id_sqlite) + t.reset (db_.begin ()); + else + { + t.reset ( + static_cast<odb::sqlite::database&> (db_).begin_immediate ()); + } +#endif auto_ptr<object> o (db_.load<object> (id)); assert (o->str_ == "first object"); o->str_ = "another value"; diff --git a/common/threads/makefile b/common/threads/makefile index 91adc8d..92d00d7 100644 --- a/common/threads/makefile +++ b/common/threads/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. |