diff options
Diffstat (limited to 'common/query/array')
-rw-r--r-- | common/query/array/buildfile | 43 | ||||
-rw-r--r-- | common/query/array/driver.cxx | 81 | ||||
-rw-r--r-- | common/query/array/makefile | 117 | ||||
-rw-r--r-- | common/query/array/test.hxx | 12 | ||||
-rw-r--r-- | common/query/array/test.std | 0 | ||||
-rw-r--r-- | common/query/array/testscript | 33 |
6 files changed, 128 insertions, 158 deletions
diff --git a/common/query/array/buildfile b/common/query/array/buildfile new file mode 100644 index 0000000..3beb6d0 --- /dev/null +++ b/common/query/array/buildfile @@ -0,0 +1,43 @@ +# file : common/query/array/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +libs = + +for db: $databases + import libs += libodb-$db%lib{odb-$db} + +import libs += lib{common} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{test-odb} testscript + +# Introduce the metadata library target to make sure the libodb library is +# resolved for the odb_compile ad hoc rule (see build/root.build for details). +# +libue{test-meta}: $libodb + +<{hxx ixx cxx}{test-odb}>: hxx{test} libue{test-meta} + +for db: $databases +{ + exe{driver}: {hxx ixx cxx}{test-odb-$db}: include = $multi + <{hxx ixx cxx}{test-odb-$db}>: hxx{test} libue{test-meta} +} + +exe{driver}: libue{test-meta} $libs + +# Specify the ODB custom options to be used by the odb_compile ad hoc rule +# (see build/root.build for details). +# +odb_options = --table-prefix t_query_array_ \ + --generate-schema \ + --generate-query \ + --generate-prepared \ + --sql-name-case oracle:upper + +cxx.poptions =+ "-I$out_base" "-I$src_base" + +# Testscript's run-time prerequisites. +# +exe{driver}: ../../../alias{database-client}: include = adhoc diff --git a/common/query/array/driver.cxx b/common/query/array/driver.cxx index 4559553..9327751 100644 --- a/common/query/array/driver.cxx +++ b/common/query/array/driver.cxx @@ -5,36 +5,39 @@ // #include <string> -#include <memory> // std::auto_ptr +#include <memory> // std::unique_ptr #include <cstring> // std::memcpy -#include <cassert> #include <iostream> #include <odb/database.hxx> #include <odb/transaction.hxx> -#include <common/config.hxx> // DATABASE_* -#include <common/common.hxx> +#include <libcommon/config.hxx> // DATABASE_* +#include <libcommon/common.hxx> #include "test.hxx" #include "test-odb.hxx" +#undef NDEBUG +#include <cassert> + using namespace std; using namespace odb::core; -#if defined(DATABASE_MYSQL) +#ifndef MULTI_DATABASE +# if defined(DATABASE_MYSQL) const odb::mysql::database_type_id bt = odb::mysql::id_blob; -#elif defined(DATABASE_SQLITE) +# elif defined(DATABASE_SQLITE) const odb::sqlite::database_type_id bt = odb::sqlite::id_blob; -#elif defined(DATABASE_PGSQL) +# elif defined(DATABASE_PGSQL) const odb::pgsql::database_type_id bt = odb::pgsql::id_bytea; -#elif defined(DATABASE_ORACLE) +# elif defined(DATABASE_ORACLE) const odb::oracle::database_type_id bt = odb::oracle::id_raw; -#elif defined(DATABASE_MSSQL) +# elif defined(DATABASE_MSSQL) const odb::mssql::database_type_id bt = odb::mssql::id_binary; -#elif defined(DATABASE_COMMON) -#else -# error unknown database +# else +# error unknown database +# endif #endif int @@ -42,7 +45,7 @@ main (int argc, char* argv[]) { try { - auto_ptr<database> db (create_database (argc, argv)); + unique_ptr<database> db (create_database (argc, argv)); typedef odb::query<object> query; @@ -67,7 +70,7 @@ main (int argc, char* argv[]) // string // -#ifndef DATABASE_COMMON +#ifndef MULTI_DATABASE 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); @@ -77,12 +80,12 @@ main (int argc, char* argv[]) { char a[] = "bcd"; char* ra = a; -#ifndef DATABASE_COMMON +#ifndef MULTI_DATABASE 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 +#ifndef MULTI_DATABASE assert (size (db->query<object> ("s = " + query::_val (a))) == 1); assert (size (db->query<object> ("s = " + query::_ref (a))) == 1); #endif @@ -91,12 +94,12 @@ main (int argc, char* argv[]) { const char a[] = "bcd"; const char* ra = a; -#ifndef DATABASE_COMMON +#ifndef MULTI_DATABASE 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 +#ifndef MULTI_DATABASE assert (size (db->query<object> ("s = " + query::_val (a))) == 1); assert (size (db->query<object> ("s = " + query::_ref (a))) == 1); #endif @@ -104,12 +107,12 @@ main (int argc, char* argv[]) { const char* p = "cde"; -#ifndef DATABASE_COMMON +#ifndef MULTI_DATABASE 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 +#ifndef MULTI_DATABASE assert (size (db->query<object> ("s = " + query::_val (p))) == 1); assert (size (db->query<object> ("s = " + query::_ref (p))) == 1); #endif @@ -118,18 +121,18 @@ main (int argc, char* argv[]) { char a[] = "cde"; char* p = a; -#ifndef DATABASE_COMMON +#ifndef MULTI_DATABASE 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 +#ifndef MULTI_DATABASE assert (size (db->query<object> ("s = " + query::_val (p))) == 1); assert (size (db->query<object> ("s = " + query::_ref (p))) == 1); #endif } -#ifndef DATABASE_COMMON +#ifndef MULTI_DATABASE string s ("abc"); //assert (size (db->query<object> (query::s == s)) == 1); assert (size (db->query<object> (query::s == s.c_str ())) == 1); @@ -140,24 +143,42 @@ main (int argc, char* argv[]) assert (size (db->query<object> ("s = " + query::_ref (s))) == 1); #endif + // @@ BUILD2 Ends up with the following warning, but strangely only in the + // multi-database mode: + // + // In file included from odb/odb-tests/common/query/array/test-odb.hxx:31, + // from odb/odb-tests/common/query/array/driver.cxx:20: + // odb/libodb/odb/query-dynamic.hxx: In instantiation of ‘odb::query_base odb::query_column<T>::operator==(const odb::query_column<T2>&) const [with T2 = char [17]; T = char [17]]’: + // odb/odb-tests/common/query/array/driver.cxx:144:7: required from here + // odb/libodb/odb/query-dynamic.hxx:895:43: error: comparison between two arrays is deprecated in C++20 [-Werror=array-compare] + // 895 | (void) (sizeof (type_instance<T> () == type_instance<T2> ())); + // | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ + // odb/libodb/odb/query-dynamic.hxx:895:43: note: use unary ‘+’ which decays operands to pointers or ‘&‘indirect_ref’ not supported by dump_decl<declaration error>[0] == &‘indirect_ref’ not supported by dump_decl<declaration error>[0]’ to compare the addresses + // + // Looks like compile-time assertion. Doesn't make much sense for + // arrays since compares pointers to objects rather than objects. + // Should we somehow suppress the assertion for arrays or similar? + // + // Note: temporarily ifndef-ed. + // +#ifndef MULTI_DATABASE assert (size (db->query<object> (query::s == query::s1)) == 3); +#endif // std::array // -#ifdef ODB_CXX11 array<char, 17> a; memcpy (a.data (), "abc", 4); // VC++ strcpy deprecation. -#ifndef DATABASE_COMMON +#ifndef MULTI_DATABASE 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 +#ifndef MULTI_DATABASE assert (size (db->query<object> ("a = " + query::_val (a))) == 1); assert (size (db->query<object> ("a = " + query::_ref (a))) == 1); #endif -#endif // char // @@ -167,7 +188,7 @@ 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 +#ifndef MULTI_DATABASE assert (size (db->query<object> ("c = " + query::_val ('c'))) == 1); assert (size (db->query<object> ("c = " + query::_ref (c))) == 1); #endif @@ -176,14 +197,14 @@ main (int argc, char* argv[]) // buffer // -#ifndef DATABASE_COMMON +#ifndef MULTI_DATABASE 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 +#ifndef MULTI_DATABASE assert (size (db->query<object> ("b = " + query::_val<bt> (buf))) == 3); assert (size (db->query<object> ("b = " + query::_ref<bt> (buf))) == 3); #endif diff --git a/common/query/array/makefile b/common/query/array/makefile deleted file mode 100644 index e873a34..0000000 --- a/common/query/array/makefile +++ /dev/null @@ -1,117 +0,0 @@ -# file : common/query/array/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := test.hxx -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 - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -# Build. -# -$(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) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --generate-query \ ---generate-prepared --sql-name-case oracle:upper --table-prefix t_query_array_ -$(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)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/common/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): data_dist := test.std -$(dist): export name := $(name) -$(dist): export extra_dist := $(data_dist) $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) $(data_dist)) - $(call meta-automake,../../template/Makefile.am) - $(call meta-vc8projs,../../template/template,$(name)) - $(call meta-vc9projs,../../template/template,$(name)) - $(call meta-vc10projs,../../template/template,$(name)) - $(call meta-vc11projs,../../template/template,$(name)) - $(call meta-vc12projs,../../template/template,$(name)) - -# Test. -# -ifneq ($(db_id),common) -$(eval $(call test-rule)) -else -$(foreach d,$(databases),$(eval $(call test-rule,$d))) -endif - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addsuffix .hxx.clean,$(filter %.cxx,$(gen))) - $(call message,,rm -f $(out_base)/test.out) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - -# Dependencies. -# -$(call import,$(src_root)/libcommon/makefile) diff --git a/common/query/array/test.hxx b/common/query/array/test.hxx index d280f02..f0d5f3b 100644 --- a/common/query/array/test.hxx +++ b/common/query/array/test.hxx @@ -4,14 +4,9 @@ #ifndef TEST_HXX #define TEST_HXX -#include <common/config.hxx> // HAVE_CXX11 - +#include <array> #include <cstring> // std::memcpy, std::strlen -#ifdef HAVE_CXX11 -# include <array> -#endif - #include <odb/core.hxx> #pragma db object @@ -23,10 +18,7 @@ struct object { std::memcpy (s_, s, std::strlen (s) + 1); // VC++ strncpy deprecation. std::memcpy (s1_, s, std::strlen (s) + 1); - -#ifdef HAVE_CXX11 std::memcpy (a_.data (), s, std::strlen (s) + 1); -#endif c_ = c1_ = *s; std::memcpy (b_, b, sizeof (b_)); } @@ -37,7 +29,6 @@ struct object char s_[17]; char s1_[17]; -#ifdef HAVE_CXX11 #ifdef ODB_COMPILER # if defined(ODB_DATABASE_MYSQL) || \ defined(ODB_DATABASE_PGSQL) || \ @@ -53,7 +44,6 @@ struct object # endif #endif std::array<char, 17> a_; -#endif char c_; char c1_; diff --git a/common/query/array/test.std b/common/query/array/test.std deleted file mode 100644 index e69de29..0000000 --- a/common/query/array/test.std +++ /dev/null diff --git a/common/query/array/testscript b/common/query/array/testscript new file mode 100644 index 0000000..631ae24 --- /dev/null +++ b/common/query/array/testscript @@ -0,0 +1,33 @@ +# file : common/query/array/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../../../database-options.testscript + +: mysql +: +if $mysql +{ + .include ../../../mysql.testscript + + $create_schema; + $* +} + +: sqlite +: +if $sqlite +{ + .include ../../../sqlite.testscript + + $* +} + +: pgsql +: +if $pgsql +{ + .include ../../../pgsql.testscript + + $create_schema; + $* +} |