From d9f372d7b1bc1abbff5fdf9735118290cd024d5e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 25 Jan 2024 17:28:38 +0300 Subject: Turn libodb-pgsql repository into package for muti-package repository --- .gitignore | 37 - GPLv2 | 340 --- INSTALL | 103 - INSTALL-GIT | 78 - LICENSE | 20 - Makefile.am | 10 - NEWS | 1 - README | 20 - README-GIT | 5 - bootstrap | 16 - build/.gitignore | 3 - build/bootstrap.build | 10 - build/bootstrap.make | 70 - build/export.build | 9 - build/export/libodb-pgsql/stub.make | 8 - build/import/cli/cli-cxx.make | 47 - build/import/cli/configuration-rules.make | 13 - build/import/cli/configure | 53 - build/import/cli/stub.make | 28 - build/import/libodb-pgsql/configuration-rules.make | 13 - build/import/libodb-pgsql/configure | 53 - build/import/libodb-pgsql/stub.make | 28 - build/import/libodb/configuration-rules.make | 13 - build/import/libodb/configure | 53 - build/import/libodb/stub.make | 28 - build/import/libpq/configuration-rules.make | 13 - build/import/libpq/configure | 79 - build/import/libpq/rules.make | 29 - build/import/libpq/stub.make | 33 - build/import/libpq/version | 1 - build/root.build | 19 - buildfile | 9 - configure.ac | 57 - libodb-pgsql-vc10.sln | 26 - libodb-pgsql-vc11.sln | 26 - libodb-pgsql-vc12.sln | 28 - libodb-pgsql-vc8.sln | 26 - libodb-pgsql-vc9.sln | 26 - libodb-pgsql.pc.in | 14 - libodb-pgsql/.gitignore | 25 + libodb-pgsql/GPLv2 | 340 +++ libodb-pgsql/INSTALL | 6 + libodb-pgsql/LICENSE | 20 + libodb-pgsql/README | 20 + libodb-pgsql/build/.gitignore | 3 + libodb-pgsql/build/bootstrap.build | 10 + libodb-pgsql/build/export.build | 9 + libodb-pgsql/build/root.build | 19 + libodb-pgsql/buildfile | 9 + libodb-pgsql/manifest | 23 + libodb-pgsql/odb/pgsql/auto-handle.cxx | 24 + libodb-pgsql/odb/pgsql/auto-handle.hxx | 90 + libodb-pgsql/odb/pgsql/binding.hxx | 74 + libodb-pgsql/odb/pgsql/buildfile | 155 ++ libodb-pgsql/odb/pgsql/connection-factory.cxx | 159 ++ libodb-pgsql/odb/pgsql/connection-factory.hxx | 134 ++ libodb-pgsql/odb/pgsql/connection.cxx | 141 ++ libodb-pgsql/odb/pgsql/connection.hxx | 183 ++ libodb-pgsql/odb/pgsql/connection.ixx | 44 + libodb-pgsql/odb/pgsql/container-statements.hxx | 425 ++++ libodb-pgsql/odb/pgsql/container-statements.txx | 154 ++ libodb-pgsql/odb/pgsql/database.cxx | 424 ++++ libodb-pgsql/odb/pgsql/database.hxx | 527 +++++ libodb-pgsql/odb/pgsql/database.ixx | 638 ++++++ libodb-pgsql/odb/pgsql/details/.gitignore | 1 + .../odb/pgsql/details/build2/config-stub.h | 5 + .../odb/pgsql/details/build2/config-vc-stub.h | 5 + libodb-pgsql/odb/pgsql/details/build2/config-vc.h | 15 + libodb-pgsql/odb/pgsql/details/build2/config.h | 17 + libodb-pgsql/odb/pgsql/details/config-vc.h | 5 + libodb-pgsql/odb/pgsql/details/config.h.in | 12 + libodb-pgsql/odb/pgsql/details/config.hxx | 21 + libodb-pgsql/odb/pgsql/details/conversion.hxx | 58 + libodb-pgsql/odb/pgsql/details/endian-traits.cxx | 30 + libodb-pgsql/odb/pgsql/details/endian-traits.hxx | 155 ++ libodb-pgsql/odb/pgsql/details/export.hxx | 78 + libodb-pgsql/odb/pgsql/details/options.cli | 56 + .../pregenerated/odb/pgsql/details/options.cxx | 1114 ++++++++++ .../pregenerated/odb/pgsql/details/options.hxx | 562 +++++ .../pregenerated/odb/pgsql/details/options.ixx | 372 ++++ libodb-pgsql/odb/pgsql/error.cxx | 86 + libodb-pgsql/odb/pgsql/error.hxx | 41 + libodb-pgsql/odb/pgsql/error.ixx | 31 + libodb-pgsql/odb/pgsql/exceptions.cxx | 79 + libodb-pgsql/odb/pgsql/exceptions.hxx | 80 + libodb-pgsql/odb/pgsql/forward.hxx | 91 + libodb-pgsql/odb/pgsql/no-id-object-result.hxx | 77 + libodb-pgsql/odb/pgsql/no-id-object-result.txx | 114 + libodb-pgsql/odb/pgsql/no-id-object-statements.hxx | 147 ++ libodb-pgsql/odb/pgsql/no-id-object-statements.txx | 50 + libodb-pgsql/odb/pgsql/pgsql-fwd.hxx | 19 + libodb-pgsql/odb/pgsql/pgsql-oid.hxx | 47 + libodb-pgsql/odb/pgsql/pgsql-types.hxx | 59 + .../odb/pgsql/polymorphic-object-result.hxx | 94 + .../odb/pgsql/polymorphic-object-result.txx | 287 +++ .../odb/pgsql/polymorphic-object-statements.hxx | 513 +++++ .../odb/pgsql/polymorphic-object-statements.txx | 158 ++ libodb-pgsql/odb/pgsql/prepared-query.cxx | 15 + libodb-pgsql/odb/pgsql/prepared-query.hxx | 34 + libodb-pgsql/odb/pgsql/query-const-expr.cxx | 14 + libodb-pgsql/odb/pgsql/query-dynamic.cxx | 157 ++ libodb-pgsql/odb/pgsql/query-dynamic.hxx | 32 + libodb-pgsql/odb/pgsql/query-dynamic.ixx | 26 + libodb-pgsql/odb/pgsql/query-dynamic.txx | 20 + libodb-pgsql/odb/pgsql/query.cxx | 444 ++++ libodb-pgsql/odb/pgsql/query.hxx | 2181 ++++++++++++++++++++ libodb-pgsql/odb/pgsql/query.ixx | 34 + libodb-pgsql/odb/pgsql/query.txx | 168 ++ libodb-pgsql/odb/pgsql/section-statements.hxx | 220 ++ libodb-pgsql/odb/pgsql/section-statements.txx | 51 + libodb-pgsql/odb/pgsql/simple-object-result.hxx | 85 + libodb-pgsql/odb/pgsql/simple-object-result.txx | 158 ++ .../odb/pgsql/simple-object-statements.cxx | 15 + .../odb/pgsql/simple-object-statements.hxx | 657 ++++++ .../odb/pgsql/simple-object-statements.ixx | 68 + .../odb/pgsql/simple-object-statements.txx | 190 ++ libodb-pgsql/odb/pgsql/statement-cache.hxx | 57 + libodb-pgsql/odb/pgsql/statement-cache.txx | 60 + libodb-pgsql/odb/pgsql/statement.cxx | 1545 ++++++++++++++ libodb-pgsql/odb/pgsql/statement.hxx | 450 ++++ libodb-pgsql/odb/pgsql/statements-base.cxx | 15 + libodb-pgsql/odb/pgsql/statements-base.hxx | 63 + libodb-pgsql/odb/pgsql/tracer.cxx | 60 + libodb-pgsql/odb/pgsql/tracer.hxx | 61 + libodb-pgsql/odb/pgsql/traits-calls.hxx | 214 ++ libodb-pgsql/odb/pgsql/traits.cxx | 143 ++ libodb-pgsql/odb/pgsql/traits.hxx | 944 +++++++++ libodb-pgsql/odb/pgsql/transaction-impl.cxx | 107 + libodb-pgsql/odb/pgsql/transaction-impl.hxx | 49 + libodb-pgsql/odb/pgsql/transaction.cxx | 26 + libodb-pgsql/odb/pgsql/transaction.hxx | 88 + libodb-pgsql/odb/pgsql/transaction.ixx | 57 + libodb-pgsql/odb/pgsql/version-build2-stub.hxx | 4 + libodb-pgsql/odb/pgsql/version-build2.hxx | 0 libodb-pgsql/odb/pgsql/version-build2.hxx.in | 42 + libodb-pgsql/odb/pgsql/version.hxx | 48 + libodb-pgsql/odb/pgsql/view-result.hxx | 77 + libodb-pgsql/odb/pgsql/view-result.txx | 114 + libodb-pgsql/odb/pgsql/view-statements.hxx | 88 + libodb-pgsql/odb/pgsql/view-statements.txx | 33 + libodb-pgsql/tests/.gitignore | 1 + libodb-pgsql/tests/basics/buildfile | 6 + libodb-pgsql/tests/basics/driver.cxx | 37 + libodb-pgsql/tests/build/.gitignore | 3 + libodb-pgsql/tests/build/bootstrap.build | 8 + libodb-pgsql/tests/build/root.build | 23 + libodb-pgsql/tests/buildfile | 4 + m4/acx-pthread.m4 | 259 --- m4/disable-rpath.m4 | 24 - m4/libodb.m4 | 81 - m4/libpq.m4 | 83 - m4/libtool-link.m4 | 45 - m4/pkgconfig.m4 | 11 - m4/static-lib.m4 | 17 - m4/threads.m4 | 68 - makefile | 35 - manifest | 23 - odb/pgsql/Makefile.am | 14 - odb/pgsql/auto-handle.cxx | 24 - odb/pgsql/auto-handle.hxx | 90 - odb/pgsql/binding.hxx | 74 - odb/pgsql/buildfile | 155 -- odb/pgsql/connection-factory.cxx | 159 -- odb/pgsql/connection-factory.hxx | 134 -- odb/pgsql/connection.cxx | 141 -- odb/pgsql/connection.hxx | 183 -- odb/pgsql/connection.ixx | 44 - odb/pgsql/container-statements.hxx | 425 ---- odb/pgsql/container-statements.txx | 154 -- odb/pgsql/database.cxx | 424 ---- odb/pgsql/database.hxx | 527 ----- odb/pgsql/database.ixx | 638 ------ odb/pgsql/details/.gitignore | 1 - odb/pgsql/details/build2/config-stub.h | 5 - odb/pgsql/details/build2/config-vc-stub.h | 5 - odb/pgsql/details/build2/config-vc.h | 15 - odb/pgsql/details/build2/config.h | 17 - odb/pgsql/details/config-vc.h | 5 - odb/pgsql/details/config.h.in | 12 - odb/pgsql/details/config.hxx | 21 - odb/pgsql/details/conversion.hxx | 58 - odb/pgsql/details/endian-traits.cxx | 30 - odb/pgsql/details/endian-traits.hxx | 155 -- odb/pgsql/details/export.hxx | 78 - odb/pgsql/details/options.cli | 56 - .../pregenerated/odb/pgsql/details/options.cxx | 1114 ---------- .../pregenerated/odb/pgsql/details/options.hxx | 562 ----- .../pregenerated/odb/pgsql/details/options.ixx | 372 ---- odb/pgsql/error.cxx | 86 - odb/pgsql/error.hxx | 41 - odb/pgsql/error.ixx | 31 - odb/pgsql/exceptions.cxx | 79 - odb/pgsql/exceptions.hxx | 80 - odb/pgsql/forward.hxx | 91 - odb/pgsql/libodb-pgsql-vc10.vcxproj | 174 -- odb/pgsql/libodb-pgsql-vc10.vcxproj.filters | 19 - odb/pgsql/libodb-pgsql-vc11.vcxproj | 178 -- odb/pgsql/libodb-pgsql-vc11.vcxproj.filters | 19 - odb/pgsql/libodb-pgsql-vc12.vcxproj | 182 -- odb/pgsql/libodb-pgsql-vc12.vcxproj.filters | 19 - odb/pgsql/libodb-pgsql-vc8.vcproj | 352 ---- odb/pgsql/libodb-pgsql-vc9.vcproj | 359 ---- odb/pgsql/makefile | 157 -- odb/pgsql/no-id-object-result.hxx | 77 - odb/pgsql/no-id-object-result.txx | 114 - odb/pgsql/no-id-object-statements.hxx | 147 -- odb/pgsql/no-id-object-statements.txx | 50 - odb/pgsql/pgsql-fwd.hxx | 19 - odb/pgsql/pgsql-oid.hxx | 47 - odb/pgsql/pgsql-types.hxx | 59 - odb/pgsql/polymorphic-object-result.hxx | 94 - odb/pgsql/polymorphic-object-result.txx | 287 --- odb/pgsql/polymorphic-object-statements.hxx | 513 ----- odb/pgsql/polymorphic-object-statements.txx | 158 -- odb/pgsql/prepared-query.cxx | 15 - odb/pgsql/prepared-query.hxx | 34 - odb/pgsql/query-const-expr.cxx | 14 - odb/pgsql/query-dynamic.cxx | 157 -- odb/pgsql/query-dynamic.hxx | 32 - odb/pgsql/query-dynamic.ixx | 26 - odb/pgsql/query-dynamic.txx | 20 - odb/pgsql/query.cxx | 444 ---- odb/pgsql/query.hxx | 2181 -------------------- odb/pgsql/query.ixx | 34 - odb/pgsql/query.txx | 168 -- odb/pgsql/section-statements.hxx | 220 -- odb/pgsql/section-statements.txx | 51 - odb/pgsql/simple-object-result.hxx | 85 - odb/pgsql/simple-object-result.txx | 158 -- odb/pgsql/simple-object-statements.cxx | 15 - odb/pgsql/simple-object-statements.hxx | 657 ------ odb/pgsql/simple-object-statements.ixx | 68 - odb/pgsql/simple-object-statements.txx | 190 -- odb/pgsql/statement-cache.hxx | 57 - odb/pgsql/statement-cache.txx | 60 - odb/pgsql/statement.cxx | 1545 -------------- odb/pgsql/statement.hxx | 450 ---- odb/pgsql/statements-base.cxx | 15 - odb/pgsql/statements-base.hxx | 63 - odb/pgsql/tracer.cxx | 60 - odb/pgsql/tracer.hxx | 61 - odb/pgsql/traits-calls.hxx | 214 -- odb/pgsql/traits.cxx | 143 -- odb/pgsql/traits.hxx | 944 --------- odb/pgsql/transaction-impl.cxx | 107 - odb/pgsql/transaction-impl.hxx | 49 - odb/pgsql/transaction.cxx | 26 - odb/pgsql/transaction.hxx | 88 - odb/pgsql/transaction.ixx | 57 - odb/pgsql/version-build2-stub.hxx | 4 - odb/pgsql/version-build2.hxx | 0 odb/pgsql/version-build2.hxx.in | 42 - odb/pgsql/version.hxx | 48 - odb/pgsql/view-result.hxx | 77 - odb/pgsql/view-result.txx | 114 - odb/pgsql/view-statements.hxx | 88 - odb/pgsql/view-statements.txx | 33 - repositories.manifest | 14 - tests/.gitignore | 1 - tests/basics/buildfile | 6 - tests/basics/driver.cxx | 37 - tests/build/.gitignore | 3 - tests/build/bootstrap.build | 8 - tests/build/root.build | 23 - tests/buildfile | 4 - version.txt | 1 - 266 files changed, 17131 insertions(+), 20226 deletions(-) delete mode 100644 .gitignore delete mode 100644 GPLv2 delete mode 100644 INSTALL delete mode 100644 INSTALL-GIT delete mode 100644 LICENSE delete mode 100644 Makefile.am delete mode 100644 NEWS delete mode 100644 README delete mode 100644 README-GIT delete mode 100755 bootstrap delete mode 100644 build/.gitignore delete mode 100644 build/bootstrap.build delete mode 100644 build/bootstrap.make delete mode 100644 build/export.build delete mode 100644 build/export/libodb-pgsql/stub.make delete mode 100644 build/import/cli/cli-cxx.make delete mode 100644 build/import/cli/configuration-rules.make delete mode 100755 build/import/cli/configure delete mode 100644 build/import/cli/stub.make delete mode 100644 build/import/libodb-pgsql/configuration-rules.make delete mode 100755 build/import/libodb-pgsql/configure delete mode 100644 build/import/libodb-pgsql/stub.make delete mode 100644 build/import/libodb/configuration-rules.make delete mode 100755 build/import/libodb/configure delete mode 100644 build/import/libodb/stub.make delete mode 100644 build/import/libpq/configuration-rules.make delete mode 100755 build/import/libpq/configure delete mode 100644 build/import/libpq/rules.make delete mode 100644 build/import/libpq/stub.make delete mode 100644 build/import/libpq/version delete mode 100644 build/root.build delete mode 100644 buildfile delete mode 100644 configure.ac delete mode 100644 libodb-pgsql-vc10.sln delete mode 100644 libodb-pgsql-vc11.sln delete mode 100644 libodb-pgsql-vc12.sln delete mode 100644 libodb-pgsql-vc8.sln delete mode 100644 libodb-pgsql-vc9.sln delete mode 100644 libodb-pgsql.pc.in create mode 100644 libodb-pgsql/.gitignore create mode 100644 libodb-pgsql/GPLv2 create mode 100644 libodb-pgsql/INSTALL create mode 100644 libodb-pgsql/LICENSE create mode 100644 libodb-pgsql/README create mode 100644 libodb-pgsql/build/.gitignore create mode 100644 libodb-pgsql/build/bootstrap.build create mode 100644 libodb-pgsql/build/export.build create mode 100644 libodb-pgsql/build/root.build create mode 100644 libodb-pgsql/buildfile create mode 100644 libodb-pgsql/manifest create mode 100644 libodb-pgsql/odb/pgsql/auto-handle.cxx create mode 100644 libodb-pgsql/odb/pgsql/auto-handle.hxx create mode 100644 libodb-pgsql/odb/pgsql/binding.hxx create mode 100644 libodb-pgsql/odb/pgsql/buildfile create mode 100644 libodb-pgsql/odb/pgsql/connection-factory.cxx create mode 100644 libodb-pgsql/odb/pgsql/connection-factory.hxx create mode 100644 libodb-pgsql/odb/pgsql/connection.cxx create mode 100644 libodb-pgsql/odb/pgsql/connection.hxx create mode 100644 libodb-pgsql/odb/pgsql/connection.ixx create mode 100644 libodb-pgsql/odb/pgsql/container-statements.hxx create mode 100644 libodb-pgsql/odb/pgsql/container-statements.txx create mode 100644 libodb-pgsql/odb/pgsql/database.cxx create mode 100644 libodb-pgsql/odb/pgsql/database.hxx create mode 100644 libodb-pgsql/odb/pgsql/database.ixx create mode 100644 libodb-pgsql/odb/pgsql/details/.gitignore create mode 100644 libodb-pgsql/odb/pgsql/details/build2/config-stub.h create mode 100644 libodb-pgsql/odb/pgsql/details/build2/config-vc-stub.h create mode 100644 libodb-pgsql/odb/pgsql/details/build2/config-vc.h create mode 100644 libodb-pgsql/odb/pgsql/details/build2/config.h create mode 100644 libodb-pgsql/odb/pgsql/details/config-vc.h create mode 100644 libodb-pgsql/odb/pgsql/details/config.h.in create mode 100644 libodb-pgsql/odb/pgsql/details/config.hxx create mode 100644 libodb-pgsql/odb/pgsql/details/conversion.hxx create mode 100644 libodb-pgsql/odb/pgsql/details/endian-traits.cxx create mode 100644 libodb-pgsql/odb/pgsql/details/endian-traits.hxx create mode 100644 libodb-pgsql/odb/pgsql/details/export.hxx create mode 100644 libodb-pgsql/odb/pgsql/details/options.cli create mode 100644 libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.cxx create mode 100644 libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.hxx create mode 100644 libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.ixx create mode 100644 libodb-pgsql/odb/pgsql/error.cxx create mode 100644 libodb-pgsql/odb/pgsql/error.hxx create mode 100644 libodb-pgsql/odb/pgsql/error.ixx create mode 100644 libodb-pgsql/odb/pgsql/exceptions.cxx create mode 100644 libodb-pgsql/odb/pgsql/exceptions.hxx create mode 100644 libodb-pgsql/odb/pgsql/forward.hxx create mode 100644 libodb-pgsql/odb/pgsql/no-id-object-result.hxx create mode 100644 libodb-pgsql/odb/pgsql/no-id-object-result.txx create mode 100644 libodb-pgsql/odb/pgsql/no-id-object-statements.hxx create mode 100644 libodb-pgsql/odb/pgsql/no-id-object-statements.txx create mode 100644 libodb-pgsql/odb/pgsql/pgsql-fwd.hxx create mode 100644 libodb-pgsql/odb/pgsql/pgsql-oid.hxx create mode 100644 libodb-pgsql/odb/pgsql/pgsql-types.hxx create mode 100644 libodb-pgsql/odb/pgsql/polymorphic-object-result.hxx create mode 100644 libodb-pgsql/odb/pgsql/polymorphic-object-result.txx create mode 100644 libodb-pgsql/odb/pgsql/polymorphic-object-statements.hxx create mode 100644 libodb-pgsql/odb/pgsql/polymorphic-object-statements.txx create mode 100644 libodb-pgsql/odb/pgsql/prepared-query.cxx create mode 100644 libodb-pgsql/odb/pgsql/prepared-query.hxx create mode 100644 libodb-pgsql/odb/pgsql/query-const-expr.cxx create mode 100644 libodb-pgsql/odb/pgsql/query-dynamic.cxx create mode 100644 libodb-pgsql/odb/pgsql/query-dynamic.hxx create mode 100644 libodb-pgsql/odb/pgsql/query-dynamic.ixx create mode 100644 libodb-pgsql/odb/pgsql/query-dynamic.txx create mode 100644 libodb-pgsql/odb/pgsql/query.cxx create mode 100644 libodb-pgsql/odb/pgsql/query.hxx create mode 100644 libodb-pgsql/odb/pgsql/query.ixx create mode 100644 libodb-pgsql/odb/pgsql/query.txx create mode 100644 libodb-pgsql/odb/pgsql/section-statements.hxx create mode 100644 libodb-pgsql/odb/pgsql/section-statements.txx create mode 100644 libodb-pgsql/odb/pgsql/simple-object-result.hxx create mode 100644 libodb-pgsql/odb/pgsql/simple-object-result.txx create mode 100644 libodb-pgsql/odb/pgsql/simple-object-statements.cxx create mode 100644 libodb-pgsql/odb/pgsql/simple-object-statements.hxx create mode 100644 libodb-pgsql/odb/pgsql/simple-object-statements.ixx create mode 100644 libodb-pgsql/odb/pgsql/simple-object-statements.txx create mode 100644 libodb-pgsql/odb/pgsql/statement-cache.hxx create mode 100644 libodb-pgsql/odb/pgsql/statement-cache.txx create mode 100644 libodb-pgsql/odb/pgsql/statement.cxx create mode 100644 libodb-pgsql/odb/pgsql/statement.hxx create mode 100644 libodb-pgsql/odb/pgsql/statements-base.cxx create mode 100644 libodb-pgsql/odb/pgsql/statements-base.hxx create mode 100644 libodb-pgsql/odb/pgsql/tracer.cxx create mode 100644 libodb-pgsql/odb/pgsql/tracer.hxx create mode 100644 libodb-pgsql/odb/pgsql/traits-calls.hxx create mode 100644 libodb-pgsql/odb/pgsql/traits.cxx create mode 100644 libodb-pgsql/odb/pgsql/traits.hxx create mode 100644 libodb-pgsql/odb/pgsql/transaction-impl.cxx create mode 100644 libodb-pgsql/odb/pgsql/transaction-impl.hxx create mode 100644 libodb-pgsql/odb/pgsql/transaction.cxx create mode 100644 libodb-pgsql/odb/pgsql/transaction.hxx create mode 100644 libodb-pgsql/odb/pgsql/transaction.ixx create mode 100644 libodb-pgsql/odb/pgsql/version-build2-stub.hxx create mode 100644 libodb-pgsql/odb/pgsql/version-build2.hxx create mode 100644 libodb-pgsql/odb/pgsql/version-build2.hxx.in create mode 100644 libodb-pgsql/odb/pgsql/version.hxx create mode 100644 libodb-pgsql/odb/pgsql/view-result.hxx create mode 100644 libodb-pgsql/odb/pgsql/view-result.txx create mode 100644 libodb-pgsql/odb/pgsql/view-statements.hxx create mode 100644 libodb-pgsql/odb/pgsql/view-statements.txx create mode 100644 libodb-pgsql/tests/.gitignore create mode 100644 libodb-pgsql/tests/basics/buildfile create mode 100644 libodb-pgsql/tests/basics/driver.cxx create mode 100644 libodb-pgsql/tests/build/.gitignore create mode 100644 libodb-pgsql/tests/build/bootstrap.build create mode 100644 libodb-pgsql/tests/build/root.build create mode 100644 libodb-pgsql/tests/buildfile delete mode 100644 m4/acx-pthread.m4 delete mode 100644 m4/disable-rpath.m4 delete mode 100644 m4/libodb.m4 delete mode 100644 m4/libpq.m4 delete mode 100644 m4/libtool-link.m4 delete mode 100644 m4/pkgconfig.m4 delete mode 100644 m4/static-lib.m4 delete mode 100644 m4/threads.m4 delete mode 100644 makefile delete mode 100644 manifest delete mode 100644 odb/pgsql/Makefile.am delete mode 100644 odb/pgsql/auto-handle.cxx delete mode 100644 odb/pgsql/auto-handle.hxx delete mode 100644 odb/pgsql/binding.hxx delete mode 100644 odb/pgsql/buildfile delete mode 100644 odb/pgsql/connection-factory.cxx delete mode 100644 odb/pgsql/connection-factory.hxx delete mode 100644 odb/pgsql/connection.cxx delete mode 100644 odb/pgsql/connection.hxx delete mode 100644 odb/pgsql/connection.ixx delete mode 100644 odb/pgsql/container-statements.hxx delete mode 100644 odb/pgsql/container-statements.txx delete mode 100644 odb/pgsql/database.cxx delete mode 100644 odb/pgsql/database.hxx delete mode 100644 odb/pgsql/database.ixx delete mode 100644 odb/pgsql/details/.gitignore delete mode 100644 odb/pgsql/details/build2/config-stub.h delete mode 100644 odb/pgsql/details/build2/config-vc-stub.h delete mode 100644 odb/pgsql/details/build2/config-vc.h delete mode 100644 odb/pgsql/details/build2/config.h delete mode 100644 odb/pgsql/details/config-vc.h delete mode 100644 odb/pgsql/details/config.h.in delete mode 100644 odb/pgsql/details/config.hxx delete mode 100644 odb/pgsql/details/conversion.hxx delete mode 100644 odb/pgsql/details/endian-traits.cxx delete mode 100644 odb/pgsql/details/endian-traits.hxx delete mode 100644 odb/pgsql/details/export.hxx delete mode 100644 odb/pgsql/details/options.cli delete mode 100644 odb/pgsql/details/pregenerated/odb/pgsql/details/options.cxx delete mode 100644 odb/pgsql/details/pregenerated/odb/pgsql/details/options.hxx delete mode 100644 odb/pgsql/details/pregenerated/odb/pgsql/details/options.ixx delete mode 100644 odb/pgsql/error.cxx delete mode 100644 odb/pgsql/error.hxx delete mode 100644 odb/pgsql/error.ixx delete mode 100644 odb/pgsql/exceptions.cxx delete mode 100644 odb/pgsql/exceptions.hxx delete mode 100644 odb/pgsql/forward.hxx delete mode 100644 odb/pgsql/libodb-pgsql-vc10.vcxproj delete mode 100644 odb/pgsql/libodb-pgsql-vc10.vcxproj.filters delete mode 100644 odb/pgsql/libodb-pgsql-vc11.vcxproj delete mode 100644 odb/pgsql/libodb-pgsql-vc11.vcxproj.filters delete mode 100644 odb/pgsql/libodb-pgsql-vc12.vcxproj delete mode 100644 odb/pgsql/libodb-pgsql-vc12.vcxproj.filters delete mode 100644 odb/pgsql/libodb-pgsql-vc8.vcproj delete mode 100644 odb/pgsql/libodb-pgsql-vc9.vcproj delete mode 100644 odb/pgsql/makefile delete mode 100644 odb/pgsql/no-id-object-result.hxx delete mode 100644 odb/pgsql/no-id-object-result.txx delete mode 100644 odb/pgsql/no-id-object-statements.hxx delete mode 100644 odb/pgsql/no-id-object-statements.txx delete mode 100644 odb/pgsql/pgsql-fwd.hxx delete mode 100644 odb/pgsql/pgsql-oid.hxx delete mode 100644 odb/pgsql/pgsql-types.hxx delete mode 100644 odb/pgsql/polymorphic-object-result.hxx delete mode 100644 odb/pgsql/polymorphic-object-result.txx delete mode 100644 odb/pgsql/polymorphic-object-statements.hxx delete mode 100644 odb/pgsql/polymorphic-object-statements.txx delete mode 100644 odb/pgsql/prepared-query.cxx delete mode 100644 odb/pgsql/prepared-query.hxx delete mode 100644 odb/pgsql/query-const-expr.cxx delete mode 100644 odb/pgsql/query-dynamic.cxx delete mode 100644 odb/pgsql/query-dynamic.hxx delete mode 100644 odb/pgsql/query-dynamic.ixx delete mode 100644 odb/pgsql/query-dynamic.txx delete mode 100644 odb/pgsql/query.cxx delete mode 100644 odb/pgsql/query.hxx delete mode 100644 odb/pgsql/query.ixx delete mode 100644 odb/pgsql/query.txx delete mode 100644 odb/pgsql/section-statements.hxx delete mode 100644 odb/pgsql/section-statements.txx delete mode 100644 odb/pgsql/simple-object-result.hxx delete mode 100644 odb/pgsql/simple-object-result.txx delete mode 100644 odb/pgsql/simple-object-statements.cxx delete mode 100644 odb/pgsql/simple-object-statements.hxx delete mode 100644 odb/pgsql/simple-object-statements.ixx delete mode 100644 odb/pgsql/simple-object-statements.txx delete mode 100644 odb/pgsql/statement-cache.hxx delete mode 100644 odb/pgsql/statement-cache.txx delete mode 100644 odb/pgsql/statement.cxx delete mode 100644 odb/pgsql/statement.hxx delete mode 100644 odb/pgsql/statements-base.cxx delete mode 100644 odb/pgsql/statements-base.hxx delete mode 100644 odb/pgsql/tracer.cxx delete mode 100644 odb/pgsql/tracer.hxx delete mode 100644 odb/pgsql/traits-calls.hxx delete mode 100644 odb/pgsql/traits.cxx delete mode 100644 odb/pgsql/traits.hxx delete mode 100644 odb/pgsql/transaction-impl.cxx delete mode 100644 odb/pgsql/transaction-impl.hxx delete mode 100644 odb/pgsql/transaction.cxx delete mode 100644 odb/pgsql/transaction.hxx delete mode 100644 odb/pgsql/transaction.ixx delete mode 100644 odb/pgsql/version-build2-stub.hxx delete mode 100644 odb/pgsql/version-build2.hxx delete mode 100644 odb/pgsql/version-build2.hxx.in delete mode 100644 odb/pgsql/version.hxx delete mode 100644 odb/pgsql/view-result.hxx delete mode 100644 odb/pgsql/view-result.txx delete mode 100644 odb/pgsql/view-statements.hxx delete mode 100644 odb/pgsql/view-statements.txx delete mode 100644 repositories.manifest delete mode 100644 tests/.gitignore delete mode 100644 tests/basics/buildfile delete mode 100644 tests/basics/driver.cxx delete mode 100644 tests/build/.gitignore delete mode 100644 tests/build/bootstrap.build delete mode 100644 tests/build/root.build delete mode 100644 tests/buildfile delete mode 100644 version.txt diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3004ad1..0000000 --- a/.gitignore +++ /dev/null @@ -1,37 +0,0 @@ -.bdep/ - -# Compiler/linker output. -# -*.d -*.t -*.i -*.ii -*.o -*.obj -*.so -*.dll -*.a -*.lib -*.exp -*.pdb -*.ilk -*.exe -*.exe.dlls/ -*.exe.manifest -*.pc - -*.l -*.l.cpp-options - -# Generated documentation. -# -*.pdf -*.ps - -# Generated build system files. -# -*-dynamic.make - -# Generated .gitignore files. -# -.gitignore diff --git a/GPLv2 b/GPLv2 deleted file mode 100644 index 3912109..0000000 --- a/GPLv2 +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/INSTALL b/INSTALL deleted file mode 100644 index d75b1c8..0000000 --- a/INSTALL +++ /dev/null @@ -1,103 +0,0 @@ -Prerequisites -============= - - - libodb http://www.codesynthesis.com/products/odb/ - - libpq http://www.postgresql.org/download/ - - -Building on UNIX -================ - -The following build instructions are for the Linux/UNIX/Mac OS X -operating systems as well as for Cygwin and MinGW on Windows. - -The standard autotools-based build system is used on these platforms. -After unpacking the source code archive, change to the libodb-pgsql -package directory (referred to as libodb-pgsql/ from now on) and run -the configure script: - -./configure - -To see the available configuration options run configure with --help: - -./configure --help - -The configure script expects the libodb and libpq headers and -libraries to be installed in a directory where the C++ compiler -and linker will search for them by default (normally /usr and -/usr/local). If these libraries are installed in other directories, -you can use the CPPFLAGS and LDFLAGS configure variables to specify -their locations, for example: - -./configure CPPFLAGS=-I/opt/libodb/include LDFLAGS=-L/opt/libodb/lib - -If libodb is not installed and you would like to use its build -directory instead, you can use the --with-libodb configure option -to specify its location, for example: - -./configure --with-libodb=/tmp/libodb - -As another example, the following configure command only builds shared -libraries, uses the specified C++ compiler, and compiles with optimization -and without debug information: - -./configure --disable-static CXX=g++-4.5 CXXFLAGS=-O3 - -Once configuration is complete, run make to build libodb-pgsql: - -make - -Once the build is completed successfully, you can install the libodb-pgsql -headers and libraries using the install target (you may need to do this -step as root depending on the installation directory): - -make install - - -Building on Windows -=================== - -The following build instructions are for Windows using Microsoft Visual -Studio. If you would like to build libodb-pgsql with GCC either using -Cygwin or MinGW, refer to the "Building on UNIX" section above. - -The standard Visual Studio project and solution files are used on this -platform. The provided project files expect the libodb and libpq -header and import library directories to be in the VC++ Directories -Include and Library search lists. For libodb, see the INSTALL file in -the package directory for more information on how to setup the VC++ -Directories. - -For libpq, add the include\ directory inside the PostgreSQL package -to the Include search list and the lib\ directory to the Library -search list. - -To build libodb-pgsql, unpack the source code archive and open the -libodb-pgsql-vc.sln file located in the libodb-pgsql package -directory (referred to as libodb-pgsql\ from now on). Here is the -version of Visual Studio that you are using. Once the solution is open, -select the desired build configuration (Debug or Release) and platform -(Win32 or x64) and build the solution. - -The resulting 32-bit DLLs and import libraries are placed into the -libodb-pgsql\bin\ and libodb-pgsql\lib\ directories, respectively. -Similarly, the 64-bit DLLs and import libraries are placed into -libodb-pgsql\bin64\ and libodb-pgsql\lib64\. The Release versions of -the import libraries are named odb-pgsql.lib and the Debug versions -are named odb-pgsql-d.lib. - -To configure Visual Studio to automatically locate the libodb-pgsql -headers, DLLs, and import libraries, add the following paths to your -VC++ Directories: - -Win32: - - Include: ...\libodb-pgsql - Library: ...\libodb-pgsql\lib - Executable: ...\libodb-pgsql\bin - -x64: - - Include: ...\libodb-pgsql - Library: ...\libodb-pgsql\lib64 - Executable: ...\libodb-pgsql\bin64 diff --git a/INSTALL-GIT b/INSTALL-GIT deleted file mode 100644 index f917af5..0000000 --- a/INSTALL-GIT +++ /dev/null @@ -1,78 +0,0 @@ -The following instructions describe how to work with the source code that was -checked out from the git repository. - -The major difference between using a released source code package and source -code from the repository is that the former does not contain autotools-based -makefiles or Visual Studio project files. Instead, it contains templates for -these files as well as its own, custom build system. This build system is -used for development as well as to automatically generate the autotools and -Visual Studio files. - -This file describes how to use this build system to build the package as well -as to create a release-ready source distribution which contains the autotools -build system and Visual Studio project files. - - -Prerequisites -============= - -Besides the prerequisites listed in the INSTALL file, you will need the -following additional packages: - - - GNU bash >= 2.0.0 http://www.gnu.org/software/bash/ - - GNU make >= 3.81 http://www.gnu.org/software/make/ - - build >= latest http://www.codesynthesis.com/projects/build/ - -If you are planning to create the source code distributions, then you will -also need the following packages: - - - GNU m4 >= 1.4.0 http://www.gnu.org/software/m4/ - - GNU sed >= 4.0.0 http://www.gnu.org/software/sed/ - - tofrodos >= 1.7.0 http://www.thefreecountry.com/tofrodos/ - -As we as the GNU autotools: - - - GNU libtool >= 2.2.6b http://www.gnu.org/software/libtool/ - - GNU autoconf >= 2.67 http://www.gnu.org/software/autoconf/ - - GNU automake >= 1.11.1 http://www.gnu.org/software/automake/ - -Any reasonably up to date GNU/Linux installation would normally have all of -the above packages already present, except for build and maybe tofrodos. - - -Configuring and Building -======================== - -To build the source code simply run make in the root directory of the package. -The first time you run make, the build process will also configure the -package by asking you several questions. On the subsequent runs, make will -only rebuild what has changed. - -To run the automated test suite (if any), run 'make test'. To clean the object -files, executables, etc., run 'make clean'. To de-configure the package (that -is, to remove configuration files in addition to objects, executables, etc.), -run 'make disfigure'. - - -Creating Distribution -===================== - -To create the source code distribution, use the dist make target as well as -the dist_prefix variable to specify the directory where the distribution files -should be placed. For example: - -make dist dist_prefix=/tmp/package-1.1.0 - -Once the distribution files are ready, change to the distribution directory -and run the bootstrap script to bootstrap the autotools build system, for -example: - -cd /tmp/package-1.1.0 -./bootsrap - -To create the source code archives, use the autotools build system. First -configuring the package (see the INSTALL file for more information on this -step) and then use the dist target to make the archives, for example: - -./configure -make dist diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 9d92da1..0000000 --- a/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2009-2024 Code Synthesis Tools CC. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License version 2 as -published by the Free Software Foundation. - -For more information on ODB licensing as well as for answers to -some of the common licensing questions, visit the ODB License -page: - -http://www.codesynthesis.com/products/odb/license.xhtml - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 2c34934..0000000 --- a/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -# file : Makefile.am -# license : GNU GPL v2; see accompanying LICENSE file - -SUBDIRS = __path__(dirs) -dist_doc_DATA = __file__(docs) -EXTRA_DIST = __file__(extra_dist) -ACLOCAL_AMFLAGS = -I m4 - -pkgconfigdir = @pkgconfigdir@ -pkgconfig_DATA= libodb-pgsql.pc diff --git a/NEWS b/NEWS deleted file mode 100644 index 72d0f8b..0000000 --- a/NEWS +++ /dev/null @@ -1 +0,0 @@ -See the common NEWS file in the ODB compiler package. diff --git a/README b/README deleted file mode 100644 index c4c3e28..0000000 --- a/README +++ /dev/null @@ -1,20 +0,0 @@ -ODB is an object-relational mapping (ORM) system for C++. It provides -tools, APIs, and library support that allow you to persist C++ objects -to a relational database (RDBMS) without having to deal with tables, -columns, or SQL and without manually writing any of the mapping code. -For more information see: - -http://www.codesynthesis.com/products/odb/ - -This package contains the PostgreSQL ODB runtime library. Every -application that includes code generated for the PostgreSQL database -will need to link to this library. - -See the NEWS file for the user-visible changes from the previous release. - -See the LICENSE file for distribution conditions. - -See the INSTALL file for prerequisites and installation instructions. - -Send questions, bug reports, or any other feedback to the -odb-users@codesynthesis.com mailing list. diff --git a/README-GIT b/README-GIT deleted file mode 100644 index 33dbf5f..0000000 --- a/README-GIT +++ /dev/null @@ -1,5 +0,0 @@ -The checked out odb/pgsql/version-build2.hxx will be overwritten during the -build process but these changes should be ignored. To do this automatically, -run: - -git update-index --assume-unchanged odb/pgsql/version-build2.hxx diff --git a/bootstrap b/bootstrap deleted file mode 100755 index 85d1399..0000000 --- a/bootstrap +++ /dev/null @@ -1,16 +0,0 @@ -#! /bin/sh - -# file : bootstrap -# license : GNU GPL v2; see accompanying LICENSE file - -# -# Bootstrap the automake build system. -# - -rm -f config.cache - -if test ! -d m4; then - mkdir m4 -fi - -autoreconf --install diff --git a/build/.gitignore b/build/.gitignore deleted file mode 100644 index 4a730a3..0000000 --- a/build/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -config.build -root/ -bootstrap/ diff --git a/build/bootstrap.build b/build/bootstrap.build deleted file mode 100644 index fb6b7df..0000000 --- a/build/bootstrap.build +++ /dev/null @@ -1,10 +0,0 @@ -# file : build/bootstrap.build -# license : GNU GPL v2; see accompanying LICENSE file - -project = libodb-pgsql - -using version -using config -using dist -using test -using install diff --git a/build/bootstrap.make b/build/bootstrap.make deleted file mode 100644 index 26da3c4..0000000 --- a/build/bootstrap.make +++ /dev/null @@ -1,70 +0,0 @@ -# file : build/bootstrap.make -# license : GNU GPL v2; see accompanying LICENSE file - -project_name := libodb-pgsql - -# First try to include the bundled bootstrap.make if it exist. If that -# fails, let make search for the external bootstrap.make. -# -build := build-0.3 - --include $(dir $(lastword $(MAKEFILE_LIST)))../../$(build)/bootstrap.make - -ifeq ($(patsubst %build/bootstrap.make,,$(lastword $(MAKEFILE_LIST))),) -include $(build)/bootstrap.make -endif - - -# Aliases -# -.PHONY: $(out_base)/ \ - $(out_base)/.test \ - $(out_base)/.dist \ - $(out_base)/.clean - -ifdef %interactive% - -.PHONY: test dist clean - -test: $(out_base)/.test -dist: $(out_base)/.dist -clean: $(out_base)/.clean - -ifneq ($(filter $(.DEFAULT_GOAL),test dist clean),) -.DEFAULT_GOAL := -endif - -endif - -# Make sure the distribution prefix is set if the goal is dist. -# -ifneq ($(filter $(MAKECMDGOALS),dist),) -ifeq ($(dist_prefix),) -$(error dist_prefix is not set) -endif -endif - -# If we don't have dependency auto-generation then we need to manually -# make sure that generated files are generated before C++ file are -# compiler. To do this we make the object files ($2) depend in order- -# only on generated files ($3). -# -ifeq ($(cxx_id),generic) - -define include-dep -$(if $2,$(eval $2: | $3)) -endef - -else - -define include-dep -$(call -include,$1) -endef - -endif - -# Don't include dependency info for certain targets. -# -ifneq ($(filter $(MAKECMDGOALS),clean disfigure dist),) -include-dep = -endif diff --git a/build/export.build b/build/export.build deleted file mode 100644 index 80aba23..0000000 --- a/build/export.build +++ /dev/null @@ -1,9 +0,0 @@ -# file : build/export.build -# license : GNU GPL v2; see accompanying LICENSE file - -$out_root/ -{ - include odb/pgsql/ -} - -export $out_root/odb/pgsql/lib{odb-pgsql} diff --git a/build/export/libodb-pgsql/stub.make b/build/export/libodb-pgsql/stub.make deleted file mode 100644 index 9e646aa..0000000 --- a/build/export/libodb-pgsql/stub.make +++ /dev/null @@ -1,8 +0,0 @@ -# file : build/export/libodb-pgsql/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(src_root)/odb/pgsql/makefile,$(out_root)) - -$(call export,\ - l: $(out_root)/odb/pgsql/odb-pgsql.l,\ - cpp-options: $(out_root)/odb/pgsql/odb-pgsql.l.cpp-options) diff --git a/build/import/cli/cli-cxx.make b/build/import/cli/cli-cxx.make deleted file mode 100644 index 9bdf238..0000000 --- a/build/import/cli/cli-cxx.make +++ /dev/null @@ -1,47 +0,0 @@ -# file : build/import/cli/cli-cxx.make -# license : MIT; see accompanying LICENSE file - -# Here we are operating in the importing project's space, not in -# cli's. -# - -# Get the C++ file extensions. -# -$(call include,$(bld_root)/cxx/configuration-static.make) - -cli_pattern := \ -$(out_base)/%.$(cxx_s_suffix) \ -$(out_base)/%.$(cxx_h_suffix) \ -$(out_base)/%.$(cxx_i_suffix) - -$(cli_pattern): cli_options := \ ---hxx-suffix .$(cxx_h_suffix) \ ---ixx-suffix .$(cxx_i_suffix) \ ---cxx-suffix .$(cxx_s_suffix) - -.PRECIOUS: $(cli_pattern) - -ifeq ($(out_base),$(src_base)) - -$(cli_pattern): $(src_base)/%.cli - $(call message,cli $<,$(cli) $(cli_options) --output-dir $(dir $@) $<) - -else - -$(cli_pattern): $(src_base)/%.cli | $$(dir $$@). - $(call message,cli $<,$(cli) $(cli_options) --output-dir $(dir $@) $<) - -$(cli_pattern): $(out_base)/%.cli | $$(dir $$@). - $(call message,cli $<,$(cli) $(cli_options) --output-dir $(dir $@) $<) -endif - -.PHONY: $(out_base)/%.cxx.cli.clean - -$(out_base)/%.cxx.cli.clean: cxx_s_suffix := $(cxx_s_suffix) -$(out_base)/%.cxx.cli.clean: cxx_h_suffix := $(cxx_h_suffix) -$(out_base)/%.cxx.cli.clean: cxx_i_suffix := $(cxx_i_suffix) - -$(out_base)/%.cxx.cli.clean: - $(call message,rm $$1,rm -f $$1,$(@:.cxx.cli.clean=.$(cxx_s_suffix))) - $(call message,rm $$1,rm -f $$1,$(@:.cxx.cli.clean=.$(cxx_h_suffix))) - $(call message,rm $$1,rm -f $$1,$(@:.cxx.cli.clean=.$(cxx_i_suffix))) diff --git a/build/import/cli/configuration-rules.make b/build/import/cli/configuration-rules.make deleted file mode 100644 index 6355000..0000000 --- a/build/import/cli/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/cli/configuration-rules.make -# license : MIT; see accompanying LICENSE file - -$(dcf_root)/import/cli/configuration-dynamic.make: | $(dcf_root)/import/cli/. - $(call message,,$(scf_root)/import/cli/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/cli/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/cli/configuration-dynamic.make) - -endif diff --git a/build/import/cli/configure b/build/import/cli/configure deleted file mode 100755 index 2a1fde4..0000000 --- a/build/import/cli/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/cli/configure -# license : MIT; see accompanying LICENSE file - - -# $1 - out file -# -# bld_root - build root -# project_name - project name -# - -source $bld_root/dialog.bash - - -$echo -$echo "Configuring external dependency on 'cli' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed " -$echo "version of 'cli' as opposed to the development build?" -$echo - -installed=`read_y_n y` - -path= - -if [ "$installed" = "n" ]; then - -$echo -$echo "Please enter the src_root for 'cli'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'cli'." -$eche - -out_root=`read_path --directory $src_root` - -fi - -echo cli_installed := $installed >$1 - -if [ "$installed" = "n" ]; then - -echo src_root := $src_root >>$1 -echo scf_root := \$\(src_root\)/build >>$1 -echo out_root := $out_root >>$1 - -fi diff --git a/build/import/cli/stub.make b/build/import/cli/stub.make deleted file mode 100644 index 741b371..0000000 --- a/build/import/cli/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/cli/stub.make -# license : MIT; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/cli/configuration-rules.make,$(dcf_root)) - -cli_installed := - -$(call -include,$(dcf_root)/import/cli/configuration-dynamic.make) - -ifdef cli_installed - -ifeq ($(cli_installed),y) - -$(call export,cli: cli,cli-rules: $(scf_root)/import/cli/cli-cxx.make) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/cli/stub.make) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libodb-pgsql/configuration-rules.make b/build/import/libodb-pgsql/configuration-rules.make deleted file mode 100644 index 326a60c..0000000 --- a/build/import/libodb-pgsql/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libodb-pgsql/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libodb-pgsql/configuration-dynamic.make: | $(dcf_root)/import/libodb-pgsql/. - $(call message,,$(scf_root)/import/libodb-pgsql/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/libodb-pgsql/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libodb-pgsql/configuration-dynamic.make) - -endif diff --git a/build/import/libodb-pgsql/configure b/build/import/libodb-pgsql/configure deleted file mode 100755 index 9d75cad..0000000 --- a/build/import/libodb-pgsql/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libodb-pgsql/configure -# license : GNU GPL v2; see accompanying LICENSE file - - -# $1 - out file -# -# bld_root - build root -# project_name - project name -# - -source $bld_root/dialog.bash - - -$echo -$echo "Configuring external dependency on 'libodb-pgsql' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'libodb-pgsql' as opposed to the development build?" -$echo - -installed=`read_y_n y` - -path= - -if [ "$installed" = "n" ]; then - -$echo -$echo "Please enter the src_root for 'libodb-pgsql'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'libodb-pgsql'." -$echo - -out_root=`read_path --directory $src_root` - -fi - -echo libodb_pgsql_installed := $installed >$1 - -if [ "$installed" = "n" ]; then - -echo src_root := $src_root >>$1 -echo scf_root := \$\(src_root\)/build >>$1 -echo out_root := $out_root >>$1 - -fi diff --git a/build/import/libodb-pgsql/stub.make b/build/import/libodb-pgsql/stub.make deleted file mode 100644 index b770a63..0000000 --- a/build/import/libodb-pgsql/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/libodb-pgsql/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libodb-pgsql/configuration-rules.make,$(dcf_root)) - -libodb_pgsql_installed := - -$(call -include,$(dcf_root)/import/libodb-pgsql/configuration-dynamic.make) - -ifdef libodb_pgsql_installed - -ifeq ($(libodb_pgsql_installed),y) - -$(call export,l: -lodb-pgsql -lodb -lpq,cpp-options: ) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/libodb-pgsql/stub.make) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libodb/configuration-rules.make b/build/import/libodb/configuration-rules.make deleted file mode 100644 index 340c418..0000000 --- a/build/import/libodb/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libodb/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libodb/configuration-dynamic.make: | $(dcf_root)/import/libodb/. - $(call message,,$(scf_root)/import/libodb/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/libodb/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libodb/configuration-dynamic.make) - -endif diff --git a/build/import/libodb/configure b/build/import/libodb/configure deleted file mode 100755 index 261a202..0000000 --- a/build/import/libodb/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libodb/configure -# license : GNU GPL v2; see accompanying LICENSE file - - -# $1 - out file -# -# bld_root - build root -# project_name - project name -# - -source $bld_root/dialog.bash - - -$echo -$echo "Configuring external dependency on 'libodb' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed " -$echo "version of 'libodb' as opposed to the development build?" -$echo - -installed=`read_y_n y` - -path= - -if [ "$installed" = "n" ]; then - -$echo -$echo "Please enter the src_root for 'libodb'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'libodb'." -$echo - -out_root=`read_path --directory $src_root` - -fi - -echo libodb_installed := $installed >$1 - -if [ "$installed" = "n" ]; then - -echo src_root := $src_root >>$1 -echo scf_root := \$\(src_root\)/build >>$1 -echo out_root := $out_root >>$1 - -fi diff --git a/build/import/libodb/stub.make b/build/import/libodb/stub.make deleted file mode 100644 index 04dc786..0000000 --- a/build/import/libodb/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/libodb/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libodb/configuration-rules.make,$(dcf_root)) - -libodb_installed := - -$(call -include,$(dcf_root)/import/libodb/configuration-dynamic.make) - -ifdef libodb_installed - -ifeq ($(libodb_installed),y) - -$(call export,l: -lodb,cpp-options: ) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/libodb/stub.make) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libpq/configuration-rules.make b/build/import/libpq/configuration-rules.make deleted file mode 100644 index 3b43941..0000000 --- a/build/import/libpq/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libpq/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libpq/configuration-dynamic.make: | $(dcf_root)/import/libpq/. - $(call message,,$(scf_root)/import/libpq/configure $@) - -ifndef %foreign% - -disfigure:: - $(call message,rm $(dcf_root)/import/libpq/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libpq/configuration-dynamic.make) - -endif diff --git a/build/import/libpq/configure b/build/import/libpq/configure deleted file mode 100755 index 91b196f..0000000 --- a/build/import/libpq/configure +++ /dev/null @@ -1,79 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libpq/configure -# license : GNU GPL v2; see accompanying LICENSE file - - -# $1 - out config file -# -# bld_root - build root -# project_name - project name -# - -source $bld_root/dialog.bash - - -$echo -$echo "Configuring external dependency on 'PostgreSQL library' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'PostgreSQL library' as opposed to the development build?" -$echo - -installed=`read_y_n y` - -path= -type= - -if [ "$installed" = "n" ]; then - - $echo - $echo "Please enter the 'PostgreSQL' root directory." - $echo - - root=`read_path --directory --exist` - - $echo - $echo "Please select the library type you would like to use:" - $echo - $echo "(1) archive" - $echo "(2) shared object" - $echo - - type=`read_option "archive shared" "shared"` - -else - - libpq_libs=-lpq - - if pg_config --version > /dev/null 2>&1; then - - libpq_cppflags=-I`pg_config --includedir` - - else - $echo - $echo "Unable to discover installed 'PostgreSQL libraries' using pg_config." - $echo "Assuming the C++ compiler will find them automatically." - $echo - - libpq_cppflags= - - fi - -fi - -echo libpq_installed := $installed >$1 - -if [ "$installed" = "n" ]; then - - echo libpq_root := $root >>$1 - echo libpq_type := $type >>$1 - -else - - echo libpq_cppflags := $libpq_cppflags >>$1 - echo libpq_libs := $libpq_libs >>$1 - -fi diff --git a/build/import/libpq/rules.make b/build/import/libpq/rules.make deleted file mode 100644 index 016a671..0000000 --- a/build/import/libpq/rules.make +++ /dev/null @@ -1,29 +0,0 @@ -# file : build/import/libpq/rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libpq/%: root := $(libpq_root) - -ifeq ($(libpq_type),archive) - -$(dcf_root)/import/libpq/pq.l: $(libpq_root)/libpq/.libs/libpq.a - @echo $< >$@ -else - -$(dcf_root)/import/libpq/pq.l: $(libpq_root)/libpq/.libs/libpq.so - @echo $< >$@ - @echo rpath:$(root)/libpq/.libs >>$@ -endif - -$(dcf_root)/import/libpq/pq.l.cpp-options: - @ln -s $(root)/include $(dcf_root)/import/libpq/pq - @echo include: -I$(dcf_root)/import/libpq >$@ - -ifndef %foreign% - -disfigure:: - $(call message,rm $(dcf_root)/import/pq/pq.l,\ -rm -f $(dcf_root)/import/pq/pq.l) - $(call message,,rm -f $(dcf_root)/import/libpq/pq) - $(call message,,rm -f $(dcf_root)/import/libpq/pq.l.cpp-options) - -endif diff --git a/build/import/libpq/stub.make b/build/import/libpq/stub.make deleted file mode 100644 index 94ba269..0000000 --- a/build/import/libpq/stub.make +++ /dev/null @@ -1,33 +0,0 @@ -# file : build/import/libpq/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libpq/configuration-rules.make,$(dcf_root)) - -libpq_installed := - -$(call -include,$(dcf_root)/import/libpq/configuration-dynamic.make) - -ifdef libpq_installed - -ifeq ($(libpq_installed),y) - -$(call export,\ - l: $(libpq_libs),\ - cpp-options: ,\ - cpp-options-inline: $(libpq_cppflags)) - -else - -$(call include-once,$(scf_root)/import/libpq/rules.make,$(dcf_root)) - -$(call export,\ - l: $(dcf_root)/import/libpq/pq.l,\ - cpp-options: $(dcf_root)/import/libpq/pq.l.cpp-options) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libpq/version b/build/import/libpq/version deleted file mode 100644 index 6e8bf73..0000000 --- a/build/import/libpq/version +++ /dev/null @@ -1 +0,0 @@ -0.1.0 diff --git a/build/root.build b/build/root.build deleted file mode 100644 index 329cc45..0000000 --- a/build/root.build +++ /dev/null @@ -1,19 +0,0 @@ -# file : build/root.build -# license : GNU GPL v2; see accompanying LICENSE file - -config [bool] config.libodb_pgsql.develop ?= false - -cxx.std = latest - -using cxx - -hxx{*}: extension = hxx -ixx{*}: extension = ixx -txx{*}: extension = txx -cxx{*}: extension = cxx - -if ($cxx.target.system == 'win32-msvc') - cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS - -if ($cxx.class == 'msvc') - cxx.coptions += /wd4251 /wd4275 /wd4800 diff --git a/buildfile b/buildfile deleted file mode 100644 index 406853f..0000000 --- a/buildfile +++ /dev/null @@ -1,9 +0,0 @@ -# file : buildfile -# license : GNU GPL v2; see accompanying LICENSE file - -./: {*/ -build/ -m4/} doc{INSTALL NEWS README} legal{GPLv2 LICENSE} manifest - -# Don't install tests or the INSTALL file. -# -tests/: install = false -doc{INSTALL}@./: install = false diff --git a/configure.ac b/configure.ac deleted file mode 100644 index f09dc37..0000000 --- a/configure.ac +++ /dev/null @@ -1,57 +0,0 @@ -# file : configure.ac -# license : GNU GPL v2; see accompanying LICENSE file - -AC_PREREQ(2.60) -AC_INIT([libodb-pgsql], [__value__(version)], [odb-users@codesynthesis.com]) -AC_CONFIG_AUX_DIR([config]) -AC_CONFIG_MACRO_DIR([m4]) -AC_CONFIG_SRCDIR([odb/pgsql/version.hxx]) - -AM_INIT_AUTOMAKE([-Wall -Werror foreign nostdinc subdir-objects dist-bzip2 dist-zip tar-ustar]) -m4_equote()[m4_ifdef]m4_dquote()([AM_PROG_AR], [AM_PROG_AR]) # Required by automake 1.12. - -LT_INIT([win32-dll]) - -AC_CANONICAL_HOST - -# Check for C++ compiler and use it to compile the tests. -# -AC_PROG_CXX -AC_LANG(C++) - -# Create the libtool executable so that we can use it in further tests. -# -LT_OUTPUT - -# Check for threads. -# -THREADS - -# Check for libpq -# -LIBPQ( - [], - [AC_MSG_ERROR([libpq is not found; consider using CPPFLAGS/LDFLAGS to specify its location])]) - -# Check for libodb. -# -LIBODB([],[AC_MSG_ERROR([libodb is not found; consider using --with-libodb=DIR])]) - -# Define LIBODB_PGSQL_STATIC_LIB if we are building static library on certain -# platforms. -# -STATIC_LIB([LIBODB_PGSQL_STATIC_LIB], [Static library interface.]) - -# Allow the user to specify the pkgconfig directory. -# -PKGCONFIG - -# Check if we should disable rpath. -# -DISABLE_RPATH - -# Output. -# -AC_CONFIG_HEADERS([odb/pgsql/config.h odb/pgsql/details/config.h]) -AC_CONFIG_FILES([__path__(config_files)]) -AC_OUTPUT diff --git a/libodb-pgsql-vc10.sln b/libodb-pgsql-vc10.sln deleted file mode 100644 index 0849b9f..0000000 --- a/libodb-pgsql-vc10.sln +++ /dev/null @@ -1,26 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libodb-pgsql", "odb\pgsql\libodb-pgsql-vc10.vcxproj", {B6185C00-39EC-4429-B774-164B4397B995}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|Win32.ActiveCfg = Debug|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|Win32.Build.0 = Debug|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|x64.ActiveCfg = Debug|x64 - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|x64.Build.0 = Debug|x64 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|Win32.ActiveCfg = Release|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|Win32.Build.0 = Release|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|x64.ActiveCfg = Release|x64 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/libodb-pgsql-vc11.sln b/libodb-pgsql-vc11.sln deleted file mode 100644 index e318293..0000000 --- a/libodb-pgsql-vc11.sln +++ /dev/null @@ -1,26 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libodb-pgsql", "odb\pgsql\libodb-pgsql-vc11.vcxproj", {B6185C00-39EC-4429-B774-164B4397B995}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|Win32.ActiveCfg = Debug|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|Win32.Build.0 = Debug|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|x64.ActiveCfg = Debug|x64 - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|x64.Build.0 = Debug|x64 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|Win32.ActiveCfg = Release|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|Win32.Build.0 = Release|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|x64.ActiveCfg = Release|x64 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/libodb-pgsql-vc12.sln b/libodb-pgsql-vc12.sln deleted file mode 100644 index ac1b648..0000000 --- a/libodb-pgsql-vc12.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libodb-pgsql", "odb\pgsql\libodb-pgsql-vc12.vcxproj", {B6185C00-39EC-4429-B774-164B4397B995}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|Win32.ActiveCfg = Debug|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|Win32.Build.0 = Debug|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|x64.ActiveCfg = Debug|x64 - {B6185C00-39EC-4429-B774-164B4397B995}.Debug|x64.Build.0 = Debug|x64 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|Win32.ActiveCfg = Release|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|Win32.Build.0 = Release|Win32 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|x64.ActiveCfg = Release|x64 - {B6185C00-39EC-4429-B774-164B4397B995}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/libodb-pgsql-vc8.sln b/libodb-pgsql-vc8.sln deleted file mode 100644 index d8092f4..0000000 --- a/libodb-pgsql-vc8.sln +++ /dev/null @@ -1,26 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libodb-pgsql", "odb\pgsql\libodb-pgsql-vc8.vcproj", "{574D4042-A2C5-482C-B0EA-F1C2A8B0D374}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Debug|Win32.ActiveCfg = Debug|Win32 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Debug|Win32.Build.0 = Debug|Win32 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Debug|x64.ActiveCfg = Debug|x64 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Debug|x64.Build.0 = Debug|x64 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Release|Win32.ActiveCfg = Release|Win32 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Release|Win32.Build.0 = Release|Win32 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Release|x64.ActiveCfg = Release|x64 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/libodb-pgsql-vc9.sln b/libodb-pgsql-vc9.sln deleted file mode 100644 index c4c0878..0000000 --- a/libodb-pgsql-vc9.sln +++ /dev/null @@ -1,26 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libodb-pgsql", "odb\pgsql\libodb-pgsql-vc9.vcproj", "{574D4042-A2C5-482C-B0EA-F1C2A8B0D374}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Debug|Win32.ActiveCfg = Debug|Win32 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Debug|Win32.Build.0 = Debug|Win32 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Debug|x64.ActiveCfg = Debug|x64 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Debug|x64.Build.0 = Debug|x64 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Release|Win32.ActiveCfg = Release|Win32 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Release|Win32.Build.0 = Release|Win32 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Release|x64.ActiveCfg = Release|x64 - {574D4042-A2C5-482C-B0EA-F1C2A8B0D374}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/libodb-pgsql.pc.in b/libodb-pgsql.pc.in deleted file mode 100644 index 63c6966..0000000 --- a/libodb-pgsql.pc.in +++ /dev/null @@ -1,14 +0,0 @@ -# file : libodb-pgsql.pc.in -# license : GNU GPL v2; see accompanying LICENSE file - -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: libodb-pgsql -Description: Object-relational mapping (ORM) system for C++, PostgreSQL runtime library -URL: http://www.codesynthesis.com/products/odb/ -Version: @VERSION@ -Libs: -L${libdir} -lodb-pgsql -Cflags: -I${includedir} diff --git a/libodb-pgsql/.gitignore b/libodb-pgsql/.gitignore new file mode 100644 index 0000000..1c363a0 --- /dev/null +++ b/libodb-pgsql/.gitignore @@ -0,0 +1,25 @@ +# Compiler/linker output. +# +*.d +*.t +*.i +*.i.* +*.ii +*.ii.* +*.o +*.obj +*.gcm +*.pcm +*.ifc +*.so +*.dylib +*.dll +*.a +*.lib +*.exp +*.pdb +*.ilk +*.exe +*.exe.dlls/ +*.exe.manifest +*.pc diff --git a/libodb-pgsql/GPLv2 b/libodb-pgsql/GPLv2 new file mode 100644 index 0000000..3912109 --- /dev/null +++ b/libodb-pgsql/GPLv2 @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/libodb-pgsql/INSTALL b/libodb-pgsql/INSTALL new file mode 100644 index 0000000..32df42c --- /dev/null +++ b/libodb-pgsql/INSTALL @@ -0,0 +1,6 @@ +The easiest way to build this package is with the bpkg package manager: + +$ bpkg build libodb-pgsql + +But if you don't want to use the package manager, then you can also build it +manually using the standard build2 build system. diff --git a/libodb-pgsql/LICENSE b/libodb-pgsql/LICENSE new file mode 100644 index 0000000..9d92da1 --- /dev/null +++ b/libodb-pgsql/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2009-2024 Code Synthesis Tools CC. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License version 2 as +published by the Free Software Foundation. + +For more information on ODB licensing as well as for answers to +some of the common licensing questions, visit the ODB License +page: + +http://www.codesynthesis.com/products/odb/license.xhtml + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/libodb-pgsql/README b/libodb-pgsql/README new file mode 100644 index 0000000..c4c3e28 --- /dev/null +++ b/libodb-pgsql/README @@ -0,0 +1,20 @@ +ODB is an object-relational mapping (ORM) system for C++. It provides +tools, APIs, and library support that allow you to persist C++ objects +to a relational database (RDBMS) without having to deal with tables, +columns, or SQL and without manually writing any of the mapping code. +For more information see: + +http://www.codesynthesis.com/products/odb/ + +This package contains the PostgreSQL ODB runtime library. Every +application that includes code generated for the PostgreSQL database +will need to link to this library. + +See the NEWS file for the user-visible changes from the previous release. + +See the LICENSE file for distribution conditions. + +See the INSTALL file for prerequisites and installation instructions. + +Send questions, bug reports, or any other feedback to the +odb-users@codesynthesis.com mailing list. diff --git a/libodb-pgsql/build/.gitignore b/libodb-pgsql/build/.gitignore new file mode 100644 index 0000000..4a730a3 --- /dev/null +++ b/libodb-pgsql/build/.gitignore @@ -0,0 +1,3 @@ +config.build +root/ +bootstrap/ diff --git a/libodb-pgsql/build/bootstrap.build b/libodb-pgsql/build/bootstrap.build new file mode 100644 index 0000000..fb6b7df --- /dev/null +++ b/libodb-pgsql/build/bootstrap.build @@ -0,0 +1,10 @@ +# file : build/bootstrap.build +# license : GNU GPL v2; see accompanying LICENSE file + +project = libodb-pgsql + +using version +using config +using dist +using test +using install diff --git a/libodb-pgsql/build/export.build b/libodb-pgsql/build/export.build new file mode 100644 index 0000000..80aba23 --- /dev/null +++ b/libodb-pgsql/build/export.build @@ -0,0 +1,9 @@ +# file : build/export.build +# license : GNU GPL v2; see accompanying LICENSE file + +$out_root/ +{ + include odb/pgsql/ +} + +export $out_root/odb/pgsql/lib{odb-pgsql} diff --git a/libodb-pgsql/build/root.build b/libodb-pgsql/build/root.build new file mode 100644 index 0000000..329cc45 --- /dev/null +++ b/libodb-pgsql/build/root.build @@ -0,0 +1,19 @@ +# file : build/root.build +# license : GNU GPL v2; see accompanying LICENSE file + +config [bool] config.libodb_pgsql.develop ?= false + +cxx.std = latest + +using cxx + +hxx{*}: extension = hxx +ixx{*}: extension = ixx +txx{*}: extension = txx +cxx{*}: extension = cxx + +if ($cxx.target.system == 'win32-msvc') + cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS + +if ($cxx.class == 'msvc') + cxx.coptions += /wd4251 /wd4275 /wd4800 diff --git a/libodb-pgsql/buildfile b/libodb-pgsql/buildfile new file mode 100644 index 0000000..a04e206 --- /dev/null +++ b/libodb-pgsql/buildfile @@ -0,0 +1,9 @@ +# file : buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +./: {*/ -build/} doc{INSTALL NEWS README} legal{GPLv2 LICENSE} manifest + +# Don't install tests or the INSTALL file. +# +tests/: install = false +doc{INSTALL}@./: install = false diff --git a/libodb-pgsql/manifest b/libodb-pgsql/manifest new file mode 100644 index 0000000..83b1a10 --- /dev/null +++ b/libodb-pgsql/manifest @@ -0,0 +1,23 @@ +: 1 +name: libodb-pgsql +version: 2.5.0-b.26.z +project: odb +summary: PostgreSQL ODB runtime library +license: GPL-2.0-only +license: other: proprietary ; Not free/open source. +topics: C++, ORM, PostgreSQL, SQL +description-file: README +changes-file: NEWS +url: https://www.codesynthesis.com/products/odb/ +doc-url: https://www.codesynthesis.com/products/odb/doc/manual.xhtml +src-url: https://git.codesynthesis.com/cgit/odb/odb/ +email: odb-users@codesynthesis.com +build-warning-email: odb-builds@codesynthesis.com +builds: all +builds: -wasm +requires: c++11 +depends: * build2 >= 0.16.0- +depends: * bpkg >= 0.16.0- +depends: libpq >=7.4.0 +depends: libodb == $ +depends: * cli ^1.2.0- ? ($config.libodb_pgsql.develop) diff --git a/libodb-pgsql/odb/pgsql/auto-handle.cxx b/libodb-pgsql/odb/pgsql/auto-handle.cxx new file mode 100644 index 0000000..d6c0565 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/auto-handle.cxx @@ -0,0 +1,24 @@ +// file : odb/pgsql/auto-handle.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include + +namespace odb +{ + namespace pgsql + { + void handle_traits:: + release (PGconn* h) + { + PQfinish (h); + } + + void handle_traits:: + release (PGresult* h) + { + PQclear (h); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/auto-handle.hxx b/libodb-pgsql/odb/pgsql/auto-handle.hxx new file mode 100644 index 0000000..49b396d --- /dev/null +++ b/libodb-pgsql/odb/pgsql/auto-handle.hxx @@ -0,0 +1,90 @@ +// file : odb/pgsql/auto-handle.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_AUTO_HANDLE_HXX +#define ODB_PGSQL_AUTO_HANDLE_HXX + +#include + +#include +#include // PGconn, PGresult + +#include + +namespace odb +{ + namespace pgsql + { + template + struct handle_traits; + + template <> + struct LIBODB_PGSQL_EXPORT handle_traits + { + static void + release (PGconn*); + }; + + template <> + struct LIBODB_PGSQL_EXPORT handle_traits + { + static void + release (PGresult*); + }; + + template + class auto_handle + { + public: + auto_handle (H* h = 0) + : h_ (h) + { + } + + ~auto_handle () + { + if (h_ != 0) + handle_traits::release (h_); + } + + H* + get () const + { + return h_; + } + + void + reset (H* h = 0) + { + if (h_ != 0) + handle_traits::release (h_); + + h_ = h; + } + + H* + release () + { + H* h (h_); + h_ = 0; + return h; + } + + operator H* () const + { + return h_; + } + + private: + auto_handle (const auto_handle&); + auto_handle& operator= (const auto_handle&); + + private: + H* h_; + }; + } +} + +#include + +#endif // ODB_PGSQL_AUTO_HANDLE_HXX diff --git a/libodb-pgsql/odb/pgsql/binding.hxx b/libodb-pgsql/odb/pgsql/binding.hxx new file mode 100644 index 0000000..1adf144 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/binding.hxx @@ -0,0 +1,74 @@ +// file : odb/pgsql/binding.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_BINDING_HXX +#define ODB_PGSQL_BINDING_HXX + +#include + +#include // std::size_t + +#include +#include + +namespace odb +{ + namespace pgsql + { + class native_binding + { + public: + native_binding (char** v, + int* l, + int* f, + std::size_t n) + : values (v), lengths (l), formats (f), count (n) + { + } + + char** values; + int* lengths; + int* formats; + std::size_t count; + + private: + native_binding (const native_binding&); + native_binding& operator= (const native_binding&); + }; + + class binding + { + public: + typedef pgsql::bind bind_type; + + binding () + : bind (0), count (0), version (0), + batch (0), skip (0), status (0) {} + + binding (bind_type* b, std::size_t n) + : bind (b), count (n), version (0), + batch (0), skip (0), status (0) {} + + binding (bind_type* b, std::size_t n, + std::size_t bt, std::size_t s, unsigned long long* st) + : bind (b), count (n), version (0), + batch (bt), skip (s), status (st) {} + + bind_type* bind; + std::size_t count; + std::size_t version; + + std::size_t batch; + std::size_t skip; + unsigned long long* status; // Batch status array. + + private: + binding (const binding&); + binding& operator= (const binding&); + }; + } +} + +#include + +#endif // ODB_PGSQL_BINDING_HXX diff --git a/libodb-pgsql/odb/pgsql/buildfile b/libodb-pgsql/odb/pgsql/buildfile new file mode 100644 index 0000000..f1d05b6 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/buildfile @@ -0,0 +1,155 @@ +# file : odb/pgsql/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +define cli: file +cli{*}: extension = cli + +import int_libs = libodb%lib{odb} +import imp_libs = libpq%lib{pq} + +lib{odb-pgsql}: {hxx ixx txx cxx}{* -version-build2} {hxx}{version-build2} \ + details/{hxx ixx txx cxx}{* -options} \ + details/build2/{h}{*} \ + $imp_libs $int_libs + +# Include the generated version header into the distribution (so that we don't +# pick up an installed one) and don't remove it when cleaning in src (so that +# clean results in a state identical to distributed). +# +hxx{version-build2}: in{version-build2} $src_root/manifest +hxx{version-build2}: +{ + dist = true + clean = ($src_root != $out_root) +} + +# Build options. +# +cxx.poptions =+ "-I$out_root" "-I$src_root" -DLIBODB_PGSQL_BUILD2 + +obja{*}: cxx.poptions += -DLIBODB_PGSQL_STATIC_BUILD +objs{*}: cxx.poptions += -DLIBODB_PGSQL_SHARED_BUILD + +# Export options. +# +lib{odb-pgsql}: +{ + cxx.export.poptions = "-I$out_root" "-I$src_root" -DLIBODB_PGSQL_BUILD2 + cxx.export.libs = $int_libs +} + +liba{odb-pgsql}: cxx.export.poptions += -DLIBODB_PGSQL_STATIC +libs{odb-pgsql}: cxx.export.poptions += -DLIBODB_PGSQL_SHARED + +# For pre-releases use the complete version to make sure they cannot be used +# in place of another pre-release or the final version. See the version module +# for details on the version.* variable values. +# +if $version.pre_release + lib{odb-pgsql}: bin.lib.version = @"-$version.project_id" +else + lib{odb-pgsql}: bin.lib.version = @"-$version.major.$version.minor" + +develop = $config.libodb_pgsql.develop + +## Consumption build ($develop == false). +# + +# Use pregenerated versions in the consumption build. +# +lib{odb-pgsql}: details/pregenerated/{hxx ixx cxx}{**}: include = (!$develop) + +if! $develop + cxx.poptions =+ "-I($src_base/details/pregenerated)" # Note: must come first. + +# Don't install pregenerated headers since they are only used internally in +# the database implementation (also below). +# +details/pregenerated/{hxx ixx}{*}: install = false + +# Distribute pregenerated versions only in the consumption build. +# +details/pregenerated/{hxx ixx cxx}{*}: dist = (!$develop) + +# +## + +## Development build ($develop == true). +# + +lib{odb-pgsql}: details/{hxx ixx cxx}{options}: include = $develop + +if $develop + import! [metadata] cli = cli%exe{cli} + +# In the development build distribute regenerated {hxx ixx cxx}{options}, +# remapping their locations to the paths of the pregenerated versions (which +# are only distributed in the consumption build; see above). This way we make +# sure that the distributed files are always up-to-date. +# +
: details/cli{options} $cli +{ + install = false + dist = ($develop ? pregenerated/odb/pgsql/details/ : false) + + # Symlink the generated code in src for convenience of development. + # + backlink = true +} +% +if $develop +{{ + options = --include-with-brackets --include-prefix odb/pgsql/details \ + --guard-prefix LIBODB_PGSQL_DETAILS --generate-file-scanner \ + --cli-namespace odb::pgsql::details::cli --long-usage \ + --generate-specifier --no-combined-flags + + $cli $options -o $out_base/details/ $path($<[0]) + + # If the result differs from the pregenerated version, copy it over. + # + d = [dir_path] $src_base/details/pregenerated/odb/pgsql/details/ + + if diff $d/options.hxx $path($>[0]) >- && \ + diff $d/options.ixx $path($>[1]) >- && \ + diff $d/options.cxx $path($>[2]) >- + exit + end + + cp $path($>[0]) $d/options.hxx + cp $path($>[1]) $d/options.ixx + cp $path($>[2]) $d/options.cxx +}} + +# Install into the odb/pgsql/ subdirectory of, say, /usr/include/ +# recreating subdirectories. +# +install_include = [dir_path] include/odb/pgsql/ + +{hxx ixx txx}{*}: +{ + install = $install_include + install.subdirs = true +} + +# We want these to be picked up whether LIBODB_PGSQL_BUILD2 is defined or not. +# +hxx{version}@./: install = false +hxx{version-build2}: install = $install_include/version.hxx +hxx{version-build2-stub}@./: install = $install_include/version-build2.hxx + +details/build2/ +{ + h{*}: install = false + + if ($cxx.target.system == 'win32-msvc') + { + h{config-vc}@./: install = $install_include/details/ + h{config-vc-stub}@./: install = $install_include/details/build2/config-vc.h + } + else + { + h{config}@./: install = $install_include/details/ + h{config-stub}@./: install = $install_include/details/build2/config.h + } +} diff --git a/libodb-pgsql/odb/pgsql/connection-factory.cxx b/libodb-pgsql/odb/pgsql/connection-factory.cxx new file mode 100644 index 0000000..855a9bc --- /dev/null +++ b/libodb-pgsql/odb/pgsql/connection-factory.cxx @@ -0,0 +1,159 @@ +// file : odb/pgsql/connection-factory.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include +#include + +#include + +using namespace std; + +namespace odb +{ + using namespace details; + + namespace pgsql + { + // new_connection_factory + // + connection_ptr new_connection_factory:: + connect () + { + return connection_ptr (new (shared) connection (*this)); + } + + // connection_pool_factory + // + connection_pool_factory::pooled_connection_ptr connection_pool_factory:: + create () + { + return pooled_connection_ptr (new (shared) pooled_connection (*this)); + } + + connection_pool_factory:: + ~connection_pool_factory () + { + // Wait for all the connections currently in use to return to + // the pool. + // + lock l (mutex_); + while (in_use_ != 0) + { + waiters_++; + cond_.wait (l); + waiters_--; + } + } + + connection_ptr connection_pool_factory:: + connect () + { + lock l (mutex_); + + while (true) + { + // See if we have a spare connection. + // + if (connections_.size () != 0) + { + shared_ptr c (connections_.back ()); + connections_.pop_back (); + + c->callback_ = &c->cb_; + in_use_++; + return c; + } + + // See if we can create a new one. + // + if (max_ == 0 || in_use_ < max_) + { + shared_ptr c (create ()); + c->callback_ = &c->cb_; + in_use_++; + return c; + } + + // Wait until someone releases a connection. + // + waiters_++; + cond_.wait (l); + waiters_--; + } + } + + void connection_pool_factory:: + database (database_type& db) + { + bool first (db_ == 0); + + connection_factory::database (db); + + if (!first) + return; + + if (min_ > 0) + { + connections_.reserve (min_); + + for (size_t i (0); i < min_; ++i) + connections_.push_back (create ()); + } + } + + bool connection_pool_factory:: + release (pooled_connection* c) + { + c->callback_ = 0; + + lock l (mutex_); + + // Determine if we need to keep or free this connection. + // + bool keep (!c->failed () && + (waiters_ != 0 || + min_ == 0 || + (connections_.size () + in_use_ <= min_))); + + in_use_--; + + if (keep) + { + connections_.push_back (pooled_connection_ptr (inc_ref (c))); + connections_.back ()->recycle (); + } + + if (waiters_ != 0) + cond_.signal (); + + return !keep; + } + + // + // connection_pool_factory::pooled_connection + // + + connection_pool_factory::pooled_connection:: + pooled_connection (connection_pool_factory& f) + : connection (f) + { + cb_.arg = this; + cb_.zero_counter = &zero_counter; + } + + connection_pool_factory::pooled_connection:: + pooled_connection (connection_pool_factory& f, PGconn* handle) + : connection (f, handle) + { + cb_.arg = this; + cb_.zero_counter = &zero_counter; + } + + bool connection_pool_factory::pooled_connection:: + zero_counter (void* arg) + { + pooled_connection* c (static_cast (arg)); + return static_cast (c->factory_).release (c); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/connection-factory.hxx b/libodb-pgsql/odb/pgsql/connection-factory.hxx new file mode 100644 index 0000000..2f300a8 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/connection-factory.hxx @@ -0,0 +1,134 @@ +// file : odb/pgsql/connection-factory.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_CONNECTION_FACTORY_HXX +#define ODB_PGSQL_CONNECTION_FACTORY_HXX + +#include + +#include +#include // std::size_t +#include + +#include +#include +#include + +#include +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + class LIBODB_PGSQL_EXPORT new_connection_factory: public connection_factory + { + public: + new_connection_factory () {} + + virtual connection_ptr + connect (); + + private: + new_connection_factory (const new_connection_factory&); + new_connection_factory& operator= (const new_connection_factory&); + }; + + class LIBODB_PGSQL_EXPORT connection_pool_factory: + public connection_factory + { + public: + // The max_connections argument specifies the maximum number of + // concurrent connections this pool will maintain. If this value + // is 0 then the pool will create a new connection every time all + // of the existing connections are in use. + // + // The min_connections argument specifies the minimum number of + // connections that should be maintained by the pool. If the + // number of connections maintained by the pool exceeds this + // number and there are no active waiters for a new connection, + // then the pool will release the excess connections. If this + // value is 0 then the pool will maintain all the connections + // that were ever created. + // + connection_pool_factory (std::size_t max_connections = 0, + std::size_t min_connections = 0) + : max_ (max_connections), + min_ (min_connections), + in_use_ (0), + waiters_ (0), + cond_ (mutex_) + { + // max_connections == 0 means unlimited. + // + assert (max_connections == 0 || max_connections >= min_connections); + } + + virtual connection_ptr + connect (); + + virtual void + database (database_type&); + + virtual + ~connection_pool_factory (); + + private: + connection_pool_factory (const connection_pool_factory&); + connection_pool_factory& operator= (const connection_pool_factory&); + + protected: + class LIBODB_PGSQL_EXPORT pooled_connection: public connection + { + public: + pooled_connection (connection_pool_factory&); + pooled_connection (connection_pool_factory&, PGconn*); + + private: + static bool + zero_counter (void*); + + private: + friend class connection_pool_factory; + + shared_base::refcount_callback cb_; + }; + + friend class pooled_connection; + + typedef details::shared_ptr pooled_connection_ptr; + typedef std::vector connections; + + // This function is called whenever the pool needs to create a new + // connection. + // + virtual pooled_connection_ptr + create (); + + protected: + // Return true if the connection should be deleted, false otherwise. + // + bool + release (pooled_connection*); + + protected: + const std::size_t max_; + const std::size_t min_; + + std::size_t in_use_; // Number of connections currently in use. + std::size_t waiters_; // Number of threads waiting for a connection. + + connections connections_; + + details::mutex mutex_; + details::condition cond_; + }; + } +} + +#include + +#endif // ODB_PGSQL_CONNECTION_FACTORY_HXX diff --git a/libodb-pgsql/odb/pgsql/connection.cxx b/libodb-pgsql/odb/pgsql/connection.cxx new file mode 100644 index 0000000..80a1dd2 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/connection.cxx @@ -0,0 +1,141 @@ +// file : odb/pgsql/connection.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::bad_alloc +#include +#include // std::strcmp +#include // std::atol + +#include + +#include +#include +#include +#include +#include +#include + +using namespace std; + +extern "C" void +odb_pgsql_process_notice (void*, const char*) +{ +} + +namespace odb +{ + namespace pgsql + { + connection:: + connection (connection_factory& cf) + : odb::connection (cf), failed_ (false) + { + database_type& db (database ()); + handle_.reset (PQconnectdb (db.conninfo ().c_str ())); + + if (handle_ == 0) + throw bad_alloc (); + else if (PQstatus (handle_) == CONNECTION_BAD) + throw database_exception (PQerrorMessage (handle_)); + + init (); + } + + connection:: + connection (connection_factory& cf, PGconn* handle) + : odb::connection (cf), handle_ (handle), failed_ (false) + { + init (); + } + + void connection:: + init () + { + // Establish whether date/time values are represented as + // 8-byte integers. + // + if (strcmp (PQparameterStatus (handle_, "integer_datetimes"), "on") != 0) + throw database_exception ("unsupported binary format for PostgreSQL " + "date-time SQL types"); + + // Suppress server notifications to stdout. + // + PQsetNoticeProcessor (handle_, &odb_pgsql_process_notice, 0); + + // Create statement cache. + // + statement_cache_.reset (new statement_cache_type (*this)); + } + + connection:: + ~connection () + { + // Destroy prepared query statements before freeing the connections. + // + recycle (); + clear_prepared_map (); + } + + int connection:: + server_version () const + { + return PQserverVersion (handle_); + } + + transaction_impl* connection:: + begin () + { + return new transaction_impl (connection_ptr (inc_ref (this))); + } + + unsigned long long connection:: + execute (const char* s, std::size_t n) + { + // The string may not be '\0'-terminated. + // + string str (s, n); + + { + odb::tracer* t; + if ((t = transaction_tracer ()) || + (t = tracer ()) || + (t = database ().tracer ())) + t->execute (*this, str.c_str ()); + } + + auto_handle h (PQexec (handle_, str.c_str ())); + + unsigned long long count (0); + + if (!is_good_result (h)) + translate_error (*this, h); + else if (PGRES_TUPLES_OK == PQresultStatus (h)) + count = static_cast (PQntuples (h)); + else + { + const char* s (PQcmdTuples (h)); + + if (s[0] != '\0' && s[1] == '\0') + count = static_cast (s[0] - '0'); + else + count = static_cast (atol (s)); + } + + return count; + } + + // connection_factory + // + connection_factory:: + ~connection_factory () + { + } + + void connection_factory:: + database (database_type& db) + { + odb::connection_factory::db_ = &db; + db_ = &db; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/connection.hxx b/libodb-pgsql/odb/pgsql/connection.hxx new file mode 100644 index 0000000..d779273 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/connection.hxx @@ -0,0 +1,183 @@ +// file : odb/pgsql/connection.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_CONNECTION_HXX +#define ODB_PGSQL_CONNECTION_HXX + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include // PGconn + +#include + +namespace odb +{ + namespace pgsql + { + class statement_cache; + class connection_factory; + + class connection; + typedef details::shared_ptr connection_ptr; + + class LIBODB_PGSQL_EXPORT connection: public odb::connection + { + public: + typedef pgsql::statement_cache statement_cache_type; + typedef pgsql::database database_type; + + virtual + ~connection (); + + connection (connection_factory&); + connection (connection_factory&, PGconn* handle); + + database_type& + database (); + + public: + virtual transaction_impl* + begin (); + + public: + using odb::connection::execute; + + virtual unsigned long long + execute (const char* statement, std::size_t length); + + // Query preparation. + // + public: + template + prepared_query + prepare_query (const char* name, const char*); + + template + prepared_query + prepare_query (const char* name, const std::string&); + + template + prepared_query + prepare_query (const char* name, const pgsql::query_base&); + + template + prepared_query + prepare_query (const char* name, const odb::query_base&); + + // SQL statement tracing. + // + public: + typedef pgsql::tracer tracer_type; + + void + tracer (tracer_type& t) + { + odb::connection::tracer (t); + } + + void + tracer (tracer_type* t) + { + odb::connection::tracer (t); + } + + using odb::connection::tracer; + + public: + bool + failed () const + { + return failed_; + } + + void + mark_failed () + { + failed_ = true; + } + + public: + PGconn* + handle () + { + return handle_; + } + + // Server version as returned by PQserverVersion(), for example, 90200 + // (9.2.0), 90201 (9.2.1), 100000 (10.0), 110001 (11.1). + // + int + server_version () const; + + statement_cache_type& + statement_cache () + { + return *statement_cache_; + } + + private: + connection (const connection&); + connection& operator= (const connection&); + + private: + void + init (); + + private: + friend class transaction_impl; // invalidate_results() + + private: + auto_handle handle_; + bool failed_; + + // Keep statement_cache_ after handle_ so that it is destroyed before + // the connection is closed. + // + details::unique_ptr statement_cache_; + }; + + class LIBODB_PGSQL_EXPORT connection_factory: + public odb::connection_factory + { + public: + typedef pgsql::database database_type; + + virtual void + database (database_type&); + + database_type& + database () {return *db_;} + + virtual connection_ptr + connect () = 0; + + virtual + ~connection_factory (); + + connection_factory (): db_ (0) {} + + // Needed to break the circular connection_factory-database dependency + // (odb::connection_factory has the odb::database member). + // + protected: + database_type* db_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_CONNECTION_HXX diff --git a/libodb-pgsql/odb/pgsql/connection.ixx b/libodb-pgsql/odb/pgsql/connection.ixx new file mode 100644 index 0000000..76d558b --- /dev/null +++ b/libodb-pgsql/odb/pgsql/connection.ixx @@ -0,0 +1,44 @@ +// file : odb/pgsql/connection.ixx +// license : GNU GPL v2; see accompanying LICENSE file + +namespace odb +{ + namespace pgsql + { + inline database& connection:: + database () + { + return static_cast (factory_).database (); + } + + template + inline prepared_query connection:: + prepare_query (const char* n, const char* q) + { + return prepare_query (n, query (q)); + } + + template + inline prepared_query connection:: + prepare_query (const char* n, const std::string& q) + { + return prepare_query (n, query (q)); + } + + template + inline prepared_query connection:: + prepare_query (const char* n, const pgsql::query_base& q) + { + return query_::call (*this, n, q); + } + + template + inline prepared_query connection:: + prepare_query (const char* n, const odb::query_base& q) + { + // Translate to native query. + // + return prepare_query (n, pgsql::query_base (q)); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/container-statements.hxx b/libodb-pgsql/odb/pgsql/container-statements.hxx new file mode 100644 index 0000000..1856bb9 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/container-statements.hxx @@ -0,0 +1,425 @@ +// file : odb/pgsql/container-statements.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_CONTAINER_STATEMENTS_HXX +#define ODB_PGSQL_CONTAINER_STATEMENTS_HXX + +#include + +#include // std::size_t + +#include +#include +#include + +#include +#include +#include +#include // Oid +#include + +namespace odb +{ + namespace pgsql + { + class connection; + + // Template argument is the generated abstract container traits type. + // That is, it doesn't need to provide column counts and statements. + // + template + class container_statements + { + public: + typedef T traits; + + typedef typename traits::data_image_type data_image_type; + typedef typename traits::functions_type functions_type; + + typedef pgsql::insert_statement insert_statement_type; + typedef pgsql::select_statement select_statement_type; + typedef pgsql::delete_statement delete_statement_type; + + typedef pgsql::connection connection_type; + + container_statements (connection_type&, + binding& id, + native_binding& idn, + const Oid* idt); + + connection_type& + connection () + { + return conn_; + } + + // Functions. + // + functions_type& + functions () + { + return functions_; + } + + // Schema version. + // + const schema_version_migration& + version_migration () const {return *svm_;} + + void + version_migration (const schema_version_migration& svm) {svm_ = &svm;} + + // Id image binding (external). + // + const binding& + id_binding () + { + return id_binding_; + } + + // Data image. The image is split into the id (that comes as a + // binding) and index/key plus value which are in data_image_type. + // The select binding is a subset of the full binding (no id). + // + data_image_type& + data_image () + { + return data_image_; + } + + bind* + data_bind () + { + return insert_image_binding_.bind; + } + + bool + data_binding_test_version () const + { + return data_id_binding_version_ != id_binding_.version || + data_image_version_ != data_image_.version || + insert_image_binding_.version == 0; + } + + void + data_binding_update_version () + { + data_id_binding_version_ = id_binding_.version; + data_image_version_ = data_image_.version; + insert_image_binding_.version++; + select_image_binding_.version++; + } + + bool* + select_image_truncated () + { + return select_image_truncated_; + } + + // + // Statements. + // + + insert_statement_type& + insert_statement () + { + if (insert_ == 0) + insert_.reset ( + new (details::shared) insert_statement_type ( + conn_, + insert_name_, + insert_text_, + versioned_, // Process if versioned. + insert_types_, + insert_count_, + insert_image_binding_, + insert_image_native_binding_, + 0, + false)); + + return *insert_; + } + + select_statement_type& + select_statement () + { + if (select_ == 0) + select_.reset ( + new (details::shared) select_statement_type ( + conn_, + select_name_, + select_text_, + versioned_, // Process if versioned. + false, // Don't optimize. + id_types_, + id_binding_.count, + id_binding_, + id_native_binding_, + select_image_binding_, + false)); + + return *select_; + } + + delete_statement_type& + delete_statement () + { + if (delete_ == 0) + delete_.reset ( + new (details::shared) delete_statement_type ( + conn_, + delete_name_, + delete_text_, + id_types_, + id_binding_.count, + id_binding_, + id_native_binding_, + false)); + + return *delete_; + } + + private: + container_statements (const container_statements&); + container_statements& operator= (const container_statements&); + + protected: + connection_type& conn_; + binding& id_binding_; + native_binding& id_native_binding_; + const Oid* id_types_; + + functions_type functions_; + + data_image_type data_image_; + std::size_t data_image_version_; + std::size_t data_id_binding_version_; + + binding insert_image_binding_; + native_binding insert_image_native_binding_; + + binding select_image_binding_; + bool* select_image_truncated_; + + const char* insert_name_; + const char* insert_text_; + const Oid* insert_types_; + std::size_t insert_count_; + + const char* select_name_; + const char* select_text_; + + const char* delete_name_; + const char* delete_text_; + + bool versioned_; + const schema_version_migration* svm_; + + details::shared_ptr insert_; + details::shared_ptr select_; + details::shared_ptr delete_; + }; + + template + class smart_container_statements: public container_statements + { + public: + typedef T traits; + typedef typename traits::cond_image_type cond_image_type; + + typedef pgsql::update_statement update_statement_type; + typedef pgsql::delete_statement delete_statement_type; + + typedef pgsql::connection connection_type; + + smart_container_statements (connection_type&, + binding& id, + native_binding& idn, + const Oid* idt); + + // Condition image. The image is split into the id (that comes as + // a binding) and index/key/value which is in cond_image_type. + // + cond_image_type& + cond_image () + { + return cond_image_; + } + + bind* + cond_bind () + { + return cond_image_binding_.bind; + } + + bool + cond_binding_test_version () const + { + return cond_id_binding_version_ != this->id_binding_.version || + cond_image_version_ != cond_image_.version || + cond_image_binding_.version == 0; + } + + void + cond_binding_update_version () + { + cond_id_binding_version_ = this->id_binding_.version; + cond_image_version_ = cond_image_.version; + cond_image_binding_.version++; + } + + // Update image. The image is split as follows: value comes + // from the data image, id comes as binding, and index/key + // comes from the condition image. + // + bind* + update_bind () + { + return update_image_binding_.bind; + } + + bool + update_binding_test_version () const + { + return update_id_binding_version_ != this->id_binding_.version || + update_cond_image_version_ != cond_image_.version || + update_data_image_version_ != this->data_image_.version || + update_image_binding_.version == 0; + } + + void + update_binding_update_version () + { + update_id_binding_version_ = this->id_binding_.version; + update_cond_image_version_ = cond_image_.version; + update_data_image_version_ = this->data_image_.version; + update_image_binding_.version++; + } + + // + // Statements. + // + + delete_statement_type& + delete_statement () + { + if (this->delete_ == 0) + this->delete_.reset ( + new (details::shared) delete_statement_type ( + this->conn_, + this->delete_name_, + this->delete_text_, + delete_types_, + delete_count_, + cond_image_binding_, + cond_image_native_binding_, + false)); + + return *this->delete_; + } + + update_statement_type& + update_statement () + { + if (update_ == 0) + update_.reset ( + new (details::shared) update_statement_type ( + this->conn_, + update_name_, + update_text_, + this->versioned_, // Process if versioned. + update_types_, + update_count_, + update_image_binding_, + update_image_native_binding_, + false)); + + return *update_; + } + + protected: + cond_image_type cond_image_; + std::size_t cond_image_version_; + std::size_t cond_id_binding_version_; + binding cond_image_binding_; + native_binding cond_image_native_binding_; + + std::size_t update_id_binding_version_; + std::size_t update_cond_image_version_; + std::size_t update_data_image_version_; + binding update_image_binding_; + native_binding update_image_native_binding_; + + const char* update_name_; + const char* update_text_; + const Oid* update_types_; + std::size_t update_count_; + + const Oid* delete_types_; + std::size_t delete_count_; + + details::shared_ptr update_; + }; + + // Template argument is the generated concrete container traits type. + // + template + class container_statements_impl: public T::statements_type + { + public: + typedef T traits; + typedef typename T::statements_type base; + typedef pgsql::connection connection_type; + + container_statements_impl (connection_type&, + binding&, + native_binding&, + const Oid*); + private: + container_statements_impl (const container_statements_impl&); + container_statements_impl& operator= (const container_statements_impl&); + + private: + bind data_image_bind_[traits::data_column_count]; + char* data_image_values_[traits::data_column_count]; + int data_image_lengths_[traits::data_column_count]; + int data_image_formats_[traits::data_column_count]; + + bool select_image_truncated_array_[traits::data_column_count - + traits::id_column_count]; + }; + + template + class smart_container_statements_impl: public container_statements_impl + { + public: + typedef T traits; + typedef pgsql::connection connection_type; + + smart_container_statements_impl (connection_type&, + binding&, + native_binding&, + const Oid*); + private: + bind cond_image_bind_[traits::cond_column_count]; + char* cond_image_values_[traits::cond_column_count]; + int cond_image_lengths_[traits::cond_column_count]; + int cond_image_formats_[traits::cond_column_count]; + + bind update_image_bind_[traits::value_column_count + + traits::cond_column_count]; + char* update_image_values_[traits::value_column_count + + traits::cond_column_count]; + int update_image_lengths_[traits::value_column_count + + traits::cond_column_count]; + int update_image_formats_[traits::value_column_count + + traits::cond_column_count]; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_CONTAINER_STATEMENTS_HXX diff --git a/libodb-pgsql/odb/pgsql/container-statements.txx b/libodb-pgsql/odb/pgsql/container-statements.txx new file mode 100644 index 0000000..34eb99f --- /dev/null +++ b/libodb-pgsql/odb/pgsql/container-statements.txx @@ -0,0 +1,154 @@ +// file : odb/pgsql/container-statements.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::size_t +#include // std::memset + +namespace odb +{ + namespace pgsql + { + // container_statements + // + template + container_statements:: + container_statements (connection_type& conn, + binding& id, + native_binding& idn, + const Oid* idt) + : conn_ (conn), + id_binding_ (id), + id_native_binding_ (idn), + id_types_ (idt), + functions_ (this), + insert_image_binding_ (0, 0), // Initialized by impl. + insert_image_native_binding_ (0, 0, 0, 0), // Initialized by impl. + select_image_binding_ (0, 0), // Initialized by impl. + svm_ (0) + { + functions_.insert_ = &traits::insert; + functions_.select_ = &traits::select; + functions_.delete__ = &traits::delete_; + + data_image_.version = 0; + data_image_version_ = 0; + data_id_binding_version_ = 0; + } + + // smart_container_statements + // + template + smart_container_statements:: + smart_container_statements (connection_type& conn, + binding& id, + native_binding& idn, + const Oid* idt) + : container_statements (conn, id, idn, idt), + cond_image_binding_ (0, 0), // Initialized by impl. + cond_image_native_binding_ (0, 0, 0, 0), // Initialized by impl. + update_image_binding_ (0, 0), // Initialized by impl. + update_image_native_binding_ (0, 0, 0, 0) // Initialized by impl. + { + this->functions_.update_ = &traits::update; + + cond_image_.version = 0; + cond_image_version_ = 0; + cond_id_binding_version_ = 0; + + update_id_binding_version_ = 0; + update_cond_image_version_ = 0; + update_data_image_version_ = 0; + } + + // container_statements_impl + // + template + container_statements_impl:: + container_statements_impl (connection_type& conn, + binding& id, + native_binding& idn, + const Oid* idt) + : base (conn, id, idn, idt) + { + this->select_image_truncated_ = select_image_truncated_array_; + + this->insert_image_binding_.bind = data_image_bind_; + this->insert_image_binding_.count = traits::data_column_count; + + this->select_image_binding_.bind = data_image_bind_ + + traits::id_column_count; + this->select_image_binding_.count = traits::data_column_count - + traits::id_column_count; + + this->insert_image_native_binding_.values = data_image_values_; + this->insert_image_native_binding_.lengths = data_image_lengths_; + this->insert_image_native_binding_.formats = data_image_formats_; + this->insert_image_native_binding_.count = traits::data_column_count; + + std::memset (data_image_bind_, 0, sizeof (data_image_bind_)); + std::memset (select_image_truncated_array_, + 0, + sizeof (select_image_truncated_array_)); + + for (std::size_t i (0); + i < traits::data_column_count - traits::id_column_count; + ++i) + data_image_bind_[i + traits::id_column_count].truncated = + select_image_truncated_array_ + i; + + this->insert_name_ = traits::insert_name; + this->insert_text_ = traits::insert_statement; + this->insert_types_ = traits::insert_types; + this->insert_count_ = traits::data_column_count; + + this->select_name_ = traits::select_name; + this->select_text_ = traits::select_statement; + + this->delete_name_ = traits::delete_name; + this->delete_text_ = traits::delete_statement; + + this->versioned_ = traits::versioned; + } + + // smart_container_statements_impl + // + template + smart_container_statements_impl:: + smart_container_statements_impl (connection_type& conn, + binding& id, + native_binding& idn, + const Oid* idt) + : container_statements_impl (conn, id, idn, idt) + { + this->cond_image_binding_.bind = cond_image_bind_; + this->cond_image_binding_.count = traits::cond_column_count; + + this->update_image_binding_.bind = update_image_bind_; + this->update_image_binding_.count = traits::value_column_count + + traits::cond_column_count; + + this->cond_image_native_binding_.values = cond_image_values_; + this->cond_image_native_binding_.lengths = cond_image_lengths_; + this->cond_image_native_binding_.formats = cond_image_formats_; + this->cond_image_native_binding_.count = traits::cond_column_count; + + this->update_image_native_binding_.values = update_image_values_; + this->update_image_native_binding_.lengths = update_image_lengths_; + this->update_image_native_binding_.formats = update_image_formats_; + this->update_image_native_binding_.count = traits::value_column_count + + traits::cond_column_count; + + std::memset (cond_image_bind_, 0, sizeof (cond_image_bind_)); + std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); + + this->update_name_ = traits::update_name; + this->update_text_ = traits::update_statement; + this->update_types_ = traits::update_types; + this->update_count_ = traits::value_column_count + + traits::cond_column_count; + + this->delete_types_ = traits::delete_types; + this->delete_count_ = traits::cond_column_count; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/database.cxx b/libodb-pgsql/odb/pgsql/database.cxx new file mode 100644 index 0000000..09bf6f0 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/database.cxx @@ -0,0 +1,424 @@ +// file : odb/pgsql/database.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // strlen() +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; + +namespace odb +{ + namespace pgsql + { + using odb::details::transfer_ptr; + + database:: + database (const string& user, + const string& password, + const string& db, + const string& host, + unsigned int port, + const string& extra_conninfo, + transfer_ptr factory) + : odb::database (id_pgsql), + user_ (user), + password_ (password), + db_ (db), + host_ (host), + port_ (port), + extra_conninfo_ (extra_conninfo), + factory_ (factory.transfer ()) + { + ostringstream ss; + + if (!user.empty ()) + ss << "user='" << user << "' "; + + if (!password.empty ()) + ss << "password='" << password << "' "; + + if (!db.empty ()) + ss << "dbname='" << db << "' "; + + if (!host.empty ()) + ss << "host='" << host << "' "; + + if (port) + ss << "port=" << port << " "; + + // Only the last occurence of keyword/value pair is used by libpq. + // extra_conninfo specified options take precedence. + // + if (!extra_conninfo.empty ()) + ss << extra_conninfo; + + conninfo_ = ss.str (); + + if (!factory_) + factory_.reset (new connection_pool_factory ()); + + factory_->database (*this); + } + + database:: + database (const string& user, + const string& password, + const string& db, + const string& host, + const string& socket_ext, + const string& extra_conninfo, + transfer_ptr factory) + : odb::database (id_pgsql), + user_ (user), + password_ (password), + db_ (db), + host_ (host), + port_ (0), + socket_ext_ (socket_ext), + extra_conninfo_ (extra_conninfo), + factory_ (factory.transfer ()) + { + ostringstream ss; + + if (!user.empty ()) + ss << "user='" << user << "' "; + + if (!password.empty ()) + ss << "password='" << password << "' "; + + if (!db.empty ()) + ss << "dbname='" << db << "' "; + + if (!host.empty ()) + ss << "host='" << host << "' "; + + if (!socket_ext.empty ()) + ss << "port='" << socket_ext << "' "; + + // Only the last occurence of keyword/value pair is used by libpq. + // extra_conninfo specified options take precedence. + // + if (!extra_conninfo.empty ()) + ss << extra_conninfo; + + conninfo_ = ss.str (); + + if (!factory_) + factory_.reset (new connection_pool_factory ()); + + factory_->database (*this); + } + + database:: + database (const string& conninfo, transfer_ptr factory) + : odb::database (id_pgsql), + port_ (0), + conninfo_ (conninfo), + factory_ (factory.transfer ()) + { + if (!factory_) + factory_.reset (new connection_pool_factory ()); + + factory_->database (*this); + } + + database:: + database (int& argc, + char* argv[], + bool erase, + const string& extra_conninfo, + transfer_ptr factory) + : odb::database (id_pgsql), port_ (0), factory_ (factory.transfer ()) + { + using namespace details; + + try + { + cli::argv_file_scanner scan (argc, argv, "--options-file", erase); + options ops (scan, cli::unknown_mode::skip, cli::unknown_mode::skip); + + ostringstream oss; + + if (ops.user_specified ()) + { + user_ = ops.user (); + oss << "user='" << user_ << "' "; + } + + if (ops.password_specified ()) + { + password_ = ops.password (); + oss << "password='" << password_ << "' "; + } + + if (ops.database_specified ()) + { + db_ = ops.database (); + oss << "dbname='" << db_ << "' "; + } + + if (ops.host_specified ()) + { + host_ = ops.host (); + oss << "host='" << host_ << "' "; + } + + if (ops.port_specified ()) + { + istringstream iss (ops.port ()); + + if (iss >> port_ && iss.eof ()) + oss << " port=" << port_ << " "; + else + { + port_ = 0; + socket_ext_ = ops.port (); + oss << "port='" << socket_ext_ << "' "; + } + } + + if (!extra_conninfo.empty ()) + oss << extra_conninfo; + + conninfo_ = oss.str (); + } + catch (const cli::exception& e) + { + ostringstream oss; + oss << e; + throw cli_exception (oss.str ()); + } + + if (!factory_) + factory_.reset (new connection_pool_factory ()); + + factory_->database (*this); + } + + void database:: + print_usage (std::ostream& os) + { + details::options::print_usage (os); + } + + database:: + ~database () + { + } + + transaction_impl* database:: + begin () + { + return new transaction_impl (*this); + } + + odb::connection* database:: + connection_ () + { + connection_ptr c (factory_->connect ()); + return c.release (); + } + + const database::schema_version_info& database:: + load_schema_version (const string& name) const + { + schema_version_info& svi (schema_version_map_[name]); + + // Quoted table name. + // + const char* table ( + !svi.version_table.empty () ? svi.version_table.c_str () : + !schema_version_table_.empty () ? schema_version_table_.c_str () : + /* */ "\"schema_version\""); + + // Construct the SELECT statement text. + // + string text ("SELECT \"version\", \"migration\" FROM "); + text += table; + text += " WHERE \"name\" = $1"; + + // Bind parameters and results. + // + char* pbuf[1] = {const_cast (name.c_str ())}; + size_t psize[1] = {name.size ()}; + bool pnull[1] = {false}; + bind pbind[1] = {{bind::text, + &pbuf[0], + &psize[0], + psize[0], + &pnull[0], + 0}}; + binding param (pbind, 1); + param.version++; + + unsigned int param_types[1] = {text_oid}; + + char* values[1]; + int lengths[1]; + int formats[1]; + native_binding nparam (values, lengths, formats, 1); + + long long version; + bool rnull[2]; + bind rbind[2] = {{bind::bigint, &version, 0, 0, &rnull[0], 0}, + {bind::boolean_, &svi.migration, 0, 0, &rnull[1], 0}}; + binding result (rbind, 2); + result.version++; + + // If we are not in transaction, PostgreSQL will start an implicit one + // which suits us just fine. + // + connection_ptr cp; + if (!transaction::has_current ()) + cp = factory_->connect (); + + pgsql::connection& c ( + cp != 0 + ? *cp + : transaction::current ().connection (const_cast (*this))); + + // If we are in the user's transaction then things are complicated. When + // we try to execute SELECT on a non-existent table, PG "poisons" the + // transaction (those "current transaction is aborted, commands ignored + // until end of transaction block" messages in the log). Which means all + // the user's schema creation statements that are likely to follow will + // fail. + // + // There doesn't seem to be a better way to solve this than to check for + // the table's existence. It is relatively easy to do with to_regclass() + // in 9.4+ and a real pain in earlier versions. So we are going to do + // this for 9.4+ and for older versions the workaround is to "pre-call" + // database::schema_version() outside of any transaction. + // + bool exists (true); + if (cp == 0 && c.server_version () >= 90400) + { + char* pbuf[1] = {const_cast (table)}; + size_t psize[1] = {strlen (table)}; + bool pnull[1] = {false}; + bind pbind[1] = {{bind::text, + &pbuf[0], + &psize[0], + psize[0], + &pnull[0], + 0}}; + binding param (pbind, 1); + param.version++; + + unsigned int param_types[1] = {text_oid}; + + char* values[1]; + int lengths[1]; + int formats[1]; + native_binding nparam (values, lengths, formats, 1); + + bool rnull[1]; + bind rbind[1] = {{bind::boolean_, &exists, 0, 0, &rnull[0], 0}}; + binding result (rbind, 1); + result.version++; + + // Note that to_regclass() seems happy to accept a quoted table name. + // + // Also note that starting 9.6 it requires text type rather than + // cstring type. + // + select_statement st (c, + "odb_database_schema_version_exists", + c.server_version () >= 90600 + ? "SELECT to_regclass($1::text) IS NOT NULL" + : "SELECT to_regclass($1::cstring) IS NOT NULL", + false, // Don't process. + false, // Don't optimize. + param_types, + 1, + param, + nparam, + result, + false); + + st.execute (); + auto_result ar (st); + + switch (st.fetch ()) + { + case select_statement::success: + { + assert (st.fetch () == select_statement::no_data); + break; + } + case select_statement::no_data: + case select_statement::truncated: + { + assert (false); + break; + } + } + } + + // Assume no schema until determined otherwise. + // + svi.version = 0; + + if (exists) + { + try + { + select_statement st (c, + "odb_database_schema_version_query", + text.c_str (), + false, // Don't process. + false, // Don't optimize. + param_types, + 1, + param, + nparam, + result, + false); + st.execute (); + auto_result ar (st); + + switch (st.fetch ()) + { + case select_statement::success: + { + value_traits::set_value ( + svi.version, version, rnull[0]); + assert (st.fetch () == select_statement::no_data); + break; + } + case select_statement::no_data: + { + // No schema. + break; + } + case select_statement::truncated: + { + assert (false); + break; + } + } + } + catch (const database_exception& e) + { + // Detect the case where there is no version table (the implicit + // transaction case). + // + if (e.sqlstate () != "42P01") + throw; + } + } + + return svi; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/database.hxx b/libodb-pgsql/odb/pgsql/database.hxx new file mode 100644 index 0000000..950cad1 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/database.hxx @@ -0,0 +1,527 @@ +// file : odb/pgsql/database.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_DATABASE_HXX +#define ODB_PGSQL_DATABASE_HXX + +#include + +#include +#include // std::ostream + +#include +#include // ODB_CXX11 +#include +#include + +#include +#include +#include +#include +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + class transaction_impl; + + class LIBODB_PGSQL_EXPORT database: public odb::database + { + public: + database (const std::string& user, + const std::string& password, + const std::string& db, + const std::string& host = "", + unsigned int port = 0, + const std::string& extra_conninfo = "", + details::transfer_ptr = + details::transfer_ptr ()); + + database (const std::string& user, + const std::string& password, + const std::string& db, + const std::string& host, + const std::string& socket_ext, + const std::string& extra_conninfo = "", + details::transfer_ptr = + details::transfer_ptr ()); + + explicit + database (const std::string& conninfo, + details::transfer_ptr = + details::transfer_ptr ()); + + // Extract the database parameters from the command line. The + // following options are recognized: + // + // --user | --username + // --password + // --database | --dbname + // --host + // --port + // --options-file + // + // For more information, see the output of the print_usage() function + // below. If erase is true, the above options are removed from the + // argv array and the argc count is updated accordingly. This + // constructor may throw the cli_exception exception. + // + database (int& argc, + char* argv[], + bool erase = false, + const std::string& extra_conninfo = "", + details::transfer_ptr = + details::transfer_ptr ()); + + // Move-constructible but not move-assignable. + // + // Note: noexcept is not specified since odb::database(odb::database&&) + // can throw. + // +#ifdef ODB_CXX11 + database (database&&); +#endif + + static void + print_usage (std::ostream&); + + // Object persistence API. + // + public: + + // Make the object persistent. + // + template + typename object_traits::id_type + persist (T& object); + + template + typename object_traits::id_type + persist (const T& object); + + template + typename object_traits::id_type + persist (T* obj_ptr); + + template class P> + typename object_traits::id_type + persist (const P& obj_ptr); + + template class P> + typename object_traits::id_type + persist (const P& obj_ptr); + + template class P> + typename object_traits::id_type + persist (P& obj_ptr); + + template class P> + typename object_traits::id_type + persist (P& obj_ptr); + + template + typename object_traits::id_type + persist (const typename object_traits::pointer_type& obj_ptr); + + // Bulk persist. Can be a range of references or pointers (including + // smart pointers) to objects. + // + template + void + persist (I begin, I end, bool continue_failed = true); + + // Load an object. Throw object_not_persistent if not found. + // + template + typename object_traits::pointer_type + load (const typename object_traits::id_type& id); + + template + void + load (const typename object_traits::id_type& id, T& object); + + // Load (or reload, if it is already loaded) a section of an object. + // + template + void + load (T& object, section&); + + // Reload an object. + // + template + void + reload (T& object); + + template + void + reload (T* obj_ptr); + + template class P> + void + reload (const P& obj_ptr); + + template class P> + void + reload (const P& obj_ptr); + + template class P> + void + reload (P& obj_ptr); + + template class P> + void + reload (P& obj_ptr); + + template + void + reload (const typename object_traits::pointer_type& obj_ptr); + + // Loan an object if found. Return NULL/false if not found. + // + template + typename object_traits::pointer_type + find (const typename object_traits::id_type& id); + + template + bool + find (const typename object_traits::id_type& id, T& object); + + // Update the state of a modified objects. + // + template + void + update (T& object); + + template + void + update (T* obj_ptr); + + template class P> + void + update (const P& obj_ptr); + + template class P> + void + update (const P& obj_ptr); + + template class P> + void + update (P& obj_ptr); + + template class P> + void + update (P& obj_ptr); + + template + void + update (const typename object_traits::pointer_type& obj_ptr); + + // Bulk update. Can be a range of references or pointers (including + // smart pointers) to objects. + // + template + void + update (I begin, I end, bool continue_failed = true); + + // Update a section of an object. Throws the section_not_loaded + // exception if the section is not loaded. Note also that this + // function does not clear the changed flag if it is set. + // + template + void + update (const T& object, const section&); + + // Make the object transient. Throw object_not_persistent if not + // found. + // + template + void + erase (const typename object_traits::id_type& id); + + template + void + erase (T& object); + + template + void + erase (T* obj_ptr); + + template class P> + void + erase (const P& obj_ptr); + + template class P> + void + erase (const P& obj_ptr); + + template class P> + void + erase (P& obj_ptr); + + template class P> + void + erase (P& obj_ptr); + + template + void + erase (const typename object_traits::pointer_type& obj_ptr); + + // Bulk erase. + // + template + void + erase (I id_begin, I id_end, bool continue_failed = true); + + // Can be a range of references or pointers (including smart pointers) + // to objects. + // + template + void + erase (I obj_begin, I obj_end, bool continue_failed = true); + + // Erase multiple objects matching a query predicate. + // + template + unsigned long long + erase_query (); + + template + unsigned long long + erase_query (const char*); + + template + unsigned long long + erase_query (const std::string&); + + template + unsigned long long + erase_query (const pgsql::query_base&); + + template + unsigned long long + erase_query (const odb::query_base&); + + // Query API. + // + template + result + query (); + + template + result + query (const char*); + + template + result + query (const std::string&); + + template + result + query (const pgsql::query_base&); + + template + result + query (const odb::query_base&); + + // Query one API. + // + template + typename result::pointer_type + query_one (); + + template + bool + query_one (T& object); + + template + T + query_value (); + + template + typename result::pointer_type + query_one (const char*); + + template + bool + query_one (const char*, T& object); + + template + T + query_value (const char*); + + template + typename result::pointer_type + query_one (const std::string&); + + template + bool + query_one (const std::string&, T& object); + + template + T + query_value (const std::string&); + + template + typename result::pointer_type + query_one (const pgsql::query_base&); + + template + bool + query_one (const pgsql::query_base&, T& object); + + template + T + query_value (const pgsql::query_base&); + + template + typename result::pointer_type + query_one (const odb::query_base&); + + template + bool + query_one (const odb::query_base&, T& object); + + template + T + query_value (const odb::query_base&); + + // Query preparation. + // + template + prepared_query + prepare_query (const char* name, const char*); + + template + prepared_query + prepare_query (const char* name, const std::string&); + + template + prepared_query + prepare_query (const char* name, const pgsql::query_base&); + + template + prepared_query + prepare_query (const char* name, const odb::query_base&); + + // Transactions. + // + public: + virtual transaction_impl* + begin (); + + public: + connection_ptr + connection (); + + // Database schema version. + // + protected: + virtual const schema_version_info& + load_schema_version (const std::string& schema_name) const; + + public: + // Database id constant (useful for meta-programming). + // + static const odb::database_id database_id = id_pgsql; + + public: + virtual + ~database (); + + protected: + virtual odb::connection* + connection_ (); + + // SQL statement tracing. + // + public: + typedef pgsql::tracer tracer_type; + + void + tracer (tracer_type& t) + { + odb::database::tracer (t); + } + + void + tracer (tracer_type* t) + { + odb::database::tracer (t); + } + + using odb::database::tracer; + + public: + const std::string& + user () const + { + return user_; + } + + const std::string& + password () const + { + return password_; + } + + const std::string& + db () const + { + return db_; + } + + const std::string& + host () const + { + return host_; + } + + unsigned int + port () const + { + return port_; + } + + const std::string& + socket_ext () const + { + return socket_ext_; + } + + const std::string& + extra_conninfo () const + { + return extra_conninfo_; + } + + const std::string& + conninfo () const + { + return conninfo_; + } + + private: + // Note: remember to update move ctor if adding any new members. + // + std::string user_; + std::string password_; + std::string db_; + std::string host_; + unsigned int port_; + std::string socket_ext_; + std::string extra_conninfo_; + std::string conninfo_; + details::unique_ptr factory_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_DATABASE_HXX diff --git a/libodb-pgsql/odb/pgsql/database.ixx b/libodb-pgsql/odb/pgsql/database.ixx new file mode 100644 index 0000000..f04c3e6 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/database.ixx @@ -0,0 +1,638 @@ +// file : odb/pgsql/database.ixx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // move() + +#include + +namespace odb +{ + namespace pgsql + { +#ifdef ODB_CXX11 + inline database:: + database (database&& db) // Has to be inline. + : odb::database (std::move (db)), + user_ (std::move (db.user_)), + password_ (std::move (db.password_)), + db_ (std::move (db.db_)), + host_ (std::move (db.host_)), + port_ (db.port_), + socket_ext_ (std::move (db.socket_ext_)), + extra_conninfo_ (std::move (db.extra_conninfo_)), + conninfo_ (std::move (db.conninfo_)), + factory_ (std::move (db.factory_)) + { + factory_->database (*this); // New database instance. + } +#endif + + inline connection_ptr database:: + connection () + { + // Go through the virtual connection_() function instead of + // directly to allow overriding. + // + return connection_ptr ( + static_cast (connection_ ())); + } + + template + inline typename object_traits::id_type database:: + persist (T& obj) + { + return persist_ (obj); + } + + template + inline typename object_traits::id_type database:: + persist (const T& obj) + { + return persist_ (obj); + } + + template + inline typename object_traits::id_type database:: + persist (T* p) + { + typedef typename object_traits::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + return persist_ (pobj); + } + + template class P> + inline typename object_traits::id_type database:: + persist (const P& p) + { + typedef typename object_traits::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + return persist_ (pobj); + } + + template class P> + inline typename object_traits::id_type database:: + persist (const P& p) + { + typedef typename object_traits::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + return persist_ (pobj); + } + + template class P> + inline typename object_traits::id_type database:: + persist (P& p) + { + const P& cr (p); + return persist (cr); + } + + template class P> + inline typename object_traits::id_type database:: + persist (P& p) + { + const P& cr (p); + return persist (cr); + } + + template + inline typename object_traits::id_type database:: + persist (const typename object_traits::pointer_type& pobj) + { + return persist_ (pobj); + } + + template + inline void database:: + persist (I b, I e, bool cont) + { + persist_ (b, e, cont); + } + + template + inline typename object_traits::pointer_type database:: + load (const typename object_traits::id_type& id) + { + return load_ (id); + } + + template + inline void database:: + load (const typename object_traits::id_type& id, T& obj) + { + return load_ (id, obj); + } + + template + inline void database:: + load (T& obj, section& s) + { + return load_ (obj, s); + } + + template + inline typename object_traits::pointer_type database:: + find (const typename object_traits::id_type& id) + { + return find_ (id); + } + + template + inline bool database:: + find (const typename object_traits::id_type& id, T& obj) + { + return find_ (id, obj); + } + + template + inline void database:: + reload (T& obj) + { + reload_ (obj); + } + + template + inline void database:: + reload (T* p) + { + reload (*p); + } + + template class P> + inline void database:: + reload (const P& p) + { + reload (odb::pointer_traits< P >::get_ref (p)); + } + + template class P> + inline void database:: + reload (const P& p) + { + reload (odb::pointer_traits< P >::get_ref (p)); + } + + template class P> + inline void database:: + reload (P& p) + { + reload (odb::pointer_traits< P >::get_ref (p)); + } + + template class P> + inline void database:: + reload (P& p) + { + reload (odb::pointer_traits< P >::get_ref (p)); + } + + template + inline void database:: + reload (const typename object_traits::pointer_type& pobj) + { + typedef typename object_traits::pointer_type pointer_type; + + reload (odb::pointer_traits::get_ref (pobj)); + } + + template + inline void database:: + update (T& obj) + { + update_ (obj); + } + + template + inline void database:: + update (T* p) + { + typedef typename object_traits::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + update_ (pobj); + } + + template class P> + inline void database:: + update (const P& p) + { + typedef typename object_traits::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + update_ (pobj); + } + + template class P> + inline void database:: + update (const P& p) + { + typedef typename object_traits::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + update_ (pobj); + } + + template class P> + inline void database:: + update (P& p) + { + const P& cr (p); + update (cr); + } + + template class P> + inline void database:: + update (P& p) + { + const P& cr (p); + update (cr); + } + + template + inline void database:: + update (const typename object_traits::pointer_type& pobj) + { + update_ (pobj); + } + + template + inline void database:: + update (I b, I e, bool cont) + { + update_ (b, e, cont); + } + + template + inline void database:: + update (const T& obj, const section& s) + { + update_ (obj, s); + } + + template + inline void database:: + erase (const typename object_traits::id_type& id) + { + return erase_ (id); + } + + template + inline void database:: + erase (T& obj) + { + return erase_ (obj); + } + + template + inline void database:: + erase (T* p) + { + typedef typename object_traits::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + erase_ (pobj); + } + + template class P> + inline void database:: + erase (const P& p) + { + typedef typename object_traits::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + erase_ (pobj); + } + + template class P> + inline void database:: + erase (const P& p) + { + typedef typename object_traits::pointer_type object_pointer; + + // The passed pointer should be the same or implicit-convertible + // to the object pointer. This way we make sure the object pointer + // does not assume ownership of the passed object. + // + const object_pointer& pobj (p); + + erase_ (pobj); + } + + template class P> + inline void database:: + erase (P& p) + { + const P& cr (p); + erase (cr); + } + + template class P> + inline void database:: + erase (P& p) + { + const P& cr (p); + erase (cr); + } + + template + inline void database:: + erase (const typename object_traits::pointer_type& pobj) + { + erase_ (pobj); + } + + template + inline void database:: + erase (I idb, I ide, bool cont) + { + erase_id_ (idb, ide, cont); + } + + template + inline void database:: + erase (I ob, I oe, bool cont) + { + erase_object_ (ob, oe, cont); + } + + template + inline unsigned long long database:: + erase_query () + { + // T is always object_type. + // + return erase_query (pgsql::query_base ()); + } + + template + inline unsigned long long database:: + erase_query (const char* q) + { + // T is always object_type. + // + return erase_query (pgsql::query_base (q)); + } + + template + inline unsigned long long database:: + erase_query (const std::string& q) + { + // T is always object_type. + // + return erase_query (pgsql::query_base (q)); + } + + template + inline unsigned long long database:: + erase_query (const pgsql::query_base& q) + { + // T is always object_type. + // + return object_traits_impl::erase_query (*this, q); + } + + template + inline unsigned long long database:: + erase_query (const odb::query_base& q) + { + // Translate to native query. + // + return erase_query (pgsql::query_base (q)); + } + + template + inline result database:: + query () + { + return query (pgsql::query_base ()); + } + + template + inline result database:: + query (const char* q) + { + return query (pgsql::query_base (q)); + } + + template + inline result database:: + query (const std::string& q) + { + return query (pgsql::query_base (q)); + } + + template + inline result database:: + query (const pgsql::query_base& q) + { + // T is always object_type. We also don't need to check for transaction + // here; object_traits::query () does this. + // + return query_::call (*this, q); + } + + template + inline result database:: + query (const odb::query_base& q) + { + // Translate to native query. + // + return query (pgsql::query_base (q)); + } + + template + inline typename result::pointer_type database:: + query_one () + { + return query_one (pgsql::query_base ()); + } + + template + inline bool database:: + query_one (T& o) + { + return query_one (pgsql::query_base (), o); + } + + template + inline T database:: + query_value () + { + return query_value (pgsql::query_base ()); + } + + template + inline typename result::pointer_type database:: + query_one (const char* q) + { + return query_one (pgsql::query_base (q)); + } + + template + inline bool database:: + query_one (const char* q, T& o) + { + return query_one (pgsql::query_base (q), o); + } + + template + inline T database:: + query_value (const char* q) + { + return query_value (pgsql::query_base (q)); + } + + template + inline typename result::pointer_type database:: + query_one (const std::string& q) + { + return query_one (pgsql::query_base (q)); + } + + template + inline bool database:: + query_one (const std::string& q, T& o) + { + return query_one (pgsql::query_base (q), o); + } + + template + inline T database:: + query_value (const std::string& q) + { + return query_value (pgsql::query_base (q)); + } + + template + inline typename result::pointer_type database:: + query_one (const pgsql::query_base& q) + { + // T is always object_type. We also don't need to check for transaction + // here; object_traits::query () does this. + // + return query_one_ (q); + } + + template + inline bool database:: + query_one (const pgsql::query_base& q, T& o) + { + // T is always object_type. We also don't need to check for transaction + // here; object_traits::query () does this. + // + return query_one_ (q, o); + } + + template + inline T database:: + query_value (const pgsql::query_base& q) + { + // T is always object_type. We also don't need to check for transaction + // here; object_traits::query () does this. + // + return query_value_ (q); + } + + template + inline typename result::pointer_type database:: + query_one (const odb::query_base& q) + { + // Translate to native query. + // + return query_one (pgsql::query_base (q)); + } + + template + inline bool database:: + query_one (const odb::query_base& q, T& o) + { + // Translate to native query. + // + return query_one (pgsql::query_base (q), o); + } + + template + inline T database:: + query_value (const odb::query_base& q) + { + // Translate to native query. + // + return query_value (pgsql::query_base (q)); + } + + template + inline prepared_query database:: + prepare_query (const char* n, const char* q) + { + return prepare_query (n, pgsql::query_base (q)); + } + + template + inline prepared_query database:: + prepare_query (const char* n, const std::string& q) + { + return prepare_query (n, pgsql::query_base (q)); + } + + template + inline prepared_query database:: + prepare_query (const char* n, const pgsql::query_base& q) + { + // Throws if not in transaction. + // + pgsql::connection& c (transaction::current ().connection (*this)); + return c.prepare_query (n, q); + } + + template + inline prepared_query database:: + prepare_query (const char* n, const odb::query_base& q) + { + // Translate to native query. + // + return prepare_query (n, pgsql::query_base (q)); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/details/.gitignore b/libodb-pgsql/odb/pgsql/details/.gitignore new file mode 100644 index 0000000..b298f89 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/.gitignore @@ -0,0 +1 @@ +/options.?xx diff --git a/libodb-pgsql/odb/pgsql/details/build2/config-stub.h b/libodb-pgsql/odb/pgsql/details/build2/config-stub.h new file mode 100644 index 0000000..00c5940 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/build2/config-stub.h @@ -0,0 +1,5 @@ +/* file : odb/pgsql/details/build2/config-stub.h + * license : GNU GPL v2; see accompanying LICENSE file + */ + +#include diff --git a/libodb-pgsql/odb/pgsql/details/build2/config-vc-stub.h b/libodb-pgsql/odb/pgsql/details/build2/config-vc-stub.h new file mode 100644 index 0000000..473cd96 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/build2/config-vc-stub.h @@ -0,0 +1,5 @@ +/* file : odb/pgsql/details/build2/config-vc-stub.h + * license : GNU GPL v2; see accompanying LICENSE file + */ + +#include diff --git a/libodb-pgsql/odb/pgsql/details/build2/config-vc.h b/libodb-pgsql/odb/pgsql/details/build2/config-vc.h new file mode 100644 index 0000000..e9d9ade --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/build2/config-vc.h @@ -0,0 +1,15 @@ +/* file : odb/pgsql/details/build2/config-vc.h + * license : GNU GPL v2; see accompanying LICENSE file + */ + +/* Configuration file for Windows/VC++ for the build2 build. */ + +#ifndef ODB_PGSQL_DETAILS_CONFIG_VC_H +#define ODB_PGSQL_DETAILS_CONFIG_VC_H + +/* Define LIBODB_PGSQL_BUILD2 for the installed case. */ +#ifndef LIBODB_PGSQL_BUILD2 +# define LIBODB_PGSQL_BUILD2 +#endif + +#endif /* ODB_PGSQL_DETAILS_CONFIG_VC_H */ diff --git a/libodb-pgsql/odb/pgsql/details/build2/config.h b/libodb-pgsql/odb/pgsql/details/build2/config.h new file mode 100644 index 0000000..b2a81b5 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/build2/config.h @@ -0,0 +1,17 @@ +/* file : odb/pgsql/details/build2/config.h + * license : GNU GPL v2; see accompanying LICENSE file + */ + +/* Static configuration file for the build2 build. The installed case + (when LIBODB_PGSQL_BUILD2 is not necessarily defined) is the only + reason we have it. */ + +#ifndef ODB_PGSQL_DETAILS_CONFIG_H +#define ODB_PGSQL_DETAILS_CONFIG_H + +/* Define LIBODB_PGSQL_BUILD2 for the installed case. */ +#ifndef LIBODB_PGSQL_BUILD2 +# define LIBODB_PGSQL_BUILD2 +#endif + +#endif /* ODB_PGSQL_DETAILS_CONFIG_H */ diff --git a/libodb-pgsql/odb/pgsql/details/config-vc.h b/libodb-pgsql/odb/pgsql/details/config-vc.h new file mode 100644 index 0000000..77a0be5 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/config-vc.h @@ -0,0 +1,5 @@ +/* file : odb/pgsql/details/config-vc.h + * license : GNU GPL v2; see accompanying LICENSE file + */ + +/* Dummy configuration file for Windows/VC++. */ diff --git a/libodb-pgsql/odb/pgsql/details/config.h.in b/libodb-pgsql/odb/pgsql/details/config.h.in new file mode 100644 index 0000000..889023c --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/config.h.in @@ -0,0 +1,12 @@ +/* file : odb/pgsql/details/config.h.in + * license : GNU GPL v2; see accompanying LICENSE file + */ + +/* This file is automatically processed by configure. */ + +#ifndef ODB_PGSQL_DETAILS_CONFIG_H +#define ODB_PGSQL_DETAILS_CONFIG_H + +#undef LIBODB_PGSQL_STATIC_LIB + +#endif /* ODB_PGSQL_DETAILS_CONFIG_H */ diff --git a/libodb-pgsql/odb/pgsql/details/config.hxx b/libodb-pgsql/odb/pgsql/details/config.hxx new file mode 100644 index 0000000..1340622 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/config.hxx @@ -0,0 +1,21 @@ +// file : odb/pgsql/details/config.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_DETAILS_CONFIG_HXX +#define ODB_PGSQL_DETAILS_CONFIG_HXX + +// no pre + +#ifdef ODB_COMPILER +# error libodb-pgsql header included in odb-compiled header +#elif !defined(LIBODB_PGSQL_BUILD2) +# ifdef _MSC_VER +# include +# else +# include +# endif +#endif + +// no post + +#endif // ODB_PGSQL_DETAILS_CONFIG_HXX diff --git a/libodb-pgsql/odb/pgsql/details/conversion.hxx b/libodb-pgsql/odb/pgsql/details/conversion.hxx new file mode 100644 index 0000000..b4d7e4f --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/conversion.hxx @@ -0,0 +1,58 @@ +// file : odb/pgsql/details/conversion.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_DETAILS_CONVERSION_HXX +#define ODB_PGSQL_DETAILS_CONVERSION_HXX + +#include + +#include + +namespace odb +{ + // @@ Revise this. + // + namespace details {} + + namespace pgsql + { + namespace details + { + using namespace odb::details; + + // Detect whether conversion is specified in type_traits. + // + template + meta::yes + conversion_p_test (typename type_traits::conversion*); + + template + meta::no + conversion_p_test (...); + + template + struct conversion_p + { + static const bool value = + sizeof (conversion_p_test (0)) == sizeof (meta::yes); + }; + + template ::value> + struct conversion; + + template + struct conversion + { + static const char* to () {return type_traits::conversion::to ();} + }; + + template + struct conversion + { + static const char* to () {return 0;} + }; + } + } +} + +#endif // ODB_PGSQL_DETAILS_CONVERSION_HXX diff --git a/libodb-pgsql/odb/pgsql/details/endian-traits.cxx b/libodb-pgsql/odb/pgsql/details/endian-traits.cxx new file mode 100644 index 0000000..77fdc95 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/endian-traits.cxx @@ -0,0 +1,30 @@ +// file : odb/pgsql/details/endian-traits.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + namespace pgsql + { + namespace details + { + namespace + { + endian_traits::endian + infer_host_endian () + { + short s (1); + char* c (reinterpret_cast (&s)); + + return *c == 0 ? + endian_traits::big : + endian_traits::little; + } + } + + const endian_traits::endian endian_traits::host_endian ( + infer_host_endian ()); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/details/endian-traits.hxx b/libodb-pgsql/odb/pgsql/details/endian-traits.hxx new file mode 100644 index 0000000..532a4a3 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/endian-traits.hxx @@ -0,0 +1,155 @@ +// file : odb/pgsql/details/endian-traits.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_DETAILS_ENDIAN_TRAITS_HXX +#define ODB_PGSQL_DETAILS_ENDIAN_TRAITS_HXX + +#include // std::size_t +#include // std::reverse + +#include + +namespace odb +{ + // @@ Revise this. + // + namespace details + { + } + + namespace pgsql + { + namespace details + { + using namespace odb::details; + + template + struct swap_endian; + + template + struct swap_endian + { + static T + swap (T x) + { + return x; + } + }; + + template + struct swap_endian + { + static T + swap (T x) + { + union u2 + { + T t; + char c[2]; + }; + + u2 u; + u.t = x; + + char tmp (u.c[0]); + u.c[0] = u.c[1]; + u.c[1] = tmp; + + return u.t; + } + }; + + template + struct swap_endian + { + static T + swap (T x) + { + union u4 + { + T t; + char c[4]; + }; + + u4 u; + u.t = x; + + char tmp (u.c[0]); + u.c[0] = u.c[3]; + u.c[3] = tmp; + + tmp = u.c[1]; + u.c[1] = u.c[2]; + u.c[2] = tmp; + + return u.t; + } + }; + + template + struct swap_endian + { + static T + swap (T x) + { + union u8 + { + T t; + char c[8]; + }; + + u8 u; + u.t = x; + + char tmp (u.c[0]); + u.c[0] = u.c[7]; + u.c[7] = tmp; + + tmp = u.c[1]; + u.c[1] = u.c[6]; + u.c[6] = tmp; + + tmp = u.c[2]; + u.c[2] = u.c[5]; + u.c[5] = tmp; + + tmp = u.c[3]; + u.c[3] = u.c[4]; + u.c[4] = tmp; + + return u.t; + } + }; + + class LIBODB_PGSQL_EXPORT endian_traits + { + public: + enum endian + { + big, + little + }; + + public: + static const endian host_endian; + + public: + template + static T + hton (T x) + { + return host_endian == big ? x : swap_endian::swap (x); + } + + template + static T + ntoh (T x) + { + return host_endian == big ? x : swap_endian::swap (x); + } + }; + } + } +} + +#endif // ODB_PGSQL_DETAILS_ENDIAN_TRAITS_HXX diff --git a/libodb-pgsql/odb/pgsql/details/export.hxx b/libodb-pgsql/odb/pgsql/details/export.hxx new file mode 100644 index 0000000..81ff6a0 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/export.hxx @@ -0,0 +1,78 @@ +// file : odb/pgsql/details/export.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_DETAILS_EXPORT_HXX +#define ODB_PGSQL_DETAILS_EXPORT_HXX + +#include + +#include + +// Normally we don't export class templates (but do complete specializations), +// inline functions, and classes with only inline member functions. Exporting +// classes that inherit from non-exported/imported bases (e.g., std::string) +// will end up badly. The only known workarounds are to not inherit or to not +// export. Also, MinGW GCC doesn't like seeing non-exported function being +// used before their inline definition. The workaround is to reorder code. In +// the end it's all trial and error. + +#ifdef LIBODB_PGSQL_BUILD2 + +#if defined(LIBODB_PGSQL_STATIC) // Using static. +# define LIBODB_PGSQL_EXPORT +#elif defined(LIBODB_PGSQL_STATIC_BUILD) // Building static. +# define LIBODB_PGSQL_EXPORT +#elif defined(LIBODB_PGSQL_SHARED) // Using shared. +# ifdef _WIN32 +# define LIBODB_PGSQL_EXPORT __declspec(dllimport) +# else +# define LIBODB_PGSQL_EXPORT +# endif +#elif defined(LIBODB_PGSQL_SHARED_BUILD) // Building shared. +# ifdef _WIN32 +# define LIBODB_PGSQL_EXPORT __declspec(dllexport) +# else +# define LIBODB_PGSQL_EXPORT +# endif +#else +// If none of the above macros are defined, then we assume we are being used +// by some third-party build system that cannot/doesn't signal the library +// type. Note that this fallback works for both static and shared but in case +// of shared will be sub-optimal compared to having dllimport. +// +# define LIBODB_PGSQL_EXPORT // Using static or shared. +#endif + +#else // LIBODB_PGSQL_BUILD2 + +#ifdef LIBODB_PGSQL_STATIC_LIB +# define LIBODB_PGSQL_EXPORT +#else +# ifdef _WIN32 +# ifdef _MSC_VER +# ifdef LIBODB_PGSQL_DYNAMIC_LIB +# define LIBODB_PGSQL_EXPORT __declspec(dllexport) +# else +# define LIBODB_PGSQL_EXPORT __declspec(dllimport) +# endif +# else +# ifdef LIBODB_PGSQL_DYNAMIC_LIB +# ifdef DLL_EXPORT +# define LIBODB_PGSQL_EXPORT __declspec(dllexport) +# else +# define LIBODB_PGSQL_EXPORT +# endif +# else +# define LIBODB_PGSQL_EXPORT __declspec(dllimport) +# endif +# endif +# else +# define LIBODB_PGSQL_EXPORT +# endif +#endif + +#endif // LIBODB_PGSQL_BUILD2 + +#include + +#endif // ODB_PGSQL_DETAILS_EXPORT_HXX diff --git a/libodb-pgsql/odb/pgsql/details/options.cli b/libodb-pgsql/odb/pgsql/details/options.cli new file mode 100644 index 0000000..f568236 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/options.cli @@ -0,0 +1,56 @@ +// file : odb/pgsql/details/options.cli +// license : GNU GPL v2; see accompanying LICENSE file + +include ; + +namespace odb +{ + namespace pgsql + { + namespace details + { + class options + { + std::string --user | --username + { + "", + "PostgreSQL database user." + }; + + std::string --password + { + "", + "PostgreSQL database password." + }; + + std::string --database | --dbname + { + "", + "PostgreSQL database name." + }; + + std::string --host + { + "", + "PostgreSQL database host name or address (localhost by default)." + }; + + std::string --port + { + "", + "PostgreSQL database port number or socket file name extension for + Unix-domain connections." + }; + + std::string --options-file + { + "", + "Read additional options from . Each option should appear on a + separate line optionally followed by space or equal sign (\cb{=}) + and an option value. Empty lines and lines starting with \cb{#} are + ignored." + }; + }; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.cxx b/libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.cxx new file mode 100644 index 0000000..a4a5da6 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.cxx @@ -0,0 +1,1114 @@ +// -*- C++ -*- +// +// This file was generated by CLI, a command line interface +// compiler for C++. +// + +// Begin prologue. +// +// +// End prologue. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + namespace details + { + namespace cli + { + // unknown_option + // + unknown_option:: + ~unknown_option () throw () + { + } + + void unknown_option:: + print (::std::ostream& os) const + { + os << "unknown option '" << option ().c_str () << "'"; + } + + const char* unknown_option:: + what () const throw () + { + return "unknown option"; + } + + // unknown_argument + // + unknown_argument:: + ~unknown_argument () throw () + { + } + + void unknown_argument:: + print (::std::ostream& os) const + { + os << "unknown argument '" << argument ().c_str () << "'"; + } + + const char* unknown_argument:: + what () const throw () + { + return "unknown argument"; + } + + // missing_value + // + missing_value:: + ~missing_value () throw () + { + } + + void missing_value:: + print (::std::ostream& os) const + { + os << "missing value for option '" << option ().c_str () << "'"; + } + + const char* missing_value:: + what () const throw () + { + return "missing option value"; + } + + // invalid_value + // + invalid_value:: + ~invalid_value () throw () + { + } + + void invalid_value:: + print (::std::ostream& os) const + { + os << "invalid value '" << value ().c_str () << "' for option '" + << option ().c_str () << "'"; + + if (!message ().empty ()) + os << ": " << message ().c_str (); + } + + const char* invalid_value:: + what () const throw () + { + return "invalid option value"; + } + + // eos_reached + // + void eos_reached:: + print (::std::ostream& os) const + { + os << what (); + } + + const char* eos_reached:: + what () const throw () + { + return "end of argument stream reached"; + } + + // file_io_failure + // + file_io_failure:: + ~file_io_failure () throw () + { + } + + void file_io_failure:: + print (::std::ostream& os) const + { + os << "unable to open file '" << file ().c_str () << "' or read failure"; + } + + const char* file_io_failure:: + what () const throw () + { + return "unable to open file or read failure"; + } + + // unmatched_quote + // + unmatched_quote:: + ~unmatched_quote () throw () + { + } + + void unmatched_quote:: + print (::std::ostream& os) const + { + os << "unmatched quote in argument '" << argument ().c_str () << "'"; + } + + const char* unmatched_quote:: + what () const throw () + { + return "unmatched quote"; + } + + // scanner + // + scanner:: + ~scanner () + { + } + + // argv_scanner + // + bool argv_scanner:: + more () + { + return i_ < argc_; + } + + const char* argv_scanner:: + peek () + { + if (i_ < argc_) + return argv_[i_]; + else + throw eos_reached (); + } + + const char* argv_scanner:: + next () + { + if (i_ < argc_) + { + const char* r (argv_[i_]); + + if (erase_) + { + for (int i (i_ + 1); i < argc_; ++i) + argv_[i - 1] = argv_[i]; + + --argc_; + argv_[argc_] = 0; + } + else + ++i_; + + ++start_position_; + return r; + } + else + throw eos_reached (); + } + + void argv_scanner:: + skip () + { + if (i_ < argc_) + { + ++i_; + ++start_position_; + } + else + throw eos_reached (); + } + + std::size_t argv_scanner:: + position () + { + return start_position_; + } + + // argv_file_scanner + // + int argv_file_scanner::zero_argc_ = 0; + std::string argv_file_scanner::empty_string_; + + bool argv_file_scanner:: + more () + { + if (!args_.empty ()) + return true; + + while (base::more ()) + { + // See if the next argument is the file option. + // + const char* a (base::peek ()); + const option_info* oi = 0; + const char* ov = 0; + + if (!skip_) + { + if ((oi = find (a)) != 0) + { + base::next (); + + if (!base::more ()) + throw missing_value (a); + + ov = base::next (); + } + else if (std::strncmp (a, "-", 1) == 0) + { + if ((ov = std::strchr (a, '=')) != 0) + { + std::string o (a, 0, ov - a); + if ((oi = find (o.c_str ())) != 0) + { + base::next (); + ++ov; + } + } + } + } + + if (oi != 0) + { + if (oi->search_func != 0) + { + std::string f (oi->search_func (ov, oi->arg)); + + if (!f.empty ()) + load (f); + } + else + load (ov); + + if (!args_.empty ()) + return true; + } + else + { + if (!skip_) + skip_ = (std::strcmp (a, "--") == 0); + + return true; + } + } + + return false; + } + + const char* argv_file_scanner:: + peek () + { + if (!more ()) + throw eos_reached (); + + return args_.empty () ? base::peek () : args_.front ().value.c_str (); + } + + const std::string& argv_file_scanner:: + peek_file () + { + if (!more ()) + throw eos_reached (); + + return args_.empty () ? empty_string_ : *args_.front ().file; + } + + std::size_t argv_file_scanner:: + peek_line () + { + if (!more ()) + throw eos_reached (); + + return args_.empty () ? 0 : args_.front ().line; + } + + const char* argv_file_scanner:: + next () + { + if (!more ()) + throw eos_reached (); + + if (args_.empty ()) + return base::next (); + else + { + hold_[i_ == 0 ? ++i_ : --i_].swap (args_.front ().value); + args_.pop_front (); + ++start_position_; + return hold_[i_].c_str (); + } + } + + void argv_file_scanner:: + skip () + { + if (!more ()) + throw eos_reached (); + + if (args_.empty ()) + return base::skip (); + else + { + args_.pop_front (); + ++start_position_; + } + } + + const argv_file_scanner::option_info* argv_file_scanner:: + find (const char* a) const + { + for (std::size_t i (0); i < options_count_; ++i) + if (std::strcmp (a, options_[i].option) == 0) + return &options_[i]; + + return 0; + } + + std::size_t argv_file_scanner:: + position () + { + return start_position_; + } + + void argv_file_scanner:: + load (const std::string& file) + { + using namespace std; + + ifstream is (file.c_str ()); + + if (!is.is_open ()) + throw file_io_failure (file); + + files_.push_back (file); + + arg a; + a.file = &*files_.rbegin (); + + for (a.line = 1; !is.eof (); ++a.line) + { + string line; + getline (is, line); + + if (is.fail () && !is.eof ()) + throw file_io_failure (file); + + string::size_type n (line.size ()); + + // Trim the line from leading and trailing whitespaces. + // + if (n != 0) + { + const char* f (line.c_str ()); + const char* l (f + n); + + const char* of (f); + while (f < l && (*f == ' ' || *f == '\t' || *f == '\r')) + ++f; + + --l; + + const char* ol (l); + while (l > f && (*l == ' ' || *l == '\t' || *l == '\r')) + --l; + + if (f != of || l != ol) + line = f <= l ? string (f, l - f + 1) : string (); + } + + // Ignore empty lines, those that start with #. + // + if (line.empty () || line[0] == '#') + continue; + + string::size_type p (string::npos); + if (line.compare (0, 1, "-") == 0) + { + p = line.find (' '); + + string::size_type q (line.find ('=')); + if (q != string::npos && q < p) + p = q; + } + + string s1; + if (p != string::npos) + { + s1.assign (line, 0, p); + + // Skip leading whitespaces in the argument. + // + if (line[p] == '=') + ++p; + else + { + n = line.size (); + for (++p; p < n; ++p) + { + char c (line[p]); + if (c != ' ' && c != '\t' && c != '\r') + break; + } + } + } + else if (!skip_) + skip_ = (line == "--"); + + string s2 (line, p != string::npos ? p : 0); + + // If the string (which is an option value or argument) is + // wrapped in quotes, remove them. + // + n = s2.size (); + char cf (s2[0]), cl (s2[n - 1]); + + if (cf == '"' || cf == '\'' || cl == '"' || cl == '\'') + { + if (n == 1 || cf != cl) + throw unmatched_quote (s2); + + s2 = string (s2, 1, n - 2); + } + + if (!s1.empty ()) + { + // See if this is another file option. + // + const option_info* oi; + if (!skip_ && (oi = find (s1.c_str ()))) + { + if (s2.empty ()) + throw missing_value (oi->option); + + if (oi->search_func != 0) + { + string f (oi->search_func (s2.c_str (), oi->arg)); + if (!f.empty ()) + load (f); + } + else + { + // If the path of the file being parsed is not simple and the + // path of the file that needs to be loaded is relative, then + // complete the latter using the former as a base. + // +#ifndef _WIN32 + string::size_type p (file.find_last_of ('/')); + bool c (p != string::npos && s2[0] != '/'); +#else + string::size_type p (file.find_last_of ("/\\")); + bool c (p != string::npos && s2[1] != ':'); +#endif + if (c) + s2.insert (0, file, 0, p + 1); + + load (s2); + } + + continue; + } + + a.value = s1; + args_.push_back (a); + } + + a.value = s2; + args_.push_back (a); + } + } + + template + struct parser + { + static void + parse (X& x, bool& xs, scanner& s) + { + using namespace std; + + const char* o (s.next ()); + if (s.more ()) + { + string v (s.next ()); + istringstream is (v); + if (!(is >> x && is.peek () == istringstream::traits_type::eof ())) + throw invalid_value (o, v); + } + else + throw missing_value (o); + + xs = true; + } + }; + + template <> + struct parser + { + static void + parse (bool& x, bool& xs, scanner& s) + { + const char* o (s.next ()); + + if (s.more ()) + { + const char* v (s.next ()); + + if (std::strcmp (v, "1") == 0 || + std::strcmp (v, "true") == 0 || + std::strcmp (v, "TRUE") == 0 || + std::strcmp (v, "True") == 0) + x = true; + else if (std::strcmp (v, "0") == 0 || + std::strcmp (v, "false") == 0 || + std::strcmp (v, "FALSE") == 0 || + std::strcmp (v, "False") == 0) + x = false; + else + throw invalid_value (o, v); + } + else + throw missing_value (o); + + xs = true; + } + }; + + template <> + struct parser + { + static void + parse (std::string& x, bool& xs, scanner& s) + { + const char* o (s.next ()); + + if (s.more ()) + x = s.next (); + else + throw missing_value (o); + + xs = true; + } + }; + + template + struct parser > + { + static void + parse (std::pair& x, bool& xs, scanner& s) + { + x.second = s.position (); + parser::parse (x.first, xs, s); + } + }; + + template + struct parser > + { + static void + parse (std::vector& c, bool& xs, scanner& s) + { + X x; + bool dummy; + parser::parse (x, dummy, s); + c.push_back (x); + xs = true; + } + }; + + template + struct parser > + { + static void + parse (std::set& c, bool& xs, scanner& s) + { + X x; + bool dummy; + parser::parse (x, dummy, s); + c.insert (x); + xs = true; + } + }; + + template + struct parser > + { + static void + parse (std::map& m, bool& xs, scanner& s) + { + const char* o (s.next ()); + + if (s.more ()) + { + std::size_t pos (s.position ()); + std::string ov (s.next ()); + std::string::size_type p = ov.find ('='); + + K k = K (); + V v = V (); + std::string kstr (ov, 0, p); + std::string vstr (ov, (p != std::string::npos ? p + 1 : ov.size ())); + + int ac (2); + char* av[] = + { + const_cast (o), + 0 + }; + + bool dummy; + if (!kstr.empty ()) + { + av[1] = const_cast (kstr.c_str ()); + argv_scanner s (0, ac, av, false, pos); + parser::parse (k, dummy, s); + } + + if (!vstr.empty ()) + { + av[1] = const_cast (vstr.c_str ()); + argv_scanner s (0, ac, av, false, pos); + parser::parse (v, dummy, s); + } + + m[k] = v; + } + else + throw missing_value (o); + + xs = true; + } + }; + + template + struct parser > + { + static void + parse (std::multimap& m, bool& xs, scanner& s) + { + const char* o (s.next ()); + + if (s.more ()) + { + std::size_t pos (s.position ()); + std::string ov (s.next ()); + std::string::size_type p = ov.find ('='); + + K k = K (); + V v = V (); + std::string kstr (ov, 0, p); + std::string vstr (ov, (p != std::string::npos ? p + 1 : ov.size ())); + + int ac (2); + char* av[] = + { + const_cast (o), + 0 + }; + + bool dummy; + if (!kstr.empty ()) + { + av[1] = const_cast (kstr.c_str ()); + argv_scanner s (0, ac, av, false, pos); + parser::parse (k, dummy, s); + } + + if (!vstr.empty ()) + { + av[1] = const_cast (vstr.c_str ()); + argv_scanner s (0, ac, av, false, pos); + parser::parse (v, dummy, s); + } + + m.insert (typename std::multimap::value_type (k, v)); + } + else + throw missing_value (o); + + xs = true; + } + }; + + template + void + thunk (X& x, scanner& s) + { + parser::parse (x.*M, s); + } + + template + void + thunk (X& x, scanner& s) + { + s.next (); + x.*M = true; + } + + template + void + thunk (X& x, scanner& s) + { + parser::parse (x.*M, x.*S, s); + } + } + } + } +} + +#include + +namespace odb +{ + namespace pgsql + { + namespace details + { + // options + // + + options:: + options () + : user_ (), + user_specified_ (false), + password_ (), + password_specified_ (false), + database_ (), + database_specified_ (false), + host_ (), + host_specified_ (false), + port_ (), + port_specified_ (false), + options_file_ (), + options_file_specified_ (false) + { + } + + options:: + options (int& argc, + char** argv, + bool erase, + ::odb::pgsql::details::cli::unknown_mode opt, + ::odb::pgsql::details::cli::unknown_mode arg) + : user_ (), + user_specified_ (false), + password_ (), + password_specified_ (false), + database_ (), + database_specified_ (false), + host_ (), + host_specified_ (false), + port_ (), + port_specified_ (false), + options_file_ (), + options_file_specified_ (false) + { + ::odb::pgsql::details::cli::argv_scanner s (argc, argv, erase); + _parse (s, opt, arg); + } + + options:: + options (int start, + int& argc, + char** argv, + bool erase, + ::odb::pgsql::details::cli::unknown_mode opt, + ::odb::pgsql::details::cli::unknown_mode arg) + : user_ (), + user_specified_ (false), + password_ (), + password_specified_ (false), + database_ (), + database_specified_ (false), + host_ (), + host_specified_ (false), + port_ (), + port_specified_ (false), + options_file_ (), + options_file_specified_ (false) + { + ::odb::pgsql::details::cli::argv_scanner s (start, argc, argv, erase); + _parse (s, opt, arg); + } + + options:: + options (int& argc, + char** argv, + int& end, + bool erase, + ::odb::pgsql::details::cli::unknown_mode opt, + ::odb::pgsql::details::cli::unknown_mode arg) + : user_ (), + user_specified_ (false), + password_ (), + password_specified_ (false), + database_ (), + database_specified_ (false), + host_ (), + host_specified_ (false), + port_ (), + port_specified_ (false), + options_file_ (), + options_file_specified_ (false) + { + ::odb::pgsql::details::cli::argv_scanner s (argc, argv, erase); + _parse (s, opt, arg); + end = s.end (); + } + + options:: + options (int start, + int& argc, + char** argv, + int& end, + bool erase, + ::odb::pgsql::details::cli::unknown_mode opt, + ::odb::pgsql::details::cli::unknown_mode arg) + : user_ (), + user_specified_ (false), + password_ (), + password_specified_ (false), + database_ (), + database_specified_ (false), + host_ (), + host_specified_ (false), + port_ (), + port_specified_ (false), + options_file_ (), + options_file_specified_ (false) + { + ::odb::pgsql::details::cli::argv_scanner s (start, argc, argv, erase); + _parse (s, opt, arg); + end = s.end (); + } + + options:: + options (::odb::pgsql::details::cli::scanner& s, + ::odb::pgsql::details::cli::unknown_mode opt, + ::odb::pgsql::details::cli::unknown_mode arg) + : user_ (), + user_specified_ (false), + password_ (), + password_specified_ (false), + database_ (), + database_specified_ (false), + host_ (), + host_specified_ (false), + port_ (), + port_specified_ (false), + options_file_ (), + options_file_specified_ (false) + { + _parse (s, opt, arg); + } + + ::odb::pgsql::details::cli::usage_para options:: + print_usage (::std::ostream& os, ::odb::pgsql::details::cli::usage_para p) + { + CLI_POTENTIALLY_UNUSED (os); + + if (p != ::odb::pgsql::details::cli::usage_para::none) + os << ::std::endl; + + os << "--user|--username PostgreSQL database user." << ::std::endl; + + os << std::endl + << "--password PostgreSQL database password." << ::std::endl; + + os << std::endl + << "--database|--dbname PostgreSQL database name." << ::std::endl; + + os << std::endl + << "--host PostgreSQL database host name or address (localhost" << ::std::endl + << " by default)." << ::std::endl; + + os << std::endl + << "--port PostgreSQL database port number or socket file name" << ::std::endl + << " extension for Unix-domain connections." << ::std::endl; + + os << std::endl + << "--options-file Read additional options from . Each option" << ::std::endl + << " should appear on a separate line optionally followed" << ::std::endl + << " by space or equal sign (=) and an option value." << ::std::endl + << " Empty lines and lines starting with # are ignored." << ::std::endl; + + p = ::odb::pgsql::details::cli::usage_para::option; + + return p; + } + + typedef + std::map + _cli_options_map; + + static _cli_options_map _cli_options_map_; + + struct _cli_options_map_init + { + _cli_options_map_init () + { + _cli_options_map_["--user"] = + &::odb::pgsql::details::cli::thunk< options, std::string, &options::user_, + &options::user_specified_ >; + _cli_options_map_["--username"] = + &::odb::pgsql::details::cli::thunk< options, std::string, &options::user_, + &options::user_specified_ >; + _cli_options_map_["--password"] = + &::odb::pgsql::details::cli::thunk< options, std::string, &options::password_, + &options::password_specified_ >; + _cli_options_map_["--database"] = + &::odb::pgsql::details::cli::thunk< options, std::string, &options::database_, + &options::database_specified_ >; + _cli_options_map_["--dbname"] = + &::odb::pgsql::details::cli::thunk< options, std::string, &options::database_, + &options::database_specified_ >; + _cli_options_map_["--host"] = + &::odb::pgsql::details::cli::thunk< options, std::string, &options::host_, + &options::host_specified_ >; + _cli_options_map_["--port"] = + &::odb::pgsql::details::cli::thunk< options, std::string, &options::port_, + &options::port_specified_ >; + _cli_options_map_["--options-file"] = + &::odb::pgsql::details::cli::thunk< options, std::string, &options::options_file_, + &options::options_file_specified_ >; + } + }; + + static _cli_options_map_init _cli_options_map_init_; + + bool options:: + _parse (const char* o, ::odb::pgsql::details::cli::scanner& s) + { + _cli_options_map::const_iterator i (_cli_options_map_.find (o)); + + if (i != _cli_options_map_.end ()) + { + (*(i->second)) (*this, s); + return true; + } + + return false; + } + + bool options:: + _parse (::odb::pgsql::details::cli::scanner& s, + ::odb::pgsql::details::cli::unknown_mode opt_mode, + ::odb::pgsql::details::cli::unknown_mode arg_mode) + { + bool r = false; + bool opt = true; + + while (s.more ()) + { + const char* o = s.peek (); + + if (std::strcmp (o, "--") == 0) + { + opt = false; + s.skip (); + r = true; + continue; + } + + if (opt) + { + if (_parse (o, s)) + { + r = true; + continue; + } + + if (std::strncmp (o, "-", 1) == 0 && o[1] != '\0') + { + // Handle combined option values. + // + std::string co; + if (const char* v = std::strchr (o, '=')) + { + co.assign (o, 0, v - o); + ++v; + + int ac (2); + char* av[] = + { + const_cast (co.c_str ()), + const_cast (v) + }; + + ::odb::pgsql::details::cli::argv_scanner ns (0, ac, av); + + if (_parse (co.c_str (), ns)) + { + // Parsed the option but not its value? + // + if (ns.end () != 2) + throw ::odb::pgsql::details::cli::invalid_value (co, v); + + s.next (); + r = true; + continue; + } + else + { + // Set the unknown option and fall through. + // + o = co.c_str (); + } + } + + switch (opt_mode) + { + case ::odb::pgsql::details::cli::unknown_mode::skip: + { + s.skip (); + r = true; + continue; + } + case ::odb::pgsql::details::cli::unknown_mode::stop: + { + break; + } + case ::odb::pgsql::details::cli::unknown_mode::fail: + { + throw ::odb::pgsql::details::cli::unknown_option (o); + } + } + + break; + } + } + + switch (arg_mode) + { + case ::odb::pgsql::details::cli::unknown_mode::skip: + { + s.skip (); + r = true; + continue; + } + case ::odb::pgsql::details::cli::unknown_mode::stop: + { + break; + } + case ::odb::pgsql::details::cli::unknown_mode::fail: + { + throw ::odb::pgsql::details::cli::unknown_argument (o); + } + } + + break; + } + + return r; + } + } + } +} + +// Begin epilogue. +// +// +// End epilogue. + diff --git a/libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.hxx b/libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.hxx new file mode 100644 index 0000000..4d264d4 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.hxx @@ -0,0 +1,562 @@ +// -*- C++ -*- +// +// This file was generated by CLI, a command line interface +// compiler for C++. +// + +#ifndef LIBODB_PGSQL_DETAILS_OPTIONS_HXX +#define LIBODB_PGSQL_DETAILS_OPTIONS_HXX + +// Begin prologue. +// +// +// End prologue. + +#include +#include +#include +#include +#include +#include + +#ifndef CLI_POTENTIALLY_UNUSED +# if defined(_MSC_VER) || defined(__xlC__) +# define CLI_POTENTIALLY_UNUSED(x) (void*)&x +# else +# define CLI_POTENTIALLY_UNUSED(x) (void)x +# endif +#endif + +namespace odb +{ + namespace pgsql + { + namespace details + { + namespace cli + { + class usage_para + { + public: + enum value + { + none, + text, + option + }; + + usage_para (value); + + operator value () const + { + return v_; + } + + private: + value v_; + }; + + class unknown_mode + { + public: + enum value + { + skip, + stop, + fail + }; + + unknown_mode (value); + + operator value () const + { + return v_; + } + + private: + value v_; + }; + + // Exceptions. + // + + class exception: public std::exception + { + public: + virtual void + print (::std::ostream&) const = 0; + }; + + ::std::ostream& + operator<< (::std::ostream&, const exception&); + + class unknown_option: public exception + { + public: + virtual + ~unknown_option () throw (); + + unknown_option (const std::string& option); + + const std::string& + option () const; + + virtual void + print (::std::ostream&) const; + + virtual const char* + what () const throw (); + + private: + std::string option_; + }; + + class unknown_argument: public exception + { + public: + virtual + ~unknown_argument () throw (); + + unknown_argument (const std::string& argument); + + const std::string& + argument () const; + + virtual void + print (::std::ostream&) const; + + virtual const char* + what () const throw (); + + private: + std::string argument_; + }; + + class missing_value: public exception + { + public: + virtual + ~missing_value () throw (); + + missing_value (const std::string& option); + + const std::string& + option () const; + + virtual void + print (::std::ostream&) const; + + virtual const char* + what () const throw (); + + private: + std::string option_; + }; + + class invalid_value: public exception + { + public: + virtual + ~invalid_value () throw (); + + invalid_value (const std::string& option, + const std::string& value, + const std::string& message = std::string ()); + + const std::string& + option () const; + + const std::string& + value () const; + + const std::string& + message () const; + + virtual void + print (::std::ostream&) const; + + virtual const char* + what () const throw (); + + private: + std::string option_; + std::string value_; + std::string message_; + }; + + class eos_reached: public exception + { + public: + virtual void + print (::std::ostream&) const; + + virtual const char* + what () const throw (); + }; + + class file_io_failure: public exception + { + public: + virtual + ~file_io_failure () throw (); + + file_io_failure (const std::string& file); + + const std::string& + file () const; + + virtual void + print (::std::ostream&) const; + + virtual const char* + what () const throw (); + + private: + std::string file_; + }; + + class unmatched_quote: public exception + { + public: + virtual + ~unmatched_quote () throw (); + + unmatched_quote (const std::string& argument); + + const std::string& + argument () const; + + virtual void + print (::std::ostream&) const; + + virtual const char* + what () const throw (); + + private: + std::string argument_; + }; + + // Command line argument scanner interface. + // + // The values returned by next() are guaranteed to be valid + // for the two previous arguments up until a call to a third + // peek() or next(). + // + // The position() function returns a monotonically-increasing + // number which, if stored, can later be used to determine the + // relative position of the argument returned by the following + // call to next(). Note that if multiple scanners are used to + // extract arguments from multiple sources, then the end + // position of the previous scanner should be used as the + // start position of the next. + // + class scanner + { + public: + virtual + ~scanner (); + + virtual bool + more () = 0; + + virtual const char* + peek () = 0; + + virtual const char* + next () = 0; + + virtual void + skip () = 0; + + virtual std::size_t + position () = 0; + }; + + class argv_scanner: public scanner + { + public: + argv_scanner (int& argc, + char** argv, + bool erase = false, + std::size_t start_position = 0); + + argv_scanner (int start, + int& argc, + char** argv, + bool erase = false, + std::size_t start_position = 0); + + int + end () const; + + virtual bool + more (); + + virtual const char* + peek (); + + virtual const char* + next (); + + virtual void + skip (); + + virtual std::size_t + position (); + + protected: + std::size_t start_position_; + int i_; + int& argc_; + char** argv_; + bool erase_; + }; + + class argv_file_scanner: public argv_scanner + { + public: + argv_file_scanner (int& argc, + char** argv, + const std::string& option, + bool erase = false, + std::size_t start_position = 0); + + argv_file_scanner (int start, + int& argc, + char** argv, + const std::string& option, + bool erase = false, + std::size_t start_position = 0); + + argv_file_scanner (const std::string& file, + const std::string& option, + std::size_t start_position = 0); + + struct option_info + { + // If search_func is not NULL, it is called, with the arg + // value as the second argument, to locate the options file. + // If it returns an empty string, then the file is ignored. + // + const char* option; + std::string (*search_func) (const char*, void* arg); + void* arg; + }; + + argv_file_scanner (int& argc, + char** argv, + const option_info* options, + std::size_t options_count, + bool erase = false, + std::size_t start_position = 0); + + argv_file_scanner (int start, + int& argc, + char** argv, + const option_info* options, + std::size_t options_count, + bool erase = false, + std::size_t start_position = 0); + + argv_file_scanner (const std::string& file, + const option_info* options = 0, + std::size_t options_count = 0, + std::size_t start_position = 0); + + virtual bool + more (); + + virtual const char* + peek (); + + virtual const char* + next (); + + virtual void + skip (); + + virtual std::size_t + position (); + + // Return the file path if the peeked at argument came from a file and + // the empty string otherwise. The reference is guaranteed to be valid + // till the end of the scanner lifetime. + // + const std::string& + peek_file (); + + // Return the 1-based line number if the peeked at argument came from + // a file and zero otherwise. + // + std::size_t + peek_line (); + + private: + const option_info* + find (const char*) const; + + void + load (const std::string& file); + + typedef argv_scanner base; + + const std::string option_; + option_info option_info_; + const option_info* options_; + std::size_t options_count_; + + struct arg + { + std::string value; + const std::string* file; + std::size_t line; + }; + + std::deque args_; + std::list files_; + + // Circular buffer of two arguments. + // + std::string hold_[2]; + std::size_t i_; + + bool skip_; + + static int zero_argc_; + static std::string empty_string_; + }; + + template + struct parser; + } + } + } +} + +#include + +namespace odb +{ + namespace pgsql + { + namespace details + { + class options + { + public: + options (); + + options (int& argc, + char** argv, + bool erase = false, + ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, + ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); + + options (int start, + int& argc, + char** argv, + bool erase = false, + ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, + ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); + + options (int& argc, + char** argv, + int& end, + bool erase = false, + ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, + ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); + + options (int start, + int& argc, + char** argv, + int& end, + bool erase = false, + ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, + ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); + + options (::odb::pgsql::details::cli::scanner&, + ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, + ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); + + // Option accessors. + // + const std::string& + user () const; + + bool + user_specified () const; + + const std::string& + password () const; + + bool + password_specified () const; + + const std::string& + database () const; + + bool + database_specified () const; + + const std::string& + host () const; + + bool + host_specified () const; + + const std::string& + port () const; + + bool + port_specified () const; + + const std::string& + options_file () const; + + bool + options_file_specified () const; + + // Print usage information. + // + static ::odb::pgsql::details::cli::usage_para + print_usage (::std::ostream&, + ::odb::pgsql::details::cli::usage_para = ::odb::pgsql::details::cli::usage_para::none); + + // Implementation details. + // + protected: + bool + _parse (const char*, ::odb::pgsql::details::cli::scanner&); + + private: + bool + _parse (::odb::pgsql::details::cli::scanner&, + ::odb::pgsql::details::cli::unknown_mode option, + ::odb::pgsql::details::cli::unknown_mode argument); + + public: + std::string user_; + bool user_specified_; + std::string password_; + bool password_specified_; + std::string database_; + bool database_specified_; + std::string host_; + bool host_specified_; + std::string port_; + bool port_specified_; + std::string options_file_; + bool options_file_specified_; + }; + } + } +} + +#include + +// Begin epilogue. +// +// +// End epilogue. + +#endif // LIBODB_PGSQL_DETAILS_OPTIONS_HXX diff --git a/libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.ixx b/libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.ixx new file mode 100644 index 0000000..340789e --- /dev/null +++ b/libodb-pgsql/odb/pgsql/details/pregenerated/odb/pgsql/details/options.ixx @@ -0,0 +1,372 @@ +// -*- C++ -*- +// +// This file was generated by CLI, a command line interface +// compiler for C++. +// + +// Begin prologue. +// +// +// End prologue. + +#include + +namespace odb +{ + namespace pgsql + { + namespace details + { + namespace cli + { + // usage_para + // + inline usage_para:: + usage_para (value v) + : v_ (v) + { + } + + // unknown_mode + // + inline unknown_mode:: + unknown_mode (value v) + : v_ (v) + { + } + + // exception + // + inline ::std::ostream& + operator<< (::std::ostream& os, const exception& e) + { + e.print (os); + return os; + } + + // unknown_option + // + inline unknown_option:: + unknown_option (const std::string& option) + : option_ (option) + { + } + + inline const std::string& unknown_option:: + option () const + { + return option_; + } + + // unknown_argument + // + inline unknown_argument:: + unknown_argument (const std::string& argument) + : argument_ (argument) + { + } + + inline const std::string& unknown_argument:: + argument () const + { + return argument_; + } + + // missing_value + // + inline missing_value:: + missing_value (const std::string& option) + : option_ (option) + { + } + + inline const std::string& missing_value:: + option () const + { + return option_; + } + + // invalid_value + // + inline invalid_value:: + invalid_value (const std::string& option, + const std::string& value, + const std::string& message) + : option_ (option), + value_ (value), + message_ (message) + { + } + + inline const std::string& invalid_value:: + option () const + { + return option_; + } + + inline const std::string& invalid_value:: + value () const + { + return value_; + } + + inline const std::string& invalid_value:: + message () const + { + return message_; + } + + // file_io_failure + // + inline file_io_failure:: + file_io_failure (const std::string& file) + : file_ (file) + { + } + + inline const std::string& file_io_failure:: + file () const + { + return file_; + } + + // unmatched_quote + // + inline unmatched_quote:: + unmatched_quote (const std::string& argument) + : argument_ (argument) + { + } + + inline const std::string& unmatched_quote:: + argument () const + { + return argument_; + } + + // argv_scanner + // + inline argv_scanner:: + argv_scanner (int& argc, + char** argv, + bool erase, + std::size_t sp) + : start_position_ (sp + 1), + i_ (1), + argc_ (argc), + argv_ (argv), + erase_ (erase) + { + } + + inline argv_scanner:: + argv_scanner (int start, + int& argc, + char** argv, + bool erase, + std::size_t sp) + : start_position_ (sp + static_cast (start)), + i_ (start), + argc_ (argc), + argv_ (argv), + erase_ (erase) + { + } + + inline int argv_scanner:: + end () const + { + return i_; + } + + // argv_file_scanner + // + inline argv_file_scanner:: + argv_file_scanner (int& argc, + char** argv, + const std::string& option, + bool erase, + std::size_t sp) + : argv_scanner (argc, argv, erase, sp), + option_ (option), + options_ (&option_info_), + options_count_ (1), + i_ (1), + skip_ (false) + { + option_info_.option = option_.c_str (); + option_info_.search_func = 0; + } + + inline argv_file_scanner:: + argv_file_scanner (int start, + int& argc, + char** argv, + const std::string& option, + bool erase, + std::size_t sp) + : argv_scanner (start, argc, argv, erase, sp), + option_ (option), + options_ (&option_info_), + options_count_ (1), + i_ (1), + skip_ (false) + { + option_info_.option = option_.c_str (); + option_info_.search_func = 0; + } + + inline argv_file_scanner:: + argv_file_scanner (const std::string& file, + const std::string& option, + std::size_t sp) + : argv_scanner (0, zero_argc_, 0, sp), + option_ (option), + options_ (&option_info_), + options_count_ (1), + i_ (1), + skip_ (false) + { + option_info_.option = option_.c_str (); + option_info_.search_func = 0; + + load (file); + } + + inline argv_file_scanner:: + argv_file_scanner (int& argc, + char** argv, + const option_info* options, + std::size_t options_count, + bool erase, + std::size_t sp) + : argv_scanner (argc, argv, erase, sp), + options_ (options), + options_count_ (options_count), + i_ (1), + skip_ (false) + { + } + + inline argv_file_scanner:: + argv_file_scanner (int start, + int& argc, + char** argv, + const option_info* options, + std::size_t options_count, + bool erase, + std::size_t sp) + : argv_scanner (start, argc, argv, erase, sp), + options_ (options), + options_count_ (options_count), + i_ (1), + skip_ (false) + { + } + + inline argv_file_scanner:: + argv_file_scanner (const std::string& file, + const option_info* options, + std::size_t options_count, + std::size_t sp) + : argv_scanner (0, zero_argc_, 0, sp), + options_ (options), + options_count_ (options_count), + i_ (1), + skip_ (false) + { + load (file); + } + } + } + } +} + +namespace odb +{ + namespace pgsql + { + namespace details + { + // options + // + + inline const std::string& options:: + user () const + { + return this->user_; + } + + inline bool options:: + user_specified () const + { + return this->user_specified_; + } + + inline const std::string& options:: + password () const + { + return this->password_; + } + + inline bool options:: + password_specified () const + { + return this->password_specified_; + } + + inline const std::string& options:: + database () const + { + return this->database_; + } + + inline bool options:: + database_specified () const + { + return this->database_specified_; + } + + inline const std::string& options:: + host () const + { + return this->host_; + } + + inline bool options:: + host_specified () const + { + return this->host_specified_; + } + + inline const std::string& options:: + port () const + { + return this->port_; + } + + inline bool options:: + port_specified () const + { + return this->port_specified_; + } + + inline const std::string& options:: + options_file () const + { + return this->options_file_; + } + + inline bool options:: + options_file_specified () const + { + return this->options_file_specified_; + } + } + } +} + +// Begin epilogue. +// +// +// End epilogue. diff --git a/libodb-pgsql/odb/pgsql/error.cxx b/libodb-pgsql/odb/pgsql/error.cxx new file mode 100644 index 0000000..ba8451e --- /dev/null +++ b/libodb-pgsql/odb/pgsql/error.cxx @@ -0,0 +1,86 @@ +// file : odb/pgsql/error.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include +#include + +#include +#include +#include + +using namespace std; + +namespace odb +{ + namespace pgsql + { + void + translate_error (connection& c, PGresult* r, + size_t pos, multiple_exceptions* mex) + { + if (!r) + { + if (PQstatus (c.handle ()) == CONNECTION_BAD) + { + c.mark_failed (); + throw connection_lost (); + } + else + throw bad_alloc (); + } + + // Note that we expect the caller to handle PGRES_PIPELINE_ABORTED since + // it's not really an error but rather an indication that no attempt was + // made to execute this statement. + // + string ss; + switch (PQresultStatus (r)) + { + case PGRES_BAD_RESPONSE: + { + throw database_exception ("bad server response"); + } + case PGRES_FATAL_ERROR: + { + const char* s (PQresultErrorField (r, PG_DIAG_SQLSTATE)); + ss = (s != 0 ? s : "?????"); + + // Deadlock detected. + // + if (ss == "40001" || ss == "40P01") + throw deadlock (); + else if (PQstatus (c.handle ()) == CONNECTION_BAD) + { + c.mark_failed (); + throw connection_lost (); + } + break; + } + default: + assert (false); + break; + } + + string msg; + { + // Can be NULL in case of PGRES_BAD_RESPONSE. + // + const char* m (PQresultErrorMessage (r)); + msg = (m != 0 ? m : "bad server response"); + + // Get rid of the trailing newline if there is one. + // + string::size_type n (msg.size ()); + if (n != 0 && msg[n - 1] == '\n') + msg.resize (n - 1); + } + + if (mex == 0) + throw database_exception (ss, msg); + else + // In PosgreSQL all errors are fatal. + // + mex->insert (pos, database_exception (ss, msg), true); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/error.hxx b/libodb-pgsql/odb/pgsql/error.hxx new file mode 100644 index 0000000..8d2793d --- /dev/null +++ b/libodb-pgsql/odb/pgsql/error.hxx @@ -0,0 +1,41 @@ +// file : odb/pgsql/error.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_ERROR_HXX +#define ODB_PGSQL_ERROR_HXX + +#include + +#include + +#include +#include // connection, multiple_exceptions +#include + +namespace odb +{ + namespace pgsql + { + // Translate an error condition involving PGresult* and throw (or return, + // in case multiple_exceptions is not NULL) an appropriate exception. If + // result is NULL, it is assumed that the error was caused due to a bad + // connection or a memory allocation error. + // + LIBODB_PGSQL_EXPORT void + translate_error (connection& c, PGresult* r, + std::size_t pos = 0, multiple_exceptions* = 0); + + // Return true if PGresult is not NULL and is not in an error state. If + // both s and r are non-NULL, the pointed to value will be populated with + // the result status. Otherwise, s is ignored. + // + LIBODB_PGSQL_EXPORT bool + is_good_result (PGresult* r, ExecStatusType* s = 0); + } +} + +#include + +#include + +#endif // ODB_PGSQL_ERROR_HXX diff --git a/libodb-pgsql/odb/pgsql/error.ixx b/libodb-pgsql/odb/pgsql/error.ixx new file mode 100644 index 0000000..6a010aa --- /dev/null +++ b/libodb-pgsql/odb/pgsql/error.ixx @@ -0,0 +1,31 @@ +// file : odb/pgsql/error.ixx +// license : GNU GPL v2; see accompanying LICENSE file + +namespace odb +{ + namespace pgsql + { + inline bool + is_good_result (PGresult* r, ExecStatusType* s) + { + if (r != 0) + { + ExecStatusType status (PQresultStatus (r)); + + if (s != 0) + *s = status; + + return + status != PGRES_BAD_RESPONSE + && status != PGRES_NONFATAL_ERROR + && status != PGRES_FATAL_ERROR +#ifdef LIBPQ_HAS_PIPELINING + && status != PGRES_PIPELINE_ABORTED +#endif + ; + } + + return false; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/exceptions.cxx b/libodb-pgsql/odb/pgsql/exceptions.cxx new file mode 100644 index 0000000..28e7fc4 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/exceptions.cxx @@ -0,0 +1,79 @@ +// file : odb/pgsql/exceptions.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include + +using namespace std; + +namespace odb +{ + namespace pgsql + { + // + // database_exception + // + + database_exception:: + database_exception (const string& message) + : message_ (message), what_ (message) + { + } + + database_exception:: + database_exception (const string& sqlstate, + const string& message) + : sqlstate_ (sqlstate), message_ (message) + { + if (!sqlstate_.empty ()) + what_ = sqlstate_ + ": " + message_; + else + what_ = message_; + } + + database_exception:: + ~database_exception () ODB_NOTHROW_NOEXCEPT + { + } + + const char* database_exception:: + what () const ODB_NOTHROW_NOEXCEPT + { + return what_.c_str (); + } + + database_exception* database_exception:: + clone () const + { + return new database_exception (*this); + } + + // + // cli_exception + // + + cli_exception:: + cli_exception (const string& what) + : what_ (what) + { + } + + cli_exception:: + ~cli_exception () ODB_NOTHROW_NOEXCEPT + { + } + + const char* cli_exception:: + what () const ODB_NOTHROW_NOEXCEPT + { + return what_.c_str (); + } + + cli_exception* cli_exception:: + clone () const + { + return new cli_exception (*this); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/exceptions.hxx b/libodb-pgsql/odb/pgsql/exceptions.hxx new file mode 100644 index 0000000..8417c1a --- /dev/null +++ b/libodb-pgsql/odb/pgsql/exceptions.hxx @@ -0,0 +1,80 @@ +// file : odb/pgsql/exceptions.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_EXCEPTIONS_HXX +#define ODB_PGSQL_EXCEPTIONS_HXX + +#include + +#include + +#include +#include // ODB_NOTHROW_NOEXCEPT + +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + struct LIBODB_PGSQL_EXPORT database_exception: odb::database_exception + { + database_exception (const std::string& message); + + database_exception (const std::string& sqlstate, + const std::string& message); + + ~database_exception () ODB_NOTHROW_NOEXCEPT; + + const std::string& + message () const + { + return message_; + } + + const std::string& + sqlstate () const + { + return sqlstate_; + } + + virtual const char* + what () const ODB_NOTHROW_NOEXCEPT; + + virtual database_exception* + clone () const; + + private: + std::string sqlstate_; + std::string message_; + std::string what_; + }; + + struct LIBODB_PGSQL_EXPORT cli_exception: odb::exception + { + cli_exception (const std::string& what); + ~cli_exception () ODB_NOTHROW_NOEXCEPT; + + virtual const char* + what () const ODB_NOTHROW_NOEXCEPT; + + virtual cli_exception* + clone () const; + + private: + std::string what_; + }; + + namespace core + { + using pgsql::database_exception; + using pgsql::cli_exception; + } + } +} + +#include + +#endif // ODB_PGSQL_EXCEPTIONS_HXX diff --git a/libodb-pgsql/odb/pgsql/forward.hxx b/libodb-pgsql/odb/pgsql/forward.hxx new file mode 100644 index 0000000..1186b28 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/forward.hxx @@ -0,0 +1,91 @@ +// file : odb/pgsql/forward.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_FORWARD_HXX +#define ODB_PGSQL_FORWARD_HXX + +#include + +#include + +namespace odb +{ + namespace pgsql + { + namespace core + { + using namespace odb::common; + } + + // + // + class database; + class connection; + typedef details::shared_ptr connection_ptr; + class connection_factory; + class statement; + class transaction; + class tracer; + + namespace core + { + using pgsql::database; + using pgsql::connection; + using pgsql::connection_ptr; + using pgsql::transaction; + using pgsql::statement; + } + + // Implementation details. + // + enum statement_kind + { + statement_select, + statement_insert, + statement_update, + statement_delete + }; + + class binding; + class select_statement; + + template + class object_statements; + + template + class polymorphic_root_object_statements; + + template + class polymorphic_derived_object_statements; + + template + class no_id_object_statements; + + template + class view_statements; + + template + class container_statements; + + template + class smart_container_statements; + + template + class section_statements; + + class query_base; + } + + namespace details + { + template <> + struct counter_type + { + typedef shared_base counter; + }; + } +} + +#include + +#endif // ODB_PGSQL_FORWARD_HXX diff --git a/libodb-pgsql/odb/pgsql/no-id-object-result.hxx b/libodb-pgsql/odb/pgsql/no-id-object-result.hxx new file mode 100644 index 0000000..734d4a7 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/no-id-object-result.hxx @@ -0,0 +1,77 @@ +// file : odb/pgsql/no-id-object-result.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_NO_ID_OBJECT_RESULT_HXX +#define ODB_PGSQL_NO_ID_OBJECT_RESULT_HXX + +#include + +#include // std::size_t + +#include +#include + +#include + +#include +#include // query_base +#include +#include + +namespace odb +{ + namespace pgsql + { + template + class no_id_object_result_impl: public odb::no_id_object_result_impl + { + public: + typedef odb::no_id_object_result_impl base_type; + + typedef typename base_type::object_type object_type; + typedef typename base_type::pointer_type pointer_type; + + typedef object_traits_impl object_traits; + typedef typename base_type::pointer_traits pointer_traits; + + typedef typename object_traits::statements_type statements_type; + + virtual + ~no_id_object_result_impl (); + + no_id_object_result_impl (const query_base&, + details::shared_ptr, + statements_type&, + const schema_version_migration*); + + virtual void + load (object_type&); + + virtual void + next (); + + virtual void + cache (); + + virtual std::size_t + size (); + + virtual void + invalidate (); + + using base_type::current; + + private: + details::shared_ptr statement_; + statements_type& statements_; + object_traits_calls tc_; + std::size_t count_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_NO_ID_OBJECT_RESULT_HXX diff --git a/libodb-pgsql/odb/pgsql/no-id-object-result.txx b/libodb-pgsql/odb/pgsql/no-id-object-result.txx new file mode 100644 index 0000000..0bae952 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/no-id-object-result.txx @@ -0,0 +1,114 @@ +// file : odb/pgsql/no-id-object-result.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include + +namespace odb +{ + namespace pgsql + { + template + no_id_object_result_impl:: + ~no_id_object_result_impl () + { + if (!this->end_) + statement_->free_result (); + } + + template + void no_id_object_result_impl:: + invalidate () + { + if (!this->end_) + { + statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); + } + + template + no_id_object_result_impl:: + no_id_object_result_impl (const query_base&, + details::shared_ptr statement, + statements_type& statements, + const schema_version_migration* svm) + : base_type (statements.connection ()), + statement_ (statement), + statements_ (statements), + tc_ (svm), + count_ (0) + { + } + + template + void no_id_object_result_impl:: + load (object_type& obj) + { + // The image can grow between calls to load() as a result of other + // statements execution. + // + typename object_traits::image_type& im (statements_.image ()); + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + tc_.bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + } + + select_statement::result r (statement_->load ()); + + if (r == select_statement::truncated) + { + if (tc_.grow (im, statements_.select_image_truncated ())) + im.version++; + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + tc_.bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + statement_->reload (); + } + } + + object_traits::callback (this->db_, obj, callback_event::pre_load); + tc_.init (obj, im, &this->db_); + object_traits::callback (this->db_, obj, callback_event::post_load); + } + + template + void no_id_object_result_impl:: + next () + { + this->current (pointer_type ()); + + if (statement_->next ()) + count_++; + else + { + statement_->free_result (); + this->end_ = true; + } + } + + template + void no_id_object_result_impl:: + cache () + { + } + + template + std::size_t no_id_object_result_impl:: + size () + { + return this->end_ ? count_ : statement_->result_size (); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/no-id-object-statements.hxx b/libodb-pgsql/odb/pgsql/no-id-object-statements.hxx new file mode 100644 index 0000000..baa1b2a --- /dev/null +++ b/libodb-pgsql/odb/pgsql/no-id-object-statements.hxx @@ -0,0 +1,147 @@ +// file : odb/pgsql/no-id-object-statements.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_NO_ID_OBJECT_STATEMENTS_HXX +#define ODB_PGSQL_NO_ID_OBJECT_STATEMENTS_HXX + +#include + +#include // std::size_t + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + // + // Implementation for objects without object id. + // + + template + class no_id_object_statements: public statements_base + { + public: + typedef T object_type; + typedef object_traits_impl object_traits; + typedef typename object_traits::pointer_type pointer_type; + typedef typename object_traits::image_type image_type; + + typedef pgsql::insert_statement insert_statement_type; + + public: + no_id_object_statements (connection_type&); + + virtual + ~no_id_object_statements (); + + // Object image. + // + image_type& + image (std::size_t i = 0) + { + return image_[i]; + } + + // Insert binding. + // + std::size_t + insert_image_version () const { return insert_image_version_;} + + void + insert_image_version (std::size_t v) {insert_image_version_ = v;} + + binding& + insert_image_binding () {return insert_image_binding_;} + + // Select binding (needed for query support). + // + std::size_t + select_image_version () const { return select_image_version_;} + + void + select_image_version (std::size_t v) {select_image_version_ = v;} + + binding& + select_image_binding () {return select_image_binding_;} + + bool* + select_image_truncated () {return select_image_truncated_;} + + // Statements. + // + insert_statement_type& + persist_statement () + { + if (persist_ == 0) + persist_.reset ( + new (details::shared) insert_statement_type ( + conn_, + object_traits::persist_statement_name, + object_traits::persist_statement, + object_traits::versioned, // Process if versioned. + object_traits::persist_statement_types, + insert_column_count, + insert_image_binding_, + insert_image_native_binding_, + 0, + false)); + + return *persist_; + } + + public: + // select = total + // insert = total - inverse; inverse == 0 for object without id + // + static const std::size_t insert_column_count = + object_traits::column_count; + + static const std::size_t select_column_count = + object_traits::column_count; + + private: + no_id_object_statements (const no_id_object_statements&); + no_id_object_statements& operator= (const no_id_object_statements&); + + private: + image_type image_[object_traits::batch]; + unsigned long long status_[object_traits::batch]; + + // Select binding. + // + std::size_t select_image_version_; + binding select_image_binding_; + bind select_image_bind_[select_column_count]; + bool select_image_truncated_[select_column_count]; + + // Insert binding. + // + std::size_t insert_image_version_; + binding insert_image_binding_; + bind insert_image_bind_[insert_column_count]; + native_binding insert_image_native_binding_; + char* insert_image_values_[insert_column_count]; + int insert_image_lengths_[insert_column_count]; + int insert_image_formats_[insert_column_count]; + + details::shared_ptr persist_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_NO_ID_OBJECT_STATEMENTS_HXX diff --git a/libodb-pgsql/odb/pgsql/no-id-object-statements.txx b/libodb-pgsql/odb/pgsql/no-id-object-statements.txx new file mode 100644 index 0000000..0c340ab --- /dev/null +++ b/libodb-pgsql/odb/pgsql/no-id-object-statements.txx @@ -0,0 +1,50 @@ +// file : odb/pgsql/no-id-object-statements.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::memset + +namespace odb +{ + namespace pgsql + { + // + // no_id_object_statements + // + + template + no_id_object_statements:: + ~no_id_object_statements () + { + } + + template + no_id_object_statements:: + no_id_object_statements (connection_type& conn) + : statements_base (conn), + // select + select_image_binding_ (select_image_bind_, select_column_count), + // insert + insert_image_binding_ (insert_image_bind_, + insert_column_count, + object_traits::batch, + sizeof (image_type), + status_), + insert_image_native_binding_ (insert_image_values_, + insert_image_lengths_, + insert_image_formats_, + insert_column_count) + { + image_[0].version = 0; // Only version in the first element used. + select_image_version_ = 0; + insert_image_version_ = 0; + + std::memset (insert_image_bind_, 0, sizeof (insert_image_bind_)); + std::memset (select_image_bind_, 0, sizeof (select_image_bind_)); + std::memset ( + select_image_truncated_, 0, sizeof (select_image_truncated_)); + + for (std::size_t i (0); i < select_column_count; ++i) + select_image_bind_[i].truncated = select_image_truncated_ + i; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/pgsql-fwd.hxx b/libodb-pgsql/odb/pgsql/pgsql-fwd.hxx new file mode 100644 index 0000000..e60bc37 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/pgsql-fwd.hxx @@ -0,0 +1,19 @@ +// file : odb/pgsql/pgsql-fwd.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_PGSQL_FWD_HXX +#define ODB_PGSQL_PGSQL_FWD_HXX + +#include + +// Forward declaration for some of the types defined in libpq-fe.h. This +// allows us to avoid having to include libpq-fe.h in public headers. +// +typedef unsigned int Oid; + +typedef struct pg_conn PGconn; +typedef struct pg_result PGresult; + +#include + +#endif // ODB_PGSQL_PGSQL_FWD_HXX diff --git a/libodb-pgsql/odb/pgsql/pgsql-oid.hxx b/libodb-pgsql/odb/pgsql/pgsql-oid.hxx new file mode 100644 index 0000000..e2ef1af --- /dev/null +++ b/libodb-pgsql/odb/pgsql/pgsql-oid.hxx @@ -0,0 +1,47 @@ +// file : odb/pgsql/pgsql-oid.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Generated file of OIDs extracted from the PostgreSQL 8.4.8 source file +// src/include/catalog/pg_type.h +// + +#ifndef ODB_PGSQL_PGSQL_OID_HXX +#define ODB_PGSQL_PGSQL_OID_HXX + +#include + +#include + +namespace odb +{ + namespace pgsql + { + enum + { + bool_oid = 16, + int2_oid = 21, + int4_oid = 23, + int8_oid = 20, + + numeric_oid = 1700, + + float4_oid = 700, + float8_oid = 701, + + date_oid = 1082, + time_oid = 1083, + timestamp_oid = 1114, + + text_oid = 25, + bytea_oid = 17, + bit_oid = 1560, + varbit_oid = 1562, + + uuid_oid = 2950 + }; + } +} + +#include + +#endif // ODB_PGSQL_PGSQL_OID_HXX diff --git a/libodb-pgsql/odb/pgsql/pgsql-types.hxx b/libodb-pgsql/odb/pgsql/pgsql-types.hxx new file mode 100644 index 0000000..117a41e --- /dev/null +++ b/libodb-pgsql/odb/pgsql/pgsql-types.hxx @@ -0,0 +1,59 @@ +// file : odb/pgsql/pgsql-types.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_PGSQL_TYPES_HXX +#define ODB_PGSQL_PGSQL_TYPES_HXX + +#include + +#include // std::size_t + +#include // Oid + +namespace odb +{ + namespace pgsql + { + // The libpq result binding. This data structures is roughly modeled + // after MYSQL_BIND from MySQL. + // + // Types that may need to grow are bound as pointers to pointers to char + // array (normally in details::buffer) in order to allow simple offsetting + // in bulk operation support. Note that if we were to do the same for + // capacity, we could get rid of the buffer growth tracking altogether. + // + struct bind + { + enum buffer_type + { + boolean_, // Buffer is a bool; size, capacity, truncated are unused. + smallint, // Buffer is short; size, capacity, truncated are unused. + integer, // Buffer is int; size, capacity, truncated are unused. + bigint, // Buffer is long long; size, capacity, truncated are unused. + real, // Buffer is float; size, capacity, truncated are unused. + double_, // Buffer is double; size, capacity, truncated are unused. + numeric, // Buffer is a pointer to pointer to char array. + date, // Buffer is int; size, capacity, truncated are unused. + time, // Buffer is long long; size, capacity, truncated are unused. + timestamp,// Buffer is long long; size, capacity, truncated are unused. + text, // Buffer is a pointer to pointer to char array. + bytea, // Buffer is a pointer to pointer to char array. + bit, // Buffer is a pointer to char array. + varbit, // Buffer is a pointer to pointer to char array. + uuid // Buffer is a 16-byte char array; size capacity, truncated + // are unused. Note: big-endian, in RFC 4122/4.1.2 order. + }; + + buffer_type type; + void* buffer; + std::size_t* size; + std::size_t capacity; + bool* is_null; + bool* truncated; + }; + } +} + +#include + +#endif // ODB_PGSQL_PGSQL_TYPES_HXX diff --git a/libodb-pgsql/odb/pgsql/polymorphic-object-result.hxx b/libodb-pgsql/odb/pgsql/polymorphic-object-result.hxx new file mode 100644 index 0000000..a1cd108 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/polymorphic-object-result.hxx @@ -0,0 +1,94 @@ +// file : odb/pgsql/polymorphic-object-result.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_POLYMORPHIC_OBJECT_RESULT_HXX +#define ODB_PGSQL_POLYMORPHIC_OBJECT_RESULT_HXX + +#include + +#include // std::size_t + +#include +#include + +#include + +#include +#include // query_base +#include +#include + +namespace odb +{ + namespace pgsql + { + template + class polymorphic_object_result_impl: + public odb::polymorphic_object_result_impl + { + public: + typedef odb::polymorphic_object_result_impl base_type; + + typedef typename base_type::id_type id_type; + typedef typename base_type::object_type object_type; + typedef typename base_type::pointer_type pointer_type; + + typedef object_traits_impl object_traits; + typedef typename base_type::pointer_traits pointer_traits; + + typedef typename base_type::root_type root_type; + typedef typename base_type::discriminator_type discriminator_type; + + typedef object_traits_impl root_traits; + + typedef typename object_traits::statements_type statements_type; + + virtual + ~polymorphic_object_result_impl (); + + polymorphic_object_result_impl (const query_base&, + details::shared_ptr, + statements_type&, + const schema_version_migration*); + + virtual void + load (object_type*, bool fetch); + + virtual id_type + load_id (); + + virtual discriminator_type + load_discriminator (); + + virtual void + next (); + + virtual void + cache (); + + virtual std::size_t + size (); + + virtual void + invalidate (); + + using base_type::current; + + private: + void + load_image (); + + private: + details::shared_ptr statement_; + statements_type& statements_; + object_traits_calls tc_; + std::size_t count_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_POLYMORPHIC_OBJECT_RESULT_HXX diff --git a/libodb-pgsql/odb/pgsql/polymorphic-object-result.txx b/libodb-pgsql/odb/pgsql/polymorphic-object-result.txx new file mode 100644 index 0000000..bad2091 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/polymorphic-object-result.txx @@ -0,0 +1,287 @@ +// file : odb/pgsql/polymorphic-object-result.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include +#include // object_not_persistent + +#include + +namespace odb +{ + namespace pgsql + { + template + polymorphic_object_result_impl:: + ~polymorphic_object_result_impl () + { + if (!this->end_) + statement_->free_result (); + } + + template + void polymorphic_object_result_impl:: + invalidate () + { + if (!this->end_) + { + statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); + } + + template + polymorphic_object_result_impl:: + polymorphic_object_result_impl (const query_base&, + details::shared_ptr st, + statements_type& sts, + const schema_version_migration* svm) + : base_type (sts.connection ()), + statement_ (st), + statements_ (sts), + tc_ (svm), + count_ (0) + { + } + + template + void polymorphic_object_result_impl:: + load (object_type* pobj, bool fetch) + { + if (fetch) + load_image (); + + typename statements_type::root_statements_type& rsts ( + statements_.root_statements ()); + + // This is a top-level call so the statements cannot be locked. + // + assert (!rsts.locked ()); + typename statements_type::auto_lock l (rsts); + + typename object_traits::image_type& i (statements_.image ()); + typename root_traits::image_type& ri (rsts.image ()); + + id_type id (root_traits::id (ri)); + + // Determine this object's dynamic type. + // + typedef typename root_traits::info_type info_type; + discriminator_type d (root_traits::discriminator (ri)); + discriminator_type disc (d); + + // Use the polymorphic_info() helper to get concrete_info if + // object_type is concrete and NULL if it is abstract. + // + const info_type* spi (polymorphic_info (object_traits::info)); + const info_type& pi ( + spi != 0 && spi->discriminator == d + ? *spi + : root_traits::map->find (d)); + + typedef typename root_traits::pointer_type root_pointer_type; + typedef typename root_traits::pointer_traits root_pointer_traits; + + typename object_traits::pointer_cache_traits::insert_guard ig; + + if (pobj == 0) + { + // Need to create a new instance of the dynamic type. + // + root_pointer_type rp (pi.create ()); + pointer_type p ( + root_pointer_traits::template static_pointer_cast (rp)); + + // Insert it as a root pointer (for non-unique pointers, rp should + // still be valid and for unique pointers this is a no-op). + // + ig.reset ( + object_traits::pointer_cache_traits::insert (this->db_, id, rp)); + + pobj = &pointer_traits::get_ref (p); + current (p); + } + else + { + // We are loading into an existing instance. If the static and + // dynamic types differ, then make sure the instance is at least + // of the dynamic type. + // + if (&pi != &object_traits::info) + { + const info_type& dpi (root_traits::map->find (typeid (*pobj))); + + if (&dpi != &pi && dpi.derived (pi)) + throw object_not_persistent (); // @@ type_mismatch ? + } + } + + callback_event ce (callback_event::pre_load); + pi.dispatch (info_type::call_callback, this->db_, pobj, &ce); + + tc_.init (*pobj, i, &this->db_); + + // Initialize the id image and binding and load the rest of the object + // (containers, dynamic part, etc). + // + typename object_traits::id_image_type& idi (statements_.id_image ()); + root_traits::init (idi, id); + + binding& idb (statements_.id_image_binding ()); + if (idi.version != statements_.id_image_version () || idb.version == 0) + { + object_traits::bind (idb.bind, idi); + statements_.id_image_version (idi.version); + idb.version++; + } + + tc_.load_ (statements_, *pobj, false); + + // Load the dynamic part of the object unless static and dynamic + // types are the same. + // + if (&pi != &object_traits::info) + { + std::size_t d (object_traits::depth); + pi.dispatch (info_type::call_load, this->db_, pobj, &d); + }; + + rsts.load_delayed (tc_.version ()); + l.unlock (); + + ce = callback_event::post_load; + pi.dispatch (info_type::call_callback, this->db_, pobj, &ce); + object_traits::pointer_cache_traits::load (ig.position ()); + ig.release (); + } + + template + typename polymorphic_object_result_impl::id_type + polymorphic_object_result_impl:: + load_id () + { + load_image (); + return root_traits::id (statements_.root_statements ().image ()); + } + + template + typename polymorphic_object_result_impl::discriminator_type + polymorphic_object_result_impl:: + load_discriminator () + { + load_image (); + return root_traits::discriminator ( + statements_.root_statements ().image ()); + } + + template + void polymorphic_object_result_impl:: + next () + { + this->current (pointer_type ()); + + if (statement_->next ()) + count_++; + else + { + statement_->free_result (); + this->end_ = true; + } + } + + template + struct polymorphic_image_rebind + { + // Derived type version. + // + typedef object_traits_impl traits; + + static bool + rebind (typename traits::statements_type& sts, + const schema_version_migration* svm) + { + typename traits::image_type& im (sts.image ()); + + if (traits::check_version (sts.select_image_versions (), im)) + { + binding& b (sts.select_image_binding (traits::depth)); + object_traits_calls tc (svm); + tc.bind (b.bind, 0, 0, im, statement_select); + traits::update_version ( + sts.select_image_versions (), im, sts.select_image_bindings ()); + return true; + } + + return false; + } + }; + + template + struct polymorphic_image_rebind + { + // Root type version. + // + typedef object_traits_impl traits; + + static bool + rebind (typename traits::statements_type& sts, + const schema_version_migration* svm) + { + typename traits::image_type& im (sts.image ()); + + if (im.version != sts.select_image_version ()) + { + binding& b (sts.select_image_binding ()); + object_traits_calls tc (svm); + tc.bind (b.bind, im, statement_select); + sts.select_image_version (im.version); + b.version++; + return true; + } + + return false; + } + }; + + template + void polymorphic_object_result_impl:: + load_image () + { + typedef polymorphic_image_rebind image_rebind; + + // The image can grow between calls to load() as a result of other + // statements execution. + // + image_rebind::rebind (statements_, tc_.version ()); + + select_statement::result r (statement_->load ()); + + if (r == select_statement::truncated) + { + typename object_traits::image_type& im (statements_.image ()); + + if (tc_.grow (im, statements_.select_image_truncated ())) + im.version++; + + if (image_rebind::rebind (statements_, tc_.version ())) + statement_->reload (); + } + } + + template + void polymorphic_object_result_impl:: + cache () + { + } + + template + std::size_t polymorphic_object_result_impl:: + size () + { + return this->end_ ? count_ : statement_->result_size (); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/polymorphic-object-statements.hxx b/libodb-pgsql/odb/pgsql/polymorphic-object-statements.hxx new file mode 100644 index 0000000..717410a --- /dev/null +++ b/libodb-pgsql/odb/pgsql/polymorphic-object-statements.hxx @@ -0,0 +1,513 @@ +// file : odb/pgsql/polymorphic-object-statements.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX +#define ODB_PGSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX + +#include + +#include // std::size_t + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + // + // Implementation for polymorphic objects. + // + + template + class polymorphic_root_object_statements: public object_statements + { + public: + typedef typename object_statements::connection_type connection_type; + typedef typename object_statements::object_traits object_traits; + typedef typename object_statements::id_image_type id_image_type; + + typedef + typename object_traits::discriminator_image_type + discriminator_image_type; + + typedef + typename object_statements::select_statement_type + select_statement_type; + + public: + // Interface compatibility with derived_object_statements. + // + typedef polymorphic_root_object_statements root_statements_type; + + root_statements_type& + root_statements () + { + return *this; + } + + public: + // Discriminator binding. + // + discriminator_image_type& + discriminator_image () {return discriminator_image_;} + + std::size_t + discriminator_image_version () const + {return discriminator_image_version_;} + + void + discriminator_image_version (std::size_t v) + {discriminator_image_version_ = v;} + + binding& + discriminator_image_binding () {return discriminator_image_binding_;} + + bool* + discriminator_image_truncated () {return discriminator_image_truncated_;} + + // Id binding for discriminator retrieval. + // + id_image_type& + discriminator_id_image () {return discriminator_id_image_;} + + std::size_t + discriminator_id_image_version () const + {return discriminator_id_image_version_;} + + void + discriminator_id_image_version (std::size_t v) + {discriminator_id_image_version_ = v;} + + binding& + discriminator_id_image_binding () + {return discriminator_id_image_binding_;} + + // Expose id native binding from object_statements. + // + native_binding& + id_image_native_binding () {return this->id_image_native_binding_;} + + // + // + select_statement_type& + find_discriminator_statement () + { + if (find_discriminator_ == 0) + find_discriminator_.reset ( + new (details::shared) select_statement_type ( + this->conn_, + object_traits::find_discriminator_statement_name, + object_traits::find_discriminator_statement, + false, // Doesn't need to be processed. + false, // Don't optimize. + object_traits::find_statement_types, // The same as find (id). + id_column_count, + discriminator_id_image_binding_, + discriminator_id_image_native_binding_, + discriminator_image_binding_, + false)); + + return *find_discriminator_; + } + + public: + polymorphic_root_object_statements (connection_type&); + + virtual + ~polymorphic_root_object_statements (); + + // Static "override" (statements type). + // + void + load_delayed (const schema_version_migration* svm) + { + assert (this->locked ()); + + if (!this->delayed_.empty ()) + this->template load_delayed_ ( + svm); + } + + public: + static const std::size_t id_column_count = + object_statements::id_column_count; + + static const std::size_t discriminator_column_count = + object_traits::discriminator_column_count; + + static const std::size_t managed_optimistic_column_count = + object_traits::managed_optimistic_column_count; + + private: + // Discriminator image. + // + discriminator_image_type discriminator_image_; + std::size_t discriminator_image_version_; + binding discriminator_image_binding_; + bind discriminator_image_bind_[discriminator_column_count + + managed_optimistic_column_count]; + bool discriminator_image_truncated_[discriminator_column_count + + managed_optimistic_column_count]; + + // Id image for discriminator retrieval (only used as a parameter). + // + id_image_type discriminator_id_image_; + std::size_t discriminator_id_image_version_; + binding discriminator_id_image_binding_; + native_binding discriminator_id_image_native_binding_; + bind discriminator_id_image_bind_[id_column_count]; + char* discriminator_id_image_values_[id_column_count]; + int discriminator_id_image_lengths_[id_column_count]; + int discriminator_id_image_formats_[id_column_count]; + + details::shared_ptr find_discriminator_; + }; + + template + class polymorphic_derived_object_statements: public statements_base + { + public: + typedef T object_type; + typedef object_traits_impl object_traits; + typedef typename object_traits::id_type id_type; + typedef typename object_traits::pointer_type pointer_type; + typedef typename object_traits::id_image_type id_image_type; + typedef typename object_traits::image_type image_type; + + typedef typename object_traits::root_type root_type; + typedef + polymorphic_root_object_statements + root_statements_type; + + typedef typename object_traits::base_type base_type; + typedef + typename object_traits::base_traits::statements_type + base_statements_type; + + typedef + typename object_traits::extra_statement_cache_type + extra_statement_cache_type; + + typedef pgsql::insert_statement insert_statement_type; + typedef pgsql::select_statement select_statement_type; + typedef pgsql::update_statement update_statement_type; + typedef pgsql::delete_statement delete_statement_type; + + typedef typename root_statements_type::auto_lock auto_lock; + + public: + polymorphic_derived_object_statements (connection_type&); + + virtual + ~polymorphic_derived_object_statements (); + + public: + // Delayed loading. + // + static void + delayed_loader (odb::database&, + const id_type&, + root_type&, + const schema_version_migration*); + public: + // Root and immediate base statements. + // + root_statements_type& + root_statements () + { + return root_statements_; + } + + base_statements_type& + base_statements () + { + return base_statements_; + } + + public: + // Object image. + // + image_type& + image () + { + return image_; + } + + // Insert binding. + // + std::size_t + insert_image_version () const { return insert_image_version_;} + + void + insert_image_version (std::size_t v) {insert_image_version_ = v;} + + std::size_t + insert_id_binding_version () const { return insert_id_binding_version_;} + + void + insert_id_binding_version (std::size_t v) {insert_id_binding_version_ = v;} + + binding& + insert_image_binding () {return insert_image_binding_;} + + // Update binding. + // + std::size_t + update_image_version () const { return update_image_version_;} + + void + update_image_version (std::size_t v) {update_image_version_ = v;} + + std::size_t + update_id_binding_version () const { return update_id_binding_version_;} + + void + update_id_binding_version (std::size_t v) {update_id_binding_version_ = v;} + + binding& + update_image_binding () {return update_image_binding_;} + + // Select binding. + // + std::size_t* + select_image_versions () { return select_image_versions_;} + + binding* + select_image_bindings () {return select_image_bindings_;} + + binding& + select_image_binding (std::size_t d) + { + return select_image_bindings_[object_traits::depth - d]; + } + + bool* + select_image_truncated () {return select_image_truncated_;} + + // Object id binding (comes from the root statements). + // + id_image_type& + id_image () {return root_statements_.id_image ();} + + std::size_t + id_image_version () const {return root_statements_.id_image_version ();} + + void + id_image_version (std::size_t v) {root_statements_.id_image_version (v);} + + binding& + id_image_binding () {return root_statements_.id_image_binding ();} + + binding& + optimistic_id_image_binding () { + return root_statements_.optimistic_id_image_binding ();} + + // Statements. + // + insert_statement_type& + persist_statement () + { + if (persist_ == 0) + persist_.reset ( + new (details::shared) insert_statement_type ( + conn_, + object_traits::persist_statement_name, + object_traits::persist_statement, + object_traits::versioned, // Process if versioned. + object_traits::persist_statement_types, + insert_column_count, + insert_image_binding_, + insert_image_native_binding_, + 0, + false)); + + return *persist_; + } + + select_statement_type& + find_statement (std::size_t d) + { + std::size_t i (object_traits::depth - d); + details::shared_ptr& p (find_[i]); + + if (p == 0) + p.reset ( + new (details::shared) select_statement_type ( + conn_, + object_traits::find_statement_names[i], + object_traits::find_statements[i], + object_traits::versioned, // Process if versioned. + false, // Don't optimize. + object_traits::find_statement_types, + id_column_count, + root_statements_.id_image_binding (), + root_statements_.id_image_native_binding (), + select_image_bindings_[i], + false)); + + return *p; + } + + update_statement_type& + update_statement () + { + if (update_ == 0) + update_.reset ( + new (details::shared) update_statement_type ( + conn_, + object_traits::update_statement_name, + object_traits::update_statement, + object_traits::versioned, // Process if versioned. + object_traits::update_statement_types, + update_column_count + id_column_count, + update_image_binding_, + update_image_native_binding_, + false)); + + return *update_; + } + + delete_statement_type& + erase_statement () + { + if (erase_ == 0) + erase_.reset ( + new (details::shared) delete_statement_type ( + conn_, + object_traits::erase_statement_name, + object_traits::erase_statement, + object_traits::find_statement_types, // The same as find (id). + id_column_count, + root_statements_.id_image_binding (), + root_statements_.id_image_native_binding (), + false)); + + return *erase_; + } + + // Extra (container, section) statement cache. + // + extra_statement_cache_type& + extra_statement_cache () + { + return extra_statement_cache_.get ( + conn_, + image_, + id_image (), + id_image_binding (), + &id_image_binding (), // Note, not id+version. + root_statements_.id_image_native_binding (), + object_traits::find_statement_types); + } + + public: + // select = total - id - separate_load + base::select + // insert = total - inverse + // update = total - inverse - id - readonly - separate_update + // + static const std::size_t id_column_count = + object_traits::id_column_count; + + static const std::size_t select_column_count = + object_traits::column_count - + id_column_count - + object_traits::separate_load_column_count + + base_statements_type::select_column_count; + + static const std::size_t insert_column_count = + object_traits::column_count - + object_traits::inverse_column_count; + + static const std::size_t update_column_count = + insert_column_count - + object_traits::id_column_count - + object_traits::readonly_column_count - + object_traits::separate_update_column_count; + + private: + polymorphic_derived_object_statements ( + const polymorphic_derived_object_statements&); + + polymorphic_derived_object_statements& + operator= (const polymorphic_derived_object_statements&); + + private: + root_statements_type& root_statements_; + base_statements_type& base_statements_; + + extra_statement_cache_ptr extra_statement_cache_; + + image_type image_; + + // Select binding. Here we are have an array of statements/bindings + // one for each depth. In other words, if we have classes root, base, + // and derived, then we have the following array of statements: + // + // [0] d + b + r + // [1] d + b + // [2] d + // + // Also, because we have a chain of images bound to these statements, + // we have an array of versions, one entry for each base plus one for + // our own image. + // + // A poly-abstract class only needs the first statement and in this + // case we have only one entry in the the bindings and statements + // arrays (but not versions; we still have a chain of images). + // + std::size_t select_image_versions_[object_traits::depth]; + binding select_image_bindings_[ + object_traits::abstract ? 1 : object_traits::depth]; + bind select_image_bind_[select_column_count]; + bool select_image_truncated_[select_column_count]; + + // Insert binding. The id binding is copied from the hierarchy root. + // + std::size_t insert_image_version_; + std::size_t insert_id_binding_version_; + binding insert_image_binding_; + bind insert_image_bind_[insert_column_count]; + native_binding insert_image_native_binding_; + char* insert_image_values_[insert_column_count]; + int insert_image_lengths_[insert_column_count]; + int insert_image_formats_[insert_column_count]; + + // Update binding. The id suffix binding is copied from the hierarchy + // root. + // + std::size_t update_image_version_; + std::size_t update_id_binding_version_; + binding update_image_binding_; + bind update_image_bind_[update_column_count + id_column_count]; + native_binding update_image_native_binding_; + char* update_image_values_[update_column_count + id_column_count]; + int update_image_lengths_[update_column_count + id_column_count]; + int update_image_formats_[update_column_count + id_column_count]; + + details::shared_ptr persist_; + details::shared_ptr find_[ + object_traits::abstract ? 1 : object_traits::depth]; + details::shared_ptr update_; + details::shared_ptr erase_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX diff --git a/libodb-pgsql/odb/pgsql/polymorphic-object-statements.txx b/libodb-pgsql/odb/pgsql/polymorphic-object-statements.txx new file mode 100644 index 0000000..8472fca --- /dev/null +++ b/libodb-pgsql/odb/pgsql/polymorphic-object-statements.txx @@ -0,0 +1,158 @@ +// file : odb/pgsql/polymorphic-object-statements.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::memset + +#include +#include + +#include +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + // + // polymorphic_root_object_statements + // + + template + polymorphic_root_object_statements:: + ~polymorphic_root_object_statements () + { + } + + template + polymorphic_root_object_statements:: + polymorphic_root_object_statements (connection_type& conn) + : object_statements (conn), + discriminator_image_binding_ (discriminator_image_bind_, + discriminator_column_count + + managed_optimistic_column_count), + discriminator_id_image_binding_ (discriminator_id_image_bind_, + id_column_count), + discriminator_id_image_native_binding_ ( + discriminator_id_image_values_, + discriminator_id_image_lengths_, + discriminator_id_image_formats_, + id_column_count) + { + discriminator_image_.version = 0; + discriminator_id_image_.version = 0; + + discriminator_image_version_ = 0; + discriminator_id_image_version_ = 0; + + std::memset (discriminator_image_bind_, + 0, + sizeof (discriminator_image_bind_)); + std::memset (discriminator_id_image_bind_, + 0, + sizeof (discriminator_id_image_bind_)); + std::memset (discriminator_image_truncated_, + 0, + sizeof (discriminator_image_truncated_)); + + for (std::size_t i (0); + i < discriminator_column_count + managed_optimistic_column_count; + ++i) + { + discriminator_image_bind_[i].truncated = + discriminator_image_truncated_ + i; + } + } + + // + // polymorphic_derived_object_statements + // + + template + polymorphic_derived_object_statements:: + ~polymorphic_derived_object_statements () + { + } + + template + polymorphic_derived_object_statements:: + polymorphic_derived_object_statements (connection_type& conn) + : statements_base (conn), + root_statements_ (conn.statement_cache ().find_object ()), + base_statements_ (conn.statement_cache ().find_object ()), + insert_image_binding_ (insert_image_bind_, insert_column_count), + insert_image_native_binding_ (insert_image_values_, + insert_image_lengths_, + insert_image_formats_, + insert_column_count), + update_image_binding_ (update_image_bind_, + update_column_count + id_column_count), + update_image_native_binding_ (update_image_values_, + update_image_lengths_, + update_image_formats_, + update_column_count + id_column_count) + { + image_.base = &base_statements_.image (); + image_.version = 0; + + for (std::size_t i (0); i < object_traits::depth; ++i) + select_image_versions_[i] = 0; + + for (std::size_t i (0); + i < (object_traits::abstract ? 1 : object_traits::depth); + ++i) + { + select_image_bindings_[i].bind = select_image_bind_; + select_image_bindings_[i].count = object_traits::find_column_counts[i]; + } + + insert_image_version_ = 0; + insert_id_binding_version_ = 0; + update_image_version_ = 0; + update_id_binding_version_ = 0; + + std::memset (insert_image_bind_, 0, sizeof (insert_image_bind_)); + std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); + std::memset (select_image_bind_, 0, sizeof (select_image_bind_)); + std::memset ( + select_image_truncated_, 0, sizeof (select_image_truncated_)); + + for (std::size_t i (0); i < select_column_count; ++i) + select_image_bind_[i].truncated = select_image_truncated_ + i; + } + + template + void polymorphic_derived_object_statements:: + delayed_loader (odb::database& db, + const id_type& id, + root_type& robj, + const schema_version_migration* svm) + { + connection_type& conn (transaction::current ().connection (db)); + polymorphic_derived_object_statements& sts ( + conn.statement_cache ().find_object ()); + root_statements_type& rsts (sts.root_statements ()); + + object_type& obj (static_cast (robj)); + + // The same code as in object_statements::load_delayed_(). + // + object_traits_calls tc (svm); + + if (!tc.find_ (sts, &id)) + throw object_not_persistent (); + + object_traits::callback (db, obj, callback_event::pre_load); + tc.init (obj, sts.image (), &db); + tc.load_ (sts, obj, false); // Load containers, etc. + + rsts.load_delayed (svm); + + { + typename root_statements_type::auto_unlock u (rsts); + object_traits::callback (db, obj, callback_event::post_load); + } + } + } +} diff --git a/libodb-pgsql/odb/pgsql/prepared-query.cxx b/libodb-pgsql/odb/pgsql/prepared-query.cxx new file mode 100644 index 0000000..a6d783c --- /dev/null +++ b/libodb-pgsql/odb/pgsql/prepared-query.cxx @@ -0,0 +1,15 @@ +// file : odb/pgsql/prepared-query.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + namespace pgsql + { + prepared_query_impl:: + ~prepared_query_impl () + { + } + } +} diff --git a/libodb-pgsql/odb/pgsql/prepared-query.hxx b/libodb-pgsql/odb/pgsql/prepared-query.hxx new file mode 100644 index 0000000..3622226 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/prepared-query.hxx @@ -0,0 +1,34 @@ +// file : odb/pgsql/prepared-query.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_PREPARED_QUERY_HXX +#define ODB_PGSQL_PREPARED_QUERY_HXX + +#include + +#include + +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + struct LIBODB_PGSQL_EXPORT prepared_query_impl: odb::prepared_query_impl + { + virtual + ~prepared_query_impl (); + + prepared_query_impl (odb::connection& c): odb::prepared_query_impl (c) {} + + pgsql::query_base query; + }; + } +} + +#include + +#endif // ODB_PGSQL_PREPARED_QUERY_HXX diff --git a/libodb-pgsql/odb/pgsql/query-const-expr.cxx b/libodb-pgsql/odb/pgsql/query-const-expr.cxx new file mode 100644 index 0000000..c910620 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query-const-expr.cxx @@ -0,0 +1,14 @@ +// file : odb/pgsql/query-const-expr.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + namespace pgsql + { + // Sun CC cannot handle this in query.cxx. + // + const query_base query_base::true_expr (true); + } +} diff --git a/libodb-pgsql/odb/pgsql/query-dynamic.cxx b/libodb-pgsql/odb/pgsql/query-dynamic.cxx new file mode 100644 index 0000000..ebd62de --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query-dynamic.cxx @@ -0,0 +1,157 @@ +// file : odb/pgsql/query-dynamic.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::size_t + +#include + +using namespace std; + +namespace odb +{ + namespace pgsql + { + static const char* logic_operators[] = {") AND (", ") OR ("}; + static const char* comp_operators[] = {"=", "!=", "<", ">", "<=", ">="}; + + static void + translate (query_base& q, const odb::query_base& s, size_t p) + { + typedef odb::query_base::clause_part part; + + const part& x (s.clause ()[p]); + + switch (x.kind) + { + case part::kind_column: + { + const query_column_base* c ( + static_cast ( + x.native_info[id_pgsql].column)); + + q.append (c->table (), c->column ()); + break; + } + case part::kind_param_val: + case part::kind_param_ref: + { + const query_column_base* c ( + static_cast ( + x.native_info[id_pgsql].column)); + + query_param_factory f ( + reinterpret_cast ( + x.native_info[id_pgsql].param_factory)); + + const odb::query_param* p ( + reinterpret_cast (x.data)); + + q.append (f (p->value, x.kind == part::kind_param_ref), + c->conversion ()); + break; + } + case part::kind_native: + { + q.append (s.strings ()[x.data]); + break; + } + case part::kind_true: + case part::kind_false: + { + q.append (x.kind == part::kind_true); + break; + } + case part::op_add: + { + translate (q, s, x.data); + translate (q, s, p - 1); + break; + } + case part::op_and: + case part::op_or: + { + q += "("; + translate (q, s, x.data); + q += logic_operators[x.kind - part::op_and]; + translate (q, s, p - 1); + q += ")"; + break; + } + case part::op_not: + { + q += "NOT ("; + translate (q, s, p - 1); + q += ")"; + break; + } + case part::op_null: + case part::op_not_null: + { + translate (q, s, p - 1); + q += (x.kind == part::op_null ? "IS NULL" : "IS NOT NULL"); + break; + } + case part::op_in: + { + if (x.data != 0) + { + size_t b (p - x.data); + + translate (q, s, b - 1); // column + q += "IN ("; + + for (size_t i (b); i != p; ++i) + { + if (i != b) + q += ","; + + translate (q, s, i); + } + + q += ")"; + } + else + q.append (false); + + break; + } + case part::op_like: + { + translate (q, s, p - 2); // column + q += "LIKE"; + translate (q, s, p - 1); // pattern + break; + } + case part::op_like_escape: + { + translate (q, s, p - 3); // column + q += "LIKE"; + translate (q, s, p - 2); // pattern + q += "ESCAPE"; + translate (q, s, p - 1); // escape + break; + } + case part::op_eq: + case part::op_ne: + case part::op_lt: + case part::op_gt: + case part::op_le: + case part::op_ge: + { + translate (q, s, x.data); + q += comp_operators[x.kind - part::op_eq]; + translate (q, s, p - 1); + break; + } + } + } + + query_base:: + query_base (const odb::query_base& q) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + if (!q.empty ()) + translate (*this, q, q.clause ().size () - 1); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/query-dynamic.hxx b/libodb-pgsql/odb/pgsql/query-dynamic.hxx new file mode 100644 index 0000000..df87519 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query-dynamic.hxx @@ -0,0 +1,32 @@ +// file : odb/pgsql/query-dynamic.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_QUERY_DYNAMIC_HXX +#define ODB_PGSQL_QUERY_DYNAMIC_HXX + +#include + +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + typedef details::shared_ptr (*query_param_factory) ( + const void* val, bool by_ref); + + template + details::shared_ptr + query_param_factory_impl (const void*, bool); + } +} + +#include +#include + +#include + +#endif // ODB_PGSQL_QUERY_DYNAMIC_HXX diff --git a/libodb-pgsql/odb/pgsql/query-dynamic.ixx b/libodb-pgsql/odb/pgsql/query-dynamic.ixx new file mode 100644 index 0000000..016d213 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query-dynamic.ixx @@ -0,0 +1,26 @@ +// file : odb/pgsql/query-dynamic.ixx +// license : GNU GPL v2; see accompanying LICENSE file + +namespace odb +{ + namespace pgsql + { + // + // + template + inline query_column:: + query_column (odb::query_column& qc, + const char* table, const char* column, const char* conv) + : query_column_base (table, column, conv) + { + native_column_info& ci (qc.native_info[id_pgsql]); + ci.column = static_cast (this); + + // For some reason GCC needs this statically-typed pointer in + // order to instantiate the functions. + // + query_param_factory f (&query_param_factory_impl); + ci.param_factory = reinterpret_cast (f); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/query-dynamic.txx b/libodb-pgsql/odb/pgsql/query-dynamic.txx new file mode 100644 index 0000000..7cfaf63 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query-dynamic.txx @@ -0,0 +1,20 @@ +// file : odb/pgsql/query-dynamic.txx +// license : GNU GPL v2; see accompanying LICENSE file + +namespace odb +{ + namespace pgsql + { + template + details::shared_ptr + query_param_factory_impl (const void* val, bool by_ref) + { + const T& v (*static_cast (val)); + + return details::shared_ptr ( + by_ref + ? new (details::shared) query_param_impl (ref_bind (v)) + : new (details::shared) query_param_impl (val_bind (v))); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/query.cxx b/libodb-pgsql/odb/pgsql/query.cxx new file mode 100644 index 0000000..b096c97 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query.cxx @@ -0,0 +1,444 @@ +// file : odb/pgsql/query.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::size_t +#include // std::memset +#include +#include + +#include +#include + +using namespace std; + +namespace odb +{ + namespace pgsql + { + // query_param + // + query_param:: + ~query_param () + { + } + + // query_base + // + query_base:: + query_base (const query_base& q) + : clause_ (q.clause_), + parameters_ (q.parameters_), + bind_ (q.bind_), + binding_ (0, 0), + values_ (q.values_), + lengths_ (q.lengths_), + formats_ (q.formats_), + types_ (q.types_), + native_binding_ (0, 0, 0, 0) + { + // Here and below we want to maintain up to date binding info so + // that the call to parameters_binding() below is an immutable + // operation, provided the query does not have any by-reference + // parameters. This way a by-value-only query can be shared + // between multiple threads without the need for synchronization. + // + if (size_t n = bind_.size ()) + { + binding_.bind = &bind_[0]; + binding_.count = n; + binding_.version++; + + native_binding_.values = &values_[0]; + native_binding_.lengths = &lengths_[0]; + native_binding_.formats = &formats_[0]; + native_binding_.count = n; + + assert (values_.size () == n); + assert (lengths_.size () == n); + assert (formats_.size () == n); + assert (types_.size () == n); + + statement::bind_param (native_binding_, binding_); + } + } + + query_base& query_base:: + operator= (const query_base& q) + { + if (this != &q) + { + clause_ = q.clause_; + parameters_ = q.parameters_; + bind_ = q.bind_; + + size_t n (bind_.size ()); + + binding_.count = n; + binding_.version++; + + values_ = q.values_; + lengths_ = q.lengths_; + formats_ = q.formats_; + types_ = q.types_; + + native_binding_.count = n; + + assert (values_.size () == n); + assert (lengths_.size () == n); + assert (formats_.size () == n); + assert (types_.size () == n); + + if (n != 0) + { + binding_.bind = &bind_[0]; + + native_binding_.values = &values_[0]; + native_binding_.lengths = &lengths_[0]; + native_binding_.formats = &formats_[0]; + + statement::bind_param (native_binding_, binding_); + } + } + + return *this; + } + + query_base& query_base:: + operator+= (const query_base& q) + { + clause_.insert (clause_.end (), q.clause_.begin (), q.clause_.end ()); + + size_t n (bind_.size ()); + + parameters_.insert ( + parameters_.end (), q.parameters_.begin (), q.parameters_.end ()); + + bind_.insert ( + bind_.end (), q.bind_.begin (), q.bind_.end ()); + + values_.insert ( + values_.end (), q.values_.begin (), q.values_.end ()); + + lengths_.insert ( + lengths_.end (), q.lengths_.begin (), q.lengths_.end ()); + + formats_.insert ( + formats_.end (), q.formats_.begin (), q.formats_.end ()); + + types_.insert ( + types_.end (), q.types_.begin (), q.types_.end ()); + + if (n != bind_.size ()) + { + n = bind_.size (); + + binding_.bind = &bind_[0]; + binding_.count = n; + binding_.version++; + + assert (values_.size () == n); + assert (lengths_.size () == n); + assert (formats_.size () == n); + assert (types_.size () == n); + + native_binding_.values = &values_[0]; + native_binding_.lengths = &lengths_[0]; + native_binding_.formats = &formats_[0]; + native_binding_.count = n; + + statement::bind_param (native_binding_, binding_); + } + + return *this; + } + + void query_base:: + append (const string& q) + { + if (!clause_.empty () && + clause_.back ().kind == clause_part::kind_native) + { + string& s (clause_.back ().part); + + char first (!q.empty () ? q[0] : ' '); + char last (!s.empty () ? s[s.size () - 1] : ' '); + + // We don't want extra spaces after '(' as well as before ',' + // and ')'. + // + if (last != ' ' && last != '\n' && last != '(' && + first != ' ' && first != '\n' && first != ',' && first != ')') + s += ' '; + + s += q; + } + else + clause_.push_back (clause_part (clause_part::kind_native, q)); + } + + void query_base:: + append (const char* table, const char* column) + { + string s (table); + s += '.'; + s += column; + + clause_.push_back (clause_part (clause_part::kind_column, s)); + } + + void query_base:: + append (details::shared_ptr p, const char* conv) + { + clause_.push_back (clause_part (clause_part::kind_param)); + + if (conv != 0) + clause_.back ().part = conv; + + parameters_.push_back (p); + bind_.push_back (bind ()); + binding_.bind = &bind_[0]; + binding_.count = bind_.size (); + binding_.version++; + + bind* b (&bind_.back ()); + memset (b, 0, sizeof (bind)); + p->bind (b); + + values_.push_back (0); + lengths_.push_back (0); + formats_.push_back (0); + native_binding_.values = &values_[0]; + native_binding_.lengths = &lengths_[0]; + native_binding_.formats = &formats_[0]; + + // native_binding_.count should always equal binding_.count. + // At this point, we know that we have added one element to + // each array, so there is no need to check. + // + native_binding_.count = binding_.count; + + types_.push_back (p->oid ()); + + statement::bind_param (native_binding_, binding_); + } + + void query_base:: + init_parameters () const + { + bool ref (false), inc_ver (false); + + for (size_t i (0); i < parameters_.size (); ++i) + { + query_param& p (*parameters_[i]); + + if (p.reference ()) + { + ref = true; + + if (p.init ()) + { + p.bind (&bind_[i]); + inc_ver = true; + } + } + } + + if (ref) + { + statement::bind_param (native_binding_, binding_); + + if (inc_ver) + binding_.version++; + } + } + + static bool + check_prefix (const string& s) + { + string::size_type n; + + // It is easier to compare to upper and lower-case versions + // rather than getting involved with the portable case- + // insensitive string comparison mess. + // + if (s.compare (0, (n = 5), "WHERE") == 0 || + s.compare (0, (n = 5), "where") == 0 || + s.compare (0, (n = 6), "SELECT") == 0 || + s.compare (0, (n = 6), "select") == 0 || + s.compare (0, (n = 8), "ORDER BY") == 0 || + s.compare (0, (n = 8), "order by") == 0 || + s.compare (0, (n = 8), "GROUP BY") == 0 || + s.compare (0, (n = 8), "group by") == 0 || + s.compare (0, (n = 6), "HAVING") == 0 || + s.compare (0, (n = 6), "having") == 0 || + s.compare (0, (n = 4), "WITH") == 0 || + s.compare (0, (n = 4), "with") == 0) + { + // It either has to be an exact match, or there should be + // a whitespace following the keyword. + // + if (s.size () == n || s[n] == ' ' || s[n] == '\n' || s[n] =='\t') + return true; + } + + return false; + } + + void query_base:: + optimize () + { + // Remove a single TRUE literal or one that is followe by one of + // the other clauses. This avoids useless WHERE clauses like + // + // WHERE TRUE GROUP BY foo + // + clause_type::iterator i (clause_.begin ()), e (clause_.end ()); + + if (i != e && i->kind == clause_part::kind_bool && i->bool_part) + { + clause_type::iterator j (i + 1); + + if (j == e || + (j->kind == clause_part::kind_native && check_prefix (j->part))) + clause_.erase (i); + } + } + + const char* query_base:: + clause_prefix () const + { + if (!clause_.empty ()) + { + const clause_part& p (clause_.front ()); + + if (p.kind == clause_part::kind_native && check_prefix (p.part)) + return ""; + + return "WHERE "; + } + + return ""; + } + + string query_base:: + clause () const + { + string r; + size_t param (1); + + for (clause_type::const_iterator i (clause_.begin ()), + end (clause_.end ()); + i != end; + ++i) + { + char last (!r.empty () ? r[r.size () - 1] : ' '); + + switch (i->kind) + { + case clause_part::kind_column: + { + if (last != ' ' && last != '\n' && last != '(') + r += ' '; + + r += i->part; + break; + } + case clause_part::kind_param: + { + if (last != ' ' && last != '\n' && last != '(') + r += ' '; + + ostringstream os; + os << param++; + + // Add the conversion expression, if any. + // + string::size_type p (0); + if (!i->part.empty ()) + { + p = i->part.find ("(?)"); + r.append (i->part, 0, p); + } + + r += '$'; + r += os.str (); + + if (!i->part.empty ()) + r.append (i->part, p + 3, string::npos); + + break; + } + case clause_part::kind_native: + { + // We don't want extra spaces after '(' as well as before ',' + // and ')'. + // + const string& p (i->part); + char first (!p.empty () ? p[0] : ' '); + + if (last != ' ' && last != '\n' && last != '(' && + first != ' ' && first != '\n' && first != ',' && first != ')') + r += ' '; + + r += p; + break; + } + case clause_part::kind_bool: + { + if (last != ' ' && last != '\n' && last != '(') + r += ' '; + + r += i->bool_part ? "TRUE" : "FALSE"; + break; + } + } + } + + return clause_prefix () + r; + } + + query_base + operator&& (const query_base& x, const query_base& y) + { + // Optimize cases where one or both sides are constant truth. + // + bool xt (x.const_true ()), yt (y.const_true ()); + + if (xt && yt) + return x; + + if (xt) + return y; + + if (yt) + return x; + + query_base r ("("); + r += x; + r += ") AND ("; + r += y; + r += ")"; + return r; + } + + query_base + operator|| (const query_base& x, const query_base& y) + { + query_base r ("("); + r += x; + r += ") OR ("; + r += y; + r += ")"; + return r; + } + + query_base + operator! (const query_base& x) + { + query_base r ("NOT ("); + r += x; + r += ")"; + return r; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/query.hxx b/libodb-pgsql/odb/pgsql/query.hxx new file mode 100644 index 0000000..42182d6 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query.hxx @@ -0,0 +1,2181 @@ +// file : odb/pgsql/query.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_QUERY_HXX +#define ODB_PGSQL_QUERY_HXX + +#include + +#include +#include +#include // std::size_t + +#include // odb::query_column +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +namespace odb +{ + namespace pgsql + { + template + struct val_bind + { + typedef const T& type; + + explicit + val_bind (type v): val (v) {} + + type val; + }; + + template + struct val_bind + { + typedef const T* type; + + explicit + val_bind (type v): val (v) {} + + type val; + }; + + template + struct ref_bind + { + typedef const T& type; + + explicit + ref_bind (type r): ref (r) {} + + const void* + ptr () const {return &ref;} + + type ref; + }; + + template + struct ref_bind + { + typedef const T* type; + + explicit + ref_bind (type r): ref (r) {} + + // Allow implicit conversion from decayed ref_bind's. + // + ref_bind (ref_bind r): ref (r.ref) {} + ref_bind (ref_bind r): ref (r.ref) {} + + const void* + ptr () const {return ref;} + + type ref; + }; + + template + struct val_bind_typed: val_bind + { + explicit + val_bind_typed (typename val_bind::type v): val_bind (v) {} + }; + + template + struct ref_bind_typed: ref_bind + { + explicit + ref_bind_typed (typename ref_bind::type r): ref_bind (r) {} + }; + + struct LIBODB_PGSQL_EXPORT query_param: details::shared_base + { + typedef pgsql::bind bind_type; + + virtual + ~query_param (); + + bool + reference () const + { + return value_ != 0; + } + + virtual bool + init () = 0; + + virtual void + bind (bind_type*) = 0; + + virtual unsigned int + oid () const = 0; + + protected: + query_param (const void* value) + : value_ (value) + { + } + + protected: + const void* value_; + }; + + // + // + template + struct query_column; + + class LIBODB_PGSQL_EXPORT query_base + { + public: + struct clause_part + { + enum kind_type + { + kind_column, + kind_param, + kind_native, + kind_bool + }; + + clause_part (kind_type k): kind (k), bool_part (false) {} + clause_part (kind_type k, const std::string& p) + : kind (k), part (p), bool_part (false) {} + clause_part (bool p): kind (kind_bool), bool_part (p) {} + + kind_type kind; + std::string part; // If kind is param, then part is conversion expr. + bool bool_part; + }; + + query_base () + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + } + + // True or false literal. + // + explicit + query_base (bool v) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + append (v); + } + + explicit + query_base (const char* native) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + clause_.push_back (clause_part (clause_part::kind_native, native)); + } + + explicit + query_base (const std::string& native) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + clause_.push_back (clause_part (clause_part::kind_native, native)); + } + + query_base (const char* table, const char* column) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + append (table, column); + } + + template + explicit + query_base (val_bind v) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + *this += v; + } + + template + explicit + query_base (val_bind_typed v) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + *this += v; + } + + template + explicit + query_base (ref_bind r) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + *this += r; + } + + template + explicit + query_base (ref_bind_typed r) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + *this += r; + } + + template + query_base (const query_column&); + + // Translate common query representation to PostgreSQL native. Defined + // in query-dynamic.cxx + // + query_base (const odb::query_base&); + + // Copy c-tor and assignment. + // + query_base (const query_base&); + + query_base& + operator= (const query_base&); + + public: + std::string + clause () const; + + const char* + clause_prefix () const; + + // Initialize the by-reference parameters from bound variables. + // + void + init_parameters () const; + + native_binding& + parameters_binding () const; + + const unsigned int* + parameter_types () const + { + return types_.empty () ? 0 : &types_[0]; + } + + std::size_t + parameter_count () const + { + return parameters_.size (); + } + + public: + bool + empty () const + { + return clause_.empty (); + } + + static const query_base true_expr; + + bool + const_true () const + { + return clause_.size () == 1 && + clause_.front ().kind == clause_part::kind_bool && + clause_.front ().bool_part; + } + + void + optimize (); + + public: + template + static val_bind + _val (const T& x) + { + return val_bind (x); + } + + template + static val_bind_typed + _val (const T& x) + { + return val_bind_typed (x); + } + + template + static ref_bind + _ref (const T& x) + { + return ref_bind (x); + } + + template + static ref_bind_typed + _ref (const T& x) + { + return ref_bind_typed (x); + } + + // Some compilers (notably VC++), when deducing const T& from const + // array do not strip const from the array type. As a result, in the + // above signatures we get, for example, T = const char[4] instead + // of T = char[4], which is what we want. So to "fix" such compilers, + // we will have to provide the following specializations of the above + // functions. + // + template + static val_bind + _val (const T (&x) [N]) + { + return val_bind (x); + } + + template + static val_bind_typed + _val (const T (&x) [N]) + { + return val_bind_typed (x); + } + + template + static ref_bind + _ref (const T (&x) [N]) + { + return ref_bind (x); + } + + template + static ref_bind_typed + _ref (const T (&x) [N]) + { + return ref_bind_typed (x); + } + + public: + query_base& + operator+= (const query_base&); + + query_base& + operator+= (const std::string& q) + { + append (q); + return *this; + } + + template + query_base& + operator+= (val_bind v) + { + append::db_type_id> ( + v, details::conversion::to ()); + return *this; + } + + template + query_base& + operator+= (val_bind_typed v) + { + // We are not using default type_traits so no default conversion + // either. + // + append (v, 0); + return *this; + } + + template + query_base& + operator+= (ref_bind r) + { + append::db_type_id> ( + r, details::conversion::to ()); + return *this; + } + + template + query_base& + operator+= (ref_bind_typed r) + { + // We are not using default type_traits so no default conversion + // either. + // + append (r, 0); + return *this; + } + + // Implementation details. + // + public: + template + void + append (val_bind, const char* conv); + + template + void + append (ref_bind, const char* conv); + + void + append (details::shared_ptr, const char* conv); + + void + append (bool v) + { + clause_.push_back (clause_part (v)); + } + + void + append (const std::string& native); + + void + append (const char* native) // Clashes with append(bool). + { + append (std::string (native)); + } + + void + append (const char* table, const char* column); + + private: + typedef std::vector clause_type; + typedef std::vector > parameters_type; + + clause_type clause_; + parameters_type parameters_; + + mutable std::vector bind_; + mutable binding binding_; + + std::vector values_; + std::vector lengths_; + std::vector formats_; + std::vector types_; + mutable native_binding native_binding_; + }; + + inline query_base + operator+ (const query_base& x, const query_base& y) + { + query_base r (x); + r += y; + return r; + } + + template + inline query_base + operator+ (const query_base& q, val_bind b) + { + query_base r (q); + r += b; + return r; + } + + template + inline query_base + operator+ (val_bind b, const query_base& q) + { + query_base r; + r += b; + r += q; + return r; + } + + template + inline query_base + operator+ (const query_base& q, val_bind_typed b) + { + query_base r (q); + r += b; + return r; + } + + template + inline query_base + operator+ (val_bind_typed b, const query_base& q) + { + query_base r; + r += b; + r += q; + return r; + } + + template + inline query_base + operator+ (const query_base& q, ref_bind b) + { + query_base r (q); + r += b; + return r; + } + + template + inline query_base + operator+ (ref_bind b, const query_base& q) + { + query_base r; + r += b; + r += q; + return r; + } + + template + inline query_base + operator+ (const query_base& q, ref_bind_typed b) + { + query_base r (q); + r += b; + return r; + } + + template + inline query_base + operator+ (ref_bind_typed b, const query_base& q) + { + query_base r; + r += b; + r += q; + return r; + } + + inline query_base + operator+ (const query_base& q, const std::string& s) + { + query_base r (q); + r += s; + return r; + } + + inline query_base + operator+ (const std::string& s, const query_base& q) + { + query_base r (s); + r += q; + return r; + } + + template + inline query_base + operator+ (const std::string& s, val_bind b) + { + query_base r (s); + r += b; + return r; + } + + template + inline query_base + operator+ (val_bind b, const std::string& s) + { + query_base r; + r += b; + r += s; + return r; + } + + template + inline query_base + operator+ (const std::string& s, val_bind_typed b) + { + query_base r (s); + r += b; + return r; + } + + template + inline query_base + operator+ (val_bind_typed b, const std::string& s) + { + query_base r; + r += b; + r += s; + return r; + } + + template + inline query_base + operator+ (const std::string& s, ref_bind b) + { + query_base r (s); + r += b; + return r; + } + + template + inline query_base + operator+ (ref_bind b, const std::string& s) + { + query_base r; + r += b; + r += s; + return r; + } + + template + inline query_base + operator+ (const std::string& s, ref_bind_typed b) + { + query_base r (s); + r += b; + return r; + } + + template + inline query_base + operator+ (ref_bind_typed b, const std::string& s) + { + query_base r; + r += b; + r += s; + return r; + } + + LIBODB_PGSQL_EXPORT query_base + operator&& (const query_base&, const query_base&); + + LIBODB_PGSQL_EXPORT query_base + operator|| (const query_base&, const query_base&); + + LIBODB_PGSQL_EXPORT query_base + operator! (const query_base&); + + // query_column + // + struct query_column_base + { + // Note that we keep shallow copies of the table, column, and conversion + // expression. The latter can be NULL. + // + query_column_base (const char* table, + const char* column, + const char* conv) + : table_ (table), column_ (column), conversion_ (conv) + { + } + + const char* + table () const + { + return table_; + } + + const char* + column () const + { + return column_; + } + + // Can be NULL. + // + const char* + conversion () const + { + return conversion_; + } + + protected: + const char* table_; + const char* column_; + const char* conversion_; + }; + + template + struct query_column: query_column_base + { + typedef typename decay_traits::type decayed_type; + + // Note that we keep shallow copies of the table, column, and conversion + // expression. The latter can be NULL. + // + query_column (const char* table, const char* column, const char* conv) + : query_column_base (table, column, conv) {} + + // Implementation is in query-dynamic.ixx. + // + query_column (odb::query_column&, + const char* table, const char* column, const char* conv); + + // is_null, is_not_null + // + public: + query_base + is_null () const + { + query_base q (table_, column_); + q += "IS NULL"; + return q; + } + + query_base + is_not_null () const + { + query_base q (table_, column_); + q += "IS NOT NULL"; + return q; + } + + // in + // + public: + query_base + in (decayed_type, decayed_type) const; + + query_base + in (decayed_type, decayed_type, decayed_type) const; + + query_base + in (decayed_type, decayed_type, decayed_type, decayed_type) const; + + query_base + in (decayed_type, decayed_type, decayed_type, decayed_type, + decayed_type) const; + + template + query_base + in_range (I begin, I end) const; + + // like + // + public: + query_base + like (decayed_type pattern) const + { + return like (val_bind (pattern)); + } + + query_base + like (val_bind pattern) const; + + template + query_base + like (val_bind pattern) const + { + return like (val_bind (decayed_type (pattern.val))); + } + + query_base + like (ref_bind pattern) const; + + query_base + like (decayed_type pattern, decayed_type escape) const + { + return like (val_bind (pattern), escape); + } + + query_base + like (val_bind pattern, decayed_type escape) const; + + template + query_base + like (val_bind pattern, decayed_type escape) const + { + return like (val_bind (decayed_type (pattern.val)), escape); + } + + query_base + like (ref_bind pattern, decayed_type escape) const; + + // = + // + public: + query_base + equal (decayed_type v) const + { + return equal (val_bind (v)); + } + + query_base + equal (val_bind v) const + { + query_base q (table_, column_); + q += "="; + q.append (v, conversion_); + return q; + } + + template + query_base + equal (val_bind v) const + { + return equal (val_bind (decayed_type (v.val))); + } + + query_base + equal (ref_bind r) const + { + query_base q (table_, column_); + q += "="; + q.append (r, conversion_); + return q; + } + + friend query_base + operator== (const query_column& c, decayed_type v) + { + return c.equal (v); + } + + friend query_base + operator== (decayed_type v, const query_column& c) + { + return c.equal (v); + } + + friend query_base + operator== (const query_column& c, val_bind v) + { + return c.equal (v); + } + + friend query_base + operator== (val_bind v, const query_column& c) + { + return c.equal (v); + } + + template + friend query_base + operator== (const query_column& c, val_bind v) + { + return c.equal (v); + } + + template + friend query_base + operator== (val_bind v, const query_column& c) + { + return c.equal (v); + } + + friend query_base + operator== (const query_column& c, ref_bind r) + { + return c.equal (r); + } + + friend query_base + operator== (ref_bind r, const query_column& c) + { + return c.equal (r); + } + + // != + // + public: + query_base + unequal (decayed_type v) const + { + return unequal (val_bind (v)); + } + + query_base + unequal (val_bind v) const + { + query_base q (table_, column_); + q += "!="; + q.append (v, conversion_); + return q; + } + + template + query_base + unequal (val_bind v) const + { + return unequal (val_bind (decayed_type (v.val))); + } + + query_base + unequal (ref_bind r) const + { + query_base q (table_, column_); + q += "!="; + q.append (r, conversion_); + return q; + } + + friend query_base + operator!= (const query_column& c, decayed_type v) + { + return c.unequal (v); + } + + friend query_base + operator!= (decayed_type v, const query_column& c) + { + return c.unequal (v); + } + + friend query_base + operator!= (const query_column& c, val_bind v) + { + return c.unequal (v); + } + + friend query_base + operator!= (val_bind v, const query_column& c) + { + return c.unequal (v); + } + + template + friend query_base + operator!= (const query_column& c, val_bind v) + { + return c.unequal (v); + } + + template + friend query_base + operator!= (val_bind v, const query_column& c) + { + return c.unequal (v); + } + + friend query_base + operator!= (const query_column& c, ref_bind r) + { + return c.unequal (r); + } + + friend query_base + operator!= (ref_bind r, const query_column& c) + { + return c.unequal (r); + } + + // < + // + public: + query_base + less (decayed_type v) const + { + return less (val_bind (v)); + } + + query_base + less (val_bind v) const + { + query_base q (table_, column_); + q += "<"; + q.append (v, conversion_); + return q; + } + + template + query_base + less (val_bind v) const + { + return less (val_bind (decayed_type (v.val))); + } + + query_base + less (ref_bind r) const + { + query_base q (table_, column_); + q += "<"; + q.append (r, conversion_); + return q; + } + + friend query_base + operator< (const query_column& c, decayed_type v) + { + return c.less (v); + } + + friend query_base + operator< (decayed_type v, const query_column& c) + { + return c.greater (v); + } + + friend query_base + operator< (const query_column& c, val_bind v) + { + return c.less (v); + } + + friend query_base + operator< (val_bind v, const query_column& c) + { + return c.greater (v); + } + + template + friend query_base + operator< (const query_column& c, val_bind v) + { + return c.less (v); + } + + template + friend query_base + operator< (val_bind v, const query_column& c) + { + return c.greater (v); + } + + friend query_base + operator< (const query_column& c, ref_bind r) + { + return c.less (r); + } + + friend query_base + operator< (ref_bind r, const query_column& c) + { + return c.greater (r); + } + + // > + // + public: + query_base + greater (decayed_type v) const + { + return greater (val_bind (v)); + } + + query_base + greater (val_bind v) const + { + query_base q (table_, column_); + q += ">"; + q.append (v, conversion_); + return q; + } + + template + query_base + greater (val_bind v) const + { + return greater (val_bind (decayed_type (v.val))); + } + + query_base + greater (ref_bind r) const + { + query_base q (table_, column_); + q += ">"; + q.append (r, conversion_); + return q; + } + + friend query_base + operator> (const query_column& c, decayed_type v) + { + return c.greater (v); + } + + friend query_base + operator> (decayed_type v, const query_column& c) + { + return c.less (v); + } + + friend query_base + operator> (const query_column& c, val_bind v) + { + return c.greater (v); + } + + friend query_base + operator> (val_bind v, const query_column& c) + { + return c.less (v); + } + + template + friend query_base + operator> (const query_column& c, val_bind v) + { + return c.greater (v); + } + + template + friend query_base + operator> (val_bind v, const query_column& c) + { + return c.less (v); + } + + friend query_base + operator> (const query_column& c, ref_bind r) + { + return c.greater (r); + } + + friend query_base + operator> (ref_bind r, const query_column& c) + { + return c.less (r); + } + + // <= + // + public: + query_base + less_equal (decayed_type v) const + { + return less_equal (val_bind (v)); + } + + query_base + less_equal (val_bind v) const + { + query_base q (table_, column_); + q += "<="; + q.append (v, conversion_); + return q; + } + + template + query_base + less_equal (val_bind v) const + { + return less_equal (val_bind (decayed_type (v.val)));; + } + + query_base + less_equal (ref_bind r) const + { + query_base q (table_, column_); + q += "<="; + q.append (r, conversion_); + return q; + } + + friend query_base + operator<= (const query_column& c, decayed_type v) + { + return c.less_equal (v); + } + + friend query_base + operator<= (decayed_type v, const query_column& c) + { + return c.greater_equal (v); + } + + friend query_base + operator<= (const query_column& c, val_bind v) + { + return c.less_equal (v); + } + + friend query_base + operator<= (val_bind v, const query_column& c) + { + return c.greater_equal (v); + } + + template + friend query_base + operator<= (const query_column& c, val_bind v) + { + return c.less_equal (v); + } + + template + friend query_base + operator<= (val_bind v, const query_column& c) + { + return c.greater_equal (v); + } + + friend query_base + operator<= (const query_column& c, ref_bind r) + { + return c.less_equal (r); + } + + friend query_base + operator<= (ref_bind r, const query_column& c) + { + return c.greater_equal (r); + } + + // >= + // + public: + query_base + greater_equal (decayed_type v) const + { + return greater_equal (val_bind (v)); + } + + query_base + greater_equal (val_bind v) const + { + query_base q (table_, column_); + q += ">="; + q.append (v, conversion_); + return q; + } + + template + query_base + greater_equal (val_bind v) const + { + return greater_equal (val_bind (decayed_type (v.val)));; + } + + query_base + greater_equal (ref_bind r) const + { + query_base q (table_, column_); + q += ">="; + q.append (r, conversion_); + return q; + } + + friend query_base + operator>= (const query_column& c, decayed_type v) + { + return c.greater_equal (v); + } + + friend query_base + operator>= (decayed_type v, const query_column& c) + { + return c.less_equal (v); + } + + friend query_base + operator>= (const query_column& c, val_bind v) + { + return c.greater_equal (v); + } + + friend query_base + operator>= (val_bind v, const query_column& c) + { + return c.less_equal (v); + } + + template + friend query_base + operator>= (const query_column& c, val_bind v) + { + return c.greater_equal (v); + } + + template + friend query_base + operator>= (val_bind v, const query_column& c) + { + return c.less_equal (v); + } + + friend query_base + operator>= (const query_column& c, ref_bind r) + { + return c.greater_equal (r); + } + + friend query_base + operator>= (ref_bind r, const query_column& c) + { + return c.less_equal (r); + } + + // Column comparison. + // + public: + template + query_base + operator== (const query_column& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (decay_traits::instance () == + decay_traits::instance ())); + + query_base q (table_, column_); + q += "="; + q.append (c.table (), c.column ()); + return q; + } + + template + query_base + operator!= (const query_column& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (decay_traits::instance () != + decay_traits::instance ())); + + query_base q (table_, column_); + q += "!="; + q.append (c.table (), c.column ()); + return q; + } + + template + query_base + operator< (const query_column& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (decay_traits::instance () < + decay_traits::instance ())); + + query_base q (table_, column_); + q += "<"; + q.append (c.table (), c.column ()); + return q; + } + + template + query_base + operator> (const query_column& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (decay_traits::instance () > + decay_traits::instance ())); + + query_base q (table_, column_); + q += ">"; + q.append (c.table (), c.column ()); + return q; + } + + template + query_base + operator<= (const query_column& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (decay_traits::instance () <= + decay_traits::instance ())); + + query_base q (table_, column_); + q += "<="; + q.append (c.table (), c.column ()); + return q; + } + + template + query_base + operator>= (const query_column& c) const + { + // We can compare columns only if we can compare their C++ types. + // + (void) (sizeof (decay_traits::instance () >= + decay_traits::instance ())); + + query_base q (table_, column_); + q += ">="; + q.append (c.table (), c.column ()); + return q; + } + }; + + // Provide operator+() for using columns to construct native + // query fragments (e.g., ORDER BY). + // + template + inline query_base + operator+ (const query_column& c, const std::string& s) + { + query_base q (c.table (), c.column ()); + q += s; + return q; + } + + template + inline query_base + operator+ (const std::string& s, const query_column& c) + { + query_base q (s); + q.append (c.table (), c.column ()); + return q; + } + + template + inline query_base + operator+ (const query_column& c, const query_base& q) + { + query_base r (c.table (), c.column ()); + r += q; + return r; + } + + template + inline query_base + operator+ (const query_base& q, const query_column& c) + { + query_base r (q); + r.append (c.table (), c.column ()); + return r; + } + + // + // + template + struct query_param_impl; + + // BOOLEAN + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::boolean_; + b->buffer = &image_; + } + + virtual unsigned int + oid () const + { + return bool_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (image_, is_null, v); + } + + private: + bool image_; + }; + + // SMALLINT + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::smallint; + b->buffer = &image_; + } + + virtual unsigned int + oid () const + { + return int2_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (image_, is_null, v); + } + + private: + short image_; + }; + + // INTEGER + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::integer; + b->buffer = &image_; + } + + virtual unsigned int + oid () const + { + return int4_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (image_, is_null, v); + } + + private: + int image_; + }; + + // BIGINT + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::bigint; + b->buffer = &image_; + } + + virtual unsigned int + oid () const + { + return int8_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (image_, is_null, v); + } + + private: + long long image_; + }; + + // REAL + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::real; + b->buffer = &image_; + } + + virtual unsigned int + oid () const + { + return float4_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (image_, is_null, v); + } + + private: + float image_; + }; + + // DOUBLE + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::double_; + b->buffer = &image_; + } + + virtual unsigned int + oid () const + { + return float8_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (image_, is_null, v); + } + + private: + double image_; + }; + + // NUMERIC + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + return init (*static_cast (value_)); + } + + virtual void + bind (bind_type* b) + { + b->type = bind::numeric; + b->buffer = buffer_.data_ptr (); + b->capacity = buffer_.capacity (); + b->size = &size_; + } + + virtual unsigned int + oid () const + { + return numeric_oid; + } + + private: + bool + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + std::size_t size (0), cap (buffer_.capacity ()); + value_traits::set_image (buffer_, size, is_null, v); + size_ = size; + return cap != buffer_.capacity (); + } + + private: + details::buffer buffer_; + std::size_t size_; + }; + + // DATE + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::date; + b->buffer = &image_; + } + + virtual unsigned int + oid () const + { + return date_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (image_, is_null, v); + } + + private: + int image_; + }; + + // TIME + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::time; + b->buffer = &image_; + } + + virtual unsigned int + oid () const + { + return time_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (image_, is_null, v); + } + + private: + long long image_; + }; + + // TIMESTAMP + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::timestamp; + b->buffer = &image_; + } + + virtual unsigned int + oid () const + { + return timestamp_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (image_, is_null, v); + } + + private: + long long image_; + }; + + // STRING + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + return init (*static_cast (value_)); + } + + virtual void + bind (bind_type* b) + { + b->type = bind::text; + b->buffer = buffer_.data_ptr (); + b->capacity = buffer_.capacity (); + b->size = &size_; + } + + virtual unsigned int + oid () const + { + return text_oid; + } + + private: + bool + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + std::size_t size (0), cap (buffer_.capacity ()); + value_traits::set_image (buffer_, size, is_null, v); + size_ = size; + return cap != buffer_.capacity (); + } + + private: + details::buffer buffer_; + std::size_t size_; + }; + + // BYTEA + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + return init (*static_cast (value_)); + } + + virtual void + bind (bind_type* b) + { + b->type = bind::bytea; + b->buffer = buffer_.data_ptr (); + b->capacity = buffer_.capacity (); + b->size = &size_; + } + + virtual unsigned int + oid () const + { + return bytea_oid; + } + + private: + bool + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + std::size_t size (0), cap (buffer_.capacity ()); + value_traits::set_image (buffer_, size, is_null, v); + size_ = size; + return cap != buffer_.capacity (); + } + + private: + details::buffer buffer_; + std::size_t size_; + }; + + // BIT + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + return init (*static_cast (value_)); + } + + virtual void + bind (bind_type* b) + { + b->type = bind::bit; + b->buffer = buffer_.data_ptr (); + b->capacity = buffer_.capacity (); + b->size = &size_; + } + + private: + bool + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + std::size_t size (0), cap (buffer_.capacity ()); + + // NOTE: Using a fixed size bit type in queries requires + // alternative image buffer type support. + // + value_traits::set_image (buffer_, size, is_null, v); + size_ = size; + + return cap != buffer_.capacity (); + } + + private: + details::ubuffer buffer_; + std::size_t size_; + }; + + // VARBIT + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + return init (*static_cast (value_)); + } + + virtual void + bind (bind_type* b) + { + b->type = bind::varbit; + b->buffer = buffer_.data_ptr (); + b->capacity = buffer_.capacity (); + b->size = &size_; + } + + virtual unsigned int + oid () const + { + return varbit_oid; + } + + private: + bool + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + std::size_t size (0), cap (buffer_.capacity ()); + value_traits::set_image (buffer_, size, is_null, v); + size_ = size; + return cap != buffer_.capacity (); + } + + private: + details::ubuffer buffer_; + std::size_t size_; + }; + + // UUID + // + template + struct query_param_impl: query_param + { + query_param_impl (ref_bind r) : query_param (r.ptr ()) {} + query_param_impl (val_bind v) : query_param (0) {init (v.val);} + + virtual bool + init () + { + init (*static_cast (value_)); + return false; + } + + virtual void + bind (bind_type* b) + { + b->type = bind::uuid; + b->buffer = buffer_; + } + + virtual unsigned int + oid () const + { + return uuid_oid; + } + + private: + void + init (typename decay_traits::type v) + { + bool is_null (false); // Can't be NULL. + value_traits::set_image (buffer_, is_null, v); + } + + private: + unsigned char buffer_[16]; + }; + } +} + +// odb::pgsql::query and odb::query specialization for PostgreSQL. +// +namespace odb +{ + namespace pgsql + { + template + class query: public query_base, + public query_selector::columns_type + { + public: + // We don't define any typedefs here since they may clash with + // column names defined by our base type. + // + + query () + { + } + + explicit + query (bool v) + : query_base (v) + { + } + + explicit + query (const char* q) + : query_base (q) + { + } + + explicit + query (const std::string& q) + : query_base (q) + { + } + + template + explicit + query (val_bind v) + : query_base (v) + { + } + + template + explicit + query (ref_bind r) + : query_base (r) + { + } + + query (const query_base& q) + : query_base (q) + { + } + + template + query (const query_column& qc) + : query_base (qc) + { + } + + query (const odb::query_base& q) + : query_base (q) + { + } + }; + + namespace core + { + using pgsql::query; + } + } + + // Derive odb::query from odb::pgsql::query so that it can be + // implicitly converted in pgsql::database::query() calls. + // + template + class query: public pgsql::query + { + public: + // We don't define any typedefs here since they may clash with + // column names defined by our base type. + // + + query () + { + } + + explicit + query (bool v) + : pgsql::query (v) + { + } + + explicit + query (const char* q) + : pgsql::query (q) + { + } + + explicit + query (const std::string& q) + : pgsql::query (q) + { + } + + template + explicit + query (pgsql::val_bind v) + : pgsql::query (v) + { + } + + template + explicit + query (pgsql::ref_bind r) + : pgsql::query (r) + { + } + + query (const pgsql::query_base& q) + : pgsql::query (q) + { + } + + template + query (const pgsql::query_column& qc) + : pgsql::query (qc) + { + } + }; +} + +#include +#include + +#include + +#endif // ODB_PGSQL_QUERY_HXX diff --git a/libodb-pgsql/odb/pgsql/query.ixx b/libodb-pgsql/odb/pgsql/query.ixx new file mode 100644 index 0000000..826b4ab --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query.ixx @@ -0,0 +1,34 @@ +// file : odb/pgsql/query.ixx +// license : GNU GPL v2; see accompanying LICENSE file + +namespace odb +{ + namespace pgsql + { + inline native_binding& query_base:: + parameters_binding () const + { + return native_binding_; + } + + template + inline void query_base:: + append (val_bind v, const char* conv) + { + append ( + details::shared_ptr ( + new (details::shared) query_param_impl (v)), + conv); + } + + template + inline void query_base:: + append (ref_bind r, const char* conv) + { + append ( + details::shared_ptr ( + new (details::shared) query_param_impl (r)), + conv); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/query.txx b/libodb-pgsql/odb/pgsql/query.txx new file mode 100644 index 0000000..44dae30 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/query.txx @@ -0,0 +1,168 @@ +// file : odb/pgsql/query.txx +// license : GNU GPL v2; see accompanying LICENSE file + +namespace odb +{ + namespace pgsql + { + // + // query_base + // + + template + query_base:: + query_base (const query_column& c) + : binding_ (0, 0), native_binding_ (0, 0, 0, 0) + { + // Cannot use IS TRUE here since database type can be a non- + // integral type. + // + append (c.table (), c.column ()); + append ("="); + append (val_bind (true), c.conversion ()); + } + + // + // query_column + // + + // in + // + template + query_base query_column:: + in (decayed_type v1, decayed_type v2) const + { + query_base q (table_, column_); + q += "IN ("; + q.append (val_bind (v1), conversion_); + q += ","; + q.append (val_bind (v2), conversion_); + q += ")"; + return q; + } + + template + query_base query_column:: + in (decayed_type v1, decayed_type v2, decayed_type v3) const + { + query_base q (table_, column_); + q += "IN ("; + q.append (val_bind (v1), conversion_); + q += ","; + q.append (val_bind (v2), conversion_); + q += ","; + q.append (val_bind (v3), conversion_); + q += ")"; + return q; + } + + template + query_base query_column:: + in (decayed_type v1, decayed_type v2, decayed_type v3, + decayed_type v4) const + { + query_base q (table_, column_); + q += "IN ("; + q.append (val_bind (v1), conversion_); + q += ","; + q.append (val_bind (v2), conversion_); + q += ","; + q.append (val_bind (v3), conversion_); + q += ","; + q.append (val_bind (v4), conversion_); + q += ")"; + return q; + } + + template + query_base query_column:: + in (decayed_type v1, decayed_type v2, decayed_type v3, decayed_type v4, + decayed_type v5) const + { + query_base q (table_, column_); + q += "IN ("; + q.append (val_bind (v1), conversion_); + q += ","; + q.append (val_bind (v2), conversion_); + q += ","; + q.append (val_bind (v3), conversion_); + q += ","; + q.append (val_bind (v4), conversion_); + q += ","; + q.append (val_bind (v5), conversion_); + q += ")"; + return q; + } + + template + template + query_base query_column:: + in_range (I begin, I end) const + { + if (begin != end) + { + query_base q (table_, column_); + q += "IN ("; + + for (I i (begin); i != end; ++i) + { + if (i != begin) + q += ","; + + q.append (val_bind (*i), conversion_); + } + + q += ")"; + return q; + } + else + return query_base (false); + } + + // like + // + template + query_base query_column:: + like (val_bind p) const + { + query_base q (table_, column_); + q += "LIKE"; + q.append (p, conversion_); + return q; + } + + template + query_base query_column:: + like (ref_bind p) const + { + query_base q (table_, column_); + q += "LIKE"; + q.append (p, conversion_); + return q; + } + + template + query_base query_column:: + like (val_bind p, decayed_type e) const + { + query_base q (table_, column_); + q += "LIKE"; + q.append (p, conversion_); + q += "ESCAPE"; + q.append (val_bind (e), conversion_); + return q; + } + + template + query_base query_column:: + like (ref_bind p, decayed_type e) const + { + query_base q (table_, column_); + q += "LIKE"; + q.append (p, conversion_); + q += "ESCAPE"; + q.append (val_bind (e), conversion_); + return q; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/section-statements.hxx b/libodb-pgsql/odb/pgsql/section-statements.hxx new file mode 100644 index 0000000..e40b282 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/section-statements.hxx @@ -0,0 +1,220 @@ +// file : odb/pgsql/section-statements.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_SECTION_STATEMENTS_HXX +#define ODB_PGSQL_SECTION_STATEMENTS_HXX + +#include + +#include // std::size_t + +#include +#include +#include + +#include +#include +#include +#include +#include +#include // Oid +#include + +namespace odb +{ + namespace pgsql + { + class connection; + + // Template argument is the section traits type. + // + template + class section_statements + { + public: + typedef ST traits; + + typedef typename traits::image_type image_type; + typedef typename traits::id_image_type id_image_type; + + typedef pgsql::select_statement select_statement_type; + typedef pgsql::update_statement update_statement_type; + + typedef pgsql::connection connection_type; + + section_statements (connection_type&, + image_type&, + id_image_type&, + binding& id, + binding& idv, + native_binding& idn, + const Oid* idt); + + connection_type& + connection () {return conn_;} + + const schema_version_migration& + version_migration (const char* name = "") const + { + if (svm_ == 0) + svm_ = &conn_.database ().schema_version_migration (name); + + return *svm_; + } + + image_type& + image () {return image_;} + + const binding& + id_binding () {return id_binding_;} + + // Id and optimistic concurrency version (if any). + // + const binding& + idv_binding () {return idv_binding_;} + + // Select binding. + // + std::size_t + select_image_version () const { return select_image_version_;} + + void + select_image_version (std::size_t v) {select_image_version_ = v;} + + binding& + select_image_binding () {return select_image_binding_;} + + bool* + select_image_truncated () {return select_image_truncated_;} + + // Update binding. + // + std::size_t + update_image_version () const { return update_image_version_;} + + void + update_image_version (std::size_t v) {update_image_version_ = v;} + + std::size_t + update_id_binding_version () const { return update_id_binding_version_;} + + void + update_id_binding_version (std::size_t v) {update_id_binding_version_ = v;} + + binding& + update_image_binding () {return update_image_binding_;} + + // + // Statements. + // + + select_statement_type& + select_statement () + { + if (select_ == 0) + select_.reset ( + new (details::shared) select_statement_type ( + conn_, + traits::select_name, + traits::select_statement, + traits::versioned, // Process if versioned. + false, // Don't optimize. + id_types_, + id_column_count, + id_binding_, + id_native_binding_, + select_image_binding_, + false)); + + return *select_; + } + + update_statement_type& + update_statement () + { + if (update_ == 0) + update_.reset ( + new (details::shared) update_statement_type ( + conn_, + traits::update_name, + traits::update_statement, + traits::versioned, // Process if versioned. + traits::update_types, + update_column_count + id_column_count + + managed_optimistic_update_column_count, + update_image_binding_, + update_image_native_binding_, + false)); + + return *update_; + } + + public: + static const std::size_t id_column_count = traits::id_column_count; + static const std::size_t managed_optimistic_load_column_count = + traits::managed_optimistic_load_column_count; + static const std::size_t managed_optimistic_update_column_count = + traits::managed_optimistic_update_column_count; + static const std::size_t select_column_count = traits::load_column_count; + static const std::size_t update_column_count = + traits::update_column_count; + + private: + section_statements (const section_statements&); + section_statements& operator= (const section_statements&); + + protected: + connection_type& conn_; + mutable const schema_version_migration* svm_; + + // These come from object_statements. + // + image_type& image_; + binding& id_binding_; + binding& idv_binding_; + native_binding& id_native_binding_; + const Oid* id_types_; + + // Select binding. + // + std::size_t select_image_version_; + + static const std::size_t select_bind_count = + select_column_count != 0 || managed_optimistic_load_column_count != 0 + ? select_column_count + managed_optimistic_load_column_count + : 1; + + binding select_image_binding_; + bind select_image_bind_[select_bind_count]; + bool select_image_truncated_[select_bind_count]; + + // Update binding. + // + std::size_t update_image_version_; + std::size_t update_id_binding_version_; + + static const std::size_t update_bind_count = + update_column_count != 0 || managed_optimistic_update_column_count != 0 + ? update_column_count + id_column_count + + managed_optimistic_update_column_count + : 1; + + binding update_image_binding_; + bind update_image_bind_[update_bind_count]; + + native_binding update_image_native_binding_; + char* update_image_values_[update_bind_count]; + int update_image_lengths_[update_bind_count]; + int update_image_formats_[update_bind_count]; + + details::shared_ptr select_; + details::shared_ptr update_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_SECTION_STATEMENTS_HXX diff --git a/libodb-pgsql/odb/pgsql/section-statements.txx b/libodb-pgsql/odb/pgsql/section-statements.txx new file mode 100644 index 0000000..55f4093 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/section-statements.txx @@ -0,0 +1,51 @@ +// file : odb/pgsql/section-statements.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::memset + +namespace odb +{ + namespace pgsql + { + template + section_statements:: + section_statements (connection_type& conn, + image_type& im, + id_image_type&, + binding& id, + binding& idv, + native_binding& idn, + const Oid* idt) + : conn_ (conn), + svm_ (0), + image_ (im), + id_binding_ (id), + idv_binding_ (idv), + id_native_binding_ (idn), + id_types_ (idt), + select_image_binding_ (select_image_bind_, + select_column_count + + managed_optimistic_load_column_count), + update_image_binding_ (update_image_bind_, + update_column_count + id_column_count + + managed_optimistic_update_column_count), + update_image_native_binding_ (update_image_values_, + update_image_lengths_, + update_image_formats_, + update_column_count + id_column_count + + managed_optimistic_update_column_count) + { + select_image_version_ = 0; + update_image_version_ = 0; + update_id_binding_version_ = 0; + + std::memset (select_image_bind_, 0, sizeof (select_image_bind_)); + std::memset ( + select_image_truncated_, 0, sizeof (select_image_truncated_)); + std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); + + for (std::size_t i (0); i < select_bind_count; ++i) + select_image_bind_[i].truncated = select_image_truncated_ + i; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/simple-object-result.hxx b/libodb-pgsql/odb/pgsql/simple-object-result.hxx new file mode 100644 index 0000000..7472cbe --- /dev/null +++ b/libodb-pgsql/odb/pgsql/simple-object-result.hxx @@ -0,0 +1,85 @@ +// file : odb/pgsql/simple-object-result.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_SIMPLE_OBJECT_RESULT_HXX +#define ODB_PGSQL_SIMPLE_OBJECT_RESULT_HXX + +#include + +#include // std::size_t + +#include +#include + +#include + +#include +#include // query_base +#include +#include + +namespace odb +{ + namespace pgsql + { + template + class object_result_impl: public odb::object_result_impl + { + public: + typedef odb::object_result_impl base_type; + + typedef typename base_type::id_type id_type; + typedef typename base_type::object_type object_type; + typedef typename base_type::pointer_type pointer_type; + + typedef object_traits_impl object_traits; + typedef typename base_type::pointer_traits pointer_traits; + + typedef typename object_traits::statements_type statements_type; + + virtual + ~object_result_impl (); + + object_result_impl (const query_base&, + details::shared_ptr, + statements_type&, + const schema_version_migration*); + + virtual void + load (object_type&, bool fetch); + + virtual id_type + load_id (); + + virtual void + next (); + + virtual void + cache (); + + virtual std::size_t + size (); + + virtual void + invalidate (); + + using base_type::current; + + private: + void + load_image (); + + private: + details::shared_ptr statement_; + statements_type& statements_; + object_traits_calls tc_; + std::size_t count_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_SIMPLE_OBJECT_RESULT_HXX diff --git a/libodb-pgsql/odb/pgsql/simple-object-result.txx b/libodb-pgsql/odb/pgsql/simple-object-result.txx new file mode 100644 index 0000000..c14d64b --- /dev/null +++ b/libodb-pgsql/odb/pgsql/simple-object-result.txx @@ -0,0 +1,158 @@ +// file : odb/pgsql/simple-object-result.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include + +#include + +namespace odb +{ + namespace pgsql + { + template + object_result_impl:: + ~object_result_impl () + { + if (!this->end_) + statement_->free_result (); + } + + template + void object_result_impl:: + invalidate () + { + if (!this->end_) + { + statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); + } + + template + object_result_impl:: + object_result_impl (const query_base&, + details::shared_ptr statement, + statements_type& statements, + const schema_version_migration* svm) + : base_type (statements.connection ()), + statement_ (statement), + statements_ (statements), + tc_ (svm), + count_ (0) + { + } + + template + void object_result_impl:: + load (object_type& obj, bool fetch) + { + if (fetch) + load_image (); + + // This is a top-level call so the statements cannot be locked. + // + assert (!statements_.locked ()); + typename statements_type::auto_lock l (statements_); + + object_traits::callback (this->db_, obj, callback_event::pre_load); + + typename object_traits::image_type& i (statements_.image ()); + tc_.init (obj, i, &this->db_); + + // Initialize the id image and binding and load the rest of the object + // (containers, etc). + // + typename object_traits::id_image_type& idi (statements_.id_image ()); + object_traits::init (idi, object_traits::id (i)); + + binding& idb (statements_.id_image_binding ()); + if (idi.version != statements_.id_image_version () || idb.version == 0) + { + object_traits::bind (idb.bind, idi); + statements_.id_image_version (idi.version); + idb.version++; + } + + tc_.load_ (statements_, obj, false); + statements_.load_delayed (tc_.version ()); + l.unlock (); + object_traits::callback (this->db_, obj, callback_event::post_load); + } + + template + typename object_result_impl::id_type + object_result_impl:: + load_id () + { + load_image (); + return object_traits::id (statements_.image ()); + } + + template + void object_result_impl:: + next () + { + this->current (pointer_type ()); + + if (statement_->next ()) + count_++; + else + { + statement_->free_result (); + this->end_ = true; + } + } + + template + void object_result_impl:: + load_image () + { + // The image can grow between calls to load() as a result of other + // statements execution. + // + typename object_traits::image_type& im (statements_.image ()); + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + tc_.bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + } + + select_statement::result r (statement_->load ()); + + if (r == select_statement::truncated) + { + if (tc_.grow (im, statements_.select_image_truncated ())) + im.version++; + + if (im.version != statements_.select_image_version ()) + { + binding& b (statements_.select_image_binding ()); + tc_.bind (b.bind, im, statement_select); + statements_.select_image_version (im.version); + b.version++; + statement_->reload (); + } + } + } + + template + void object_result_impl:: + cache () + { + } + + template + std::size_t object_result_impl:: + size () + { + return this->end_ ? count_ : statement_->result_size (); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/simple-object-statements.cxx b/libodb-pgsql/odb/pgsql/simple-object-statements.cxx new file mode 100644 index 0000000..432f990 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/simple-object-statements.cxx @@ -0,0 +1,15 @@ +// file : odb/pgsql/simple-object-statements.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + namespace pgsql + { + object_statements_base:: + ~object_statements_base () + { + } + } +} diff --git a/libodb-pgsql/odb/pgsql/simple-object-statements.hxx b/libodb-pgsql/odb/pgsql/simple-object-statements.hxx new file mode 100644 index 0000000..086ef5f --- /dev/null +++ b/libodb-pgsql/odb/pgsql/simple-object-statements.hxx @@ -0,0 +1,657 @@ +// file : odb/pgsql/simple-object-statements.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_SIMPLE_OBJECT_STATEMENTS_HXX +#define ODB_PGSQL_SIMPLE_OBJECT_STATEMENTS_HXX + +#include + +#include +#include +#include // std::size_t + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + // The extra_statement_cache class is only defined (and used) in + // the generated source file. However, object_statements may be + // referenced from another source file in the case of a polymorphic + // hierarchy (though in this case the extra statement cache is + // not used). As a result, we cannot have a by-value member and + // instead will store a pointer and lazily allocate the cache if + // and when needed. We will also need to store a pointer to the + // deleter function which will be initialized during allocation + // (at that point we know that the cache class is defined). + // + template + struct extra_statement_cache_ptr + { + typedef I image_type; + typedef ID id_image_type; + typedef pgsql::connection connection_type; + + extra_statement_cache_ptr (): p_ (0) {} + ~extra_statement_cache_ptr () + { + if (p_ != 0) + (this->*deleter_) (0, 0, 0, 0, 0, 0, 0); + } + + T& + get (connection_type& c, + image_type& im, + id_image_type& idim, + binding& id, + binding* idv, + native_binding& idn, + const Oid* idt) + { + if (p_ == 0) + allocate (&c, &im, &idim, &id, (idv != 0 ? idv : &id), &idn, idt); + + return *p_; + } + + private: + void + allocate (connection_type*, + image_type*, id_image_type*, + binding*, binding*, native_binding*, const Oid*); + + private: + T* p_; + void (extra_statement_cache_ptr::*deleter_) ( + connection_type*, + image_type*, id_image_type*, + binding*, binding*, native_binding*, const Oid*); + }; + + template + void extra_statement_cache_ptr:: + allocate (connection_type* c, + image_type* im, id_image_type* idim, + binding* id, binding* idv, native_binding* idn, const Oid* idt) + { + // To reduce object code size, this function acts as both allocator + // and deleter. + // + if (p_ == 0) + { + p_ = new T (*c, *im, *idim, *id, *idv, *idn, idt); + deleter_ = &extra_statement_cache_ptr::allocate; + } + else + delete p_; + } + + // + // Implementation for objects with object id. + // + + class LIBODB_PGSQL_EXPORT object_statements_base: public statements_base + { + public: + // Locking. + // + void + lock () + { + assert (!locked_); + locked_ = true; + } + + void + unlock () + { + assert (locked_); + locked_ = false; + } + + bool + locked () const + { + return locked_; + } + + struct auto_unlock + { + // Unlocks the statement on construction and re-locks it on + // destruction. + // + auto_unlock (object_statements_base&); + ~auto_unlock (); + + private: + auto_unlock (const auto_unlock&); + auto_unlock& operator= (const auto_unlock&); + + private: + object_statements_base& s_; + }; + + public: + virtual + ~object_statements_base (); + + protected: + object_statements_base (connection_type& conn) + : statements_base (conn), locked_ (false) + { + } + + protected: + bool locked_; + }; + + template + struct optimistic_data; + + template + struct optimistic_data + { + typedef T object_type; + typedef object_traits_impl object_traits; + + optimistic_data (bind*, char** nv, int* nl, int* nf, + std::size_t skip, unsigned long long* status); + + binding* + id_image_binding () {return &id_image_binding_;} + + native_binding* + id_image_native_binding () {return &id_image_native_binding_;} + + const Oid* + id_image_types () + {return object_traits::optimistic_erase_statement_types;} + + // The id + optimistic column binding. + // + binding id_image_binding_; + native_binding id_image_native_binding_; + + details::shared_ptr erase_; + }; + + template + struct optimistic_data + { + optimistic_data (bind*, char**, int*, int*, + std::size_t, unsigned long long*) {} + + binding* + id_image_binding () {return 0;} + + native_binding* + id_image_native_binding () {return 0;} + + const Oid* + id_image_types () {return 0;} + }; + + template + class object_statements: public object_statements_base + { + public: + typedef T object_type; + typedef object_traits_impl object_traits; + typedef typename object_traits::id_type id_type; + typedef typename object_traits::pointer_type pointer_type; + typedef typename object_traits::image_type image_type; + typedef typename object_traits::id_image_type id_image_type; + + typedef + typename object_traits::pointer_cache_traits + pointer_cache_traits; + + typedef + typename object_traits::extra_statement_cache_type + extra_statement_cache_type; + + typedef pgsql::insert_statement insert_statement_type; + typedef pgsql::select_statement select_statement_type; + typedef pgsql::update_statement update_statement_type; + typedef pgsql::delete_statement delete_statement_type; + + // Automatic lock. + // + struct auto_lock + { + // Lock the statements unless they are already locked in which + // case subsequent calls to locked() will return false. + // + auto_lock (object_statements&); + + // Unlock the statemens if we are holding the lock and clear + // the delayed loads. This should only happen in case an + // exception is thrown. In normal circumstances, the user + // should call unlock() explicitly. + // + ~auto_lock (); + + // Return true if this auto_lock instance holds the lock. + // + bool + locked () const; + + // Unlock the statemens. + // + void + unlock (); + + private: + auto_lock (const auto_lock&); + auto_lock& operator= (const auto_lock&); + + private: + object_statements& s_; + bool locked_; + }; + + public: + object_statements (connection_type&); + + virtual + ~object_statements (); + + // Delayed loading. + // + typedef void (*loader_function) (odb::database&, + const id_type&, + object_type&, + const schema_version_migration*); + void + delay_load (const id_type& id, + object_type& obj, + const typename pointer_cache_traits::position_type& p, + loader_function l = 0) + { + delayed_.push_back (delayed_load (id, obj, p, l)); + } + + void + load_delayed (const schema_version_migration* svm) + { + assert (locked ()); + + if (!delayed_.empty ()) + load_delayed_ (svm); + } + + void + clear_delayed () + { + if (!delayed_.empty ()) + clear_delayed_ (); + } + + // Object image. + // + image_type& + image (std::size_t i = 0) {return images_[i].obj;} + + // Insert binding. + // + std::size_t + insert_image_version () const { return insert_image_version_;} + + void + insert_image_version (std::size_t v) {insert_image_version_ = v;} + + binding& + insert_image_binding () {return insert_image_binding_;} + + // Update binding. + // + std::size_t + update_image_version () const { return update_image_version_;} + + void + update_image_version (std::size_t v) {update_image_version_ = v;} + + std::size_t + update_id_image_version () const { return update_id_image_version_;} + + void + update_id_image_version (std::size_t v) {update_id_image_version_ = v;} + + binding& + update_image_binding () {return update_image_binding_;} + + // Select binding. + // + std::size_t + select_image_version () const { return select_image_version_;} + + void + select_image_version (std::size_t v) {select_image_version_ = v;} + + binding& + select_image_binding () {return select_image_binding_;} + + bool* + select_image_truncated () {return select_image_truncated_;} + + // Object id image and binding. + // + id_image_type& + id_image (std::size_t i = 0) {return images_[i].id;} + + std::size_t + id_image_version () const {return id_image_version_;} + + void + id_image_version (std::size_t v) {id_image_version_ = v;} + + binding& + id_image_binding () {return id_image_binding_;} + + // Optimistic id + managed column image binding. It points to + // the same suffix as id binding and they are always updated + // at the same time. + // + binding& + optimistic_id_image_binding () {return od_.id_image_binding_;} + + // Statements. + // + insert_statement_type& + persist_statement () + { + if (persist_ == 0) + persist_.reset ( + new (details::shared) insert_statement_type ( + conn_, + object_traits::persist_statement_name, + object_traits::persist_statement, + object_traits::versioned, // Process if versioned. + object_traits::persist_statement_types, + insert_column_count, + insert_image_binding_, + insert_image_native_binding_, + (object_traits::auto_id ? &id_image_binding_ : 0), + false)); + + return *persist_; + } + + select_statement_type& + find_statement () + { + if (find_ == 0) + find_.reset ( + new (details::shared) select_statement_type ( + conn_, + object_traits::find_statement_name, + object_traits::find_statement, + object_traits::versioned, // Process if versioned. + false, // Don't optimize. + object_traits::find_statement_types, + id_column_count, + id_image_binding_, + id_image_native_binding_, + select_image_binding_, + false)); + + return *find_; + } + + update_statement_type& + update_statement () + { + if (update_ == 0) + update_.reset ( + new (details::shared) update_statement_type ( + conn_, + object_traits::update_statement_name, + object_traits::update_statement, + object_traits::versioned, // Process if versioned. + object_traits::update_statement_types, + update_column_count + id_column_count, + update_image_binding_, + update_image_native_binding_, + false)); + + return *update_; + } + + delete_statement_type& + erase_statement () + { + if (erase_ == 0) + erase_.reset ( + new (details::shared) delete_statement_type ( + conn_, + object_traits::erase_statement_name, + object_traits::erase_statement, + object_traits::find_statement_types, // The same as find (id). + id_column_count, + id_image_binding_, + id_image_native_binding_, + false)); + + return *erase_; + } + + delete_statement_type& + optimistic_erase_statement () + { + if (od_.erase_ == 0) + od_.erase_.reset ( + new (details::shared) delete_statement_type ( + conn_, + object_traits::optimistic_erase_statement_name, + object_traits::optimistic_erase_statement, + object_traits::optimistic_erase_statement_types, + id_column_count + managed_optimistic_column_count, + od_.id_image_binding_, + od_.id_image_native_binding_, + false)); + + return *od_.erase_; + } + + // Extra (container, section) statement cache. + // + extra_statement_cache_type& + extra_statement_cache () + { + return extra_statement_cache_.get ( + conn_, + images_[0].obj, + images_[0].id, + id_image_binding_, + od_.id_image_binding (), + id_image_native_binding_, + object_traits::find_statement_types); + } + + public: + // select = total - separate_load + // insert = total - inverse - managed_optimistic - auto_id + // update = total - inverse - managed_optimistic - id - readonly - + // separate_update + // + static const std::size_t select_column_count = + object_traits::column_count - + object_traits::separate_load_column_count; + + static const std::size_t id_column_count = + object_traits::id_column_count; + + static const std::size_t insert_column_count = + object_traits::column_count - + object_traits::inverse_column_count - + object_traits::managed_optimistic_column_count - + (object_traits::auto_id ? id_column_count : 0); + + static const std::size_t update_column_count = + insert_column_count - + (object_traits::auto_id ? 0 : id_column_count) - + object_traits::readonly_column_count - + object_traits::separate_update_column_count; + + static const std::size_t managed_optimistic_column_count = + object_traits::managed_optimistic_column_count; + + private: + object_statements (const object_statements&); + object_statements& operator= (const object_statements&); + + protected: + template + void + load_delayed_ (const schema_version_migration*); + + void + clear_delayed_ (); + + protected: + template + friend class polymorphic_derived_object_statements; + + extra_statement_cache_ptr extra_statement_cache_; + + // The UPDATE statement uses both the object and id image. Keep them + // next to each other so that the same skip distance can be used in + // batch binding. + // + struct images + { + image_type obj; + id_image_type id; + }; + + images images_[object_traits::batch]; + unsigned long long status_[object_traits::batch]; + + // Select binding. + // + std::size_t select_image_version_; + binding select_image_binding_; + bind select_image_bind_[select_column_count]; + bool select_image_truncated_[select_column_count]; + + // Insert binding. + // + std::size_t insert_image_version_; + binding insert_image_binding_; + bind insert_image_bind_[ + insert_column_count != 0 ? insert_column_count : 1]; + native_binding insert_image_native_binding_; + char* insert_image_values_[ + insert_column_count != 0 ? insert_column_count : 1]; + int insert_image_lengths_[ + insert_column_count != 0 ? insert_column_count : 1]; + int insert_image_formats_[ + insert_column_count != 0 ? insert_column_count : 1]; + + // Update binding. Note that the id suffix is bound to id_image_ + // below instead of image_ which makes this binding effectively + // bound to two images. As a result, we have to track versions + // for both of them. If this object uses optimistic concurrency, + // then the binding for the managed column (version, timestamp, + // etc) comes after the id and the image for such a column is + // stored as part of the id image. + // + std::size_t update_image_version_; + std::size_t update_id_image_version_; + binding update_image_binding_; + bind update_image_bind_[update_column_count + id_column_count + + managed_optimistic_column_count]; + native_binding update_image_native_binding_; + char* update_image_values_[update_column_count + id_column_count + + managed_optimistic_column_count]; + int update_image_lengths_[update_column_count + id_column_count + + managed_optimistic_column_count]; + int update_image_formats_[update_column_count + id_column_count + + managed_optimistic_column_count]; + + // Id image binding (only used as a parameter). Uses the suffix in + // the update bind. + // + std::size_t id_image_version_; + binding id_image_binding_; + native_binding id_image_native_binding_; + + // Extra data for objects with optimistic concurrency support. + // + optimistic_data od_; + + details::shared_ptr persist_; + details::shared_ptr find_; + details::shared_ptr update_; + details::shared_ptr erase_; + + // Delayed loading. + // + struct delayed_load + { + typedef typename pointer_cache_traits::position_type position_type; + + delayed_load () {} + delayed_load (const id_type& i, + object_type& o, + const position_type& p, + loader_function l) + : id (i), obj (&o), pos (p), loader (l) + { + } + + id_type id; + object_type* obj; + position_type pos; + loader_function loader; + }; + + typedef std::vector delayed_loads; + delayed_loads delayed_; + + // Delayed vectors swap guard. See the load_delayed_() function for + // details. + // + struct swap_guard + { + swap_guard (object_statements& os, delayed_loads& dl) + : os_ (os), dl_ (dl) + { + dl_.swap (os_.delayed_); + } + + ~swap_guard () + { + os_.clear_delayed (); + dl_.swap (os_.delayed_); + } + + private: + object_statements& os_; + delayed_loads& dl_; + }; + }; + } +} + +#include +#include + +#include + +#endif // ODB_PGSQL_SIMPLE_OBJECT_STATEMENTS_HXX diff --git a/libodb-pgsql/odb/pgsql/simple-object-statements.ixx b/libodb-pgsql/odb/pgsql/simple-object-statements.ixx new file mode 100644 index 0000000..fbb2775 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/simple-object-statements.ixx @@ -0,0 +1,68 @@ +// file : odb/pgsql/simple-object-statements.ixx +// license : GNU GPL v2; see accompanying LICENSE file + +namespace odb +{ + namespace pgsql + { + // + // auto_unlock + // + inline object_statements_base::auto_unlock:: + auto_unlock (object_statements_base& s) + : s_ (s) + { + s_.unlock (); + } + + inline object_statements_base::auto_unlock:: + ~auto_unlock () + { + s_.lock (); + } + + // + // auto_lock + // + template + inline object_statements::auto_lock:: + auto_lock (object_statements& s) + : s_ (s) + { + if (!s_.locked ()) + { + s_.lock (); + locked_ = true; + } + else + locked_ = false; + } + + template + inline object_statements::auto_lock:: + ~auto_lock () + { + if (locked_) + { + s_.unlock (); + s_.clear_delayed (); + } + } + + template + inline bool object_statements::auto_lock:: + locked () const + { + return locked_; + } + + template + inline void object_statements::auto_lock:: + unlock () + { + assert (locked_); + s_.unlock (); + locked_ = false; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/simple-object-statements.txx b/libodb-pgsql/odb/pgsql/simple-object-statements.txx new file mode 100644 index 0000000..bb47b43 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/simple-object-statements.txx @@ -0,0 +1,190 @@ +// file : odb/pgsql/simple-object-statements.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::memset + +#include +#include + +#include +#include + +namespace odb +{ + namespace pgsql + { + // + // optimistic_data + // + + template + optimistic_data:: + optimistic_data (bind* b, char** nv, int* nl, int* nf, + std::size_t skip, unsigned long long* status) + : id_image_binding_ ( + b, + object_traits::id_column_count + + object_traits::managed_optimistic_column_count, + object_traits::batch, + skip, + status), + id_image_native_binding_ ( + nv, nl, nf, + object_traits::id_column_count + + object_traits::managed_optimistic_column_count) + { + } + + // + // object_statements + // + + template + object_statements:: + ~object_statements () + { + } + + template + object_statements:: + object_statements (connection_type& conn) + : object_statements_base (conn), + // select + select_image_binding_ (select_image_bind_, select_column_count), + // insert + insert_image_binding_ (insert_image_bind_, + insert_column_count, + object_traits::batch, + sizeof (images), + status_), + insert_image_native_binding_ (insert_image_values_, + insert_image_lengths_, + insert_image_formats_, + insert_column_count), + // update + update_image_binding_ (update_image_bind_, + update_column_count + id_column_count + + managed_optimistic_column_count, + object_traits::batch, + sizeof (images), + status_), + update_image_native_binding_ (update_image_values_, + update_image_lengths_, + update_image_formats_, + update_column_count + id_column_count + + managed_optimistic_column_count), + // id + id_image_binding_ (update_image_bind_ + update_column_count, + id_column_count, + object_traits::batch, + sizeof (images), + status_), + id_image_native_binding_ ( + update_image_values_ + update_column_count, + update_image_lengths_ + update_column_count, + update_image_formats_ + update_column_count, + id_column_count), + // optimistic data + od_ (update_image_bind_ + update_column_count, + update_image_values_ + update_column_count, + update_image_lengths_ + update_column_count, + update_image_formats_ + update_column_count, + sizeof (images), + status_) + { + // Only versions in the first element used. + // + images_[0].obj.version = 0; + images_[0].id.version = 0; + + select_image_version_ = 0; + insert_image_version_ = 0; + update_image_version_ = 0; + update_id_image_version_ = 0; + id_image_version_ = 0; + + std::memset (insert_image_bind_, 0, sizeof (insert_image_bind_)); + std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); + std::memset (select_image_bind_, 0, sizeof (select_image_bind_)); + std::memset ( + select_image_truncated_, 0, sizeof (select_image_truncated_)); + + for (std::size_t i (0); i < select_column_count; ++i) + select_image_bind_[i].truncated = select_image_truncated_ + i; + } + + template + template + void object_statements:: + load_delayed_ (const schema_version_migration* svm) + { + database& db (connection ().database ()); + + delayed_loads dls; + swap_guard sg (*this, dls); + + while (!dls.empty ()) + { + delayed_load l (dls.back ()); + typename pointer_cache_traits::insert_guard ig (l.pos); + dls.pop_back (); + + if (l.loader == 0) + { + object_traits_calls tc (svm); + + if (!tc.find_ (static_cast (*this), &l.id)) + throw object_not_persistent (); + + object_traits::callback (db, *l.obj, callback_event::pre_load); + + // Our calls to init/load below can result in additional delayed + // loads being added to the delayed_ vector. We need to process + // those before we call the post callback. + // + tc.init (*l.obj, image (), &db); + + // Load containers, etc. + // + tc.load_ (static_cast (*this), *l.obj, false); + + if (!delayed_.empty ()) + load_delayed_ (svm); + + // Temporarily unlock the statement for the post_load call so that + // it can load objects of this type recursively. This is safe to do + // because we have completely loaded the current object. Also the + // delayed_ list is clear before the unlock and should be clear on + // re-lock (since a callback can only call public API functions + // which will make sure all the delayed loads are processed before + // returning). + // + { + auto_unlock u (*this); + object_traits::callback (db, *l.obj, callback_event::post_load); + } + } + else + l.loader (db, l.id, *l.obj, svm); + + pointer_cache_traits::load (ig.position ()); + ig.release (); + } + } + + template + void object_statements:: + clear_delayed_ () + { + // Remove the objects from the session cache. + // + for (typename delayed_loads::iterator i (delayed_.begin ()), + e (delayed_.end ()); i != e; ++i) + { + pointer_cache_traits::erase (i->pos); + } + + delayed_.clear (); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/statement-cache.hxx b/libodb-pgsql/odb/pgsql/statement-cache.hxx new file mode 100644 index 0000000..9417949 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/statement-cache.hxx @@ -0,0 +1,57 @@ +// file : odb/pgsql/statement-cache.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_STATEMENT_CACHE_HXX +#define ODB_PGSQL_STATEMENT_CACHE_HXX + +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + class statement_cache + { + public: + statement_cache (connection& conn) + : conn_ (conn), + version_seq_ (conn_.database ().schema_version_sequence ()) {} + + template + typename object_traits_impl::statements_type& + find_object (); + + template + view_statements& + find_view (); + + private: + typedef std::map, + details::type_info_comparator> map; + + connection& conn_; + unsigned int version_seq_; + map map_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_STATEMENT_CACHE_HXX diff --git a/libodb-pgsql/odb/pgsql/statement-cache.txx b/libodb-pgsql/odb/pgsql/statement-cache.txx new file mode 100644 index 0000000..488ba2c --- /dev/null +++ b/libodb-pgsql/odb/pgsql/statement-cache.txx @@ -0,0 +1,60 @@ +// file : odb/pgsql/statement-cache.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + namespace pgsql + { + template + typename object_traits_impl::statements_type& + statement_cache:: + find_object () + { + typedef + typename object_traits_impl::statements_type + statements_type; + + // Clear the cache if the database version has changed. This + // makes sure we don't re-use statements that correspond to + // the old schema. + // + if (version_seq_ != conn_.database ().schema_version_sequence ()) + { + map_.clear (); + version_seq_ = conn_.database ().schema_version_sequence (); + } + + map::iterator i (map_.find (&typeid (T))); + + if (i != map_.end ()) + return static_cast (*i->second); + + details::shared_ptr p ( + new (details::shared) statements_type (conn_)); + + map_.insert (map::value_type (&typeid (T), p)); + return *p; + } + + template + view_statements& statement_cache:: + find_view () + { + // We don't cache any statements for views so no need to clear + // the cache. + + map::iterator i (map_.find (&typeid (T))); + + if (i != map_.end ()) + return static_cast&> (*i->second); + + details::shared_ptr > p ( + new (details::shared) view_statements (conn_)); + + map_.insert (map::value_type (&typeid (T), p)); + return *p; + } + } +} diff --git a/libodb-pgsql/odb/pgsql/statement.cxx b/libodb-pgsql/odb/pgsql/statement.cxx new file mode 100644 index 0000000..8574c37 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/statement.cxx @@ -0,0 +1,1545 @@ +// file : odb/pgsql/statement.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // ODB_CXX11 + +#include + +#ifdef LIBPQ_HAS_PIPELINING +# ifndef _WIN32 +# include +# include +# endif +#endif + +#include // strcmp +#include // pair +#include + +#ifdef ODB_CXX11 +# include // strtoull +#else +# include // istringstream +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace std; + +namespace odb +{ + namespace pgsql + { + using namespace details; + + static unsigned long long + affected_row_count (PGresult* h) + { + const char* s (PQcmdTuples (h)); + unsigned long long count; + + if (s[0] != '\0' && s[1] == '\0') + count = static_cast (s[0] - '0'); + else + { +#ifdef ODB_CXX11 + count = strtoull (s, 0, 10); +#else + istringstream ss (s); + ss >> count; +#endif + } + + return count; + } + + // + // statement + // + + statement:: + ~statement () + { + try + { + deallocate (); + } + catch (...) + { + } + } + + void statement:: + deallocate () + { + if (!deallocated_) + { + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->deallocate (conn_, *this); + } + + string s ("deallocate \""); + s += name_; + s += "\""; + + deallocated_ = true; + auto_handle h (PQexec (conn_.handle (), s.c_str ())); + + if (!is_good_result (h)) + { + // When we try to execute an invalid statement, PG "poisons" the + // transaction (those "current transaction is aborted, commands + // ignored until end of transaction block" messages in the log). + // This includes prepared statement deallocations (quite a stupid + // decision, if you ask me). + // + // So what can happen in this situation is the deallocation fails + // but we ignore it because we are already unwinding the stack + // (i.e., the prepared statement execution has failed). Next the + // user fixes things (e.g., passes valid parameters) and tries to + // re-execute the same query. But since we have failed to deallocate + // the statement, we now cannot re-prepare it; the name is already + // in use. + // + // What can we do to fix this? One way would be to postpone the + // deallocation until after the transaction is rolled back. This, + // however, would require quite an elaborate machinery: connection + // will have to store a list of such statements, etc. A much simpler + // solution is to mark the connection as failed. While it maybe a + // bit less efficient, we assume this is an "exceptional" situation + // that doesn't occur often. The only potentially problematic case + // is if the user holds the pointer to the connection and runs + // multiple transactions on it. But in this case the user should + // check if the connection is still good after each failure anyway. + // + conn_.mark_failed (); + + translate_error (conn_, h); + } + } + } + + statement:: + statement (connection_type& conn, + const string& name, + const string& text, + statement_kind sk, + const binding* process, + bool optimize, + const Oid* types, + size_t types_count) + : conn_ (conn), + name_copy_ (name), name_ (name_copy_.c_str ()), + deallocated_ (false) + { + if (process == 0) + { + text_copy_ = text; + text_ = text_copy_.c_str (); + } + else + text_ = text.c_str (); // Temporary, see init(). + + init (sk, process, optimize, types, types_count); + + // + // If any code after this line throws, the statement will be leaked + // (on the server) since deallocate() won't be called for it. + // + } + + statement:: + statement (connection_type& conn, + const char* name, + const char* text, + statement_kind sk, + const binding* process, + bool optimize, + bool copy, + const Oid* types, + size_t types_count) + : conn_ (conn), deallocated_ (false) + { + if (copy) + { + name_copy_ = name; + name_ = name_copy_.c_str (); + } + else + name_ = name; + + if (process == 0 && copy) + { + text_copy_ = text; + text_ = text_copy_.c_str (); + } + else + text_ = text; // Potentially temporary, see init(). + + init (sk, process, optimize, types, types_count); + + // + // If any code after this line throws, the statement will be leaked + // (on the server) since deallocate() won't be called for it. + // + } + + void statement:: + init (statement_kind sk, + const binding* proc, + bool optimize, + const Oid* types, + size_t types_count) + { + if (proc != 0) + { + switch (sk) + { + case statement_select: + process_select (text_copy_, + text_, + &proc->bind->buffer, proc->count, sizeof (bind), + '"', '"', + optimize); + break; + case statement_insert: + process_insert (text_copy_, + text_, + &proc->bind->buffer, proc->count, sizeof (bind), + '$'); + break; + case statement_update: + process_update (text_copy_, + text_, + &proc->bind->buffer, proc->count, sizeof (bind), + '$'); + break; + case statement_delete: + assert (false); + } + + text_ = text_copy_.c_str (); + } + + // Empty statement. + // + if (*text_ == '\0') + { + deallocated_ = true; + return; + } + + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->prepare (conn_, *this); + } + + auto_handle h ( + PQprepare (conn_.handle (), + name_, + text_, + static_cast (types_count), + types)); + + if (!is_good_result (h)) + translate_error (conn_, h); + + // + // If any code after this line throws, the statement will be leaked + // (on the server) since deallocate() won't be called for it. + // + } + + const char* statement:: + text () const + { + return text_; + } + + template + static inline T* + offset (T* base, size_t count, size_t size) + { + return reinterpret_cast ( + reinterpret_cast (base) + count * size); + } + + void statement:: + bind_param (native_binding& ns, const binding& bs, size_t pos) + { + assert (ns.count == bs.count); + + for (size_t i (0); i < ns.count; ++i) + { + const bind& b (bs.bind[i]); + + ns.formats[i] = 1; + + bool* n (b.is_null != 0 ? offset (b.is_null, pos, bs.skip) : 0); + + if ((n != 0 && *n) || b.buffer == 0) // Handle NULL entries. + { + ns.values[i] = 0; + ns.lengths[i] = 0; + continue; + } + + ns.values[i] = static_cast (offset (b.buffer, pos, bs.skip)); + + size_t l (0); + + switch (b.type) + { + case bind::boolean_: + { + l = sizeof (bool); + break; + } + case bind::smallint: + { + l = sizeof (short); + break; + } + case bind::integer: + { + l = sizeof (int); + break; + } + case bind::bigint: + { + l = sizeof (long long); + break; + } + case bind::real: + { + l = sizeof (float); + break; + } + case bind::double_: + { + l = sizeof (double); + break; + } + case bind::date: + { + l = sizeof (int); + break; + } + case bind::time: + case bind::timestamp: + { + l = sizeof (long long); + break; + } + case bind::numeric: + case bind::text: + case bind::bytea: + case bind::varbit: + { + // In this case b.buffer is a pointer to pointer to buffer so we + // need to chase one level. + // + ns.values[i] = static_cast ( + *reinterpret_cast (ns.values[i])); + } + // Fall through. + case bind::bit: + { + l = *offset (b.size, pos, bs.skip); + break; + } + case bind::uuid: + { + // UUID is a 16-byte sequence. + // + l = 16; + break; + } + } + + ns.lengths[i] = static_cast (l); + } + } + + bool statement:: + bind_result (const binding& bs, + PGresult* result, + size_t row, + bool truncated, + size_t pos) + { + bool r (true); + int col_count (PQnfields (result)); + + int col (0); + for (size_t i (0); i != bs.count && col != col_count; ++i) + { + const bind& b (bs.bind[i]); + + if (b.buffer == 0) // Skip NULL entries. + continue; + + int c (col++); + + { + bool* t (b.truncated != 0 ? offset (b.truncated, pos, bs.skip) : 0); + + if (truncated && (t == 0 || !*t)) + continue; + + if (t != 0) + *t = false; + } + + // Check for NULL unless we are reloading a truncated result. + // + if (!truncated) + { + bool* n (offset (b.is_null, pos, bs.skip)); + + *n = PQgetisnull (result, static_cast (row), c) == 1; + + if (*n) + continue; + } + + void* buf (offset (b.buffer, pos, bs.skip)); + + const char* v (PQgetvalue (result, static_cast (row), c)); + + switch (b.type) + { + case bind::boolean_: + { + *static_cast (buf) = *reinterpret_cast (v); + break; + } + case bind::smallint: + case bind::integer: + case bind::bigint: + { + // If we are dealing with a custom schema, we may have a + // difference in the integer widths. Note also that we have + // to go to our endianness and back in order for casts to + // work properly. + // + long long i (0); + + switch (PQftype (result, c)) + { + case int2_oid: + { + i = endian_traits::ntoh (*reinterpret_cast (v)); + break; + } + case int4_oid: + { + i = endian_traits::ntoh (*reinterpret_cast (v)); + break; + } + case int8_oid: + { + i = endian_traits::ntoh ( + *reinterpret_cast (v)); + break; + } + default: + { + assert (false); // Column in the database is not an integer. + break; + } + } + + switch (b.type) + { + case bind::smallint: + { + *static_cast (buf) = + endian_traits::hton (static_cast (i)); + break; + } + case bind::integer: + { + *static_cast (buf) = + endian_traits::hton (static_cast (i)); + break; + } + case bind::bigint: + { + *static_cast (buf) = endian_traits::hton (i); + break; + } + default: + break; + } + + break; + } + case bind::real: + { + *static_cast (buf) = *reinterpret_cast (v); + break; + } + case bind::double_: + { + *static_cast (buf) = *reinterpret_cast (v); + break; + } + case bind::date: + { + *static_cast (buf) = *reinterpret_cast (v); + break; + } + case bind::time: + case bind::timestamp: + { + *static_cast (buf) = + *reinterpret_cast (v); + break; + } + case bind::numeric: + case bind::text: + case bind::bytea: + case bind::bit: + case bind::varbit: + { + // Currently this is neither supported (due to capacity) nor used + // in batches. + // +#ifdef LIBPGSQL_EXTRA_CHECKS + assert (pos == 0); +#endif + + *b.size = static_cast ( + PQgetlength (result, static_cast (row), c)); + + if (b.capacity < *b.size) + { + if (b.truncated) + *b.truncated = true; + + r = false; + continue; + } + + // In these cases b.buffer is a pointer to pointer to buffer so we + // need to chase one level. + // + if (b.type != bind::bit) + buf = *static_cast (buf); + + memcpy (buf, v, *b.size); + break; + } + case bind::uuid: + { + memcpy (buf, v, 16); + break; + } + } + } + + // Make sure that the number of columns in the result returned by + // the database matches the number that we expect. A common cause + // of this assertion is a native view with a number of data members + // not matching the number of columns in the SELECT-list. + // + assert (col == col_count); + + return r; + } + +#if defined(LIBPQ_HAS_PIPELINING) && !defined(_WIN32) + + // Note that this function always marks the connection as failed. + // + static void + translate_connection_error (connection& conn) + { + const char* m (PQerrorMessage (conn.handle ())); + + if (PQstatus (conn.handle ()) == CONNECTION_BAD) + { + conn.mark_failed (); + throw connection_lost (); + } + else + { + conn.mark_failed (); + throw database_exception (m != 0 ? m : "bad connection state"); + } + } + + // A RAII object for PGconn's non-blocking pipeline mode. + // + struct pipeline + { + connection& conn; + int sock; + + explicit + pipeline (connection& c) + : conn (c) + { + PGconn* ch (conn.handle ()); + + if ((sock = PQsocket (ch)) == -1 || + PQsetnonblocking (ch, 1) == -1 || + PQenterPipelineMode (ch) == 0) + { + translate_connection_error (conn); + } + } + + void + close (bool throw_ = true) + { + if (!conn.failed ()) + { + PGconn* ch (conn.handle ()); + + if (PQexitPipelineMode (ch) == 0 || + PQsetnonblocking (ch, 0) == -1) + { + if (throw_) + translate_connection_error (conn); + else + conn.mark_failed (); + } + } + } + + ~pipeline () + { + close (false); + } + + pair + wait (bool write, bool throw_ = true) + { + fd_set wds; + fd_set rds; + + for (;;) + { + if (write) + { + FD_ZERO (&wds); + FD_SET (sock, &wds); + } + + FD_ZERO (&rds); + FD_SET (sock, &rds); + + if (select (sock + 1, &rds, write ? &wds : 0, 0, 0) != -1) + break; + + if (errno != EINTR) + { + if (throw_) + translate_connection_error (conn); + else + { + conn.mark_failed (); + return pair (false, false); + } + } + } + + return pair (FD_ISSET (sock, &rds), + write && FD_ISSET (sock, &wds)); + } + }; + + // A RAII object for recovering from an error in a pipeline. + // + // Specifically, it reads and discards results until reaching + // PGRES_PIPELINE_SYNC. + // + struct pipeline_recovery + { + pipeline_recovery (pipeline& pl, bool wdone, bool sync) + : pl_ (&pl), wdone_ (wdone), sync_ (sync) + { + } + + ~pipeline_recovery () + { + if (pl_ != 0 && !pl_->conn.failed ()) + { + PGconn* ch (pl_->conn.handle ()); + + // This code runs as part of stack unwinding caused by an exception + // so if we encounter an error, we "upgrade" the existing exception + // by marking the connection as failed. + // + // The rest is essentially a special version of execute() below. + // + // Note that on the first iteration we may still have results from + // the previous call to PQconsumeInput() (and these results may + // be the entire outstanding sequence, in which case calling wait() + // will block indefinitely). + // + for (bool first (true);; first = false) + { + if (sync_) + { + assert (!wdone_); + + if (PQpipelineSync (ch) == 0) + break; + + sync_ = false; + } + + pair r (false, false); + + if (!first) + { + r = pl_->wait (!wdone_); + if (!r.first && !r.second) + break; + } + + if (r.first /* read */ || first) + { + if (r.first && PQconsumeInput (ch) == 0) + break; + + while (PQisBusy (ch) == 0) + { + auto_handle res (PQgetResult (ch)); + + // We should only get NULLs as well as PGRES_PIPELINE_ABORTED + // finished with PGRES_PIPELINE_SYNC. + // + if (res != 0) + { + ExecStatusType stat (PQresultStatus (res)); + + if (stat == PGRES_PIPELINE_SYNC) + return; + + assert (stat == PGRES_PIPELINE_ABORTED); + } + } + } + + if (r.second /* write */) + { + int r (PQflush (ch)); + if (r == -1) + break; + + if (r == 0) + wdone_ = true; + } + } + + pl_->conn.mark_failed (); + } + } + + void + cancel () + { + pl_ = 0; + } + + private: + pipeline* pl_; + bool wdone_; + bool sync_; + }; + + size_t statement:: + execute (const binding& param, + native_binding& native_param, + size_t n, + multiple_exceptions& mex, + bool (*process) (size_t, PGresult*, bool, void*), + void* data) + { + size_t i (0); // Parameter set being attempted. + mex.current (i); + + PGconn* ch (conn_.handle ()); + + pipeline pl (conn_); + + // True if we've written and read everything, respectively. + // + bool wdone (false), rdone (false); + + for (size_t wn (0), rn (0); !rdone; ) + { + // Note that there is a special version of this code above in + // ~pipeline_recovery(). + // + pair r (pl.wait (!wdone)); + + // Note that once we start the pipeline, any call that may throw + // without marking the connection as failed should be guarded by + // pipeline_recovery. + + // Try to minimize the chance of blocking the server by first + // processing the result and then sending more queries. + // + if (r.first /* read */) + { + if (PQconsumeInput (ch) == 0) + translate_connection_error (conn_); + + // Note that PQisBusy() will return 0 (and subsequent PQgetResult() + // -- NULL) if we have consumed all the results for the queries that + // we have sent so far. Thus the (wn > rn) condition. Note that for + // this to work correctly we have to count the PQpipelineSync() call + // below as one of the queries (since it has a separate result). + // + while (wn > rn && PQisBusy (ch) == 0) + { + auto_handle res (PQgetResult (ch)); + + ExecStatusType stat (PGRES_FATAL_ERROR); + bool gr (is_good_result (res, &stat)); + + if (stat == PGRES_PIPELINE_SYNC) + { + assert (wdone && rn == n); + rdone = true; + break; + } + + assert (rn != n); + ++rn; + + if (stat != PGRES_PIPELINE_ABORTED) + { + // translate_error() may throw an exception (e.g., deadlock) + // without marking the connection as failed. + // + { + pipeline_recovery plr (pl, wdone, wn < n); + + if (!process (i, res, gr, data)) + translate_error (conn_, res, i, &mex); + + plr.cancel (); + } + + mex.attempted (++i); + mex.current (i); + } + else + { + // Should we treat PGRES_PIPELINE_ABORTED entries as attempted + // or not? While we did issue PQsendQueryPrepared() for them, + // the server tells us that it did not attemp to execute them. + // So it feels like they should not be treated as attempted. + // + // Note that for this to fit into out multiple_exceptions model, + // such an incomplete batch should be fatal (otherwise we could + // end up with unattempted "holes"). This is currently the case + // for errors handled by translate_error() but not necessarily + // the case for those handled by the process function (e.g., + // duplicate id handled by process_insert_result() below). So in + // a somewhat hackish way we assume the error (e.g., duplicate + // id) will always be translated to an exception and pre-mark + // multiple_exceptions as fatal. + // + mex.fatal (true); + } + + // We get a NULL result after each query result. + // + { + PGresult* end (PQgetResult (ch)); + assert (end == 0); + } + } + } + + if (r.second /* write */) + { + // Send queries until we get blocked (write-biased). This feels like + // a better overall strategy to keep the server busy compared to + // sending one query at a time and then re-checking if there is + // anything to read because the results of INSERT/UPDATE/DELETE are + // presumably small and quite a few of them can get buffered before + // the server gets blocked. + // + for (;;) + { + if (wn < n) + { + bind_param (native_param, param, wn); + + if (PQsendQueryPrepared (ch, + name_, + static_cast (native_param.count), + native_param.values, + native_param.lengths, + native_param.formats, + 1) == 0) + translate_connection_error (conn_); + + if (++wn == n) + { + if (PQpipelineSync (ch) == 0) + translate_connection_error (conn_); + + // Count as one of the queries since it has a separate result. + // + ++wn; + } + } + + // PQflush() result: + // + // 0 -- success (queue is now empty) + // 1 -- blocked + // -1 -- error + // + int r (PQflush (ch)); + if (r == -1) + translate_connection_error (conn_); + + if (r == 0) + { + if (wn < n) + { + // If we continue here, then we are write-biased. And if we + // break, then we are read-biased. + // +#ifdef LIBPGSQL_READ_BIASED + break; +#else + continue; +#endif + } + + wdone = true; + } + + break; // Blocked or done. + } + } + } + + pl.close (); + return i; + } +#endif + + // + // select_statement + // + + select_statement:: + ~select_statement () + { + } + + select_statement:: + select_statement (connection_type& conn, + const std::string& name, + const std::string& text, + bool process, + bool optimize, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param, + binding& result) + : statement (conn, + name, text, statement_select, + (process ? &result : 0), optimize, + types, types_count), + param_ (¶m), + native_param_ (&native_param), + result_ (result), + row_count_ (0), + current_row_ (0) + { + } + + select_statement:: + select_statement (connection_type& conn, + const char* name, + const char* text, + bool process, + bool optimize, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param, + binding& result, + bool copy) + : statement (conn, + name, text, statement_select, + (process ? &result : 0), optimize, copy, + types, types_count), + param_ (¶m), + native_param_ (&native_param), + result_ (result), + row_count_ (0), + current_row_ (0) + { + } + + select_statement:: + select_statement (connection_type& conn, + const std::string& name, + const std::string& text, + bool process, + bool optimize, + binding& result) + : statement (conn, + name, text, statement_select, + (process ? &result : 0), optimize, + 0, 0), + param_ (0), + native_param_ (0), + result_ (result), + row_count_ (0), + current_row_ (0) + { + } + + select_statement:: + select_statement (connection_type& conn, + const char* name, + const char* text, + bool process, + bool optimize, + binding& result, + bool copy) + : statement (conn, + name, text, statement_select, + (process ? &result : 0), optimize, copy, + 0, 0), + param_ (0), + native_param_ (0), + result_ (result), + row_count_ (0), + current_row_ (0) + { + } + + select_statement:: + select_statement (connection_type& conn, + const std::string& name, + const std::string& text, + bool process, + bool optimize, + const Oid* types, + std::size_t types_count, + native_binding& native_param, + binding& result) + : statement (conn, + name, text, statement_select, + (process ? &result : 0), optimize, + types, types_count), + param_ (0), + native_param_ (&native_param), + result_ (result), + row_count_ (0), + current_row_ (0) + { + } + + void select_statement:: + execute () + { + handle_.reset (); + + if (param_ != 0) + bind_param (*native_param_, *param_); + + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + + bool in (native_param_ != 0); + + handle_.reset ( + PQexecPrepared (conn_.handle (), + name_, + in ? static_cast (native_param_->count) : 0, + in ? native_param_->values : 0, + in ? native_param_->lengths : 0, + in ? native_param_->formats : 0, + 1)); + + if (!is_good_result (handle_)) + translate_error (conn_, handle_); + + row_count_ = static_cast (PQntuples (handle_)); + current_row_ = 0; + } + + void select_statement:: + free_result () + { + handle_.reset (); + row_count_ = 0; + current_row_ = 0; + } + + bool select_statement:: + next () + { + if (current_row_ <= row_count_) + ++current_row_; + + return current_row_ <= row_count_; + } + + select_statement::result select_statement:: + load () + { + if (current_row_ > row_count_) + return no_data; + + assert (current_row_ > 0); + return bind_result (result_, handle_, current_row_ - 1) + ? success + : truncated; + } + + void select_statement:: + reload () + { + assert (current_row_ > 0); + assert (current_row_ <= row_count_); + + if (!bind_result (result_, handle_, current_row_ - 1, true)) + assert (false); + } + + // + // insert_statement + // + + insert_statement:: + ~insert_statement () + { + } + + insert_statement:: + insert_statement (connection_type& conn, + const string& name, + const string& text, + bool process, + const Oid* types, + size_t types_count, + binding& param, + native_binding& native_param, + binding* returning) + : statement (conn, + name, text, statement_insert, + (process ? ¶m : 0), false, + types, types_count), + param_ (param), + native_param_ (native_param), + returning_ (returning) + { + if (returning_ != 0) + assert (returning_->count == 1); + } + + insert_statement:: + insert_statement (connection_type& conn, + const char* name, + const char* text, + bool process, + const Oid* types, + size_t types_count, + binding& param, + native_binding& native_param, + binding* returning, + bool copy) + : statement (conn, + name, text, statement_insert, + (process ? ¶m : 0), false, copy, + types, types_count), + param_ (param), + native_param_ (native_param), + returning_ (returning) + { + if (returning_ != 0) + assert (returning_->count == 1); + } + + bool insert_statement:: + execute () + { + bind_param (native_param_, param_); + + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + + auto_handle h ( + PQexecPrepared (conn_.handle (), + name_, + static_cast (native_param_.count), + native_param_.values, + native_param_.lengths, + native_param_.formats, + 1)); + + ExecStatusType stat (PGRES_FATAL_ERROR); + + if (!is_good_result (h, &stat)) + { + // An auto-assigned object id should never cause a duplicate + // primary key. + // + if (returning_ == 0 && stat == PGRES_FATAL_ERROR) + { + const char* ss (PQresultErrorField (h, PG_DIAG_SQLSTATE)); + + if (ss != 0 && strcmp (ss, "23505") == 0) + return false; + } + + translate_error (conn_, h); + } + + if (returning_ != 0) + bind_result (*returning_, h, 0); + + return true; + } + +#if defined(LIBPQ_HAS_PIPELINING) && !defined(_WIN32) + + struct insert_data + { + binding& param; + binding* returning; + }; + + static bool + process_insert_result (size_t i, PGresult* r, bool gr, void* data) + { + insert_data& d (*static_cast (data)); + + unsigned long long& s (d.param.status[i]); + s = 1; + + if (gr) + { + // Note that the result can never be truncated. + // + if (d.returning != 0) + statement::bind_result (*d.returning, r, 0, false, i); + } + else + { + // An auto-assigned object id should never cause a duplicate + // primary key. + // + if (d.returning == 0 && + r != 0 && PQresultStatus (r) == PGRES_FATAL_ERROR) + { + // Note that statement::execute() assumes that this will eventually + // be translated to an entry in multiple_exceptions. + // + const char* ss (PQresultErrorField (r, PG_DIAG_SQLSTATE)); + + if (ss != 0 && strcmp (ss, "23505") == 0) + s = 0; + } + + if (s == 1) + return false; + } + + return true; + } + + size_t insert_statement:: + execute (size_t n, multiple_exceptions& mex) + { + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + + insert_data d {param_, returning_}; + + return statement::execute ( + param_, native_param_, n, mex, &process_insert_result, &d); + } +#endif + + // + // update_statement + // + + update_statement:: + ~update_statement () + { + } + + update_statement:: + update_statement (connection_type& conn, + const string& name, + const string& text, + bool process, + const Oid* types, + size_t types_count, + binding& param, + native_binding& native_param) + : statement (conn, + name, text, statement_update, + (process ? ¶m : 0), false, + types, types_count), + param_ (param), + native_param_ (native_param) + { + } + + update_statement:: + update_statement (connection_type& conn, + const char* name, + const char* text, + bool process, + const Oid* types, + size_t types_count, + binding& param, + native_binding& native_param, + bool copy) + : statement (conn, + name, text, statement_update, + (process ? ¶m : 0), false, copy, + types, types_count), + param_ (param), + native_param_ (native_param) + { + } + + unsigned long long update_statement:: + execute () + { + bind_param (native_param_, param_); + + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + + auto_handle h ( + PQexecPrepared (conn_.handle (), + name_, + static_cast (native_param_.count), + native_param_.values, + native_param_.lengths, + native_param_.formats, + 1)); + + if (!is_good_result (h)) + translate_error (conn_, h); + + return affected_row_count (h); + } + +#if defined(LIBPQ_HAS_PIPELINING) && !defined(_WIN32) + + static bool + process_update_result (size_t i, PGresult* r, bool gr, void* data) + { + binding& param (*static_cast (data)); + + unsigned long long& s (param.status[i]); + + if (gr) + { + s = affected_row_count (r); + return true; + } + else + { + s = update_statement::result_unknown; + return false; + } + } + + size_t update_statement:: + execute (size_t n, multiple_exceptions& mex) + { + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + + return statement::execute ( + param_, native_param_, n, mex, &process_update_result, ¶m_); + } +#endif + + // + // delete_statement + // + + delete_statement:: + ~delete_statement () + { + } + + delete_statement:: + delete_statement (connection_type& conn, + const string& name, + const string& text, + const Oid* types, + size_t types_count, + binding& param, + native_binding& native_param) + : statement (conn, + name, text, statement_delete, + 0, false, + types, types_count), + param_ (¶m), + native_param_ (native_param) + { + } + + delete_statement:: + delete_statement (connection_type& conn, + const char* name, + const char* text, + const Oid* types, + size_t types_count, + binding& param, + native_binding& native_param, + bool copy) + : statement (conn, + name, text, statement_delete, + 0, false, copy, + types, types_count), + param_ (¶m), + native_param_ (native_param) + { + } + + delete_statement:: + delete_statement (connection_type& conn, + const string& name, + const string& text, + const Oid* types, + size_t types_count, + native_binding& native_param) + : statement (conn, + name, text, statement_delete, + 0, false, + types, types_count), + param_ (0), + native_param_ (native_param) + { + } + + unsigned long long delete_statement:: + execute () + { + if (param_ != 0) + bind_param (native_param_, *param_); + + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + + auto_handle h ( + PQexecPrepared (conn_.handle (), + name_, + static_cast (native_param_.count), + native_param_.values, + native_param_.lengths, + native_param_.formats, + 1)); + + if (!is_good_result (h)) + translate_error (conn_, h); + + return affected_row_count (h); + } + +#if defined(LIBPQ_HAS_PIPELINING) && !defined(_WIN32) + + static bool + process_delete_result (size_t i, PGresult* r, bool gr, void* data) + { + binding& param (*static_cast (data)); + + unsigned long long& s (param.status[i]); + + if (gr) + { + s = affected_row_count (r); + return true; + } + else + { + s = delete_statement::result_unknown; + return false; + } + } + + size_t delete_statement:: + execute (size_t n, multiple_exceptions& mex) + { + assert (param_ != 0); + + { + odb::tracer* t; + if ((t = conn_.transaction_tracer ()) || + (t = conn_.tracer ()) || + (t = conn_.database ().tracer ())) + t->execute (conn_, *this); + } + + return statement::execute ( + *param_, native_param_, n, mex, &process_delete_result, param_); + } +#endif + } +} diff --git a/libodb-pgsql/odb/pgsql/statement.hxx b/libodb-pgsql/odb/pgsql/statement.hxx new file mode 100644 index 0000000..139d2d6 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/statement.hxx @@ -0,0 +1,450 @@ +// file : odb/pgsql/statement.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_STATEMENT_HXX +#define ODB_PGSQL_STATEMENT_HXX + +#include + +#include +#include // std::size_t + +#include + +#include +#include +#include +#include // PGresult +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + class connection; + + class LIBODB_PGSQL_EXPORT statement: public odb::statement + { + public: + typedef pgsql::connection connection_type; + + virtual + ~statement () = 0; + + const char* + name () const + { + return name_; + } + + virtual const char* + text () const; + + virtual connection_type& + connection () + { + return conn_; + } + + // A statement can be empty. This is used to handle situations + // where a SELECT or UPDATE statement ends up not having any + // columns after processing. An empty statement cannot be + // executed. + // + bool + empty () const + { + return *text_ == '\0'; + } + + void + deallocate (); + + // Adapt an ODB binding to a native PostgreSQL parameter binding. If pos + // is not 0, then bind the parameter set at this position in a batch. + // + static void + bind_param (native_binding&, const binding&, std::size_t pos = 0); + + // Populate an ODB binding given a PostgreSQL result. If the truncated + // argument is true, then only truncated columns are extracted. Return + // true if all the data was extracted successfully and false if one or + // more columns were truncated. If pos is not 0, then populate the + // parameter set at this position in a batch. + // + static bool + bind_result (const binding&, + PGresult*, + std::size_t row, + bool truncated = false, + std::size_t pos = 0); + + protected: + // We keep two versions to take advantage of std::string COW. + // + statement (connection_type&, + const std::string& name, + const std::string& text, + statement_kind, + const binding* process, + bool optimize, + const Oid* types, + std::size_t types_count); + + statement (connection_type&, + const char* name, + const char* text, + statement_kind, + const binding* process, + bool optimize, + bool copy_name_text, + const Oid* types, + std::size_t types_count); + + // Bulk execute implementation. + // + std::size_t + execute (const binding& param, + native_binding& native_param, + std::size_t n, + multiple_exceptions&, + bool (*process) (size_t i, PGresult*, bool good, void* data), + void* data); + + private: + void + init (statement_kind, + const binding* process, + bool optimize, + const Oid* types, + std::size_t types_count); + + protected: + connection_type& conn_; + + std::string name_copy_; + const char* name_; + + std::string text_copy_; + const char* text_; + + private: + bool deallocated_; + }; + + class LIBODB_PGSQL_EXPORT select_statement: public statement + { + public: + virtual + ~select_statement (); + + select_statement (connection_type& conn, + const std::string& name, + const std::string& text, + bool process_text, + bool optimize_text, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param, + binding& result); + + select_statement (connection_type& conn, + const char* name, + const char* stmt, + bool process_text, + bool optimize_text, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param, + binding& result, + bool copy_name_text = true); + + select_statement (connection_type& conn, + const std::string& name, + const std::string& text, + bool process_text, + bool optimize_text, + binding& result); + + select_statement (connection_type& conn, + const char* name, + const char* text, + bool process_text, + bool optimize_text, + binding& result, + bool copy_name_text = true); + + select_statement (connection_type& conn, + const std::string& name, + const std::string& text, + bool process_text, + bool optimize_text, + const Oid* types, + std::size_t types_count, + native_binding& native_param, + binding& result); + + // Common select interface expected by the generated code. + // + public: + enum result + { + success, + no_data, + truncated + }; + + void + execute (); + + void + cache () const + { + } + + std::size_t + result_size () const + { + return row_count_; + } + + // Load next row columns into bound buffers. + // + result + fetch () + { + return next () ? load () : no_data; + } + + // Reload truncated columns into bound buffers. + // + void + refetch () + { + reload (); + } + + // Free the result set. + // + void + free_result (); + + // Finer grained control of PostgreSQL-specific interface that + // splits fetch() into next() and load(). + // + public: + bool + next (); + + result + load (); + + void + reload (); + + private: + select_statement (const select_statement&); + select_statement& operator= (const select_statement&); + + private: + binding* param_; + native_binding* native_param_; + + binding& result_; + + auto_handle handle_; + std::size_t row_count_; + std::size_t current_row_; + }; + + struct LIBODB_PGSQL_EXPORT auto_result + { + explicit auto_result (select_statement& s): s_ (s) {} + ~auto_result () {s_.free_result ();} + + private: + auto_result (const auto_result&); + auto_result& operator= (const auto_result&); + + private: + select_statement& s_; + }; + + class LIBODB_PGSQL_EXPORT insert_statement: public statement + { + public: + virtual + ~insert_statement (); + + insert_statement (connection_type& conn, + const std::string& name, + const std::string& text, + bool process_text, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param, + binding* returning); + + insert_statement (connection_type& conn, + const char* name, + const char* text, + bool process_text, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param, + binding* returning, + bool copy_name_text = true); + + // Return true if successful and false if the row is a duplicate. + // All other errors are reported by throwing exceptions. + // + bool + execute (); + + // Return the number of parameter sets (out of n) that were attempted. + // + std::size_t + execute (std::size_t n, multiple_exceptions&); + + // Return true if successful and false if this row is a duplicate. + // All other errors are reported via exceptions. + // + bool + result (std::size_t i) + { + return param_.status[i] != 0; + } + + private: + insert_statement (const insert_statement&); + insert_statement& operator= (const insert_statement&); + + private: + binding& param_; + native_binding& native_param_; + binding* returning_; + }; + + class LIBODB_PGSQL_EXPORT update_statement: public statement + { + public: + virtual + ~update_statement (); + + update_statement (connection_type& conn, + const std::string& name, + const std::string& text, + bool process_text, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param); + + update_statement (connection_type& conn, + const char* name, + const char* text, + bool process_text, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param, + bool copy_name_text = true); + + unsigned long long + execute (); + + // Return the number of parameter sets (out of n) that were attempted. + // + std::size_t + execute (std::size_t n, multiple_exceptions&); + + // Return the number of rows affected (updated) by the parameter + // set. All errors are reported by throwing exceptions. + // + static const unsigned long long result_unknown = ~0ULL; + + unsigned long long + result (std::size_t i) + { + return param_.status[i]; + } + + private: + update_statement (const update_statement&); + update_statement& operator= (const update_statement&); + + private: + binding& param_; + native_binding& native_param_; + }; + + class LIBODB_PGSQL_EXPORT delete_statement: public statement + { + public: + virtual + ~delete_statement (); + + delete_statement (connection_type& conn, + const std::string& name, + const std::string& text, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param); + + delete_statement (connection_type& conn, + const char* name, + const char* text, + const Oid* types, + std::size_t types_count, + binding& param, + native_binding& native_param, + bool copy_name_text = true); + + delete_statement (connection_type& conn, + const std::string& name, + const std::string& text, + const Oid* types, + std::size_t types_count, + native_binding& native_param); + + unsigned long long + execute (); + + // Return the number of parameter sets (out of n) that were attempted. + // + std::size_t + execute (std::size_t n, multiple_exceptions&); + + // Return the number of rows affected (deleted) by the parameter + // set. All errors are reported by throwing exceptions. + // + static const unsigned long long result_unknown = ~0ULL; + + unsigned long long + result (std::size_t i) + { + return param_->status[i]; + } + + private: + delete_statement (const delete_statement&); + delete_statement& operator= (const delete_statement&); + + private: + binding* param_; + native_binding& native_param_; + }; + } +} + +#include + +#endif // ODB_PGSQL_STATEMENT_HXX diff --git a/libodb-pgsql/odb/pgsql/statements-base.cxx b/libodb-pgsql/odb/pgsql/statements-base.cxx new file mode 100644 index 0000000..0e72555 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/statements-base.cxx @@ -0,0 +1,15 @@ +// file : odb/pgsql/statements-base.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +namespace odb +{ + namespace pgsql + { + statements_base:: + ~statements_base () + { + } + } +} diff --git a/libodb-pgsql/odb/pgsql/statements-base.hxx b/libodb-pgsql/odb/pgsql/statements-base.hxx new file mode 100644 index 0000000..8b45bdc --- /dev/null +++ b/libodb-pgsql/odb/pgsql/statements-base.hxx @@ -0,0 +1,63 @@ +// file : odb/pgsql/statements-base.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_STATEMENTS_BASE_HXX +#define ODB_PGSQL_STATEMENTS_BASE_HXX + +#include + +#include +#include + +#include +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + class LIBODB_PGSQL_EXPORT statements_base: public details::shared_base + { + public: + typedef pgsql::connection connection_type; + + connection_type& + connection () + { + return conn_; + } + + // Schema version. database::schema_version_migration() is thread- + // safe which means it is also slow. Cache the result in statements + // so we can avoid the mutex lock. This is thread-safe since if the + // version is updated, then the statements cache will be expired. + // + const schema_version_migration& + version_migration (const char* name = "") const + { + if (svm_ == 0) + svm_ = &conn_.database ().schema_version_migration (name); + + return *svm_; + } + + public: + virtual + ~statements_base (); + + protected: + statements_base (connection_type& conn): conn_ (conn), svm_ (0) {} + + protected: + connection_type& conn_; + mutable const schema_version_migration* svm_; + }; + } +} + +#include + +#endif // ODB_PGSQL_STATEMENTS_BASE_HXX diff --git a/libodb-pgsql/odb/pgsql/tracer.cxx b/libodb-pgsql/odb/pgsql/tracer.cxx new file mode 100644 index 0000000..48e0cf8 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/tracer.cxx @@ -0,0 +1,60 @@ +// file : odb/pgsql/tracer.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + tracer:: + ~tracer () + { + } + + void tracer:: + prepare (connection&, const statement&) + { + } + + void tracer:: + execute (connection& c, const statement& s) + { + execute (c, s.text ()); + } + + void tracer:: + deallocate (connection&, const statement&) + { + } + + void tracer:: + prepare (odb::connection& c, const odb::statement& s) + { + prepare (static_cast (c), + static_cast (s)); + } + + void tracer:: + execute (odb::connection& c, const odb::statement& s) + { + execute (static_cast (c), + static_cast (s)); + } + + void tracer:: + execute (odb::connection& c, const char* s) + { + execute (static_cast (c), s); + } + + void tracer:: + deallocate (odb::connection& c, const odb::statement& s) + { + deallocate (static_cast (c), + static_cast (s)); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/tracer.hxx b/libodb-pgsql/odb/pgsql/tracer.hxx new file mode 100644 index 0000000..89cda1c --- /dev/null +++ b/libodb-pgsql/odb/pgsql/tracer.hxx @@ -0,0 +1,61 @@ +// file : odb/pgsql/tracer.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_TRACER_HXX +#define ODB_PGSQL_TRACER_HXX + +#include + +#include + +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + class LIBODB_PGSQL_EXPORT tracer: private odb::tracer + { + public: + virtual + ~tracer (); + + virtual void + prepare (connection&, const statement&); + + virtual void + execute (connection&, const statement&); + + virtual void + execute (connection&, const char* statement) = 0; + + virtual void + deallocate (connection&, const statement&); + + private: + // Allow these classes to convert pgsql::tracer to odb::tracer. + // + friend class database; + friend class connection; + friend class transaction; + + virtual void + prepare (odb::connection&, const odb::statement&); + + virtual void + execute (odb::connection&, const odb::statement&); + + virtual void + execute (odb::connection&, const char* statement); + + virtual void + deallocate (odb::connection&, const odb::statement&); + }; + } +} + +#include + +#endif // ODB_PGSQL_TRACER_HXX diff --git a/libodb-pgsql/odb/pgsql/traits-calls.hxx b/libodb-pgsql/odb/pgsql/traits-calls.hxx new file mode 100644 index 0000000..419c7b2 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/traits-calls.hxx @@ -0,0 +1,214 @@ +// file : odb/pgsql/traits-calls.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_TRAITS_CALLS_HXX +#define ODB_PGSQL_TRAITS_CALLS_HXX + +#include + +#include // std::size_t + +#include +#include +#include + +#include +#include + +namespace odb +{ + namespace pgsql + { + // + // object_traits_calls + // + + template ::versioned> + struct object_traits_calls; + + template + struct object_traits_calls + { + typedef object_traits_impl traits; + typedef typename traits::image_type image_type; + typedef pgsql::bind bind_type; + + object_traits_calls (const schema_version_migration*) {} + + const schema_version_migration* + version () const {return 0;} + + static bool + grow (image_type& i, bool* t) + { + return traits::grow (i, t); + } + + static void + bind (bind_type* b, image_type& i, statement_kind sk) + { + traits::bind (b, i, sk); + } + + // Poly-derived version. + // + static void + bind (bind_type* b, + const bind_type* id, std::size_t id_size, + image_type& i, + statement_kind sk) + { + traits::bind (b, id, id_size, i, sk); + } + + static void + init (T& o, const image_type& i, odb::database* db) + { + traits::init (o, i, db); + } + + static bool + find_ (typename traits::statements_type& sts, + const typename traits::id_type* id) + { + return traits::find_ (sts, id); + } + + static void + load_ (typename traits::statements_type& sts, T& o, bool reload) + { + return traits::load_ (sts, o, reload); + } + }; + + template + struct object_traits_calls + { + typedef object_traits_impl traits; + typedef typename traits::image_type image_type; + typedef pgsql::bind bind_type; + + object_traits_calls (const schema_version_migration* svm): svm_ (*svm) {} + + const schema_version_migration* + version () const {return &svm_;} + + bool + grow (image_type& i, bool* t) const + { + return traits::grow (i, t, svm_); + } + + void + bind (bind_type* b, image_type& i, statement_kind sk) const + { + traits::bind (b, i, sk, svm_); + } + + // Poly-derived version. + // + void + bind (bind_type* b, + const bind_type* id, std::size_t id_size, + image_type& i, + statement_kind sk) const + { + traits::bind (b, id, id_size, i, sk, svm_); + } + + void + init (T& o, const image_type& i, odb::database* db) const + { + traits::init (o, i, db, svm_); + } + + bool + find_ (typename traits::statements_type& sts, + const typename traits::id_type* id) const + { + return traits::find_ (sts, id, svm_); + } + + void + load_ (typename traits::statements_type& sts, T& o, bool reload) const + { + return traits::load_ (sts, o, reload, svm_); + } + + private: + const schema_version_migration& svm_; + }; + + // + // view_traits_calls + // + + template ::versioned> + struct view_traits_calls; + + template + struct view_traits_calls + { + typedef view_traits_impl traits; + typedef typename traits::image_type image_type; + typedef pgsql::bind bind_type; + + view_traits_calls (const schema_version_migration*) {} + + static bool + grow (image_type& i, bool* t) + { + return traits::grow (i, t); + } + + static void + bind (bind_type* b, image_type& i) + { + traits::bind (b, i); + } + + static void + init (T& o, const image_type& i, odb::database* db) + { + traits::init (o, i, db); + } + }; + + template + struct view_traits_calls + { + typedef view_traits_impl traits; + typedef typename traits::image_type image_type; + typedef pgsql::bind bind_type; + + view_traits_calls (const schema_version_migration* svm): svm_ (*svm) {} + + bool + grow (image_type& i, bool* t) const + { + return traits::grow (i, t, svm_); + } + + void + bind (bind_type* b, image_type& i) const + { + traits::bind (b, i, svm_); + } + + void + init (T& o, const image_type& i, odb::database* db) const + { + traits::init (o, i, db, svm_); + } + + private: + const schema_version_migration& svm_; + }; + } +} + +#include + +#endif // ODB_PGSQL_TRAITS_CALLS_HXX diff --git a/libodb-pgsql/odb/pgsql/traits.cxx b/libodb-pgsql/odb/pgsql/traits.cxx new file mode 100644 index 0000000..11a3a67 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/traits.cxx @@ -0,0 +1,143 @@ +// file : odb/pgsql/traits.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +using namespace std; + +namespace odb +{ + namespace pgsql + { + using details::buffer; + + // + // default_value_traits + // + void default_value_traits:: + set_image (buffer& b, + size_t& n, + bool& is_null, + const string& v) + { + is_null = false; + n = v.size (); + + if (n > b.capacity ()) + b.capacity (n); + + if (n != 0) + memcpy (b.data (), v.c_str (), n); + } + + // + // c_string_value_traits + // + void c_string_value_traits:: + set_image (buffer& b, + size_t& n, + bool& is_null, + const char* v) + { + is_null = false; + n = strlen (v); + + if (n > b.capacity ()) + b.capacity (n); + + if (n != 0) + memcpy (b.data (), v, n); + } + + // + // c_array_value_traits_base + // + void c_array_value_traits_base:: + set_value (char* const& v, + const details::buffer& b, + size_t n, + bool is_null, + size_t N) + { + if (!is_null) + { + n = n < N ? n : N; + + if (n != 0) + memcpy (v, b.data (), n); + } + else + n = 0; + + if (n != N) // Append '\0' if there is space. + v[n] = '\0'; + } + + void c_array_value_traits_base:: + set_image (details::buffer& b, + size_t& n, + bool& is_null, + const char* v, + size_t N) + { + is_null = false; + + // Figure out the length. We cannot use strlen since it may + // not be 0-terminated (strnlen is not standard). + // + for (n = 0; n != N && v[n] != '\0'; ++n) ; + + if (n > b.capacity ()) + b.capacity (n); + + if (n != 0) + memcpy (b.data (), v, n); + } + + // + // default_value_traits, id_bytea> + // + // std::vector has to be qualified for Sun CC. + // + void default_value_traits, id_bytea>:: + set_image (details::buffer& b, + size_t& n, + bool& is_null, + const value_type& v) + { + is_null = false; + n = v.size (); + + if (n > b.capacity ()) + b.capacity (n); + + // std::vector::data() may not be available in older compilers. + // + if (n != 0) + memcpy (b.data (), &v.front (), n); + } + + // + // default_value_traits, id_bytea> + // + // std::vector has to be qualified for Sun CC. + // + void default_value_traits, id_bytea>:: + set_image (details::buffer& b, + size_t& n, + bool& is_null, + const value_type& v) + { + is_null = false; + n = v.size (); + + if (n > b.capacity ()) + b.capacity (n); + + // std::vector::data() may not be available in older compilers. + // + if (n != 0) + memcpy (b.data (), &v.front (), n); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/traits.hxx b/libodb-pgsql/odb/pgsql/traits.hxx new file mode 100644 index 0000000..3d87033 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/traits.hxx @@ -0,0 +1,944 @@ +// file : odb/pgsql/traits.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_TRAITS_HXX +#define ODB_PGSQL_TRAITS_HXX + +#include + +#include // ODB_CXX11 + +#include +#include +#include // std::size_t +#include // std::memcpy, std::memset, std::strlen + +#ifdef ODB_CXX11 +# include +#endif + +#include +#include + +#include +#include + +#include +#include + +#include +#include + +namespace odb +{ + namespace pgsql + { + enum database_type_id + { + id_boolean, + id_smallint, + id_integer, + id_bigint, + + id_numeric, // Internal PostgreSQL binary representation. + + id_real, + id_double, + + id_date, + id_time, + id_timestamp, + + id_string, + id_bytea, + id_bit, + id_varbit, + + id_uuid + }; + + // + // image_traits + // + + template + struct image_traits; + + template <> + struct image_traits {typedef bool image_type;}; + + template <> + struct image_traits {typedef short image_type;}; + + template <> + struct image_traits {typedef int image_type;}; + + template <> + struct image_traits {typedef long long image_type;}; + + template <> + struct image_traits {typedef details::buffer image_type;}; + + template <> + struct image_traits {typedef float image_type;}; + + template <> + struct image_traits {typedef double image_type;}; + + template <> + struct image_traits {typedef int image_type;}; + + template <> + struct image_traits {typedef long long image_type;}; + + template <> + struct image_traits {typedef long long image_type;}; + + template <> + struct image_traits {typedef details::buffer image_type;}; + + template <> + struct image_traits {typedef details::buffer image_type;}; + + template <> + struct image_traits {typedef unsigned char* image_type;}; + + template <> + struct image_traits {typedef details::ubuffer image_type;}; + + // UUID image is a 16-byte sequence. + // + template <> + struct image_traits {typedef unsigned char* image_type;}; + + // + // value_traits + // + + template + struct wrapped_value_traits; + + template + struct default_value_traits; + + template ::r> + struct select_traits; + + template + struct select_traits + { + typedef default_value_traits type; + }; + + template + struct select_traits + { + typedef + wrapped_value_traits::null_handler> + type; + }; + + template + class value_traits: public select_traits::type + { + }; + + // The wrapped_value_traits specializations should be able to handle + // any value type which means we have to have every possible signature + // of the set_value() and set_image() functions. + // + template + struct wrapped_value_traits + { + typedef wrapper_traits wtraits; + typedef typename wtraits::unrestricted_wrapped_type wrapped_type; + + typedef W value_type; + typedef wrapped_type query_type; + typedef typename image_traits::image_type image_type; + + typedef value_traits vtraits; + + static void + set_value (W& v, const image_type& i, bool is_null) + { + vtraits::set_value (wtraits::set_ref (v), i, is_null); + } + + static void + set_image (image_type& i, bool& is_null, const W& v) + { + vtraits::set_image (i, is_null, wtraits::get_ref (v)); + } + + // String, BYTEA, and NUMERIC. + // + static void + set_value (W& v, const details::buffer& b, std::size_t n, bool is_null) + { + vtraits::set_value (wtraits::set_ref (v), b, n, is_null); + } + + static void + set_image (details::buffer& b, std::size_t& n, bool& is_null, const W& v) + { + vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); + } + + // BIT. + // + static void + set_value (W& v, const unsigned char* i, std::size_t n, bool is_null) + { + vtraits::set_value (wtraits::set_ref (v), i, n, is_null); + } + + static void + set_image (unsigned char* i, + std::size_t c, + std::size_t& n, + bool& is_null, + const W& v) + { + vtraits::set_image (i, c, n, is_null, wtraits::get_ref (v)); + } + + // VARBIT. + // + static void + set_value (W& v, const details::ubuffer& b, std::size_t n, bool is_null) + { + vtraits::set_value (wtraits::set_ref (v), b, n, is_null); + } + + static void + set_image (details::ubuffer& b, + std::size_t& n, + bool& is_null, + const W& v) + { + vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); + } + + // UUID. + // + static void + set_value (W& v, const unsigned char* i, bool is_null) + { + vtraits::set_value (wtraits::set_ref (v), i, is_null); + } + + static void + set_image (unsigned char* i, bool& is_null, const W& v) + { + vtraits::set_image (i, is_null, wtraits::get_ref (v)); + } + }; + + template + struct wrapped_value_traits + { + typedef wrapper_traits wtraits; + typedef typename wtraits::unrestricted_wrapped_type wrapped_type; + + typedef W value_type; + typedef wrapped_type query_type; + typedef typename image_traits::image_type image_type; + + typedef value_traits vtraits; + + static void + set_value (W& v, const image_type& i, bool is_null) + { + if (is_null) + wtraits::set_null (v); + else + vtraits::set_value (wtraits::set_ref (v), i, is_null); + } + + static void + set_image (image_type& i, bool& is_null, const W& v) + { + is_null = wtraits::get_null (v); + + if (!is_null) + vtraits::set_image (i, is_null, wtraits::get_ref (v)); + } + + // String, BYTEA, and NUMERIC. + // + static void + set_value (W& v, const details::buffer& b, std::size_t n, bool is_null) + { + if (is_null) + wtraits::set_null (v); + else + vtraits::set_value (wtraits::set_ref (v), b, n, is_null); + } + + static void + set_image (details::buffer& b, std::size_t& n, bool& is_null, const W& v) + { + is_null = wtraits::get_null (v); + + if (!is_null) + vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); + } + + // BIT. + // + static void + set_value (W& v, const unsigned char* i, std::size_t n, bool is_null) + { + if (is_null) + wtraits::set_null (v); + else + vtraits::set_value (wtraits::set_ref (v), i, n, is_null); + } + + static void + set_image (unsigned char* i, + std::size_t c, + std::size_t& n, + bool& is_null, + const W& v) + { + is_null = wtraits::get_null (v); + + if (!is_null) + vtraits::set_image (i, c, n, is_null, wtraits::get_ref (v)); + } + + // VARBIT. + // + static void + set_value (W& v, const details::ubuffer& b, std::size_t n, bool is_null) + { + if (is_null) + wtraits::set_null (v); + else + vtraits::set_value (wtraits::set_ref (v), b, n, is_null); + } + + static void + set_image (details::ubuffer& b, std::size_t& n, bool& is_null, const W& v) + { + is_null = wtraits::get_null (v); + + if (!is_null) + vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); + } + + // UUID. + // + static void + set_value (W& v, const unsigned char* i, bool is_null) + { + if (is_null) + wtraits::set_null (v); + else + vtraits::set_value (wtraits::set_ref (v), i, is_null); + } + + static void + set_image (unsigned char* i, bool& is_null, const W& v) + { + is_null = wtraits::get_null (v); + + if (!is_null) + vtraits::set_image (i, is_null, wtraits::get_ref (v)); + } + }; + + template + struct default_value_traits + { + typedef T value_type; + typedef T query_type; + typedef typename image_traits::image_type image_type; + + static void + set_value (T& v, const image_type& i, bool is_null) + { + if (!is_null) + v = T (details::endian_traits::ntoh (i)); + else + v = T (); + } + + static void + set_image (image_type& i, bool& is_null, T v) + { + is_null = false; + i = details::endian_traits::hton (image_type (v)); + } + }; + + // std::string specialization. + // + template <> + struct LIBODB_PGSQL_EXPORT default_value_traits + { + typedef std::string value_type; + typedef std::string query_type; + typedef details::buffer image_type; + + static void + set_value (std::string& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + v.assign (b.data (), n); + else + v.erase (); + } + + static void + set_image (details::buffer&, + std::size_t& n, + bool& is_null, + const std::string&); + }; + + // char*/const char* specialization + // + // Specialization for const char* which only supports initialization + // of an image from the value but not the other way around. This way + // we can pass such values to the queries. + // + class LIBODB_PGSQL_EXPORT c_string_value_traits + { + public: + typedef const char* value_type; + typedef details::buffer image_type; + + static void + set_image (details::buffer&, + std::size_t& n, + bool& is_null, + const char*); + }; + + template <> + struct default_value_traits: c_string_value_traits {}; + + template <> + struct default_value_traits: + c_string_value_traits {}; + + // char[N] specializations. + // + struct LIBODB_PGSQL_EXPORT c_array_value_traits_base + { + static void + set_value (char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null, + std::size_t N); + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const char* v, + std::size_t N); + }; + + template + struct default_value_traits + { + typedef char* value_type; + typedef char query_type[N]; + typedef details::buffer image_type; + + static void + set_value (char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + c_array_value_traits_base::set_value (v, b, n, is_null, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const char* v) + { + c_array_value_traits_base::set_image (b, n, is_null, v, N); + } + }; + + // std::array (string) specialization. + // +#ifdef ODB_CXX11 + template + struct default_value_traits, id_string> + { + typedef std::array value_type; + typedef std::array query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + c_array_value_traits_base::set_value (v.data (), b, n, is_null, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + c_array_value_traits_base::set_image (b, n, is_null, v.data (), N); + } + }; +#endif + + // char specialization. + // + template <> + struct default_value_traits + { + typedef char value_type; + typedef char query_type; + typedef details::buffer image_type; + + static void + set_value (char& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + c_array_value_traits_base::set_value (&v, b, n, is_null, 1); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + char v) + { + c_array_value_traits_base::set_image (b, n, is_null, &v, 1); + } + }; + + // std::vector (buffer) specialization. + // + template <> + struct LIBODB_PGSQL_EXPORT default_value_traits< + std::vector, id_bytea> + { + public: + typedef std::vector value_type; + typedef std::vector query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + v.assign (b.data (), b.data () + n); + else + v.clear (); + } + + static void + set_image (details::buffer&, + std::size_t& n, + bool& is_null, + const value_type&); + }; + + // std::vector (buffer) specialization. + // + template <> + struct LIBODB_PGSQL_EXPORT default_value_traits< + std::vector, id_bytea> + { + public: + typedef std::vector value_type; + typedef std::vector query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + { + const unsigned char* d ( + reinterpret_cast (b.data ())); + v.assign (d, d + n); + } + else + v.clear (); + } + + static void + set_image (details::buffer&, + std::size_t& n, + bool& is_null, + const value_type&); + }; + + // char[N] (buffer) specialization. + // + template + struct default_value_traits + { + public: + typedef char* value_type; + typedef char query_type[N]; + typedef details::buffer image_type; + + static void + set_value (char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + std::memcpy (v, b.data (), (n < N ? n : N)); + else + std::memset (v, 0, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const char* v) + { + is_null = false; + n = N; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v, n); + } + }; + + // unsigned char[N] (buffer) specialization. + // + template + struct default_value_traits + { + public: + typedef unsigned char* value_type; + typedef unsigned char query_type[N]; + typedef details::buffer image_type; + + static void + set_value (unsigned char* const& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + std::memcpy (v, b.data (), (n < N ? n : N)); + else + std::memset (v, 0, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const unsigned char* v) + { + is_null = false; + n = N; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v, n); + } + }; + +#ifdef ODB_CXX11 + // std::array (buffer) specialization. + // + template + struct default_value_traits, id_bytea> + { + public: + typedef std::array value_type; + typedef value_type query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + std::memcpy (v.data (), b.data (), (n < N ? n : N)); + else + std::memset (v.data (), 0, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + is_null = false; + n = N; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v.data (), n); + } + }; + + // std::array (buffer) specialization. + // + template + struct default_value_traits, id_bytea> + { + public: + typedef std::array value_type; + typedef value_type query_type; + typedef details::buffer image_type; + + static void + set_value (value_type& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + if (!is_null) + std::memcpy (v.data (), b.data (), (n < N ? n : N)); + else + std::memset (v.data (), 0, N); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const value_type& v) + { + is_null = false; + n = N; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), v.data (), n); + } + }; +#endif + + // char[16] specialization for uuid. + // + template <> + struct default_value_traits + { + typedef char* value_type; + typedef char query_type[16]; + typedef unsigned char* image_type; + + static void + set_value (char* const& v, const unsigned char* i, bool is_null) + { + if (!is_null) + std::memcpy (v, i, 16); + else + std::memset (v, 0, 16); + } + + static void + set_image (unsigned char* i, bool& is_null, const char* v) + { + is_null = false; + std::memcpy (i, v, 16); + } + }; + + // + // type_traits + // + + template + struct default_type_traits; + + template + class type_traits: public default_type_traits + { + }; + + // Integral types. + // + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_boolean; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_smallint; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_smallint; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_smallint; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_smallint; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_integer; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_integer; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_bigint; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_bigint; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_bigint; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_bigint; + }; + + // Float types. + // + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_real; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_double; + }; + + // String types. + // + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_string; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_string; + }; + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_string; + }; + + template + struct default_type_traits + { + static const database_type_id db_type_id = id_string; + }; + +#ifdef ODB_CXX11 + template + struct default_type_traits > + { + static const database_type_id db_type_id = id_string; + }; +#endif + + template <> + struct default_type_traits + { + static const database_type_id db_type_id = id_string; + }; + + // Binary types. + // + template + struct default_type_traits + { + static const database_type_id db_type_id = id_bytea; + }; + + template <> + struct default_type_traits > + { + static const database_type_id db_type_id = id_bytea; + }; + + template <> + struct default_type_traits > + { + static const database_type_id db_type_id = id_bytea; + }; + +#ifdef ODB_CXX11 + template + struct default_type_traits > + { + static const database_type_id db_type_id = id_bytea; + }; +#endif + } +} + +#include + +#endif // ODB_PGSQL_TRAITS_HXX diff --git a/libodb-pgsql/odb/pgsql/transaction-impl.cxx b/libodb-pgsql/odb/pgsql/transaction-impl.cxx new file mode 100644 index 0000000..012fe18 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/transaction-impl.cxx @@ -0,0 +1,107 @@ +// file : odb/pgsql/transaction-impl.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + transaction_impl:: + transaction_impl (database_type& db) + : odb::transaction_impl (db) + { + } + + transaction_impl:: + transaction_impl (connection_ptr c) + : odb::transaction_impl (c->database (), *c), connection_ (c) + { + } + + transaction_impl:: + ~transaction_impl () + { + } + + void transaction_impl:: + start () + { + // Grab a connection if we don't already have one. + // + if (connection_ == 0) + { + connection_ = static_cast (database_).connection (); + odb::transaction_impl::connection_ = connection_.get (); + } + + { + odb::tracer* t; + if ((t = connection_->tracer ()) || (t = database_.tracer ())) + t->execute (*connection_, "BEGIN"); + } + + auto_handle h (PQexec (connection_->handle (), "begin")); + + if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) + translate_error (*connection_, h); + } + + void transaction_impl:: + commit () + { + // Invalidate query results. + // + connection_->invalidate_results (); + + { + odb::tracer* t; + if ((t = connection_->tracer ()) || (t = database_.tracer ())) + t->execute (*connection_, "COMMIT"); + } + + auto_handle h (PQexec (connection_->handle (), "commit")); + + if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) + translate_error (*connection_, h); + + // Release the connection. + // + connection_.reset (); + } + + void transaction_impl:: + rollback () + { + // Invalidate query results. + // + connection_->invalidate_results (); + + { + odb::tracer* t; + if ((t = connection_->tracer ()) || (t = database_.tracer ())) + t->execute (*connection_, "ROLLBACK"); + } + + auto_handle h (PQexec (connection_->handle (), "rollback")); + + if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) + translate_error (*connection_, h); + + // Release the connection. + // + connection_.reset (); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/transaction-impl.hxx b/libodb-pgsql/odb/pgsql/transaction-impl.hxx new file mode 100644 index 0000000..5c93b0e --- /dev/null +++ b/libodb-pgsql/odb/pgsql/transaction-impl.hxx @@ -0,0 +1,49 @@ +// file : odb/pgsql/transaction-impl.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_TRANSACTION_IMPL_HXX +#define ODB_PGSQL_TRANSACTION_IMPL_HXX + +#include + +#include + +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + class LIBODB_PGSQL_EXPORT transaction_impl: public odb::transaction_impl + { + public: + typedef pgsql::database database_type; + typedef pgsql::connection connection_type; + + transaction_impl (database_type&); + transaction_impl (connection_ptr); + + virtual + ~transaction_impl (); + + virtual void + start (); + + virtual void + commit (); + + virtual void + rollback (); + + private: + connection_ptr connection_; + }; + } +} + +#include + +#endif // ODB_PGSQL_TRANSACTION_IMPL_HXX diff --git a/libodb-pgsql/odb/pgsql/transaction.cxx b/libodb-pgsql/odb/pgsql/transaction.cxx new file mode 100644 index 0000000..3b32d80 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/transaction.cxx @@ -0,0 +1,26 @@ +// file : odb/pgsql/transaction.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include + +namespace odb +{ + namespace pgsql + { + transaction& transaction:: + current () + { + // While the impl type can be of the concrete type, the transaction + // object can be created as either odb:: or odb::pgsql:: type. To + // work around that we are going to hard-cast one to the other + // relying on the fact that they have the same representation and + // no virtual functions. The former is checked in the tests. + // + odb::transaction& b (odb::transaction::current ()); + assert (dynamic_cast (&b.implementation ()) != 0); + return reinterpret_cast (b); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/transaction.hxx b/libodb-pgsql/odb/pgsql/transaction.hxx new file mode 100644 index 0000000..e83c754 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/transaction.hxx @@ -0,0 +1,88 @@ +// file : odb/pgsql/transaction.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_TRANSACTION_HXX +#define ODB_PGSQL_TRANSACTION_HXX + +#include + +#include + +#include +#include +#include + +#include + +namespace odb +{ + namespace pgsql + { + class transaction_impl; + + class LIBODB_PGSQL_EXPORT transaction: public odb::transaction + { + public: + typedef pgsql::database database_type; + typedef pgsql::connection connection_type; + + explicit + transaction (transaction_impl*, bool make_current = true); + + transaction (); + + // Return the database this transaction is on. + // + database_type& + database (); + + // Return the underlying database connection for this transaction. + // + connection_type& + connection (); + + connection_type& + connection (odb::database&); + + // Return current transaction or throw if there is no transaction + // in effect. + // + static transaction& + current (); + + // Set the current thread's transaction. + // + static void + current (transaction&); + + // SQL statement tracing. + // + public: + typedef pgsql::tracer tracer_type; + + void + tracer (tracer_type& t) + { + odb::transaction::tracer (t); + } + + void + tracer (tracer_type* t) + { + odb::transaction::tracer (t); + } + + using odb::transaction::tracer; + + public: + transaction_impl& + implementation (); + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_TRANSACTION_HXX diff --git a/libodb-pgsql/odb/pgsql/transaction.ixx b/libodb-pgsql/odb/pgsql/transaction.ixx new file mode 100644 index 0000000..31aa603 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/transaction.ixx @@ -0,0 +1,57 @@ +// file : odb/pgsql/transaction.ixx +// license : GNU GPL v2; see accompanying LICENSE file + +#include +#include + +namespace odb +{ + namespace pgsql + { + inline transaction:: + transaction (transaction_impl* impl, bool make_current) + : odb::transaction (impl, make_current) + { + } + + inline transaction:: + transaction () + : odb::transaction () + { + } + + inline transaction_impl& transaction:: + implementation () + { + // We can use static_cast here since we have an instance of + // pgsql::transaction. + // + return static_cast ( + odb::transaction::implementation ()); + } + + inline transaction::database_type& transaction:: + database () + { + return static_cast (odb::transaction::database ()); + } + + inline transaction::connection_type& transaction:: + connection () + { + return static_cast (odb::transaction::connection ()); + } + + inline transaction::connection_type& transaction:: + connection (odb::database& db) + { + return static_cast (odb::transaction::connection (db)); + } + + inline void transaction:: + current (transaction& t) + { + odb::transaction::current (t); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/version-build2-stub.hxx b/libodb-pgsql/odb/pgsql/version-build2-stub.hxx new file mode 100644 index 0000000..a99b093 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/version-build2-stub.hxx @@ -0,0 +1,4 @@ +// file : odb/pgsql/version-build2-stub.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#include diff --git a/libodb-pgsql/odb/pgsql/version-build2.hxx b/libodb-pgsql/odb/pgsql/version-build2.hxx new file mode 100644 index 0000000..e69de29 diff --git a/libodb-pgsql/odb/pgsql/version-build2.hxx.in b/libodb-pgsql/odb/pgsql/version-build2.hxx.in new file mode 100644 index 0000000..ed4396b --- /dev/null +++ b/libodb-pgsql/odb/pgsql/version-build2.hxx.in @@ -0,0 +1,42 @@ +// file : odb/pgsql/version-build2.hxx.in +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef LIBODB_PGSQL_VERSION // Note: using the version macro itself. + +// The numeric version format is AAAAABBBBBCCCCCDDDE where: +// +// AAAAA - major version number +// BBBBB - minor version number +// CCCCC - bugfix version number +// DDD - alpha / beta (DDD + 500) version number +// E - final (0) / snapshot (1) +// +// When DDDE is not 0, 1 is subtracted from AAAAABBBBBCCCCC. For example: +// +// Version AAAAABBBBBCCCCCDDDE +// +// 0.1.0 0000000001000000000 +// 0.1.2 0000000001000020000 +// 1.2.3 0000100002000030000 +// 2.2.0-a.1 0000200001999990010 +// 3.0.0-b.2 0000299999999995020 +// 2.2.0-a.1.z 0000200001999990011 +// +#define LIBODB_PGSQL_VERSION $libodb_pgsql.version.project_number$ULL +#define LIBODB_PGSQL_VERSION_STR "$libodb_pgsql.version.project$" +#define LIBODB_PGSQL_VERSION_ID "$libodb_pgsql.version.project_id$" + +#define LIBODB_PGSQL_VERSION_MAJOR $libodb_pgsql.version.major$ +#define LIBODB_PGSQL_VERSION_MINOR $libodb_pgsql.version.minor$ +#define LIBODB_PGSQL_VERSION_PATCH $libodb_pgsql.version.patch$ + +#define LIBODB_PGSQL_PRE_RELEASE $libodb_pgsql.version.pre_release$ + +#define LIBODB_PGSQL_SNAPSHOT $libodb_pgsql.version.snapshot_sn$ULL +#define LIBODB_PGSQL_SNAPSHOT_ID "$libodb_pgsql.version.snapshot_id$" + +#include + +$libodb.check(LIBODB_VERSION, LIBODB_SNAPSHOT)$ + +#endif // LIBODB_PGSQL_VERSION diff --git a/libodb-pgsql/odb/pgsql/version.hxx b/libodb-pgsql/odb/pgsql/version.hxx new file mode 100644 index 0000000..e050de4 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/version.hxx @@ -0,0 +1,48 @@ +// file : odb/pgsql/version.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifdef LIBODB_PGSQL_BUILD2 +# include +#else + +#ifndef ODB_PGSQL_VERSION_HXX +#define ODB_PGSQL_VERSION_HXX + +#include + +#include +#include + +// Version format is AABBCCDD where +// +// AA - major version number +// BB - minor version number +// CC - bugfix version number +// DD - alpha / beta (DD + 50) version number +// +// When DD is not 00, 1 is subtracted from AABBCC. For example: +// +// Version AABBCCDD +// 2.0.0 02000000 +// 2.1.0 02010000 +// 2.1.1 02010100 +// 2.2.0.a1 02019901 +// 3.0.0.b2 02999952 +// + +// Check that we have compatible ODB version. +// +#if ODB_VERSION != 20476 +# error incompatible odb interface version detected +#endif + +// libodb-pgsql version: odb interface version plus the bugfix +// version. +// +#define LIBODB_PGSQL_VERSION 2049976 +#define LIBODB_PGSQL_VERSION_STR "2.5.0-b.26" + +#include + +#endif // ODB_PGSQL_VERSION_HXX +#endif // LIBODB_PGSQL_BUILD2 diff --git a/libodb-pgsql/odb/pgsql/view-result.hxx b/libodb-pgsql/odb/pgsql/view-result.hxx new file mode 100644 index 0000000..f9acace --- /dev/null +++ b/libodb-pgsql/odb/pgsql/view-result.hxx @@ -0,0 +1,77 @@ +// file : odb/pgsql/view-result.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_VIEW_RESULT_HXX +#define ODB_PGSQL_VIEW_RESULT_HXX + +#include + +#include // std::size_t + +#include +#include + +#include + +#include +#include // query_base, view_statements +#include +#include + +namespace odb +{ + namespace pgsql + { + template + class view_result_impl: public odb::view_result_impl + { + public: + typedef odb::view_result_impl base_type; + + typedef typename base_type::view_type view_type; + typedef typename base_type::pointer_type pointer_type; + + typedef view_traits_impl view_traits; + typedef typename base_type::pointer_traits pointer_traits; + + typedef view_statements statements_type; + + virtual + ~view_result_impl (); + + view_result_impl (const query_base&, + details::shared_ptr, + statements_type&, + const schema_version_migration*); + + virtual void + load (view_type&); + + virtual void + next (); + + virtual void + cache (); + + virtual std::size_t + size (); + + virtual void + invalidate (); + + using base_type::current; + + private: + details::shared_ptr statement_; + statements_type& statements_; + view_traits_calls tc_; + std::size_t count_; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_VIEW_RESULT_HXX diff --git a/libodb-pgsql/odb/pgsql/view-result.txx b/libodb-pgsql/odb/pgsql/view-result.txx new file mode 100644 index 0000000..980811a --- /dev/null +++ b/libodb-pgsql/odb/pgsql/view-result.txx @@ -0,0 +1,114 @@ +// file : odb/pgsql/view-result.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include + +namespace odb +{ + namespace pgsql + { + template + view_result_impl:: + ~view_result_impl () + { + if (!this->end_) + statement_->free_result (); + } + + template + void view_result_impl:: + invalidate () + { + if (!this->end_) + { + statement_->free_result (); + this->end_ = true; + } + + statement_.reset (); + } + + template + view_result_impl:: + view_result_impl (const query_base&, + details::shared_ptr statement, + statements_type& statements, + const schema_version_migration* svm) + : base_type (statements.connection ()), + statement_ (statement), + statements_ (statements), + tc_ (svm), + count_ (0) + { + } + + template + void view_result_impl:: + load (view_type& view) + { + // The image can grow between calls to load() as a result of other + // statements execution. + // + typename view_traits::image_type& im (statements_.image ()); + + if (im.version != statements_.image_version ()) + { + binding& b (statements_.image_binding ()); + tc_.bind (b.bind, im); + statements_.image_version (im.version); + b.version++; + } + + select_statement::result r (statement_->load ()); + + if (r == select_statement::truncated) + { + if (tc_.grow (im, statements_.image_truncated ())) + im.version++; + + if (im.version != statements_.image_version ()) + { + binding& b (statements_.image_binding ()); + tc_.bind (b.bind, im); + statements_.image_version (im.version); + b.version++; + statement_->reload (); + } + } + + view_traits::callback (this->db_, view, callback_event::pre_load); + tc_.init (view, im, &this->db_); + view_traits::callback (this->db_, view, callback_event::post_load); + } + + template + void view_result_impl:: + next () + { + this->current (pointer_type ()); + + if (statement_->next ()) + count_++; + else + { + statement_->free_result (); + this->end_ = true; + } + } + + template + void view_result_impl:: + cache () + { + } + + template + std::size_t view_result_impl:: + size () + { + return this->end_ ? count_ : statement_->result_size (); + } + } +} diff --git a/libodb-pgsql/odb/pgsql/view-statements.hxx b/libodb-pgsql/odb/pgsql/view-statements.hxx new file mode 100644 index 0000000..970e610 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/view-statements.hxx @@ -0,0 +1,88 @@ +// file : odb/pgsql/view-statements.hxx +// license : GNU GPL v2; see accompanying LICENSE file + +#ifndef ODB_PGSQL_VIEW_STATEMENTS_HXX +#define ODB_PGSQL_VIEW_STATEMENTS_HXX + +#include + +#include // std::size_t + +#include +#include + +#include +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + template + class view_statements: public statements_base + { + public: + typedef T view_type; + typedef view_traits_impl view_traits; + typedef typename view_traits::pointer_type pointer_type; + typedef typename view_traits::image_type image_type; + + public: + view_statements (connection_type&); + + virtual + ~view_statements (); + + // View image. + // + image_type& + image () + { + return image_; + } + + std::size_t + image_version () const + { + return image_version_; + } + + void + image_version (std::size_t v) + { + image_version_ = v; + } + + binding& + image_binding () + { + return image_binding_; + } + + bool* + image_truncated () + { + return image_truncated_; + } + + private: + view_statements (const view_statements&); + view_statements& operator= (const view_statements&); + + private: + image_type image_; + std::size_t image_version_; + binding image_binding_; + bind image_bind_[view_traits::column_count]; + bool image_truncated_[view_traits::column_count]; + }; + } +} + +#include + +#include + +#endif // ODB_PGSQL_VIEW_STATEMENTS_HXX diff --git a/libodb-pgsql/odb/pgsql/view-statements.txx b/libodb-pgsql/odb/pgsql/view-statements.txx new file mode 100644 index 0000000..afa2a49 --- /dev/null +++ b/libodb-pgsql/odb/pgsql/view-statements.txx @@ -0,0 +1,33 @@ +// file : odb/pgsql/view-statements.txx +// license : GNU GPL v2; see accompanying LICENSE file + +#include // std::size_t +#include // std::memset + +namespace odb +{ + namespace pgsql + { + template + view_statements:: + ~view_statements () + { + } + + template + view_statements:: + view_statements (connection_type& conn) + : statements_base (conn), + image_binding_ (image_bind_, view_traits::column_count) + { + image_.version = 0; + image_version_ = 0; + + std::memset (image_bind_, 0, sizeof (image_bind_)); + std::memset (image_truncated_, 0, sizeof (image_truncated_)); + + for (std::size_t i (0); i < view_traits::column_count; ++i) + image_bind_[i].truncated = image_truncated_ + i; + } + } +} diff --git a/libodb-pgsql/tests/.gitignore b/libodb-pgsql/tests/.gitignore new file mode 100644 index 0000000..e54525b --- /dev/null +++ b/libodb-pgsql/tests/.gitignore @@ -0,0 +1 @@ +driver diff --git a/libodb-pgsql/tests/basics/buildfile b/libodb-pgsql/tests/basics/buildfile new file mode 100644 index 0000000..fccb243 --- /dev/null +++ b/libodb-pgsql/tests/basics/buildfile @@ -0,0 +1,6 @@ +# file : tests/basics/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libs = libodb-pgsql%lib{odb-pgsql} + +exe{driver}: {hxx cxx}{*} $libs diff --git a/libodb-pgsql/tests/basics/driver.cxx b/libodb-pgsql/tests/basics/driver.cxx new file mode 100644 index 0000000..efd1985 --- /dev/null +++ b/libodb-pgsql/tests/basics/driver.cxx @@ -0,0 +1,37 @@ +// file : tests/basics/driver.cxx +// license : GNU GPL v2; see accompanying LICENSE file + +// Basic test to make sure the library is usable. Functionality testing +// is done in the odb-tests package. + +#include +#include + +#include +#include +#include + +using namespace odb::pgsql; + +int +main () +{ + { + std::ostringstream os; + database::print_usage (os); + assert (!os.str ().empty ()); + } + + // We can't really do much here since that would require a database. We can + // create a fake database object as long as we don't expect to get a valid + // connection. + // + database db ("john", "secret", "dummy whammy"); + + try + { + transaction t (db.begin ()); + assert (false); + } + catch (const database_exception&) {} +} diff --git a/libodb-pgsql/tests/build/.gitignore b/libodb-pgsql/tests/build/.gitignore new file mode 100644 index 0000000..4a730a3 --- /dev/null +++ b/libodb-pgsql/tests/build/.gitignore @@ -0,0 +1,3 @@ +config.build +root/ +bootstrap/ diff --git a/libodb-pgsql/tests/build/bootstrap.build b/libodb-pgsql/tests/build/bootstrap.build new file mode 100644 index 0000000..6ee38db --- /dev/null +++ b/libodb-pgsql/tests/build/bootstrap.build @@ -0,0 +1,8 @@ +# file : tests/build/bootstrap.build +# license : GNU GPL v2; see accompanying LICENSE file + +project = # Unnamed subproject. + +using config +using dist +using test diff --git a/libodb-pgsql/tests/build/root.build b/libodb-pgsql/tests/build/root.build new file mode 100644 index 0000000..6c5a90b --- /dev/null +++ b/libodb-pgsql/tests/build/root.build @@ -0,0 +1,23 @@ +# file : tests/build/root.build +# license : GNU GPL v2; see accompanying LICENSE file + +cxx.std = latest + +using cxx + +hxx{*}: extension = hxx +cxx{*}: extension = cxx + +if ($cxx.target.system == 'win32-msvc') + cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS + +if ($cxx.class == 'msvc') + cxx.coptions += /wd4251 /wd4275 /wd4800 + +# Every exe{} in this subproject is by default a test. +# +exe{*}: test = true + +# Specify the test target for cross-testing. +# +test.target = $cxx.target diff --git a/libodb-pgsql/tests/buildfile b/libodb-pgsql/tests/buildfile new file mode 100644 index 0000000..57588a4 --- /dev/null +++ b/libodb-pgsql/tests/buildfile @@ -0,0 +1,4 @@ +# file : tests/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +./: {*/ -build/} diff --git a/m4/acx-pthread.m4 b/m4/acx-pthread.m4 deleted file mode 100644 index 204b32d..0000000 --- a/m4/acx-pthread.m4 +++ /dev/null @@ -1,259 +0,0 @@ -dnl -dnl NOTE: This file was modified. See the comments starting with 'CS:' -dnl for more information. In particular, it was changed to use C++ -dnl instead of C. -dnl -dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl @summary figure out how to build C++ programs using POSIX threads -dnl -dnl This macro figures out how to build C++ programs using POSIX threads. -dnl It sets the PTHREAD_LIBS output variable to the threads library and -dnl linker flags, and the PTHREAD_CXXFLAGS output variable to any special -dnl C++ compiler flags that are needed. (The user can also force certain -dnl compiler flags/libs to be tested by setting these environment -dnl variables.) -dnl -dnl Also sets PTHREAD_CXX to any special C++ compiler that is needed for -dnl multi-threaded programs (defaults to the value of CXX otherwise). -dnl (This is necessary on AIX to use the special xlC_r compiler alias.) -dnl -dnl NOTE: You are assumed to not only compile your program with these -dnl flags, but also link it with them as well. e.g. you should link -dnl with $PTHREAD_CXX $CXXFLAGS $PTHREAD_CXXFLAGS $LDFLAGS ... $PTHREAD_LIBS -dnl $LIBS -dnl -dnl If you are only building threads programs, you may wish to use -dnl these variables in your default LIBS, CXXFLAGS, and CXX: -dnl -dnl LIBS="$PTHREAD_LIBS $LIBS" -dnl CXXFLAGS="$CXXFLAGS $PTHREAD_CXXFLAGS" -dnl CXX="$PTHREAD_CXX" -dnl -dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute -dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to -dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). -dnl -dnl ACTION-IF-FOUND is a list of shell commands to run if a threads -dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to -dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the -dnl default action will define HAVE_PTHREAD. -dnl -dnl Please let the authors know if this macro fails on any platform, or -dnl if you have any other suggestions or comments. This macro was based -dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with -dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros -dnl posted by Alejandro Forero Cuervo to the autoconf macro repository. -dnl We are also grateful for the helpful feedback of numerous users. -dnl -dnl @category InstalledPackages -dnl @author Steven G. Johnson -dnl @version 2006-05-29 -dnl @license GPLWithACException - -AC_DEFUN([ACX_PTHREAD], [ -AC_REQUIRE([AC_CANONICAL_HOST]) -AC_LANG_SAVE -AC_LANG(C++) -acx_pthread_ok=no - -# We used to check for pthread.h first, but this fails if pthread.h -# requires special compiler flags (e.g. on True64 or Sequent). -# It gets checked for in the link test anyway. - -# First of all, check if the user has set any of the PTHREAD_LIBS, -# etcetera environment variables, and if threads linking works using -# them: -if test x"$PTHREAD_LIBS$PTHREAD_CXXFLAGS" != x; then - save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS $PTHREAD_CXXFLAGS" - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CXXFLAGS=$PTHREAD_CXXFLAGS]) - AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) - AC_MSG_RESULT($acx_pthread_ok) - if test x"$acx_pthread_ok" = xno; then - PTHREAD_LIBS="" - PTHREAD_CXXFLAGS="" - fi - LIBS="$save_LIBS" - CXXFLAGS="$save_CXXFLAGS" -fi - -# We must check for the threads library under a number of different -# names; the ordering is very important because some systems -# (e.g. DEC) have both -lpthread and -lpthreads, where one of the -# libraries is broken (non-POSIX). - -# Create a list of thread flags to try. Items starting with a "-" are -# C compiler flags, and other items are library names, except for "none" -# which indicates that we try without any flags at all, and "pthread-config" -# which is a program returning the flags for the Pth emulation library. - -# CS: On GNU/Linux with gcc both -pthread and -lpthread are valid. -# However, libtool links libraries with -nostdlib which results in -# -pthread being stripped from the linker command line. To resolve -# this we move pthread from after -mthreads to after pthreads. -# -acx_pthread_flags="pthreads pthread none -Kthread -kthread lthread -pthread -pthreads -mthreads --thread-safe -mt pthread-config" - -# The ordering *is* (sometimes) important. Some notes on the -# individual items follow: - -# pthreads: AIX (must check this before -lpthread) -# none: in case threads are in libc; should be tried before -Kthread and -# other compiler flags to prevent continual compiler warnings -# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) -# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) -# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) -# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) -# -pthreads: Solaris/gcc -# -mthreads: Mingw32/gcc, Lynx/gcc -# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it -# doesn't hurt to check since this sometimes defines pthreads too; -# also defines -D_REENTRANT) -# ... -mt is also the pthreads flag for HP/aCC -# pthread: Linux, etcetera -# --thread-safe: KAI C++ -# pthread-config: use pthread-config program (for GNU Pth library) - -case "${host_cpu}-${host_os}" in - *solaris*) - - # On Solaris (at least, for some versions), libc contains stubbed - # (non-functional) versions of the pthreads routines, so link-based - # tests will erroneously succeed. (We need to link with -pthreads/-mt/ - # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather - # a function called by this macro, so we could check for that, but - # who knows whether they'll stub that too in a future libc.) So, - # we'll just look for -pthreads and -lpthread first: - - # CS: Move -mt to the front of the list; Sun CC will use -mt, - # gcc will use -pthreads. - # - acx_pthread_flags="-mt -pthreads pthread -pthread $acx_pthread_flags" - ;; -esac - -if test x"$acx_pthread_ok" = xno; then -for flag in $acx_pthread_flags; do - - case $flag in - none) - AC_MSG_CHECKING([whether pthreads work without any flags]) - ;; - - -*) - AC_MSG_CHECKING([whether pthreads work with $flag]) - PTHREAD_CXXFLAGS="$flag" - ;; - - pthread-config) - AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) - if test x"$acx_pthread_config" = xno; then continue; fi - PTHREAD_CXXFLAGS="`pthread-config --cflags`" - PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" - ;; - - *) - AC_MSG_CHECKING([for the pthreads library -l$flag]) - PTHREAD_LIBS="-l$flag" - ;; - esac - - save_LIBS="$LIBS" - save_CXXFLAGS="$CXXFLAGS" - LIBS="$PTHREAD_LIBS $LIBS" - CXXFLAGS="$CXXFLAGS $PTHREAD_CXXFLAGS" - - # Check for various functions. We must include pthread.h, - # since some functions may be macros. (On the Sequent, we - # need a special flag -Kthread to make this header compile.) - # We check for pthread_join because it is in -lpthread on IRIX - # while pthread_create is in libc. We check for pthread_attr_init - # due to DEC craziness with -lpthreads. We check for - # pthread_cleanup_push because it is one of the few pthread - # functions on Solaris that doesn't have a non-functional libc stub. - # We try pthread_create on general principles. - # - AC_TRY_LINK([#include ], - [pthread_t th; pthread_join(th, 0); - pthread_attr_init(0); pthread_cleanup_push(0, 0); - pthread_create(0,0,0,0); pthread_cleanup_pop(0);], - [acx_pthread_ok=yes]) - - LIBS="$save_LIBS" - CXXFLAGS="$save_CXXFLAGS" - - AC_MSG_RESULT($acx_pthread_ok) - if test "x$acx_pthread_ok" = xyes; then - break; - fi - - PTHREAD_LIBS="" - PTHREAD_CXXFLAGS="" -done -fi - -# Various other checks: -if test "x$acx_pthread_ok" = xyes; then - save_LIBS="$LIBS" - LIBS="$PTHREAD_LIBS $LIBS" - save_CXXFLAGS="$CXXFLAGS" - CXXFLAGS="$CXXFLAGS $PTHREAD_CXXFLAGS" - -dnl # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. -dnl AC_MSG_CHECKING([for joinable pthread attribute]) -dnl attr_name=unknown -dnl for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do -dnl AC_TRY_LINK([#include ], [int attr=$attr; return attr;], -dnl [attr_name=$attr; break]) -dnl done -dnl AC_MSG_RESULT($attr_name) -dnl if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then -dnl AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, -dnl [Define to necessary symbol if this constant -dnl uses a non-standard name on your system.]) -dnl fi - - AC_MSG_CHECKING([if more special flags are required for pthreads]) - flag=no - case "${host_cpu}-${host_os}" in - *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; - # CS: Add _REENTRANT in Linux to emulate -pthread. - # - *-linux* | *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; - esac - AC_MSG_RESULT(${flag}) - if test "x$flag" != xno; then - PTHREAD_CXXFLAGS="$flag $PTHREAD_CXXFLAGS" - fi - - LIBS="$save_LIBS" - CXXFLAGS="$save_CXXFLAGS" - -dnl # More AIX lossage: must compile with xlC_r -dnl if test x"$GXX" != xyes; then -dnl AC_CHECK_PROGS(PTHREAD_CXX, xlC_r, ${CXX}) -dnl else -dnl PTHREAD_CXX=$CXX -dnl fi - -else - PTHREAD_CXX="$CXX" -fi - -AC_SUBST(PTHREAD_LIBS) -AC_SUBST(PTHREAD_CXXFLAGS) -AC_SUBST(PTHREAD_CXX) - -# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: -if test x"$acx_pthread_ok" = xyes; then - ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) - : -else - acx_pthread_ok=no - $2 -fi -AC_LANG_RESTORE -])dnl ACX_PTHREAD diff --git a/m4/disable-rpath.m4 b/m4/disable-rpath.m4 deleted file mode 100644 index 0864209..0000000 --- a/m4/disable-rpath.m4 +++ /dev/null @@ -1,24 +0,0 @@ -dnl file : m4/disable-rpath.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -AC_DEFUN([DISABLE_RPATH],[ - -AC_MSG_CHECKING([whether to use rpath]) -AC_ARG_ENABLE( - [rpath], - [AC_HELP_STRING([--disable-rpath], [patch libtool to not use rpath])], - [libtool_rpath="$enable_rpath"], - [libtool_rpath="yes"]) -AC_MSG_RESULT($libtool_rpath) - -# Patch libtool to not use rpath if requested. -# -AC_CONFIG_COMMANDS( - [libtool-rpath-patch], - [if test "$libtool_use_rpath" = "no"; then - sed < libtool > libtool-2 's/^hardcode_libdir_flag_spec.*$'/'hardcode_libdir_flag_spec=" -D__LIBTOOL_NO_RPATH__ "/' - mv libtool-2 libtool - chmod 755 libtool - fi], - [libtool_use_rpath=$libtool_rpath]) -])dnl diff --git a/m4/libodb.m4 b/m4/libodb.m4 deleted file mode 100644 index 0dba7c4..0000000 --- a/m4/libodb.m4 +++ /dev/null @@ -1,81 +0,0 @@ -dnl file : m4/libodb.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBODB([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBODB], [ -libodb_found=no - -AC_ARG_WITH( - [libodb], - [AC_HELP_STRING([--with-libodb=DIR],[location of libodb build directory])], - [libodb_dir=${withval}], - [libodb_dir=]) - -AC_MSG_CHECKING([for libodb]) - -# If libodb_dir was given, add the necessary preprocessor and linker flags. -# -if test x"$libodb_dir" != x; then - save_CPPFLAGS="$CPPFLAGS" - save_LDFLAGS="$LDFLAGS" - - AS_SET_CATFILE([abs_libodb_dir], [$ac_pwd], [$libodb_dir]) - - CPPFLAGS="$CPPFLAGS -I$abs_libodb_dir" - LDFLAGS="$LDFLAGS -L$abs_libodb_dir/odb" -fi - -save_LIBS="$LIBS" -LIBS="-lodb $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -void -f () -{ -} - -const char* -g () -{ - try - { - f (); - } - catch (const odb::exception& e) - { - return e.what (); - } - return 0; -} - -int -main () -{ - const char* m (g ()); - return m != 0; -} -])], -[libodb_found=yes]) - -if test x"$libodb_found" = xno; then - LIBS="$save_LIBS" - - if test x"$libodb_dir" != x; then - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - fi -fi - -if test x"$libodb_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - AC_MSG_RESULT([no]) - $2 -fi -])dnl diff --git a/m4/libpq.m4 b/m4/libpq.m4 deleted file mode 100644 index a29ae2d..0000000 --- a/m4/libpq.m4 +++ /dev/null @@ -1,83 +0,0 @@ -dnl file : m4/libpq.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBPQ([ACTION-IF-FOUND[, -dnl ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBPQ], [ -libpq_found=no - -AC_PATH_PROG([pg_config],[pg_config]) - -AC_MSG_CHECKING([for libpq]) - -# Check for libpq using default CPPFLAGS/LDFLAGS. -# -save_LIBS="$LIBS" -LIBS="-lpq $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -int -main () -{ - PGconn* conn = PQconnectdb (""); - char* dbname = PQdb (conn); - PQfinish (conn); - return 0; -} -])], -[ -libpq_found=yes -]) - -if test x"$libpq_found" = xno; then - - # If default CPPFLAGS/LDFLAGS didn't work, try to discover - # them using pg_config. - # - if test x"$libpq_found" = xno; then - - if test x"$pg_config" != x; then - save_CPPFLAGS="$CPPFLAGS" - - CPPFLAGS=-I`$pg_config --includedir` - CPPFLAGS="$CPPFLAGS $save_CPPFLAGS" - - CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -int -main () -{ - PGconn* conn = PQconnectdb (""); - char* dbname = PQdb (conn); - PQfinish (conn); - return 0; -} -])], -[ -libpq_found=yes -]) - - if test x"$libpq_found" = xno; then - CPPFLAGS="$save_CPPFLAGS" - fi - - fi - fi -fi - -if test x"$libpq_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - LIBS="$save_LIBS" - AC_MSG_RESULT([no]) - $2 -fi -])dnl diff --git a/m4/libtool-link.m4 b/m4/libtool-link.m4 deleted file mode 100644 index 302639f..0000000 --- a/m4/libtool-link.m4 +++ /dev/null @@ -1,45 +0,0 @@ -dnl file : m4/libtool-link.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl -dnl CXX_LIBTOOL_LINK_IFELSE (input, [action-if-true], [action-if-false]) -dnl -dnl Similar to AC_LINK_IFELSE except it uses libtool to perform the -dnl linking and it does this using the C++ compiler. -dnl -AC_DEFUN([CXX_LIBTOOL_LINK_IFELSE],[ -AC_LANG_SAVE -AC_LANG(C++) - -if test -d .libs; then - delete_libs_dir=no -else - delete_libs_dir=yes -fi - -AC_COMPILE_IFELSE([$1], -[ - ac_try='./libtool --tag=CXX --mode=link $CXX -no-install $CXXFLAGS $LDFLAGS -o conftest conftest.$OBJEXT $LIBS >&AS_MESSAGE_LOG_FD' - if _AC_DO_VAR(ac_try); then - libtool_link_ok=yes - else - libtool_link_ok=no - fi -], -[ - libtool_link_ok=no -]) - -if test x"$delete_libs_dir" = xyes; then - rm -rf .libs -fi - -if test x"$libtool_link_ok" = xyes; then -[$2] -: -else -[$3] -: -fi - -AC_LANG_RESTORE])dnl diff --git a/m4/pkgconfig.m4 b/m4/pkgconfig.m4 deleted file mode 100644 index c48ea56..0000000 --- a/m4/pkgconfig.m4 +++ /dev/null @@ -1,11 +0,0 @@ -dnl file : m4/pkgconfig.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -AC_DEFUN([PKGCONFIG],[ -AC_ARG_WITH( - [pkgconfigdir], - [AC_HELP_STRING([--with-pkgconfigdir=DIR],[location of pkgconfig dir (default is libdir/pkgconfig)])], - [pkgconfigdir=${withval}], - [pkgconfigdir='${libdir}/pkgconfig']) -AC_SUBST([pkgconfigdir]) -])dnl diff --git a/m4/static-lib.m4 b/m4/static-lib.m4 deleted file mode 100644 index 5fb1c11..0000000 --- a/m4/static-lib.m4 +++ /dev/null @@ -1,17 +0,0 @@ -dnl file : m4/static-lib.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl STATIC_LIB(MACRO, DESCRIPTION) -dnl -dnl Define MACRO if we are on MinGW and are only building static library. -dnl -AC_DEFUN([STATIC_LIB], -[ -if test x$enable_shared = xno; then - case $host_os in - mingw*) - AC_DEFINE([$1], [1], [$2]) - ;; - esac -fi -])dnl diff --git a/m4/threads.m4 b/m4/threads.m4 deleted file mode 100644 index 6f2e25f..0000000 --- a/m4/threads.m4 +++ /dev/null @@ -1,68 +0,0 @@ -dnl file : m4/threads.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -AC_DEFUN([THREADS],[ - -threads_thread_keyword=no - -AC_ARG_ENABLE( - [threads], - AS_HELP_STRING([--disable-threads], [disable threads (enabled by default)]), - [AS_IF([test x"$enableval" = xno], [threads=none], [threads=check])], - [threads=check]) - -# If thread support is not disabled by the user, figure out what we can use. -# -if test x$threads = xcheck; then - case $host_os in - windows* | mingw*) - case $host_os in - mingw*) - CXXFLAGS="$CXXFLAGS -mthreads" - ;; - esac - - # Newer versions of GCC can be configured to use either Win32 or POSIX - # threads. It appears that -mthreads should be used in both cases but - # if the model is POSIX then GCC will also link -lpthread by default. - # Use that fact to test which model we have. - # - AC_TRY_LINK([#include ], - [pthread_create(0,0,0,0);], - [threads=posix], - [threads=win32]) - ;; - *) - ACX_PTHREAD - - if test x$acx_pthread_ok = xyes; then - threads=posix - LIBS="$LIBS $PTHREAD_LIBS" - CXXFLAGS="$CXXFLAGS $PTHREAD_CXXFLAGS" - - # Check if we can use the __thread keyword. - # - AC_MSG_CHECKING([for __thread keyword]) - - CXX_LIBTOOL_LINK_IFELSE([ - AC_LANG_SOURCE([ - __thread int tls_var; - - int - main () - { - tls_var = 0; - } - ])], - [threads_thread_keyword=yes]) - - AC_MSG_RESULT([$threads_thread_keyword]) - fi - ;; - esac -fi - -if test x$threads = xcheck; then - AC_MSG_ERROR([thread support not available; use --disable-threads to force single-threaded mode]) -fi -])dnl diff --git a/makefile b/makefile deleted file mode 100644 index 4031289..0000000 --- a/makefile +++ /dev/null @@ -1,35 +0,0 @@ -# file : makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))build/bootstrap.make - -dirs := odb/pgsql - -default := $(out_base)/ -dist := $(out_base)/.dist -clean := $(out_base)/.clean - -$(default): $(addprefix $(out_base)/,$(addsuffix /,$(dirs))) - -$(dist): export dirs := $(dirs) -$(dist): export docs := GPLv2 LICENSE README NEWS version.txt -$(dist): data_dist := INSTALL libodb-pgsql-vc8.sln libodb-pgsql-vc9.sln \ -libodb-pgsql-vc10.sln libodb-pgsql-vc11.sln libodb-pgsql-vc12.sln -$(dist): exec_dist := bootstrap -$(dist): export extra_dist := $(data_dist) $(exec_dist) -$(dist): export version = $(shell cat $(src_root)/version.txt) - -$(dist): $(addprefix $(out_base)/,$(addsuffix /.dist,$(dirs))) - $(call dist-data,$(docs) $(data_dist) libodb-pgsql.pc.in) - $(call dist-exec,$(exec_dist)) - $(call dist-dir,m4) - $(call meta-automake) - $(call meta-autoconf) - -$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(dirs))) - -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/automake.make) -$(call include,$(bld_root)/meta/autoconf.make) - -$(foreach d,$(dirs),$(call import,$(src_base)/$d/makefile)) diff --git a/manifest b/manifest deleted file mode 100644 index 7a523d7..0000000 --- a/manifest +++ /dev/null @@ -1,23 +0,0 @@ -: 1 -name: libodb-pgsql -version: 2.5.0-b.26.z -project: odb -summary: PostgreSQL ODB runtime library -license: GPL-2.0-only -license: other: proprietary ; Not free/open source. -topics: C++, ORM, PostgreSQL, SQL -description-file: README -changes-file: NEWS -url: https://www.codesynthesis.com/products/odb/ -doc-url: https://www.codesynthesis.com/products/odb/doc/manual.xhtml -src-url: https://git.codesynthesis.com/cgit/odb/libodb-pgsql/ -email: odb-users@codesynthesis.com -build-warning-email: odb-builds@codesynthesis.com -builds: all -builds: -wasm -requires: c++11 -depends: * build2 >= 0.16.0- -depends: * bpkg >= 0.16.0- -depends: libpq >=7.4.0 -depends: libodb [2.5.0-b.26.1 2.5.0-b.27) -depends: * cli ^1.2.0- ? ($config.libodb_pgsql.develop) diff --git a/odb/pgsql/Makefile.am b/odb/pgsql/Makefile.am deleted file mode 100644 index 8a95b93..0000000 --- a/odb/pgsql/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -# file : odb/pgsql/Makefile.am -# license : GNU GPL v2; see accompanying LICENSE file - -lib_LTLIBRARIES = libodb-pgsql.la -libodb_pgsql_la_SOURCES = __path__(sources) - -odbpgsqlincludedir = $(includedir)/odb/pgsql/ -nobase_odbpgsqlinclude_HEADERS = __path__(headers) -nobase_nodist_odbpgsqlinclude_HEADERS = details/config.h - -EXTRA_DIST = __file__(extra_dist) - -AM_CPPFLAGS= -I'$(top_builddir)' -I'$(top_srcdir)' -DLIBODB_PGSQL_DYNAMIC_LIB -AM_LDFLAGS = -release __value__(interface_version) -no-undefined diff --git a/odb/pgsql/auto-handle.cxx b/odb/pgsql/auto-handle.cxx deleted file mode 100644 index d6c0565..0000000 --- a/odb/pgsql/auto-handle.cxx +++ /dev/null @@ -1,24 +0,0 @@ -// file : odb/pgsql/auto-handle.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -#include - -namespace odb -{ - namespace pgsql - { - void handle_traits:: - release (PGconn* h) - { - PQfinish (h); - } - - void handle_traits:: - release (PGresult* h) - { - PQclear (h); - } - } -} diff --git a/odb/pgsql/auto-handle.hxx b/odb/pgsql/auto-handle.hxx deleted file mode 100644 index 49b396d..0000000 --- a/odb/pgsql/auto-handle.hxx +++ /dev/null @@ -1,90 +0,0 @@ -// file : odb/pgsql/auto-handle.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_AUTO_HANDLE_HXX -#define ODB_PGSQL_AUTO_HANDLE_HXX - -#include - -#include -#include // PGconn, PGresult - -#include - -namespace odb -{ - namespace pgsql - { - template - struct handle_traits; - - template <> - struct LIBODB_PGSQL_EXPORT handle_traits - { - static void - release (PGconn*); - }; - - template <> - struct LIBODB_PGSQL_EXPORT handle_traits - { - static void - release (PGresult*); - }; - - template - class auto_handle - { - public: - auto_handle (H* h = 0) - : h_ (h) - { - } - - ~auto_handle () - { - if (h_ != 0) - handle_traits::release (h_); - } - - H* - get () const - { - return h_; - } - - void - reset (H* h = 0) - { - if (h_ != 0) - handle_traits::release (h_); - - h_ = h; - } - - H* - release () - { - H* h (h_); - h_ = 0; - return h; - } - - operator H* () const - { - return h_; - } - - private: - auto_handle (const auto_handle&); - auto_handle& operator= (const auto_handle&); - - private: - H* h_; - }; - } -} - -#include - -#endif // ODB_PGSQL_AUTO_HANDLE_HXX diff --git a/odb/pgsql/binding.hxx b/odb/pgsql/binding.hxx deleted file mode 100644 index 1adf144..0000000 --- a/odb/pgsql/binding.hxx +++ /dev/null @@ -1,74 +0,0 @@ -// file : odb/pgsql/binding.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_BINDING_HXX -#define ODB_PGSQL_BINDING_HXX - -#include - -#include // std::size_t - -#include -#include - -namespace odb -{ - namespace pgsql - { - class native_binding - { - public: - native_binding (char** v, - int* l, - int* f, - std::size_t n) - : values (v), lengths (l), formats (f), count (n) - { - } - - char** values; - int* lengths; - int* formats; - std::size_t count; - - private: - native_binding (const native_binding&); - native_binding& operator= (const native_binding&); - }; - - class binding - { - public: - typedef pgsql::bind bind_type; - - binding () - : bind (0), count (0), version (0), - batch (0), skip (0), status (0) {} - - binding (bind_type* b, std::size_t n) - : bind (b), count (n), version (0), - batch (0), skip (0), status (0) {} - - binding (bind_type* b, std::size_t n, - std::size_t bt, std::size_t s, unsigned long long* st) - : bind (b), count (n), version (0), - batch (bt), skip (s), status (st) {} - - bind_type* bind; - std::size_t count; - std::size_t version; - - std::size_t batch; - std::size_t skip; - unsigned long long* status; // Batch status array. - - private: - binding (const binding&); - binding& operator= (const binding&); - }; - } -} - -#include - -#endif // ODB_PGSQL_BINDING_HXX diff --git a/odb/pgsql/buildfile b/odb/pgsql/buildfile deleted file mode 100644 index f1d05b6..0000000 --- a/odb/pgsql/buildfile +++ /dev/null @@ -1,155 +0,0 @@ -# file : odb/pgsql/buildfile -# license : GNU GPL v2; see accompanying LICENSE file - -define cli: file -cli{*}: extension = cli - -import int_libs = libodb%lib{odb} -import imp_libs = libpq%lib{pq} - -lib{odb-pgsql}: {hxx ixx txx cxx}{* -version-build2} {hxx}{version-build2} \ - details/{hxx ixx txx cxx}{* -options} \ - details/build2/{h}{*} \ - $imp_libs $int_libs - -# Include the generated version header into the distribution (so that we don't -# pick up an installed one) and don't remove it when cleaning in src (so that -# clean results in a state identical to distributed). -# -hxx{version-build2}: in{version-build2} $src_root/manifest -hxx{version-build2}: -{ - dist = true - clean = ($src_root != $out_root) -} - -# Build options. -# -cxx.poptions =+ "-I$out_root" "-I$src_root" -DLIBODB_PGSQL_BUILD2 - -obja{*}: cxx.poptions += -DLIBODB_PGSQL_STATIC_BUILD -objs{*}: cxx.poptions += -DLIBODB_PGSQL_SHARED_BUILD - -# Export options. -# -lib{odb-pgsql}: -{ - cxx.export.poptions = "-I$out_root" "-I$src_root" -DLIBODB_PGSQL_BUILD2 - cxx.export.libs = $int_libs -} - -liba{odb-pgsql}: cxx.export.poptions += -DLIBODB_PGSQL_STATIC -libs{odb-pgsql}: cxx.export.poptions += -DLIBODB_PGSQL_SHARED - -# For pre-releases use the complete version to make sure they cannot be used -# in place of another pre-release or the final version. See the version module -# for details on the version.* variable values. -# -if $version.pre_release - lib{odb-pgsql}: bin.lib.version = @"-$version.project_id" -else - lib{odb-pgsql}: bin.lib.version = @"-$version.major.$version.minor" - -develop = $config.libodb_pgsql.develop - -## Consumption build ($develop == false). -# - -# Use pregenerated versions in the consumption build. -# -lib{odb-pgsql}: details/pregenerated/{hxx ixx cxx}{**}: include = (!$develop) - -if! $develop - cxx.poptions =+ "-I($src_base/details/pregenerated)" # Note: must come first. - -# Don't install pregenerated headers since they are only used internally in -# the database implementation (also below). -# -details/pregenerated/{hxx ixx}{*}: install = false - -# Distribute pregenerated versions only in the consumption build. -# -details/pregenerated/{hxx ixx cxx}{*}: dist = (!$develop) - -# -## - -## Development build ($develop == true). -# - -lib{odb-pgsql}: details/{hxx ixx cxx}{options}: include = $develop - -if $develop - import! [metadata] cli = cli%exe{cli} - -# In the development build distribute regenerated {hxx ixx cxx}{options}, -# remapping their locations to the paths of the pregenerated versions (which -# are only distributed in the consumption build; see above). This way we make -# sure that the distributed files are always up-to-date. -# -
: details/cli{options} $cli -{ - install = false - dist = ($develop ? pregenerated/odb/pgsql/details/ : false) - - # Symlink the generated code in src for convenience of development. - # - backlink = true -} -% -if $develop -{{ - options = --include-with-brackets --include-prefix odb/pgsql/details \ - --guard-prefix LIBODB_PGSQL_DETAILS --generate-file-scanner \ - --cli-namespace odb::pgsql::details::cli --long-usage \ - --generate-specifier --no-combined-flags - - $cli $options -o $out_base/details/ $path($<[0]) - - # If the result differs from the pregenerated version, copy it over. - # - d = [dir_path] $src_base/details/pregenerated/odb/pgsql/details/ - - if diff $d/options.hxx $path($>[0]) >- && \ - diff $d/options.ixx $path($>[1]) >- && \ - diff $d/options.cxx $path($>[2]) >- - exit - end - - cp $path($>[0]) $d/options.hxx - cp $path($>[1]) $d/options.ixx - cp $path($>[2]) $d/options.cxx -}} - -# Install into the odb/pgsql/ subdirectory of, say, /usr/include/ -# recreating subdirectories. -# -install_include = [dir_path] include/odb/pgsql/ - -{hxx ixx txx}{*}: -{ - install = $install_include - install.subdirs = true -} - -# We want these to be picked up whether LIBODB_PGSQL_BUILD2 is defined or not. -# -hxx{version}@./: install = false -hxx{version-build2}: install = $install_include/version.hxx -hxx{version-build2-stub}@./: install = $install_include/version-build2.hxx - -details/build2/ -{ - h{*}: install = false - - if ($cxx.target.system == 'win32-msvc') - { - h{config-vc}@./: install = $install_include/details/ - h{config-vc-stub}@./: install = $install_include/details/build2/config-vc.h - } - else - { - h{config}@./: install = $install_include/details/ - h{config-stub}@./: install = $install_include/details/build2/config.h - } -} diff --git a/odb/pgsql/connection-factory.cxx b/odb/pgsql/connection-factory.cxx deleted file mode 100644 index 855a9bc..0000000 --- a/odb/pgsql/connection-factory.cxx +++ /dev/null @@ -1,159 +0,0 @@ -// file : odb/pgsql/connection-factory.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include -#include - -#include - -using namespace std; - -namespace odb -{ - using namespace details; - - namespace pgsql - { - // new_connection_factory - // - connection_ptr new_connection_factory:: - connect () - { - return connection_ptr (new (shared) connection (*this)); - } - - // connection_pool_factory - // - connection_pool_factory::pooled_connection_ptr connection_pool_factory:: - create () - { - return pooled_connection_ptr (new (shared) pooled_connection (*this)); - } - - connection_pool_factory:: - ~connection_pool_factory () - { - // Wait for all the connections currently in use to return to - // the pool. - // - lock l (mutex_); - while (in_use_ != 0) - { - waiters_++; - cond_.wait (l); - waiters_--; - } - } - - connection_ptr connection_pool_factory:: - connect () - { - lock l (mutex_); - - while (true) - { - // See if we have a spare connection. - // - if (connections_.size () != 0) - { - shared_ptr c (connections_.back ()); - connections_.pop_back (); - - c->callback_ = &c->cb_; - in_use_++; - return c; - } - - // See if we can create a new one. - // - if (max_ == 0 || in_use_ < max_) - { - shared_ptr c (create ()); - c->callback_ = &c->cb_; - in_use_++; - return c; - } - - // Wait until someone releases a connection. - // - waiters_++; - cond_.wait (l); - waiters_--; - } - } - - void connection_pool_factory:: - database (database_type& db) - { - bool first (db_ == 0); - - connection_factory::database (db); - - if (!first) - return; - - if (min_ > 0) - { - connections_.reserve (min_); - - for (size_t i (0); i < min_; ++i) - connections_.push_back (create ()); - } - } - - bool connection_pool_factory:: - release (pooled_connection* c) - { - c->callback_ = 0; - - lock l (mutex_); - - // Determine if we need to keep or free this connection. - // - bool keep (!c->failed () && - (waiters_ != 0 || - min_ == 0 || - (connections_.size () + in_use_ <= min_))); - - in_use_--; - - if (keep) - { - connections_.push_back (pooled_connection_ptr (inc_ref (c))); - connections_.back ()->recycle (); - } - - if (waiters_ != 0) - cond_.signal (); - - return !keep; - } - - // - // connection_pool_factory::pooled_connection - // - - connection_pool_factory::pooled_connection:: - pooled_connection (connection_pool_factory& f) - : connection (f) - { - cb_.arg = this; - cb_.zero_counter = &zero_counter; - } - - connection_pool_factory::pooled_connection:: - pooled_connection (connection_pool_factory& f, PGconn* handle) - : connection (f, handle) - { - cb_.arg = this; - cb_.zero_counter = &zero_counter; - } - - bool connection_pool_factory::pooled_connection:: - zero_counter (void* arg) - { - pooled_connection* c (static_cast (arg)); - return static_cast (c->factory_).release (c); - } - } -} diff --git a/odb/pgsql/connection-factory.hxx b/odb/pgsql/connection-factory.hxx deleted file mode 100644 index 2f300a8..0000000 --- a/odb/pgsql/connection-factory.hxx +++ /dev/null @@ -1,134 +0,0 @@ -// file : odb/pgsql/connection-factory.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_CONNECTION_FACTORY_HXX -#define ODB_PGSQL_CONNECTION_FACTORY_HXX - -#include - -#include -#include // std::size_t -#include - -#include -#include -#include - -#include -#include -#include - -#include - -namespace odb -{ - namespace pgsql - { - class LIBODB_PGSQL_EXPORT new_connection_factory: public connection_factory - { - public: - new_connection_factory () {} - - virtual connection_ptr - connect (); - - private: - new_connection_factory (const new_connection_factory&); - new_connection_factory& operator= (const new_connection_factory&); - }; - - class LIBODB_PGSQL_EXPORT connection_pool_factory: - public connection_factory - { - public: - // The max_connections argument specifies the maximum number of - // concurrent connections this pool will maintain. If this value - // is 0 then the pool will create a new connection every time all - // of the existing connections are in use. - // - // The min_connections argument specifies the minimum number of - // connections that should be maintained by the pool. If the - // number of connections maintained by the pool exceeds this - // number and there are no active waiters for a new connection, - // then the pool will release the excess connections. If this - // value is 0 then the pool will maintain all the connections - // that were ever created. - // - connection_pool_factory (std::size_t max_connections = 0, - std::size_t min_connections = 0) - : max_ (max_connections), - min_ (min_connections), - in_use_ (0), - waiters_ (0), - cond_ (mutex_) - { - // max_connections == 0 means unlimited. - // - assert (max_connections == 0 || max_connections >= min_connections); - } - - virtual connection_ptr - connect (); - - virtual void - database (database_type&); - - virtual - ~connection_pool_factory (); - - private: - connection_pool_factory (const connection_pool_factory&); - connection_pool_factory& operator= (const connection_pool_factory&); - - protected: - class LIBODB_PGSQL_EXPORT pooled_connection: public connection - { - public: - pooled_connection (connection_pool_factory&); - pooled_connection (connection_pool_factory&, PGconn*); - - private: - static bool - zero_counter (void*); - - private: - friend class connection_pool_factory; - - shared_base::refcount_callback cb_; - }; - - friend class pooled_connection; - - typedef details::shared_ptr pooled_connection_ptr; - typedef std::vector connections; - - // This function is called whenever the pool needs to create a new - // connection. - // - virtual pooled_connection_ptr - create (); - - protected: - // Return true if the connection should be deleted, false otherwise. - // - bool - release (pooled_connection*); - - protected: - const std::size_t max_; - const std::size_t min_; - - std::size_t in_use_; // Number of connections currently in use. - std::size_t waiters_; // Number of threads waiting for a connection. - - connections connections_; - - details::mutex mutex_; - details::condition cond_; - }; - } -} - -#include - -#endif // ODB_PGSQL_CONNECTION_FACTORY_HXX diff --git a/odb/pgsql/connection.cxx b/odb/pgsql/connection.cxx deleted file mode 100644 index 80a1dd2..0000000 --- a/odb/pgsql/connection.cxx +++ /dev/null @@ -1,141 +0,0 @@ -// file : odb/pgsql/connection.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // std::bad_alloc -#include -#include // std::strcmp -#include // std::atol - -#include - -#include -#include -#include -#include -#include -#include - -using namespace std; - -extern "C" void -odb_pgsql_process_notice (void*, const char*) -{ -} - -namespace odb -{ - namespace pgsql - { - connection:: - connection (connection_factory& cf) - : odb::connection (cf), failed_ (false) - { - database_type& db (database ()); - handle_.reset (PQconnectdb (db.conninfo ().c_str ())); - - if (handle_ == 0) - throw bad_alloc (); - else if (PQstatus (handle_) == CONNECTION_BAD) - throw database_exception (PQerrorMessage (handle_)); - - init (); - } - - connection:: - connection (connection_factory& cf, PGconn* handle) - : odb::connection (cf), handle_ (handle), failed_ (false) - { - init (); - } - - void connection:: - init () - { - // Establish whether date/time values are represented as - // 8-byte integers. - // - if (strcmp (PQparameterStatus (handle_, "integer_datetimes"), "on") != 0) - throw database_exception ("unsupported binary format for PostgreSQL " - "date-time SQL types"); - - // Suppress server notifications to stdout. - // - PQsetNoticeProcessor (handle_, &odb_pgsql_process_notice, 0); - - // Create statement cache. - // - statement_cache_.reset (new statement_cache_type (*this)); - } - - connection:: - ~connection () - { - // Destroy prepared query statements before freeing the connections. - // - recycle (); - clear_prepared_map (); - } - - int connection:: - server_version () const - { - return PQserverVersion (handle_); - } - - transaction_impl* connection:: - begin () - { - return new transaction_impl (connection_ptr (inc_ref (this))); - } - - unsigned long long connection:: - execute (const char* s, std::size_t n) - { - // The string may not be '\0'-terminated. - // - string str (s, n); - - { - odb::tracer* t; - if ((t = transaction_tracer ()) || - (t = tracer ()) || - (t = database ().tracer ())) - t->execute (*this, str.c_str ()); - } - - auto_handle h (PQexec (handle_, str.c_str ())); - - unsigned long long count (0); - - if (!is_good_result (h)) - translate_error (*this, h); - else if (PGRES_TUPLES_OK == PQresultStatus (h)) - count = static_cast (PQntuples (h)); - else - { - const char* s (PQcmdTuples (h)); - - if (s[0] != '\0' && s[1] == '\0') - count = static_cast (s[0] - '0'); - else - count = static_cast (atol (s)); - } - - return count; - } - - // connection_factory - // - connection_factory:: - ~connection_factory () - { - } - - void connection_factory:: - database (database_type& db) - { - odb::connection_factory::db_ = &db; - db_ = &db; - } - } -} diff --git a/odb/pgsql/connection.hxx b/odb/pgsql/connection.hxx deleted file mode 100644 index d779273..0000000 --- a/odb/pgsql/connection.hxx +++ /dev/null @@ -1,183 +0,0 @@ -// file : odb/pgsql/connection.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_CONNECTION_HXX -#define ODB_PGSQL_CONNECTION_HXX - -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include // PGconn - -#include - -namespace odb -{ - namespace pgsql - { - class statement_cache; - class connection_factory; - - class connection; - typedef details::shared_ptr connection_ptr; - - class LIBODB_PGSQL_EXPORT connection: public odb::connection - { - public: - typedef pgsql::statement_cache statement_cache_type; - typedef pgsql::database database_type; - - virtual - ~connection (); - - connection (connection_factory&); - connection (connection_factory&, PGconn* handle); - - database_type& - database (); - - public: - virtual transaction_impl* - begin (); - - public: - using odb::connection::execute; - - virtual unsigned long long - execute (const char* statement, std::size_t length); - - // Query preparation. - // - public: - template - prepared_query - prepare_query (const char* name, const char*); - - template - prepared_query - prepare_query (const char* name, const std::string&); - - template - prepared_query - prepare_query (const char* name, const pgsql::query_base&); - - template - prepared_query - prepare_query (const char* name, const odb::query_base&); - - // SQL statement tracing. - // - public: - typedef pgsql::tracer tracer_type; - - void - tracer (tracer_type& t) - { - odb::connection::tracer (t); - } - - void - tracer (tracer_type* t) - { - odb::connection::tracer (t); - } - - using odb::connection::tracer; - - public: - bool - failed () const - { - return failed_; - } - - void - mark_failed () - { - failed_ = true; - } - - public: - PGconn* - handle () - { - return handle_; - } - - // Server version as returned by PQserverVersion(), for example, 90200 - // (9.2.0), 90201 (9.2.1), 100000 (10.0), 110001 (11.1). - // - int - server_version () const; - - statement_cache_type& - statement_cache () - { - return *statement_cache_; - } - - private: - connection (const connection&); - connection& operator= (const connection&); - - private: - void - init (); - - private: - friend class transaction_impl; // invalidate_results() - - private: - auto_handle handle_; - bool failed_; - - // Keep statement_cache_ after handle_ so that it is destroyed before - // the connection is closed. - // - details::unique_ptr statement_cache_; - }; - - class LIBODB_PGSQL_EXPORT connection_factory: - public odb::connection_factory - { - public: - typedef pgsql::database database_type; - - virtual void - database (database_type&); - - database_type& - database () {return *db_;} - - virtual connection_ptr - connect () = 0; - - virtual - ~connection_factory (); - - connection_factory (): db_ (0) {} - - // Needed to break the circular connection_factory-database dependency - // (odb::connection_factory has the odb::database member). - // - protected: - database_type* db_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_CONNECTION_HXX diff --git a/odb/pgsql/connection.ixx b/odb/pgsql/connection.ixx deleted file mode 100644 index 76d558b..0000000 --- a/odb/pgsql/connection.ixx +++ /dev/null @@ -1,44 +0,0 @@ -// file : odb/pgsql/connection.ixx -// license : GNU GPL v2; see accompanying LICENSE file - -namespace odb -{ - namespace pgsql - { - inline database& connection:: - database () - { - return static_cast (factory_).database (); - } - - template - inline prepared_query connection:: - prepare_query (const char* n, const char* q) - { - return prepare_query (n, query (q)); - } - - template - inline prepared_query connection:: - prepare_query (const char* n, const std::string& q) - { - return prepare_query (n, query (q)); - } - - template - inline prepared_query connection:: - prepare_query (const char* n, const pgsql::query_base& q) - { - return query_::call (*this, n, q); - } - - template - inline prepared_query connection:: - prepare_query (const char* n, const odb::query_base& q) - { - // Translate to native query. - // - return prepare_query (n, pgsql::query_base (q)); - } - } -} diff --git a/odb/pgsql/container-statements.hxx b/odb/pgsql/container-statements.hxx deleted file mode 100644 index 1856bb9..0000000 --- a/odb/pgsql/container-statements.hxx +++ /dev/null @@ -1,425 +0,0 @@ -// file : odb/pgsql/container-statements.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_CONTAINER_STATEMENTS_HXX -#define ODB_PGSQL_CONTAINER_STATEMENTS_HXX - -#include - -#include // std::size_t - -#include -#include -#include - -#include -#include -#include -#include // Oid -#include - -namespace odb -{ - namespace pgsql - { - class connection; - - // Template argument is the generated abstract container traits type. - // That is, it doesn't need to provide column counts and statements. - // - template - class container_statements - { - public: - typedef T traits; - - typedef typename traits::data_image_type data_image_type; - typedef typename traits::functions_type functions_type; - - typedef pgsql::insert_statement insert_statement_type; - typedef pgsql::select_statement select_statement_type; - typedef pgsql::delete_statement delete_statement_type; - - typedef pgsql::connection connection_type; - - container_statements (connection_type&, - binding& id, - native_binding& idn, - const Oid* idt); - - connection_type& - connection () - { - return conn_; - } - - // Functions. - // - functions_type& - functions () - { - return functions_; - } - - // Schema version. - // - const schema_version_migration& - version_migration () const {return *svm_;} - - void - version_migration (const schema_version_migration& svm) {svm_ = &svm;} - - // Id image binding (external). - // - const binding& - id_binding () - { - return id_binding_; - } - - // Data image. The image is split into the id (that comes as a - // binding) and index/key plus value which are in data_image_type. - // The select binding is a subset of the full binding (no id). - // - data_image_type& - data_image () - { - return data_image_; - } - - bind* - data_bind () - { - return insert_image_binding_.bind; - } - - bool - data_binding_test_version () const - { - return data_id_binding_version_ != id_binding_.version || - data_image_version_ != data_image_.version || - insert_image_binding_.version == 0; - } - - void - data_binding_update_version () - { - data_id_binding_version_ = id_binding_.version; - data_image_version_ = data_image_.version; - insert_image_binding_.version++; - select_image_binding_.version++; - } - - bool* - select_image_truncated () - { - return select_image_truncated_; - } - - // - // Statements. - // - - insert_statement_type& - insert_statement () - { - if (insert_ == 0) - insert_.reset ( - new (details::shared) insert_statement_type ( - conn_, - insert_name_, - insert_text_, - versioned_, // Process if versioned. - insert_types_, - insert_count_, - insert_image_binding_, - insert_image_native_binding_, - 0, - false)); - - return *insert_; - } - - select_statement_type& - select_statement () - { - if (select_ == 0) - select_.reset ( - new (details::shared) select_statement_type ( - conn_, - select_name_, - select_text_, - versioned_, // Process if versioned. - false, // Don't optimize. - id_types_, - id_binding_.count, - id_binding_, - id_native_binding_, - select_image_binding_, - false)); - - return *select_; - } - - delete_statement_type& - delete_statement () - { - if (delete_ == 0) - delete_.reset ( - new (details::shared) delete_statement_type ( - conn_, - delete_name_, - delete_text_, - id_types_, - id_binding_.count, - id_binding_, - id_native_binding_, - false)); - - return *delete_; - } - - private: - container_statements (const container_statements&); - container_statements& operator= (const container_statements&); - - protected: - connection_type& conn_; - binding& id_binding_; - native_binding& id_native_binding_; - const Oid* id_types_; - - functions_type functions_; - - data_image_type data_image_; - std::size_t data_image_version_; - std::size_t data_id_binding_version_; - - binding insert_image_binding_; - native_binding insert_image_native_binding_; - - binding select_image_binding_; - bool* select_image_truncated_; - - const char* insert_name_; - const char* insert_text_; - const Oid* insert_types_; - std::size_t insert_count_; - - const char* select_name_; - const char* select_text_; - - const char* delete_name_; - const char* delete_text_; - - bool versioned_; - const schema_version_migration* svm_; - - details::shared_ptr insert_; - details::shared_ptr select_; - details::shared_ptr delete_; - }; - - template - class smart_container_statements: public container_statements - { - public: - typedef T traits; - typedef typename traits::cond_image_type cond_image_type; - - typedef pgsql::update_statement update_statement_type; - typedef pgsql::delete_statement delete_statement_type; - - typedef pgsql::connection connection_type; - - smart_container_statements (connection_type&, - binding& id, - native_binding& idn, - const Oid* idt); - - // Condition image. The image is split into the id (that comes as - // a binding) and index/key/value which is in cond_image_type. - // - cond_image_type& - cond_image () - { - return cond_image_; - } - - bind* - cond_bind () - { - return cond_image_binding_.bind; - } - - bool - cond_binding_test_version () const - { - return cond_id_binding_version_ != this->id_binding_.version || - cond_image_version_ != cond_image_.version || - cond_image_binding_.version == 0; - } - - void - cond_binding_update_version () - { - cond_id_binding_version_ = this->id_binding_.version; - cond_image_version_ = cond_image_.version; - cond_image_binding_.version++; - } - - // Update image. The image is split as follows: value comes - // from the data image, id comes as binding, and index/key - // comes from the condition image. - // - bind* - update_bind () - { - return update_image_binding_.bind; - } - - bool - update_binding_test_version () const - { - return update_id_binding_version_ != this->id_binding_.version || - update_cond_image_version_ != cond_image_.version || - update_data_image_version_ != this->data_image_.version || - update_image_binding_.version == 0; - } - - void - update_binding_update_version () - { - update_id_binding_version_ = this->id_binding_.version; - update_cond_image_version_ = cond_image_.version; - update_data_image_version_ = this->data_image_.version; - update_image_binding_.version++; - } - - // - // Statements. - // - - delete_statement_type& - delete_statement () - { - if (this->delete_ == 0) - this->delete_.reset ( - new (details::shared) delete_statement_type ( - this->conn_, - this->delete_name_, - this->delete_text_, - delete_types_, - delete_count_, - cond_image_binding_, - cond_image_native_binding_, - false)); - - return *this->delete_; - } - - update_statement_type& - update_statement () - { - if (update_ == 0) - update_.reset ( - new (details::shared) update_statement_type ( - this->conn_, - update_name_, - update_text_, - this->versioned_, // Process if versioned. - update_types_, - update_count_, - update_image_binding_, - update_image_native_binding_, - false)); - - return *update_; - } - - protected: - cond_image_type cond_image_; - std::size_t cond_image_version_; - std::size_t cond_id_binding_version_; - binding cond_image_binding_; - native_binding cond_image_native_binding_; - - std::size_t update_id_binding_version_; - std::size_t update_cond_image_version_; - std::size_t update_data_image_version_; - binding update_image_binding_; - native_binding update_image_native_binding_; - - const char* update_name_; - const char* update_text_; - const Oid* update_types_; - std::size_t update_count_; - - const Oid* delete_types_; - std::size_t delete_count_; - - details::shared_ptr update_; - }; - - // Template argument is the generated concrete container traits type. - // - template - class container_statements_impl: public T::statements_type - { - public: - typedef T traits; - typedef typename T::statements_type base; - typedef pgsql::connection connection_type; - - container_statements_impl (connection_type&, - binding&, - native_binding&, - const Oid*); - private: - container_statements_impl (const container_statements_impl&); - container_statements_impl& operator= (const container_statements_impl&); - - private: - bind data_image_bind_[traits::data_column_count]; - char* data_image_values_[traits::data_column_count]; - int data_image_lengths_[traits::data_column_count]; - int data_image_formats_[traits::data_column_count]; - - bool select_image_truncated_array_[traits::data_column_count - - traits::id_column_count]; - }; - - template - class smart_container_statements_impl: public container_statements_impl - { - public: - typedef T traits; - typedef pgsql::connection connection_type; - - smart_container_statements_impl (connection_type&, - binding&, - native_binding&, - const Oid*); - private: - bind cond_image_bind_[traits::cond_column_count]; - char* cond_image_values_[traits::cond_column_count]; - int cond_image_lengths_[traits::cond_column_count]; - int cond_image_formats_[traits::cond_column_count]; - - bind update_image_bind_[traits::value_column_count + - traits::cond_column_count]; - char* update_image_values_[traits::value_column_count + - traits::cond_column_count]; - int update_image_lengths_[traits::value_column_count + - traits::cond_column_count]; - int update_image_formats_[traits::value_column_count + - traits::cond_column_count]; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_CONTAINER_STATEMENTS_HXX diff --git a/odb/pgsql/container-statements.txx b/odb/pgsql/container-statements.txx deleted file mode 100644 index 34eb99f..0000000 --- a/odb/pgsql/container-statements.txx +++ /dev/null @@ -1,154 +0,0 @@ -// file : odb/pgsql/container-statements.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // std::size_t -#include // std::memset - -namespace odb -{ - namespace pgsql - { - // container_statements - // - template - container_statements:: - container_statements (connection_type& conn, - binding& id, - native_binding& idn, - const Oid* idt) - : conn_ (conn), - id_binding_ (id), - id_native_binding_ (idn), - id_types_ (idt), - functions_ (this), - insert_image_binding_ (0, 0), // Initialized by impl. - insert_image_native_binding_ (0, 0, 0, 0), // Initialized by impl. - select_image_binding_ (0, 0), // Initialized by impl. - svm_ (0) - { - functions_.insert_ = &traits::insert; - functions_.select_ = &traits::select; - functions_.delete__ = &traits::delete_; - - data_image_.version = 0; - data_image_version_ = 0; - data_id_binding_version_ = 0; - } - - // smart_container_statements - // - template - smart_container_statements:: - smart_container_statements (connection_type& conn, - binding& id, - native_binding& idn, - const Oid* idt) - : container_statements (conn, id, idn, idt), - cond_image_binding_ (0, 0), // Initialized by impl. - cond_image_native_binding_ (0, 0, 0, 0), // Initialized by impl. - update_image_binding_ (0, 0), // Initialized by impl. - update_image_native_binding_ (0, 0, 0, 0) // Initialized by impl. - { - this->functions_.update_ = &traits::update; - - cond_image_.version = 0; - cond_image_version_ = 0; - cond_id_binding_version_ = 0; - - update_id_binding_version_ = 0; - update_cond_image_version_ = 0; - update_data_image_version_ = 0; - } - - // container_statements_impl - // - template - container_statements_impl:: - container_statements_impl (connection_type& conn, - binding& id, - native_binding& idn, - const Oid* idt) - : base (conn, id, idn, idt) - { - this->select_image_truncated_ = select_image_truncated_array_; - - this->insert_image_binding_.bind = data_image_bind_; - this->insert_image_binding_.count = traits::data_column_count; - - this->select_image_binding_.bind = data_image_bind_ + - traits::id_column_count; - this->select_image_binding_.count = traits::data_column_count - - traits::id_column_count; - - this->insert_image_native_binding_.values = data_image_values_; - this->insert_image_native_binding_.lengths = data_image_lengths_; - this->insert_image_native_binding_.formats = data_image_formats_; - this->insert_image_native_binding_.count = traits::data_column_count; - - std::memset (data_image_bind_, 0, sizeof (data_image_bind_)); - std::memset (select_image_truncated_array_, - 0, - sizeof (select_image_truncated_array_)); - - for (std::size_t i (0); - i < traits::data_column_count - traits::id_column_count; - ++i) - data_image_bind_[i + traits::id_column_count].truncated = - select_image_truncated_array_ + i; - - this->insert_name_ = traits::insert_name; - this->insert_text_ = traits::insert_statement; - this->insert_types_ = traits::insert_types; - this->insert_count_ = traits::data_column_count; - - this->select_name_ = traits::select_name; - this->select_text_ = traits::select_statement; - - this->delete_name_ = traits::delete_name; - this->delete_text_ = traits::delete_statement; - - this->versioned_ = traits::versioned; - } - - // smart_container_statements_impl - // - template - smart_container_statements_impl:: - smart_container_statements_impl (connection_type& conn, - binding& id, - native_binding& idn, - const Oid* idt) - : container_statements_impl (conn, id, idn, idt) - { - this->cond_image_binding_.bind = cond_image_bind_; - this->cond_image_binding_.count = traits::cond_column_count; - - this->update_image_binding_.bind = update_image_bind_; - this->update_image_binding_.count = traits::value_column_count + - traits::cond_column_count; - - this->cond_image_native_binding_.values = cond_image_values_; - this->cond_image_native_binding_.lengths = cond_image_lengths_; - this->cond_image_native_binding_.formats = cond_image_formats_; - this->cond_image_native_binding_.count = traits::cond_column_count; - - this->update_image_native_binding_.values = update_image_values_; - this->update_image_native_binding_.lengths = update_image_lengths_; - this->update_image_native_binding_.formats = update_image_formats_; - this->update_image_native_binding_.count = traits::value_column_count + - traits::cond_column_count; - - std::memset (cond_image_bind_, 0, sizeof (cond_image_bind_)); - std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); - - this->update_name_ = traits::update_name; - this->update_text_ = traits::update_statement; - this->update_types_ = traits::update_types; - this->update_count_ = traits::value_column_count + - traits::cond_column_count; - - this->delete_types_ = traits::delete_types; - this->delete_count_ = traits::cond_column_count; - } - } -} diff --git a/odb/pgsql/database.cxx b/odb/pgsql/database.cxx deleted file mode 100644 index 09bf6f0..0000000 --- a/odb/pgsql/database.cxx +++ /dev/null @@ -1,424 +0,0 @@ -// file : odb/pgsql/database.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // strlen() -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; - -namespace odb -{ - namespace pgsql - { - using odb::details::transfer_ptr; - - database:: - database (const string& user, - const string& password, - const string& db, - const string& host, - unsigned int port, - const string& extra_conninfo, - transfer_ptr factory) - : odb::database (id_pgsql), - user_ (user), - password_ (password), - db_ (db), - host_ (host), - port_ (port), - extra_conninfo_ (extra_conninfo), - factory_ (factory.transfer ()) - { - ostringstream ss; - - if (!user.empty ()) - ss << "user='" << user << "' "; - - if (!password.empty ()) - ss << "password='" << password << "' "; - - if (!db.empty ()) - ss << "dbname='" << db << "' "; - - if (!host.empty ()) - ss << "host='" << host << "' "; - - if (port) - ss << "port=" << port << " "; - - // Only the last occurence of keyword/value pair is used by libpq. - // extra_conninfo specified options take precedence. - // - if (!extra_conninfo.empty ()) - ss << extra_conninfo; - - conninfo_ = ss.str (); - - if (!factory_) - factory_.reset (new connection_pool_factory ()); - - factory_->database (*this); - } - - database:: - database (const string& user, - const string& password, - const string& db, - const string& host, - const string& socket_ext, - const string& extra_conninfo, - transfer_ptr factory) - : odb::database (id_pgsql), - user_ (user), - password_ (password), - db_ (db), - host_ (host), - port_ (0), - socket_ext_ (socket_ext), - extra_conninfo_ (extra_conninfo), - factory_ (factory.transfer ()) - { - ostringstream ss; - - if (!user.empty ()) - ss << "user='" << user << "' "; - - if (!password.empty ()) - ss << "password='" << password << "' "; - - if (!db.empty ()) - ss << "dbname='" << db << "' "; - - if (!host.empty ()) - ss << "host='" << host << "' "; - - if (!socket_ext.empty ()) - ss << "port='" << socket_ext << "' "; - - // Only the last occurence of keyword/value pair is used by libpq. - // extra_conninfo specified options take precedence. - // - if (!extra_conninfo.empty ()) - ss << extra_conninfo; - - conninfo_ = ss.str (); - - if (!factory_) - factory_.reset (new connection_pool_factory ()); - - factory_->database (*this); - } - - database:: - database (const string& conninfo, transfer_ptr factory) - : odb::database (id_pgsql), - port_ (0), - conninfo_ (conninfo), - factory_ (factory.transfer ()) - { - if (!factory_) - factory_.reset (new connection_pool_factory ()); - - factory_->database (*this); - } - - database:: - database (int& argc, - char* argv[], - bool erase, - const string& extra_conninfo, - transfer_ptr factory) - : odb::database (id_pgsql), port_ (0), factory_ (factory.transfer ()) - { - using namespace details; - - try - { - cli::argv_file_scanner scan (argc, argv, "--options-file", erase); - options ops (scan, cli::unknown_mode::skip, cli::unknown_mode::skip); - - ostringstream oss; - - if (ops.user_specified ()) - { - user_ = ops.user (); - oss << "user='" << user_ << "' "; - } - - if (ops.password_specified ()) - { - password_ = ops.password (); - oss << "password='" << password_ << "' "; - } - - if (ops.database_specified ()) - { - db_ = ops.database (); - oss << "dbname='" << db_ << "' "; - } - - if (ops.host_specified ()) - { - host_ = ops.host (); - oss << "host='" << host_ << "' "; - } - - if (ops.port_specified ()) - { - istringstream iss (ops.port ()); - - if (iss >> port_ && iss.eof ()) - oss << " port=" << port_ << " "; - else - { - port_ = 0; - socket_ext_ = ops.port (); - oss << "port='" << socket_ext_ << "' "; - } - } - - if (!extra_conninfo.empty ()) - oss << extra_conninfo; - - conninfo_ = oss.str (); - } - catch (const cli::exception& e) - { - ostringstream oss; - oss << e; - throw cli_exception (oss.str ()); - } - - if (!factory_) - factory_.reset (new connection_pool_factory ()); - - factory_->database (*this); - } - - void database:: - print_usage (std::ostream& os) - { - details::options::print_usage (os); - } - - database:: - ~database () - { - } - - transaction_impl* database:: - begin () - { - return new transaction_impl (*this); - } - - odb::connection* database:: - connection_ () - { - connection_ptr c (factory_->connect ()); - return c.release (); - } - - const database::schema_version_info& database:: - load_schema_version (const string& name) const - { - schema_version_info& svi (schema_version_map_[name]); - - // Quoted table name. - // - const char* table ( - !svi.version_table.empty () ? svi.version_table.c_str () : - !schema_version_table_.empty () ? schema_version_table_.c_str () : - /* */ "\"schema_version\""); - - // Construct the SELECT statement text. - // - string text ("SELECT \"version\", \"migration\" FROM "); - text += table; - text += " WHERE \"name\" = $1"; - - // Bind parameters and results. - // - char* pbuf[1] = {const_cast (name.c_str ())}; - size_t psize[1] = {name.size ()}; - bool pnull[1] = {false}; - bind pbind[1] = {{bind::text, - &pbuf[0], - &psize[0], - psize[0], - &pnull[0], - 0}}; - binding param (pbind, 1); - param.version++; - - unsigned int param_types[1] = {text_oid}; - - char* values[1]; - int lengths[1]; - int formats[1]; - native_binding nparam (values, lengths, formats, 1); - - long long version; - bool rnull[2]; - bind rbind[2] = {{bind::bigint, &version, 0, 0, &rnull[0], 0}, - {bind::boolean_, &svi.migration, 0, 0, &rnull[1], 0}}; - binding result (rbind, 2); - result.version++; - - // If we are not in transaction, PostgreSQL will start an implicit one - // which suits us just fine. - // - connection_ptr cp; - if (!transaction::has_current ()) - cp = factory_->connect (); - - pgsql::connection& c ( - cp != 0 - ? *cp - : transaction::current ().connection (const_cast (*this))); - - // If we are in the user's transaction then things are complicated. When - // we try to execute SELECT on a non-existent table, PG "poisons" the - // transaction (those "current transaction is aborted, commands ignored - // until end of transaction block" messages in the log). Which means all - // the user's schema creation statements that are likely to follow will - // fail. - // - // There doesn't seem to be a better way to solve this than to check for - // the table's existence. It is relatively easy to do with to_regclass() - // in 9.4+ and a real pain in earlier versions. So we are going to do - // this for 9.4+ and for older versions the workaround is to "pre-call" - // database::schema_version() outside of any transaction. - // - bool exists (true); - if (cp == 0 && c.server_version () >= 90400) - { - char* pbuf[1] = {const_cast (table)}; - size_t psize[1] = {strlen (table)}; - bool pnull[1] = {false}; - bind pbind[1] = {{bind::text, - &pbuf[0], - &psize[0], - psize[0], - &pnull[0], - 0}}; - binding param (pbind, 1); - param.version++; - - unsigned int param_types[1] = {text_oid}; - - char* values[1]; - int lengths[1]; - int formats[1]; - native_binding nparam (values, lengths, formats, 1); - - bool rnull[1]; - bind rbind[1] = {{bind::boolean_, &exists, 0, 0, &rnull[0], 0}}; - binding result (rbind, 1); - result.version++; - - // Note that to_regclass() seems happy to accept a quoted table name. - // - // Also note that starting 9.6 it requires text type rather than - // cstring type. - // - select_statement st (c, - "odb_database_schema_version_exists", - c.server_version () >= 90600 - ? "SELECT to_regclass($1::text) IS NOT NULL" - : "SELECT to_regclass($1::cstring) IS NOT NULL", - false, // Don't process. - false, // Don't optimize. - param_types, - 1, - param, - nparam, - result, - false); - - st.execute (); - auto_result ar (st); - - switch (st.fetch ()) - { - case select_statement::success: - { - assert (st.fetch () == select_statement::no_data); - break; - } - case select_statement::no_data: - case select_statement::truncated: - { - assert (false); - break; - } - } - } - - // Assume no schema until determined otherwise. - // - svi.version = 0; - - if (exists) - { - try - { - select_statement st (c, - "odb_database_schema_version_query", - text.c_str (), - false, // Don't process. - false, // Don't optimize. - param_types, - 1, - param, - nparam, - result, - false); - st.execute (); - auto_result ar (st); - - switch (st.fetch ()) - { - case select_statement::success: - { - value_traits::set_value ( - svi.version, version, rnull[0]); - assert (st.fetch () == select_statement::no_data); - break; - } - case select_statement::no_data: - { - // No schema. - break; - } - case select_statement::truncated: - { - assert (false); - break; - } - } - } - catch (const database_exception& e) - { - // Detect the case where there is no version table (the implicit - // transaction case). - // - if (e.sqlstate () != "42P01") - throw; - } - } - - return svi; - } - } -} diff --git a/odb/pgsql/database.hxx b/odb/pgsql/database.hxx deleted file mode 100644 index 950cad1..0000000 --- a/odb/pgsql/database.hxx +++ /dev/null @@ -1,527 +0,0 @@ -// file : odb/pgsql/database.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_DATABASE_HXX -#define ODB_PGSQL_DATABASE_HXX - -#include - -#include -#include // std::ostream - -#include -#include // ODB_CXX11 -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -namespace odb -{ - namespace pgsql - { - class transaction_impl; - - class LIBODB_PGSQL_EXPORT database: public odb::database - { - public: - database (const std::string& user, - const std::string& password, - const std::string& db, - const std::string& host = "", - unsigned int port = 0, - const std::string& extra_conninfo = "", - details::transfer_ptr = - details::transfer_ptr ()); - - database (const std::string& user, - const std::string& password, - const std::string& db, - const std::string& host, - const std::string& socket_ext, - const std::string& extra_conninfo = "", - details::transfer_ptr = - details::transfer_ptr ()); - - explicit - database (const std::string& conninfo, - details::transfer_ptr = - details::transfer_ptr ()); - - // Extract the database parameters from the command line. The - // following options are recognized: - // - // --user | --username - // --password - // --database | --dbname - // --host - // --port - // --options-file - // - // For more information, see the output of the print_usage() function - // below. If erase is true, the above options are removed from the - // argv array and the argc count is updated accordingly. This - // constructor may throw the cli_exception exception. - // - database (int& argc, - char* argv[], - bool erase = false, - const std::string& extra_conninfo = "", - details::transfer_ptr = - details::transfer_ptr ()); - - // Move-constructible but not move-assignable. - // - // Note: noexcept is not specified since odb::database(odb::database&&) - // can throw. - // -#ifdef ODB_CXX11 - database (database&&); -#endif - - static void - print_usage (std::ostream&); - - // Object persistence API. - // - public: - - // Make the object persistent. - // - template - typename object_traits::id_type - persist (T& object); - - template - typename object_traits::id_type - persist (const T& object); - - template - typename object_traits::id_type - persist (T* obj_ptr); - - template class P> - typename object_traits::id_type - persist (const P& obj_ptr); - - template class P> - typename object_traits::id_type - persist (const P& obj_ptr); - - template class P> - typename object_traits::id_type - persist (P& obj_ptr); - - template class P> - typename object_traits::id_type - persist (P& obj_ptr); - - template - typename object_traits::id_type - persist (const typename object_traits::pointer_type& obj_ptr); - - // Bulk persist. Can be a range of references or pointers (including - // smart pointers) to objects. - // - template - void - persist (I begin, I end, bool continue_failed = true); - - // Load an object. Throw object_not_persistent if not found. - // - template - typename object_traits::pointer_type - load (const typename object_traits::id_type& id); - - template - void - load (const typename object_traits::id_type& id, T& object); - - // Load (or reload, if it is already loaded) a section of an object. - // - template - void - load (T& object, section&); - - // Reload an object. - // - template - void - reload (T& object); - - template - void - reload (T* obj_ptr); - - template class P> - void - reload (const P& obj_ptr); - - template class P> - void - reload (const P& obj_ptr); - - template class P> - void - reload (P& obj_ptr); - - template class P> - void - reload (P& obj_ptr); - - template - void - reload (const typename object_traits::pointer_type& obj_ptr); - - // Loan an object if found. Return NULL/false if not found. - // - template - typename object_traits::pointer_type - find (const typename object_traits::id_type& id); - - template - bool - find (const typename object_traits::id_type& id, T& object); - - // Update the state of a modified objects. - // - template - void - update (T& object); - - template - void - update (T* obj_ptr); - - template class P> - void - update (const P& obj_ptr); - - template class P> - void - update (const P& obj_ptr); - - template class P> - void - update (P& obj_ptr); - - template class P> - void - update (P& obj_ptr); - - template - void - update (const typename object_traits::pointer_type& obj_ptr); - - // Bulk update. Can be a range of references or pointers (including - // smart pointers) to objects. - // - template - void - update (I begin, I end, bool continue_failed = true); - - // Update a section of an object. Throws the section_not_loaded - // exception if the section is not loaded. Note also that this - // function does not clear the changed flag if it is set. - // - template - void - update (const T& object, const section&); - - // Make the object transient. Throw object_not_persistent if not - // found. - // - template - void - erase (const typename object_traits::id_type& id); - - template - void - erase (T& object); - - template - void - erase (T* obj_ptr); - - template class P> - void - erase (const P& obj_ptr); - - template class P> - void - erase (const P& obj_ptr); - - template class P> - void - erase (P& obj_ptr); - - template class P> - void - erase (P& obj_ptr); - - template - void - erase (const typename object_traits::pointer_type& obj_ptr); - - // Bulk erase. - // - template - void - erase (I id_begin, I id_end, bool continue_failed = true); - - // Can be a range of references or pointers (including smart pointers) - // to objects. - // - template - void - erase (I obj_begin, I obj_end, bool continue_failed = true); - - // Erase multiple objects matching a query predicate. - // - template - unsigned long long - erase_query (); - - template - unsigned long long - erase_query (const char*); - - template - unsigned long long - erase_query (const std::string&); - - template - unsigned long long - erase_query (const pgsql::query_base&); - - template - unsigned long long - erase_query (const odb::query_base&); - - // Query API. - // - template - result - query (); - - template - result - query (const char*); - - template - result - query (const std::string&); - - template - result - query (const pgsql::query_base&); - - template - result - query (const odb::query_base&); - - // Query one API. - // - template - typename result::pointer_type - query_one (); - - template - bool - query_one (T& object); - - template - T - query_value (); - - template - typename result::pointer_type - query_one (const char*); - - template - bool - query_one (const char*, T& object); - - template - T - query_value (const char*); - - template - typename result::pointer_type - query_one (const std::string&); - - template - bool - query_one (const std::string&, T& object); - - template - T - query_value (const std::string&); - - template - typename result::pointer_type - query_one (const pgsql::query_base&); - - template - bool - query_one (const pgsql::query_base&, T& object); - - template - T - query_value (const pgsql::query_base&); - - template - typename result::pointer_type - query_one (const odb::query_base&); - - template - bool - query_one (const odb::query_base&, T& object); - - template - T - query_value (const odb::query_base&); - - // Query preparation. - // - template - prepared_query - prepare_query (const char* name, const char*); - - template - prepared_query - prepare_query (const char* name, const std::string&); - - template - prepared_query - prepare_query (const char* name, const pgsql::query_base&); - - template - prepared_query - prepare_query (const char* name, const odb::query_base&); - - // Transactions. - // - public: - virtual transaction_impl* - begin (); - - public: - connection_ptr - connection (); - - // Database schema version. - // - protected: - virtual const schema_version_info& - load_schema_version (const std::string& schema_name) const; - - public: - // Database id constant (useful for meta-programming). - // - static const odb::database_id database_id = id_pgsql; - - public: - virtual - ~database (); - - protected: - virtual odb::connection* - connection_ (); - - // SQL statement tracing. - // - public: - typedef pgsql::tracer tracer_type; - - void - tracer (tracer_type& t) - { - odb::database::tracer (t); - } - - void - tracer (tracer_type* t) - { - odb::database::tracer (t); - } - - using odb::database::tracer; - - public: - const std::string& - user () const - { - return user_; - } - - const std::string& - password () const - { - return password_; - } - - const std::string& - db () const - { - return db_; - } - - const std::string& - host () const - { - return host_; - } - - unsigned int - port () const - { - return port_; - } - - const std::string& - socket_ext () const - { - return socket_ext_; - } - - const std::string& - extra_conninfo () const - { - return extra_conninfo_; - } - - const std::string& - conninfo () const - { - return conninfo_; - } - - private: - // Note: remember to update move ctor if adding any new members. - // - std::string user_; - std::string password_; - std::string db_; - std::string host_; - unsigned int port_; - std::string socket_ext_; - std::string extra_conninfo_; - std::string conninfo_; - details::unique_ptr factory_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_DATABASE_HXX diff --git a/odb/pgsql/database.ixx b/odb/pgsql/database.ixx deleted file mode 100644 index f04c3e6..0000000 --- a/odb/pgsql/database.ixx +++ /dev/null @@ -1,638 +0,0 @@ -// file : odb/pgsql/database.ixx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // move() - -#include - -namespace odb -{ - namespace pgsql - { -#ifdef ODB_CXX11 - inline database:: - database (database&& db) // Has to be inline. - : odb::database (std::move (db)), - user_ (std::move (db.user_)), - password_ (std::move (db.password_)), - db_ (std::move (db.db_)), - host_ (std::move (db.host_)), - port_ (db.port_), - socket_ext_ (std::move (db.socket_ext_)), - extra_conninfo_ (std::move (db.extra_conninfo_)), - conninfo_ (std::move (db.conninfo_)), - factory_ (std::move (db.factory_)) - { - factory_->database (*this); // New database instance. - } -#endif - - inline connection_ptr database:: - connection () - { - // Go through the virtual connection_() function instead of - // directly to allow overriding. - // - return connection_ptr ( - static_cast (connection_ ())); - } - - template - inline typename object_traits::id_type database:: - persist (T& obj) - { - return persist_ (obj); - } - - template - inline typename object_traits::id_type database:: - persist (const T& obj) - { - return persist_ (obj); - } - - template - inline typename object_traits::id_type database:: - persist (T* p) - { - typedef typename object_traits::pointer_type object_pointer; - - // The passed pointer should be the same or implicit-convertible - // to the object pointer. This way we make sure the object pointer - // does not assume ownership of the passed object. - // - const object_pointer& pobj (p); - - return persist_ (pobj); - } - - template class P> - inline typename object_traits::id_type database:: - persist (const P& p) - { - typedef typename object_traits::pointer_type object_pointer; - - // The passed pointer should be the same or implicit-convertible - // to the object pointer. This way we make sure the object pointer - // does not assume ownership of the passed object. - // - const object_pointer& pobj (p); - - return persist_ (pobj); - } - - template class P> - inline typename object_traits::id_type database:: - persist (const P& p) - { - typedef typename object_traits::pointer_type object_pointer; - - // The passed pointer should be the same or implicit-convertible - // to the object pointer. This way we make sure the object pointer - // does not assume ownership of the passed object. - // - const object_pointer& pobj (p); - - return persist_ (pobj); - } - - template class P> - inline typename object_traits::id_type database:: - persist (P& p) - { - const P& cr (p); - return persist (cr); - } - - template class P> - inline typename object_traits::id_type database:: - persist (P& p) - { - const P& cr (p); - return persist (cr); - } - - template - inline typename object_traits::id_type database:: - persist (const typename object_traits::pointer_type& pobj) - { - return persist_ (pobj); - } - - template - inline void database:: - persist (I b, I e, bool cont) - { - persist_ (b, e, cont); - } - - template - inline typename object_traits::pointer_type database:: - load (const typename object_traits::id_type& id) - { - return load_ (id); - } - - template - inline void database:: - load (const typename object_traits::id_type& id, T& obj) - { - return load_ (id, obj); - } - - template - inline void database:: - load (T& obj, section& s) - { - return load_ (obj, s); - } - - template - inline typename object_traits::pointer_type database:: - find (const typename object_traits::id_type& id) - { - return find_ (id); - } - - template - inline bool database:: - find (const typename object_traits::id_type& id, T& obj) - { - return find_ (id, obj); - } - - template - inline void database:: - reload (T& obj) - { - reload_ (obj); - } - - template - inline void database:: - reload (T* p) - { - reload (*p); - } - - template class P> - inline void database:: - reload (const P& p) - { - reload (odb::pointer_traits< P >::get_ref (p)); - } - - template class P> - inline void database:: - reload (const P& p) - { - reload (odb::pointer_traits< P >::get_ref (p)); - } - - template class P> - inline void database:: - reload (P& p) - { - reload (odb::pointer_traits< P >::get_ref (p)); - } - - template class P> - inline void database:: - reload (P& p) - { - reload (odb::pointer_traits< P >::get_ref (p)); - } - - template - inline void database:: - reload (const typename object_traits::pointer_type& pobj) - { - typedef typename object_traits::pointer_type pointer_type; - - reload (odb::pointer_traits::get_ref (pobj)); - } - - template - inline void database:: - update (T& obj) - { - update_ (obj); - } - - template - inline void database:: - update (T* p) - { - typedef typename object_traits::pointer_type object_pointer; - - // The passed pointer should be the same or implicit-convertible - // to the object pointer. This way we make sure the object pointer - // does not assume ownership of the passed object. - // - const object_pointer& pobj (p); - - update_ (pobj); - } - - template class P> - inline void database:: - update (const P& p) - { - typedef typename object_traits::pointer_type object_pointer; - - // The passed pointer should be the same or implicit-convertible - // to the object pointer. This way we make sure the object pointer - // does not assume ownership of the passed object. - // - const object_pointer& pobj (p); - - update_ (pobj); - } - - template class P> - inline void database:: - update (const P& p) - { - typedef typename object_traits::pointer_type object_pointer; - - // The passed pointer should be the same or implicit-convertible - // to the object pointer. This way we make sure the object pointer - // does not assume ownership of the passed object. - // - const object_pointer& pobj (p); - - update_ (pobj); - } - - template class P> - inline void database:: - update (P& p) - { - const P& cr (p); - update (cr); - } - - template class P> - inline void database:: - update (P& p) - { - const P& cr (p); - update (cr); - } - - template - inline void database:: - update (const typename object_traits::pointer_type& pobj) - { - update_ (pobj); - } - - template - inline void database:: - update (I b, I e, bool cont) - { - update_ (b, e, cont); - } - - template - inline void database:: - update (const T& obj, const section& s) - { - update_ (obj, s); - } - - template - inline void database:: - erase (const typename object_traits::id_type& id) - { - return erase_ (id); - } - - template - inline void database:: - erase (T& obj) - { - return erase_ (obj); - } - - template - inline void database:: - erase (T* p) - { - typedef typename object_traits::pointer_type object_pointer; - - // The passed pointer should be the same or implicit-convertible - // to the object pointer. This way we make sure the object pointer - // does not assume ownership of the passed object. - // - const object_pointer& pobj (p); - - erase_ (pobj); - } - - template class P> - inline void database:: - erase (const P& p) - { - typedef typename object_traits::pointer_type object_pointer; - - // The passed pointer should be the same or implicit-convertible - // to the object pointer. This way we make sure the object pointer - // does not assume ownership of the passed object. - // - const object_pointer& pobj (p); - - erase_ (pobj); - } - - template class P> - inline void database:: - erase (const P& p) - { - typedef typename object_traits::pointer_type object_pointer; - - // The passed pointer should be the same or implicit-convertible - // to the object pointer. This way we make sure the object pointer - // does not assume ownership of the passed object. - // - const object_pointer& pobj (p); - - erase_ (pobj); - } - - template class P> - inline void database:: - erase (P& p) - { - const P& cr (p); - erase (cr); - } - - template class P> - inline void database:: - erase (P& p) - { - const P& cr (p); - erase (cr); - } - - template - inline void database:: - erase (const typename object_traits::pointer_type& pobj) - { - erase_ (pobj); - } - - template - inline void database:: - erase (I idb, I ide, bool cont) - { - erase_id_ (idb, ide, cont); - } - - template - inline void database:: - erase (I ob, I oe, bool cont) - { - erase_object_ (ob, oe, cont); - } - - template - inline unsigned long long database:: - erase_query () - { - // T is always object_type. - // - return erase_query (pgsql::query_base ()); - } - - template - inline unsigned long long database:: - erase_query (const char* q) - { - // T is always object_type. - // - return erase_query (pgsql::query_base (q)); - } - - template - inline unsigned long long database:: - erase_query (const std::string& q) - { - // T is always object_type. - // - return erase_query (pgsql::query_base (q)); - } - - template - inline unsigned long long database:: - erase_query (const pgsql::query_base& q) - { - // T is always object_type. - // - return object_traits_impl::erase_query (*this, q); - } - - template - inline unsigned long long database:: - erase_query (const odb::query_base& q) - { - // Translate to native query. - // - return erase_query (pgsql::query_base (q)); - } - - template - inline result database:: - query () - { - return query (pgsql::query_base ()); - } - - template - inline result database:: - query (const char* q) - { - return query (pgsql::query_base (q)); - } - - template - inline result database:: - query (const std::string& q) - { - return query (pgsql::query_base (q)); - } - - template - inline result database:: - query (const pgsql::query_base& q) - { - // T is always object_type. We also don't need to check for transaction - // here; object_traits::query () does this. - // - return query_::call (*this, q); - } - - template - inline result database:: - query (const odb::query_base& q) - { - // Translate to native query. - // - return query (pgsql::query_base (q)); - } - - template - inline typename result::pointer_type database:: - query_one () - { - return query_one (pgsql::query_base ()); - } - - template - inline bool database:: - query_one (T& o) - { - return query_one (pgsql::query_base (), o); - } - - template - inline T database:: - query_value () - { - return query_value (pgsql::query_base ()); - } - - template - inline typename result::pointer_type database:: - query_one (const char* q) - { - return query_one (pgsql::query_base (q)); - } - - template - inline bool database:: - query_one (const char* q, T& o) - { - return query_one (pgsql::query_base (q), o); - } - - template - inline T database:: - query_value (const char* q) - { - return query_value (pgsql::query_base (q)); - } - - template - inline typename result::pointer_type database:: - query_one (const std::string& q) - { - return query_one (pgsql::query_base (q)); - } - - template - inline bool database:: - query_one (const std::string& q, T& o) - { - return query_one (pgsql::query_base (q), o); - } - - template - inline T database:: - query_value (const std::string& q) - { - return query_value (pgsql::query_base (q)); - } - - template - inline typename result::pointer_type database:: - query_one (const pgsql::query_base& q) - { - // T is always object_type. We also don't need to check for transaction - // here; object_traits::query () does this. - // - return query_one_ (q); - } - - template - inline bool database:: - query_one (const pgsql::query_base& q, T& o) - { - // T is always object_type. We also don't need to check for transaction - // here; object_traits::query () does this. - // - return query_one_ (q, o); - } - - template - inline T database:: - query_value (const pgsql::query_base& q) - { - // T is always object_type. We also don't need to check for transaction - // here; object_traits::query () does this. - // - return query_value_ (q); - } - - template - inline typename result::pointer_type database:: - query_one (const odb::query_base& q) - { - // Translate to native query. - // - return query_one (pgsql::query_base (q)); - } - - template - inline bool database:: - query_one (const odb::query_base& q, T& o) - { - // Translate to native query. - // - return query_one (pgsql::query_base (q), o); - } - - template - inline T database:: - query_value (const odb::query_base& q) - { - // Translate to native query. - // - return query_value (pgsql::query_base (q)); - } - - template - inline prepared_query database:: - prepare_query (const char* n, const char* q) - { - return prepare_query (n, pgsql::query_base (q)); - } - - template - inline prepared_query database:: - prepare_query (const char* n, const std::string& q) - { - return prepare_query (n, pgsql::query_base (q)); - } - - template - inline prepared_query database:: - prepare_query (const char* n, const pgsql::query_base& q) - { - // Throws if not in transaction. - // - pgsql::connection& c (transaction::current ().connection (*this)); - return c.prepare_query (n, q); - } - - template - inline prepared_query database:: - prepare_query (const char* n, const odb::query_base& q) - { - // Translate to native query. - // - return prepare_query (n, pgsql::query_base (q)); - } - } -} diff --git a/odb/pgsql/details/.gitignore b/odb/pgsql/details/.gitignore deleted file mode 100644 index b298f89..0000000 --- a/odb/pgsql/details/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/options.?xx diff --git a/odb/pgsql/details/build2/config-stub.h b/odb/pgsql/details/build2/config-stub.h deleted file mode 100644 index 00c5940..0000000 --- a/odb/pgsql/details/build2/config-stub.h +++ /dev/null @@ -1,5 +0,0 @@ -/* file : odb/pgsql/details/build2/config-stub.h - * license : GNU GPL v2; see accompanying LICENSE file - */ - -#include diff --git a/odb/pgsql/details/build2/config-vc-stub.h b/odb/pgsql/details/build2/config-vc-stub.h deleted file mode 100644 index 473cd96..0000000 --- a/odb/pgsql/details/build2/config-vc-stub.h +++ /dev/null @@ -1,5 +0,0 @@ -/* file : odb/pgsql/details/build2/config-vc-stub.h - * license : GNU GPL v2; see accompanying LICENSE file - */ - -#include diff --git a/odb/pgsql/details/build2/config-vc.h b/odb/pgsql/details/build2/config-vc.h deleted file mode 100644 index e9d9ade..0000000 --- a/odb/pgsql/details/build2/config-vc.h +++ /dev/null @@ -1,15 +0,0 @@ -/* file : odb/pgsql/details/build2/config-vc.h - * license : GNU GPL v2; see accompanying LICENSE file - */ - -/* Configuration file for Windows/VC++ for the build2 build. */ - -#ifndef ODB_PGSQL_DETAILS_CONFIG_VC_H -#define ODB_PGSQL_DETAILS_CONFIG_VC_H - -/* Define LIBODB_PGSQL_BUILD2 for the installed case. */ -#ifndef LIBODB_PGSQL_BUILD2 -# define LIBODB_PGSQL_BUILD2 -#endif - -#endif /* ODB_PGSQL_DETAILS_CONFIG_VC_H */ diff --git a/odb/pgsql/details/build2/config.h b/odb/pgsql/details/build2/config.h deleted file mode 100644 index b2a81b5..0000000 --- a/odb/pgsql/details/build2/config.h +++ /dev/null @@ -1,17 +0,0 @@ -/* file : odb/pgsql/details/build2/config.h - * license : GNU GPL v2; see accompanying LICENSE file - */ - -/* Static configuration file for the build2 build. The installed case - (when LIBODB_PGSQL_BUILD2 is not necessarily defined) is the only - reason we have it. */ - -#ifndef ODB_PGSQL_DETAILS_CONFIG_H -#define ODB_PGSQL_DETAILS_CONFIG_H - -/* Define LIBODB_PGSQL_BUILD2 for the installed case. */ -#ifndef LIBODB_PGSQL_BUILD2 -# define LIBODB_PGSQL_BUILD2 -#endif - -#endif /* ODB_PGSQL_DETAILS_CONFIG_H */ diff --git a/odb/pgsql/details/config-vc.h b/odb/pgsql/details/config-vc.h deleted file mode 100644 index 77a0be5..0000000 --- a/odb/pgsql/details/config-vc.h +++ /dev/null @@ -1,5 +0,0 @@ -/* file : odb/pgsql/details/config-vc.h - * license : GNU GPL v2; see accompanying LICENSE file - */ - -/* Dummy configuration file for Windows/VC++. */ diff --git a/odb/pgsql/details/config.h.in b/odb/pgsql/details/config.h.in deleted file mode 100644 index 889023c..0000000 --- a/odb/pgsql/details/config.h.in +++ /dev/null @@ -1,12 +0,0 @@ -/* file : odb/pgsql/details/config.h.in - * license : GNU GPL v2; see accompanying LICENSE file - */ - -/* This file is automatically processed by configure. */ - -#ifndef ODB_PGSQL_DETAILS_CONFIG_H -#define ODB_PGSQL_DETAILS_CONFIG_H - -#undef LIBODB_PGSQL_STATIC_LIB - -#endif /* ODB_PGSQL_DETAILS_CONFIG_H */ diff --git a/odb/pgsql/details/config.hxx b/odb/pgsql/details/config.hxx deleted file mode 100644 index 1340622..0000000 --- a/odb/pgsql/details/config.hxx +++ /dev/null @@ -1,21 +0,0 @@ -// file : odb/pgsql/details/config.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_DETAILS_CONFIG_HXX -#define ODB_PGSQL_DETAILS_CONFIG_HXX - -// no pre - -#ifdef ODB_COMPILER -# error libodb-pgsql header included in odb-compiled header -#elif !defined(LIBODB_PGSQL_BUILD2) -# ifdef _MSC_VER -# include -# else -# include -# endif -#endif - -// no post - -#endif // ODB_PGSQL_DETAILS_CONFIG_HXX diff --git a/odb/pgsql/details/conversion.hxx b/odb/pgsql/details/conversion.hxx deleted file mode 100644 index b4d7e4f..0000000 --- a/odb/pgsql/details/conversion.hxx +++ /dev/null @@ -1,58 +0,0 @@ -// file : odb/pgsql/details/conversion.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_DETAILS_CONVERSION_HXX -#define ODB_PGSQL_DETAILS_CONVERSION_HXX - -#include - -#include - -namespace odb -{ - // @@ Revise this. - // - namespace details {} - - namespace pgsql - { - namespace details - { - using namespace odb::details; - - // Detect whether conversion is specified in type_traits. - // - template - meta::yes - conversion_p_test (typename type_traits::conversion*); - - template - meta::no - conversion_p_test (...); - - template - struct conversion_p - { - static const bool value = - sizeof (conversion_p_test (0)) == sizeof (meta::yes); - }; - - template ::value> - struct conversion; - - template - struct conversion - { - static const char* to () {return type_traits::conversion::to ();} - }; - - template - struct conversion - { - static const char* to () {return 0;} - }; - } - } -} - -#endif // ODB_PGSQL_DETAILS_CONVERSION_HXX diff --git a/odb/pgsql/details/endian-traits.cxx b/odb/pgsql/details/endian-traits.cxx deleted file mode 100644 index 77fdc95..0000000 --- a/odb/pgsql/details/endian-traits.cxx +++ /dev/null @@ -1,30 +0,0 @@ -// file : odb/pgsql/details/endian-traits.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -namespace odb -{ - namespace pgsql - { - namespace details - { - namespace - { - endian_traits::endian - infer_host_endian () - { - short s (1); - char* c (reinterpret_cast (&s)); - - return *c == 0 ? - endian_traits::big : - endian_traits::little; - } - } - - const endian_traits::endian endian_traits::host_endian ( - infer_host_endian ()); - } - } -} diff --git a/odb/pgsql/details/endian-traits.hxx b/odb/pgsql/details/endian-traits.hxx deleted file mode 100644 index 532a4a3..0000000 --- a/odb/pgsql/details/endian-traits.hxx +++ /dev/null @@ -1,155 +0,0 @@ -// file : odb/pgsql/details/endian-traits.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_DETAILS_ENDIAN_TRAITS_HXX -#define ODB_PGSQL_DETAILS_ENDIAN_TRAITS_HXX - -#include // std::size_t -#include // std::reverse - -#include - -namespace odb -{ - // @@ Revise this. - // - namespace details - { - } - - namespace pgsql - { - namespace details - { - using namespace odb::details; - - template - struct swap_endian; - - template - struct swap_endian - { - static T - swap (T x) - { - return x; - } - }; - - template - struct swap_endian - { - static T - swap (T x) - { - union u2 - { - T t; - char c[2]; - }; - - u2 u; - u.t = x; - - char tmp (u.c[0]); - u.c[0] = u.c[1]; - u.c[1] = tmp; - - return u.t; - } - }; - - template - struct swap_endian - { - static T - swap (T x) - { - union u4 - { - T t; - char c[4]; - }; - - u4 u; - u.t = x; - - char tmp (u.c[0]); - u.c[0] = u.c[3]; - u.c[3] = tmp; - - tmp = u.c[1]; - u.c[1] = u.c[2]; - u.c[2] = tmp; - - return u.t; - } - }; - - template - struct swap_endian - { - static T - swap (T x) - { - union u8 - { - T t; - char c[8]; - }; - - u8 u; - u.t = x; - - char tmp (u.c[0]); - u.c[0] = u.c[7]; - u.c[7] = tmp; - - tmp = u.c[1]; - u.c[1] = u.c[6]; - u.c[6] = tmp; - - tmp = u.c[2]; - u.c[2] = u.c[5]; - u.c[5] = tmp; - - tmp = u.c[3]; - u.c[3] = u.c[4]; - u.c[4] = tmp; - - return u.t; - } - }; - - class LIBODB_PGSQL_EXPORT endian_traits - { - public: - enum endian - { - big, - little - }; - - public: - static const endian host_endian; - - public: - template - static T - hton (T x) - { - return host_endian == big ? x : swap_endian::swap (x); - } - - template - static T - ntoh (T x) - { - return host_endian == big ? x : swap_endian::swap (x); - } - }; - } - } -} - -#endif // ODB_PGSQL_DETAILS_ENDIAN_TRAITS_HXX diff --git a/odb/pgsql/details/export.hxx b/odb/pgsql/details/export.hxx deleted file mode 100644 index 81ff6a0..0000000 --- a/odb/pgsql/details/export.hxx +++ /dev/null @@ -1,78 +0,0 @@ -// file : odb/pgsql/details/export.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_DETAILS_EXPORT_HXX -#define ODB_PGSQL_DETAILS_EXPORT_HXX - -#include - -#include - -// Normally we don't export class templates (but do complete specializations), -// inline functions, and classes with only inline member functions. Exporting -// classes that inherit from non-exported/imported bases (e.g., std::string) -// will end up badly. The only known workarounds are to not inherit or to not -// export. Also, MinGW GCC doesn't like seeing non-exported function being -// used before their inline definition. The workaround is to reorder code. In -// the end it's all trial and error. - -#ifdef LIBODB_PGSQL_BUILD2 - -#if defined(LIBODB_PGSQL_STATIC) // Using static. -# define LIBODB_PGSQL_EXPORT -#elif defined(LIBODB_PGSQL_STATIC_BUILD) // Building static. -# define LIBODB_PGSQL_EXPORT -#elif defined(LIBODB_PGSQL_SHARED) // Using shared. -# ifdef _WIN32 -# define LIBODB_PGSQL_EXPORT __declspec(dllimport) -# else -# define LIBODB_PGSQL_EXPORT -# endif -#elif defined(LIBODB_PGSQL_SHARED_BUILD) // Building shared. -# ifdef _WIN32 -# define LIBODB_PGSQL_EXPORT __declspec(dllexport) -# else -# define LIBODB_PGSQL_EXPORT -# endif -#else -// If none of the above macros are defined, then we assume we are being used -// by some third-party build system that cannot/doesn't signal the library -// type. Note that this fallback works for both static and shared but in case -// of shared will be sub-optimal compared to having dllimport. -// -# define LIBODB_PGSQL_EXPORT // Using static or shared. -#endif - -#else // LIBODB_PGSQL_BUILD2 - -#ifdef LIBODB_PGSQL_STATIC_LIB -# define LIBODB_PGSQL_EXPORT -#else -# ifdef _WIN32 -# ifdef _MSC_VER -# ifdef LIBODB_PGSQL_DYNAMIC_LIB -# define LIBODB_PGSQL_EXPORT __declspec(dllexport) -# else -# define LIBODB_PGSQL_EXPORT __declspec(dllimport) -# endif -# else -# ifdef LIBODB_PGSQL_DYNAMIC_LIB -# ifdef DLL_EXPORT -# define LIBODB_PGSQL_EXPORT __declspec(dllexport) -# else -# define LIBODB_PGSQL_EXPORT -# endif -# else -# define LIBODB_PGSQL_EXPORT __declspec(dllimport) -# endif -# endif -# else -# define LIBODB_PGSQL_EXPORT -# endif -#endif - -#endif // LIBODB_PGSQL_BUILD2 - -#include - -#endif // ODB_PGSQL_DETAILS_EXPORT_HXX diff --git a/odb/pgsql/details/options.cli b/odb/pgsql/details/options.cli deleted file mode 100644 index f568236..0000000 --- a/odb/pgsql/details/options.cli +++ /dev/null @@ -1,56 +0,0 @@ -// file : odb/pgsql/details/options.cli -// license : GNU GPL v2; see accompanying LICENSE file - -include ; - -namespace odb -{ - namespace pgsql - { - namespace details - { - class options - { - std::string --user | --username - { - "", - "PostgreSQL database user." - }; - - std::string --password - { - "", - "PostgreSQL database password." - }; - - std::string --database | --dbname - { - "", - "PostgreSQL database name." - }; - - std::string --host - { - "", - "PostgreSQL database host name or address (localhost by default)." - }; - - std::string --port - { - "", - "PostgreSQL database port number or socket file name extension for - Unix-domain connections." - }; - - std::string --options-file - { - "", - "Read additional options from . Each option should appear on a - separate line optionally followed by space or equal sign (\cb{=}) - and an option value. Empty lines and lines starting with \cb{#} are - ignored." - }; - }; - } - } -} diff --git a/odb/pgsql/details/pregenerated/odb/pgsql/details/options.cxx b/odb/pgsql/details/pregenerated/odb/pgsql/details/options.cxx deleted file mode 100644 index a4a5da6..0000000 --- a/odb/pgsql/details/pregenerated/odb/pgsql/details/options.cxx +++ /dev/null @@ -1,1114 +0,0 @@ -// -*- C++ -*- -// -// This file was generated by CLI, a command line interface -// compiler for C++. -// - -// Begin prologue. -// -// -// End prologue. - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - namespace details - { - namespace cli - { - // unknown_option - // - unknown_option:: - ~unknown_option () throw () - { - } - - void unknown_option:: - print (::std::ostream& os) const - { - os << "unknown option '" << option ().c_str () << "'"; - } - - const char* unknown_option:: - what () const throw () - { - return "unknown option"; - } - - // unknown_argument - // - unknown_argument:: - ~unknown_argument () throw () - { - } - - void unknown_argument:: - print (::std::ostream& os) const - { - os << "unknown argument '" << argument ().c_str () << "'"; - } - - const char* unknown_argument:: - what () const throw () - { - return "unknown argument"; - } - - // missing_value - // - missing_value:: - ~missing_value () throw () - { - } - - void missing_value:: - print (::std::ostream& os) const - { - os << "missing value for option '" << option ().c_str () << "'"; - } - - const char* missing_value:: - what () const throw () - { - return "missing option value"; - } - - // invalid_value - // - invalid_value:: - ~invalid_value () throw () - { - } - - void invalid_value:: - print (::std::ostream& os) const - { - os << "invalid value '" << value ().c_str () << "' for option '" - << option ().c_str () << "'"; - - if (!message ().empty ()) - os << ": " << message ().c_str (); - } - - const char* invalid_value:: - what () const throw () - { - return "invalid option value"; - } - - // eos_reached - // - void eos_reached:: - print (::std::ostream& os) const - { - os << what (); - } - - const char* eos_reached:: - what () const throw () - { - return "end of argument stream reached"; - } - - // file_io_failure - // - file_io_failure:: - ~file_io_failure () throw () - { - } - - void file_io_failure:: - print (::std::ostream& os) const - { - os << "unable to open file '" << file ().c_str () << "' or read failure"; - } - - const char* file_io_failure:: - what () const throw () - { - return "unable to open file or read failure"; - } - - // unmatched_quote - // - unmatched_quote:: - ~unmatched_quote () throw () - { - } - - void unmatched_quote:: - print (::std::ostream& os) const - { - os << "unmatched quote in argument '" << argument ().c_str () << "'"; - } - - const char* unmatched_quote:: - what () const throw () - { - return "unmatched quote"; - } - - // scanner - // - scanner:: - ~scanner () - { - } - - // argv_scanner - // - bool argv_scanner:: - more () - { - return i_ < argc_; - } - - const char* argv_scanner:: - peek () - { - if (i_ < argc_) - return argv_[i_]; - else - throw eos_reached (); - } - - const char* argv_scanner:: - next () - { - if (i_ < argc_) - { - const char* r (argv_[i_]); - - if (erase_) - { - for (int i (i_ + 1); i < argc_; ++i) - argv_[i - 1] = argv_[i]; - - --argc_; - argv_[argc_] = 0; - } - else - ++i_; - - ++start_position_; - return r; - } - else - throw eos_reached (); - } - - void argv_scanner:: - skip () - { - if (i_ < argc_) - { - ++i_; - ++start_position_; - } - else - throw eos_reached (); - } - - std::size_t argv_scanner:: - position () - { - return start_position_; - } - - // argv_file_scanner - // - int argv_file_scanner::zero_argc_ = 0; - std::string argv_file_scanner::empty_string_; - - bool argv_file_scanner:: - more () - { - if (!args_.empty ()) - return true; - - while (base::more ()) - { - // See if the next argument is the file option. - // - const char* a (base::peek ()); - const option_info* oi = 0; - const char* ov = 0; - - if (!skip_) - { - if ((oi = find (a)) != 0) - { - base::next (); - - if (!base::more ()) - throw missing_value (a); - - ov = base::next (); - } - else if (std::strncmp (a, "-", 1) == 0) - { - if ((ov = std::strchr (a, '=')) != 0) - { - std::string o (a, 0, ov - a); - if ((oi = find (o.c_str ())) != 0) - { - base::next (); - ++ov; - } - } - } - } - - if (oi != 0) - { - if (oi->search_func != 0) - { - std::string f (oi->search_func (ov, oi->arg)); - - if (!f.empty ()) - load (f); - } - else - load (ov); - - if (!args_.empty ()) - return true; - } - else - { - if (!skip_) - skip_ = (std::strcmp (a, "--") == 0); - - return true; - } - } - - return false; - } - - const char* argv_file_scanner:: - peek () - { - if (!more ()) - throw eos_reached (); - - return args_.empty () ? base::peek () : args_.front ().value.c_str (); - } - - const std::string& argv_file_scanner:: - peek_file () - { - if (!more ()) - throw eos_reached (); - - return args_.empty () ? empty_string_ : *args_.front ().file; - } - - std::size_t argv_file_scanner:: - peek_line () - { - if (!more ()) - throw eos_reached (); - - return args_.empty () ? 0 : args_.front ().line; - } - - const char* argv_file_scanner:: - next () - { - if (!more ()) - throw eos_reached (); - - if (args_.empty ()) - return base::next (); - else - { - hold_[i_ == 0 ? ++i_ : --i_].swap (args_.front ().value); - args_.pop_front (); - ++start_position_; - return hold_[i_].c_str (); - } - } - - void argv_file_scanner:: - skip () - { - if (!more ()) - throw eos_reached (); - - if (args_.empty ()) - return base::skip (); - else - { - args_.pop_front (); - ++start_position_; - } - } - - const argv_file_scanner::option_info* argv_file_scanner:: - find (const char* a) const - { - for (std::size_t i (0); i < options_count_; ++i) - if (std::strcmp (a, options_[i].option) == 0) - return &options_[i]; - - return 0; - } - - std::size_t argv_file_scanner:: - position () - { - return start_position_; - } - - void argv_file_scanner:: - load (const std::string& file) - { - using namespace std; - - ifstream is (file.c_str ()); - - if (!is.is_open ()) - throw file_io_failure (file); - - files_.push_back (file); - - arg a; - a.file = &*files_.rbegin (); - - for (a.line = 1; !is.eof (); ++a.line) - { - string line; - getline (is, line); - - if (is.fail () && !is.eof ()) - throw file_io_failure (file); - - string::size_type n (line.size ()); - - // Trim the line from leading and trailing whitespaces. - // - if (n != 0) - { - const char* f (line.c_str ()); - const char* l (f + n); - - const char* of (f); - while (f < l && (*f == ' ' || *f == '\t' || *f == '\r')) - ++f; - - --l; - - const char* ol (l); - while (l > f && (*l == ' ' || *l == '\t' || *l == '\r')) - --l; - - if (f != of || l != ol) - line = f <= l ? string (f, l - f + 1) : string (); - } - - // Ignore empty lines, those that start with #. - // - if (line.empty () || line[0] == '#') - continue; - - string::size_type p (string::npos); - if (line.compare (0, 1, "-") == 0) - { - p = line.find (' '); - - string::size_type q (line.find ('=')); - if (q != string::npos && q < p) - p = q; - } - - string s1; - if (p != string::npos) - { - s1.assign (line, 0, p); - - // Skip leading whitespaces in the argument. - // - if (line[p] == '=') - ++p; - else - { - n = line.size (); - for (++p; p < n; ++p) - { - char c (line[p]); - if (c != ' ' && c != '\t' && c != '\r') - break; - } - } - } - else if (!skip_) - skip_ = (line == "--"); - - string s2 (line, p != string::npos ? p : 0); - - // If the string (which is an option value or argument) is - // wrapped in quotes, remove them. - // - n = s2.size (); - char cf (s2[0]), cl (s2[n - 1]); - - if (cf == '"' || cf == '\'' || cl == '"' || cl == '\'') - { - if (n == 1 || cf != cl) - throw unmatched_quote (s2); - - s2 = string (s2, 1, n - 2); - } - - if (!s1.empty ()) - { - // See if this is another file option. - // - const option_info* oi; - if (!skip_ && (oi = find (s1.c_str ()))) - { - if (s2.empty ()) - throw missing_value (oi->option); - - if (oi->search_func != 0) - { - string f (oi->search_func (s2.c_str (), oi->arg)); - if (!f.empty ()) - load (f); - } - else - { - // If the path of the file being parsed is not simple and the - // path of the file that needs to be loaded is relative, then - // complete the latter using the former as a base. - // -#ifndef _WIN32 - string::size_type p (file.find_last_of ('/')); - bool c (p != string::npos && s2[0] != '/'); -#else - string::size_type p (file.find_last_of ("/\\")); - bool c (p != string::npos && s2[1] != ':'); -#endif - if (c) - s2.insert (0, file, 0, p + 1); - - load (s2); - } - - continue; - } - - a.value = s1; - args_.push_back (a); - } - - a.value = s2; - args_.push_back (a); - } - } - - template - struct parser - { - static void - parse (X& x, bool& xs, scanner& s) - { - using namespace std; - - const char* o (s.next ()); - if (s.more ()) - { - string v (s.next ()); - istringstream is (v); - if (!(is >> x && is.peek () == istringstream::traits_type::eof ())) - throw invalid_value (o, v); - } - else - throw missing_value (o); - - xs = true; - } - }; - - template <> - struct parser - { - static void - parse (bool& x, bool& xs, scanner& s) - { - const char* o (s.next ()); - - if (s.more ()) - { - const char* v (s.next ()); - - if (std::strcmp (v, "1") == 0 || - std::strcmp (v, "true") == 0 || - std::strcmp (v, "TRUE") == 0 || - std::strcmp (v, "True") == 0) - x = true; - else if (std::strcmp (v, "0") == 0 || - std::strcmp (v, "false") == 0 || - std::strcmp (v, "FALSE") == 0 || - std::strcmp (v, "False") == 0) - x = false; - else - throw invalid_value (o, v); - } - else - throw missing_value (o); - - xs = true; - } - }; - - template <> - struct parser - { - static void - parse (std::string& x, bool& xs, scanner& s) - { - const char* o (s.next ()); - - if (s.more ()) - x = s.next (); - else - throw missing_value (o); - - xs = true; - } - }; - - template - struct parser > - { - static void - parse (std::pair& x, bool& xs, scanner& s) - { - x.second = s.position (); - parser::parse (x.first, xs, s); - } - }; - - template - struct parser > - { - static void - parse (std::vector& c, bool& xs, scanner& s) - { - X x; - bool dummy; - parser::parse (x, dummy, s); - c.push_back (x); - xs = true; - } - }; - - template - struct parser > - { - static void - parse (std::set& c, bool& xs, scanner& s) - { - X x; - bool dummy; - parser::parse (x, dummy, s); - c.insert (x); - xs = true; - } - }; - - template - struct parser > - { - static void - parse (std::map& m, bool& xs, scanner& s) - { - const char* o (s.next ()); - - if (s.more ()) - { - std::size_t pos (s.position ()); - std::string ov (s.next ()); - std::string::size_type p = ov.find ('='); - - K k = K (); - V v = V (); - std::string kstr (ov, 0, p); - std::string vstr (ov, (p != std::string::npos ? p + 1 : ov.size ())); - - int ac (2); - char* av[] = - { - const_cast (o), - 0 - }; - - bool dummy; - if (!kstr.empty ()) - { - av[1] = const_cast (kstr.c_str ()); - argv_scanner s (0, ac, av, false, pos); - parser::parse (k, dummy, s); - } - - if (!vstr.empty ()) - { - av[1] = const_cast (vstr.c_str ()); - argv_scanner s (0, ac, av, false, pos); - parser::parse (v, dummy, s); - } - - m[k] = v; - } - else - throw missing_value (o); - - xs = true; - } - }; - - template - struct parser > - { - static void - parse (std::multimap& m, bool& xs, scanner& s) - { - const char* o (s.next ()); - - if (s.more ()) - { - std::size_t pos (s.position ()); - std::string ov (s.next ()); - std::string::size_type p = ov.find ('='); - - K k = K (); - V v = V (); - std::string kstr (ov, 0, p); - std::string vstr (ov, (p != std::string::npos ? p + 1 : ov.size ())); - - int ac (2); - char* av[] = - { - const_cast (o), - 0 - }; - - bool dummy; - if (!kstr.empty ()) - { - av[1] = const_cast (kstr.c_str ()); - argv_scanner s (0, ac, av, false, pos); - parser::parse (k, dummy, s); - } - - if (!vstr.empty ()) - { - av[1] = const_cast (vstr.c_str ()); - argv_scanner s (0, ac, av, false, pos); - parser::parse (v, dummy, s); - } - - m.insert (typename std::multimap::value_type (k, v)); - } - else - throw missing_value (o); - - xs = true; - } - }; - - template - void - thunk (X& x, scanner& s) - { - parser::parse (x.*M, s); - } - - template - void - thunk (X& x, scanner& s) - { - s.next (); - x.*M = true; - } - - template - void - thunk (X& x, scanner& s) - { - parser::parse (x.*M, x.*S, s); - } - } - } - } -} - -#include - -namespace odb -{ - namespace pgsql - { - namespace details - { - // options - // - - options:: - options () - : user_ (), - user_specified_ (false), - password_ (), - password_specified_ (false), - database_ (), - database_specified_ (false), - host_ (), - host_specified_ (false), - port_ (), - port_specified_ (false), - options_file_ (), - options_file_specified_ (false) - { - } - - options:: - options (int& argc, - char** argv, - bool erase, - ::odb::pgsql::details::cli::unknown_mode opt, - ::odb::pgsql::details::cli::unknown_mode arg) - : user_ (), - user_specified_ (false), - password_ (), - password_specified_ (false), - database_ (), - database_specified_ (false), - host_ (), - host_specified_ (false), - port_ (), - port_specified_ (false), - options_file_ (), - options_file_specified_ (false) - { - ::odb::pgsql::details::cli::argv_scanner s (argc, argv, erase); - _parse (s, opt, arg); - } - - options:: - options (int start, - int& argc, - char** argv, - bool erase, - ::odb::pgsql::details::cli::unknown_mode opt, - ::odb::pgsql::details::cli::unknown_mode arg) - : user_ (), - user_specified_ (false), - password_ (), - password_specified_ (false), - database_ (), - database_specified_ (false), - host_ (), - host_specified_ (false), - port_ (), - port_specified_ (false), - options_file_ (), - options_file_specified_ (false) - { - ::odb::pgsql::details::cli::argv_scanner s (start, argc, argv, erase); - _parse (s, opt, arg); - } - - options:: - options (int& argc, - char** argv, - int& end, - bool erase, - ::odb::pgsql::details::cli::unknown_mode opt, - ::odb::pgsql::details::cli::unknown_mode arg) - : user_ (), - user_specified_ (false), - password_ (), - password_specified_ (false), - database_ (), - database_specified_ (false), - host_ (), - host_specified_ (false), - port_ (), - port_specified_ (false), - options_file_ (), - options_file_specified_ (false) - { - ::odb::pgsql::details::cli::argv_scanner s (argc, argv, erase); - _parse (s, opt, arg); - end = s.end (); - } - - options:: - options (int start, - int& argc, - char** argv, - int& end, - bool erase, - ::odb::pgsql::details::cli::unknown_mode opt, - ::odb::pgsql::details::cli::unknown_mode arg) - : user_ (), - user_specified_ (false), - password_ (), - password_specified_ (false), - database_ (), - database_specified_ (false), - host_ (), - host_specified_ (false), - port_ (), - port_specified_ (false), - options_file_ (), - options_file_specified_ (false) - { - ::odb::pgsql::details::cli::argv_scanner s (start, argc, argv, erase); - _parse (s, opt, arg); - end = s.end (); - } - - options:: - options (::odb::pgsql::details::cli::scanner& s, - ::odb::pgsql::details::cli::unknown_mode opt, - ::odb::pgsql::details::cli::unknown_mode arg) - : user_ (), - user_specified_ (false), - password_ (), - password_specified_ (false), - database_ (), - database_specified_ (false), - host_ (), - host_specified_ (false), - port_ (), - port_specified_ (false), - options_file_ (), - options_file_specified_ (false) - { - _parse (s, opt, arg); - } - - ::odb::pgsql::details::cli::usage_para options:: - print_usage (::std::ostream& os, ::odb::pgsql::details::cli::usage_para p) - { - CLI_POTENTIALLY_UNUSED (os); - - if (p != ::odb::pgsql::details::cli::usage_para::none) - os << ::std::endl; - - os << "--user|--username PostgreSQL database user." << ::std::endl; - - os << std::endl - << "--password PostgreSQL database password." << ::std::endl; - - os << std::endl - << "--database|--dbname PostgreSQL database name." << ::std::endl; - - os << std::endl - << "--host PostgreSQL database host name or address (localhost" << ::std::endl - << " by default)." << ::std::endl; - - os << std::endl - << "--port PostgreSQL database port number or socket file name" << ::std::endl - << " extension for Unix-domain connections." << ::std::endl; - - os << std::endl - << "--options-file Read additional options from . Each option" << ::std::endl - << " should appear on a separate line optionally followed" << ::std::endl - << " by space or equal sign (=) and an option value." << ::std::endl - << " Empty lines and lines starting with # are ignored." << ::std::endl; - - p = ::odb::pgsql::details::cli::usage_para::option; - - return p; - } - - typedef - std::map - _cli_options_map; - - static _cli_options_map _cli_options_map_; - - struct _cli_options_map_init - { - _cli_options_map_init () - { - _cli_options_map_["--user"] = - &::odb::pgsql::details::cli::thunk< options, std::string, &options::user_, - &options::user_specified_ >; - _cli_options_map_["--username"] = - &::odb::pgsql::details::cli::thunk< options, std::string, &options::user_, - &options::user_specified_ >; - _cli_options_map_["--password"] = - &::odb::pgsql::details::cli::thunk< options, std::string, &options::password_, - &options::password_specified_ >; - _cli_options_map_["--database"] = - &::odb::pgsql::details::cli::thunk< options, std::string, &options::database_, - &options::database_specified_ >; - _cli_options_map_["--dbname"] = - &::odb::pgsql::details::cli::thunk< options, std::string, &options::database_, - &options::database_specified_ >; - _cli_options_map_["--host"] = - &::odb::pgsql::details::cli::thunk< options, std::string, &options::host_, - &options::host_specified_ >; - _cli_options_map_["--port"] = - &::odb::pgsql::details::cli::thunk< options, std::string, &options::port_, - &options::port_specified_ >; - _cli_options_map_["--options-file"] = - &::odb::pgsql::details::cli::thunk< options, std::string, &options::options_file_, - &options::options_file_specified_ >; - } - }; - - static _cli_options_map_init _cli_options_map_init_; - - bool options:: - _parse (const char* o, ::odb::pgsql::details::cli::scanner& s) - { - _cli_options_map::const_iterator i (_cli_options_map_.find (o)); - - if (i != _cli_options_map_.end ()) - { - (*(i->second)) (*this, s); - return true; - } - - return false; - } - - bool options:: - _parse (::odb::pgsql::details::cli::scanner& s, - ::odb::pgsql::details::cli::unknown_mode opt_mode, - ::odb::pgsql::details::cli::unknown_mode arg_mode) - { - bool r = false; - bool opt = true; - - while (s.more ()) - { - const char* o = s.peek (); - - if (std::strcmp (o, "--") == 0) - { - opt = false; - s.skip (); - r = true; - continue; - } - - if (opt) - { - if (_parse (o, s)) - { - r = true; - continue; - } - - if (std::strncmp (o, "-", 1) == 0 && o[1] != '\0') - { - // Handle combined option values. - // - std::string co; - if (const char* v = std::strchr (o, '=')) - { - co.assign (o, 0, v - o); - ++v; - - int ac (2); - char* av[] = - { - const_cast (co.c_str ()), - const_cast (v) - }; - - ::odb::pgsql::details::cli::argv_scanner ns (0, ac, av); - - if (_parse (co.c_str (), ns)) - { - // Parsed the option but not its value? - // - if (ns.end () != 2) - throw ::odb::pgsql::details::cli::invalid_value (co, v); - - s.next (); - r = true; - continue; - } - else - { - // Set the unknown option and fall through. - // - o = co.c_str (); - } - } - - switch (opt_mode) - { - case ::odb::pgsql::details::cli::unknown_mode::skip: - { - s.skip (); - r = true; - continue; - } - case ::odb::pgsql::details::cli::unknown_mode::stop: - { - break; - } - case ::odb::pgsql::details::cli::unknown_mode::fail: - { - throw ::odb::pgsql::details::cli::unknown_option (o); - } - } - - break; - } - } - - switch (arg_mode) - { - case ::odb::pgsql::details::cli::unknown_mode::skip: - { - s.skip (); - r = true; - continue; - } - case ::odb::pgsql::details::cli::unknown_mode::stop: - { - break; - } - case ::odb::pgsql::details::cli::unknown_mode::fail: - { - throw ::odb::pgsql::details::cli::unknown_argument (o); - } - } - - break; - } - - return r; - } - } - } -} - -// Begin epilogue. -// -// -// End epilogue. - diff --git a/odb/pgsql/details/pregenerated/odb/pgsql/details/options.hxx b/odb/pgsql/details/pregenerated/odb/pgsql/details/options.hxx deleted file mode 100644 index 4d264d4..0000000 --- a/odb/pgsql/details/pregenerated/odb/pgsql/details/options.hxx +++ /dev/null @@ -1,562 +0,0 @@ -// -*- C++ -*- -// -// This file was generated by CLI, a command line interface -// compiler for C++. -// - -#ifndef LIBODB_PGSQL_DETAILS_OPTIONS_HXX -#define LIBODB_PGSQL_DETAILS_OPTIONS_HXX - -// Begin prologue. -// -// -// End prologue. - -#include -#include -#include -#include -#include -#include - -#ifndef CLI_POTENTIALLY_UNUSED -# if defined(_MSC_VER) || defined(__xlC__) -# define CLI_POTENTIALLY_UNUSED(x) (void*)&x -# else -# define CLI_POTENTIALLY_UNUSED(x) (void)x -# endif -#endif - -namespace odb -{ - namespace pgsql - { - namespace details - { - namespace cli - { - class usage_para - { - public: - enum value - { - none, - text, - option - }; - - usage_para (value); - - operator value () const - { - return v_; - } - - private: - value v_; - }; - - class unknown_mode - { - public: - enum value - { - skip, - stop, - fail - }; - - unknown_mode (value); - - operator value () const - { - return v_; - } - - private: - value v_; - }; - - // Exceptions. - // - - class exception: public std::exception - { - public: - virtual void - print (::std::ostream&) const = 0; - }; - - ::std::ostream& - operator<< (::std::ostream&, const exception&); - - class unknown_option: public exception - { - public: - virtual - ~unknown_option () throw (); - - unknown_option (const std::string& option); - - const std::string& - option () const; - - virtual void - print (::std::ostream&) const; - - virtual const char* - what () const throw (); - - private: - std::string option_; - }; - - class unknown_argument: public exception - { - public: - virtual - ~unknown_argument () throw (); - - unknown_argument (const std::string& argument); - - const std::string& - argument () const; - - virtual void - print (::std::ostream&) const; - - virtual const char* - what () const throw (); - - private: - std::string argument_; - }; - - class missing_value: public exception - { - public: - virtual - ~missing_value () throw (); - - missing_value (const std::string& option); - - const std::string& - option () const; - - virtual void - print (::std::ostream&) const; - - virtual const char* - what () const throw (); - - private: - std::string option_; - }; - - class invalid_value: public exception - { - public: - virtual - ~invalid_value () throw (); - - invalid_value (const std::string& option, - const std::string& value, - const std::string& message = std::string ()); - - const std::string& - option () const; - - const std::string& - value () const; - - const std::string& - message () const; - - virtual void - print (::std::ostream&) const; - - virtual const char* - what () const throw (); - - private: - std::string option_; - std::string value_; - std::string message_; - }; - - class eos_reached: public exception - { - public: - virtual void - print (::std::ostream&) const; - - virtual const char* - what () const throw (); - }; - - class file_io_failure: public exception - { - public: - virtual - ~file_io_failure () throw (); - - file_io_failure (const std::string& file); - - const std::string& - file () const; - - virtual void - print (::std::ostream&) const; - - virtual const char* - what () const throw (); - - private: - std::string file_; - }; - - class unmatched_quote: public exception - { - public: - virtual - ~unmatched_quote () throw (); - - unmatched_quote (const std::string& argument); - - const std::string& - argument () const; - - virtual void - print (::std::ostream&) const; - - virtual const char* - what () const throw (); - - private: - std::string argument_; - }; - - // Command line argument scanner interface. - // - // The values returned by next() are guaranteed to be valid - // for the two previous arguments up until a call to a third - // peek() or next(). - // - // The position() function returns a monotonically-increasing - // number which, if stored, can later be used to determine the - // relative position of the argument returned by the following - // call to next(). Note that if multiple scanners are used to - // extract arguments from multiple sources, then the end - // position of the previous scanner should be used as the - // start position of the next. - // - class scanner - { - public: - virtual - ~scanner (); - - virtual bool - more () = 0; - - virtual const char* - peek () = 0; - - virtual const char* - next () = 0; - - virtual void - skip () = 0; - - virtual std::size_t - position () = 0; - }; - - class argv_scanner: public scanner - { - public: - argv_scanner (int& argc, - char** argv, - bool erase = false, - std::size_t start_position = 0); - - argv_scanner (int start, - int& argc, - char** argv, - bool erase = false, - std::size_t start_position = 0); - - int - end () const; - - virtual bool - more (); - - virtual const char* - peek (); - - virtual const char* - next (); - - virtual void - skip (); - - virtual std::size_t - position (); - - protected: - std::size_t start_position_; - int i_; - int& argc_; - char** argv_; - bool erase_; - }; - - class argv_file_scanner: public argv_scanner - { - public: - argv_file_scanner (int& argc, - char** argv, - const std::string& option, - bool erase = false, - std::size_t start_position = 0); - - argv_file_scanner (int start, - int& argc, - char** argv, - const std::string& option, - bool erase = false, - std::size_t start_position = 0); - - argv_file_scanner (const std::string& file, - const std::string& option, - std::size_t start_position = 0); - - struct option_info - { - // If search_func is not NULL, it is called, with the arg - // value as the second argument, to locate the options file. - // If it returns an empty string, then the file is ignored. - // - const char* option; - std::string (*search_func) (const char*, void* arg); - void* arg; - }; - - argv_file_scanner (int& argc, - char** argv, - const option_info* options, - std::size_t options_count, - bool erase = false, - std::size_t start_position = 0); - - argv_file_scanner (int start, - int& argc, - char** argv, - const option_info* options, - std::size_t options_count, - bool erase = false, - std::size_t start_position = 0); - - argv_file_scanner (const std::string& file, - const option_info* options = 0, - std::size_t options_count = 0, - std::size_t start_position = 0); - - virtual bool - more (); - - virtual const char* - peek (); - - virtual const char* - next (); - - virtual void - skip (); - - virtual std::size_t - position (); - - // Return the file path if the peeked at argument came from a file and - // the empty string otherwise. The reference is guaranteed to be valid - // till the end of the scanner lifetime. - // - const std::string& - peek_file (); - - // Return the 1-based line number if the peeked at argument came from - // a file and zero otherwise. - // - std::size_t - peek_line (); - - private: - const option_info* - find (const char*) const; - - void - load (const std::string& file); - - typedef argv_scanner base; - - const std::string option_; - option_info option_info_; - const option_info* options_; - std::size_t options_count_; - - struct arg - { - std::string value; - const std::string* file; - std::size_t line; - }; - - std::deque args_; - std::list files_; - - // Circular buffer of two arguments. - // - std::string hold_[2]; - std::size_t i_; - - bool skip_; - - static int zero_argc_; - static std::string empty_string_; - }; - - template - struct parser; - } - } - } -} - -#include - -namespace odb -{ - namespace pgsql - { - namespace details - { - class options - { - public: - options (); - - options (int& argc, - char** argv, - bool erase = false, - ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, - ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); - - options (int start, - int& argc, - char** argv, - bool erase = false, - ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, - ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); - - options (int& argc, - char** argv, - int& end, - bool erase = false, - ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, - ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); - - options (int start, - int& argc, - char** argv, - int& end, - bool erase = false, - ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, - ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); - - options (::odb::pgsql::details::cli::scanner&, - ::odb::pgsql::details::cli::unknown_mode option = ::odb::pgsql::details::cli::unknown_mode::fail, - ::odb::pgsql::details::cli::unknown_mode argument = ::odb::pgsql::details::cli::unknown_mode::stop); - - // Option accessors. - // - const std::string& - user () const; - - bool - user_specified () const; - - const std::string& - password () const; - - bool - password_specified () const; - - const std::string& - database () const; - - bool - database_specified () const; - - const std::string& - host () const; - - bool - host_specified () const; - - const std::string& - port () const; - - bool - port_specified () const; - - const std::string& - options_file () const; - - bool - options_file_specified () const; - - // Print usage information. - // - static ::odb::pgsql::details::cli::usage_para - print_usage (::std::ostream&, - ::odb::pgsql::details::cli::usage_para = ::odb::pgsql::details::cli::usage_para::none); - - // Implementation details. - // - protected: - bool - _parse (const char*, ::odb::pgsql::details::cli::scanner&); - - private: - bool - _parse (::odb::pgsql::details::cli::scanner&, - ::odb::pgsql::details::cli::unknown_mode option, - ::odb::pgsql::details::cli::unknown_mode argument); - - public: - std::string user_; - bool user_specified_; - std::string password_; - bool password_specified_; - std::string database_; - bool database_specified_; - std::string host_; - bool host_specified_; - std::string port_; - bool port_specified_; - std::string options_file_; - bool options_file_specified_; - }; - } - } -} - -#include - -// Begin epilogue. -// -// -// End epilogue. - -#endif // LIBODB_PGSQL_DETAILS_OPTIONS_HXX diff --git a/odb/pgsql/details/pregenerated/odb/pgsql/details/options.ixx b/odb/pgsql/details/pregenerated/odb/pgsql/details/options.ixx deleted file mode 100644 index 340789e..0000000 --- a/odb/pgsql/details/pregenerated/odb/pgsql/details/options.ixx +++ /dev/null @@ -1,372 +0,0 @@ -// -*- C++ -*- -// -// This file was generated by CLI, a command line interface -// compiler for C++. -// - -// Begin prologue. -// -// -// End prologue. - -#include - -namespace odb -{ - namespace pgsql - { - namespace details - { - namespace cli - { - // usage_para - // - inline usage_para:: - usage_para (value v) - : v_ (v) - { - } - - // unknown_mode - // - inline unknown_mode:: - unknown_mode (value v) - : v_ (v) - { - } - - // exception - // - inline ::std::ostream& - operator<< (::std::ostream& os, const exception& e) - { - e.print (os); - return os; - } - - // unknown_option - // - inline unknown_option:: - unknown_option (const std::string& option) - : option_ (option) - { - } - - inline const std::string& unknown_option:: - option () const - { - return option_; - } - - // unknown_argument - // - inline unknown_argument:: - unknown_argument (const std::string& argument) - : argument_ (argument) - { - } - - inline const std::string& unknown_argument:: - argument () const - { - return argument_; - } - - // missing_value - // - inline missing_value:: - missing_value (const std::string& option) - : option_ (option) - { - } - - inline const std::string& missing_value:: - option () const - { - return option_; - } - - // invalid_value - // - inline invalid_value:: - invalid_value (const std::string& option, - const std::string& value, - const std::string& message) - : option_ (option), - value_ (value), - message_ (message) - { - } - - inline const std::string& invalid_value:: - option () const - { - return option_; - } - - inline const std::string& invalid_value:: - value () const - { - return value_; - } - - inline const std::string& invalid_value:: - message () const - { - return message_; - } - - // file_io_failure - // - inline file_io_failure:: - file_io_failure (const std::string& file) - : file_ (file) - { - } - - inline const std::string& file_io_failure:: - file () const - { - return file_; - } - - // unmatched_quote - // - inline unmatched_quote:: - unmatched_quote (const std::string& argument) - : argument_ (argument) - { - } - - inline const std::string& unmatched_quote:: - argument () const - { - return argument_; - } - - // argv_scanner - // - inline argv_scanner:: - argv_scanner (int& argc, - char** argv, - bool erase, - std::size_t sp) - : start_position_ (sp + 1), - i_ (1), - argc_ (argc), - argv_ (argv), - erase_ (erase) - { - } - - inline argv_scanner:: - argv_scanner (int start, - int& argc, - char** argv, - bool erase, - std::size_t sp) - : start_position_ (sp + static_cast (start)), - i_ (start), - argc_ (argc), - argv_ (argv), - erase_ (erase) - { - } - - inline int argv_scanner:: - end () const - { - return i_; - } - - // argv_file_scanner - // - inline argv_file_scanner:: - argv_file_scanner (int& argc, - char** argv, - const std::string& option, - bool erase, - std::size_t sp) - : argv_scanner (argc, argv, erase, sp), - option_ (option), - options_ (&option_info_), - options_count_ (1), - i_ (1), - skip_ (false) - { - option_info_.option = option_.c_str (); - option_info_.search_func = 0; - } - - inline argv_file_scanner:: - argv_file_scanner (int start, - int& argc, - char** argv, - const std::string& option, - bool erase, - std::size_t sp) - : argv_scanner (start, argc, argv, erase, sp), - option_ (option), - options_ (&option_info_), - options_count_ (1), - i_ (1), - skip_ (false) - { - option_info_.option = option_.c_str (); - option_info_.search_func = 0; - } - - inline argv_file_scanner:: - argv_file_scanner (const std::string& file, - const std::string& option, - std::size_t sp) - : argv_scanner (0, zero_argc_, 0, sp), - option_ (option), - options_ (&option_info_), - options_count_ (1), - i_ (1), - skip_ (false) - { - option_info_.option = option_.c_str (); - option_info_.search_func = 0; - - load (file); - } - - inline argv_file_scanner:: - argv_file_scanner (int& argc, - char** argv, - const option_info* options, - std::size_t options_count, - bool erase, - std::size_t sp) - : argv_scanner (argc, argv, erase, sp), - options_ (options), - options_count_ (options_count), - i_ (1), - skip_ (false) - { - } - - inline argv_file_scanner:: - argv_file_scanner (int start, - int& argc, - char** argv, - const option_info* options, - std::size_t options_count, - bool erase, - std::size_t sp) - : argv_scanner (start, argc, argv, erase, sp), - options_ (options), - options_count_ (options_count), - i_ (1), - skip_ (false) - { - } - - inline argv_file_scanner:: - argv_file_scanner (const std::string& file, - const option_info* options, - std::size_t options_count, - std::size_t sp) - : argv_scanner (0, zero_argc_, 0, sp), - options_ (options), - options_count_ (options_count), - i_ (1), - skip_ (false) - { - load (file); - } - } - } - } -} - -namespace odb -{ - namespace pgsql - { - namespace details - { - // options - // - - inline const std::string& options:: - user () const - { - return this->user_; - } - - inline bool options:: - user_specified () const - { - return this->user_specified_; - } - - inline const std::string& options:: - password () const - { - return this->password_; - } - - inline bool options:: - password_specified () const - { - return this->password_specified_; - } - - inline const std::string& options:: - database () const - { - return this->database_; - } - - inline bool options:: - database_specified () const - { - return this->database_specified_; - } - - inline const std::string& options:: - host () const - { - return this->host_; - } - - inline bool options:: - host_specified () const - { - return this->host_specified_; - } - - inline const std::string& options:: - port () const - { - return this->port_; - } - - inline bool options:: - port_specified () const - { - return this->port_specified_; - } - - inline const std::string& options:: - options_file () const - { - return this->options_file_; - } - - inline bool options:: - options_file_specified () const - { - return this->options_file_specified_; - } - } - } -} - -// Begin epilogue. -// -// -// End epilogue. diff --git a/odb/pgsql/error.cxx b/odb/pgsql/error.cxx deleted file mode 100644 index ba8451e..0000000 --- a/odb/pgsql/error.cxx +++ /dev/null @@ -1,86 +0,0 @@ -// file : odb/pgsql/error.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include -#include - -#include -#include -#include - -using namespace std; - -namespace odb -{ - namespace pgsql - { - void - translate_error (connection& c, PGresult* r, - size_t pos, multiple_exceptions* mex) - { - if (!r) - { - if (PQstatus (c.handle ()) == CONNECTION_BAD) - { - c.mark_failed (); - throw connection_lost (); - } - else - throw bad_alloc (); - } - - // Note that we expect the caller to handle PGRES_PIPELINE_ABORTED since - // it's not really an error but rather an indication that no attempt was - // made to execute this statement. - // - string ss; - switch (PQresultStatus (r)) - { - case PGRES_BAD_RESPONSE: - { - throw database_exception ("bad server response"); - } - case PGRES_FATAL_ERROR: - { - const char* s (PQresultErrorField (r, PG_DIAG_SQLSTATE)); - ss = (s != 0 ? s : "?????"); - - // Deadlock detected. - // - if (ss == "40001" || ss == "40P01") - throw deadlock (); - else if (PQstatus (c.handle ()) == CONNECTION_BAD) - { - c.mark_failed (); - throw connection_lost (); - } - break; - } - default: - assert (false); - break; - } - - string msg; - { - // Can be NULL in case of PGRES_BAD_RESPONSE. - // - const char* m (PQresultErrorMessage (r)); - msg = (m != 0 ? m : "bad server response"); - - // Get rid of the trailing newline if there is one. - // - string::size_type n (msg.size ()); - if (n != 0 && msg[n - 1] == '\n') - msg.resize (n - 1); - } - - if (mex == 0) - throw database_exception (ss, msg); - else - // In PosgreSQL all errors are fatal. - // - mex->insert (pos, database_exception (ss, msg), true); - } - } -} diff --git a/odb/pgsql/error.hxx b/odb/pgsql/error.hxx deleted file mode 100644 index 8d2793d..0000000 --- a/odb/pgsql/error.hxx +++ /dev/null @@ -1,41 +0,0 @@ -// file : odb/pgsql/error.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_ERROR_HXX -#define ODB_PGSQL_ERROR_HXX - -#include - -#include - -#include -#include // connection, multiple_exceptions -#include - -namespace odb -{ - namespace pgsql - { - // Translate an error condition involving PGresult* and throw (or return, - // in case multiple_exceptions is not NULL) an appropriate exception. If - // result is NULL, it is assumed that the error was caused due to a bad - // connection or a memory allocation error. - // - LIBODB_PGSQL_EXPORT void - translate_error (connection& c, PGresult* r, - std::size_t pos = 0, multiple_exceptions* = 0); - - // Return true if PGresult is not NULL and is not in an error state. If - // both s and r are non-NULL, the pointed to value will be populated with - // the result status. Otherwise, s is ignored. - // - LIBODB_PGSQL_EXPORT bool - is_good_result (PGresult* r, ExecStatusType* s = 0); - } -} - -#include - -#include - -#endif // ODB_PGSQL_ERROR_HXX diff --git a/odb/pgsql/error.ixx b/odb/pgsql/error.ixx deleted file mode 100644 index 6a010aa..0000000 --- a/odb/pgsql/error.ixx +++ /dev/null @@ -1,31 +0,0 @@ -// file : odb/pgsql/error.ixx -// license : GNU GPL v2; see accompanying LICENSE file - -namespace odb -{ - namespace pgsql - { - inline bool - is_good_result (PGresult* r, ExecStatusType* s) - { - if (r != 0) - { - ExecStatusType status (PQresultStatus (r)); - - if (s != 0) - *s = status; - - return - status != PGRES_BAD_RESPONSE - && status != PGRES_NONFATAL_ERROR - && status != PGRES_FATAL_ERROR -#ifdef LIBPQ_HAS_PIPELINING - && status != PGRES_PIPELINE_ABORTED -#endif - ; - } - - return false; - } - } -} diff --git a/odb/pgsql/exceptions.cxx b/odb/pgsql/exceptions.cxx deleted file mode 100644 index 28e7fc4..0000000 --- a/odb/pgsql/exceptions.cxx +++ /dev/null @@ -1,79 +0,0 @@ -// file : odb/pgsql/exceptions.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -#include - -using namespace std; - -namespace odb -{ - namespace pgsql - { - // - // database_exception - // - - database_exception:: - database_exception (const string& message) - : message_ (message), what_ (message) - { - } - - database_exception:: - database_exception (const string& sqlstate, - const string& message) - : sqlstate_ (sqlstate), message_ (message) - { - if (!sqlstate_.empty ()) - what_ = sqlstate_ + ": " + message_; - else - what_ = message_; - } - - database_exception:: - ~database_exception () ODB_NOTHROW_NOEXCEPT - { - } - - const char* database_exception:: - what () const ODB_NOTHROW_NOEXCEPT - { - return what_.c_str (); - } - - database_exception* database_exception:: - clone () const - { - return new database_exception (*this); - } - - // - // cli_exception - // - - cli_exception:: - cli_exception (const string& what) - : what_ (what) - { - } - - cli_exception:: - ~cli_exception () ODB_NOTHROW_NOEXCEPT - { - } - - const char* cli_exception:: - what () const ODB_NOTHROW_NOEXCEPT - { - return what_.c_str (); - } - - cli_exception* cli_exception:: - clone () const - { - return new cli_exception (*this); - } - } -} diff --git a/odb/pgsql/exceptions.hxx b/odb/pgsql/exceptions.hxx deleted file mode 100644 index 8417c1a..0000000 --- a/odb/pgsql/exceptions.hxx +++ /dev/null @@ -1,80 +0,0 @@ -// file : odb/pgsql/exceptions.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_EXCEPTIONS_HXX -#define ODB_PGSQL_EXCEPTIONS_HXX - -#include - -#include - -#include -#include // ODB_NOTHROW_NOEXCEPT - -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - struct LIBODB_PGSQL_EXPORT database_exception: odb::database_exception - { - database_exception (const std::string& message); - - database_exception (const std::string& sqlstate, - const std::string& message); - - ~database_exception () ODB_NOTHROW_NOEXCEPT; - - const std::string& - message () const - { - return message_; - } - - const std::string& - sqlstate () const - { - return sqlstate_; - } - - virtual const char* - what () const ODB_NOTHROW_NOEXCEPT; - - virtual database_exception* - clone () const; - - private: - std::string sqlstate_; - std::string message_; - std::string what_; - }; - - struct LIBODB_PGSQL_EXPORT cli_exception: odb::exception - { - cli_exception (const std::string& what); - ~cli_exception () ODB_NOTHROW_NOEXCEPT; - - virtual const char* - what () const ODB_NOTHROW_NOEXCEPT; - - virtual cli_exception* - clone () const; - - private: - std::string what_; - }; - - namespace core - { - using pgsql::database_exception; - using pgsql::cli_exception; - } - } -} - -#include - -#endif // ODB_PGSQL_EXCEPTIONS_HXX diff --git a/odb/pgsql/forward.hxx b/odb/pgsql/forward.hxx deleted file mode 100644 index 1186b28..0000000 --- a/odb/pgsql/forward.hxx +++ /dev/null @@ -1,91 +0,0 @@ -// file : odb/pgsql/forward.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_FORWARD_HXX -#define ODB_PGSQL_FORWARD_HXX - -#include - -#include - -namespace odb -{ - namespace pgsql - { - namespace core - { - using namespace odb::common; - } - - // - // - class database; - class connection; - typedef details::shared_ptr connection_ptr; - class connection_factory; - class statement; - class transaction; - class tracer; - - namespace core - { - using pgsql::database; - using pgsql::connection; - using pgsql::connection_ptr; - using pgsql::transaction; - using pgsql::statement; - } - - // Implementation details. - // - enum statement_kind - { - statement_select, - statement_insert, - statement_update, - statement_delete - }; - - class binding; - class select_statement; - - template - class object_statements; - - template - class polymorphic_root_object_statements; - - template - class polymorphic_derived_object_statements; - - template - class no_id_object_statements; - - template - class view_statements; - - template - class container_statements; - - template - class smart_container_statements; - - template - class section_statements; - - class query_base; - } - - namespace details - { - template <> - struct counter_type - { - typedef shared_base counter; - }; - } -} - -#include - -#endif // ODB_PGSQL_FORWARD_HXX diff --git a/odb/pgsql/libodb-pgsql-vc10.vcxproj b/odb/pgsql/libodb-pgsql-vc10.vcxproj deleted file mode 100644 index c764ed2..0000000 --- a/odb/pgsql/libodb-pgsql-vc10.vcxproj +++ /dev/null @@ -1,174 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {B6185C00-39EC-4429-B774-164B4397B995} - Win32Proj - libodb-pgsql - - - - DynamicLibrary - true - Unicode - - - DynamicLibrary - true - Unicode - - - DynamicLibrary - false - true - Unicode - - - DynamicLibrary - false - true - Unicode - - - - - - - - - - - - - - - - - - - true - ..\..\bin\ - odb-pgsql-d-__value__(interface_version)-vc10 - - - true - ..\..\bin64\ - odb-pgsql-d-__value__(interface_version)-vc10 - - - false - ..\..\bin\ - odb-pgsql-__value__(interface_version)-vc10 - - - false - ..\..\bin64\ - odb-pgsql-__value__(interface_version)-vc10 - - - - - - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - - - odb-d.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - $(TargetPath) - ..\..\lib\odb-pgsql-d.lib - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - - - odb-d.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - $(TargetPath) - ..\..\lib64\odb-pgsql-d.lib - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - - - odb.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - true - true - $(TargetPath) - ..\..\lib\odb-pgsql.lib - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - - - odb.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - true - true - $(TargetPath) - ..\..\lib64\odb-pgsql.lib - - - -__header_entries__(headers) - - -__source_entries__(sources) - - - - - diff --git a/odb/pgsql/libodb-pgsql-vc10.vcxproj.filters b/odb/pgsql/libodb-pgsql-vc10.vcxproj.filters deleted file mode 100644 index 781fff8..0000000 --- a/odb/pgsql/libodb-pgsql-vc10.vcxproj.filters +++ /dev/null @@ -1,19 +0,0 @@ - - - - - {A070BD3A-62AD-4ED5-8080-860954BF9EF8} - cxx - - - {8586465A-41C6-4A76-B0AA-256E10243DC2} - h;hxx;ixx;txx - - - -__header_filter_entries__(headers) - - -__source_filter_entries__(sources) - - diff --git a/odb/pgsql/libodb-pgsql-vc11.vcxproj b/odb/pgsql/libodb-pgsql-vc11.vcxproj deleted file mode 100644 index 86d2f81..0000000 --- a/odb/pgsql/libodb-pgsql-vc11.vcxproj +++ /dev/null @@ -1,178 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {B6185C00-39EC-4429-B774-164B4397B995} - Win32Proj - libodb-pgsql - - - - DynamicLibrary - true - v110 - Unicode - - - DynamicLibrary - true - v110 - Unicode - - - DynamicLibrary - false - v110 - true - Unicode - - - DynamicLibrary - false - v110 - true - Unicode - - - - - - - - - - - - - - - - - - - true - ..\..\bin\ - odb-pgsql-d-__value__(interface_version)-vc11 - - - true - ..\..\bin64\ - odb-pgsql-d-__value__(interface_version)-vc11 - - - false - ..\..\bin\ - odb-pgsql-__value__(interface_version)-vc11 - - - false - ..\..\bin64\ - odb-pgsql-__value__(interface_version)-vc11 - - - - - - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - - - odb-d.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - $(TargetPath) - ..\..\lib\odb-pgsql-d.lib - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - - - odb-d.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - $(TargetPath) - ..\..\lib64\odb-pgsql-d.lib - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - - - odb.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - true - true - $(TargetPath) - ..\..\lib\odb-pgsql.lib - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - - - odb.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - true - true - $(TargetPath) - ..\..\lib64\odb-pgsql.lib - - - -__header_entries__(headers) - - -__source_entries__(sources) - - - - - diff --git a/odb/pgsql/libodb-pgsql-vc11.vcxproj.filters b/odb/pgsql/libodb-pgsql-vc11.vcxproj.filters deleted file mode 100644 index 781fff8..0000000 --- a/odb/pgsql/libodb-pgsql-vc11.vcxproj.filters +++ /dev/null @@ -1,19 +0,0 @@ - - - - - {A070BD3A-62AD-4ED5-8080-860954BF9EF8} - cxx - - - {8586465A-41C6-4A76-B0AA-256E10243DC2} - h;hxx;ixx;txx - - - -__header_filter_entries__(headers) - - -__source_filter_entries__(sources) - - diff --git a/odb/pgsql/libodb-pgsql-vc12.vcxproj b/odb/pgsql/libodb-pgsql-vc12.vcxproj deleted file mode 100644 index 1b4f080..0000000 --- a/odb/pgsql/libodb-pgsql-vc12.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {B6185C00-39EC-4429-B774-164B4397B995} - Win32Proj - libodb-pgsql - - - - DynamicLibrary - true - v120 - Unicode - - - DynamicLibrary - true - v120 - Unicode - - - DynamicLibrary - false - v120 - true - Unicode - - - DynamicLibrary - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - ..\..\bin\ - odb-pgsql-d-__value__(interface_version)-vc12 - - - true - ..\..\bin64\ - odb-pgsql-d-__value__(interface_version)-vc12 - - - false - ..\..\bin\ - odb-pgsql-__value__(interface_version)-vc12 - - - false - ..\..\bin64\ - odb-pgsql-__value__(interface_version)-vc12 - - - - - - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - true - - - odb-d.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - $(TargetPath) - ..\..\lib\odb-pgsql-d.lib - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - true - - - odb-d.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - $(TargetPath) - ..\..\lib64\odb-pgsql-d.lib - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - true - - - odb.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - true - true - $(TargetPath) - ..\..\lib\odb-pgsql.lib - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBODB_PGSQL_DYNAMIC_LIB;%(PreprocessorDefinitions) - ..\.. - 4355;4800;4290;4251;4267;%(DisableSpecificWarnings) - true - - - odb.lib;libpq.lib;%(AdditionalDependencies) - Windows - true - true - true - $(TargetPath) - ..\..\lib64\odb-pgsql.lib - - - -__header_entries__(headers) - - -__source_entries__(sources) - - - - - diff --git a/odb/pgsql/libodb-pgsql-vc12.vcxproj.filters b/odb/pgsql/libodb-pgsql-vc12.vcxproj.filters deleted file mode 100644 index 781fff8..0000000 --- a/odb/pgsql/libodb-pgsql-vc12.vcxproj.filters +++ /dev/null @@ -1,19 +0,0 @@ - - - - - {A070BD3A-62AD-4ED5-8080-860954BF9EF8} - cxx - - - {8586465A-41C6-4A76-B0AA-256E10243DC2} - h;hxx;ixx;txx - - - -__header_filter_entries__(headers) - - -__source_filter_entries__(sources) - - diff --git a/odb/pgsql/libodb-pgsql-vc8.vcproj b/odb/pgsql/libodb-pgsql-vc8.vcproj deleted file mode 100644 index 8e3718c..0000000 --- a/odb/pgsql/libodb-pgsql-vc8.vcproj +++ /dev/null @@ -1,352 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__source_entries__(sources) - - -__file_entries__(headers) - - - - - diff --git a/odb/pgsql/libodb-pgsql-vc9.vcproj b/odb/pgsql/libodb-pgsql-vc9.vcproj deleted file mode 100644 index af0b2c2..0000000 --- a/odb/pgsql/libodb-pgsql-vc9.vcproj +++ /dev/null @@ -1,359 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__source_entries__(sources) - - -__file_entries__(headers) - - - - - diff --git a/odb/pgsql/makefile b/odb/pgsql/makefile deleted file mode 100644 index acd23f6..0000000 --- a/odb/pgsql/makefile +++ /dev/null @@ -1,157 +0,0 @@ -# file : odb/pgsql/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make - -cxx := \ -auto-handle.cxx \ -connection.cxx \ -connection-factory.cxx \ -database.cxx \ -error.cxx \ -exceptions.cxx \ -prepared-query.cxx \ -query.cxx \ -query-dynamic.cxx \ -query-const-expr.cxx \ -simple-object-statements.cxx \ -statement.cxx \ -statements-base.cxx \ -tracer.cxx \ -traits.cxx \ -transaction.cxx \ -transaction-impl.cxx \ -details/endian-traits.cxx - -cli_tun := details/options.cli -cxx_tun := $(cxx) -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(cli_tun:.cli=.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -odb_pgsql.l := $(out_base)/odb-pgsql.l -odb_pgsql.l.cpp-options := $(out_base)/odb-pgsql.l.cpp-options - -default := $(out_base)/ -dist := $(out_base)/.dist -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/cli/stub.make,\ - cli: cli,cli-rules: cli_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libpq/stub.make,\ - l: pq.l,\ - cpp-options: pq.l.cpp-options,\ - cpp-options-inline: pq_cpp_options) - -# Build. -# -$(odb_pgsql.l): $(cxx_obj) $(odb.l) $(pq.l) -$(odb_pgsql.l.cpp-options): value := -I$(out_root) -I$(src_root) \ -$(pq_cpp_options) -$(odb_pgsql.l.cpp-options): $(odb.l.cpp-options) $(pq.l.cpp-options) - -$(cxx_obj) $(cxx_od): $(odb_pgsql.l.cpp-options) $(out_base)/details/config.h - -genf := $(cli_tun:.cli=.hxx) $(cli_tun:.cli=.ixx) $(cli_tun:.cli=.cxx) -gen := $(addprefix $(out_base)/,$(genf)) - -# Don't try to depend on the installed executable. -# -ifneq ($(cli),cli) -$(gen): $(cli) -endif - -$(gen): cli := $(cli) -$(gen): cli_options += \ ---long-usage \ ---generate-specifier \ ---generate-file-scanner \ ---cli-namespace odb::pgsql::details::cli \ ---guard-prefix LIBODB_PGSQL_DETAILS - -$(out_base)/details/config.h: | $(out_base)/details/. - @echo '/* file : odb/pgsql/details/config.h' >$@ - @echo ' * note : automatically generated' >>$@ - @echo ' */' >>$@ - @echo '' >>$@ - @echo '#ifndef ODB_PGSQL_DETAILS_CONFIG_H' >>$@ - @echo '#define ODB_PGSQL_DETAILS_CONFIG_H' >>$@ - @echo '' >>$@ - @echo '#endif /* ODB_PGSQL_DETAILS_CONFIG_H */' >>$@ - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen) $(out_base)/details/config.h) - -# Convenience alias for default target. -# -$(out_base)/: $(odb_pgsql.l) - -# Dist. -# -$(dist): sources_dist := $(cxx) -$(dist): export sources := $(sources_dist) $(cli_tun:.cli=.cxx) -$(dist): headers_dist = $(subst $(src_base)/,,$(shell find $(src_base) \ --name '*.hxx' -o -name '*.ixx' -o -name '*.txx')) -$(dist): gen_headers := $(cli_tun:.cli=.hxx) $(cli_tun:.cli=.ixx) -$(dist): export headers = $(sort $(headers_dist) $(gen_headers)) -$(dist): gen_dist := $(gen) -$(dist): data_dist := $(cli_tun) details/config.h.in details/config-vc.h -$(dist): export extra_dist := $(data_dist) \ -libodb-pgsql-vc8.vcproj libodb-pgsql-vc9.vcproj \ -libodb-pgsql-vc10.vcxproj libodb-pgsql-vc10.vcxproj.filters \ -libodb-pgsql-vc11.vcxproj libodb-pgsql-vc11.vcxproj.filters \ -libodb-pgsql-vc12.vcxproj libodb-pgsql-vc12.vcxproj.filters -$(dist): export interface_version = $(shell sed -e \ -'s/^\([0-9]*\.[0-9]*\).*/\1/' $(src_root)/version.txt) - -$(dist): $(gen) - $(call dist-data,$(sources_dist) $(headers_dist) $(data_dist)) - $(call dist-data,$(gen_dist),$(dist_prefix)/odb/pgsql/details) - $(call meta-vc8proj,$(src_base)/libodb-pgsql-vc8.vcproj) - $(call meta-vc9proj,$(src_base)/libodb-pgsql-vc9.vcproj) - $(call meta-vc10proj,$(src_base)/libodb-pgsql-vc10.vcxproj) - $(call meta-vc11proj,$(src_base)/libodb-pgsql-vc11.vcxproj) - $(call meta-vc12proj,$(src_base)/libodb-pgsql-vc12.vcxproj) - $(call meta-automake) - -# Clean. -# -$(clean): $(odb_pgsql.l).o.clean \ - $(odb_pgsql.l.cpp-options).clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(cli_tun:.cli=.cxx.cli.clean)) - $(call message,rm $$1,rm -f $$1,$(out_base)/details/config.h) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(odb_pgsql.l): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := details/config.h $(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,$(cli_rules)) -$(call include,$(bld_root)/cxx/o-l.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/cxx-d.make) diff --git a/odb/pgsql/no-id-object-result.hxx b/odb/pgsql/no-id-object-result.hxx deleted file mode 100644 index 734d4a7..0000000 --- a/odb/pgsql/no-id-object-result.hxx +++ /dev/null @@ -1,77 +0,0 @@ -// file : odb/pgsql/no-id-object-result.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_NO_ID_OBJECT_RESULT_HXX -#define ODB_PGSQL_NO_ID_OBJECT_RESULT_HXX - -#include - -#include // std::size_t - -#include -#include - -#include - -#include -#include // query_base -#include -#include - -namespace odb -{ - namespace pgsql - { - template - class no_id_object_result_impl: public odb::no_id_object_result_impl - { - public: - typedef odb::no_id_object_result_impl base_type; - - typedef typename base_type::object_type object_type; - typedef typename base_type::pointer_type pointer_type; - - typedef object_traits_impl object_traits; - typedef typename base_type::pointer_traits pointer_traits; - - typedef typename object_traits::statements_type statements_type; - - virtual - ~no_id_object_result_impl (); - - no_id_object_result_impl (const query_base&, - details::shared_ptr, - statements_type&, - const schema_version_migration*); - - virtual void - load (object_type&); - - virtual void - next (); - - virtual void - cache (); - - virtual std::size_t - size (); - - virtual void - invalidate (); - - using base_type::current; - - private: - details::shared_ptr statement_; - statements_type& statements_; - object_traits_calls tc_; - std::size_t count_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_NO_ID_OBJECT_RESULT_HXX diff --git a/odb/pgsql/no-id-object-result.txx b/odb/pgsql/no-id-object-result.txx deleted file mode 100644 index 0bae952..0000000 --- a/odb/pgsql/no-id-object-result.txx +++ /dev/null @@ -1,114 +0,0 @@ -// file : odb/pgsql/no-id-object-result.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -#include - -namespace odb -{ - namespace pgsql - { - template - no_id_object_result_impl:: - ~no_id_object_result_impl () - { - if (!this->end_) - statement_->free_result (); - } - - template - void no_id_object_result_impl:: - invalidate () - { - if (!this->end_) - { - statement_->free_result (); - this->end_ = true; - } - - statement_.reset (); - } - - template - no_id_object_result_impl:: - no_id_object_result_impl (const query_base&, - details::shared_ptr statement, - statements_type& statements, - const schema_version_migration* svm) - : base_type (statements.connection ()), - statement_ (statement), - statements_ (statements), - tc_ (svm), - count_ (0) - { - } - - template - void no_id_object_result_impl:: - load (object_type& obj) - { - // The image can grow between calls to load() as a result of other - // statements execution. - // - typename object_traits::image_type& im (statements_.image ()); - - if (im.version != statements_.select_image_version ()) - { - binding& b (statements_.select_image_binding ()); - tc_.bind (b.bind, im, statement_select); - statements_.select_image_version (im.version); - b.version++; - } - - select_statement::result r (statement_->load ()); - - if (r == select_statement::truncated) - { - if (tc_.grow (im, statements_.select_image_truncated ())) - im.version++; - - if (im.version != statements_.select_image_version ()) - { - binding& b (statements_.select_image_binding ()); - tc_.bind (b.bind, im, statement_select); - statements_.select_image_version (im.version); - b.version++; - statement_->reload (); - } - } - - object_traits::callback (this->db_, obj, callback_event::pre_load); - tc_.init (obj, im, &this->db_); - object_traits::callback (this->db_, obj, callback_event::post_load); - } - - template - void no_id_object_result_impl:: - next () - { - this->current (pointer_type ()); - - if (statement_->next ()) - count_++; - else - { - statement_->free_result (); - this->end_ = true; - } - } - - template - void no_id_object_result_impl:: - cache () - { - } - - template - std::size_t no_id_object_result_impl:: - size () - { - return this->end_ ? count_ : statement_->result_size (); - } - } -} diff --git a/odb/pgsql/no-id-object-statements.hxx b/odb/pgsql/no-id-object-statements.hxx deleted file mode 100644 index baa1b2a..0000000 --- a/odb/pgsql/no-id-object-statements.hxx +++ /dev/null @@ -1,147 +0,0 @@ -// file : odb/pgsql/no-id-object-statements.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_NO_ID_OBJECT_STATEMENTS_HXX -#define ODB_PGSQL_NO_ID_OBJECT_STATEMENTS_HXX - -#include - -#include // std::size_t - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - // - // Implementation for objects without object id. - // - - template - class no_id_object_statements: public statements_base - { - public: - typedef T object_type; - typedef object_traits_impl object_traits; - typedef typename object_traits::pointer_type pointer_type; - typedef typename object_traits::image_type image_type; - - typedef pgsql::insert_statement insert_statement_type; - - public: - no_id_object_statements (connection_type&); - - virtual - ~no_id_object_statements (); - - // Object image. - // - image_type& - image (std::size_t i = 0) - { - return image_[i]; - } - - // Insert binding. - // - std::size_t - insert_image_version () const { return insert_image_version_;} - - void - insert_image_version (std::size_t v) {insert_image_version_ = v;} - - binding& - insert_image_binding () {return insert_image_binding_;} - - // Select binding (needed for query support). - // - std::size_t - select_image_version () const { return select_image_version_;} - - void - select_image_version (std::size_t v) {select_image_version_ = v;} - - binding& - select_image_binding () {return select_image_binding_;} - - bool* - select_image_truncated () {return select_image_truncated_;} - - // Statements. - // - insert_statement_type& - persist_statement () - { - if (persist_ == 0) - persist_.reset ( - new (details::shared) insert_statement_type ( - conn_, - object_traits::persist_statement_name, - object_traits::persist_statement, - object_traits::versioned, // Process if versioned. - object_traits::persist_statement_types, - insert_column_count, - insert_image_binding_, - insert_image_native_binding_, - 0, - false)); - - return *persist_; - } - - public: - // select = total - // insert = total - inverse; inverse == 0 for object without id - // - static const std::size_t insert_column_count = - object_traits::column_count; - - static const std::size_t select_column_count = - object_traits::column_count; - - private: - no_id_object_statements (const no_id_object_statements&); - no_id_object_statements& operator= (const no_id_object_statements&); - - private: - image_type image_[object_traits::batch]; - unsigned long long status_[object_traits::batch]; - - // Select binding. - // - std::size_t select_image_version_; - binding select_image_binding_; - bind select_image_bind_[select_column_count]; - bool select_image_truncated_[select_column_count]; - - // Insert binding. - // - std::size_t insert_image_version_; - binding insert_image_binding_; - bind insert_image_bind_[insert_column_count]; - native_binding insert_image_native_binding_; - char* insert_image_values_[insert_column_count]; - int insert_image_lengths_[insert_column_count]; - int insert_image_formats_[insert_column_count]; - - details::shared_ptr persist_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_NO_ID_OBJECT_STATEMENTS_HXX diff --git a/odb/pgsql/no-id-object-statements.txx b/odb/pgsql/no-id-object-statements.txx deleted file mode 100644 index 0c340ab..0000000 --- a/odb/pgsql/no-id-object-statements.txx +++ /dev/null @@ -1,50 +0,0 @@ -// file : odb/pgsql/no-id-object-statements.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // std::memset - -namespace odb -{ - namespace pgsql - { - // - // no_id_object_statements - // - - template - no_id_object_statements:: - ~no_id_object_statements () - { - } - - template - no_id_object_statements:: - no_id_object_statements (connection_type& conn) - : statements_base (conn), - // select - select_image_binding_ (select_image_bind_, select_column_count), - // insert - insert_image_binding_ (insert_image_bind_, - insert_column_count, - object_traits::batch, - sizeof (image_type), - status_), - insert_image_native_binding_ (insert_image_values_, - insert_image_lengths_, - insert_image_formats_, - insert_column_count) - { - image_[0].version = 0; // Only version in the first element used. - select_image_version_ = 0; - insert_image_version_ = 0; - - std::memset (insert_image_bind_, 0, sizeof (insert_image_bind_)); - std::memset (select_image_bind_, 0, sizeof (select_image_bind_)); - std::memset ( - select_image_truncated_, 0, sizeof (select_image_truncated_)); - - for (std::size_t i (0); i < select_column_count; ++i) - select_image_bind_[i].truncated = select_image_truncated_ + i; - } - } -} diff --git a/odb/pgsql/pgsql-fwd.hxx b/odb/pgsql/pgsql-fwd.hxx deleted file mode 100644 index e60bc37..0000000 --- a/odb/pgsql/pgsql-fwd.hxx +++ /dev/null @@ -1,19 +0,0 @@ -// file : odb/pgsql/pgsql-fwd.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_PGSQL_FWD_HXX -#define ODB_PGSQL_PGSQL_FWD_HXX - -#include - -// Forward declaration for some of the types defined in libpq-fe.h. This -// allows us to avoid having to include libpq-fe.h in public headers. -// -typedef unsigned int Oid; - -typedef struct pg_conn PGconn; -typedef struct pg_result PGresult; - -#include - -#endif // ODB_PGSQL_PGSQL_FWD_HXX diff --git a/odb/pgsql/pgsql-oid.hxx b/odb/pgsql/pgsql-oid.hxx deleted file mode 100644 index e2ef1af..0000000 --- a/odb/pgsql/pgsql-oid.hxx +++ /dev/null @@ -1,47 +0,0 @@ -// file : odb/pgsql/pgsql-oid.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -// Generated file of OIDs extracted from the PostgreSQL 8.4.8 source file -// src/include/catalog/pg_type.h -// - -#ifndef ODB_PGSQL_PGSQL_OID_HXX -#define ODB_PGSQL_PGSQL_OID_HXX - -#include - -#include - -namespace odb -{ - namespace pgsql - { - enum - { - bool_oid = 16, - int2_oid = 21, - int4_oid = 23, - int8_oid = 20, - - numeric_oid = 1700, - - float4_oid = 700, - float8_oid = 701, - - date_oid = 1082, - time_oid = 1083, - timestamp_oid = 1114, - - text_oid = 25, - bytea_oid = 17, - bit_oid = 1560, - varbit_oid = 1562, - - uuid_oid = 2950 - }; - } -} - -#include - -#endif // ODB_PGSQL_PGSQL_OID_HXX diff --git a/odb/pgsql/pgsql-types.hxx b/odb/pgsql/pgsql-types.hxx deleted file mode 100644 index 117a41e..0000000 --- a/odb/pgsql/pgsql-types.hxx +++ /dev/null @@ -1,59 +0,0 @@ -// file : odb/pgsql/pgsql-types.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_PGSQL_TYPES_HXX -#define ODB_PGSQL_PGSQL_TYPES_HXX - -#include - -#include // std::size_t - -#include // Oid - -namespace odb -{ - namespace pgsql - { - // The libpq result binding. This data structures is roughly modeled - // after MYSQL_BIND from MySQL. - // - // Types that may need to grow are bound as pointers to pointers to char - // array (normally in details::buffer) in order to allow simple offsetting - // in bulk operation support. Note that if we were to do the same for - // capacity, we could get rid of the buffer growth tracking altogether. - // - struct bind - { - enum buffer_type - { - boolean_, // Buffer is a bool; size, capacity, truncated are unused. - smallint, // Buffer is short; size, capacity, truncated are unused. - integer, // Buffer is int; size, capacity, truncated are unused. - bigint, // Buffer is long long; size, capacity, truncated are unused. - real, // Buffer is float; size, capacity, truncated are unused. - double_, // Buffer is double; size, capacity, truncated are unused. - numeric, // Buffer is a pointer to pointer to char array. - date, // Buffer is int; size, capacity, truncated are unused. - time, // Buffer is long long; size, capacity, truncated are unused. - timestamp,// Buffer is long long; size, capacity, truncated are unused. - text, // Buffer is a pointer to pointer to char array. - bytea, // Buffer is a pointer to pointer to char array. - bit, // Buffer is a pointer to char array. - varbit, // Buffer is a pointer to pointer to char array. - uuid // Buffer is a 16-byte char array; size capacity, truncated - // are unused. Note: big-endian, in RFC 4122/4.1.2 order. - }; - - buffer_type type; - void* buffer; - std::size_t* size; - std::size_t capacity; - bool* is_null; - bool* truncated; - }; - } -} - -#include - -#endif // ODB_PGSQL_PGSQL_TYPES_HXX diff --git a/odb/pgsql/polymorphic-object-result.hxx b/odb/pgsql/polymorphic-object-result.hxx deleted file mode 100644 index a1cd108..0000000 --- a/odb/pgsql/polymorphic-object-result.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : odb/pgsql/polymorphic-object-result.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_POLYMORPHIC_OBJECT_RESULT_HXX -#define ODB_PGSQL_POLYMORPHIC_OBJECT_RESULT_HXX - -#include - -#include // std::size_t - -#include -#include - -#include - -#include -#include // query_base -#include -#include - -namespace odb -{ - namespace pgsql - { - template - class polymorphic_object_result_impl: - public odb::polymorphic_object_result_impl - { - public: - typedef odb::polymorphic_object_result_impl base_type; - - typedef typename base_type::id_type id_type; - typedef typename base_type::object_type object_type; - typedef typename base_type::pointer_type pointer_type; - - typedef object_traits_impl object_traits; - typedef typename base_type::pointer_traits pointer_traits; - - typedef typename base_type::root_type root_type; - typedef typename base_type::discriminator_type discriminator_type; - - typedef object_traits_impl root_traits; - - typedef typename object_traits::statements_type statements_type; - - virtual - ~polymorphic_object_result_impl (); - - polymorphic_object_result_impl (const query_base&, - details::shared_ptr, - statements_type&, - const schema_version_migration*); - - virtual void - load (object_type*, bool fetch); - - virtual id_type - load_id (); - - virtual discriminator_type - load_discriminator (); - - virtual void - next (); - - virtual void - cache (); - - virtual std::size_t - size (); - - virtual void - invalidate (); - - using base_type::current; - - private: - void - load_image (); - - private: - details::shared_ptr statement_; - statements_type& statements_; - object_traits_calls tc_; - std::size_t count_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_POLYMORPHIC_OBJECT_RESULT_HXX diff --git a/odb/pgsql/polymorphic-object-result.txx b/odb/pgsql/polymorphic-object-result.txx deleted file mode 100644 index bad2091..0000000 --- a/odb/pgsql/polymorphic-object-result.txx +++ /dev/null @@ -1,287 +0,0 @@ -// file : odb/pgsql/polymorphic-object-result.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -#include -#include // object_not_persistent - -#include - -namespace odb -{ - namespace pgsql - { - template - polymorphic_object_result_impl:: - ~polymorphic_object_result_impl () - { - if (!this->end_) - statement_->free_result (); - } - - template - void polymorphic_object_result_impl:: - invalidate () - { - if (!this->end_) - { - statement_->free_result (); - this->end_ = true; - } - - statement_.reset (); - } - - template - polymorphic_object_result_impl:: - polymorphic_object_result_impl (const query_base&, - details::shared_ptr st, - statements_type& sts, - const schema_version_migration* svm) - : base_type (sts.connection ()), - statement_ (st), - statements_ (sts), - tc_ (svm), - count_ (0) - { - } - - template - void polymorphic_object_result_impl:: - load (object_type* pobj, bool fetch) - { - if (fetch) - load_image (); - - typename statements_type::root_statements_type& rsts ( - statements_.root_statements ()); - - // This is a top-level call so the statements cannot be locked. - // - assert (!rsts.locked ()); - typename statements_type::auto_lock l (rsts); - - typename object_traits::image_type& i (statements_.image ()); - typename root_traits::image_type& ri (rsts.image ()); - - id_type id (root_traits::id (ri)); - - // Determine this object's dynamic type. - // - typedef typename root_traits::info_type info_type; - discriminator_type d (root_traits::discriminator (ri)); - discriminator_type disc (d); - - // Use the polymorphic_info() helper to get concrete_info if - // object_type is concrete and NULL if it is abstract. - // - const info_type* spi (polymorphic_info (object_traits::info)); - const info_type& pi ( - spi != 0 && spi->discriminator == d - ? *spi - : root_traits::map->find (d)); - - typedef typename root_traits::pointer_type root_pointer_type; - typedef typename root_traits::pointer_traits root_pointer_traits; - - typename object_traits::pointer_cache_traits::insert_guard ig; - - if (pobj == 0) - { - // Need to create a new instance of the dynamic type. - // - root_pointer_type rp (pi.create ()); - pointer_type p ( - root_pointer_traits::template static_pointer_cast (rp)); - - // Insert it as a root pointer (for non-unique pointers, rp should - // still be valid and for unique pointers this is a no-op). - // - ig.reset ( - object_traits::pointer_cache_traits::insert (this->db_, id, rp)); - - pobj = &pointer_traits::get_ref (p); - current (p); - } - else - { - // We are loading into an existing instance. If the static and - // dynamic types differ, then make sure the instance is at least - // of the dynamic type. - // - if (&pi != &object_traits::info) - { - const info_type& dpi (root_traits::map->find (typeid (*pobj))); - - if (&dpi != &pi && dpi.derived (pi)) - throw object_not_persistent (); // @@ type_mismatch ? - } - } - - callback_event ce (callback_event::pre_load); - pi.dispatch (info_type::call_callback, this->db_, pobj, &ce); - - tc_.init (*pobj, i, &this->db_); - - // Initialize the id image and binding and load the rest of the object - // (containers, dynamic part, etc). - // - typename object_traits::id_image_type& idi (statements_.id_image ()); - root_traits::init (idi, id); - - binding& idb (statements_.id_image_binding ()); - if (idi.version != statements_.id_image_version () || idb.version == 0) - { - object_traits::bind (idb.bind, idi); - statements_.id_image_version (idi.version); - idb.version++; - } - - tc_.load_ (statements_, *pobj, false); - - // Load the dynamic part of the object unless static and dynamic - // types are the same. - // - if (&pi != &object_traits::info) - { - std::size_t d (object_traits::depth); - pi.dispatch (info_type::call_load, this->db_, pobj, &d); - }; - - rsts.load_delayed (tc_.version ()); - l.unlock (); - - ce = callback_event::post_load; - pi.dispatch (info_type::call_callback, this->db_, pobj, &ce); - object_traits::pointer_cache_traits::load (ig.position ()); - ig.release (); - } - - template - typename polymorphic_object_result_impl::id_type - polymorphic_object_result_impl:: - load_id () - { - load_image (); - return root_traits::id (statements_.root_statements ().image ()); - } - - template - typename polymorphic_object_result_impl::discriminator_type - polymorphic_object_result_impl:: - load_discriminator () - { - load_image (); - return root_traits::discriminator ( - statements_.root_statements ().image ()); - } - - template - void polymorphic_object_result_impl:: - next () - { - this->current (pointer_type ()); - - if (statement_->next ()) - count_++; - else - { - statement_->free_result (); - this->end_ = true; - } - } - - template - struct polymorphic_image_rebind - { - // Derived type version. - // - typedef object_traits_impl traits; - - static bool - rebind (typename traits::statements_type& sts, - const schema_version_migration* svm) - { - typename traits::image_type& im (sts.image ()); - - if (traits::check_version (sts.select_image_versions (), im)) - { - binding& b (sts.select_image_binding (traits::depth)); - object_traits_calls tc (svm); - tc.bind (b.bind, 0, 0, im, statement_select); - traits::update_version ( - sts.select_image_versions (), im, sts.select_image_bindings ()); - return true; - } - - return false; - } - }; - - template - struct polymorphic_image_rebind - { - // Root type version. - // - typedef object_traits_impl traits; - - static bool - rebind (typename traits::statements_type& sts, - const schema_version_migration* svm) - { - typename traits::image_type& im (sts.image ()); - - if (im.version != sts.select_image_version ()) - { - binding& b (sts.select_image_binding ()); - object_traits_calls tc (svm); - tc.bind (b.bind, im, statement_select); - sts.select_image_version (im.version); - b.version++; - return true; - } - - return false; - } - }; - - template - void polymorphic_object_result_impl:: - load_image () - { - typedef polymorphic_image_rebind image_rebind; - - // The image can grow between calls to load() as a result of other - // statements execution. - // - image_rebind::rebind (statements_, tc_.version ()); - - select_statement::result r (statement_->load ()); - - if (r == select_statement::truncated) - { - typename object_traits::image_type& im (statements_.image ()); - - if (tc_.grow (im, statements_.select_image_truncated ())) - im.version++; - - if (image_rebind::rebind (statements_, tc_.version ())) - statement_->reload (); - } - } - - template - void polymorphic_object_result_impl:: - cache () - { - } - - template - std::size_t polymorphic_object_result_impl:: - size () - { - return this->end_ ? count_ : statement_->result_size (); - } - } -} diff --git a/odb/pgsql/polymorphic-object-statements.hxx b/odb/pgsql/polymorphic-object-statements.hxx deleted file mode 100644 index 717410a..0000000 --- a/odb/pgsql/polymorphic-object-statements.hxx +++ /dev/null @@ -1,513 +0,0 @@ -// file : odb/pgsql/polymorphic-object-statements.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX -#define ODB_PGSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX - -#include - -#include // std::size_t - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - // - // Implementation for polymorphic objects. - // - - template - class polymorphic_root_object_statements: public object_statements - { - public: - typedef typename object_statements::connection_type connection_type; - typedef typename object_statements::object_traits object_traits; - typedef typename object_statements::id_image_type id_image_type; - - typedef - typename object_traits::discriminator_image_type - discriminator_image_type; - - typedef - typename object_statements::select_statement_type - select_statement_type; - - public: - // Interface compatibility with derived_object_statements. - // - typedef polymorphic_root_object_statements root_statements_type; - - root_statements_type& - root_statements () - { - return *this; - } - - public: - // Discriminator binding. - // - discriminator_image_type& - discriminator_image () {return discriminator_image_;} - - std::size_t - discriminator_image_version () const - {return discriminator_image_version_;} - - void - discriminator_image_version (std::size_t v) - {discriminator_image_version_ = v;} - - binding& - discriminator_image_binding () {return discriminator_image_binding_;} - - bool* - discriminator_image_truncated () {return discriminator_image_truncated_;} - - // Id binding for discriminator retrieval. - // - id_image_type& - discriminator_id_image () {return discriminator_id_image_;} - - std::size_t - discriminator_id_image_version () const - {return discriminator_id_image_version_;} - - void - discriminator_id_image_version (std::size_t v) - {discriminator_id_image_version_ = v;} - - binding& - discriminator_id_image_binding () - {return discriminator_id_image_binding_;} - - // Expose id native binding from object_statements. - // - native_binding& - id_image_native_binding () {return this->id_image_native_binding_;} - - // - // - select_statement_type& - find_discriminator_statement () - { - if (find_discriminator_ == 0) - find_discriminator_.reset ( - new (details::shared) select_statement_type ( - this->conn_, - object_traits::find_discriminator_statement_name, - object_traits::find_discriminator_statement, - false, // Doesn't need to be processed. - false, // Don't optimize. - object_traits::find_statement_types, // The same as find (id). - id_column_count, - discriminator_id_image_binding_, - discriminator_id_image_native_binding_, - discriminator_image_binding_, - false)); - - return *find_discriminator_; - } - - public: - polymorphic_root_object_statements (connection_type&); - - virtual - ~polymorphic_root_object_statements (); - - // Static "override" (statements type). - // - void - load_delayed (const schema_version_migration* svm) - { - assert (this->locked ()); - - if (!this->delayed_.empty ()) - this->template load_delayed_ ( - svm); - } - - public: - static const std::size_t id_column_count = - object_statements::id_column_count; - - static const std::size_t discriminator_column_count = - object_traits::discriminator_column_count; - - static const std::size_t managed_optimistic_column_count = - object_traits::managed_optimistic_column_count; - - private: - // Discriminator image. - // - discriminator_image_type discriminator_image_; - std::size_t discriminator_image_version_; - binding discriminator_image_binding_; - bind discriminator_image_bind_[discriminator_column_count + - managed_optimistic_column_count]; - bool discriminator_image_truncated_[discriminator_column_count + - managed_optimistic_column_count]; - - // Id image for discriminator retrieval (only used as a parameter). - // - id_image_type discriminator_id_image_; - std::size_t discriminator_id_image_version_; - binding discriminator_id_image_binding_; - native_binding discriminator_id_image_native_binding_; - bind discriminator_id_image_bind_[id_column_count]; - char* discriminator_id_image_values_[id_column_count]; - int discriminator_id_image_lengths_[id_column_count]; - int discriminator_id_image_formats_[id_column_count]; - - details::shared_ptr find_discriminator_; - }; - - template - class polymorphic_derived_object_statements: public statements_base - { - public: - typedef T object_type; - typedef object_traits_impl object_traits; - typedef typename object_traits::id_type id_type; - typedef typename object_traits::pointer_type pointer_type; - typedef typename object_traits::id_image_type id_image_type; - typedef typename object_traits::image_type image_type; - - typedef typename object_traits::root_type root_type; - typedef - polymorphic_root_object_statements - root_statements_type; - - typedef typename object_traits::base_type base_type; - typedef - typename object_traits::base_traits::statements_type - base_statements_type; - - typedef - typename object_traits::extra_statement_cache_type - extra_statement_cache_type; - - typedef pgsql::insert_statement insert_statement_type; - typedef pgsql::select_statement select_statement_type; - typedef pgsql::update_statement update_statement_type; - typedef pgsql::delete_statement delete_statement_type; - - typedef typename root_statements_type::auto_lock auto_lock; - - public: - polymorphic_derived_object_statements (connection_type&); - - virtual - ~polymorphic_derived_object_statements (); - - public: - // Delayed loading. - // - static void - delayed_loader (odb::database&, - const id_type&, - root_type&, - const schema_version_migration*); - public: - // Root and immediate base statements. - // - root_statements_type& - root_statements () - { - return root_statements_; - } - - base_statements_type& - base_statements () - { - return base_statements_; - } - - public: - // Object image. - // - image_type& - image () - { - return image_; - } - - // Insert binding. - // - std::size_t - insert_image_version () const { return insert_image_version_;} - - void - insert_image_version (std::size_t v) {insert_image_version_ = v;} - - std::size_t - insert_id_binding_version () const { return insert_id_binding_version_;} - - void - insert_id_binding_version (std::size_t v) {insert_id_binding_version_ = v;} - - binding& - insert_image_binding () {return insert_image_binding_;} - - // Update binding. - // - std::size_t - update_image_version () const { return update_image_version_;} - - void - update_image_version (std::size_t v) {update_image_version_ = v;} - - std::size_t - update_id_binding_version () const { return update_id_binding_version_;} - - void - update_id_binding_version (std::size_t v) {update_id_binding_version_ = v;} - - binding& - update_image_binding () {return update_image_binding_;} - - // Select binding. - // - std::size_t* - select_image_versions () { return select_image_versions_;} - - binding* - select_image_bindings () {return select_image_bindings_;} - - binding& - select_image_binding (std::size_t d) - { - return select_image_bindings_[object_traits::depth - d]; - } - - bool* - select_image_truncated () {return select_image_truncated_;} - - // Object id binding (comes from the root statements). - // - id_image_type& - id_image () {return root_statements_.id_image ();} - - std::size_t - id_image_version () const {return root_statements_.id_image_version ();} - - void - id_image_version (std::size_t v) {root_statements_.id_image_version (v);} - - binding& - id_image_binding () {return root_statements_.id_image_binding ();} - - binding& - optimistic_id_image_binding () { - return root_statements_.optimistic_id_image_binding ();} - - // Statements. - // - insert_statement_type& - persist_statement () - { - if (persist_ == 0) - persist_.reset ( - new (details::shared) insert_statement_type ( - conn_, - object_traits::persist_statement_name, - object_traits::persist_statement, - object_traits::versioned, // Process if versioned. - object_traits::persist_statement_types, - insert_column_count, - insert_image_binding_, - insert_image_native_binding_, - 0, - false)); - - return *persist_; - } - - select_statement_type& - find_statement (std::size_t d) - { - std::size_t i (object_traits::depth - d); - details::shared_ptr& p (find_[i]); - - if (p == 0) - p.reset ( - new (details::shared) select_statement_type ( - conn_, - object_traits::find_statement_names[i], - object_traits::find_statements[i], - object_traits::versioned, // Process if versioned. - false, // Don't optimize. - object_traits::find_statement_types, - id_column_count, - root_statements_.id_image_binding (), - root_statements_.id_image_native_binding (), - select_image_bindings_[i], - false)); - - return *p; - } - - update_statement_type& - update_statement () - { - if (update_ == 0) - update_.reset ( - new (details::shared) update_statement_type ( - conn_, - object_traits::update_statement_name, - object_traits::update_statement, - object_traits::versioned, // Process if versioned. - object_traits::update_statement_types, - update_column_count + id_column_count, - update_image_binding_, - update_image_native_binding_, - false)); - - return *update_; - } - - delete_statement_type& - erase_statement () - { - if (erase_ == 0) - erase_.reset ( - new (details::shared) delete_statement_type ( - conn_, - object_traits::erase_statement_name, - object_traits::erase_statement, - object_traits::find_statement_types, // The same as find (id). - id_column_count, - root_statements_.id_image_binding (), - root_statements_.id_image_native_binding (), - false)); - - return *erase_; - } - - // Extra (container, section) statement cache. - // - extra_statement_cache_type& - extra_statement_cache () - { - return extra_statement_cache_.get ( - conn_, - image_, - id_image (), - id_image_binding (), - &id_image_binding (), // Note, not id+version. - root_statements_.id_image_native_binding (), - object_traits::find_statement_types); - } - - public: - // select = total - id - separate_load + base::select - // insert = total - inverse - // update = total - inverse - id - readonly - separate_update - // - static const std::size_t id_column_count = - object_traits::id_column_count; - - static const std::size_t select_column_count = - object_traits::column_count - - id_column_count - - object_traits::separate_load_column_count + - base_statements_type::select_column_count; - - static const std::size_t insert_column_count = - object_traits::column_count - - object_traits::inverse_column_count; - - static const std::size_t update_column_count = - insert_column_count - - object_traits::id_column_count - - object_traits::readonly_column_count - - object_traits::separate_update_column_count; - - private: - polymorphic_derived_object_statements ( - const polymorphic_derived_object_statements&); - - polymorphic_derived_object_statements& - operator= (const polymorphic_derived_object_statements&); - - private: - root_statements_type& root_statements_; - base_statements_type& base_statements_; - - extra_statement_cache_ptr extra_statement_cache_; - - image_type image_; - - // Select binding. Here we are have an array of statements/bindings - // one for each depth. In other words, if we have classes root, base, - // and derived, then we have the following array of statements: - // - // [0] d + b + r - // [1] d + b - // [2] d - // - // Also, because we have a chain of images bound to these statements, - // we have an array of versions, one entry for each base plus one for - // our own image. - // - // A poly-abstract class only needs the first statement and in this - // case we have only one entry in the the bindings and statements - // arrays (but not versions; we still have a chain of images). - // - std::size_t select_image_versions_[object_traits::depth]; - binding select_image_bindings_[ - object_traits::abstract ? 1 : object_traits::depth]; - bind select_image_bind_[select_column_count]; - bool select_image_truncated_[select_column_count]; - - // Insert binding. The id binding is copied from the hierarchy root. - // - std::size_t insert_image_version_; - std::size_t insert_id_binding_version_; - binding insert_image_binding_; - bind insert_image_bind_[insert_column_count]; - native_binding insert_image_native_binding_; - char* insert_image_values_[insert_column_count]; - int insert_image_lengths_[insert_column_count]; - int insert_image_formats_[insert_column_count]; - - // Update binding. The id suffix binding is copied from the hierarchy - // root. - // - std::size_t update_image_version_; - std::size_t update_id_binding_version_; - binding update_image_binding_; - bind update_image_bind_[update_column_count + id_column_count]; - native_binding update_image_native_binding_; - char* update_image_values_[update_column_count + id_column_count]; - int update_image_lengths_[update_column_count + id_column_count]; - int update_image_formats_[update_column_count + id_column_count]; - - details::shared_ptr persist_; - details::shared_ptr find_[ - object_traits::abstract ? 1 : object_traits::depth]; - details::shared_ptr update_; - details::shared_ptr erase_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_POLYMORPHIC_OBJECT_STATEMENTS_HXX diff --git a/odb/pgsql/polymorphic-object-statements.txx b/odb/pgsql/polymorphic-object-statements.txx deleted file mode 100644 index 8472fca..0000000 --- a/odb/pgsql/polymorphic-object-statements.txx +++ /dev/null @@ -1,158 +0,0 @@ -// file : odb/pgsql/polymorphic-object-statements.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // std::memset - -#include -#include - -#include -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - // - // polymorphic_root_object_statements - // - - template - polymorphic_root_object_statements:: - ~polymorphic_root_object_statements () - { - } - - template - polymorphic_root_object_statements:: - polymorphic_root_object_statements (connection_type& conn) - : object_statements (conn), - discriminator_image_binding_ (discriminator_image_bind_, - discriminator_column_count + - managed_optimistic_column_count), - discriminator_id_image_binding_ (discriminator_id_image_bind_, - id_column_count), - discriminator_id_image_native_binding_ ( - discriminator_id_image_values_, - discriminator_id_image_lengths_, - discriminator_id_image_formats_, - id_column_count) - { - discriminator_image_.version = 0; - discriminator_id_image_.version = 0; - - discriminator_image_version_ = 0; - discriminator_id_image_version_ = 0; - - std::memset (discriminator_image_bind_, - 0, - sizeof (discriminator_image_bind_)); - std::memset (discriminator_id_image_bind_, - 0, - sizeof (discriminator_id_image_bind_)); - std::memset (discriminator_image_truncated_, - 0, - sizeof (discriminator_image_truncated_)); - - for (std::size_t i (0); - i < discriminator_column_count + managed_optimistic_column_count; - ++i) - { - discriminator_image_bind_[i].truncated = - discriminator_image_truncated_ + i; - } - } - - // - // polymorphic_derived_object_statements - // - - template - polymorphic_derived_object_statements:: - ~polymorphic_derived_object_statements () - { - } - - template - polymorphic_derived_object_statements:: - polymorphic_derived_object_statements (connection_type& conn) - : statements_base (conn), - root_statements_ (conn.statement_cache ().find_object ()), - base_statements_ (conn.statement_cache ().find_object ()), - insert_image_binding_ (insert_image_bind_, insert_column_count), - insert_image_native_binding_ (insert_image_values_, - insert_image_lengths_, - insert_image_formats_, - insert_column_count), - update_image_binding_ (update_image_bind_, - update_column_count + id_column_count), - update_image_native_binding_ (update_image_values_, - update_image_lengths_, - update_image_formats_, - update_column_count + id_column_count) - { - image_.base = &base_statements_.image (); - image_.version = 0; - - for (std::size_t i (0); i < object_traits::depth; ++i) - select_image_versions_[i] = 0; - - for (std::size_t i (0); - i < (object_traits::abstract ? 1 : object_traits::depth); - ++i) - { - select_image_bindings_[i].bind = select_image_bind_; - select_image_bindings_[i].count = object_traits::find_column_counts[i]; - } - - insert_image_version_ = 0; - insert_id_binding_version_ = 0; - update_image_version_ = 0; - update_id_binding_version_ = 0; - - std::memset (insert_image_bind_, 0, sizeof (insert_image_bind_)); - std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); - std::memset (select_image_bind_, 0, sizeof (select_image_bind_)); - std::memset ( - select_image_truncated_, 0, sizeof (select_image_truncated_)); - - for (std::size_t i (0); i < select_column_count; ++i) - select_image_bind_[i].truncated = select_image_truncated_ + i; - } - - template - void polymorphic_derived_object_statements:: - delayed_loader (odb::database& db, - const id_type& id, - root_type& robj, - const schema_version_migration* svm) - { - connection_type& conn (transaction::current ().connection (db)); - polymorphic_derived_object_statements& sts ( - conn.statement_cache ().find_object ()); - root_statements_type& rsts (sts.root_statements ()); - - object_type& obj (static_cast (robj)); - - // The same code as in object_statements::load_delayed_(). - // - object_traits_calls tc (svm); - - if (!tc.find_ (sts, &id)) - throw object_not_persistent (); - - object_traits::callback (db, obj, callback_event::pre_load); - tc.init (obj, sts.image (), &db); - tc.load_ (sts, obj, false); // Load containers, etc. - - rsts.load_delayed (svm); - - { - typename root_statements_type::auto_unlock u (rsts); - object_traits::callback (db, obj, callback_event::post_load); - } - } - } -} diff --git a/odb/pgsql/prepared-query.cxx b/odb/pgsql/prepared-query.cxx deleted file mode 100644 index a6d783c..0000000 --- a/odb/pgsql/prepared-query.cxx +++ /dev/null @@ -1,15 +0,0 @@ -// file : odb/pgsql/prepared-query.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -namespace odb -{ - namespace pgsql - { - prepared_query_impl:: - ~prepared_query_impl () - { - } - } -} diff --git a/odb/pgsql/prepared-query.hxx b/odb/pgsql/prepared-query.hxx deleted file mode 100644 index 3622226..0000000 --- a/odb/pgsql/prepared-query.hxx +++ /dev/null @@ -1,34 +0,0 @@ -// file : odb/pgsql/prepared-query.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_PREPARED_QUERY_HXX -#define ODB_PGSQL_PREPARED_QUERY_HXX - -#include - -#include - -#include -#include - -#include - -namespace odb -{ - namespace pgsql - { - struct LIBODB_PGSQL_EXPORT prepared_query_impl: odb::prepared_query_impl - { - virtual - ~prepared_query_impl (); - - prepared_query_impl (odb::connection& c): odb::prepared_query_impl (c) {} - - pgsql::query_base query; - }; - } -} - -#include - -#endif // ODB_PGSQL_PREPARED_QUERY_HXX diff --git a/odb/pgsql/query-const-expr.cxx b/odb/pgsql/query-const-expr.cxx deleted file mode 100644 index c910620..0000000 --- a/odb/pgsql/query-const-expr.cxx +++ /dev/null @@ -1,14 +0,0 @@ -// file : odb/pgsql/query-const-expr.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -namespace odb -{ - namespace pgsql - { - // Sun CC cannot handle this in query.cxx. - // - const query_base query_base::true_expr (true); - } -} diff --git a/odb/pgsql/query-dynamic.cxx b/odb/pgsql/query-dynamic.cxx deleted file mode 100644 index ebd62de..0000000 --- a/odb/pgsql/query-dynamic.cxx +++ /dev/null @@ -1,157 +0,0 @@ -// file : odb/pgsql/query-dynamic.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // std::size_t - -#include - -using namespace std; - -namespace odb -{ - namespace pgsql - { - static const char* logic_operators[] = {") AND (", ") OR ("}; - static const char* comp_operators[] = {"=", "!=", "<", ">", "<=", ">="}; - - static void - translate (query_base& q, const odb::query_base& s, size_t p) - { - typedef odb::query_base::clause_part part; - - const part& x (s.clause ()[p]); - - switch (x.kind) - { - case part::kind_column: - { - const query_column_base* c ( - static_cast ( - x.native_info[id_pgsql].column)); - - q.append (c->table (), c->column ()); - break; - } - case part::kind_param_val: - case part::kind_param_ref: - { - const query_column_base* c ( - static_cast ( - x.native_info[id_pgsql].column)); - - query_param_factory f ( - reinterpret_cast ( - x.native_info[id_pgsql].param_factory)); - - const odb::query_param* p ( - reinterpret_cast (x.data)); - - q.append (f (p->value, x.kind == part::kind_param_ref), - c->conversion ()); - break; - } - case part::kind_native: - { - q.append (s.strings ()[x.data]); - break; - } - case part::kind_true: - case part::kind_false: - { - q.append (x.kind == part::kind_true); - break; - } - case part::op_add: - { - translate (q, s, x.data); - translate (q, s, p - 1); - break; - } - case part::op_and: - case part::op_or: - { - q += "("; - translate (q, s, x.data); - q += logic_operators[x.kind - part::op_and]; - translate (q, s, p - 1); - q += ")"; - break; - } - case part::op_not: - { - q += "NOT ("; - translate (q, s, p - 1); - q += ")"; - break; - } - case part::op_null: - case part::op_not_null: - { - translate (q, s, p - 1); - q += (x.kind == part::op_null ? "IS NULL" : "IS NOT NULL"); - break; - } - case part::op_in: - { - if (x.data != 0) - { - size_t b (p - x.data); - - translate (q, s, b - 1); // column - q += "IN ("; - - for (size_t i (b); i != p; ++i) - { - if (i != b) - q += ","; - - translate (q, s, i); - } - - q += ")"; - } - else - q.append (false); - - break; - } - case part::op_like: - { - translate (q, s, p - 2); // column - q += "LIKE"; - translate (q, s, p - 1); // pattern - break; - } - case part::op_like_escape: - { - translate (q, s, p - 3); // column - q += "LIKE"; - translate (q, s, p - 2); // pattern - q += "ESCAPE"; - translate (q, s, p - 1); // escape - break; - } - case part::op_eq: - case part::op_ne: - case part::op_lt: - case part::op_gt: - case part::op_le: - case part::op_ge: - { - translate (q, s, x.data); - q += comp_operators[x.kind - part::op_eq]; - translate (q, s, p - 1); - break; - } - } - } - - query_base:: - query_base (const odb::query_base& q) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - if (!q.empty ()) - translate (*this, q, q.clause ().size () - 1); - } - } -} diff --git a/odb/pgsql/query-dynamic.hxx b/odb/pgsql/query-dynamic.hxx deleted file mode 100644 index df87519..0000000 --- a/odb/pgsql/query-dynamic.hxx +++ /dev/null @@ -1,32 +0,0 @@ -// file : odb/pgsql/query-dynamic.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_QUERY_DYNAMIC_HXX -#define ODB_PGSQL_QUERY_DYNAMIC_HXX - -#include - -#include -#include - -#include - -namespace odb -{ - namespace pgsql - { - typedef details::shared_ptr (*query_param_factory) ( - const void* val, bool by_ref); - - template - details::shared_ptr - query_param_factory_impl (const void*, bool); - } -} - -#include -#include - -#include - -#endif // ODB_PGSQL_QUERY_DYNAMIC_HXX diff --git a/odb/pgsql/query-dynamic.ixx b/odb/pgsql/query-dynamic.ixx deleted file mode 100644 index 016d213..0000000 --- a/odb/pgsql/query-dynamic.ixx +++ /dev/null @@ -1,26 +0,0 @@ -// file : odb/pgsql/query-dynamic.ixx -// license : GNU GPL v2; see accompanying LICENSE file - -namespace odb -{ - namespace pgsql - { - // - // - template - inline query_column:: - query_column (odb::query_column& qc, - const char* table, const char* column, const char* conv) - : query_column_base (table, column, conv) - { - native_column_info& ci (qc.native_info[id_pgsql]); - ci.column = static_cast (this); - - // For some reason GCC needs this statically-typed pointer in - // order to instantiate the functions. - // - query_param_factory f (&query_param_factory_impl); - ci.param_factory = reinterpret_cast (f); - } - } -} diff --git a/odb/pgsql/query-dynamic.txx b/odb/pgsql/query-dynamic.txx deleted file mode 100644 index 7cfaf63..0000000 --- a/odb/pgsql/query-dynamic.txx +++ /dev/null @@ -1,20 +0,0 @@ -// file : odb/pgsql/query-dynamic.txx -// license : GNU GPL v2; see accompanying LICENSE file - -namespace odb -{ - namespace pgsql - { - template - details::shared_ptr - query_param_factory_impl (const void* val, bool by_ref) - { - const T& v (*static_cast (val)); - - return details::shared_ptr ( - by_ref - ? new (details::shared) query_param_impl (ref_bind (v)) - : new (details::shared) query_param_impl (val_bind (v))); - } - } -} diff --git a/odb/pgsql/query.cxx b/odb/pgsql/query.cxx deleted file mode 100644 index b096c97..0000000 --- a/odb/pgsql/query.cxx +++ /dev/null @@ -1,444 +0,0 @@ -// file : odb/pgsql/query.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // std::size_t -#include // std::memset -#include -#include - -#include -#include - -using namespace std; - -namespace odb -{ - namespace pgsql - { - // query_param - // - query_param:: - ~query_param () - { - } - - // query_base - // - query_base:: - query_base (const query_base& q) - : clause_ (q.clause_), - parameters_ (q.parameters_), - bind_ (q.bind_), - binding_ (0, 0), - values_ (q.values_), - lengths_ (q.lengths_), - formats_ (q.formats_), - types_ (q.types_), - native_binding_ (0, 0, 0, 0) - { - // Here and below we want to maintain up to date binding info so - // that the call to parameters_binding() below is an immutable - // operation, provided the query does not have any by-reference - // parameters. This way a by-value-only query can be shared - // between multiple threads without the need for synchronization. - // - if (size_t n = bind_.size ()) - { - binding_.bind = &bind_[0]; - binding_.count = n; - binding_.version++; - - native_binding_.values = &values_[0]; - native_binding_.lengths = &lengths_[0]; - native_binding_.formats = &formats_[0]; - native_binding_.count = n; - - assert (values_.size () == n); - assert (lengths_.size () == n); - assert (formats_.size () == n); - assert (types_.size () == n); - - statement::bind_param (native_binding_, binding_); - } - } - - query_base& query_base:: - operator= (const query_base& q) - { - if (this != &q) - { - clause_ = q.clause_; - parameters_ = q.parameters_; - bind_ = q.bind_; - - size_t n (bind_.size ()); - - binding_.count = n; - binding_.version++; - - values_ = q.values_; - lengths_ = q.lengths_; - formats_ = q.formats_; - types_ = q.types_; - - native_binding_.count = n; - - assert (values_.size () == n); - assert (lengths_.size () == n); - assert (formats_.size () == n); - assert (types_.size () == n); - - if (n != 0) - { - binding_.bind = &bind_[0]; - - native_binding_.values = &values_[0]; - native_binding_.lengths = &lengths_[0]; - native_binding_.formats = &formats_[0]; - - statement::bind_param (native_binding_, binding_); - } - } - - return *this; - } - - query_base& query_base:: - operator+= (const query_base& q) - { - clause_.insert (clause_.end (), q.clause_.begin (), q.clause_.end ()); - - size_t n (bind_.size ()); - - parameters_.insert ( - parameters_.end (), q.parameters_.begin (), q.parameters_.end ()); - - bind_.insert ( - bind_.end (), q.bind_.begin (), q.bind_.end ()); - - values_.insert ( - values_.end (), q.values_.begin (), q.values_.end ()); - - lengths_.insert ( - lengths_.end (), q.lengths_.begin (), q.lengths_.end ()); - - formats_.insert ( - formats_.end (), q.formats_.begin (), q.formats_.end ()); - - types_.insert ( - types_.end (), q.types_.begin (), q.types_.end ()); - - if (n != bind_.size ()) - { - n = bind_.size (); - - binding_.bind = &bind_[0]; - binding_.count = n; - binding_.version++; - - assert (values_.size () == n); - assert (lengths_.size () == n); - assert (formats_.size () == n); - assert (types_.size () == n); - - native_binding_.values = &values_[0]; - native_binding_.lengths = &lengths_[0]; - native_binding_.formats = &formats_[0]; - native_binding_.count = n; - - statement::bind_param (native_binding_, binding_); - } - - return *this; - } - - void query_base:: - append (const string& q) - { - if (!clause_.empty () && - clause_.back ().kind == clause_part::kind_native) - { - string& s (clause_.back ().part); - - char first (!q.empty () ? q[0] : ' '); - char last (!s.empty () ? s[s.size () - 1] : ' '); - - // We don't want extra spaces after '(' as well as before ',' - // and ')'. - // - if (last != ' ' && last != '\n' && last != '(' && - first != ' ' && first != '\n' && first != ',' && first != ')') - s += ' '; - - s += q; - } - else - clause_.push_back (clause_part (clause_part::kind_native, q)); - } - - void query_base:: - append (const char* table, const char* column) - { - string s (table); - s += '.'; - s += column; - - clause_.push_back (clause_part (clause_part::kind_column, s)); - } - - void query_base:: - append (details::shared_ptr p, const char* conv) - { - clause_.push_back (clause_part (clause_part::kind_param)); - - if (conv != 0) - clause_.back ().part = conv; - - parameters_.push_back (p); - bind_.push_back (bind ()); - binding_.bind = &bind_[0]; - binding_.count = bind_.size (); - binding_.version++; - - bind* b (&bind_.back ()); - memset (b, 0, sizeof (bind)); - p->bind (b); - - values_.push_back (0); - lengths_.push_back (0); - formats_.push_back (0); - native_binding_.values = &values_[0]; - native_binding_.lengths = &lengths_[0]; - native_binding_.formats = &formats_[0]; - - // native_binding_.count should always equal binding_.count. - // At this point, we know that we have added one element to - // each array, so there is no need to check. - // - native_binding_.count = binding_.count; - - types_.push_back (p->oid ()); - - statement::bind_param (native_binding_, binding_); - } - - void query_base:: - init_parameters () const - { - bool ref (false), inc_ver (false); - - for (size_t i (0); i < parameters_.size (); ++i) - { - query_param& p (*parameters_[i]); - - if (p.reference ()) - { - ref = true; - - if (p.init ()) - { - p.bind (&bind_[i]); - inc_ver = true; - } - } - } - - if (ref) - { - statement::bind_param (native_binding_, binding_); - - if (inc_ver) - binding_.version++; - } - } - - static bool - check_prefix (const string& s) - { - string::size_type n; - - // It is easier to compare to upper and lower-case versions - // rather than getting involved with the portable case- - // insensitive string comparison mess. - // - if (s.compare (0, (n = 5), "WHERE") == 0 || - s.compare (0, (n = 5), "where") == 0 || - s.compare (0, (n = 6), "SELECT") == 0 || - s.compare (0, (n = 6), "select") == 0 || - s.compare (0, (n = 8), "ORDER BY") == 0 || - s.compare (0, (n = 8), "order by") == 0 || - s.compare (0, (n = 8), "GROUP BY") == 0 || - s.compare (0, (n = 8), "group by") == 0 || - s.compare (0, (n = 6), "HAVING") == 0 || - s.compare (0, (n = 6), "having") == 0 || - s.compare (0, (n = 4), "WITH") == 0 || - s.compare (0, (n = 4), "with") == 0) - { - // It either has to be an exact match, or there should be - // a whitespace following the keyword. - // - if (s.size () == n || s[n] == ' ' || s[n] == '\n' || s[n] =='\t') - return true; - } - - return false; - } - - void query_base:: - optimize () - { - // Remove a single TRUE literal or one that is followe by one of - // the other clauses. This avoids useless WHERE clauses like - // - // WHERE TRUE GROUP BY foo - // - clause_type::iterator i (clause_.begin ()), e (clause_.end ()); - - if (i != e && i->kind == clause_part::kind_bool && i->bool_part) - { - clause_type::iterator j (i + 1); - - if (j == e || - (j->kind == clause_part::kind_native && check_prefix (j->part))) - clause_.erase (i); - } - } - - const char* query_base:: - clause_prefix () const - { - if (!clause_.empty ()) - { - const clause_part& p (clause_.front ()); - - if (p.kind == clause_part::kind_native && check_prefix (p.part)) - return ""; - - return "WHERE "; - } - - return ""; - } - - string query_base:: - clause () const - { - string r; - size_t param (1); - - for (clause_type::const_iterator i (clause_.begin ()), - end (clause_.end ()); - i != end; - ++i) - { - char last (!r.empty () ? r[r.size () - 1] : ' '); - - switch (i->kind) - { - case clause_part::kind_column: - { - if (last != ' ' && last != '\n' && last != '(') - r += ' '; - - r += i->part; - break; - } - case clause_part::kind_param: - { - if (last != ' ' && last != '\n' && last != '(') - r += ' '; - - ostringstream os; - os << param++; - - // Add the conversion expression, if any. - // - string::size_type p (0); - if (!i->part.empty ()) - { - p = i->part.find ("(?)"); - r.append (i->part, 0, p); - } - - r += '$'; - r += os.str (); - - if (!i->part.empty ()) - r.append (i->part, p + 3, string::npos); - - break; - } - case clause_part::kind_native: - { - // We don't want extra spaces after '(' as well as before ',' - // and ')'. - // - const string& p (i->part); - char first (!p.empty () ? p[0] : ' '); - - if (last != ' ' && last != '\n' && last != '(' && - first != ' ' && first != '\n' && first != ',' && first != ')') - r += ' '; - - r += p; - break; - } - case clause_part::kind_bool: - { - if (last != ' ' && last != '\n' && last != '(') - r += ' '; - - r += i->bool_part ? "TRUE" : "FALSE"; - break; - } - } - } - - return clause_prefix () + r; - } - - query_base - operator&& (const query_base& x, const query_base& y) - { - // Optimize cases where one or both sides are constant truth. - // - bool xt (x.const_true ()), yt (y.const_true ()); - - if (xt && yt) - return x; - - if (xt) - return y; - - if (yt) - return x; - - query_base r ("("); - r += x; - r += ") AND ("; - r += y; - r += ")"; - return r; - } - - query_base - operator|| (const query_base& x, const query_base& y) - { - query_base r ("("); - r += x; - r += ") OR ("; - r += y; - r += ")"; - return r; - } - - query_base - operator! (const query_base& x) - { - query_base r ("NOT ("); - r += x; - r += ")"; - return r; - } - } -} diff --git a/odb/pgsql/query.hxx b/odb/pgsql/query.hxx deleted file mode 100644 index 42182d6..0000000 --- a/odb/pgsql/query.hxx +++ /dev/null @@ -1,2181 +0,0 @@ -// file : odb/pgsql/query.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_QUERY_HXX -#define ODB_PGSQL_QUERY_HXX - -#include - -#include -#include -#include // std::size_t - -#include // odb::query_column -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -namespace odb -{ - namespace pgsql - { - template - struct val_bind - { - typedef const T& type; - - explicit - val_bind (type v): val (v) {} - - type val; - }; - - template - struct val_bind - { - typedef const T* type; - - explicit - val_bind (type v): val (v) {} - - type val; - }; - - template - struct ref_bind - { - typedef const T& type; - - explicit - ref_bind (type r): ref (r) {} - - const void* - ptr () const {return &ref;} - - type ref; - }; - - template - struct ref_bind - { - typedef const T* type; - - explicit - ref_bind (type r): ref (r) {} - - // Allow implicit conversion from decayed ref_bind's. - // - ref_bind (ref_bind r): ref (r.ref) {} - ref_bind (ref_bind r): ref (r.ref) {} - - const void* - ptr () const {return ref;} - - type ref; - }; - - template - struct val_bind_typed: val_bind - { - explicit - val_bind_typed (typename val_bind::type v): val_bind (v) {} - }; - - template - struct ref_bind_typed: ref_bind - { - explicit - ref_bind_typed (typename ref_bind::type r): ref_bind (r) {} - }; - - struct LIBODB_PGSQL_EXPORT query_param: details::shared_base - { - typedef pgsql::bind bind_type; - - virtual - ~query_param (); - - bool - reference () const - { - return value_ != 0; - } - - virtual bool - init () = 0; - - virtual void - bind (bind_type*) = 0; - - virtual unsigned int - oid () const = 0; - - protected: - query_param (const void* value) - : value_ (value) - { - } - - protected: - const void* value_; - }; - - // - // - template - struct query_column; - - class LIBODB_PGSQL_EXPORT query_base - { - public: - struct clause_part - { - enum kind_type - { - kind_column, - kind_param, - kind_native, - kind_bool - }; - - clause_part (kind_type k): kind (k), bool_part (false) {} - clause_part (kind_type k, const std::string& p) - : kind (k), part (p), bool_part (false) {} - clause_part (bool p): kind (kind_bool), bool_part (p) {} - - kind_type kind; - std::string part; // If kind is param, then part is conversion expr. - bool bool_part; - }; - - query_base () - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - } - - // True or false literal. - // - explicit - query_base (bool v) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - append (v); - } - - explicit - query_base (const char* native) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - clause_.push_back (clause_part (clause_part::kind_native, native)); - } - - explicit - query_base (const std::string& native) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - clause_.push_back (clause_part (clause_part::kind_native, native)); - } - - query_base (const char* table, const char* column) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - append (table, column); - } - - template - explicit - query_base (val_bind v) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - *this += v; - } - - template - explicit - query_base (val_bind_typed v) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - *this += v; - } - - template - explicit - query_base (ref_bind r) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - *this += r; - } - - template - explicit - query_base (ref_bind_typed r) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - *this += r; - } - - template - query_base (const query_column&); - - // Translate common query representation to PostgreSQL native. Defined - // in query-dynamic.cxx - // - query_base (const odb::query_base&); - - // Copy c-tor and assignment. - // - query_base (const query_base&); - - query_base& - operator= (const query_base&); - - public: - std::string - clause () const; - - const char* - clause_prefix () const; - - // Initialize the by-reference parameters from bound variables. - // - void - init_parameters () const; - - native_binding& - parameters_binding () const; - - const unsigned int* - parameter_types () const - { - return types_.empty () ? 0 : &types_[0]; - } - - std::size_t - parameter_count () const - { - return parameters_.size (); - } - - public: - bool - empty () const - { - return clause_.empty (); - } - - static const query_base true_expr; - - bool - const_true () const - { - return clause_.size () == 1 && - clause_.front ().kind == clause_part::kind_bool && - clause_.front ().bool_part; - } - - void - optimize (); - - public: - template - static val_bind - _val (const T& x) - { - return val_bind (x); - } - - template - static val_bind_typed - _val (const T& x) - { - return val_bind_typed (x); - } - - template - static ref_bind - _ref (const T& x) - { - return ref_bind (x); - } - - template - static ref_bind_typed - _ref (const T& x) - { - return ref_bind_typed (x); - } - - // Some compilers (notably VC++), when deducing const T& from const - // array do not strip const from the array type. As a result, in the - // above signatures we get, for example, T = const char[4] instead - // of T = char[4], which is what we want. So to "fix" such compilers, - // we will have to provide the following specializations of the above - // functions. - // - template - static val_bind - _val (const T (&x) [N]) - { - return val_bind (x); - } - - template - static val_bind_typed - _val (const T (&x) [N]) - { - return val_bind_typed (x); - } - - template - static ref_bind - _ref (const T (&x) [N]) - { - return ref_bind (x); - } - - template - static ref_bind_typed - _ref (const T (&x) [N]) - { - return ref_bind_typed (x); - } - - public: - query_base& - operator+= (const query_base&); - - query_base& - operator+= (const std::string& q) - { - append (q); - return *this; - } - - template - query_base& - operator+= (val_bind v) - { - append::db_type_id> ( - v, details::conversion::to ()); - return *this; - } - - template - query_base& - operator+= (val_bind_typed v) - { - // We are not using default type_traits so no default conversion - // either. - // - append (v, 0); - return *this; - } - - template - query_base& - operator+= (ref_bind r) - { - append::db_type_id> ( - r, details::conversion::to ()); - return *this; - } - - template - query_base& - operator+= (ref_bind_typed r) - { - // We are not using default type_traits so no default conversion - // either. - // - append (r, 0); - return *this; - } - - // Implementation details. - // - public: - template - void - append (val_bind, const char* conv); - - template - void - append (ref_bind, const char* conv); - - void - append (details::shared_ptr, const char* conv); - - void - append (bool v) - { - clause_.push_back (clause_part (v)); - } - - void - append (const std::string& native); - - void - append (const char* native) // Clashes with append(bool). - { - append (std::string (native)); - } - - void - append (const char* table, const char* column); - - private: - typedef std::vector clause_type; - typedef std::vector > parameters_type; - - clause_type clause_; - parameters_type parameters_; - - mutable std::vector bind_; - mutable binding binding_; - - std::vector values_; - std::vector lengths_; - std::vector formats_; - std::vector types_; - mutable native_binding native_binding_; - }; - - inline query_base - operator+ (const query_base& x, const query_base& y) - { - query_base r (x); - r += y; - return r; - } - - template - inline query_base - operator+ (const query_base& q, val_bind b) - { - query_base r (q); - r += b; - return r; - } - - template - inline query_base - operator+ (val_bind b, const query_base& q) - { - query_base r; - r += b; - r += q; - return r; - } - - template - inline query_base - operator+ (const query_base& q, val_bind_typed b) - { - query_base r (q); - r += b; - return r; - } - - template - inline query_base - operator+ (val_bind_typed b, const query_base& q) - { - query_base r; - r += b; - r += q; - return r; - } - - template - inline query_base - operator+ (const query_base& q, ref_bind b) - { - query_base r (q); - r += b; - return r; - } - - template - inline query_base - operator+ (ref_bind b, const query_base& q) - { - query_base r; - r += b; - r += q; - return r; - } - - template - inline query_base - operator+ (const query_base& q, ref_bind_typed b) - { - query_base r (q); - r += b; - return r; - } - - template - inline query_base - operator+ (ref_bind_typed b, const query_base& q) - { - query_base r; - r += b; - r += q; - return r; - } - - inline query_base - operator+ (const query_base& q, const std::string& s) - { - query_base r (q); - r += s; - return r; - } - - inline query_base - operator+ (const std::string& s, const query_base& q) - { - query_base r (s); - r += q; - return r; - } - - template - inline query_base - operator+ (const std::string& s, val_bind b) - { - query_base r (s); - r += b; - return r; - } - - template - inline query_base - operator+ (val_bind b, const std::string& s) - { - query_base r; - r += b; - r += s; - return r; - } - - template - inline query_base - operator+ (const std::string& s, val_bind_typed b) - { - query_base r (s); - r += b; - return r; - } - - template - inline query_base - operator+ (val_bind_typed b, const std::string& s) - { - query_base r; - r += b; - r += s; - return r; - } - - template - inline query_base - operator+ (const std::string& s, ref_bind b) - { - query_base r (s); - r += b; - return r; - } - - template - inline query_base - operator+ (ref_bind b, const std::string& s) - { - query_base r; - r += b; - r += s; - return r; - } - - template - inline query_base - operator+ (const std::string& s, ref_bind_typed b) - { - query_base r (s); - r += b; - return r; - } - - template - inline query_base - operator+ (ref_bind_typed b, const std::string& s) - { - query_base r; - r += b; - r += s; - return r; - } - - LIBODB_PGSQL_EXPORT query_base - operator&& (const query_base&, const query_base&); - - LIBODB_PGSQL_EXPORT query_base - operator|| (const query_base&, const query_base&); - - LIBODB_PGSQL_EXPORT query_base - operator! (const query_base&); - - // query_column - // - struct query_column_base - { - // Note that we keep shallow copies of the table, column, and conversion - // expression. The latter can be NULL. - // - query_column_base (const char* table, - const char* column, - const char* conv) - : table_ (table), column_ (column), conversion_ (conv) - { - } - - const char* - table () const - { - return table_; - } - - const char* - column () const - { - return column_; - } - - // Can be NULL. - // - const char* - conversion () const - { - return conversion_; - } - - protected: - const char* table_; - const char* column_; - const char* conversion_; - }; - - template - struct query_column: query_column_base - { - typedef typename decay_traits::type decayed_type; - - // Note that we keep shallow copies of the table, column, and conversion - // expression. The latter can be NULL. - // - query_column (const char* table, const char* column, const char* conv) - : query_column_base (table, column, conv) {} - - // Implementation is in query-dynamic.ixx. - // - query_column (odb::query_column&, - const char* table, const char* column, const char* conv); - - // is_null, is_not_null - // - public: - query_base - is_null () const - { - query_base q (table_, column_); - q += "IS NULL"; - return q; - } - - query_base - is_not_null () const - { - query_base q (table_, column_); - q += "IS NOT NULL"; - return q; - } - - // in - // - public: - query_base - in (decayed_type, decayed_type) const; - - query_base - in (decayed_type, decayed_type, decayed_type) const; - - query_base - in (decayed_type, decayed_type, decayed_type, decayed_type) const; - - query_base - in (decayed_type, decayed_type, decayed_type, decayed_type, - decayed_type) const; - - template - query_base - in_range (I begin, I end) const; - - // like - // - public: - query_base - like (decayed_type pattern) const - { - return like (val_bind (pattern)); - } - - query_base - like (val_bind pattern) const; - - template - query_base - like (val_bind pattern) const - { - return like (val_bind (decayed_type (pattern.val))); - } - - query_base - like (ref_bind pattern) const; - - query_base - like (decayed_type pattern, decayed_type escape) const - { - return like (val_bind (pattern), escape); - } - - query_base - like (val_bind pattern, decayed_type escape) const; - - template - query_base - like (val_bind pattern, decayed_type escape) const - { - return like (val_bind (decayed_type (pattern.val)), escape); - } - - query_base - like (ref_bind pattern, decayed_type escape) const; - - // = - // - public: - query_base - equal (decayed_type v) const - { - return equal (val_bind (v)); - } - - query_base - equal (val_bind v) const - { - query_base q (table_, column_); - q += "="; - q.append (v, conversion_); - return q; - } - - template - query_base - equal (val_bind v) const - { - return equal (val_bind (decayed_type (v.val))); - } - - query_base - equal (ref_bind r) const - { - query_base q (table_, column_); - q += "="; - q.append (r, conversion_); - return q; - } - - friend query_base - operator== (const query_column& c, decayed_type v) - { - return c.equal (v); - } - - friend query_base - operator== (decayed_type v, const query_column& c) - { - return c.equal (v); - } - - friend query_base - operator== (const query_column& c, val_bind v) - { - return c.equal (v); - } - - friend query_base - operator== (val_bind v, const query_column& c) - { - return c.equal (v); - } - - template - friend query_base - operator== (const query_column& c, val_bind v) - { - return c.equal (v); - } - - template - friend query_base - operator== (val_bind v, const query_column& c) - { - return c.equal (v); - } - - friend query_base - operator== (const query_column& c, ref_bind r) - { - return c.equal (r); - } - - friend query_base - operator== (ref_bind r, const query_column& c) - { - return c.equal (r); - } - - // != - // - public: - query_base - unequal (decayed_type v) const - { - return unequal (val_bind (v)); - } - - query_base - unequal (val_bind v) const - { - query_base q (table_, column_); - q += "!="; - q.append (v, conversion_); - return q; - } - - template - query_base - unequal (val_bind v) const - { - return unequal (val_bind (decayed_type (v.val))); - } - - query_base - unequal (ref_bind r) const - { - query_base q (table_, column_); - q += "!="; - q.append (r, conversion_); - return q; - } - - friend query_base - operator!= (const query_column& c, decayed_type v) - { - return c.unequal (v); - } - - friend query_base - operator!= (decayed_type v, const query_column& c) - { - return c.unequal (v); - } - - friend query_base - operator!= (const query_column& c, val_bind v) - { - return c.unequal (v); - } - - friend query_base - operator!= (val_bind v, const query_column& c) - { - return c.unequal (v); - } - - template - friend query_base - operator!= (const query_column& c, val_bind v) - { - return c.unequal (v); - } - - template - friend query_base - operator!= (val_bind v, const query_column& c) - { - return c.unequal (v); - } - - friend query_base - operator!= (const query_column& c, ref_bind r) - { - return c.unequal (r); - } - - friend query_base - operator!= (ref_bind r, const query_column& c) - { - return c.unequal (r); - } - - // < - // - public: - query_base - less (decayed_type v) const - { - return less (val_bind (v)); - } - - query_base - less (val_bind v) const - { - query_base q (table_, column_); - q += "<"; - q.append (v, conversion_); - return q; - } - - template - query_base - less (val_bind v) const - { - return less (val_bind (decayed_type (v.val))); - } - - query_base - less (ref_bind r) const - { - query_base q (table_, column_); - q += "<"; - q.append (r, conversion_); - return q; - } - - friend query_base - operator< (const query_column& c, decayed_type v) - { - return c.less (v); - } - - friend query_base - operator< (decayed_type v, const query_column& c) - { - return c.greater (v); - } - - friend query_base - operator< (const query_column& c, val_bind v) - { - return c.less (v); - } - - friend query_base - operator< (val_bind v, const query_column& c) - { - return c.greater (v); - } - - template - friend query_base - operator< (const query_column& c, val_bind v) - { - return c.less (v); - } - - template - friend query_base - operator< (val_bind v, const query_column& c) - { - return c.greater (v); - } - - friend query_base - operator< (const query_column& c, ref_bind r) - { - return c.less (r); - } - - friend query_base - operator< (ref_bind r, const query_column& c) - { - return c.greater (r); - } - - // > - // - public: - query_base - greater (decayed_type v) const - { - return greater (val_bind (v)); - } - - query_base - greater (val_bind v) const - { - query_base q (table_, column_); - q += ">"; - q.append (v, conversion_); - return q; - } - - template - query_base - greater (val_bind v) const - { - return greater (val_bind (decayed_type (v.val))); - } - - query_base - greater (ref_bind r) const - { - query_base q (table_, column_); - q += ">"; - q.append (r, conversion_); - return q; - } - - friend query_base - operator> (const query_column& c, decayed_type v) - { - return c.greater (v); - } - - friend query_base - operator> (decayed_type v, const query_column& c) - { - return c.less (v); - } - - friend query_base - operator> (const query_column& c, val_bind v) - { - return c.greater (v); - } - - friend query_base - operator> (val_bind v, const query_column& c) - { - return c.less (v); - } - - template - friend query_base - operator> (const query_column& c, val_bind v) - { - return c.greater (v); - } - - template - friend query_base - operator> (val_bind v, const query_column& c) - { - return c.less (v); - } - - friend query_base - operator> (const query_column& c, ref_bind r) - { - return c.greater (r); - } - - friend query_base - operator> (ref_bind r, const query_column& c) - { - return c.less (r); - } - - // <= - // - public: - query_base - less_equal (decayed_type v) const - { - return less_equal (val_bind (v)); - } - - query_base - less_equal (val_bind v) const - { - query_base q (table_, column_); - q += "<="; - q.append (v, conversion_); - return q; - } - - template - query_base - less_equal (val_bind v) const - { - return less_equal (val_bind (decayed_type (v.val)));; - } - - query_base - less_equal (ref_bind r) const - { - query_base q (table_, column_); - q += "<="; - q.append (r, conversion_); - return q; - } - - friend query_base - operator<= (const query_column& c, decayed_type v) - { - return c.less_equal (v); - } - - friend query_base - operator<= (decayed_type v, const query_column& c) - { - return c.greater_equal (v); - } - - friend query_base - operator<= (const query_column& c, val_bind v) - { - return c.less_equal (v); - } - - friend query_base - operator<= (val_bind v, const query_column& c) - { - return c.greater_equal (v); - } - - template - friend query_base - operator<= (const query_column& c, val_bind v) - { - return c.less_equal (v); - } - - template - friend query_base - operator<= (val_bind v, const query_column& c) - { - return c.greater_equal (v); - } - - friend query_base - operator<= (const query_column& c, ref_bind r) - { - return c.less_equal (r); - } - - friend query_base - operator<= (ref_bind r, const query_column& c) - { - return c.greater_equal (r); - } - - // >= - // - public: - query_base - greater_equal (decayed_type v) const - { - return greater_equal (val_bind (v)); - } - - query_base - greater_equal (val_bind v) const - { - query_base q (table_, column_); - q += ">="; - q.append (v, conversion_); - return q; - } - - template - query_base - greater_equal (val_bind v) const - { - return greater_equal (val_bind (decayed_type (v.val)));; - } - - query_base - greater_equal (ref_bind r) const - { - query_base q (table_, column_); - q += ">="; - q.append (r, conversion_); - return q; - } - - friend query_base - operator>= (const query_column& c, decayed_type v) - { - return c.greater_equal (v); - } - - friend query_base - operator>= (decayed_type v, const query_column& c) - { - return c.less_equal (v); - } - - friend query_base - operator>= (const query_column& c, val_bind v) - { - return c.greater_equal (v); - } - - friend query_base - operator>= (val_bind v, const query_column& c) - { - return c.less_equal (v); - } - - template - friend query_base - operator>= (const query_column& c, val_bind v) - { - return c.greater_equal (v); - } - - template - friend query_base - operator>= (val_bind v, const query_column& c) - { - return c.less_equal (v); - } - - friend query_base - operator>= (const query_column& c, ref_bind r) - { - return c.greater_equal (r); - } - - friend query_base - operator>= (ref_bind r, const query_column& c) - { - return c.less_equal (r); - } - - // Column comparison. - // - public: - template - query_base - operator== (const query_column& c) const - { - // We can compare columns only if we can compare their C++ types. - // - (void) (sizeof (decay_traits::instance () == - decay_traits::instance ())); - - query_base q (table_, column_); - q += "="; - q.append (c.table (), c.column ()); - return q; - } - - template - query_base - operator!= (const query_column& c) const - { - // We can compare columns only if we can compare their C++ types. - // - (void) (sizeof (decay_traits::instance () != - decay_traits::instance ())); - - query_base q (table_, column_); - q += "!="; - q.append (c.table (), c.column ()); - return q; - } - - template - query_base - operator< (const query_column& c) const - { - // We can compare columns only if we can compare their C++ types. - // - (void) (sizeof (decay_traits::instance () < - decay_traits::instance ())); - - query_base q (table_, column_); - q += "<"; - q.append (c.table (), c.column ()); - return q; - } - - template - query_base - operator> (const query_column& c) const - { - // We can compare columns only if we can compare their C++ types. - // - (void) (sizeof (decay_traits::instance () > - decay_traits::instance ())); - - query_base q (table_, column_); - q += ">"; - q.append (c.table (), c.column ()); - return q; - } - - template - query_base - operator<= (const query_column& c) const - { - // We can compare columns only if we can compare their C++ types. - // - (void) (sizeof (decay_traits::instance () <= - decay_traits::instance ())); - - query_base q (table_, column_); - q += "<="; - q.append (c.table (), c.column ()); - return q; - } - - template - query_base - operator>= (const query_column& c) const - { - // We can compare columns only if we can compare their C++ types. - // - (void) (sizeof (decay_traits::instance () >= - decay_traits::instance ())); - - query_base q (table_, column_); - q += ">="; - q.append (c.table (), c.column ()); - return q; - } - }; - - // Provide operator+() for using columns to construct native - // query fragments (e.g., ORDER BY). - // - template - inline query_base - operator+ (const query_column& c, const std::string& s) - { - query_base q (c.table (), c.column ()); - q += s; - return q; - } - - template - inline query_base - operator+ (const std::string& s, const query_column& c) - { - query_base q (s); - q.append (c.table (), c.column ()); - return q; - } - - template - inline query_base - operator+ (const query_column& c, const query_base& q) - { - query_base r (c.table (), c.column ()); - r += q; - return r; - } - - template - inline query_base - operator+ (const query_base& q, const query_column& c) - { - query_base r (q); - r.append (c.table (), c.column ()); - return r; - } - - // - // - template - struct query_param_impl; - - // BOOLEAN - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::boolean_; - b->buffer = &image_; - } - - virtual unsigned int - oid () const - { - return bool_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (image_, is_null, v); - } - - private: - bool image_; - }; - - // SMALLINT - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::smallint; - b->buffer = &image_; - } - - virtual unsigned int - oid () const - { - return int2_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (image_, is_null, v); - } - - private: - short image_; - }; - - // INTEGER - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::integer; - b->buffer = &image_; - } - - virtual unsigned int - oid () const - { - return int4_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (image_, is_null, v); - } - - private: - int image_; - }; - - // BIGINT - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::bigint; - b->buffer = &image_; - } - - virtual unsigned int - oid () const - { - return int8_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (image_, is_null, v); - } - - private: - long long image_; - }; - - // REAL - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::real; - b->buffer = &image_; - } - - virtual unsigned int - oid () const - { - return float4_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (image_, is_null, v); - } - - private: - float image_; - }; - - // DOUBLE - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::double_; - b->buffer = &image_; - } - - virtual unsigned int - oid () const - { - return float8_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (image_, is_null, v); - } - - private: - double image_; - }; - - // NUMERIC - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - return init (*static_cast (value_)); - } - - virtual void - bind (bind_type* b) - { - b->type = bind::numeric; - b->buffer = buffer_.data_ptr (); - b->capacity = buffer_.capacity (); - b->size = &size_; - } - - virtual unsigned int - oid () const - { - return numeric_oid; - } - - private: - bool - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - std::size_t size (0), cap (buffer_.capacity ()); - value_traits::set_image (buffer_, size, is_null, v); - size_ = size; - return cap != buffer_.capacity (); - } - - private: - details::buffer buffer_; - std::size_t size_; - }; - - // DATE - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::date; - b->buffer = &image_; - } - - virtual unsigned int - oid () const - { - return date_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (image_, is_null, v); - } - - private: - int image_; - }; - - // TIME - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::time; - b->buffer = &image_; - } - - virtual unsigned int - oid () const - { - return time_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (image_, is_null, v); - } - - private: - long long image_; - }; - - // TIMESTAMP - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::timestamp; - b->buffer = &image_; - } - - virtual unsigned int - oid () const - { - return timestamp_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (image_, is_null, v); - } - - private: - long long image_; - }; - - // STRING - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - return init (*static_cast (value_)); - } - - virtual void - bind (bind_type* b) - { - b->type = bind::text; - b->buffer = buffer_.data_ptr (); - b->capacity = buffer_.capacity (); - b->size = &size_; - } - - virtual unsigned int - oid () const - { - return text_oid; - } - - private: - bool - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - std::size_t size (0), cap (buffer_.capacity ()); - value_traits::set_image (buffer_, size, is_null, v); - size_ = size; - return cap != buffer_.capacity (); - } - - private: - details::buffer buffer_; - std::size_t size_; - }; - - // BYTEA - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - return init (*static_cast (value_)); - } - - virtual void - bind (bind_type* b) - { - b->type = bind::bytea; - b->buffer = buffer_.data_ptr (); - b->capacity = buffer_.capacity (); - b->size = &size_; - } - - virtual unsigned int - oid () const - { - return bytea_oid; - } - - private: - bool - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - std::size_t size (0), cap (buffer_.capacity ()); - value_traits::set_image (buffer_, size, is_null, v); - size_ = size; - return cap != buffer_.capacity (); - } - - private: - details::buffer buffer_; - std::size_t size_; - }; - - // BIT - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - return init (*static_cast (value_)); - } - - virtual void - bind (bind_type* b) - { - b->type = bind::bit; - b->buffer = buffer_.data_ptr (); - b->capacity = buffer_.capacity (); - b->size = &size_; - } - - private: - bool - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - std::size_t size (0), cap (buffer_.capacity ()); - - // NOTE: Using a fixed size bit type in queries requires - // alternative image buffer type support. - // - value_traits::set_image (buffer_, size, is_null, v); - size_ = size; - - return cap != buffer_.capacity (); - } - - private: - details::ubuffer buffer_; - std::size_t size_; - }; - - // VARBIT - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - return init (*static_cast (value_)); - } - - virtual void - bind (bind_type* b) - { - b->type = bind::varbit; - b->buffer = buffer_.data_ptr (); - b->capacity = buffer_.capacity (); - b->size = &size_; - } - - virtual unsigned int - oid () const - { - return varbit_oid; - } - - private: - bool - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - std::size_t size (0), cap (buffer_.capacity ()); - value_traits::set_image (buffer_, size, is_null, v); - size_ = size; - return cap != buffer_.capacity (); - } - - private: - details::ubuffer buffer_; - std::size_t size_; - }; - - // UUID - // - template - struct query_param_impl: query_param - { - query_param_impl (ref_bind r) : query_param (r.ptr ()) {} - query_param_impl (val_bind v) : query_param (0) {init (v.val);} - - virtual bool - init () - { - init (*static_cast (value_)); - return false; - } - - virtual void - bind (bind_type* b) - { - b->type = bind::uuid; - b->buffer = buffer_; - } - - virtual unsigned int - oid () const - { - return uuid_oid; - } - - private: - void - init (typename decay_traits::type v) - { - bool is_null (false); // Can't be NULL. - value_traits::set_image (buffer_, is_null, v); - } - - private: - unsigned char buffer_[16]; - }; - } -} - -// odb::pgsql::query and odb::query specialization for PostgreSQL. -// -namespace odb -{ - namespace pgsql - { - template - class query: public query_base, - public query_selector::columns_type - { - public: - // We don't define any typedefs here since they may clash with - // column names defined by our base type. - // - - query () - { - } - - explicit - query (bool v) - : query_base (v) - { - } - - explicit - query (const char* q) - : query_base (q) - { - } - - explicit - query (const std::string& q) - : query_base (q) - { - } - - template - explicit - query (val_bind v) - : query_base (v) - { - } - - template - explicit - query (ref_bind r) - : query_base (r) - { - } - - query (const query_base& q) - : query_base (q) - { - } - - template - query (const query_column& qc) - : query_base (qc) - { - } - - query (const odb::query_base& q) - : query_base (q) - { - } - }; - - namespace core - { - using pgsql::query; - } - } - - // Derive odb::query from odb::pgsql::query so that it can be - // implicitly converted in pgsql::database::query() calls. - // - template - class query: public pgsql::query - { - public: - // We don't define any typedefs here since they may clash with - // column names defined by our base type. - // - - query () - { - } - - explicit - query (bool v) - : pgsql::query (v) - { - } - - explicit - query (const char* q) - : pgsql::query (q) - { - } - - explicit - query (const std::string& q) - : pgsql::query (q) - { - } - - template - explicit - query (pgsql::val_bind v) - : pgsql::query (v) - { - } - - template - explicit - query (pgsql::ref_bind r) - : pgsql::query (r) - { - } - - query (const pgsql::query_base& q) - : pgsql::query (q) - { - } - - template - query (const pgsql::query_column& qc) - : pgsql::query (qc) - { - } - }; -} - -#include -#include - -#include - -#endif // ODB_PGSQL_QUERY_HXX diff --git a/odb/pgsql/query.ixx b/odb/pgsql/query.ixx deleted file mode 100644 index 826b4ab..0000000 --- a/odb/pgsql/query.ixx +++ /dev/null @@ -1,34 +0,0 @@ -// file : odb/pgsql/query.ixx -// license : GNU GPL v2; see accompanying LICENSE file - -namespace odb -{ - namespace pgsql - { - inline native_binding& query_base:: - parameters_binding () const - { - return native_binding_; - } - - template - inline void query_base:: - append (val_bind v, const char* conv) - { - append ( - details::shared_ptr ( - new (details::shared) query_param_impl (v)), - conv); - } - - template - inline void query_base:: - append (ref_bind r, const char* conv) - { - append ( - details::shared_ptr ( - new (details::shared) query_param_impl (r)), - conv); - } - } -} diff --git a/odb/pgsql/query.txx b/odb/pgsql/query.txx deleted file mode 100644 index 44dae30..0000000 --- a/odb/pgsql/query.txx +++ /dev/null @@ -1,168 +0,0 @@ -// file : odb/pgsql/query.txx -// license : GNU GPL v2; see accompanying LICENSE file - -namespace odb -{ - namespace pgsql - { - // - // query_base - // - - template - query_base:: - query_base (const query_column& c) - : binding_ (0, 0), native_binding_ (0, 0, 0, 0) - { - // Cannot use IS TRUE here since database type can be a non- - // integral type. - // - append (c.table (), c.column ()); - append ("="); - append (val_bind (true), c.conversion ()); - } - - // - // query_column - // - - // in - // - template - query_base query_column:: - in (decayed_type v1, decayed_type v2) const - { - query_base q (table_, column_); - q += "IN ("; - q.append (val_bind (v1), conversion_); - q += ","; - q.append (val_bind (v2), conversion_); - q += ")"; - return q; - } - - template - query_base query_column:: - in (decayed_type v1, decayed_type v2, decayed_type v3) const - { - query_base q (table_, column_); - q += "IN ("; - q.append (val_bind (v1), conversion_); - q += ","; - q.append (val_bind (v2), conversion_); - q += ","; - q.append (val_bind (v3), conversion_); - q += ")"; - return q; - } - - template - query_base query_column:: - in (decayed_type v1, decayed_type v2, decayed_type v3, - decayed_type v4) const - { - query_base q (table_, column_); - q += "IN ("; - q.append (val_bind (v1), conversion_); - q += ","; - q.append (val_bind (v2), conversion_); - q += ","; - q.append (val_bind (v3), conversion_); - q += ","; - q.append (val_bind (v4), conversion_); - q += ")"; - return q; - } - - template - query_base query_column:: - in (decayed_type v1, decayed_type v2, decayed_type v3, decayed_type v4, - decayed_type v5) const - { - query_base q (table_, column_); - q += "IN ("; - q.append (val_bind (v1), conversion_); - q += ","; - q.append (val_bind (v2), conversion_); - q += ","; - q.append (val_bind (v3), conversion_); - q += ","; - q.append (val_bind (v4), conversion_); - q += ","; - q.append (val_bind (v5), conversion_); - q += ")"; - return q; - } - - template - template - query_base query_column:: - in_range (I begin, I end) const - { - if (begin != end) - { - query_base q (table_, column_); - q += "IN ("; - - for (I i (begin); i != end; ++i) - { - if (i != begin) - q += ","; - - q.append (val_bind (*i), conversion_); - } - - q += ")"; - return q; - } - else - return query_base (false); - } - - // like - // - template - query_base query_column:: - like (val_bind p) const - { - query_base q (table_, column_); - q += "LIKE"; - q.append (p, conversion_); - return q; - } - - template - query_base query_column:: - like (ref_bind p) const - { - query_base q (table_, column_); - q += "LIKE"; - q.append (p, conversion_); - return q; - } - - template - query_base query_column:: - like (val_bind p, decayed_type e) const - { - query_base q (table_, column_); - q += "LIKE"; - q.append (p, conversion_); - q += "ESCAPE"; - q.append (val_bind (e), conversion_); - return q; - } - - template - query_base query_column:: - like (ref_bind p, decayed_type e) const - { - query_base q (table_, column_); - q += "LIKE"; - q.append (p, conversion_); - q += "ESCAPE"; - q.append (val_bind (e), conversion_); - return q; - } - } -} diff --git a/odb/pgsql/section-statements.hxx b/odb/pgsql/section-statements.hxx deleted file mode 100644 index e40b282..0000000 --- a/odb/pgsql/section-statements.hxx +++ /dev/null @@ -1,220 +0,0 @@ -// file : odb/pgsql/section-statements.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_SECTION_STATEMENTS_HXX -#define ODB_PGSQL_SECTION_STATEMENTS_HXX - -#include - -#include // std::size_t - -#include -#include -#include - -#include -#include -#include -#include -#include -#include // Oid -#include - -namespace odb -{ - namespace pgsql - { - class connection; - - // Template argument is the section traits type. - // - template - class section_statements - { - public: - typedef ST traits; - - typedef typename traits::image_type image_type; - typedef typename traits::id_image_type id_image_type; - - typedef pgsql::select_statement select_statement_type; - typedef pgsql::update_statement update_statement_type; - - typedef pgsql::connection connection_type; - - section_statements (connection_type&, - image_type&, - id_image_type&, - binding& id, - binding& idv, - native_binding& idn, - const Oid* idt); - - connection_type& - connection () {return conn_;} - - const schema_version_migration& - version_migration (const char* name = "") const - { - if (svm_ == 0) - svm_ = &conn_.database ().schema_version_migration (name); - - return *svm_; - } - - image_type& - image () {return image_;} - - const binding& - id_binding () {return id_binding_;} - - // Id and optimistic concurrency version (if any). - // - const binding& - idv_binding () {return idv_binding_;} - - // Select binding. - // - std::size_t - select_image_version () const { return select_image_version_;} - - void - select_image_version (std::size_t v) {select_image_version_ = v;} - - binding& - select_image_binding () {return select_image_binding_;} - - bool* - select_image_truncated () {return select_image_truncated_;} - - // Update binding. - // - std::size_t - update_image_version () const { return update_image_version_;} - - void - update_image_version (std::size_t v) {update_image_version_ = v;} - - std::size_t - update_id_binding_version () const { return update_id_binding_version_;} - - void - update_id_binding_version (std::size_t v) {update_id_binding_version_ = v;} - - binding& - update_image_binding () {return update_image_binding_;} - - // - // Statements. - // - - select_statement_type& - select_statement () - { - if (select_ == 0) - select_.reset ( - new (details::shared) select_statement_type ( - conn_, - traits::select_name, - traits::select_statement, - traits::versioned, // Process if versioned. - false, // Don't optimize. - id_types_, - id_column_count, - id_binding_, - id_native_binding_, - select_image_binding_, - false)); - - return *select_; - } - - update_statement_type& - update_statement () - { - if (update_ == 0) - update_.reset ( - new (details::shared) update_statement_type ( - conn_, - traits::update_name, - traits::update_statement, - traits::versioned, // Process if versioned. - traits::update_types, - update_column_count + id_column_count + - managed_optimistic_update_column_count, - update_image_binding_, - update_image_native_binding_, - false)); - - return *update_; - } - - public: - static const std::size_t id_column_count = traits::id_column_count; - static const std::size_t managed_optimistic_load_column_count = - traits::managed_optimistic_load_column_count; - static const std::size_t managed_optimistic_update_column_count = - traits::managed_optimistic_update_column_count; - static const std::size_t select_column_count = traits::load_column_count; - static const std::size_t update_column_count = - traits::update_column_count; - - private: - section_statements (const section_statements&); - section_statements& operator= (const section_statements&); - - protected: - connection_type& conn_; - mutable const schema_version_migration* svm_; - - // These come from object_statements. - // - image_type& image_; - binding& id_binding_; - binding& idv_binding_; - native_binding& id_native_binding_; - const Oid* id_types_; - - // Select binding. - // - std::size_t select_image_version_; - - static const std::size_t select_bind_count = - select_column_count != 0 || managed_optimistic_load_column_count != 0 - ? select_column_count + managed_optimistic_load_column_count - : 1; - - binding select_image_binding_; - bind select_image_bind_[select_bind_count]; - bool select_image_truncated_[select_bind_count]; - - // Update binding. - // - std::size_t update_image_version_; - std::size_t update_id_binding_version_; - - static const std::size_t update_bind_count = - update_column_count != 0 || managed_optimistic_update_column_count != 0 - ? update_column_count + id_column_count + - managed_optimistic_update_column_count - : 1; - - binding update_image_binding_; - bind update_image_bind_[update_bind_count]; - - native_binding update_image_native_binding_; - char* update_image_values_[update_bind_count]; - int update_image_lengths_[update_bind_count]; - int update_image_formats_[update_bind_count]; - - details::shared_ptr select_; - details::shared_ptr update_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_SECTION_STATEMENTS_HXX diff --git a/odb/pgsql/section-statements.txx b/odb/pgsql/section-statements.txx deleted file mode 100644 index 55f4093..0000000 --- a/odb/pgsql/section-statements.txx +++ /dev/null @@ -1,51 +0,0 @@ -// file : odb/pgsql/section-statements.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // std::memset - -namespace odb -{ - namespace pgsql - { - template - section_statements:: - section_statements (connection_type& conn, - image_type& im, - id_image_type&, - binding& id, - binding& idv, - native_binding& idn, - const Oid* idt) - : conn_ (conn), - svm_ (0), - image_ (im), - id_binding_ (id), - idv_binding_ (idv), - id_native_binding_ (idn), - id_types_ (idt), - select_image_binding_ (select_image_bind_, - select_column_count + - managed_optimistic_load_column_count), - update_image_binding_ (update_image_bind_, - update_column_count + id_column_count + - managed_optimistic_update_column_count), - update_image_native_binding_ (update_image_values_, - update_image_lengths_, - update_image_formats_, - update_column_count + id_column_count + - managed_optimistic_update_column_count) - { - select_image_version_ = 0; - update_image_version_ = 0; - update_id_binding_version_ = 0; - - std::memset (select_image_bind_, 0, sizeof (select_image_bind_)); - std::memset ( - select_image_truncated_, 0, sizeof (select_image_truncated_)); - std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); - - for (std::size_t i (0); i < select_bind_count; ++i) - select_image_bind_[i].truncated = select_image_truncated_ + i; - } - } -} diff --git a/odb/pgsql/simple-object-result.hxx b/odb/pgsql/simple-object-result.hxx deleted file mode 100644 index 7472cbe..0000000 --- a/odb/pgsql/simple-object-result.hxx +++ /dev/null @@ -1,85 +0,0 @@ -// file : odb/pgsql/simple-object-result.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_SIMPLE_OBJECT_RESULT_HXX -#define ODB_PGSQL_SIMPLE_OBJECT_RESULT_HXX - -#include - -#include // std::size_t - -#include -#include - -#include - -#include -#include // query_base -#include -#include - -namespace odb -{ - namespace pgsql - { - template - class object_result_impl: public odb::object_result_impl - { - public: - typedef odb::object_result_impl base_type; - - typedef typename base_type::id_type id_type; - typedef typename base_type::object_type object_type; - typedef typename base_type::pointer_type pointer_type; - - typedef object_traits_impl object_traits; - typedef typename base_type::pointer_traits pointer_traits; - - typedef typename object_traits::statements_type statements_type; - - virtual - ~object_result_impl (); - - object_result_impl (const query_base&, - details::shared_ptr, - statements_type&, - const schema_version_migration*); - - virtual void - load (object_type&, bool fetch); - - virtual id_type - load_id (); - - virtual void - next (); - - virtual void - cache (); - - virtual std::size_t - size (); - - virtual void - invalidate (); - - using base_type::current; - - private: - void - load_image (); - - private: - details::shared_ptr statement_; - statements_type& statements_; - object_traits_calls tc_; - std::size_t count_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_SIMPLE_OBJECT_RESULT_HXX diff --git a/odb/pgsql/simple-object-result.txx b/odb/pgsql/simple-object-result.txx deleted file mode 100644 index c14d64b..0000000 --- a/odb/pgsql/simple-object-result.txx +++ /dev/null @@ -1,158 +0,0 @@ -// file : odb/pgsql/simple-object-result.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -#include - -#include - -namespace odb -{ - namespace pgsql - { - template - object_result_impl:: - ~object_result_impl () - { - if (!this->end_) - statement_->free_result (); - } - - template - void object_result_impl:: - invalidate () - { - if (!this->end_) - { - statement_->free_result (); - this->end_ = true; - } - - statement_.reset (); - } - - template - object_result_impl:: - object_result_impl (const query_base&, - details::shared_ptr statement, - statements_type& statements, - const schema_version_migration* svm) - : base_type (statements.connection ()), - statement_ (statement), - statements_ (statements), - tc_ (svm), - count_ (0) - { - } - - template - void object_result_impl:: - load (object_type& obj, bool fetch) - { - if (fetch) - load_image (); - - // This is a top-level call so the statements cannot be locked. - // - assert (!statements_.locked ()); - typename statements_type::auto_lock l (statements_); - - object_traits::callback (this->db_, obj, callback_event::pre_load); - - typename object_traits::image_type& i (statements_.image ()); - tc_.init (obj, i, &this->db_); - - // Initialize the id image and binding and load the rest of the object - // (containers, etc). - // - typename object_traits::id_image_type& idi (statements_.id_image ()); - object_traits::init (idi, object_traits::id (i)); - - binding& idb (statements_.id_image_binding ()); - if (idi.version != statements_.id_image_version () || idb.version == 0) - { - object_traits::bind (idb.bind, idi); - statements_.id_image_version (idi.version); - idb.version++; - } - - tc_.load_ (statements_, obj, false); - statements_.load_delayed (tc_.version ()); - l.unlock (); - object_traits::callback (this->db_, obj, callback_event::post_load); - } - - template - typename object_result_impl::id_type - object_result_impl:: - load_id () - { - load_image (); - return object_traits::id (statements_.image ()); - } - - template - void object_result_impl:: - next () - { - this->current (pointer_type ()); - - if (statement_->next ()) - count_++; - else - { - statement_->free_result (); - this->end_ = true; - } - } - - template - void object_result_impl:: - load_image () - { - // The image can grow between calls to load() as a result of other - // statements execution. - // - typename object_traits::image_type& im (statements_.image ()); - - if (im.version != statements_.select_image_version ()) - { - binding& b (statements_.select_image_binding ()); - tc_.bind (b.bind, im, statement_select); - statements_.select_image_version (im.version); - b.version++; - } - - select_statement::result r (statement_->load ()); - - if (r == select_statement::truncated) - { - if (tc_.grow (im, statements_.select_image_truncated ())) - im.version++; - - if (im.version != statements_.select_image_version ()) - { - binding& b (statements_.select_image_binding ()); - tc_.bind (b.bind, im, statement_select); - statements_.select_image_version (im.version); - b.version++; - statement_->reload (); - } - } - } - - template - void object_result_impl:: - cache () - { - } - - template - std::size_t object_result_impl:: - size () - { - return this->end_ ? count_ : statement_->result_size (); - } - } -} diff --git a/odb/pgsql/simple-object-statements.cxx b/odb/pgsql/simple-object-statements.cxx deleted file mode 100644 index 432f990..0000000 --- a/odb/pgsql/simple-object-statements.cxx +++ /dev/null @@ -1,15 +0,0 @@ -// file : odb/pgsql/simple-object-statements.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -namespace odb -{ - namespace pgsql - { - object_statements_base:: - ~object_statements_base () - { - } - } -} diff --git a/odb/pgsql/simple-object-statements.hxx b/odb/pgsql/simple-object-statements.hxx deleted file mode 100644 index 086ef5f..0000000 --- a/odb/pgsql/simple-object-statements.hxx +++ /dev/null @@ -1,657 +0,0 @@ -// file : odb/pgsql/simple-object-statements.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_SIMPLE_OBJECT_STATEMENTS_HXX -#define ODB_PGSQL_SIMPLE_OBJECT_STATEMENTS_HXX - -#include - -#include -#include -#include // std::size_t - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include - -#include - -namespace odb -{ - namespace pgsql - { - // The extra_statement_cache class is only defined (and used) in - // the generated source file. However, object_statements may be - // referenced from another source file in the case of a polymorphic - // hierarchy (though in this case the extra statement cache is - // not used). As a result, we cannot have a by-value member and - // instead will store a pointer and lazily allocate the cache if - // and when needed. We will also need to store a pointer to the - // deleter function which will be initialized during allocation - // (at that point we know that the cache class is defined). - // - template - struct extra_statement_cache_ptr - { - typedef I image_type; - typedef ID id_image_type; - typedef pgsql::connection connection_type; - - extra_statement_cache_ptr (): p_ (0) {} - ~extra_statement_cache_ptr () - { - if (p_ != 0) - (this->*deleter_) (0, 0, 0, 0, 0, 0, 0); - } - - T& - get (connection_type& c, - image_type& im, - id_image_type& idim, - binding& id, - binding* idv, - native_binding& idn, - const Oid* idt) - { - if (p_ == 0) - allocate (&c, &im, &idim, &id, (idv != 0 ? idv : &id), &idn, idt); - - return *p_; - } - - private: - void - allocate (connection_type*, - image_type*, id_image_type*, - binding*, binding*, native_binding*, const Oid*); - - private: - T* p_; - void (extra_statement_cache_ptr::*deleter_) ( - connection_type*, - image_type*, id_image_type*, - binding*, binding*, native_binding*, const Oid*); - }; - - template - void extra_statement_cache_ptr:: - allocate (connection_type* c, - image_type* im, id_image_type* idim, - binding* id, binding* idv, native_binding* idn, const Oid* idt) - { - // To reduce object code size, this function acts as both allocator - // and deleter. - // - if (p_ == 0) - { - p_ = new T (*c, *im, *idim, *id, *idv, *idn, idt); - deleter_ = &extra_statement_cache_ptr::allocate; - } - else - delete p_; - } - - // - // Implementation for objects with object id. - // - - class LIBODB_PGSQL_EXPORT object_statements_base: public statements_base - { - public: - // Locking. - // - void - lock () - { - assert (!locked_); - locked_ = true; - } - - void - unlock () - { - assert (locked_); - locked_ = false; - } - - bool - locked () const - { - return locked_; - } - - struct auto_unlock - { - // Unlocks the statement on construction and re-locks it on - // destruction. - // - auto_unlock (object_statements_base&); - ~auto_unlock (); - - private: - auto_unlock (const auto_unlock&); - auto_unlock& operator= (const auto_unlock&); - - private: - object_statements_base& s_; - }; - - public: - virtual - ~object_statements_base (); - - protected: - object_statements_base (connection_type& conn) - : statements_base (conn), locked_ (false) - { - } - - protected: - bool locked_; - }; - - template - struct optimistic_data; - - template - struct optimistic_data - { - typedef T object_type; - typedef object_traits_impl object_traits; - - optimistic_data (bind*, char** nv, int* nl, int* nf, - std::size_t skip, unsigned long long* status); - - binding* - id_image_binding () {return &id_image_binding_;} - - native_binding* - id_image_native_binding () {return &id_image_native_binding_;} - - const Oid* - id_image_types () - {return object_traits::optimistic_erase_statement_types;} - - // The id + optimistic column binding. - // - binding id_image_binding_; - native_binding id_image_native_binding_; - - details::shared_ptr erase_; - }; - - template - struct optimistic_data - { - optimistic_data (bind*, char**, int*, int*, - std::size_t, unsigned long long*) {} - - binding* - id_image_binding () {return 0;} - - native_binding* - id_image_native_binding () {return 0;} - - const Oid* - id_image_types () {return 0;} - }; - - template - class object_statements: public object_statements_base - { - public: - typedef T object_type; - typedef object_traits_impl object_traits; - typedef typename object_traits::id_type id_type; - typedef typename object_traits::pointer_type pointer_type; - typedef typename object_traits::image_type image_type; - typedef typename object_traits::id_image_type id_image_type; - - typedef - typename object_traits::pointer_cache_traits - pointer_cache_traits; - - typedef - typename object_traits::extra_statement_cache_type - extra_statement_cache_type; - - typedef pgsql::insert_statement insert_statement_type; - typedef pgsql::select_statement select_statement_type; - typedef pgsql::update_statement update_statement_type; - typedef pgsql::delete_statement delete_statement_type; - - // Automatic lock. - // - struct auto_lock - { - // Lock the statements unless they are already locked in which - // case subsequent calls to locked() will return false. - // - auto_lock (object_statements&); - - // Unlock the statemens if we are holding the lock and clear - // the delayed loads. This should only happen in case an - // exception is thrown. In normal circumstances, the user - // should call unlock() explicitly. - // - ~auto_lock (); - - // Return true if this auto_lock instance holds the lock. - // - bool - locked () const; - - // Unlock the statemens. - // - void - unlock (); - - private: - auto_lock (const auto_lock&); - auto_lock& operator= (const auto_lock&); - - private: - object_statements& s_; - bool locked_; - }; - - public: - object_statements (connection_type&); - - virtual - ~object_statements (); - - // Delayed loading. - // - typedef void (*loader_function) (odb::database&, - const id_type&, - object_type&, - const schema_version_migration*); - void - delay_load (const id_type& id, - object_type& obj, - const typename pointer_cache_traits::position_type& p, - loader_function l = 0) - { - delayed_.push_back (delayed_load (id, obj, p, l)); - } - - void - load_delayed (const schema_version_migration* svm) - { - assert (locked ()); - - if (!delayed_.empty ()) - load_delayed_ (svm); - } - - void - clear_delayed () - { - if (!delayed_.empty ()) - clear_delayed_ (); - } - - // Object image. - // - image_type& - image (std::size_t i = 0) {return images_[i].obj;} - - // Insert binding. - // - std::size_t - insert_image_version () const { return insert_image_version_;} - - void - insert_image_version (std::size_t v) {insert_image_version_ = v;} - - binding& - insert_image_binding () {return insert_image_binding_;} - - // Update binding. - // - std::size_t - update_image_version () const { return update_image_version_;} - - void - update_image_version (std::size_t v) {update_image_version_ = v;} - - std::size_t - update_id_image_version () const { return update_id_image_version_;} - - void - update_id_image_version (std::size_t v) {update_id_image_version_ = v;} - - binding& - update_image_binding () {return update_image_binding_;} - - // Select binding. - // - std::size_t - select_image_version () const { return select_image_version_;} - - void - select_image_version (std::size_t v) {select_image_version_ = v;} - - binding& - select_image_binding () {return select_image_binding_;} - - bool* - select_image_truncated () {return select_image_truncated_;} - - // Object id image and binding. - // - id_image_type& - id_image (std::size_t i = 0) {return images_[i].id;} - - std::size_t - id_image_version () const {return id_image_version_;} - - void - id_image_version (std::size_t v) {id_image_version_ = v;} - - binding& - id_image_binding () {return id_image_binding_;} - - // Optimistic id + managed column image binding. It points to - // the same suffix as id binding and they are always updated - // at the same time. - // - binding& - optimistic_id_image_binding () {return od_.id_image_binding_;} - - // Statements. - // - insert_statement_type& - persist_statement () - { - if (persist_ == 0) - persist_.reset ( - new (details::shared) insert_statement_type ( - conn_, - object_traits::persist_statement_name, - object_traits::persist_statement, - object_traits::versioned, // Process if versioned. - object_traits::persist_statement_types, - insert_column_count, - insert_image_binding_, - insert_image_native_binding_, - (object_traits::auto_id ? &id_image_binding_ : 0), - false)); - - return *persist_; - } - - select_statement_type& - find_statement () - { - if (find_ == 0) - find_.reset ( - new (details::shared) select_statement_type ( - conn_, - object_traits::find_statement_name, - object_traits::find_statement, - object_traits::versioned, // Process if versioned. - false, // Don't optimize. - object_traits::find_statement_types, - id_column_count, - id_image_binding_, - id_image_native_binding_, - select_image_binding_, - false)); - - return *find_; - } - - update_statement_type& - update_statement () - { - if (update_ == 0) - update_.reset ( - new (details::shared) update_statement_type ( - conn_, - object_traits::update_statement_name, - object_traits::update_statement, - object_traits::versioned, // Process if versioned. - object_traits::update_statement_types, - update_column_count + id_column_count, - update_image_binding_, - update_image_native_binding_, - false)); - - return *update_; - } - - delete_statement_type& - erase_statement () - { - if (erase_ == 0) - erase_.reset ( - new (details::shared) delete_statement_type ( - conn_, - object_traits::erase_statement_name, - object_traits::erase_statement, - object_traits::find_statement_types, // The same as find (id). - id_column_count, - id_image_binding_, - id_image_native_binding_, - false)); - - return *erase_; - } - - delete_statement_type& - optimistic_erase_statement () - { - if (od_.erase_ == 0) - od_.erase_.reset ( - new (details::shared) delete_statement_type ( - conn_, - object_traits::optimistic_erase_statement_name, - object_traits::optimistic_erase_statement, - object_traits::optimistic_erase_statement_types, - id_column_count + managed_optimistic_column_count, - od_.id_image_binding_, - od_.id_image_native_binding_, - false)); - - return *od_.erase_; - } - - // Extra (container, section) statement cache. - // - extra_statement_cache_type& - extra_statement_cache () - { - return extra_statement_cache_.get ( - conn_, - images_[0].obj, - images_[0].id, - id_image_binding_, - od_.id_image_binding (), - id_image_native_binding_, - object_traits::find_statement_types); - } - - public: - // select = total - separate_load - // insert = total - inverse - managed_optimistic - auto_id - // update = total - inverse - managed_optimistic - id - readonly - - // separate_update - // - static const std::size_t select_column_count = - object_traits::column_count - - object_traits::separate_load_column_count; - - static const std::size_t id_column_count = - object_traits::id_column_count; - - static const std::size_t insert_column_count = - object_traits::column_count - - object_traits::inverse_column_count - - object_traits::managed_optimistic_column_count - - (object_traits::auto_id ? id_column_count : 0); - - static const std::size_t update_column_count = - insert_column_count - - (object_traits::auto_id ? 0 : id_column_count) - - object_traits::readonly_column_count - - object_traits::separate_update_column_count; - - static const std::size_t managed_optimistic_column_count = - object_traits::managed_optimistic_column_count; - - private: - object_statements (const object_statements&); - object_statements& operator= (const object_statements&); - - protected: - template - void - load_delayed_ (const schema_version_migration*); - - void - clear_delayed_ (); - - protected: - template - friend class polymorphic_derived_object_statements; - - extra_statement_cache_ptr extra_statement_cache_; - - // The UPDATE statement uses both the object and id image. Keep them - // next to each other so that the same skip distance can be used in - // batch binding. - // - struct images - { - image_type obj; - id_image_type id; - }; - - images images_[object_traits::batch]; - unsigned long long status_[object_traits::batch]; - - // Select binding. - // - std::size_t select_image_version_; - binding select_image_binding_; - bind select_image_bind_[select_column_count]; - bool select_image_truncated_[select_column_count]; - - // Insert binding. - // - std::size_t insert_image_version_; - binding insert_image_binding_; - bind insert_image_bind_[ - insert_column_count != 0 ? insert_column_count : 1]; - native_binding insert_image_native_binding_; - char* insert_image_values_[ - insert_column_count != 0 ? insert_column_count : 1]; - int insert_image_lengths_[ - insert_column_count != 0 ? insert_column_count : 1]; - int insert_image_formats_[ - insert_column_count != 0 ? insert_column_count : 1]; - - // Update binding. Note that the id suffix is bound to id_image_ - // below instead of image_ which makes this binding effectively - // bound to two images. As a result, we have to track versions - // for both of them. If this object uses optimistic concurrency, - // then the binding for the managed column (version, timestamp, - // etc) comes after the id and the image for such a column is - // stored as part of the id image. - // - std::size_t update_image_version_; - std::size_t update_id_image_version_; - binding update_image_binding_; - bind update_image_bind_[update_column_count + id_column_count + - managed_optimistic_column_count]; - native_binding update_image_native_binding_; - char* update_image_values_[update_column_count + id_column_count + - managed_optimistic_column_count]; - int update_image_lengths_[update_column_count + id_column_count + - managed_optimistic_column_count]; - int update_image_formats_[update_column_count + id_column_count + - managed_optimistic_column_count]; - - // Id image binding (only used as a parameter). Uses the suffix in - // the update bind. - // - std::size_t id_image_version_; - binding id_image_binding_; - native_binding id_image_native_binding_; - - // Extra data for objects with optimistic concurrency support. - // - optimistic_data od_; - - details::shared_ptr persist_; - details::shared_ptr find_; - details::shared_ptr update_; - details::shared_ptr erase_; - - // Delayed loading. - // - struct delayed_load - { - typedef typename pointer_cache_traits::position_type position_type; - - delayed_load () {} - delayed_load (const id_type& i, - object_type& o, - const position_type& p, - loader_function l) - : id (i), obj (&o), pos (p), loader (l) - { - } - - id_type id; - object_type* obj; - position_type pos; - loader_function loader; - }; - - typedef std::vector delayed_loads; - delayed_loads delayed_; - - // Delayed vectors swap guard. See the load_delayed_() function for - // details. - // - struct swap_guard - { - swap_guard (object_statements& os, delayed_loads& dl) - : os_ (os), dl_ (dl) - { - dl_.swap (os_.delayed_); - } - - ~swap_guard () - { - os_.clear_delayed (); - dl_.swap (os_.delayed_); - } - - private: - object_statements& os_; - delayed_loads& dl_; - }; - }; - } -} - -#include -#include - -#include - -#endif // ODB_PGSQL_SIMPLE_OBJECT_STATEMENTS_HXX diff --git a/odb/pgsql/simple-object-statements.ixx b/odb/pgsql/simple-object-statements.ixx deleted file mode 100644 index fbb2775..0000000 --- a/odb/pgsql/simple-object-statements.ixx +++ /dev/null @@ -1,68 +0,0 @@ -// file : odb/pgsql/simple-object-statements.ixx -// license : GNU GPL v2; see accompanying LICENSE file - -namespace odb -{ - namespace pgsql - { - // - // auto_unlock - // - inline object_statements_base::auto_unlock:: - auto_unlock (object_statements_base& s) - : s_ (s) - { - s_.unlock (); - } - - inline object_statements_base::auto_unlock:: - ~auto_unlock () - { - s_.lock (); - } - - // - // auto_lock - // - template - inline object_statements::auto_lock:: - auto_lock (object_statements& s) - : s_ (s) - { - if (!s_.locked ()) - { - s_.lock (); - locked_ = true; - } - else - locked_ = false; - } - - template - inline object_statements::auto_lock:: - ~auto_lock () - { - if (locked_) - { - s_.unlock (); - s_.clear_delayed (); - } - } - - template - inline bool object_statements::auto_lock:: - locked () const - { - return locked_; - } - - template - inline void object_statements::auto_lock:: - unlock () - { - assert (locked_); - s_.unlock (); - locked_ = false; - } - } -} diff --git a/odb/pgsql/simple-object-statements.txx b/odb/pgsql/simple-object-statements.txx deleted file mode 100644 index bb47b43..0000000 --- a/odb/pgsql/simple-object-statements.txx +++ /dev/null @@ -1,190 +0,0 @@ -// file : odb/pgsql/simple-object-statements.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // std::memset - -#include -#include - -#include -#include - -namespace odb -{ - namespace pgsql - { - // - // optimistic_data - // - - template - optimistic_data:: - optimistic_data (bind* b, char** nv, int* nl, int* nf, - std::size_t skip, unsigned long long* status) - : id_image_binding_ ( - b, - object_traits::id_column_count + - object_traits::managed_optimistic_column_count, - object_traits::batch, - skip, - status), - id_image_native_binding_ ( - nv, nl, nf, - object_traits::id_column_count + - object_traits::managed_optimistic_column_count) - { - } - - // - // object_statements - // - - template - object_statements:: - ~object_statements () - { - } - - template - object_statements:: - object_statements (connection_type& conn) - : object_statements_base (conn), - // select - select_image_binding_ (select_image_bind_, select_column_count), - // insert - insert_image_binding_ (insert_image_bind_, - insert_column_count, - object_traits::batch, - sizeof (images), - status_), - insert_image_native_binding_ (insert_image_values_, - insert_image_lengths_, - insert_image_formats_, - insert_column_count), - // update - update_image_binding_ (update_image_bind_, - update_column_count + id_column_count + - managed_optimistic_column_count, - object_traits::batch, - sizeof (images), - status_), - update_image_native_binding_ (update_image_values_, - update_image_lengths_, - update_image_formats_, - update_column_count + id_column_count + - managed_optimistic_column_count), - // id - id_image_binding_ (update_image_bind_ + update_column_count, - id_column_count, - object_traits::batch, - sizeof (images), - status_), - id_image_native_binding_ ( - update_image_values_ + update_column_count, - update_image_lengths_ + update_column_count, - update_image_formats_ + update_column_count, - id_column_count), - // optimistic data - od_ (update_image_bind_ + update_column_count, - update_image_values_ + update_column_count, - update_image_lengths_ + update_column_count, - update_image_formats_ + update_column_count, - sizeof (images), - status_) - { - // Only versions in the first element used. - // - images_[0].obj.version = 0; - images_[0].id.version = 0; - - select_image_version_ = 0; - insert_image_version_ = 0; - update_image_version_ = 0; - update_id_image_version_ = 0; - id_image_version_ = 0; - - std::memset (insert_image_bind_, 0, sizeof (insert_image_bind_)); - std::memset (update_image_bind_, 0, sizeof (update_image_bind_)); - std::memset (select_image_bind_, 0, sizeof (select_image_bind_)); - std::memset ( - select_image_truncated_, 0, sizeof (select_image_truncated_)); - - for (std::size_t i (0); i < select_column_count; ++i) - select_image_bind_[i].truncated = select_image_truncated_ + i; - } - - template - template - void object_statements:: - load_delayed_ (const schema_version_migration* svm) - { - database& db (connection ().database ()); - - delayed_loads dls; - swap_guard sg (*this, dls); - - while (!dls.empty ()) - { - delayed_load l (dls.back ()); - typename pointer_cache_traits::insert_guard ig (l.pos); - dls.pop_back (); - - if (l.loader == 0) - { - object_traits_calls tc (svm); - - if (!tc.find_ (static_cast (*this), &l.id)) - throw object_not_persistent (); - - object_traits::callback (db, *l.obj, callback_event::pre_load); - - // Our calls to init/load below can result in additional delayed - // loads being added to the delayed_ vector. We need to process - // those before we call the post callback. - // - tc.init (*l.obj, image (), &db); - - // Load containers, etc. - // - tc.load_ (static_cast (*this), *l.obj, false); - - if (!delayed_.empty ()) - load_delayed_ (svm); - - // Temporarily unlock the statement for the post_load call so that - // it can load objects of this type recursively. This is safe to do - // because we have completely loaded the current object. Also the - // delayed_ list is clear before the unlock and should be clear on - // re-lock (since a callback can only call public API functions - // which will make sure all the delayed loads are processed before - // returning). - // - { - auto_unlock u (*this); - object_traits::callback (db, *l.obj, callback_event::post_load); - } - } - else - l.loader (db, l.id, *l.obj, svm); - - pointer_cache_traits::load (ig.position ()); - ig.release (); - } - } - - template - void object_statements:: - clear_delayed_ () - { - // Remove the objects from the session cache. - // - for (typename delayed_loads::iterator i (delayed_.begin ()), - e (delayed_.end ()); i != e; ++i) - { - pointer_cache_traits::erase (i->pos); - } - - delayed_.clear (); - } - } -} diff --git a/odb/pgsql/statement-cache.hxx b/odb/pgsql/statement-cache.hxx deleted file mode 100644 index 9417949..0000000 --- a/odb/pgsql/statement-cache.hxx +++ /dev/null @@ -1,57 +0,0 @@ -// file : odb/pgsql/statement-cache.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_STATEMENT_CACHE_HXX -#define ODB_PGSQL_STATEMENT_CACHE_HXX - -#include - -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - class statement_cache - { - public: - statement_cache (connection& conn) - : conn_ (conn), - version_seq_ (conn_.database ().schema_version_sequence ()) {} - - template - typename object_traits_impl::statements_type& - find_object (); - - template - view_statements& - find_view (); - - private: - typedef std::map, - details::type_info_comparator> map; - - connection& conn_; - unsigned int version_seq_; - map map_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_STATEMENT_CACHE_HXX diff --git a/odb/pgsql/statement-cache.txx b/odb/pgsql/statement-cache.txx deleted file mode 100644 index 488ba2c..0000000 --- a/odb/pgsql/statement-cache.txx +++ /dev/null @@ -1,60 +0,0 @@ -// file : odb/pgsql/statement-cache.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -namespace odb -{ - namespace pgsql - { - template - typename object_traits_impl::statements_type& - statement_cache:: - find_object () - { - typedef - typename object_traits_impl::statements_type - statements_type; - - // Clear the cache if the database version has changed. This - // makes sure we don't re-use statements that correspond to - // the old schema. - // - if (version_seq_ != conn_.database ().schema_version_sequence ()) - { - map_.clear (); - version_seq_ = conn_.database ().schema_version_sequence (); - } - - map::iterator i (map_.find (&typeid (T))); - - if (i != map_.end ()) - return static_cast (*i->second); - - details::shared_ptr p ( - new (details::shared) statements_type (conn_)); - - map_.insert (map::value_type (&typeid (T), p)); - return *p; - } - - template - view_statements& statement_cache:: - find_view () - { - // We don't cache any statements for views so no need to clear - // the cache. - - map::iterator i (map_.find (&typeid (T))); - - if (i != map_.end ()) - return static_cast&> (*i->second); - - details::shared_ptr > p ( - new (details::shared) view_statements (conn_)); - - map_.insert (map::value_type (&typeid (T), p)); - return *p; - } - } -} diff --git a/odb/pgsql/statement.cxx b/odb/pgsql/statement.cxx deleted file mode 100644 index 8574c37..0000000 --- a/odb/pgsql/statement.cxx +++ /dev/null @@ -1,1545 +0,0 @@ -// file : odb/pgsql/statement.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // ODB_CXX11 - -#include - -#ifdef LIBPQ_HAS_PIPELINING -# ifndef _WIN32 -# include -# include -# endif -#endif - -#include // strcmp -#include // pair -#include - -#ifdef ODB_CXX11 -# include // strtoull -#else -# include // istringstream -#endif - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace std; - -namespace odb -{ - namespace pgsql - { - using namespace details; - - static unsigned long long - affected_row_count (PGresult* h) - { - const char* s (PQcmdTuples (h)); - unsigned long long count; - - if (s[0] != '\0' && s[1] == '\0') - count = static_cast (s[0] - '0'); - else - { -#ifdef ODB_CXX11 - count = strtoull (s, 0, 10); -#else - istringstream ss (s); - ss >> count; -#endif - } - - return count; - } - - // - // statement - // - - statement:: - ~statement () - { - try - { - deallocate (); - } - catch (...) - { - } - } - - void statement:: - deallocate () - { - if (!deallocated_) - { - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->deallocate (conn_, *this); - } - - string s ("deallocate \""); - s += name_; - s += "\""; - - deallocated_ = true; - auto_handle h (PQexec (conn_.handle (), s.c_str ())); - - if (!is_good_result (h)) - { - // When we try to execute an invalid statement, PG "poisons" the - // transaction (those "current transaction is aborted, commands - // ignored until end of transaction block" messages in the log). - // This includes prepared statement deallocations (quite a stupid - // decision, if you ask me). - // - // So what can happen in this situation is the deallocation fails - // but we ignore it because we are already unwinding the stack - // (i.e., the prepared statement execution has failed). Next the - // user fixes things (e.g., passes valid parameters) and tries to - // re-execute the same query. But since we have failed to deallocate - // the statement, we now cannot re-prepare it; the name is already - // in use. - // - // What can we do to fix this? One way would be to postpone the - // deallocation until after the transaction is rolled back. This, - // however, would require quite an elaborate machinery: connection - // will have to store a list of such statements, etc. A much simpler - // solution is to mark the connection as failed. While it maybe a - // bit less efficient, we assume this is an "exceptional" situation - // that doesn't occur often. The only potentially problematic case - // is if the user holds the pointer to the connection and runs - // multiple transactions on it. But in this case the user should - // check if the connection is still good after each failure anyway. - // - conn_.mark_failed (); - - translate_error (conn_, h); - } - } - } - - statement:: - statement (connection_type& conn, - const string& name, - const string& text, - statement_kind sk, - const binding* process, - bool optimize, - const Oid* types, - size_t types_count) - : conn_ (conn), - name_copy_ (name), name_ (name_copy_.c_str ()), - deallocated_ (false) - { - if (process == 0) - { - text_copy_ = text; - text_ = text_copy_.c_str (); - } - else - text_ = text.c_str (); // Temporary, see init(). - - init (sk, process, optimize, types, types_count); - - // - // If any code after this line throws, the statement will be leaked - // (on the server) since deallocate() won't be called for it. - // - } - - statement:: - statement (connection_type& conn, - const char* name, - const char* text, - statement_kind sk, - const binding* process, - bool optimize, - bool copy, - const Oid* types, - size_t types_count) - : conn_ (conn), deallocated_ (false) - { - if (copy) - { - name_copy_ = name; - name_ = name_copy_.c_str (); - } - else - name_ = name; - - if (process == 0 && copy) - { - text_copy_ = text; - text_ = text_copy_.c_str (); - } - else - text_ = text; // Potentially temporary, see init(). - - init (sk, process, optimize, types, types_count); - - // - // If any code after this line throws, the statement will be leaked - // (on the server) since deallocate() won't be called for it. - // - } - - void statement:: - init (statement_kind sk, - const binding* proc, - bool optimize, - const Oid* types, - size_t types_count) - { - if (proc != 0) - { - switch (sk) - { - case statement_select: - process_select (text_copy_, - text_, - &proc->bind->buffer, proc->count, sizeof (bind), - '"', '"', - optimize); - break; - case statement_insert: - process_insert (text_copy_, - text_, - &proc->bind->buffer, proc->count, sizeof (bind), - '$'); - break; - case statement_update: - process_update (text_copy_, - text_, - &proc->bind->buffer, proc->count, sizeof (bind), - '$'); - break; - case statement_delete: - assert (false); - } - - text_ = text_copy_.c_str (); - } - - // Empty statement. - // - if (*text_ == '\0') - { - deallocated_ = true; - return; - } - - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->prepare (conn_, *this); - } - - auto_handle h ( - PQprepare (conn_.handle (), - name_, - text_, - static_cast (types_count), - types)); - - if (!is_good_result (h)) - translate_error (conn_, h); - - // - // If any code after this line throws, the statement will be leaked - // (on the server) since deallocate() won't be called for it. - // - } - - const char* statement:: - text () const - { - return text_; - } - - template - static inline T* - offset (T* base, size_t count, size_t size) - { - return reinterpret_cast ( - reinterpret_cast (base) + count * size); - } - - void statement:: - bind_param (native_binding& ns, const binding& bs, size_t pos) - { - assert (ns.count == bs.count); - - for (size_t i (0); i < ns.count; ++i) - { - const bind& b (bs.bind[i]); - - ns.formats[i] = 1; - - bool* n (b.is_null != 0 ? offset (b.is_null, pos, bs.skip) : 0); - - if ((n != 0 && *n) || b.buffer == 0) // Handle NULL entries. - { - ns.values[i] = 0; - ns.lengths[i] = 0; - continue; - } - - ns.values[i] = static_cast (offset (b.buffer, pos, bs.skip)); - - size_t l (0); - - switch (b.type) - { - case bind::boolean_: - { - l = sizeof (bool); - break; - } - case bind::smallint: - { - l = sizeof (short); - break; - } - case bind::integer: - { - l = sizeof (int); - break; - } - case bind::bigint: - { - l = sizeof (long long); - break; - } - case bind::real: - { - l = sizeof (float); - break; - } - case bind::double_: - { - l = sizeof (double); - break; - } - case bind::date: - { - l = sizeof (int); - break; - } - case bind::time: - case bind::timestamp: - { - l = sizeof (long long); - break; - } - case bind::numeric: - case bind::text: - case bind::bytea: - case bind::varbit: - { - // In this case b.buffer is a pointer to pointer to buffer so we - // need to chase one level. - // - ns.values[i] = static_cast ( - *reinterpret_cast (ns.values[i])); - } - // Fall through. - case bind::bit: - { - l = *offset (b.size, pos, bs.skip); - break; - } - case bind::uuid: - { - // UUID is a 16-byte sequence. - // - l = 16; - break; - } - } - - ns.lengths[i] = static_cast (l); - } - } - - bool statement:: - bind_result (const binding& bs, - PGresult* result, - size_t row, - bool truncated, - size_t pos) - { - bool r (true); - int col_count (PQnfields (result)); - - int col (0); - for (size_t i (0); i != bs.count && col != col_count; ++i) - { - const bind& b (bs.bind[i]); - - if (b.buffer == 0) // Skip NULL entries. - continue; - - int c (col++); - - { - bool* t (b.truncated != 0 ? offset (b.truncated, pos, bs.skip) : 0); - - if (truncated && (t == 0 || !*t)) - continue; - - if (t != 0) - *t = false; - } - - // Check for NULL unless we are reloading a truncated result. - // - if (!truncated) - { - bool* n (offset (b.is_null, pos, bs.skip)); - - *n = PQgetisnull (result, static_cast (row), c) == 1; - - if (*n) - continue; - } - - void* buf (offset (b.buffer, pos, bs.skip)); - - const char* v (PQgetvalue (result, static_cast (row), c)); - - switch (b.type) - { - case bind::boolean_: - { - *static_cast (buf) = *reinterpret_cast (v); - break; - } - case bind::smallint: - case bind::integer: - case bind::bigint: - { - // If we are dealing with a custom schema, we may have a - // difference in the integer widths. Note also that we have - // to go to our endianness and back in order for casts to - // work properly. - // - long long i (0); - - switch (PQftype (result, c)) - { - case int2_oid: - { - i = endian_traits::ntoh (*reinterpret_cast (v)); - break; - } - case int4_oid: - { - i = endian_traits::ntoh (*reinterpret_cast (v)); - break; - } - case int8_oid: - { - i = endian_traits::ntoh ( - *reinterpret_cast (v)); - break; - } - default: - { - assert (false); // Column in the database is not an integer. - break; - } - } - - switch (b.type) - { - case bind::smallint: - { - *static_cast (buf) = - endian_traits::hton (static_cast (i)); - break; - } - case bind::integer: - { - *static_cast (buf) = - endian_traits::hton (static_cast (i)); - break; - } - case bind::bigint: - { - *static_cast (buf) = endian_traits::hton (i); - break; - } - default: - break; - } - - break; - } - case bind::real: - { - *static_cast (buf) = *reinterpret_cast (v); - break; - } - case bind::double_: - { - *static_cast (buf) = *reinterpret_cast (v); - break; - } - case bind::date: - { - *static_cast (buf) = *reinterpret_cast (v); - break; - } - case bind::time: - case bind::timestamp: - { - *static_cast (buf) = - *reinterpret_cast (v); - break; - } - case bind::numeric: - case bind::text: - case bind::bytea: - case bind::bit: - case bind::varbit: - { - // Currently this is neither supported (due to capacity) nor used - // in batches. - // -#ifdef LIBPGSQL_EXTRA_CHECKS - assert (pos == 0); -#endif - - *b.size = static_cast ( - PQgetlength (result, static_cast (row), c)); - - if (b.capacity < *b.size) - { - if (b.truncated) - *b.truncated = true; - - r = false; - continue; - } - - // In these cases b.buffer is a pointer to pointer to buffer so we - // need to chase one level. - // - if (b.type != bind::bit) - buf = *static_cast (buf); - - memcpy (buf, v, *b.size); - break; - } - case bind::uuid: - { - memcpy (buf, v, 16); - break; - } - } - } - - // Make sure that the number of columns in the result returned by - // the database matches the number that we expect. A common cause - // of this assertion is a native view with a number of data members - // not matching the number of columns in the SELECT-list. - // - assert (col == col_count); - - return r; - } - -#if defined(LIBPQ_HAS_PIPELINING) && !defined(_WIN32) - - // Note that this function always marks the connection as failed. - // - static void - translate_connection_error (connection& conn) - { - const char* m (PQerrorMessage (conn.handle ())); - - if (PQstatus (conn.handle ()) == CONNECTION_BAD) - { - conn.mark_failed (); - throw connection_lost (); - } - else - { - conn.mark_failed (); - throw database_exception (m != 0 ? m : "bad connection state"); - } - } - - // A RAII object for PGconn's non-blocking pipeline mode. - // - struct pipeline - { - connection& conn; - int sock; - - explicit - pipeline (connection& c) - : conn (c) - { - PGconn* ch (conn.handle ()); - - if ((sock = PQsocket (ch)) == -1 || - PQsetnonblocking (ch, 1) == -1 || - PQenterPipelineMode (ch) == 0) - { - translate_connection_error (conn); - } - } - - void - close (bool throw_ = true) - { - if (!conn.failed ()) - { - PGconn* ch (conn.handle ()); - - if (PQexitPipelineMode (ch) == 0 || - PQsetnonblocking (ch, 0) == -1) - { - if (throw_) - translate_connection_error (conn); - else - conn.mark_failed (); - } - } - } - - ~pipeline () - { - close (false); - } - - pair - wait (bool write, bool throw_ = true) - { - fd_set wds; - fd_set rds; - - for (;;) - { - if (write) - { - FD_ZERO (&wds); - FD_SET (sock, &wds); - } - - FD_ZERO (&rds); - FD_SET (sock, &rds); - - if (select (sock + 1, &rds, write ? &wds : 0, 0, 0) != -1) - break; - - if (errno != EINTR) - { - if (throw_) - translate_connection_error (conn); - else - { - conn.mark_failed (); - return pair (false, false); - } - } - } - - return pair (FD_ISSET (sock, &rds), - write && FD_ISSET (sock, &wds)); - } - }; - - // A RAII object for recovering from an error in a pipeline. - // - // Specifically, it reads and discards results until reaching - // PGRES_PIPELINE_SYNC. - // - struct pipeline_recovery - { - pipeline_recovery (pipeline& pl, bool wdone, bool sync) - : pl_ (&pl), wdone_ (wdone), sync_ (sync) - { - } - - ~pipeline_recovery () - { - if (pl_ != 0 && !pl_->conn.failed ()) - { - PGconn* ch (pl_->conn.handle ()); - - // This code runs as part of stack unwinding caused by an exception - // so if we encounter an error, we "upgrade" the existing exception - // by marking the connection as failed. - // - // The rest is essentially a special version of execute() below. - // - // Note that on the first iteration we may still have results from - // the previous call to PQconsumeInput() (and these results may - // be the entire outstanding sequence, in which case calling wait() - // will block indefinitely). - // - for (bool first (true);; first = false) - { - if (sync_) - { - assert (!wdone_); - - if (PQpipelineSync (ch) == 0) - break; - - sync_ = false; - } - - pair r (false, false); - - if (!first) - { - r = pl_->wait (!wdone_); - if (!r.first && !r.second) - break; - } - - if (r.first /* read */ || first) - { - if (r.first && PQconsumeInput (ch) == 0) - break; - - while (PQisBusy (ch) == 0) - { - auto_handle res (PQgetResult (ch)); - - // We should only get NULLs as well as PGRES_PIPELINE_ABORTED - // finished with PGRES_PIPELINE_SYNC. - // - if (res != 0) - { - ExecStatusType stat (PQresultStatus (res)); - - if (stat == PGRES_PIPELINE_SYNC) - return; - - assert (stat == PGRES_PIPELINE_ABORTED); - } - } - } - - if (r.second /* write */) - { - int r (PQflush (ch)); - if (r == -1) - break; - - if (r == 0) - wdone_ = true; - } - } - - pl_->conn.mark_failed (); - } - } - - void - cancel () - { - pl_ = 0; - } - - private: - pipeline* pl_; - bool wdone_; - bool sync_; - }; - - size_t statement:: - execute (const binding& param, - native_binding& native_param, - size_t n, - multiple_exceptions& mex, - bool (*process) (size_t, PGresult*, bool, void*), - void* data) - { - size_t i (0); // Parameter set being attempted. - mex.current (i); - - PGconn* ch (conn_.handle ()); - - pipeline pl (conn_); - - // True if we've written and read everything, respectively. - // - bool wdone (false), rdone (false); - - for (size_t wn (0), rn (0); !rdone; ) - { - // Note that there is a special version of this code above in - // ~pipeline_recovery(). - // - pair r (pl.wait (!wdone)); - - // Note that once we start the pipeline, any call that may throw - // without marking the connection as failed should be guarded by - // pipeline_recovery. - - // Try to minimize the chance of blocking the server by first - // processing the result and then sending more queries. - // - if (r.first /* read */) - { - if (PQconsumeInput (ch) == 0) - translate_connection_error (conn_); - - // Note that PQisBusy() will return 0 (and subsequent PQgetResult() - // -- NULL) if we have consumed all the results for the queries that - // we have sent so far. Thus the (wn > rn) condition. Note that for - // this to work correctly we have to count the PQpipelineSync() call - // below as one of the queries (since it has a separate result). - // - while (wn > rn && PQisBusy (ch) == 0) - { - auto_handle res (PQgetResult (ch)); - - ExecStatusType stat (PGRES_FATAL_ERROR); - bool gr (is_good_result (res, &stat)); - - if (stat == PGRES_PIPELINE_SYNC) - { - assert (wdone && rn == n); - rdone = true; - break; - } - - assert (rn != n); - ++rn; - - if (stat != PGRES_PIPELINE_ABORTED) - { - // translate_error() may throw an exception (e.g., deadlock) - // without marking the connection as failed. - // - { - pipeline_recovery plr (pl, wdone, wn < n); - - if (!process (i, res, gr, data)) - translate_error (conn_, res, i, &mex); - - plr.cancel (); - } - - mex.attempted (++i); - mex.current (i); - } - else - { - // Should we treat PGRES_PIPELINE_ABORTED entries as attempted - // or not? While we did issue PQsendQueryPrepared() for them, - // the server tells us that it did not attemp to execute them. - // So it feels like they should not be treated as attempted. - // - // Note that for this to fit into out multiple_exceptions model, - // such an incomplete batch should be fatal (otherwise we could - // end up with unattempted "holes"). This is currently the case - // for errors handled by translate_error() but not necessarily - // the case for those handled by the process function (e.g., - // duplicate id handled by process_insert_result() below). So in - // a somewhat hackish way we assume the error (e.g., duplicate - // id) will always be translated to an exception and pre-mark - // multiple_exceptions as fatal. - // - mex.fatal (true); - } - - // We get a NULL result after each query result. - // - { - PGresult* end (PQgetResult (ch)); - assert (end == 0); - } - } - } - - if (r.second /* write */) - { - // Send queries until we get blocked (write-biased). This feels like - // a better overall strategy to keep the server busy compared to - // sending one query at a time and then re-checking if there is - // anything to read because the results of INSERT/UPDATE/DELETE are - // presumably small and quite a few of them can get buffered before - // the server gets blocked. - // - for (;;) - { - if (wn < n) - { - bind_param (native_param, param, wn); - - if (PQsendQueryPrepared (ch, - name_, - static_cast (native_param.count), - native_param.values, - native_param.lengths, - native_param.formats, - 1) == 0) - translate_connection_error (conn_); - - if (++wn == n) - { - if (PQpipelineSync (ch) == 0) - translate_connection_error (conn_); - - // Count as one of the queries since it has a separate result. - // - ++wn; - } - } - - // PQflush() result: - // - // 0 -- success (queue is now empty) - // 1 -- blocked - // -1 -- error - // - int r (PQflush (ch)); - if (r == -1) - translate_connection_error (conn_); - - if (r == 0) - { - if (wn < n) - { - // If we continue here, then we are write-biased. And if we - // break, then we are read-biased. - // -#ifdef LIBPGSQL_READ_BIASED - break; -#else - continue; -#endif - } - - wdone = true; - } - - break; // Blocked or done. - } - } - } - - pl.close (); - return i; - } -#endif - - // - // select_statement - // - - select_statement:: - ~select_statement () - { - } - - select_statement:: - select_statement (connection_type& conn, - const std::string& name, - const std::string& text, - bool process, - bool optimize, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param, - binding& result) - : statement (conn, - name, text, statement_select, - (process ? &result : 0), optimize, - types, types_count), - param_ (¶m), - native_param_ (&native_param), - result_ (result), - row_count_ (0), - current_row_ (0) - { - } - - select_statement:: - select_statement (connection_type& conn, - const char* name, - const char* text, - bool process, - bool optimize, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param, - binding& result, - bool copy) - : statement (conn, - name, text, statement_select, - (process ? &result : 0), optimize, copy, - types, types_count), - param_ (¶m), - native_param_ (&native_param), - result_ (result), - row_count_ (0), - current_row_ (0) - { - } - - select_statement:: - select_statement (connection_type& conn, - const std::string& name, - const std::string& text, - bool process, - bool optimize, - binding& result) - : statement (conn, - name, text, statement_select, - (process ? &result : 0), optimize, - 0, 0), - param_ (0), - native_param_ (0), - result_ (result), - row_count_ (0), - current_row_ (0) - { - } - - select_statement:: - select_statement (connection_type& conn, - const char* name, - const char* text, - bool process, - bool optimize, - binding& result, - bool copy) - : statement (conn, - name, text, statement_select, - (process ? &result : 0), optimize, copy, - 0, 0), - param_ (0), - native_param_ (0), - result_ (result), - row_count_ (0), - current_row_ (0) - { - } - - select_statement:: - select_statement (connection_type& conn, - const std::string& name, - const std::string& text, - bool process, - bool optimize, - const Oid* types, - std::size_t types_count, - native_binding& native_param, - binding& result) - : statement (conn, - name, text, statement_select, - (process ? &result : 0), optimize, - types, types_count), - param_ (0), - native_param_ (&native_param), - result_ (result), - row_count_ (0), - current_row_ (0) - { - } - - void select_statement:: - execute () - { - handle_.reset (); - - if (param_ != 0) - bind_param (*native_param_, *param_); - - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->execute (conn_, *this); - } - - bool in (native_param_ != 0); - - handle_.reset ( - PQexecPrepared (conn_.handle (), - name_, - in ? static_cast (native_param_->count) : 0, - in ? native_param_->values : 0, - in ? native_param_->lengths : 0, - in ? native_param_->formats : 0, - 1)); - - if (!is_good_result (handle_)) - translate_error (conn_, handle_); - - row_count_ = static_cast (PQntuples (handle_)); - current_row_ = 0; - } - - void select_statement:: - free_result () - { - handle_.reset (); - row_count_ = 0; - current_row_ = 0; - } - - bool select_statement:: - next () - { - if (current_row_ <= row_count_) - ++current_row_; - - return current_row_ <= row_count_; - } - - select_statement::result select_statement:: - load () - { - if (current_row_ > row_count_) - return no_data; - - assert (current_row_ > 0); - return bind_result (result_, handle_, current_row_ - 1) - ? success - : truncated; - } - - void select_statement:: - reload () - { - assert (current_row_ > 0); - assert (current_row_ <= row_count_); - - if (!bind_result (result_, handle_, current_row_ - 1, true)) - assert (false); - } - - // - // insert_statement - // - - insert_statement:: - ~insert_statement () - { - } - - insert_statement:: - insert_statement (connection_type& conn, - const string& name, - const string& text, - bool process, - const Oid* types, - size_t types_count, - binding& param, - native_binding& native_param, - binding* returning) - : statement (conn, - name, text, statement_insert, - (process ? ¶m : 0), false, - types, types_count), - param_ (param), - native_param_ (native_param), - returning_ (returning) - { - if (returning_ != 0) - assert (returning_->count == 1); - } - - insert_statement:: - insert_statement (connection_type& conn, - const char* name, - const char* text, - bool process, - const Oid* types, - size_t types_count, - binding& param, - native_binding& native_param, - binding* returning, - bool copy) - : statement (conn, - name, text, statement_insert, - (process ? ¶m : 0), false, copy, - types, types_count), - param_ (param), - native_param_ (native_param), - returning_ (returning) - { - if (returning_ != 0) - assert (returning_->count == 1); - } - - bool insert_statement:: - execute () - { - bind_param (native_param_, param_); - - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->execute (conn_, *this); - } - - auto_handle h ( - PQexecPrepared (conn_.handle (), - name_, - static_cast (native_param_.count), - native_param_.values, - native_param_.lengths, - native_param_.formats, - 1)); - - ExecStatusType stat (PGRES_FATAL_ERROR); - - if (!is_good_result (h, &stat)) - { - // An auto-assigned object id should never cause a duplicate - // primary key. - // - if (returning_ == 0 && stat == PGRES_FATAL_ERROR) - { - const char* ss (PQresultErrorField (h, PG_DIAG_SQLSTATE)); - - if (ss != 0 && strcmp (ss, "23505") == 0) - return false; - } - - translate_error (conn_, h); - } - - if (returning_ != 0) - bind_result (*returning_, h, 0); - - return true; - } - -#if defined(LIBPQ_HAS_PIPELINING) && !defined(_WIN32) - - struct insert_data - { - binding& param; - binding* returning; - }; - - static bool - process_insert_result (size_t i, PGresult* r, bool gr, void* data) - { - insert_data& d (*static_cast (data)); - - unsigned long long& s (d.param.status[i]); - s = 1; - - if (gr) - { - // Note that the result can never be truncated. - // - if (d.returning != 0) - statement::bind_result (*d.returning, r, 0, false, i); - } - else - { - // An auto-assigned object id should never cause a duplicate - // primary key. - // - if (d.returning == 0 && - r != 0 && PQresultStatus (r) == PGRES_FATAL_ERROR) - { - // Note that statement::execute() assumes that this will eventually - // be translated to an entry in multiple_exceptions. - // - const char* ss (PQresultErrorField (r, PG_DIAG_SQLSTATE)); - - if (ss != 0 && strcmp (ss, "23505") == 0) - s = 0; - } - - if (s == 1) - return false; - } - - return true; - } - - size_t insert_statement:: - execute (size_t n, multiple_exceptions& mex) - { - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->execute (conn_, *this); - } - - insert_data d {param_, returning_}; - - return statement::execute ( - param_, native_param_, n, mex, &process_insert_result, &d); - } -#endif - - // - // update_statement - // - - update_statement:: - ~update_statement () - { - } - - update_statement:: - update_statement (connection_type& conn, - const string& name, - const string& text, - bool process, - const Oid* types, - size_t types_count, - binding& param, - native_binding& native_param) - : statement (conn, - name, text, statement_update, - (process ? ¶m : 0), false, - types, types_count), - param_ (param), - native_param_ (native_param) - { - } - - update_statement:: - update_statement (connection_type& conn, - const char* name, - const char* text, - bool process, - const Oid* types, - size_t types_count, - binding& param, - native_binding& native_param, - bool copy) - : statement (conn, - name, text, statement_update, - (process ? ¶m : 0), false, copy, - types, types_count), - param_ (param), - native_param_ (native_param) - { - } - - unsigned long long update_statement:: - execute () - { - bind_param (native_param_, param_); - - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->execute (conn_, *this); - } - - auto_handle h ( - PQexecPrepared (conn_.handle (), - name_, - static_cast (native_param_.count), - native_param_.values, - native_param_.lengths, - native_param_.formats, - 1)); - - if (!is_good_result (h)) - translate_error (conn_, h); - - return affected_row_count (h); - } - -#if defined(LIBPQ_HAS_PIPELINING) && !defined(_WIN32) - - static bool - process_update_result (size_t i, PGresult* r, bool gr, void* data) - { - binding& param (*static_cast (data)); - - unsigned long long& s (param.status[i]); - - if (gr) - { - s = affected_row_count (r); - return true; - } - else - { - s = update_statement::result_unknown; - return false; - } - } - - size_t update_statement:: - execute (size_t n, multiple_exceptions& mex) - { - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->execute (conn_, *this); - } - - return statement::execute ( - param_, native_param_, n, mex, &process_update_result, ¶m_); - } -#endif - - // - // delete_statement - // - - delete_statement:: - ~delete_statement () - { - } - - delete_statement:: - delete_statement (connection_type& conn, - const string& name, - const string& text, - const Oid* types, - size_t types_count, - binding& param, - native_binding& native_param) - : statement (conn, - name, text, statement_delete, - 0, false, - types, types_count), - param_ (¶m), - native_param_ (native_param) - { - } - - delete_statement:: - delete_statement (connection_type& conn, - const char* name, - const char* text, - const Oid* types, - size_t types_count, - binding& param, - native_binding& native_param, - bool copy) - : statement (conn, - name, text, statement_delete, - 0, false, copy, - types, types_count), - param_ (¶m), - native_param_ (native_param) - { - } - - delete_statement:: - delete_statement (connection_type& conn, - const string& name, - const string& text, - const Oid* types, - size_t types_count, - native_binding& native_param) - : statement (conn, - name, text, statement_delete, - 0, false, - types, types_count), - param_ (0), - native_param_ (native_param) - { - } - - unsigned long long delete_statement:: - execute () - { - if (param_ != 0) - bind_param (native_param_, *param_); - - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->execute (conn_, *this); - } - - auto_handle h ( - PQexecPrepared (conn_.handle (), - name_, - static_cast (native_param_.count), - native_param_.values, - native_param_.lengths, - native_param_.formats, - 1)); - - if (!is_good_result (h)) - translate_error (conn_, h); - - return affected_row_count (h); - } - -#if defined(LIBPQ_HAS_PIPELINING) && !defined(_WIN32) - - static bool - process_delete_result (size_t i, PGresult* r, bool gr, void* data) - { - binding& param (*static_cast (data)); - - unsigned long long& s (param.status[i]); - - if (gr) - { - s = affected_row_count (r); - return true; - } - else - { - s = delete_statement::result_unknown; - return false; - } - } - - size_t delete_statement:: - execute (size_t n, multiple_exceptions& mex) - { - assert (param_ != 0); - - { - odb::tracer* t; - if ((t = conn_.transaction_tracer ()) || - (t = conn_.tracer ()) || - (t = conn_.database ().tracer ())) - t->execute (conn_, *this); - } - - return statement::execute ( - *param_, native_param_, n, mex, &process_delete_result, param_); - } -#endif - } -} diff --git a/odb/pgsql/statement.hxx b/odb/pgsql/statement.hxx deleted file mode 100644 index 139d2d6..0000000 --- a/odb/pgsql/statement.hxx +++ /dev/null @@ -1,450 +0,0 @@ -// file : odb/pgsql/statement.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_STATEMENT_HXX -#define ODB_PGSQL_STATEMENT_HXX - -#include - -#include -#include // std::size_t - -#include - -#include -#include -#include -#include // PGresult -#include -#include - -#include - -namespace odb -{ - namespace pgsql - { - class connection; - - class LIBODB_PGSQL_EXPORT statement: public odb::statement - { - public: - typedef pgsql::connection connection_type; - - virtual - ~statement () = 0; - - const char* - name () const - { - return name_; - } - - virtual const char* - text () const; - - virtual connection_type& - connection () - { - return conn_; - } - - // A statement can be empty. This is used to handle situations - // where a SELECT or UPDATE statement ends up not having any - // columns after processing. An empty statement cannot be - // executed. - // - bool - empty () const - { - return *text_ == '\0'; - } - - void - deallocate (); - - // Adapt an ODB binding to a native PostgreSQL parameter binding. If pos - // is not 0, then bind the parameter set at this position in a batch. - // - static void - bind_param (native_binding&, const binding&, std::size_t pos = 0); - - // Populate an ODB binding given a PostgreSQL result. If the truncated - // argument is true, then only truncated columns are extracted. Return - // true if all the data was extracted successfully and false if one or - // more columns were truncated. If pos is not 0, then populate the - // parameter set at this position in a batch. - // - static bool - bind_result (const binding&, - PGresult*, - std::size_t row, - bool truncated = false, - std::size_t pos = 0); - - protected: - // We keep two versions to take advantage of std::string COW. - // - statement (connection_type&, - const std::string& name, - const std::string& text, - statement_kind, - const binding* process, - bool optimize, - const Oid* types, - std::size_t types_count); - - statement (connection_type&, - const char* name, - const char* text, - statement_kind, - const binding* process, - bool optimize, - bool copy_name_text, - const Oid* types, - std::size_t types_count); - - // Bulk execute implementation. - // - std::size_t - execute (const binding& param, - native_binding& native_param, - std::size_t n, - multiple_exceptions&, - bool (*process) (size_t i, PGresult*, bool good, void* data), - void* data); - - private: - void - init (statement_kind, - const binding* process, - bool optimize, - const Oid* types, - std::size_t types_count); - - protected: - connection_type& conn_; - - std::string name_copy_; - const char* name_; - - std::string text_copy_; - const char* text_; - - private: - bool deallocated_; - }; - - class LIBODB_PGSQL_EXPORT select_statement: public statement - { - public: - virtual - ~select_statement (); - - select_statement (connection_type& conn, - const std::string& name, - const std::string& text, - bool process_text, - bool optimize_text, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param, - binding& result); - - select_statement (connection_type& conn, - const char* name, - const char* stmt, - bool process_text, - bool optimize_text, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param, - binding& result, - bool copy_name_text = true); - - select_statement (connection_type& conn, - const std::string& name, - const std::string& text, - bool process_text, - bool optimize_text, - binding& result); - - select_statement (connection_type& conn, - const char* name, - const char* text, - bool process_text, - bool optimize_text, - binding& result, - bool copy_name_text = true); - - select_statement (connection_type& conn, - const std::string& name, - const std::string& text, - bool process_text, - bool optimize_text, - const Oid* types, - std::size_t types_count, - native_binding& native_param, - binding& result); - - // Common select interface expected by the generated code. - // - public: - enum result - { - success, - no_data, - truncated - }; - - void - execute (); - - void - cache () const - { - } - - std::size_t - result_size () const - { - return row_count_; - } - - // Load next row columns into bound buffers. - // - result - fetch () - { - return next () ? load () : no_data; - } - - // Reload truncated columns into bound buffers. - // - void - refetch () - { - reload (); - } - - // Free the result set. - // - void - free_result (); - - // Finer grained control of PostgreSQL-specific interface that - // splits fetch() into next() and load(). - // - public: - bool - next (); - - result - load (); - - void - reload (); - - private: - select_statement (const select_statement&); - select_statement& operator= (const select_statement&); - - private: - binding* param_; - native_binding* native_param_; - - binding& result_; - - auto_handle handle_; - std::size_t row_count_; - std::size_t current_row_; - }; - - struct LIBODB_PGSQL_EXPORT auto_result - { - explicit auto_result (select_statement& s): s_ (s) {} - ~auto_result () {s_.free_result ();} - - private: - auto_result (const auto_result&); - auto_result& operator= (const auto_result&); - - private: - select_statement& s_; - }; - - class LIBODB_PGSQL_EXPORT insert_statement: public statement - { - public: - virtual - ~insert_statement (); - - insert_statement (connection_type& conn, - const std::string& name, - const std::string& text, - bool process_text, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param, - binding* returning); - - insert_statement (connection_type& conn, - const char* name, - const char* text, - bool process_text, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param, - binding* returning, - bool copy_name_text = true); - - // Return true if successful and false if the row is a duplicate. - // All other errors are reported by throwing exceptions. - // - bool - execute (); - - // Return the number of parameter sets (out of n) that were attempted. - // - std::size_t - execute (std::size_t n, multiple_exceptions&); - - // Return true if successful and false if this row is a duplicate. - // All other errors are reported via exceptions. - // - bool - result (std::size_t i) - { - return param_.status[i] != 0; - } - - private: - insert_statement (const insert_statement&); - insert_statement& operator= (const insert_statement&); - - private: - binding& param_; - native_binding& native_param_; - binding* returning_; - }; - - class LIBODB_PGSQL_EXPORT update_statement: public statement - { - public: - virtual - ~update_statement (); - - update_statement (connection_type& conn, - const std::string& name, - const std::string& text, - bool process_text, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param); - - update_statement (connection_type& conn, - const char* name, - const char* text, - bool process_text, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param, - bool copy_name_text = true); - - unsigned long long - execute (); - - // Return the number of parameter sets (out of n) that were attempted. - // - std::size_t - execute (std::size_t n, multiple_exceptions&); - - // Return the number of rows affected (updated) by the parameter - // set. All errors are reported by throwing exceptions. - // - static const unsigned long long result_unknown = ~0ULL; - - unsigned long long - result (std::size_t i) - { - return param_.status[i]; - } - - private: - update_statement (const update_statement&); - update_statement& operator= (const update_statement&); - - private: - binding& param_; - native_binding& native_param_; - }; - - class LIBODB_PGSQL_EXPORT delete_statement: public statement - { - public: - virtual - ~delete_statement (); - - delete_statement (connection_type& conn, - const std::string& name, - const std::string& text, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param); - - delete_statement (connection_type& conn, - const char* name, - const char* text, - const Oid* types, - std::size_t types_count, - binding& param, - native_binding& native_param, - bool copy_name_text = true); - - delete_statement (connection_type& conn, - const std::string& name, - const std::string& text, - const Oid* types, - std::size_t types_count, - native_binding& native_param); - - unsigned long long - execute (); - - // Return the number of parameter sets (out of n) that were attempted. - // - std::size_t - execute (std::size_t n, multiple_exceptions&); - - // Return the number of rows affected (deleted) by the parameter - // set. All errors are reported by throwing exceptions. - // - static const unsigned long long result_unknown = ~0ULL; - - unsigned long long - result (std::size_t i) - { - return param_->status[i]; - } - - private: - delete_statement (const delete_statement&); - delete_statement& operator= (const delete_statement&); - - private: - binding* param_; - native_binding& native_param_; - }; - } -} - -#include - -#endif // ODB_PGSQL_STATEMENT_HXX diff --git a/odb/pgsql/statements-base.cxx b/odb/pgsql/statements-base.cxx deleted file mode 100644 index 0e72555..0000000 --- a/odb/pgsql/statements-base.cxx +++ /dev/null @@ -1,15 +0,0 @@ -// file : odb/pgsql/statements-base.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -namespace odb -{ - namespace pgsql - { - statements_base:: - ~statements_base () - { - } - } -} diff --git a/odb/pgsql/statements-base.hxx b/odb/pgsql/statements-base.hxx deleted file mode 100644 index 8b45bdc..0000000 --- a/odb/pgsql/statements-base.hxx +++ /dev/null @@ -1,63 +0,0 @@ -// file : odb/pgsql/statements-base.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_STATEMENTS_BASE_HXX -#define ODB_PGSQL_STATEMENTS_BASE_HXX - -#include - -#include -#include - -#include -#include -#include - -#include - -namespace odb -{ - namespace pgsql - { - class LIBODB_PGSQL_EXPORT statements_base: public details::shared_base - { - public: - typedef pgsql::connection connection_type; - - connection_type& - connection () - { - return conn_; - } - - // Schema version. database::schema_version_migration() is thread- - // safe which means it is also slow. Cache the result in statements - // so we can avoid the mutex lock. This is thread-safe since if the - // version is updated, then the statements cache will be expired. - // - const schema_version_migration& - version_migration (const char* name = "") const - { - if (svm_ == 0) - svm_ = &conn_.database ().schema_version_migration (name); - - return *svm_; - } - - public: - virtual - ~statements_base (); - - protected: - statements_base (connection_type& conn): conn_ (conn), svm_ (0) {} - - protected: - connection_type& conn_; - mutable const schema_version_migration* svm_; - }; - } -} - -#include - -#endif // ODB_PGSQL_STATEMENTS_BASE_HXX diff --git a/odb/pgsql/tracer.cxx b/odb/pgsql/tracer.cxx deleted file mode 100644 index 48e0cf8..0000000 --- a/odb/pgsql/tracer.cxx +++ /dev/null @@ -1,60 +0,0 @@ -// file : odb/pgsql/tracer.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - tracer:: - ~tracer () - { - } - - void tracer:: - prepare (connection&, const statement&) - { - } - - void tracer:: - execute (connection& c, const statement& s) - { - execute (c, s.text ()); - } - - void tracer:: - deallocate (connection&, const statement&) - { - } - - void tracer:: - prepare (odb::connection& c, const odb::statement& s) - { - prepare (static_cast (c), - static_cast (s)); - } - - void tracer:: - execute (odb::connection& c, const odb::statement& s) - { - execute (static_cast (c), - static_cast (s)); - } - - void tracer:: - execute (odb::connection& c, const char* s) - { - execute (static_cast (c), s); - } - - void tracer:: - deallocate (odb::connection& c, const odb::statement& s) - { - deallocate (static_cast (c), - static_cast (s)); - } - } -} diff --git a/odb/pgsql/tracer.hxx b/odb/pgsql/tracer.hxx deleted file mode 100644 index 89cda1c..0000000 --- a/odb/pgsql/tracer.hxx +++ /dev/null @@ -1,61 +0,0 @@ -// file : odb/pgsql/tracer.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_TRACER_HXX -#define ODB_PGSQL_TRACER_HXX - -#include - -#include - -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - class LIBODB_PGSQL_EXPORT tracer: private odb::tracer - { - public: - virtual - ~tracer (); - - virtual void - prepare (connection&, const statement&); - - virtual void - execute (connection&, const statement&); - - virtual void - execute (connection&, const char* statement) = 0; - - virtual void - deallocate (connection&, const statement&); - - private: - // Allow these classes to convert pgsql::tracer to odb::tracer. - // - friend class database; - friend class connection; - friend class transaction; - - virtual void - prepare (odb::connection&, const odb::statement&); - - virtual void - execute (odb::connection&, const odb::statement&); - - virtual void - execute (odb::connection&, const char* statement); - - virtual void - deallocate (odb::connection&, const odb::statement&); - }; - } -} - -#include - -#endif // ODB_PGSQL_TRACER_HXX diff --git a/odb/pgsql/traits-calls.hxx b/odb/pgsql/traits-calls.hxx deleted file mode 100644 index 419c7b2..0000000 --- a/odb/pgsql/traits-calls.hxx +++ /dev/null @@ -1,214 +0,0 @@ -// file : odb/pgsql/traits-calls.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_TRAITS_CALLS_HXX -#define ODB_PGSQL_TRAITS_CALLS_HXX - -#include - -#include // std::size_t - -#include -#include -#include - -#include -#include - -namespace odb -{ - namespace pgsql - { - // - // object_traits_calls - // - - template ::versioned> - struct object_traits_calls; - - template - struct object_traits_calls - { - typedef object_traits_impl traits; - typedef typename traits::image_type image_type; - typedef pgsql::bind bind_type; - - object_traits_calls (const schema_version_migration*) {} - - const schema_version_migration* - version () const {return 0;} - - static bool - grow (image_type& i, bool* t) - { - return traits::grow (i, t); - } - - static void - bind (bind_type* b, image_type& i, statement_kind sk) - { - traits::bind (b, i, sk); - } - - // Poly-derived version. - // - static void - bind (bind_type* b, - const bind_type* id, std::size_t id_size, - image_type& i, - statement_kind sk) - { - traits::bind (b, id, id_size, i, sk); - } - - static void - init (T& o, const image_type& i, odb::database* db) - { - traits::init (o, i, db); - } - - static bool - find_ (typename traits::statements_type& sts, - const typename traits::id_type* id) - { - return traits::find_ (sts, id); - } - - static void - load_ (typename traits::statements_type& sts, T& o, bool reload) - { - return traits::load_ (sts, o, reload); - } - }; - - template - struct object_traits_calls - { - typedef object_traits_impl traits; - typedef typename traits::image_type image_type; - typedef pgsql::bind bind_type; - - object_traits_calls (const schema_version_migration* svm): svm_ (*svm) {} - - const schema_version_migration* - version () const {return &svm_;} - - bool - grow (image_type& i, bool* t) const - { - return traits::grow (i, t, svm_); - } - - void - bind (bind_type* b, image_type& i, statement_kind sk) const - { - traits::bind (b, i, sk, svm_); - } - - // Poly-derived version. - // - void - bind (bind_type* b, - const bind_type* id, std::size_t id_size, - image_type& i, - statement_kind sk) const - { - traits::bind (b, id, id_size, i, sk, svm_); - } - - void - init (T& o, const image_type& i, odb::database* db) const - { - traits::init (o, i, db, svm_); - } - - bool - find_ (typename traits::statements_type& sts, - const typename traits::id_type* id) const - { - return traits::find_ (sts, id, svm_); - } - - void - load_ (typename traits::statements_type& sts, T& o, bool reload) const - { - return traits::load_ (sts, o, reload, svm_); - } - - private: - const schema_version_migration& svm_; - }; - - // - // view_traits_calls - // - - template ::versioned> - struct view_traits_calls; - - template - struct view_traits_calls - { - typedef view_traits_impl traits; - typedef typename traits::image_type image_type; - typedef pgsql::bind bind_type; - - view_traits_calls (const schema_version_migration*) {} - - static bool - grow (image_type& i, bool* t) - { - return traits::grow (i, t); - } - - static void - bind (bind_type* b, image_type& i) - { - traits::bind (b, i); - } - - static void - init (T& o, const image_type& i, odb::database* db) - { - traits::init (o, i, db); - } - }; - - template - struct view_traits_calls - { - typedef view_traits_impl traits; - typedef typename traits::image_type image_type; - typedef pgsql::bind bind_type; - - view_traits_calls (const schema_version_migration* svm): svm_ (*svm) {} - - bool - grow (image_type& i, bool* t) const - { - return traits::grow (i, t, svm_); - } - - void - bind (bind_type* b, image_type& i) const - { - traits::bind (b, i, svm_); - } - - void - init (T& o, const image_type& i, odb::database* db) const - { - traits::init (o, i, db, svm_); - } - - private: - const schema_version_migration& svm_; - }; - } -} - -#include - -#endif // ODB_PGSQL_TRAITS_CALLS_HXX diff --git a/odb/pgsql/traits.cxx b/odb/pgsql/traits.cxx deleted file mode 100644 index 11a3a67..0000000 --- a/odb/pgsql/traits.cxx +++ /dev/null @@ -1,143 +0,0 @@ -// file : odb/pgsql/traits.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -using namespace std; - -namespace odb -{ - namespace pgsql - { - using details::buffer; - - // - // default_value_traits - // - void default_value_traits:: - set_image (buffer& b, - size_t& n, - bool& is_null, - const string& v) - { - is_null = false; - n = v.size (); - - if (n > b.capacity ()) - b.capacity (n); - - if (n != 0) - memcpy (b.data (), v.c_str (), n); - } - - // - // c_string_value_traits - // - void c_string_value_traits:: - set_image (buffer& b, - size_t& n, - bool& is_null, - const char* v) - { - is_null = false; - n = strlen (v); - - if (n > b.capacity ()) - b.capacity (n); - - if (n != 0) - memcpy (b.data (), v, n); - } - - // - // c_array_value_traits_base - // - void c_array_value_traits_base:: - set_value (char* const& v, - const details::buffer& b, - size_t n, - bool is_null, - size_t N) - { - if (!is_null) - { - n = n < N ? n : N; - - if (n != 0) - memcpy (v, b.data (), n); - } - else - n = 0; - - if (n != N) // Append '\0' if there is space. - v[n] = '\0'; - } - - void c_array_value_traits_base:: - set_image (details::buffer& b, - size_t& n, - bool& is_null, - const char* v, - size_t N) - { - is_null = false; - - // Figure out the length. We cannot use strlen since it may - // not be 0-terminated (strnlen is not standard). - // - for (n = 0; n != N && v[n] != '\0'; ++n) ; - - if (n > b.capacity ()) - b.capacity (n); - - if (n != 0) - memcpy (b.data (), v, n); - } - - // - // default_value_traits, id_bytea> - // - // std::vector has to be qualified for Sun CC. - // - void default_value_traits, id_bytea>:: - set_image (details::buffer& b, - size_t& n, - bool& is_null, - const value_type& v) - { - is_null = false; - n = v.size (); - - if (n > b.capacity ()) - b.capacity (n); - - // std::vector::data() may not be available in older compilers. - // - if (n != 0) - memcpy (b.data (), &v.front (), n); - } - - // - // default_value_traits, id_bytea> - // - // std::vector has to be qualified for Sun CC. - // - void default_value_traits, id_bytea>:: - set_image (details::buffer& b, - size_t& n, - bool& is_null, - const value_type& v) - { - is_null = false; - n = v.size (); - - if (n > b.capacity ()) - b.capacity (n); - - // std::vector::data() may not be available in older compilers. - // - if (n != 0) - memcpy (b.data (), &v.front (), n); - } - } -} diff --git a/odb/pgsql/traits.hxx b/odb/pgsql/traits.hxx deleted file mode 100644 index 3d87033..0000000 --- a/odb/pgsql/traits.hxx +++ /dev/null @@ -1,944 +0,0 @@ -// file : odb/pgsql/traits.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_TRAITS_HXX -#define ODB_PGSQL_TRAITS_HXX - -#include - -#include // ODB_CXX11 - -#include -#include -#include // std::size_t -#include // std::memcpy, std::memset, std::strlen - -#ifdef ODB_CXX11 -# include -#endif - -#include -#include - -#include -#include - -#include -#include - -#include -#include - -namespace odb -{ - namespace pgsql - { - enum database_type_id - { - id_boolean, - id_smallint, - id_integer, - id_bigint, - - id_numeric, // Internal PostgreSQL binary representation. - - id_real, - id_double, - - id_date, - id_time, - id_timestamp, - - id_string, - id_bytea, - id_bit, - id_varbit, - - id_uuid - }; - - // - // image_traits - // - - template - struct image_traits; - - template <> - struct image_traits {typedef bool image_type;}; - - template <> - struct image_traits {typedef short image_type;}; - - template <> - struct image_traits {typedef int image_type;}; - - template <> - struct image_traits {typedef long long image_type;}; - - template <> - struct image_traits {typedef details::buffer image_type;}; - - template <> - struct image_traits {typedef float image_type;}; - - template <> - struct image_traits {typedef double image_type;}; - - template <> - struct image_traits {typedef int image_type;}; - - template <> - struct image_traits {typedef long long image_type;}; - - template <> - struct image_traits {typedef long long image_type;}; - - template <> - struct image_traits {typedef details::buffer image_type;}; - - template <> - struct image_traits {typedef details::buffer image_type;}; - - template <> - struct image_traits {typedef unsigned char* image_type;}; - - template <> - struct image_traits {typedef details::ubuffer image_type;}; - - // UUID image is a 16-byte sequence. - // - template <> - struct image_traits {typedef unsigned char* image_type;}; - - // - // value_traits - // - - template - struct wrapped_value_traits; - - template - struct default_value_traits; - - template ::r> - struct select_traits; - - template - struct select_traits - { - typedef default_value_traits type; - }; - - template - struct select_traits - { - typedef - wrapped_value_traits::null_handler> - type; - }; - - template - class value_traits: public select_traits::type - { - }; - - // The wrapped_value_traits specializations should be able to handle - // any value type which means we have to have every possible signature - // of the set_value() and set_image() functions. - // - template - struct wrapped_value_traits - { - typedef wrapper_traits wtraits; - typedef typename wtraits::unrestricted_wrapped_type wrapped_type; - - typedef W value_type; - typedef wrapped_type query_type; - typedef typename image_traits::image_type image_type; - - typedef value_traits vtraits; - - static void - set_value (W& v, const image_type& i, bool is_null) - { - vtraits::set_value (wtraits::set_ref (v), i, is_null); - } - - static void - set_image (image_type& i, bool& is_null, const W& v) - { - vtraits::set_image (i, is_null, wtraits::get_ref (v)); - } - - // String, BYTEA, and NUMERIC. - // - static void - set_value (W& v, const details::buffer& b, std::size_t n, bool is_null) - { - vtraits::set_value (wtraits::set_ref (v), b, n, is_null); - } - - static void - set_image (details::buffer& b, std::size_t& n, bool& is_null, const W& v) - { - vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); - } - - // BIT. - // - static void - set_value (W& v, const unsigned char* i, std::size_t n, bool is_null) - { - vtraits::set_value (wtraits::set_ref (v), i, n, is_null); - } - - static void - set_image (unsigned char* i, - std::size_t c, - std::size_t& n, - bool& is_null, - const W& v) - { - vtraits::set_image (i, c, n, is_null, wtraits::get_ref (v)); - } - - // VARBIT. - // - static void - set_value (W& v, const details::ubuffer& b, std::size_t n, bool is_null) - { - vtraits::set_value (wtraits::set_ref (v), b, n, is_null); - } - - static void - set_image (details::ubuffer& b, - std::size_t& n, - bool& is_null, - const W& v) - { - vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); - } - - // UUID. - // - static void - set_value (W& v, const unsigned char* i, bool is_null) - { - vtraits::set_value (wtraits::set_ref (v), i, is_null); - } - - static void - set_image (unsigned char* i, bool& is_null, const W& v) - { - vtraits::set_image (i, is_null, wtraits::get_ref (v)); - } - }; - - template - struct wrapped_value_traits - { - typedef wrapper_traits wtraits; - typedef typename wtraits::unrestricted_wrapped_type wrapped_type; - - typedef W value_type; - typedef wrapped_type query_type; - typedef typename image_traits::image_type image_type; - - typedef value_traits vtraits; - - static void - set_value (W& v, const image_type& i, bool is_null) - { - if (is_null) - wtraits::set_null (v); - else - vtraits::set_value (wtraits::set_ref (v), i, is_null); - } - - static void - set_image (image_type& i, bool& is_null, const W& v) - { - is_null = wtraits::get_null (v); - - if (!is_null) - vtraits::set_image (i, is_null, wtraits::get_ref (v)); - } - - // String, BYTEA, and NUMERIC. - // - static void - set_value (W& v, const details::buffer& b, std::size_t n, bool is_null) - { - if (is_null) - wtraits::set_null (v); - else - vtraits::set_value (wtraits::set_ref (v), b, n, is_null); - } - - static void - set_image (details::buffer& b, std::size_t& n, bool& is_null, const W& v) - { - is_null = wtraits::get_null (v); - - if (!is_null) - vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); - } - - // BIT. - // - static void - set_value (W& v, const unsigned char* i, std::size_t n, bool is_null) - { - if (is_null) - wtraits::set_null (v); - else - vtraits::set_value (wtraits::set_ref (v), i, n, is_null); - } - - static void - set_image (unsigned char* i, - std::size_t c, - std::size_t& n, - bool& is_null, - const W& v) - { - is_null = wtraits::get_null (v); - - if (!is_null) - vtraits::set_image (i, c, n, is_null, wtraits::get_ref (v)); - } - - // VARBIT. - // - static void - set_value (W& v, const details::ubuffer& b, std::size_t n, bool is_null) - { - if (is_null) - wtraits::set_null (v); - else - vtraits::set_value (wtraits::set_ref (v), b, n, is_null); - } - - static void - set_image (details::ubuffer& b, std::size_t& n, bool& is_null, const W& v) - { - is_null = wtraits::get_null (v); - - if (!is_null) - vtraits::set_image (b, n, is_null, wtraits::get_ref (v)); - } - - // UUID. - // - static void - set_value (W& v, const unsigned char* i, bool is_null) - { - if (is_null) - wtraits::set_null (v); - else - vtraits::set_value (wtraits::set_ref (v), i, is_null); - } - - static void - set_image (unsigned char* i, bool& is_null, const W& v) - { - is_null = wtraits::get_null (v); - - if (!is_null) - vtraits::set_image (i, is_null, wtraits::get_ref (v)); - } - }; - - template - struct default_value_traits - { - typedef T value_type; - typedef T query_type; - typedef typename image_traits::image_type image_type; - - static void - set_value (T& v, const image_type& i, bool is_null) - { - if (!is_null) - v = T (details::endian_traits::ntoh (i)); - else - v = T (); - } - - static void - set_image (image_type& i, bool& is_null, T v) - { - is_null = false; - i = details::endian_traits::hton (image_type (v)); - } - }; - - // std::string specialization. - // - template <> - struct LIBODB_PGSQL_EXPORT default_value_traits - { - typedef std::string value_type; - typedef std::string query_type; - typedef details::buffer image_type; - - static void - set_value (std::string& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - if (!is_null) - v.assign (b.data (), n); - else - v.erase (); - } - - static void - set_image (details::buffer&, - std::size_t& n, - bool& is_null, - const std::string&); - }; - - // char*/const char* specialization - // - // Specialization for const char* which only supports initialization - // of an image from the value but not the other way around. This way - // we can pass such values to the queries. - // - class LIBODB_PGSQL_EXPORT c_string_value_traits - { - public: - typedef const char* value_type; - typedef details::buffer image_type; - - static void - set_image (details::buffer&, - std::size_t& n, - bool& is_null, - const char*); - }; - - template <> - struct default_value_traits: c_string_value_traits {}; - - template <> - struct default_value_traits: - c_string_value_traits {}; - - // char[N] specializations. - // - struct LIBODB_PGSQL_EXPORT c_array_value_traits_base - { - static void - set_value (char* const& v, - const details::buffer& b, - std::size_t n, - bool is_null, - std::size_t N); - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const char* v, - std::size_t N); - }; - - template - struct default_value_traits - { - typedef char* value_type; - typedef char query_type[N]; - typedef details::buffer image_type; - - static void - set_value (char* const& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - c_array_value_traits_base::set_value (v, b, n, is_null, N); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const char* v) - { - c_array_value_traits_base::set_image (b, n, is_null, v, N); - } - }; - - // std::array (string) specialization. - // -#ifdef ODB_CXX11 - template - struct default_value_traits, id_string> - { - typedef std::array value_type; - typedef std::array query_type; - typedef details::buffer image_type; - - static void - set_value (value_type& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - c_array_value_traits_base::set_value (v.data (), b, n, is_null, N); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const value_type& v) - { - c_array_value_traits_base::set_image (b, n, is_null, v.data (), N); - } - }; -#endif - - // char specialization. - // - template <> - struct default_value_traits - { - typedef char value_type; - typedef char query_type; - typedef details::buffer image_type; - - static void - set_value (char& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - c_array_value_traits_base::set_value (&v, b, n, is_null, 1); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - char v) - { - c_array_value_traits_base::set_image (b, n, is_null, &v, 1); - } - }; - - // std::vector (buffer) specialization. - // - template <> - struct LIBODB_PGSQL_EXPORT default_value_traits< - std::vector, id_bytea> - { - public: - typedef std::vector value_type; - typedef std::vector query_type; - typedef details::buffer image_type; - - static void - set_value (value_type& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - if (!is_null) - v.assign (b.data (), b.data () + n); - else - v.clear (); - } - - static void - set_image (details::buffer&, - std::size_t& n, - bool& is_null, - const value_type&); - }; - - // std::vector (buffer) specialization. - // - template <> - struct LIBODB_PGSQL_EXPORT default_value_traits< - std::vector, id_bytea> - { - public: - typedef std::vector value_type; - typedef std::vector query_type; - typedef details::buffer image_type; - - static void - set_value (value_type& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - if (!is_null) - { - const unsigned char* d ( - reinterpret_cast (b.data ())); - v.assign (d, d + n); - } - else - v.clear (); - } - - static void - set_image (details::buffer&, - std::size_t& n, - bool& is_null, - const value_type&); - }; - - // char[N] (buffer) specialization. - // - template - struct default_value_traits - { - public: - typedef char* value_type; - typedef char query_type[N]; - typedef details::buffer image_type; - - static void - set_value (char* const& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - if (!is_null) - std::memcpy (v, b.data (), (n < N ? n : N)); - else - std::memset (v, 0, N); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const char* v) - { - is_null = false; - n = N; - - if (n > b.capacity ()) - b.capacity (n); - - std::memcpy (b.data (), v, n); - } - }; - - // unsigned char[N] (buffer) specialization. - // - template - struct default_value_traits - { - public: - typedef unsigned char* value_type; - typedef unsigned char query_type[N]; - typedef details::buffer image_type; - - static void - set_value (unsigned char* const& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - if (!is_null) - std::memcpy (v, b.data (), (n < N ? n : N)); - else - std::memset (v, 0, N); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const unsigned char* v) - { - is_null = false; - n = N; - - if (n > b.capacity ()) - b.capacity (n); - - std::memcpy (b.data (), v, n); - } - }; - -#ifdef ODB_CXX11 - // std::array (buffer) specialization. - // - template - struct default_value_traits, id_bytea> - { - public: - typedef std::array value_type; - typedef value_type query_type; - typedef details::buffer image_type; - - static void - set_value (value_type& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - if (!is_null) - std::memcpy (v.data (), b.data (), (n < N ? n : N)); - else - std::memset (v.data (), 0, N); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const value_type& v) - { - is_null = false; - n = N; - - if (n > b.capacity ()) - b.capacity (n); - - std::memcpy (b.data (), v.data (), n); - } - }; - - // std::array (buffer) specialization. - // - template - struct default_value_traits, id_bytea> - { - public: - typedef std::array value_type; - typedef value_type query_type; - typedef details::buffer image_type; - - static void - set_value (value_type& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - if (!is_null) - std::memcpy (v.data (), b.data (), (n < N ? n : N)); - else - std::memset (v.data (), 0, N); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const value_type& v) - { - is_null = false; - n = N; - - if (n > b.capacity ()) - b.capacity (n); - - std::memcpy (b.data (), v.data (), n); - } - }; -#endif - - // char[16] specialization for uuid. - // - template <> - struct default_value_traits - { - typedef char* value_type; - typedef char query_type[16]; - typedef unsigned char* image_type; - - static void - set_value (char* const& v, const unsigned char* i, bool is_null) - { - if (!is_null) - std::memcpy (v, i, 16); - else - std::memset (v, 0, 16); - } - - static void - set_image (unsigned char* i, bool& is_null, const char* v) - { - is_null = false; - std::memcpy (i, v, 16); - } - }; - - // - // type_traits - // - - template - struct default_type_traits; - - template - class type_traits: public default_type_traits - { - }; - - // Integral types. - // - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_boolean; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_smallint; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_smallint; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_smallint; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_smallint; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_integer; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_integer; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_bigint; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_bigint; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_bigint; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_bigint; - }; - - // Float types. - // - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_real; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_double; - }; - - // String types. - // - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_string; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_string; - }; - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_string; - }; - - template - struct default_type_traits - { - static const database_type_id db_type_id = id_string; - }; - -#ifdef ODB_CXX11 - template - struct default_type_traits > - { - static const database_type_id db_type_id = id_string; - }; -#endif - - template <> - struct default_type_traits - { - static const database_type_id db_type_id = id_string; - }; - - // Binary types. - // - template - struct default_type_traits - { - static const database_type_id db_type_id = id_bytea; - }; - - template <> - struct default_type_traits > - { - static const database_type_id db_type_id = id_bytea; - }; - - template <> - struct default_type_traits > - { - static const database_type_id db_type_id = id_bytea; - }; - -#ifdef ODB_CXX11 - template - struct default_type_traits > - { - static const database_type_id db_type_id = id_bytea; - }; -#endif - } -} - -#include - -#endif // ODB_PGSQL_TRAITS_HXX diff --git a/odb/pgsql/transaction-impl.cxx b/odb/pgsql/transaction-impl.cxx deleted file mode 100644 index 012fe18..0000000 --- a/odb/pgsql/transaction-impl.cxx +++ /dev/null @@ -1,107 +0,0 @@ -// file : odb/pgsql/transaction-impl.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -#include - -#include - -#include -#include -#include -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - transaction_impl:: - transaction_impl (database_type& db) - : odb::transaction_impl (db) - { - } - - transaction_impl:: - transaction_impl (connection_ptr c) - : odb::transaction_impl (c->database (), *c), connection_ (c) - { - } - - transaction_impl:: - ~transaction_impl () - { - } - - void transaction_impl:: - start () - { - // Grab a connection if we don't already have one. - // - if (connection_ == 0) - { - connection_ = static_cast (database_).connection (); - odb::transaction_impl::connection_ = connection_.get (); - } - - { - odb::tracer* t; - if ((t = connection_->tracer ()) || (t = database_.tracer ())) - t->execute (*connection_, "BEGIN"); - } - - auto_handle h (PQexec (connection_->handle (), "begin")); - - if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) - translate_error (*connection_, h); - } - - void transaction_impl:: - commit () - { - // Invalidate query results. - // - connection_->invalidate_results (); - - { - odb::tracer* t; - if ((t = connection_->tracer ()) || (t = database_.tracer ())) - t->execute (*connection_, "COMMIT"); - } - - auto_handle h (PQexec (connection_->handle (), "commit")); - - if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) - translate_error (*connection_, h); - - // Release the connection. - // - connection_.reset (); - } - - void transaction_impl:: - rollback () - { - // Invalidate query results. - // - connection_->invalidate_results (); - - { - odb::tracer* t; - if ((t = connection_->tracer ()) || (t = database_.tracer ())) - t->execute (*connection_, "ROLLBACK"); - } - - auto_handle h (PQexec (connection_->handle (), "rollback")); - - if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) - translate_error (*connection_, h); - - // Release the connection. - // - connection_.reset (); - } - } -} diff --git a/odb/pgsql/transaction-impl.hxx b/odb/pgsql/transaction-impl.hxx deleted file mode 100644 index 5c93b0e..0000000 --- a/odb/pgsql/transaction-impl.hxx +++ /dev/null @@ -1,49 +0,0 @@ -// file : odb/pgsql/transaction-impl.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_TRANSACTION_IMPL_HXX -#define ODB_PGSQL_TRANSACTION_IMPL_HXX - -#include - -#include - -#include -#include - -#include - -namespace odb -{ - namespace pgsql - { - class LIBODB_PGSQL_EXPORT transaction_impl: public odb::transaction_impl - { - public: - typedef pgsql::database database_type; - typedef pgsql::connection connection_type; - - transaction_impl (database_type&); - transaction_impl (connection_ptr); - - virtual - ~transaction_impl (); - - virtual void - start (); - - virtual void - commit (); - - virtual void - rollback (); - - private: - connection_ptr connection_; - }; - } -} - -#include - -#endif // ODB_PGSQL_TRANSACTION_IMPL_HXX diff --git a/odb/pgsql/transaction.cxx b/odb/pgsql/transaction.cxx deleted file mode 100644 index 3b32d80..0000000 --- a/odb/pgsql/transaction.cxx +++ /dev/null @@ -1,26 +0,0 @@ -// file : odb/pgsql/transaction.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -#include - -namespace odb -{ - namespace pgsql - { - transaction& transaction:: - current () - { - // While the impl type can be of the concrete type, the transaction - // object can be created as either odb:: or odb::pgsql:: type. To - // work around that we are going to hard-cast one to the other - // relying on the fact that they have the same representation and - // no virtual functions. The former is checked in the tests. - // - odb::transaction& b (odb::transaction::current ()); - assert (dynamic_cast (&b.implementation ()) != 0); - return reinterpret_cast (b); - } - } -} diff --git a/odb/pgsql/transaction.hxx b/odb/pgsql/transaction.hxx deleted file mode 100644 index e83c754..0000000 --- a/odb/pgsql/transaction.hxx +++ /dev/null @@ -1,88 +0,0 @@ -// file : odb/pgsql/transaction.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_TRANSACTION_HXX -#define ODB_PGSQL_TRANSACTION_HXX - -#include - -#include - -#include -#include -#include - -#include - -namespace odb -{ - namespace pgsql - { - class transaction_impl; - - class LIBODB_PGSQL_EXPORT transaction: public odb::transaction - { - public: - typedef pgsql::database database_type; - typedef pgsql::connection connection_type; - - explicit - transaction (transaction_impl*, bool make_current = true); - - transaction (); - - // Return the database this transaction is on. - // - database_type& - database (); - - // Return the underlying database connection for this transaction. - // - connection_type& - connection (); - - connection_type& - connection (odb::database&); - - // Return current transaction or throw if there is no transaction - // in effect. - // - static transaction& - current (); - - // Set the current thread's transaction. - // - static void - current (transaction&); - - // SQL statement tracing. - // - public: - typedef pgsql::tracer tracer_type; - - void - tracer (tracer_type& t) - { - odb::transaction::tracer (t); - } - - void - tracer (tracer_type* t) - { - odb::transaction::tracer (t); - } - - using odb::transaction::tracer; - - public: - transaction_impl& - implementation (); - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_TRANSACTION_HXX diff --git a/odb/pgsql/transaction.ixx b/odb/pgsql/transaction.ixx deleted file mode 100644 index 31aa603..0000000 --- a/odb/pgsql/transaction.ixx +++ /dev/null @@ -1,57 +0,0 @@ -// file : odb/pgsql/transaction.ixx -// license : GNU GPL v2; see accompanying LICENSE file - -#include -#include - -namespace odb -{ - namespace pgsql - { - inline transaction:: - transaction (transaction_impl* impl, bool make_current) - : odb::transaction (impl, make_current) - { - } - - inline transaction:: - transaction () - : odb::transaction () - { - } - - inline transaction_impl& transaction:: - implementation () - { - // We can use static_cast here since we have an instance of - // pgsql::transaction. - // - return static_cast ( - odb::transaction::implementation ()); - } - - inline transaction::database_type& transaction:: - database () - { - return static_cast (odb::transaction::database ()); - } - - inline transaction::connection_type& transaction:: - connection () - { - return static_cast (odb::transaction::connection ()); - } - - inline transaction::connection_type& transaction:: - connection (odb::database& db) - { - return static_cast (odb::transaction::connection (db)); - } - - inline void transaction:: - current (transaction& t) - { - odb::transaction::current (t); - } - } -} diff --git a/odb/pgsql/version-build2-stub.hxx b/odb/pgsql/version-build2-stub.hxx deleted file mode 100644 index a99b093..0000000 --- a/odb/pgsql/version-build2-stub.hxx +++ /dev/null @@ -1,4 +0,0 @@ -// file : odb/pgsql/version-build2-stub.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#include diff --git a/odb/pgsql/version-build2.hxx b/odb/pgsql/version-build2.hxx deleted file mode 100644 index e69de29..0000000 diff --git a/odb/pgsql/version-build2.hxx.in b/odb/pgsql/version-build2.hxx.in deleted file mode 100644 index ed4396b..0000000 --- a/odb/pgsql/version-build2.hxx.in +++ /dev/null @@ -1,42 +0,0 @@ -// file : odb/pgsql/version-build2.hxx.in -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef LIBODB_PGSQL_VERSION // Note: using the version macro itself. - -// The numeric version format is AAAAABBBBBCCCCCDDDE where: -// -// AAAAA - major version number -// BBBBB - minor version number -// CCCCC - bugfix version number -// DDD - alpha / beta (DDD + 500) version number -// E - final (0) / snapshot (1) -// -// When DDDE is not 0, 1 is subtracted from AAAAABBBBBCCCCC. For example: -// -// Version AAAAABBBBBCCCCCDDDE -// -// 0.1.0 0000000001000000000 -// 0.1.2 0000000001000020000 -// 1.2.3 0000100002000030000 -// 2.2.0-a.1 0000200001999990010 -// 3.0.0-b.2 0000299999999995020 -// 2.2.0-a.1.z 0000200001999990011 -// -#define LIBODB_PGSQL_VERSION $libodb_pgsql.version.project_number$ULL -#define LIBODB_PGSQL_VERSION_STR "$libodb_pgsql.version.project$" -#define LIBODB_PGSQL_VERSION_ID "$libodb_pgsql.version.project_id$" - -#define LIBODB_PGSQL_VERSION_MAJOR $libodb_pgsql.version.major$ -#define LIBODB_PGSQL_VERSION_MINOR $libodb_pgsql.version.minor$ -#define LIBODB_PGSQL_VERSION_PATCH $libodb_pgsql.version.patch$ - -#define LIBODB_PGSQL_PRE_RELEASE $libodb_pgsql.version.pre_release$ - -#define LIBODB_PGSQL_SNAPSHOT $libodb_pgsql.version.snapshot_sn$ULL -#define LIBODB_PGSQL_SNAPSHOT_ID "$libodb_pgsql.version.snapshot_id$" - -#include - -$libodb.check(LIBODB_VERSION, LIBODB_SNAPSHOT)$ - -#endif // LIBODB_PGSQL_VERSION diff --git a/odb/pgsql/version.hxx b/odb/pgsql/version.hxx deleted file mode 100644 index e050de4..0000000 --- a/odb/pgsql/version.hxx +++ /dev/null @@ -1,48 +0,0 @@ -// file : odb/pgsql/version.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifdef LIBODB_PGSQL_BUILD2 -# include -#else - -#ifndef ODB_PGSQL_VERSION_HXX -#define ODB_PGSQL_VERSION_HXX - -#include - -#include -#include - -// Version format is AABBCCDD where -// -// AA - major version number -// BB - minor version number -// CC - bugfix version number -// DD - alpha / beta (DD + 50) version number -// -// When DD is not 00, 1 is subtracted from AABBCC. For example: -// -// Version AABBCCDD -// 2.0.0 02000000 -// 2.1.0 02010000 -// 2.1.1 02010100 -// 2.2.0.a1 02019901 -// 3.0.0.b2 02999952 -// - -// Check that we have compatible ODB version. -// -#if ODB_VERSION != 20476 -# error incompatible odb interface version detected -#endif - -// libodb-pgsql version: odb interface version plus the bugfix -// version. -// -#define LIBODB_PGSQL_VERSION 2049976 -#define LIBODB_PGSQL_VERSION_STR "2.5.0-b.26" - -#include - -#endif // ODB_PGSQL_VERSION_HXX -#endif // LIBODB_PGSQL_BUILD2 diff --git a/odb/pgsql/view-result.hxx b/odb/pgsql/view-result.hxx deleted file mode 100644 index f9acace..0000000 --- a/odb/pgsql/view-result.hxx +++ /dev/null @@ -1,77 +0,0 @@ -// file : odb/pgsql/view-result.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_VIEW_RESULT_HXX -#define ODB_PGSQL_VIEW_RESULT_HXX - -#include - -#include // std::size_t - -#include -#include - -#include - -#include -#include // query_base, view_statements -#include -#include - -namespace odb -{ - namespace pgsql - { - template - class view_result_impl: public odb::view_result_impl - { - public: - typedef odb::view_result_impl base_type; - - typedef typename base_type::view_type view_type; - typedef typename base_type::pointer_type pointer_type; - - typedef view_traits_impl view_traits; - typedef typename base_type::pointer_traits pointer_traits; - - typedef view_statements statements_type; - - virtual - ~view_result_impl (); - - view_result_impl (const query_base&, - details::shared_ptr, - statements_type&, - const schema_version_migration*); - - virtual void - load (view_type&); - - virtual void - next (); - - virtual void - cache (); - - virtual std::size_t - size (); - - virtual void - invalidate (); - - using base_type::current; - - private: - details::shared_ptr statement_; - statements_type& statements_; - view_traits_calls tc_; - std::size_t count_; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_VIEW_RESULT_HXX diff --git a/odb/pgsql/view-result.txx b/odb/pgsql/view-result.txx deleted file mode 100644 index 980811a..0000000 --- a/odb/pgsql/view-result.txx +++ /dev/null @@ -1,114 +0,0 @@ -// file : odb/pgsql/view-result.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include - -#include - -namespace odb -{ - namespace pgsql - { - template - view_result_impl:: - ~view_result_impl () - { - if (!this->end_) - statement_->free_result (); - } - - template - void view_result_impl:: - invalidate () - { - if (!this->end_) - { - statement_->free_result (); - this->end_ = true; - } - - statement_.reset (); - } - - template - view_result_impl:: - view_result_impl (const query_base&, - details::shared_ptr statement, - statements_type& statements, - const schema_version_migration* svm) - : base_type (statements.connection ()), - statement_ (statement), - statements_ (statements), - tc_ (svm), - count_ (0) - { - } - - template - void view_result_impl:: - load (view_type& view) - { - // The image can grow between calls to load() as a result of other - // statements execution. - // - typename view_traits::image_type& im (statements_.image ()); - - if (im.version != statements_.image_version ()) - { - binding& b (statements_.image_binding ()); - tc_.bind (b.bind, im); - statements_.image_version (im.version); - b.version++; - } - - select_statement::result r (statement_->load ()); - - if (r == select_statement::truncated) - { - if (tc_.grow (im, statements_.image_truncated ())) - im.version++; - - if (im.version != statements_.image_version ()) - { - binding& b (statements_.image_binding ()); - tc_.bind (b.bind, im); - statements_.image_version (im.version); - b.version++; - statement_->reload (); - } - } - - view_traits::callback (this->db_, view, callback_event::pre_load); - tc_.init (view, im, &this->db_); - view_traits::callback (this->db_, view, callback_event::post_load); - } - - template - void view_result_impl:: - next () - { - this->current (pointer_type ()); - - if (statement_->next ()) - count_++; - else - { - statement_->free_result (); - this->end_ = true; - } - } - - template - void view_result_impl:: - cache () - { - } - - template - std::size_t view_result_impl:: - size () - { - return this->end_ ? count_ : statement_->result_size (); - } - } -} diff --git a/odb/pgsql/view-statements.hxx b/odb/pgsql/view-statements.hxx deleted file mode 100644 index 970e610..0000000 --- a/odb/pgsql/view-statements.hxx +++ /dev/null @@ -1,88 +0,0 @@ -// file : odb/pgsql/view-statements.hxx -// license : GNU GPL v2; see accompanying LICENSE file - -#ifndef ODB_PGSQL_VIEW_STATEMENTS_HXX -#define ODB_PGSQL_VIEW_STATEMENTS_HXX - -#include - -#include // std::size_t - -#include -#include - -#include -#include -#include -#include - -namespace odb -{ - namespace pgsql - { - template - class view_statements: public statements_base - { - public: - typedef T view_type; - typedef view_traits_impl view_traits; - typedef typename view_traits::pointer_type pointer_type; - typedef typename view_traits::image_type image_type; - - public: - view_statements (connection_type&); - - virtual - ~view_statements (); - - // View image. - // - image_type& - image () - { - return image_; - } - - std::size_t - image_version () const - { - return image_version_; - } - - void - image_version (std::size_t v) - { - image_version_ = v; - } - - binding& - image_binding () - { - return image_binding_; - } - - bool* - image_truncated () - { - return image_truncated_; - } - - private: - view_statements (const view_statements&); - view_statements& operator= (const view_statements&); - - private: - image_type image_; - std::size_t image_version_; - binding image_binding_; - bind image_bind_[view_traits::column_count]; - bool image_truncated_[view_traits::column_count]; - }; - } -} - -#include - -#include - -#endif // ODB_PGSQL_VIEW_STATEMENTS_HXX diff --git a/odb/pgsql/view-statements.txx b/odb/pgsql/view-statements.txx deleted file mode 100644 index afa2a49..0000000 --- a/odb/pgsql/view-statements.txx +++ /dev/null @@ -1,33 +0,0 @@ -// file : odb/pgsql/view-statements.txx -// license : GNU GPL v2; see accompanying LICENSE file - -#include // std::size_t -#include // std::memset - -namespace odb -{ - namespace pgsql - { - template - view_statements:: - ~view_statements () - { - } - - template - view_statements:: - view_statements (connection_type& conn) - : statements_base (conn), - image_binding_ (image_bind_, view_traits::column_count) - { - image_.version = 0; - image_version_ = 0; - - std::memset (image_bind_, 0, sizeof (image_bind_)); - std::memset (image_truncated_, 0, sizeof (image_truncated_)); - - for (std::size_t i (0); i < view_traits::column_count; ++i) - image_bind_[i].truncated = image_truncated_ + i; - } - } -} diff --git a/repositories.manifest b/repositories.manifest deleted file mode 100644 index 4451c88..0000000 --- a/repositories.manifest +++ /dev/null @@ -1,14 +0,0 @@ -: 1 -summary: PostgreSQL ODB runtime library repository - -: -role: prerequisite -location: https://git.build2.org/packaging/postgresql/postgresql.git##HEAD - -: -role: prerequisite -location: ../libodb.git##HEAD - -: -role: prerequisite -location: https://git.codesynthesis.com/cli/cli.git##HEAD diff --git a/tests/.gitignore b/tests/.gitignore deleted file mode 100644 index e54525b..0000000 --- a/tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -driver diff --git a/tests/basics/buildfile b/tests/basics/buildfile deleted file mode 100644 index fccb243..0000000 --- a/tests/basics/buildfile +++ /dev/null @@ -1,6 +0,0 @@ -# file : tests/basics/buildfile -# license : GNU GPL v2; see accompanying LICENSE file - -import libs = libodb-pgsql%lib{odb-pgsql} - -exe{driver}: {hxx cxx}{*} $libs diff --git a/tests/basics/driver.cxx b/tests/basics/driver.cxx deleted file mode 100644 index efd1985..0000000 --- a/tests/basics/driver.cxx +++ /dev/null @@ -1,37 +0,0 @@ -// file : tests/basics/driver.cxx -// license : GNU GPL v2; see accompanying LICENSE file - -// Basic test to make sure the library is usable. Functionality testing -// is done in the odb-tests package. - -#include -#include - -#include -#include -#include - -using namespace odb::pgsql; - -int -main () -{ - { - std::ostringstream os; - database::print_usage (os); - assert (!os.str ().empty ()); - } - - // We can't really do much here since that would require a database. We can - // create a fake database object as long as we don't expect to get a valid - // connection. - // - database db ("john", "secret", "dummy whammy"); - - try - { - transaction t (db.begin ()); - assert (false); - } - catch (const database_exception&) {} -} diff --git a/tests/build/.gitignore b/tests/build/.gitignore deleted file mode 100644 index 4a730a3..0000000 --- a/tests/build/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -config.build -root/ -bootstrap/ diff --git a/tests/build/bootstrap.build b/tests/build/bootstrap.build deleted file mode 100644 index 6ee38db..0000000 --- a/tests/build/bootstrap.build +++ /dev/null @@ -1,8 +0,0 @@ -# file : tests/build/bootstrap.build -# license : GNU GPL v2; see accompanying LICENSE file - -project = # Unnamed subproject. - -using config -using dist -using test diff --git a/tests/build/root.build b/tests/build/root.build deleted file mode 100644 index 6c5a90b..0000000 --- a/tests/build/root.build +++ /dev/null @@ -1,23 +0,0 @@ -# file : tests/build/root.build -# license : GNU GPL v2; see accompanying LICENSE file - -cxx.std = latest - -using cxx - -hxx{*}: extension = hxx -cxx{*}: extension = cxx - -if ($cxx.target.system == 'win32-msvc') - cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS - -if ($cxx.class == 'msvc') - cxx.coptions += /wd4251 /wd4275 /wd4800 - -# Every exe{} in this subproject is by default a test. -# -exe{*}: test = true - -# Specify the test target for cross-testing. -# -test.target = $cxx.target diff --git a/tests/buildfile b/tests/buildfile deleted file mode 100644 index 57588a4..0000000 --- a/tests/buildfile +++ /dev/null @@ -1,4 +0,0 @@ -# file : tests/buildfile -# license : GNU GPL v2; see accompanying LICENSE file - -./: {*/ -build/} diff --git a/version.txt b/version.txt deleted file mode 100644 index 6bc2f39..0000000 --- a/version.txt +++ /dev/null @@ -1 +0,0 @@ -2.5.0-b.26 -- cgit v1.1