aboutsummaryrefslogtreecommitdiff
path: root/common/query/basics
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-12-13 21:57:53 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2024-01-23 21:20:44 +0300
commitfc3fb39c90ab7fe5fccbe3f3bc0eb2645157bb96 (patch)
tree6c8c1bfb5fe89f7378b92ac066b4ca8ecfd25228 /common/query/basics
parent02367faedb16b6186e8852de47e5b749dc48c2df (diff)
Switch to build2
Diffstat (limited to 'common/query/basics')
-rw-r--r--common/query/basics/buildfile42
-rw-r--r--common/query/basics/driver.cxx28
-rw-r--r--common/query/basics/makefile117
-rw-r--r--common/query/basics/test.hxx6
-rw-r--r--common/query/basics/test.std112
-rw-r--r--common/query/basics/testscript150
6 files changed, 207 insertions, 248 deletions
diff --git a/common/query/basics/buildfile b/common/query/basics/buildfile
new file mode 100644
index 0000000..e38e6fe
--- /dev/null
+++ b/common/query/basics/buildfile
@@ -0,0 +1,42 @@
+# file : common/query/basics/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_basics_ \
+ --generate-schema \
+ --generate-query \
+ --generate-prepared
+
+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/basics/driver.cxx b/common/query/basics/driver.cxx
index 86bae4b..73b81d2 100644
--- a/common/query/basics/driver.cxx
+++ b/common/query/basics/driver.cxx
@@ -4,19 +4,21 @@
// Test basic query support.
//
-#include <memory> // std::auto_ptr
-#include <cassert>
+#include <memory> // std::unique_ptr
#include <iostream>
#include <odb/database.hxx>
#include <odb/transaction.hxx>
-#include <common/config.hxx> // DATABASE_XXX
-#include <common/common.hxx>
+#include <libcommon/config.hxx> // DATABASE_XXX
+#include <libcommon/common.hxx>
#include "test.hxx"
#include "test-odb.hxx"
+#undef NDEBUG
+#include <cassert>
+
using namespace std;
using namespace odb::core;
@@ -25,7 +27,7 @@ print (result<person>& r)
{
for (result<person>::iterator i (r.begin ()); i != r.end (); ++i)
{
- auto_ptr<person> o (i.load ());
+ unique_ptr<person> o (i.load ());
cout << *o << endl;
}
cout << endl;
@@ -46,7 +48,7 @@ main (int argc, char* argv[])
try
{
- auto_ptr<database> db (create_database (argc, argv));
+ unique_ptr<database> db (create_database (argc, argv));
odb::database_id db_id (db->id ());
typedef odb::query<person> query;
@@ -76,7 +78,7 @@ main (int argc, char* argv[])
// Compilation tests.
//
-#ifndef DATABASE_COMMON
+#ifndef MULTI_DATABASE
if (false)
{
string name;
@@ -164,7 +166,7 @@ main (int argc, char* argv[])
const char* name = "Doe";
-#if defined(DATABASE_COMMON)
+#if defined(MULTI_DATABASE)
result r (
db->query<person> (
query::age >= query::_val (30) &&
@@ -195,7 +197,7 @@ main (int argc, char* argv[])
string name;
unsigned short age;
-#if defined(DATABASE_COMMON)
+#if defined(MULTI_DATABASE)
query q (query::age >= query::_ref (age) &&
query::last_name == query::_ref (name));
#elif defined(DATABASE_ORACLE)
@@ -249,7 +251,7 @@ 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
+#ifndef MULTI_DATABASE
db->query<person> (query::last_name == query::_val ("Doe"));
#endif
db->query<person> (query::last_name == query::_val (name));
@@ -450,7 +452,7 @@ main (int argc, char* argv[])
assert (i != r.end ());
{
- auto_ptr<person> joe (db->load<person> (3));
+ unique_ptr<person> joe (db->load<person> (3));
}
{
@@ -467,7 +469,7 @@ main (int argc, char* argv[])
// Overwrite object image again.
//
- auto_ptr<person> joe (db->load<person> (3));
+ unique_ptr<person> joe (db->load<person> (3));
person p;
i.load (p);
assert (p.last_name_ == "Doe");
@@ -499,7 +501,7 @@ main (int argc, char* argv[])
// Oracle does not support LOB comparisons.
//
-#ifndef DATABASE_ORACLE
+#if defined(MULTI_DATABASE) || !defined(DATABASE_ORACLE)
if (db_id != odb::id_oracle)
{
r = db->query<person> (query::public_key == key2);
diff --git a/common/query/basics/makefile b/common/query/basics/makefile
deleted file mode 100644
index b1749e7..0000000
--- a/common/query/basics/makefile
+++ /dev/null
@@ -1,117 +0,0 @@
-# file : common/query/basics/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 --table-prefix t_query_basics_
-$(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/basics/test.hxx b/common/query/basics/test.hxx
index 22a8d32..239f6d6 100644
--- a/common/query/basics/test.hxx
+++ b/common/query/basics/test.hxx
@@ -4,8 +4,6 @@
#ifndef TEST_HXX
#define TEST_HXX
-#include <common/config.hxx> // HAVE_CXX11
-
#include <string>
#include <vector>
#include <memory>
@@ -56,11 +54,7 @@ struct person
std::string first_name_;
#pragma db column ("middle") null
-#ifdef HAVE_CXX11
std::unique_ptr<std::string> middle_name_;
-#else
- std::auto_ptr<std::string> middle_name_;
-#endif
#pragma db column ("last")
std::string last_name_;
diff --git a/common/query/basics/test.std b/common/query/basics/test.std
deleted file mode 100644
index d420dc4..0000000
--- a/common/query/basics/test.std
+++ /dev/null
@@ -1,112 +0,0 @@
-test 001
-John Doe 30 married
-Jane Doe 29 married
-Joe Squeaky Dirt 31 single
-Johansen J Johansen 32 single
-test 002
-Jane Doe 29 married
-John Doe 30 married
-Joe Squeaky Dirt 31 single
-Johansen J Johansen 32 single
-
-test 003
-John Doe 30 married
-
-test 004
-John Doe 30 married
-
-test 005
-John Doe 30 married
-
-Joe Squeaky Dirt 31 single
-
-test 006
-John Doe 30 married
-Jane Doe 29 married
-
-Joe Squeaky Dirt 31 single
-Johansen J Johansen 32 single
-
-test 007
-John Doe 30 married
-Jane Doe 29 married
-
-Joe Squeaky Dirt 31 single
-Johansen J Johansen 32 single
-
-test 008
-John Doe 30 married
-Jane Doe 29 married
-
-Joe Squeaky Dirt 31 single
-
-John Doe 30 married
-Jane Doe 29 married
-
-test 009
-John Doe 30 married
-Jane Doe 29 married
-
-Joe Squeaky Dirt 31 single
-Johansen J Johansen 32 single
-
-John Doe 30 married
-Jane Doe 29 married
-
-Joe Squeaky Dirt 31 single
-Johansen J Johansen 32 single
-
-John Doe 30 married
-Jane Doe 29 married
-
-Joe Squeaky Dirt 31 single
-Johansen J Johansen 32 single
-
-test 010
-Jane Doe 29 married
-
-John Doe 30 married
-Jane Doe 29 married
-Joe Squeaky Dirt 31 single
-
-Jane Doe 29 married
-
-Joe Squeaky Dirt 31 single
-Johansen J Johansen 32 single
-
-Jane Doe 29 married
-John Doe 30 married
-
-test 011
-John Doe 30 married
-Jane Doe 29 married
-
-John Doe 30 married
-Jane Doe 29 married
-Joe Squeaky Dirt 31 single
-
-test 012
-Johansen J Johansen 32 single
-
-test 013
-Joe Squeaky Dirt 31 single
-
-test 014
-test 015
-John Doe 30 married
-Jane Doe 29 married
-
-test 016
-test 017
-test 018
-test 019
-test 020
-John Doe 30 married
-Joe Squeaky Dirt 31 single
-Johansen J Johansen 32 single
-
-Jane Doe 29 married
-
-
-Jane Doe 29 married
-
diff --git a/common/query/basics/testscript b/common/query/basics/testscript
new file mode 100644
index 0000000..9086b66
--- /dev/null
+++ b/common/query/basics/testscript
@@ -0,0 +1,150 @@
+# file : common/query/basics/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../../database-options.testscript
+
++cat <<EOI >=output
+ test 001
+ John Doe 30 married
+ Jane Doe 29 married
+ Joe Squeaky Dirt 31 single
+ Johansen J Johansen 32 single
+ test 002
+ Jane Doe 29 married
+ John Doe 30 married
+ Joe Squeaky Dirt 31 single
+ Johansen J Johansen 32 single
+
+ test 003
+ John Doe 30 married
+
+ test 004
+ John Doe 30 married
+
+ test 005
+ John Doe 30 married
+
+ Joe Squeaky Dirt 31 single
+
+ test 006
+ John Doe 30 married
+ Jane Doe 29 married
+
+ Joe Squeaky Dirt 31 single
+ Johansen J Johansen 32 single
+
+ test 007
+ John Doe 30 married
+ Jane Doe 29 married
+
+ Joe Squeaky Dirt 31 single
+ Johansen J Johansen 32 single
+
+ test 008
+ John Doe 30 married
+ Jane Doe 29 married
+
+ Joe Squeaky Dirt 31 single
+
+ John Doe 30 married
+ Jane Doe 29 married
+
+ test 009
+ John Doe 30 married
+ Jane Doe 29 married
+
+ Joe Squeaky Dirt 31 single
+ Johansen J Johansen 32 single
+
+ John Doe 30 married
+ Jane Doe 29 married
+
+ Joe Squeaky Dirt 31 single
+ Johansen J Johansen 32 single
+
+ John Doe 30 married
+ Jane Doe 29 married
+
+ Joe Squeaky Dirt 31 single
+ Johansen J Johansen 32 single
+
+ test 010
+ Jane Doe 29 married
+
+ John Doe 30 married
+ Jane Doe 29 married
+ Joe Squeaky Dirt 31 single
+
+ Jane Doe 29 married
+
+ Joe Squeaky Dirt 31 single
+ Johansen J Johansen 32 single
+
+ Jane Doe 29 married
+ John Doe 30 married
+
+ test 011
+ John Doe 30 married
+ Jane Doe 29 married
+
+ John Doe 30 married
+ Jane Doe 29 married
+ Joe Squeaky Dirt 31 single
+
+ test 012
+ Johansen J Johansen 32 single
+
+ test 013
+ Joe Squeaky Dirt 31 single
+
+ test 014
+ test 015
+ John Doe 30 married
+ Jane Doe 29 married
+
+ test 016
+ test 017
+ test 018
+ test 019
+ test 020
+ John Doe 30 married
+ Joe Squeaky Dirt 31 single
+ Johansen J Johansen 32 single
+
+ Jane Doe 29 married
+
+
+ Jane Doe 29 married
+
+ EOI
+
+test.redirects += >>>../output
+
+: mysql
+:
+if $mysql
+{
+ .include ../../../mysql.testscript
+
+ $create_schema;
+ $*
+}
+
+: sqlite
+:
+if $sqlite
+{
+ .include ../../../sqlite.testscript
+
+ $*
+}
+
+: pgsql
+:
+if $pgsql
+{
+ .include ../../../pgsql.testscript
+
+ $create_schema;
+ $*
+}