summaryrefslogtreecommitdiff
path: root/pgsql/bulk
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 /pgsql/bulk
parent02367faedb16b6186e8852de47e5b749dc48c2df (diff)
Switch to build2
Diffstat (limited to 'pgsql/bulk')
-rw-r--r--pgsql/bulk/buildfile40
-rw-r--r--pgsql/bulk/driver.cxx39
-rw-r--r--pgsql/bulk/makefile107
-rw-r--r--pgsql/bulk/test.std0
-rw-r--r--pgsql/bulk/testscript18
5 files changed, 88 insertions, 116 deletions
diff --git a/pgsql/bulk/buildfile b/pgsql/bulk/buildfile
new file mode 100644
index 0000000..6984edb
--- /dev/null
+++ b/pgsql/bulk/buildfile
@@ -0,0 +1,40 @@
+# file : pgsql/bulk/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+if ($build.meta_operation != 'dist')
+{
+ assert ($pgsql && !$multi) \
+ "pgsql should be configured via config.odb_tests.database variable as a single database"
+
+ assert ($pgsql_bulk) "bulk operations are disabled for pgsql"
+}
+
+import libodb = libodb%lib{odb}
+
+import libs = libpq%lib{pq}
+import libs += libodb-pgsql%lib{odb-pgsql}
+import libs += lib{common}
+
+exe{driver}: {hxx cxx}{* -*-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}
+
+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 pgsql_bulk_ \
+ --generate-schema \
+ --generate-query
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../alias{pgsql-client}: include = adhoc
diff --git a/pgsql/bulk/driver.cxx b/pgsql/bulk/driver.cxx
index fd629b8..ba25542 100644
--- a/pgsql/bulk/driver.cxx
+++ b/pgsql/bulk/driver.cxx
@@ -1,4 +1,4 @@
-// file : pgsql/savepoint/driver.cxx
+// file : pgsql/bulk/driver.cxx
// license : GNU GPL v2; see accompanying LICENSE file
// Test transaction savepoints.
@@ -10,7 +10,6 @@
#include <stdio.h>
#include <string.h>
#include <stddef.h>
-#include <assert.h>
#include <sys/select.h>
// Note: hack.
@@ -18,6 +17,9 @@
#include <arpa/inet.h>
#define htonll(x) ((((long long)htonl(x)) << 32) + htonl((x) >> 32))
+#undef NDEBUG
+#include <assert.h>
+
static const size_t columns = 3;
struct data
@@ -255,20 +257,22 @@ test (PGconn* conn)
}
}
-#include <memory> // std::auto_ptr
-#include <cassert>
-#include <iostream>
-
#include <vector>
+#include <memory> // std::unique_ptr
+#include <cstring>
+#include <iostream>
#include <odb/pgsql/database.hxx>
#include <odb/pgsql/transaction.hxx>
-#include <common/common.hxx>
+#include <libcommon/common.hxx>
#include "test.hxx"
#include "test-odb.hxx"
+#undef NDEBUG
+#include <cassert>
+
using namespace std;
namespace pgsql = odb::pgsql;
using namespace pgsql;
@@ -276,9 +280,26 @@ using namespace pgsql;
int
main (int argc, char* argv[])
{
+ bool fail_already_persistent (false);
+
+ for (int i (1); i != argc; ++i)
+ {
+ if (strcmp (argv[i], "--fail-already-persistent") == 0)
+ {
+ fail_already_persistent = true;
+
+ for (; i != argc - 1; ++i)
+ argv[i] = argv[i + 1];
+
+ --argc;
+
+ break;
+ }
+ }
+
try
{
- auto_ptr<database> db (create_specific_database<database> (argc, argv));
+ unique_ptr<database> db (create_specific_database<database> (argc, argv));
connection_ptr cn (db->connection ());
@@ -297,7 +318,7 @@ main (int argc, char* argv[])
{
os.push_back (object {i, i, string (i, 'x')});
- if (i == n / 2)
+ if (fail_already_persistent && i == n / 2)
os.push_back (object {i, i, to_string (i)});
}
diff --git a/pgsql/bulk/makefile b/pgsql/bulk/makefile
deleted file mode 100644
index 12f8dbb..0000000
--- a/pgsql/bulk/makefile
+++ /dev/null
@@ -1,107 +0,0 @@
-# file : pgsql/savepoint/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 += --database pgsql --generate-schema \
---generate-query --table-prefix pgsql_bulk_
-$(gen): cpp_options := -I$(src_base)
-$(gen): $(common.l.cpp-options)
-
-$(call include-dep,$(cxx_od),$(cxx_obj),$(gen))
-
-# Alias for default target.
-#
-$(out_base)/: $(driver)
-
-# Dist
-#
-$(dist): sources := $(cxx_tun)
-$(dist): headers := $(odb_hdr)
-$(dist): data_dist := test.std
-$(dist): export name := $(subst /,-,$(subst $(src_root)/pgsql/,,$(src_base)))
-$(dist): export extra_dist := $(data_dist) \
-$(name)-vc8.vcproj $(name)-vc9.vcproj \
-$(name)-vc10.vcxproj $(name)-vc10.vcxproj.filters \
-$(name)-vc11.vcxproj $(name)-vc11.vcxproj.filters \
-$(name)-vc12.vcxproj $(name)-vc12.vcxproj.filters
-$(dist):
- $(call dist-data,$(sources) $(headers) $(data_dist))
- $(call meta-automake,../template/Makefile.am)
- $(call meta-vc8proj,../template/template-vc8.vcproj,$(name)-vc8.vcproj)
- $(call meta-vc9proj,../template/template-vc9.vcproj,$(name)-vc9.vcproj)
- $(call meta-vc10proj,../template/template-vc10.vcxproj,$(name)-vc10.vcxproj)
- $(call meta-vc11proj,../template/template-vc11.vcxproj,$(name)-vc11.vcxproj)
- $(call meta-vc12proj,../template/template-vc12.vcxproj,$(name)-vc12.vcxproj)
-
-# Test.
-#
-$(eval $(call test-rule))
-
-# 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/pgsql/bulk/test.std b/pgsql/bulk/test.std
deleted file mode 100644
index e69de29..0000000
--- a/pgsql/bulk/test.std
+++ /dev/null
diff --git a/pgsql/bulk/testscript b/pgsql/bulk/testscript
new file mode 100644
index 0000000..60b7d92
--- /dev/null
+++ b/pgsql/bulk/testscript
@@ -0,0 +1,18 @@
+# file : pgsql/custom/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../database-options.testscript
+.include ../../pgsql.testscript
+
++$create_schema
+
+: basics
+:
+{
+ $*;
+
+ $* --fail-already-persistent 2>>EOE != 0
+ multiple exceptions, 252 elements attempted, 1 failed, fatal:
+ [251] object already persistent
+ EOE
+}