From 0bd6524e3258faee44acedf758ccfbcd55368fc2 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 7 May 2024 16:26:41 +0300 Subject: Turn odb-examples repository into package for muti-package repository --- .gitignore | 23 -- GPLv2 | 340 ----------------- INSTALL | 163 -------- INSTALL-GIT | 78 ---- LICENSE | 20 - Makefile.am | 23 -- NEWS | 1 - README | 97 ----- access/README | 63 ---- access/database.hxx | 94 ----- access/driver.cxx | 56 --- access/makefile | 125 ------ access/person.hxx | 125 ------ boost/README | 77 ---- boost/boost-vc10.vcxproj | 174 --------- boost/boost-vc10.vcxproj.filters | 25 -- boost/boost-vc11.vcxproj | 178 --------- boost/boost-vc11.vcxproj.filters | 25 -- boost/boost-vc12.vcxproj | 182 --------- boost/boost-vc12.vcxproj.filters | 25 -- boost/boost-vc8.vcproj | 350 ----------------- boost/boost-vc9.vcproj | 357 ------------------ boost/database.hxx | 94 ----- boost/driver.cxx | 176 --------- boost/employee.hxx | 196 ---------- boost/makefile | 151 -------- bootstrap | 16 - build/bootstrap.make | 173 --------- build/configuration-rules.make | 18 - build/configuration.make | 33 -- build/configure | 34 -- build/import/libboost/configuration-rules.make | 13 - build/import/libboost/configure | 72 ---- build/import/libboost/date-time/rules.make | 49 --- build/import/libboost/date-time/stub.make | 34 -- build/import/libboost/header-only/rules.make | 16 - build/import/libboost/header-only/stub.make | 26 -- build/import/libboost/version | 1 - build/import/libodb-boost/configuration-rules.make | 13 - build/import/libodb-boost/configure | 53 --- build/import/libodb-boost/stub.make | 28 -- build/import/libodb-mssql/configuration-rules.make | 13 - build/import/libodb-mssql/configure | 53 --- build/import/libodb-mssql/stub.make | 28 -- build/import/libodb-mysql/configuration-rules.make | 13 - build/import/libodb-mysql/configure | 53 --- build/import/libodb-mysql/stub.make | 28 -- .../import/libodb-oracle/configuration-rules.make | 13 - build/import/libodb-oracle/configure | 53 --- build/import/libodb-oracle/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-qt/configuration-rules.make | 13 - build/import/libodb-qt/configure | 53 --- build/import/libodb-qt/stub.make | 28 -- .../import/libodb-sqlite/configuration-rules.make | 13 - build/import/libodb-sqlite/configure | 53 --- build/import/libodb-sqlite/stub.make | 28 -- build/import/libodb/configuration-rules.make | 13 - build/import/libodb/configure | 53 --- build/import/libodb/stub.make | 28 -- build/import/libqt/configuration-rules.make | 13 - build/import/libqt/configure | 97 ----- build/import/libqt/core/rules.make | 26 -- build/import/libqt/core/stub.make | 35 -- build/import/libqt/version | 1 - build/import/odb/configuration-rules.make | 13 - build/import/odb/configure | 53 --- build/import/odb/hxx-cxx.make | 127 ------- build/import/odb/stub.make | 28 -- build/mssql/configure | 52 --- build/mssql/mssql | 51 --- build/mysql/configure | 75 ---- build/mysql/mysql | 57 --- build/oracle/configure | 97 ----- build/oracle/oracle | 80 ---- build/pgsql/configure | 63 ---- build/pgsql/pgsql | 53 --- build/sqlite/configure | 20 - c++11/README | 78 ---- c++11/database.hxx | 94 ----- c++11/driver.cxx | 207 ---------- c++11/employee.hxx | 182 --------- c++11/makefile | 139 ------- composite/README | 69 ---- composite/database.hxx | 94 ----- composite/driver.cxx | 108 ------ composite/makefile | 125 ------ composite/person.hxx | 228 ----------- configure.ac | 106 ------ container/README | 62 --- container/database.hxx | 94 ----- container/driver.cxx | 119 ------ container/makefile | 125 ------ container/person.hxx | 99 ----- hello/README | 63 ---- hello/database.hxx | 94 ----- hello/driver.cxx | 130 ------- hello/makefile | 124 ------ hello/person.hxx | 73 ---- inheritance/polymorphism/README | 78 ---- inheritance/polymorphism/database.hxx | 94 ----- inheritance/polymorphism/driver.cxx | 102 ----- inheritance/polymorphism/employee.cxx | 27 -- inheritance/polymorphism/employee.hxx | 109 ------ inheritance/polymorphism/makefile | 126 ------- inheritance/reuse/README | 69 ---- inheritance/reuse/database.hxx | 94 ----- inheritance/reuse/driver.cxx | 81 ---- inheritance/reuse/employee.hxx | 143 ------- inheritance/reuse/makefile | 125 ------ inverse/README | 78 ---- inverse/database.hxx | 94 ----- inverse/driver.cxx | 258 ------------- inverse/employee.hxx | 274 -------------- inverse/makefile | 126 ------- m4/acx-pthread.m4 | 259 ------------- m4/c++11.m4 | 37 -- m4/database.m4 | 59 --- m4/libboost.m4 | 184 --------- m4/libodb-boost.m4 | 82 ---- m4/libodb-mssql.m4 | 82 ---- m4/libodb-mysql.m4 | 82 ---- m4/libodb-oracle.m4 | 82 ---- m4/libodb-pgsql.m4 | 82 ---- m4/libodb-qt.m4 | 82 ---- m4/libodb-sqlite.m4 | 82 ---- m4/libodb.m4 | 81 ---- m4/libqt.m4 | 121 ------ m4/libtool-link.m4 | 45 --- m4/mssql.m4 | 224 ----------- m4/mysql.m4 | 270 ------------- m4/odb.m4 | 43 --- m4/oracle.m4 | 243 ------------ m4/pgsql.m4 | 204 ---------- m4/sqlite.m4 | 59 --- m4/threads.m4 | 68 ---- m4/tr1-memory.m4 | 38 -- makefile | 88 ----- mapping/README | 76 ---- mapping/database.hxx | 94 ----- mapping/driver.cxx | 65 ---- mapping/makefile | 127 ------- mapping/person.hxx | 106 ------ mapping/traits-mssql.hxx | 85 ----- mapping/traits-mysql.hxx | 85 ----- mapping/traits-oracle.hxx | 95 ----- mapping/traits-pgsql.hxx | 118 ------ mapping/traits-sqlite.hxx | 127 ------- mapping/traits.hxx | 23 -- mssql-driver.bat | 61 --- mssql.options | 10 - mysql-driver.bat | 46 --- mysql.options | 10 - odb-examples/.gitignore | 39 ++ odb-examples/GPLv2 | 340 +++++++++++++++++ odb-examples/LICENSE | 20 + odb-examples/README.md | 102 +++++ odb-examples/access/README | 63 ++++ odb-examples/access/buildfile | 44 +++ odb-examples/access/database.hxx | 95 +++++ odb-examples/access/driver.cxx | 56 +++ odb-examples/access/person.hxx | 125 ++++++ odb-examples/access/testscript | 13 + odb-examples/boost/README | 77 ++++ odb-examples/boost/database.hxx | 94 +++++ odb-examples/boost/driver.cxx | 176 +++++++++ odb-examples/boost/employee.hxx | 196 ++++++++++ odb-examples/build/.gitignore | 3 + odb-examples/build/bootstrap.build | 9 + odb-examples/build/root.build | 274 ++++++++++++++ odb-examples/buildfile | 6 + odb-examples/c++11/README | 74 ++++ odb-examples/c++11/buildfile | 44 +++ odb-examples/c++11/database.hxx | 95 +++++ odb-examples/c++11/driver.cxx | 207 ++++++++++ odb-examples/c++11/employee.hxx | 182 +++++++++ odb-examples/c++11/testscript | 13 + odb-examples/composite/README | 69 ++++ odb-examples/composite/buildfile | 44 +++ odb-examples/composite/database.hxx | 95 +++++ odb-examples/composite/driver.cxx | 108 ++++++ odb-examples/composite/person.hxx | 228 +++++++++++ odb-examples/composite/testscript | 13 + odb-examples/container/README | 62 +++ odb-examples/container/buildfile | 43 +++ odb-examples/container/database.hxx | 95 +++++ odb-examples/container/driver.cxx | 119 ++++++ odb-examples/container/person.hxx | 99 +++++ odb-examples/container/testscript | 13 + odb-examples/database-options.testscript | 148 ++++++++ odb-examples/hello/README | 63 ++++ odb-examples/hello/buildfile | 44 +++ odb-examples/hello/database.hxx | 95 +++++ odb-examples/hello/driver.cxx | 130 +++++++ odb-examples/hello/person.hxx | 73 ++++ odb-examples/hello/testscript | 13 + odb-examples/inheritance/polymorphism/README | 78 ++++ odb-examples/inheritance/polymorphism/buildfile | 44 +++ odb-examples/inheritance/polymorphism/database.hxx | 95 +++++ odb-examples/inheritance/polymorphism/driver.cxx | 102 +++++ odb-examples/inheritance/polymorphism/employee.cxx | 27 ++ odb-examples/inheritance/polymorphism/employee.hxx | 109 ++++++ odb-examples/inheritance/polymorphism/testscript | 13 + odb-examples/inheritance/reuse/README | 69 ++++ odb-examples/inheritance/reuse/buildfile | 44 +++ odb-examples/inheritance/reuse/database.hxx | 95 +++++ odb-examples/inheritance/reuse/driver.cxx | 81 ++++ odb-examples/inheritance/reuse/employee.hxx | 143 +++++++ odb-examples/inheritance/reuse/testscript | 13 + odb-examples/inverse/README | 74 ++++ odb-examples/inverse/buildfile | 46 +++ odb-examples/inverse/database.hxx | 95 +++++ odb-examples/inverse/driver.cxx | 256 +++++++++++++ odb-examples/inverse/employee.hxx | 263 +++++++++++++ odb-examples/inverse/testscript | 13 + odb-examples/manifest | 98 +++++ odb-examples/mapping/README | 76 ++++ odb-examples/mapping/buildfile | 45 +++ odb-examples/mapping/database.hxx | 95 +++++ odb-examples/mapping/driver.cxx | 65 ++++ odb-examples/mapping/person.hxx | 106 ++++++ odb-examples/mapping/testscript | 13 + odb-examples/mapping/traits-mssql.hxx | 85 +++++ odb-examples/mapping/traits-mysql.hxx | 85 +++++ odb-examples/mapping/traits-oracle.hxx | 95 +++++ odb-examples/mapping/traits-pgsql.hxx | 118 ++++++ odb-examples/mapping/traits-sqlite.hxx | 127 +++++++ odb-examples/mapping/traits.hxx | 23 ++ odb-examples/mssql-schema.testscript | 6 + odb-examples/mssql.testscript | 12 + odb-examples/mysql-schema.testscript | 9 + odb-examples/mysql.testscript | 12 + odb-examples/optimistic/README | 64 ++++ odb-examples/optimistic/buildfile | 43 +++ odb-examples/optimistic/database.hxx | 95 +++++ odb-examples/optimistic/driver.cxx | 158 ++++++++ odb-examples/optimistic/person.hxx | 67 ++++ odb-examples/optimistic/testscript | 13 + odb-examples/oracle-schema.testscript | 6 + odb-examples/oracle.testscript | 12 + odb-examples/pgsql-schema.testscript | 6 + odb-examples/pgsql.testscript | 12 + odb-examples/pimpl/README | 62 +++ odb-examples/pimpl/buildfile | 44 +++ odb-examples/pimpl/database.hxx | 95 +++++ odb-examples/pimpl/driver.cxx | 52 +++ odb-examples/pimpl/person.cxx | 71 ++++ odb-examples/pimpl/person.hxx | 56 +++ odb-examples/pimpl/testscript | 13 + odb-examples/prepared/README | 65 ++++ odb-examples/prepared/buildfile | 45 +++ odb-examples/prepared/database.hxx | 95 +++++ odb-examples/prepared/driver.cxx | 232 ++++++++++++ odb-examples/prepared/person.hxx | 61 +++ odb-examples/prepared/testscript | 13 + odb-examples/qt/README | 77 ++++ odb-examples/qt/database.hxx | 94 +++++ odb-examples/qt/driver.cxx | 180 +++++++++ odb-examples/qt/employee.hxx | 167 ++++++++ odb-examples/query/README | 59 +++ odb-examples/query/buildfile | 44 +++ odb-examples/query/database.hxx | 95 +++++ odb-examples/query/driver.cxx | 230 ++++++++++++ odb-examples/query/person.hxx | 69 ++++ odb-examples/query/testscript | 13 + odb-examples/relationship/README | 70 ++++ odb-examples/relationship/buildfile | 46 +++ odb-examples/relationship/database.hxx | 95 +++++ odb-examples/relationship/driver.cxx | 167 ++++++++ odb-examples/relationship/employee.hxx | 154 ++++++++ odb-examples/relationship/testscript | 13 + odb-examples/schema/custom/README | 61 +++ odb-examples/schema/custom/buildfile | 44 +++ odb-examples/schema/custom/database.hxx | 76 ++++ odb-examples/schema/custom/driver.cxx | 238 ++++++++++++ odb-examples/schema/custom/employee.hxx | 143 +++++++ odb-examples/schema/custom/testscript | 13 + odb-examples/schema/embedded/README | 63 ++++ odb-examples/schema/embedded/buildfile | 42 +++ odb-examples/schema/embedded/database.hxx | 76 ++++ odb-examples/schema/embedded/driver.cxx | 96 +++++ odb-examples/schema/embedded/person.hxx | 59 +++ odb-examples/schema/embedded/testscript | 9 + odb-examples/section/README | 63 ++++ odb-examples/section/buildfile | 43 +++ odb-examples/section/database.hxx | 95 +++++ odb-examples/section/driver.cxx | 133 +++++++ odb-examples/section/person.hxx | 105 ++++++ odb-examples/section/testscript | 13 + odb-examples/sqlite-schema.testscript | 5 + odb-examples/sqlite.testscript | 10 + odb-examples/view/README | 73 ++++ odb-examples/view/buildfile | 46 +++ odb-examples/view/database.hxx | 95 +++++ odb-examples/view/driver.cxx | 416 ++++++++++++++++++++ odb-examples/view/employee.hxx | 350 +++++++++++++++++ odb-examples/view/testscript | 13 + optimistic/README | 64 ---- optimistic/database.hxx | 94 ----- optimistic/driver.cxx | 158 -------- optimistic/makefile | 125 ------ optimistic/person.hxx | 67 ---- oracle-driver.bat | 42 --- oracle.options | 9 - pgsql-driver.bat | 50 --- pgsql.options | 10 - pimpl/README | 62 --- pimpl/database.hxx | 94 ----- pimpl/driver.cxx | 52 --- pimpl/makefile | 126 ------- pimpl/person.cxx | 71 ---- pimpl/person.hxx | 56 --- prepared/README | 65 ---- prepared/database.hxx | 94 ----- prepared/driver.cxx | 250 ------------ prepared/makefile | 125 ------ prepared/person.hxx | 61 --- qt/README | 77 ---- qt/database.hxx | 94 ----- qt/driver.cxx | 180 --------- qt/employee.hxx | 167 -------- qt/makefile | 168 --------- qt/qt4-vc10.vcxproj | 174 --------- qt/qt4-vc10.vcxproj.filters | 25 -- qt/qt4-vc11.vcxproj | 178 --------- qt/qt4-vc11.vcxproj.filters | 25 -- qt/qt4-vc12.vcxproj | 182 --------- qt/qt4-vc12.vcxproj.filters | 25 -- qt/qt4-vc8.vcproj | 350 ----------------- qt/qt4-vc9.vcproj | 357 ------------------ qt/qt5-vc10.vcxproj | 174 --------- qt/qt5-vc10.vcxproj.filters | 25 -- qt/qt5-vc11.vcxproj | 178 --------- qt/qt5-vc11.vcxproj.filters | 25 -- qt/qt5-vc12.vcxproj | 182 --------- qt/qt5-vc12.vcxproj.filters | 25 -- qt/qt5-vc9.vcproj | 357 ------------------ query/README | 59 --- query/database.hxx | 94 ----- query/driver.cxx | 230 ------------ query/makefile | 125 ------ query/person.hxx | 69 ---- relationship/README | 74 ---- relationship/database.hxx | 94 ----- relationship/driver.cxx | 169 --------- relationship/employee.hxx | 160 -------- relationship/makefile | 126 ------- schema/custom/README | 65 ---- schema/custom/database.hxx | 75 ---- schema/custom/driver.cxx | 240 ------------ schema/custom/employee.hxx | 149 -------- schema/custom/makefile | 123 ------ schema/embedded/README | 63 ---- schema/embedded/database.hxx | 75 ---- schema/embedded/driver.cxx | 96 ----- schema/embedded/makefile | 124 ------ schema/embedded/person.hxx | 59 --- section/README | 63 ---- section/database.hxx | 94 ----- section/driver.cxx | 133 ------- section/makefile | 124 ------ section/person.hxx | 105 ------ sqlite-driver.bat | 2 - sqlite.options | 5 - template-vc10.sln | 15 - template-vc11.sln | 15 - template-vc12.sln | 17 - template-vc8.sln | 15 - template-vc9.sln | 15 - template/Makefile.am | 50 --- template/database.hxx | 94 ----- template/driver.cxx | 38 -- template/makefile | 125 ------ template/person.hxx | 53 --- template/template-vc10.vcxproj | 174 --------- template/template-vc10.vcxproj.filters | 25 -- template/template-vc11.vcxproj | 178 --------- template/template-vc11.vcxproj.filters | 25 -- template/template-vc12.vcxproj | 182 --------- template/template-vc12.vcxproj.filters | 25 -- template/template-vc8.vcproj | 350 ----------------- template/template-vc9.vcproj | 357 ------------------ test.bat | 79 ---- tester.bat | 41 -- tester.in | 27 -- version | 1 - view/README | 77 ---- view/database.hxx | 94 ----- view/driver.cxx | 418 --------------------- view/employee.hxx | 356 ------------------ view/makefile | 125 ------ 393 files changed, 11964 insertions(+), 23821 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 access/README delete mode 100644 access/database.hxx delete mode 100644 access/driver.cxx delete mode 100644 access/makefile delete mode 100644 access/person.hxx delete mode 100644 boost/README delete mode 100644 boost/boost-vc10.vcxproj delete mode 100644 boost/boost-vc10.vcxproj.filters delete mode 100644 boost/boost-vc11.vcxproj delete mode 100644 boost/boost-vc11.vcxproj.filters delete mode 100644 boost/boost-vc12.vcxproj delete mode 100644 boost/boost-vc12.vcxproj.filters delete mode 100644 boost/boost-vc8.vcproj delete mode 100644 boost/boost-vc9.vcproj delete mode 100644 boost/database.hxx delete mode 100644 boost/driver.cxx delete mode 100644 boost/employee.hxx delete mode 100644 boost/makefile delete mode 100755 bootstrap delete mode 100644 build/bootstrap.make delete mode 100644 build/configuration-rules.make delete mode 100644 build/configuration.make delete mode 100755 build/configure delete mode 100644 build/import/libboost/configuration-rules.make delete mode 100755 build/import/libboost/configure delete mode 100644 build/import/libboost/date-time/rules.make delete mode 100644 build/import/libboost/date-time/stub.make delete mode 100644 build/import/libboost/header-only/rules.make delete mode 100644 build/import/libboost/header-only/stub.make delete mode 100644 build/import/libboost/version delete mode 100644 build/import/libodb-boost/configuration-rules.make delete mode 100755 build/import/libodb-boost/configure delete mode 100644 build/import/libodb-boost/stub.make delete mode 100644 build/import/libodb-mssql/configuration-rules.make delete mode 100755 build/import/libodb-mssql/configure delete mode 100644 build/import/libodb-mssql/stub.make delete mode 100644 build/import/libodb-mysql/configuration-rules.make delete mode 100755 build/import/libodb-mysql/configure delete mode 100644 build/import/libodb-mysql/stub.make delete mode 100644 build/import/libodb-oracle/configuration-rules.make delete mode 100755 build/import/libodb-oracle/configure delete mode 100644 build/import/libodb-oracle/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-qt/configuration-rules.make delete mode 100755 build/import/libodb-qt/configure delete mode 100644 build/import/libodb-qt/stub.make delete mode 100644 build/import/libodb-sqlite/configuration-rules.make delete mode 100755 build/import/libodb-sqlite/configure delete mode 100644 build/import/libodb-sqlite/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/libqt/configuration-rules.make delete mode 100755 build/import/libqt/configure delete mode 100644 build/import/libqt/core/rules.make delete mode 100644 build/import/libqt/core/stub.make delete mode 100644 build/import/libqt/version delete mode 100644 build/import/odb/configuration-rules.make delete mode 100755 build/import/odb/configure delete mode 100644 build/import/odb/hxx-cxx.make delete mode 100644 build/import/odb/stub.make delete mode 100755 build/mssql/configure delete mode 100755 build/mssql/mssql delete mode 100755 build/mysql/configure delete mode 100755 build/mysql/mysql delete mode 100755 build/oracle/configure delete mode 100755 build/oracle/oracle delete mode 100755 build/pgsql/configure delete mode 100755 build/pgsql/pgsql delete mode 100755 build/sqlite/configure delete mode 100644 c++11/README delete mode 100644 c++11/database.hxx delete mode 100644 c++11/driver.cxx delete mode 100644 c++11/employee.hxx delete mode 100644 c++11/makefile delete mode 100644 composite/README delete mode 100644 composite/database.hxx delete mode 100644 composite/driver.cxx delete mode 100644 composite/makefile delete mode 100644 composite/person.hxx delete mode 100644 configure.ac delete mode 100644 container/README delete mode 100644 container/database.hxx delete mode 100644 container/driver.cxx delete mode 100644 container/makefile delete mode 100644 container/person.hxx delete mode 100644 hello/README delete mode 100644 hello/database.hxx delete mode 100644 hello/driver.cxx delete mode 100644 hello/makefile delete mode 100644 hello/person.hxx delete mode 100644 inheritance/polymorphism/README delete mode 100644 inheritance/polymorphism/database.hxx delete mode 100644 inheritance/polymorphism/driver.cxx delete mode 100644 inheritance/polymorphism/employee.cxx delete mode 100644 inheritance/polymorphism/employee.hxx delete mode 100644 inheritance/polymorphism/makefile delete mode 100644 inheritance/reuse/README delete mode 100644 inheritance/reuse/database.hxx delete mode 100644 inheritance/reuse/driver.cxx delete mode 100644 inheritance/reuse/employee.hxx delete mode 100644 inheritance/reuse/makefile delete mode 100644 inverse/README delete mode 100644 inverse/database.hxx delete mode 100644 inverse/driver.cxx delete mode 100644 inverse/employee.hxx delete mode 100644 inverse/makefile delete mode 100644 m4/acx-pthread.m4 delete mode 100644 m4/c++11.m4 delete mode 100644 m4/database.m4 delete mode 100644 m4/libboost.m4 delete mode 100644 m4/libodb-boost.m4 delete mode 100644 m4/libodb-mssql.m4 delete mode 100644 m4/libodb-mysql.m4 delete mode 100644 m4/libodb-oracle.m4 delete mode 100644 m4/libodb-pgsql.m4 delete mode 100644 m4/libodb-qt.m4 delete mode 100644 m4/libodb-sqlite.m4 delete mode 100644 m4/libodb.m4 delete mode 100644 m4/libqt.m4 delete mode 100644 m4/libtool-link.m4 delete mode 100644 m4/mssql.m4 delete mode 100644 m4/mysql.m4 delete mode 100644 m4/odb.m4 delete mode 100644 m4/oracle.m4 delete mode 100644 m4/pgsql.m4 delete mode 100644 m4/sqlite.m4 delete mode 100644 m4/threads.m4 delete mode 100644 m4/tr1-memory.m4 delete mode 100644 makefile delete mode 100644 mapping/README delete mode 100644 mapping/database.hxx delete mode 100644 mapping/driver.cxx delete mode 100644 mapping/makefile delete mode 100644 mapping/person.hxx delete mode 100644 mapping/traits-mssql.hxx delete mode 100644 mapping/traits-mysql.hxx delete mode 100644 mapping/traits-oracle.hxx delete mode 100644 mapping/traits-pgsql.hxx delete mode 100644 mapping/traits-sqlite.hxx delete mode 100644 mapping/traits.hxx delete mode 100644 mssql-driver.bat delete mode 100644 mssql.options delete mode 100644 mysql-driver.bat delete mode 100644 mysql.options create mode 100644 odb-examples/.gitignore create mode 100644 odb-examples/GPLv2 create mode 100644 odb-examples/LICENSE create mode 100644 odb-examples/README.md create mode 100644 odb-examples/access/README create mode 100644 odb-examples/access/buildfile create mode 100644 odb-examples/access/database.hxx create mode 100644 odb-examples/access/driver.cxx create mode 100644 odb-examples/access/person.hxx create mode 100644 odb-examples/access/testscript create mode 100644 odb-examples/boost/README create mode 100644 odb-examples/boost/database.hxx create mode 100644 odb-examples/boost/driver.cxx create mode 100644 odb-examples/boost/employee.hxx create mode 100644 odb-examples/build/.gitignore create mode 100644 odb-examples/build/bootstrap.build create mode 100644 odb-examples/build/root.build create mode 100644 odb-examples/buildfile create mode 100644 odb-examples/c++11/README create mode 100644 odb-examples/c++11/buildfile create mode 100644 odb-examples/c++11/database.hxx create mode 100644 odb-examples/c++11/driver.cxx create mode 100644 odb-examples/c++11/employee.hxx create mode 100644 odb-examples/c++11/testscript create mode 100644 odb-examples/composite/README create mode 100644 odb-examples/composite/buildfile create mode 100644 odb-examples/composite/database.hxx create mode 100644 odb-examples/composite/driver.cxx create mode 100644 odb-examples/composite/person.hxx create mode 100644 odb-examples/composite/testscript create mode 100644 odb-examples/container/README create mode 100644 odb-examples/container/buildfile create mode 100644 odb-examples/container/database.hxx create mode 100644 odb-examples/container/driver.cxx create mode 100644 odb-examples/container/person.hxx create mode 100644 odb-examples/container/testscript create mode 100644 odb-examples/database-options.testscript create mode 100644 odb-examples/hello/README create mode 100644 odb-examples/hello/buildfile create mode 100644 odb-examples/hello/database.hxx create mode 100644 odb-examples/hello/driver.cxx create mode 100644 odb-examples/hello/person.hxx create mode 100644 odb-examples/hello/testscript create mode 100644 odb-examples/inheritance/polymorphism/README create mode 100644 odb-examples/inheritance/polymorphism/buildfile create mode 100644 odb-examples/inheritance/polymorphism/database.hxx create mode 100644 odb-examples/inheritance/polymorphism/driver.cxx create mode 100644 odb-examples/inheritance/polymorphism/employee.cxx create mode 100644 odb-examples/inheritance/polymorphism/employee.hxx create mode 100644 odb-examples/inheritance/polymorphism/testscript create mode 100644 odb-examples/inheritance/reuse/README create mode 100644 odb-examples/inheritance/reuse/buildfile create mode 100644 odb-examples/inheritance/reuse/database.hxx create mode 100644 odb-examples/inheritance/reuse/driver.cxx create mode 100644 odb-examples/inheritance/reuse/employee.hxx create mode 100644 odb-examples/inheritance/reuse/testscript create mode 100644 odb-examples/inverse/README create mode 100644 odb-examples/inverse/buildfile create mode 100644 odb-examples/inverse/database.hxx create mode 100644 odb-examples/inverse/driver.cxx create mode 100644 odb-examples/inverse/employee.hxx create mode 100644 odb-examples/inverse/testscript create mode 100644 odb-examples/manifest create mode 100644 odb-examples/mapping/README create mode 100644 odb-examples/mapping/buildfile create mode 100644 odb-examples/mapping/database.hxx create mode 100644 odb-examples/mapping/driver.cxx create mode 100644 odb-examples/mapping/person.hxx create mode 100644 odb-examples/mapping/testscript create mode 100644 odb-examples/mapping/traits-mssql.hxx create mode 100644 odb-examples/mapping/traits-mysql.hxx create mode 100644 odb-examples/mapping/traits-oracle.hxx create mode 100644 odb-examples/mapping/traits-pgsql.hxx create mode 100644 odb-examples/mapping/traits-sqlite.hxx create mode 100644 odb-examples/mapping/traits.hxx create mode 100644 odb-examples/mssql-schema.testscript create mode 100644 odb-examples/mssql.testscript create mode 100644 odb-examples/mysql-schema.testscript create mode 100644 odb-examples/mysql.testscript create mode 100644 odb-examples/optimistic/README create mode 100644 odb-examples/optimistic/buildfile create mode 100644 odb-examples/optimistic/database.hxx create mode 100644 odb-examples/optimistic/driver.cxx create mode 100644 odb-examples/optimistic/person.hxx create mode 100644 odb-examples/optimistic/testscript create mode 100644 odb-examples/oracle-schema.testscript create mode 100644 odb-examples/oracle.testscript create mode 100644 odb-examples/pgsql-schema.testscript create mode 100644 odb-examples/pgsql.testscript create mode 100644 odb-examples/pimpl/README create mode 100644 odb-examples/pimpl/buildfile create mode 100644 odb-examples/pimpl/database.hxx create mode 100644 odb-examples/pimpl/driver.cxx create mode 100644 odb-examples/pimpl/person.cxx create mode 100644 odb-examples/pimpl/person.hxx create mode 100644 odb-examples/pimpl/testscript create mode 100644 odb-examples/prepared/README create mode 100644 odb-examples/prepared/buildfile create mode 100644 odb-examples/prepared/database.hxx create mode 100644 odb-examples/prepared/driver.cxx create mode 100644 odb-examples/prepared/person.hxx create mode 100644 odb-examples/prepared/testscript create mode 100644 odb-examples/qt/README create mode 100644 odb-examples/qt/database.hxx create mode 100644 odb-examples/qt/driver.cxx create mode 100644 odb-examples/qt/employee.hxx create mode 100644 odb-examples/query/README create mode 100644 odb-examples/query/buildfile create mode 100644 odb-examples/query/database.hxx create mode 100644 odb-examples/query/driver.cxx create mode 100644 odb-examples/query/person.hxx create mode 100644 odb-examples/query/testscript create mode 100644 odb-examples/relationship/README create mode 100644 odb-examples/relationship/buildfile create mode 100644 odb-examples/relationship/database.hxx create mode 100644 odb-examples/relationship/driver.cxx create mode 100644 odb-examples/relationship/employee.hxx create mode 100644 odb-examples/relationship/testscript create mode 100644 odb-examples/schema/custom/README create mode 100644 odb-examples/schema/custom/buildfile create mode 100644 odb-examples/schema/custom/database.hxx create mode 100644 odb-examples/schema/custom/driver.cxx create mode 100644 odb-examples/schema/custom/employee.hxx create mode 100644 odb-examples/schema/custom/testscript create mode 100644 odb-examples/schema/embedded/README create mode 100644 odb-examples/schema/embedded/buildfile create mode 100644 odb-examples/schema/embedded/database.hxx create mode 100644 odb-examples/schema/embedded/driver.cxx create mode 100644 odb-examples/schema/embedded/person.hxx create mode 100644 odb-examples/schema/embedded/testscript create mode 100644 odb-examples/section/README create mode 100644 odb-examples/section/buildfile create mode 100644 odb-examples/section/database.hxx create mode 100644 odb-examples/section/driver.cxx create mode 100644 odb-examples/section/person.hxx create mode 100644 odb-examples/section/testscript create mode 100644 odb-examples/sqlite-schema.testscript create mode 100644 odb-examples/sqlite.testscript create mode 100644 odb-examples/view/README create mode 100644 odb-examples/view/buildfile create mode 100644 odb-examples/view/database.hxx create mode 100644 odb-examples/view/driver.cxx create mode 100644 odb-examples/view/employee.hxx create mode 100644 odb-examples/view/testscript delete mode 100644 optimistic/README delete mode 100644 optimistic/database.hxx delete mode 100644 optimistic/driver.cxx delete mode 100644 optimistic/makefile delete mode 100644 optimistic/person.hxx delete mode 100644 oracle-driver.bat delete mode 100644 oracle.options delete mode 100644 pgsql-driver.bat delete mode 100644 pgsql.options delete mode 100644 pimpl/README delete mode 100644 pimpl/database.hxx delete mode 100644 pimpl/driver.cxx delete mode 100644 pimpl/makefile delete mode 100644 pimpl/person.cxx delete mode 100644 pimpl/person.hxx delete mode 100644 prepared/README delete mode 100644 prepared/database.hxx delete mode 100644 prepared/driver.cxx delete mode 100644 prepared/makefile delete mode 100644 prepared/person.hxx delete mode 100644 qt/README delete mode 100644 qt/database.hxx delete mode 100644 qt/driver.cxx delete mode 100644 qt/employee.hxx delete mode 100644 qt/makefile delete mode 100644 qt/qt4-vc10.vcxproj delete mode 100644 qt/qt4-vc10.vcxproj.filters delete mode 100644 qt/qt4-vc11.vcxproj delete mode 100644 qt/qt4-vc11.vcxproj.filters delete mode 100644 qt/qt4-vc12.vcxproj delete mode 100644 qt/qt4-vc12.vcxproj.filters delete mode 100644 qt/qt4-vc8.vcproj delete mode 100644 qt/qt4-vc9.vcproj delete mode 100644 qt/qt5-vc10.vcxproj delete mode 100644 qt/qt5-vc10.vcxproj.filters delete mode 100644 qt/qt5-vc11.vcxproj delete mode 100644 qt/qt5-vc11.vcxproj.filters delete mode 100644 qt/qt5-vc12.vcxproj delete mode 100644 qt/qt5-vc12.vcxproj.filters delete mode 100644 qt/qt5-vc9.vcproj delete mode 100644 query/README delete mode 100644 query/database.hxx delete mode 100644 query/driver.cxx delete mode 100644 query/makefile delete mode 100644 query/person.hxx delete mode 100644 relationship/README delete mode 100644 relationship/database.hxx delete mode 100644 relationship/driver.cxx delete mode 100644 relationship/employee.hxx delete mode 100644 relationship/makefile delete mode 100644 schema/custom/README delete mode 100644 schema/custom/database.hxx delete mode 100644 schema/custom/driver.cxx delete mode 100644 schema/custom/employee.hxx delete mode 100644 schema/custom/makefile delete mode 100644 schema/embedded/README delete mode 100644 schema/embedded/database.hxx delete mode 100644 schema/embedded/driver.cxx delete mode 100644 schema/embedded/makefile delete mode 100644 schema/embedded/person.hxx delete mode 100644 section/README delete mode 100644 section/database.hxx delete mode 100644 section/driver.cxx delete mode 100644 section/makefile delete mode 100644 section/person.hxx delete mode 100644 sqlite-driver.bat delete mode 100644 sqlite.options delete mode 100644 template-vc10.sln delete mode 100644 template-vc11.sln delete mode 100644 template-vc12.sln delete mode 100644 template-vc8.sln delete mode 100644 template-vc9.sln delete mode 100644 template/Makefile.am delete mode 100644 template/database.hxx delete mode 100644 template/driver.cxx delete mode 100644 template/makefile delete mode 100644 template/person.hxx delete mode 100644 template/template-vc10.vcxproj delete mode 100644 template/template-vc10.vcxproj.filters delete mode 100644 template/template-vc11.vcxproj delete mode 100644 template/template-vc11.vcxproj.filters delete mode 100644 template/template-vc12.vcxproj delete mode 100644 template/template-vc12.vcxproj.filters delete mode 100644 template/template-vc8.vcproj delete mode 100644 template/template-vc9.vcproj delete mode 100644 test.bat delete mode 100644 tester.bat delete mode 100755 tester.in delete mode 100644 version delete mode 100644 view/README delete mode 100644 view/database.hxx delete mode 100644 view/driver.cxx delete mode 100644 view/employee.hxx delete mode 100644 view/makefile diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 8d08e72..0000000 --- a/.gitignore +++ /dev/null @@ -1,23 +0,0 @@ -# Compiler/linker output. -# -*.o -*.o.d -*.so -*.a -*.l -*.l.cpp-options - -# Generated documentation. -# -*.pdf -*.ps - -# Generated build system files. -# -*-dynamic.make -build/*.options -build/*-driver - -# 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 7f4cad7..0000000 --- a/INSTALL +++ /dev/null @@ -1,163 +0,0 @@ -In this document we use to refer to the name of the database -system you would like to use. Valid values for are: - - 'mysql' - The MySQL database system - 'sqlite' - The SQLite database system - 'pgsql' - The PostgreSQL database system - 'oracle' - The Oracle database system - 'mssql' - The Microsoft SQL Server database system - -Prerequisites -============= - -Required: - - odb http://www.codesynthesis.com/products/odb/ - - libodb http://www.codesynthesis.com/products/odb/ - - libodb- http://www.codesynthesis.com/products/odb/ - -Optional: - - libodb-boost http://www.codesynthesis.com/products/odb/ - - Boost http://www.boost.org - - libodb-qt http://www.codesynthesis.com/products/odb/ - - Qt http://qt.nokia.com - -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 odb-examples -package directory (referred to as odb-examples/ from now on) and run -the configure script, for example: - -./configure --with-database= - -To see the available configuration options run configure with --help: - -./configure --help - -The required --database option specifies the database system you would -like to use. - -The configure script expects the directory where the ODB compiler -binary is installed to be in the executable search path (the PATH -environment variable). If that's not the case, you can use the ODB -configure variable to specify the path to the ODB compiler, for -example: - -./configure ODB=/opt/odb/bin/odb - -If the ODB compiler is not installed and you would like to run it from -its build directory instead, you can use the --with-odb configure option -to specify the build directory, for example: - -./configure --with-odb=/tmp/odb - -The configure script also expects the libodb and libodb- -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 these libraries are not installed and you would like to use their -build directories instead, you can use the --with-libodb and ---with-libodb- configure options to specify their locations, -for example: - -./configure --with-libodb=/tmp/libodb - -If you would also like to build the boost example, then the configure -script should be able to find headers and libraries for libodb-boost -and Boost. Similarly, if you would like to build the qt example, then -the configure script should be able to find headers and libraries for -libodb-qt and Qt. The same mechanisms as described above can be used -to specify locations of these libraries if they cannot be discovered -automatically. - -For each value the configure script has a set of options in -the form --with--* that allow you to specify various database -system parameters, such as the login name, password, and database name, -that should be used when running the examples. Run configure with --help -to see the available options for your database. - -As another example, the following configure command uses the specified -C++ compiler and compiles with optimization and without debug information: - -./configure CXX=g++-4.5 CXXFLAGS=-O3 - -If you would like to build the 'c++11' example as well as other examples -in the C++11 mode, then you will need to pass the necessary options to -turn the C++ compiler into this mode. For example: - -./configure CXXFLAGS=-std=c++0x - -Once configuration is complete, run make to build the examples: - -make - -Once the build is completed successfully, you can run each example -manually from the command line. See the README file accompanying each -example for more information on how to do this. Alternatively, you can -run all the examples using the check target: - -make check - - -Building on Windows -=================== - -The following build instructions are for Windows using Microsoft Visual -Studio. If you would like to build odb-examples 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 directory where the ODB -compiler binary is installed to be in the executable search path (the -PATH environment variable). They also expect the libodb and libodb- -header and import library directories to be in the VC++ Directories Include -and Library search lists. See the INSTALL files in the ODB library packages -for more information on how to setup their VC++ Directories. - -If you would also like to build the boost example, then the header and -import library directories for libodb-boost and Boost must be in the VC++ -Directories Include and Library search lists. Similarly, if you would like -to build the qt example, then the header and import library directories -for libodb-qt and Qt must be in the VC++ Directories Include and Library -search lists. See the INSTALL files in the ODB library packages for more -information on how to setup their VC++ Directories. For Boost and Qt, -refer to their documentation. - -To build the examples, unpack the source code archive and open the -examples--vc.sln file located in the odb-examples package -directory (referred to as odb-examples\ 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. Note that with Visual Studio 10 -(2010) and later the examples are built in the C++11 mode. - -If you would like to build the boost example (requires Boost and -libodb-boost), also open and build the solution in the boost/ -subdirectory. - -If you would like to build the qt example (requires Qt and libodb-qt), -also open and build the solution in the qt/ subdirectory. - -Once the build is completed successfully, you can run each example -manually from the command line. See the README file accompanying each -example for more information on how to do this. Alternatively, you can -run all the examples using the test.bat batch file located in the -odb-examples\ directory. - -Before you can run test.bat, you may need to adjust the database system -parameters, such as the login name, password, and database name, that -should be used when running the examples. To do this, edit the -.options and -driver.bat files located in the -odb-examples\ directory. Once this is done, you can run the examples by -executing the following command from the command prompt: - -test.bat 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 9e83a2f..0000000 --- a/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ -# file : Makefile.am -# license : GNU GPL v2; see accompanying LICENSE file - -SUBDIRS = __path__(dirs) - -if HAVE_TR1_MEMORY -SUBDIRS += __path__(tr1_dirs) -endif - -if HAVE_CXX11 -SUBDIRS += __path__(cxx11_dirs) -endif - -if ODB_EXAMPLES_BOOST -SUBDIRS += __path__(boost_dirs) -endif - -if ODB_EXAMPLES_QT -SUBDIRS += __path__(qt_dirs) -endif - -EXTRA_DIST = __file__(extra_dist) -ACLOCAL_AMFLAGS = -I m4 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 0c35ecd..0000000 --- a/README +++ /dev/null @@ -1,97 +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 ODB examples. The following list gives an -overview of the available examples. See the README file accompanying -each example for more information. - -Note also that most of the examples use the --table-prefix ODB compiler -option to assign a unique prefix to tables created by each example. This -is done to allow examples to run against the same database without -causing any schema conflicts. You don't have to use this option in your -own applications. - -hello - A "Hello World" example that shows how to use ODB to perform basic - database operations. - -query - Shows how to use the ODB Query Language to search the database for - persistent objects matching certain criteria. - -composite - Shows how to declare and use composite value types. - -container - Shows how to use containers as data members in persistent objects. - -relationship - Shows how to declare and use unidirectional to-one and to-many - relationships. - -inverse - Shows how to declare and use bidirectional one-to-one, one-to-many, and - many-to-many relationships. - -inheritance/reuse - Shows how to use reuse inheritance with ODB. - -inheritance/polymorphism - Shows how to use polymorphism inheritance with ODB. - -section - Shows how to use object sections to implement lazy-loading and change- - updating of a subset of data members in a persistent class. - -view - Shows how to define and use object, table, mixed, and native views. - -prepared - Shows how to use prepared queries. - -optimistic - Shows how to use optimistic concurrency in ODB. - -pimpl - Shows how to use virtual data members to implement a persistent class that - employs the pimpl C++ idiom. - -c++11 - Shows how to use ODB with C++11. - -access - Shows various approaches used by ODB to access data members that cannot be - accessed directly. - -boost - Shows how to persist objects that use Boost smart pointers, containers, - and value types with the help of the Boost profile library (libodb-boost). - -qt - Shows how to persist objects that use Qt smart pointers, containers, and - value types with the help of the Qt profile library (libodb-qt). - -schema/embedded - Shows how to generate and use a database schema that is embedded into the - application. - -schema/custom - Shows how to map persistent C++ classes to a custom database schema. - -mapping - Shows how to customize the mapping between C++ value types and database - types. - -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/access/README b/access/README deleted file mode 100644 index 57ca2c7..0000000 --- a/access/README +++ /dev/null @@ -1,63 +0,0 @@ -This example shows various approaches used by ODB to access data members -that cannot be accessed directly. Approaches that are illustrated by this -example include the automatic discovery of suitable accessor/modifier -functions, explicit specification of the accessor/modifier functions, -explicit specification of more complex accessor/modifier expressions, and -use of virtual data members. - -The example consists of the following files: - -person.hxx - Header file implementing the 'person' persistent class. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-query --generate-schema person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent class and its database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. Then it executes a number of database transactions on the 'person' - objects. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/access/database.hxx b/access/database.hxx deleted file mode 100644 index 11599b0..0000000 --- a/access/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : access/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/access/driver.cxx b/access/driver.cxx deleted file mode 100644 index f5d34c8..0000000 --- a/access/driver.cxx +++ /dev/null @@ -1,56 +0,0 @@ -// file : access/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - { - person john ("john@doe.com", "John", "X", "Doe", 31); - person jane ("jane@doe.com", "Jane", "Y", "Doe", 29); - - transaction t (db->begin ()); - db->persist (john); - db->persist (jane); - t.commit (); - } - - { - typedef odb::result result; - - transaction t (db->begin ()); - result r (db->query ()); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << i->getFirst () << ' ' - << i->g_middle () << ' ' - << i->last () << ' ' - << i->email () << ' ' - << i->age () << endl; - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/access/makefile b/access/makefile deleted file mode 100644 index d244601..0000000 --- a/access/makefile +++ /dev/null @@ -1,125 +0,0 @@ -# file : access/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --generate-query \ ---table-prefix access_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/access/person.hxx b/access/person.hxx deleted file mode 100644 index a0e37ea..0000000 --- a/access/person.hxx +++ /dev/null @@ -1,125 +0,0 @@ -// file : access/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include - -#include - -#pragma db object -class person -{ -public: - person () {} - person (const std::string& email, - const std::string& first, - const std::string& middle, - const std::string& last, - unsigned short age) - : email_ (email), first_ (first), middle_ (middle), last_ (last) - { - data_.age = age; - } - - // Standard accessor/modifier names. Auto-discovered by ODB. - // - const std::string& - email () const - { - return email_; - } - - void - email (const std::string& email) - { - email_ = email; - } - - // Get/set-style accessor/modifier names. Also auto-discovered - // by ODB. - // - const std::string& - getFirst () const - { - return first_; - } - - std::string& - setFirst () - { - return first_; - } - - // Unconventional accessor/modifier names which ODB is unable to - // auto-discover (but see also the --{accessor,modifier}-regex - // options). We have to specify these names explicitly (see below). - // - const std::string& - g_middle () const - { - return middle_; - } - - void - s_middle (const std::string& middle) - { - middle_ = middle; - } - - // Accessor/modifier types do not match data member type. Again, - // we have to specify accessor/modifier expressions that perform - // the necessary conversions (see below). - // - const char* - last () const - { - return last_.c_str (); - } - - void - last (const char* last) - { - last_ = last; - } - - // Accessor/modifier for a data member that is wrapped in an - // anonymous struct. We use a virtual data member to handle - // this case. - // - unsigned short - age () const - { - return data_.age; - } - - void - age (unsigned short age) - { - data_.age = age; - } - -private: - #pragma db id - std::string email_; // Accessor and modifier are auto-discovered. - - std::string first_; // Accessor and modifier are auto-discovered. - - #pragma db get(g_middle) set(s_middle) - std::string middle_; - - #pragma db get(std::string (this.last ())) set(last ((?).c_str ())) - std::string last_; - - #pragma db transient - struct - { - unsigned short age; - } data_; - - #pragma db member(age) virtual(unsigned short) // Accessor and modifier - // are auto-discovered. -}; - -#endif // PERSON_HXX diff --git a/boost/README b/boost/README deleted file mode 100644 index 64942bb..0000000 --- a/boost/README +++ /dev/null @@ -1,77 +0,0 @@ -This example shows how to persist objects that use Boost smart pointers, -containers, and value types with the help of the Boost profile library -(libodb-boost). - -The example consists of the following files: - -employee.hxx - Header file defining the 'employee' and 'employer' persistent classes. - We use shared_ptr/weak_ptr smart pointers provided by Boost (as well - as their lazy versions provided by the Boost profile library) to - establish a bidirectional employee-employer relationship. We also use - the boost::gregorian::date type to store the employee's date of birth - and the boost::unordered_set container to keep track of the employee's - email addresses. The employee's object id is boost::uuids::uuid. Finally, - we use boost::optional for the optional middle name. If the middle name - is not present, it will be represented in the database as a NULL value. - -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx -employee.sql - The first three files contain the database support code and the last file - contains the database schema for the employee.hxx header. - - These files are generated by the ODB compiler from employee.hxx using the - following command line: - - odb -d --profile boost --generate-schema --generate-query \ - --generate-session employee.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The -p option is used to instruct the ODB compiler to load the Boost - profile. The --generate-session option is used to enable session support - for all the persistent classes in employee.hxx. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the employee.hxx and employee-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then creates a number of 'employee' and 'employer' objects and - persists them in the database. The next transaction loads all the employees - of a particular employer using the employee-employer relationship. Finally, - the driver performs a few database queries which use data members of the - various Boost value types in their criterion. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c employee-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o employee-odb.o -lodb-boost -lodb-mysql -lodb \ --lboost_date_time - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < employee.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/boost/boost-vc10.vcxproj b/boost/boost-vc10.vcxproj deleted file mode 100644 index c6e5083..0000000 --- a/boost/boost-vc10.vcxproj +++ /dev/null @@ -1,174 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - Unicode - - - Application - true - Unicode - - - Application - false - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-boost-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-boost-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-boost.lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-boost.lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/boost/boost-vc10.vcxproj.filters b/boost/boost-vc10.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/boost/boost-vc10.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/boost/boost-vc11.vcxproj b/boost/boost-vc11.vcxproj deleted file mode 100644 index ef60fc2..0000000 --- a/boost/boost-vc11.vcxproj +++ /dev/null @@ -1,178 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - v110 - Unicode - - - Application - true - v110 - Unicode - - - Application - false - v110 - true - Unicode - - - Application - false - v110 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-boost-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-boost-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-boost.lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-boost.lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/boost/boost-vc11.vcxproj.filters b/boost/boost-vc11.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/boost/boost-vc11.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/boost/boost-vc12.vcxproj b/boost/boost-vc12.vcxproj deleted file mode 100644 index db230a3..0000000 --- a/boost/boost-vc12.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - v120 - Unicode - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database)-d.lib;odb-boost-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database)-d.lib;odb-boost-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database).lib;odb-boost.lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;_SCL_SECURE_NO_WARNINGS;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database).lib;odb-boost.lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/boost/boost-vc12.vcxproj.filters b/boost/boost-vc12.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/boost/boost-vc12.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/boost/boost-vc8.vcproj b/boost/boost-vc8.vcproj deleted file mode 100644 index 661f6b3..0000000 --- a/boost/boost-vc8.vcproj +++ /dev/null @@ -1,350 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - -__file_entry_custom_build__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) -__file_entry__(__path__(odb_header_stem)-odb.hxx) -__file_entry__(__path__(odb_header_stem)-odb.ixx) -__file_entry__(database.hxx) -__file_entries__(extra_headers) - - - - - diff --git a/boost/boost-vc9.vcproj b/boost/boost-vc9.vcproj deleted file mode 100644 index e3f5252..0000000 --- a/boost/boost-vc9.vcproj +++ /dev/null @@ -1,357 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - -__file_entry_custom_build__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) -__file_entry__(__path__(odb_header_stem)-odb.hxx) -__file_entry__(__path__(odb_header_stem)-odb.ixx) -__file_entry__(database.hxx) -__file_entries__(extra_headers) - - - - - diff --git a/boost/database.hxx b/boost/database.hxx deleted file mode 100644 index 293f592..0000000 --- a/boost/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : boost/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/boost/driver.cxx b/boost/driver.cxx deleted file mode 100644 index 5a096f6..0000000 --- a/boost/driver.cxx +++ /dev/null @@ -1,176 +0,0 @@ -// file : boost/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include - -#include -#include -#include - -#include "database.hxx" // create_database - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace boost::gregorian; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - using boost::shared_ptr; - - try - { - auto_ptr db (create_database (argc, argv)); - - // Create a few persistent objects. - // - { - // Simple Tech Ltd. - // - { - shared_ptr er (new employer ("Simple Tech Ltd")); - - shared_ptr john ( - new employee ("John", "Doe", date (1975, Jan, 1), er)); - - shared_ptr jane ( - new employee ("Jane", "Q", "Doe", date (1976, Feb, 2), er)); - - john->emails ().insert ("john_d@example.com"); - john->emails ().insert ("john.doe@example.com"); - jane->emails ().insert ("jane_d@example.com"); - jane->emails ().insert ("jane.doe@example.com"); - - // Set the inverse side of the employee-employer relationship. - // - er->employees ().push_back (john); - er->employees ().push_back (jane); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (john); - db->persist (jane); - - t.commit (); - } - - // Complex Systems Inc. - // - { - shared_ptr er (new employer ("Complex Systems Inc")); - - shared_ptr john ( - new employee ("John", "Z", "Smith", date (1977, Mar, 3), er)); - - shared_ptr jane ( - new employee ("Jane", "Smith", date (1978, Apr, 4), er)); - - john->emails ().insert ("john_s@example.com"); - john->emails ().insert ("john.smith@example.com"); - jane->emails ().insert ("jane_s@example.com"); - jane->emails ().insert ("jane.smith@example.com"); - - // Set the inverse side of the employee-employer relationship. - // - er->employees ().push_back (john); - er->employees ().push_back (jane); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (john); - db->persist (jane); - - t.commit (); - } - } - - - // Load Simple Tech Ltd and print its employees. - // - { - session s; - transaction t (db->begin ()); - - shared_ptr stl (db->load ("Simple Tech Ltd")); - - employees& es (stl->employees ()); - - for (employees::iterator i (es.begin ()); i != es.end (); ++i) - { - lazy_weak_ptr& lwp (*i); - shared_ptr p (lwp.load ()); // Load and lock. - - cout << p->first () << " "; - - if (p->middle ()) - cout << *p->middle () << " "; - - cout << p->last () << endl; - - cout << " born: " << p->born () << endl - << " employer: " << p->employer ()->name () << endl; - - for (emails::const_iterator j (p->emails ().begin ()); - j != p->emails ().end (); ++j) - { - cout << " email: " << *j << endl; - } - - cout << " id: {" << p->id () << '}' << endl - << endl; - } - - t.commit (); - } - - typedef odb::query query; - typedef odb::result result; - - // Search for Complex Systems Inc employees that were born before - // April 1978. - // - { - session s; - transaction t (db->begin ()); - - result r (db->query ( - query::employer->name == "Complex Systems Inc" && - query::born < date (1978, Apr, 1))); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << i->first () << " " << i->last () << " " << i->born () << endl; - - cout << endl; - t.commit (); - } - - // Search for all the employees that don't have a middle name. - // - { - session s; - transaction t (db->begin ()); - - result r (db->query (query::middle.is_null ())); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << i->first () << " " << i->last () << endl; - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/boost/employee.hxx b/boost/employee.hxx deleted file mode 100644 index 8d6173a..0000000 --- a/boost/employee.hxx +++ /dev/null @@ -1,196 +0,0 @@ -// file : boost/employee.hxx -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -using boost::shared_ptr; -using boost::weak_ptr; - -using odb::boost::lazy_shared_ptr; -using odb::boost::lazy_weak_ptr; - -using boost::uuids::uuid; -using boost::gregorian::date; - -// Forward declarations. -// -class employer; -class employee; - -typedef boost::unordered_set emails; -typedef std::vector > employees; - -#pragma db object -class employer -{ -public: - employer (const std::string& name) - : name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - - // Employees of this employer. - // - typedef ::employees employees_type; - - const employees_type& - employees () const - { - return employees_; - } - - employees_type& - employees () - { - return employees_; - } - -private: - friend class odb::access; - - employer () {} - - #pragma db id - std::string name_; - - #pragma db value_not_null inverse(employer_) - employees_type employees_; -}; - -#pragma db object -class employee -{ -public: - typedef ::employer employer_type; - - employee (const std::string& first, - const std::string& last, - const date& born, - shared_ptr employer) - : id_ (boost::uuids::random_generator () ()), - first_ (first), last_ (last), - born_ (born), - employer_ (employer) - { - } - - employee (const std::string& first, - const std::string& middle, - const std::string& last, - const date& born, - shared_ptr employer) - : id_ (boost::uuids::random_generator () ()), - first_ (first), middle_ (middle), last_ (last), - born_ (born), - employer_ (employer) - { - } - - // Id. - // - const uuid& - id () const - { - return id_; - } - - // Name. - // - const std::string& - first () const - { - return first_; - } - - const boost::optional& - middle () const - { - return middle_; - } - - const std::string& - last () const - { - return last_; - } - - // Date of birth. - // - const date& - born () const - { - return born_; - } - - // Emails. - // - typedef ::emails emails_type; - - const emails_type& - emails () const - { - return emails_; - } - - emails_type& - emails () - { - return emails_; - } - - // Employer. - // - shared_ptr - employer () const - { - return employer_; - } - - void - employer (shared_ptr employer) - { - employer_ = employer; - } - -private: - friend class odb::access; - - employee () {} - - #pragma db id - uuid id_; - - std::string first_; - boost::optional middle_; - std::string last_; - - date born_; - emails_type emails_; - - #pragma db not_null - shared_ptr employer_; -}; - -#endif // EMPLOYEE_HXX diff --git a/boost/makefile b/boost/makefile deleted file mode 100644 index 5d1d1bc..0000000 --- a/boost/makefile +++ /dev/null @@ -1,151 +0,0 @@ -# file : boost/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := employee.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libodb-boost/stub.make,\ - l: odb_boost.l,cpp-options: odb_boost.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libboost/header-only/stub.make,\ - cpp-options: boost.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libboost/date-time/stub.make,\ - l: boost_date_time.l) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb_boost.l) $(odb.l) $(boost_date_time.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_boost.l.cpp-options) \ -$(odb_db.l.cpp-options) $(boost.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --profile boost \ ---generate-query --generate-schema --generate-session --table-prefix boost_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) $(odb_boost.l.cpp-options) $(boost.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README \ -$(call vc8projs,$(name)) $(call vc9projs,$(name)) $(call vc10projs,$(name)) \ -$(call vc11projs,$(name)) $(call vc12projs,$(name)) \ -$(call vc8slns,$(name)) $(call vc9slns,$(name)) $(call vc10slns,$(name)) \ -$(call vc11slns,$(name)) $(call vc12slns,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,$(name),$(name)) - $(call meta-vc9projs,$(name),$(name)) - $(call meta-vc10projs,$(name),$(name)) - $(call meta-vc11projs,$(name),$(name)) - $(call meta-vc12projs,$(name),$(name)) - $(call meta-vc8slns,$(name)) - $(call meta-vc9slns,$(name)) - $(call meta-vc10slns,$(name)) - $(call meta-vc11slns,$(name)) - $(call meta-vc12slns,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8sln.make) -$(call include,$(bld_root)/meta/vc9sln.make) -$(call include,$(bld_root)/meta/vc10sln.make) -$(call include,$(bld_root)/meta/vc11sln.make) -$(call include,$(bld_root)/meta/vc12sln.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - 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/bootstrap.make b/build/bootstrap.make deleted file mode 100644 index 5ad75c5..0000000 --- a/build/bootstrap.make +++ /dev/null @@ -1,173 +0,0 @@ -# file : build/bootstrap.make -# license : GNU GPL v2; see accompanying LICENSE file - -project_name := odb-examples - -# 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 - -# Configuration -# -$(call include,$(scf_root)/configuration.make) - -def_goal := $(.DEFAULT_GOAL) - -# Include C++ configuration. We need to know if we are using the generic -# C++ compiler in which case we need to compensate for missing dependency -# auto-generation (see below). -# -$(call include,$(bld_root)/cxx/configuration.make) - -# 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 - -endif - -# Database schema creation. -# -ifeq ($(filter $(db_id),sqlite),) -$(out_base)/.test: schema = \ -$(foreach h,$(header),$(call \ -message,sql $$1,$(dcf_root)/$(db_id)-driver \ -$$1,$(out_base)/$(basename $h).sql)$(literal_newline)$(literal_tab)) -endif - -# Dist setup. -# -ifneq ($(filter $(MAKECMDGOALS),dist),) - -# Make sure the distribution prefix is set if the goal is dist. -# -ifeq ($(dist_prefix),) -$(error dist_prefix is not set) -endif - -databases := mysql sqlite pgsql oracle mssql -$(dist): databases := $(databases) - -# $1 project template without the -vcN.vc[x]proj suffix. -# $2 project name without the -vcN.vc[x]proj suffix. -# -$(dist): meta-vc8projs = \ -$(foreach d,$(databases),$(call \ -meta-vc8proj,$1-vc8.vcproj,$(if $2,$2,$(notdir \ -$1))-$d-vc8.vcproj,database,$d)$(literal_newline)$(literal_tab))@: - -$(dist): meta-vc9projs = \ -$(foreach d,$(databases),$(call \ -meta-vc9proj,$1-vc9.vcproj,$(if $2,$2,$(notdir \ -$1))-$d-vc9.vcproj,database,$d)$(literal_newline)$(literal_tab))@: - -$(dist): meta-vc10projs = \ -$(foreach d,$(databases),$(call \ -meta-vc10proj,$1-vc10.vcxproj,$(if $2,$2,$(notdir \ -$1))-$d-vc10.vcxproj,database,$d)$(literal_newline)$(literal_tab))@: - -$(dist): meta-vc11projs = \ -$(foreach d,$(databases),$(call \ -meta-vc11proj,$1-vc11.vcxproj,$(if $2,$2,$(notdir \ -$1))-$d-vc11.vcxproj,database,$d)$(literal_newline)$(literal_tab))@: - -$(dist): meta-vc12projs = \ -$(foreach d,$(databases),$(call \ -meta-vc12proj,$1-vc12.vcxproj,$(if $2,$2,$(notdir \ -$1))-$d-vc12.vcxproj,database,$d)$(literal_newline)$(literal_tab))@: - - -# $1 project name without the -vcN.vc[x]proj suffix. -# -vc8projs = $(addprefix $1-,$(addsuffix -vc8.vcproj,$(databases))) - -vc9projs = $(addprefix $1-,$(addsuffix -vc9.vcproj,$(databases))) - -vc10projs = $(addprefix $1-,$(addsuffix -vc10.vcxproj,$(databases))) \ -$(addprefix $1-,$(addsuffix -vc10.vcxproj.filters,$(databases))) - -vc11projs = $(addprefix $1-,$(addsuffix -vc11.vcxproj,$(databases))) \ -$(addprefix $1-,$(addsuffix -vc11.vcxproj.filters,$(databases))) - -vc12projs = $(addprefix $1-,$(addsuffix -vc12.vcxproj,$(databases))) \ -$(addprefix $1-,$(addsuffix -vc12.vcxproj.filters,$(databases))) - -# $1 solution name without the -vcN.sln suffix. -# $2 extra project suffix in addition to --vcN.vcproj (optional) -# -$(dist): meta-vc8slns = \ -$(foreach d,$(databases),$(call \ -meta-vc8sln,$(src_root)/template-vc8.sln,$1-$d-vc8.sln,$2-$d-vc8.vcproj,database,$d)$(literal_newline)\ -$(literal_tab))@: - -$(dist): meta-vc9slns = \ -$(foreach d,$(databases),$(call \ -meta-vc9sln,$(src_root)/template-vc9.sln,$1-$d-vc9.sln,$2-$d-vc9.vcproj,database,$d)$(literal_newline)\ -$(literal_tab))@: - -$(dist): meta-vc10slns = \ -$(foreach d,$(databases),$(call \ -meta-vc10sln,$(src_root)/template-vc10.sln,$1-$d-vc10.sln,$2-$d-vc10.vcxproj,database,$d)$(literal_newline)\ -$(literal_tab))@: - -$(dist): meta-vc11slns = \ -$(foreach d,$(databases),$(call \ -meta-vc11sln,$(src_root)/template-vc11.sln,$1-$d-vc11.sln,$2-$d-vc11.vcxproj,database,$d)$(literal_newline)\ -$(literal_tab))@: - -$(dist): meta-vc12slns = \ -$(foreach d,$(databases),$(call \ -meta-vc12sln,$(src_root)/template-vc12.sln,$1-$d-vc12.sln,$2-$d-vc12.vcxproj,database,$d)$(literal_newline)\ -$(literal_tab))@: - -vc8slns = $(addprefix $1-,$(addsuffix -vc8.sln,$(databases))) -vc9slns = $(addprefix $1-,$(addsuffix -vc9.sln,$(databases))) -vc10slns = $(addprefix $1-,$(addsuffix -vc10.sln,$(databases))) -vc11slns = $(addprefix $1-,$(addsuffix -vc11.sln,$(databases))) -vc12slns = $(addprefix $1-,$(addsuffix -vc12.sln,$(databases))) - -endif - -# If we don't have dependency auto-generation then we need to manually -# make sure that ODB 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 - -.DEFAULT_GOAL := $(def_goal) diff --git a/build/configuration-rules.make b/build/configuration-rules.make deleted file mode 100644 index ee464cd..0000000 --- a/build/configuration-rules.make +++ /dev/null @@ -1,18 +0,0 @@ -# file : build/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/configuration-dynamic.make: | $(dcf_root)/. - $(call message,,$(scf_root)/configure $@) - -ifndef %foreign% - -disfigure:: - $(call message,rm $$1,rm -f $$1,$(dcf_root)/configuration-dynamic.make) - $(call message,rm $$1,rm -f $$1,$(dcf_root)/*.options) - $(call message,rm $$1,rm -f $$1,$(dcf_root)/*-driver) - -endif - -ifeq ($(.DEFAULT_GOAL),$(dcf_root)/configuration-dynamic.make) -.DEFAULT_GOAL := -endif diff --git a/build/configuration.make b/build/configuration.make deleted file mode 100644 index 6c4eab2..0000000 --- a/build/configuration.make +++ /dev/null @@ -1,33 +0,0 @@ -# file : build/configuration.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/configuration-rules.make,$(dcf_root)) - -# Dynamic configuration. -# -db_id := - -$(call -include,$(dcf_root)/configuration-dynamic.make) - -ifdef db_id - -ifeq ($(db_id),mysql) -db_macro := DATABASE_MYSQL -else ifeq ($(db_id),sqlite) -db_macro := DATABASE_SQLITE -else ifeq ($(db_id),pgsql) -db_macro := DATABASE_PGSQL -else ifeq ($(db_id),oracle) -db_macro := DATABASE_ORACLE -else ifeq ($(db_id),mssql) -db_macro := DATABASE_MSSQL -endif - -$(out_root)/%: db_id := $(db_id) -$(out_root)/%: db_macro := $(db_macro) - -else - -.NOTPARALLEL: - -endif diff --git a/build/configure b/build/configure deleted file mode 100755 index fa05813..0000000 --- a/build/configure +++ /dev/null @@ -1,34 +0,0 @@ -#! /usr/bin/env bash - -# file : build/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 -$echo "configuring '$project_name'" -$echo -$echo - -$echo -$echo "Please select the database you would like to use:" -$echo -$echo "(1) MySQL" -$echo "(2) SQLite" -$echo "(3) PostgreSQL" -$echo "(4) Oracle" -$echo "(5) Microsoft SQL Server" -$echo - -db_id=`read_option "mysql sqlite pgsql oracle mssql"` - -echo "db_id := $db_id" >$1 - -source $scf_root/$db_id/configure diff --git a/build/import/libboost/configuration-rules.make b/build/import/libboost/configuration-rules.make deleted file mode 100644 index dba014c..0000000 --- a/build/import/libboost/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libboost/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libboost/configuration-dynamic.make: | $(dcf_root)/import/libboost/. - $(call message,,$(scf_root)/import/libboost/configure $@) - -ifndef %foreign% - -disfigure:: - $(call message,rm $(dcf_root)/import/libboost/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libboost/configuration-dynamic.make) - -endif diff --git a/build/import/libboost/configure b/build/import/libboost/configure deleted file mode 100755 index 84d03b2..0000000 --- a/build/import/libboost/configure +++ /dev/null @@ -1,72 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libboost/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 'boost libraries' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'boost libraries' as opposed to the development build?" -$echo - -installed=`read_y_n y` - -if [ "$installed" = "n" ]; then - - $echo - $echo "Please enter the 'boost' 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"` -fi - -$echo -$echo "Link explicitly to the boost system library? This library" -$echo "is available since boost 1.35.0 and linking to it explicitly" -$echo "may be required by newer linkers." -$echo - -link_system=`read_y_n y` - -$echo -$echo "Please enter optional suffix that may be embedded into the" -$echo "boost library names. For example, if your library names are in" -$echo "the libboost_regex-gcc41-mt-d.so form, then enter -gcc41-mt-d" -$echo "Otherwise leave this field blank." -$echo - -suffix= -read -e -p "[]: " suffix - -echo libboost_installed := $installed >$1 -echo libboost_suffix := $suffix >>$1 -echo libboost_system := $link_system >>$1 - -if [ "$installed" = "n" ]; then - - echo libboost_root := $root >>$1 - echo libboost_type := $type >>$1 - -fi diff --git a/build/import/libboost/date-time/rules.make b/build/import/libboost/date-time/rules.make deleted file mode 100644 index abc8819..0000000 --- a/build/import/libboost/date-time/rules.make +++ /dev/null @@ -1,49 +0,0 @@ -# file : build/import/libboost/date-time/rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libboost/%: root := $(libboost_root) - -$(dcf_root)/import/libboost/date-time/date-time.l: \ - | $(dcf_root)/import/libboost/date-time/. - -ifeq ($(libboost_type),archive) - -ifeq ($(libboost_system),y) -$(dcf_root)/import/libboost/date-time/date-time.l: \ - $(libboost_root)/stage/lib/libboost_date_time$(libboost_suffix).a \ - $(libboost_root)/stage/lib/libboost_system$(libboost_suffix).a -else -$(dcf_root)/import/libboost/date-time/date-time.l: \ - $(libboost_root)/stage/lib/libboost_date_time$(libboost_suffix).a -endif - @echo $^ >$@ - -else - -ifeq ($(libboost_system),y) -$(dcf_root)/import/libboost/date-time/date-time.l: \ - $(libboost_root)/stage/lib/libboost_date_time$(libboost_suffix).so \ - $(libboost_root)/stage/lib/libboost_system$(libboost_suffix).so -else -$(dcf_root)/import/libboost/date-time/date-time.l: \ - $(libboost_root)/stage/lib/libboost_date_time$(libboost_suffix).so -endif - @echo $^ >$@ - @echo rpath:$(root)/stage/lib >>$@ - -endif - - -$(dcf_root)/import/libboost/date-time/date-time.l.cpp-options: \ - | $(dcf_root)/import/libboost/date-time/. - @echo include: -I$(root) >$@ - -ifndef %foreign% - -disfigure:: - $(call message,rm $(dcf_root)/import/libboost/date-time/date-time.l,\ -rm -f $(dcf_root)/import/libboost/date-time/date-time.l) - $(call message,,\ -rm -f $(dcf_root)/import/libboost/date-time/date-time.l.cpp-options) - -endif diff --git a/build/import/libboost/date-time/stub.make b/build/import/libboost/date-time/stub.make deleted file mode 100644 index 6f3aad2..0000000 --- a/build/import/libboost/date-time/stub.make +++ /dev/null @@ -1,34 +0,0 @@ -# file : build/import/libboost/date-time/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libboost/configuration-rules.make,$(dcf_root)) - -libboost_installed := - -$(call -include,$(dcf_root)/import/libboost/configuration-dynamic.make) - -ifdef libboost_installed - -ifeq ($(libboost_installed),y) - -ifeq ($(libboost_system),y) -$(call export,l: -lboost_date_time$(libboost_suffix) -lboost_system$(libboost_suffix),cpp_options: ) -else -$(call export,l: -lboost_date_time$(libboost_suffix),cpp_options: ) -endif - -else - -$(call include-once,$(scf_root)/import/libboost/date-time/rules.make,$(dcf_root)) - -$(call export,\ - l: $(dcf_root)/import/libboost/date-time/date-time.l,\ - cpp-options: $(dcf_root)/import/libboost/date-time/date-time.l.cpp-options) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libboost/header-only/rules.make b/build/import/libboost/header-only/rules.make deleted file mode 100644 index b5b0726..0000000 --- a/build/import/libboost/header-only/rules.make +++ /dev/null @@ -1,16 +0,0 @@ -# file : build/import/libboost/header-only/rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libboost/%: root := $(libboost_root) - -$(dcf_root)/import/libboost/header-only/header-only.l.cpp-options: \ - | $(dcf_root)/import/libboost/header-only/. - @echo include: -I$(root) >$@ - -ifndef %foreign% - -disfigure:: - $(call message,rm $(dcf_root)/import/libboost/header-only/header-only.l,\ -rm -f $(dcf_root)/import/libboost/header-only/header-only.l.cpp-options) - -endif diff --git a/build/import/libboost/header-only/stub.make b/build/import/libboost/header-only/stub.make deleted file mode 100644 index eebddbf..0000000 --- a/build/import/libboost/header-only/stub.make +++ /dev/null @@ -1,26 +0,0 @@ -# file : build/import/libboost/header-only/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libboost/configuration-rules.make,$(dcf_root)) - -libboost_installed := - -$(call -include,$(dcf_root)/import/libboost/configuration-dynamic.make) - -ifdef libboost_installed - -ifeq ($(libboost_installed),n) - -$(call include-once,$(scf_root)/import/libboost/header-only/rules.make,$(dcf_root)) - -$(call export,\ - l: ,\ - cpp-options: $(dcf_root)/import/libboost/header-only/header-only.l.cpp-options) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libboost/version b/build/import/libboost/version deleted file mode 100644 index faef31a..0000000 --- a/build/import/libboost/version +++ /dev/null @@ -1 +0,0 @@ -0.7.0 diff --git a/build/import/libodb-boost/configuration-rules.make b/build/import/libodb-boost/configuration-rules.make deleted file mode 100644 index a347655..0000000 --- a/build/import/libodb-boost/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libodb-boost/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libodb-boost/configuration-dynamic.make: | $(dcf_root)/import/libodb-boost/. - $(call message,,$(scf_root)/import/libodb-boost/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/libodb-boost/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libodb-boost/configuration-dynamic.make) - -endif diff --git a/build/import/libodb-boost/configure b/build/import/libodb-boost/configure deleted file mode 100755 index 8330535..0000000 --- a/build/import/libodb-boost/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libodb-boost/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-boost' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'libodb-boost' 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-boost'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'libodb-boost'." -$echo - -out_root=`read_path --directory $src_root` - -fi - -echo libodb_boost_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-boost/stub.make b/build/import/libodb-boost/stub.make deleted file mode 100644 index 73e80e6..0000000 --- a/build/import/libodb-boost/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/libodb-boost/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libodb-boost/configuration-rules.make,$(dcf_root)) - -libodb_boost_installed := - -$(call -include,$(dcf_root)/import/libodb-boost/configuration-dynamic.make) - -ifdef libodb_boost_installed - -ifeq ($(libodb_boost_installed),y) - -$(call export,l: -lodb-boost -lodb,cpp-options: ) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/libodb-boost/stub.make) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libodb-mssql/configuration-rules.make b/build/import/libodb-mssql/configuration-rules.make deleted file mode 100644 index 5fd58bc..0000000 --- a/build/import/libodb-mssql/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libodb-mssql/configuration-rules.make -# license : ODB NCUEL; see accompanying LICENSE file - -$(dcf_root)/import/libodb-mssql/configuration-dynamic.make: | $(dcf_root)/import/libodb-mssql/. - $(call message,,$(scf_root)/import/libodb-mssql/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/libodb-mssql/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libodb-mssql/configuration-dynamic.make) - -endif diff --git a/build/import/libodb-mssql/configure b/build/import/libodb-mssql/configure deleted file mode 100755 index 5e2a28a..0000000 --- a/build/import/libodb-mssql/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libodb-mssql/configure -# license : ODB NCUEL; 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-mssql' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'libodb-mssql' 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-mssql'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'libodb-mssql'." -$echo - -out_root=`read_path --directory $src_root` - -fi - -echo libodb_mssql_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-mssql/stub.make b/build/import/libodb-mssql/stub.make deleted file mode 100644 index eebf11a..0000000 --- a/build/import/libodb-mssql/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/libodb-mssql/stub.make -# license : ODB NCUEL; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libodb-mssql/configuration-rules.make,$(dcf_root)) - -libodb_mssql_installed := - -$(call -include,$(dcf_root)/import/libodb-mssql/configuration-dynamic.make) - -ifdef libodb_mssql_installed - -ifeq ($(libodb_mssql_installed),y) - -$(call export,l: -lodb-mssql -lodb -lodbc,cpp-options: ) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/libodb-mssql/stub.make) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libodb-mysql/configuration-rules.make b/build/import/libodb-mysql/configuration-rules.make deleted file mode 100644 index 384d3d4..0000000 --- a/build/import/libodb-mysql/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libodb-mysql/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libodb-mysql/configuration-dynamic.make: | $(dcf_root)/import/libodb-mysql/. - $(call message,,$(scf_root)/import/libodb-mysql/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/libodb-mysql/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libodb-mysql/configuration-dynamic.make) - -endif diff --git a/build/import/libodb-mysql/configure b/build/import/libodb-mysql/configure deleted file mode 100755 index 2a1fa8d..0000000 --- a/build/import/libodb-mysql/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libodb-mysql/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-mysql' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'libodb-mysql' 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-mysql'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'libodb-mysql'." -$echo - -out_root=`read_path --directory $src_root` - -fi - -echo libodb_mysql_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-mysql/stub.make b/build/import/libodb-mysql/stub.make deleted file mode 100644 index 1b1ecbb..0000000 --- a/build/import/libodb-mysql/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/libodb-mysql/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libodb-mysql/configuration-rules.make,$(dcf_root)) - -libodb_mysql_installed := - -$(call -include,$(dcf_root)/import/libodb-mysql/configuration-dynamic.make) - -ifdef libodb_mysql_installed - -ifeq ($(libodb_mysql_installed),y) - -$(call export,l: -lodb-mysql -lodb -lmysqlclient_r,cpp-options: ) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/libodb-mysql/stub.make) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libodb-oracle/configuration-rules.make b/build/import/libodb-oracle/configuration-rules.make deleted file mode 100644 index cef4150..0000000 --- a/build/import/libodb-oracle/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libodb-oracle/configuration-rules.make -# license : ODB NCUEL; see accompanying LICENSE file - -$(dcf_root)/import/libodb-oracle/configuration-dynamic.make: | $(dcf_root)/import/libodb-oracle/. - $(call message,,$(scf_root)/import/libodb-oracle/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/libodb-oracle/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libodb-oracle/configuration-dynamic.make) - -endif diff --git a/build/import/libodb-oracle/configure b/build/import/libodb-oracle/configure deleted file mode 100755 index 81cd5e4..0000000 --- a/build/import/libodb-oracle/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libodb-oracle/configure -# license : ODB NCUEL; 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-oracle' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'libodb-oracle' 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-oracle'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'libodb-oracle'." -$echo - -out_root=`read_path --directory $src_root` - -fi - -echo libodb_oracle_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-oracle/stub.make b/build/import/libodb-oracle/stub.make deleted file mode 100644 index 6861dc7..0000000 --- a/build/import/libodb-oracle/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/libodb-oracle/stub.make -# license : ODB NCUEL; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libodb-oracle/configuration-rules.make,$(dcf_root)) - -libodb_oracle_installed := - -$(call -include,$(dcf_root)/import/libodb-oracle/configuration-dynamic.make) - -ifdef libodb_oracle_installed - -ifeq ($(libodb_oracle_installed),y) - -$(call export,l: -lodb-oracle -lodb -lclntsh,cpp-options: ) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/libodb-oracle/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-qt/configuration-rules.make b/build/import/libodb-qt/configuration-rules.make deleted file mode 100644 index 9765a0c..0000000 --- a/build/import/libodb-qt/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libodb-qt/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libodb-qt/configuration-dynamic.make: | $(dcf_root)/import/libodb-qt/. - $(call message,,$(scf_root)/import/libodb-qt/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/libodb-qt/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libodb-qt/configuration-dynamic.make) - -endif diff --git a/build/import/libodb-qt/configure b/build/import/libodb-qt/configure deleted file mode 100755 index 6213974..0000000 --- a/build/import/libodb-qt/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libodb-qt/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-qt' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'libodb-qt' 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-qt'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'libodb-qt'." -$echo - -out_root=`read_path --directory $src_root` - -fi - -echo libodb_qt_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-qt/stub.make b/build/import/libodb-qt/stub.make deleted file mode 100644 index bd5e2ea..0000000 --- a/build/import/libodb-qt/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/libodb-qt/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libodb-qt/configuration-rules.make,$(dcf_root)) - -libodb_qt_installed := - -$(call -include,$(dcf_root)/import/libodb-qt/configuration-dynamic.make) - -ifdef libodb_qt_installed - -ifeq ($(libodb_qt_installed),y) - -$(call export,l: -lodb-qt -lodb,cpp-options: ) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/libodb-qt/stub.make) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libodb-sqlite/configuration-rules.make b/build/import/libodb-sqlite/configuration-rules.make deleted file mode 100644 index bf8dee4..0000000 --- a/build/import/libodb-sqlite/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libodb-sqlite/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libodb-sqlite/configuration-dynamic.make: | $(dcf_root)/import/libodb-sqlite/. - $(call message,,$(scf_root)/import/libodb-sqlite/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/libodb-sqlite/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libodb-sqlite/configuration-dynamic.make) - -endif diff --git a/build/import/libodb-sqlite/configure b/build/import/libodb-sqlite/configure deleted file mode 100755 index 9f245f5..0000000 --- a/build/import/libodb-sqlite/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libodb-sqlite/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-sqlite' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'libodb-sqlite' 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-sqlite'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'libodb-sqlite'." -$echo - -out_root=`read_path --directory $src_root` - -fi - -echo libodb_sqlite_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-sqlite/stub.make b/build/import/libodb-sqlite/stub.make deleted file mode 100644 index 417e65a..0000000 --- a/build/import/libodb-sqlite/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/libodb-sqlite/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libodb-sqlite/configuration-rules.make,$(dcf_root)) - -libodb_sqlite_installed := - -$(call -include,$(dcf_root)/import/libodb-sqlite/configuration-dynamic.make) - -ifdef libodb_sqlite_installed - -ifeq ($(libodb_sqlite_installed),y) - -$(call export,l: -lodb-sqlite -lodb -lsqlite3,cpp-options: ) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/libodb-sqlite/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/libqt/configuration-rules.make b/build/import/libqt/configuration-rules.make deleted file mode 100644 index badc561..0000000 --- a/build/import/libqt/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/libqt/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libqt/configuration-dynamic.make: | $(dcf_root)/import/libqt/. - $(call message,,$(scf_root)/import/libqt/configure $@) - -ifndef %foreign% - -disfigure:: - $(call message,rm $(dcf_root)/import/libqt/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/libqt/configuration-dynamic.make) - -endif diff --git a/build/import/libqt/configure b/build/import/libqt/configure deleted file mode 100755 index 904d126..0000000 --- a/build/import/libqt/configure +++ /dev/null @@ -1,97 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/libqt/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 'Qt libraries' for '$project_name'." -$echo - -$echo -$echo "Which version of Qt would you like to use?" -$echo -$echo "(1) Qt5" -$echo "(2) Qt4" -$echo -version=`read_option "5 4" "5"` - -$echo -$echo "Would you like to configure dependency on the installed version" -$echo "of 'Qt libraries' as opposed to the development build?" -$echo - -installed=`read_y_n y` - -if [ "$installed" = "n" ]; then - - $echo - $echo "Please enter the 'Qt' 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 - core_libs= - if [ "$version" = "5" ]; then - - if pkg-config --exists Qt5Core; then - core_cppflags=`pkg-config --cflags Qt5Core` - core_libs=`pkg-config --libs Qt5Core` - fi - - else - - if pkg-config --exists QtCore; then - core_cppflags=`pkg-config --cflags QtCore` - core_libs=`pkg-config --libs QtCore` - fi - - fi - - if [ "$core_libs" = "" ]; then - - $echo - $echo "Unable to discover installed 'Qt libraries' using pkg-config." - $echo "Assuming the C++ compiler will find them automatically." - $echo - - core_cppflags= - - if [ "$version" = "5" ]; then - core_libs=-lQt5Core - else - core_libs=-lQtCore - fi - fi -fi - - -echo libqt_version := $version >$1 -echo libqt_installed := $installed >>$1 - -if [ "$installed" = "n" ]; then - echo libqt_root := $root >>$1 - echo libqt_type := $type >>$1 -else - echo libqt_core_cppflags := $core_cppflags >>$1 - echo libqt_core_libs := $core_libs >>$1 -fi diff --git a/build/import/libqt/core/rules.make b/build/import/libqt/core/rules.make deleted file mode 100644 index 1fd6f10..0000000 --- a/build/import/libqt/core/rules.make +++ /dev/null @@ -1,26 +0,0 @@ -# file : build/import/libqt/core/rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/libqt/%: root := $(libqt_root) -$(dcf_root)/import/libqt/core/core.l: | $(dcf_root)/import/libqt/core/. - -ifeq ($(libqt_type),archive) -$(dcf_root)/import/libqt/core/core.l: $(libqt_root)/lib/libQtCore.a - @echo $^ >$@ -else -$(dcf_root)/import/libqt/core/core.l: $(libqt_root)/lib/libQtCore.so - @echo $^ >$@ - @echo rpath:$(root)/lib >>$@ -endif - -$(dcf_root)/import/libqt/core/core.l.cpp-options: | $(dcf_root)/import/libqt/core/. - @echo include: -I$(root)/include -I$(root)/include/QtCore >$@ - -ifndef %foreign% - -disfigure:: - $(call message,rm $(dcf_root)/import/libqt/core/core.l,\ -rm -f $(dcf_root)/import/libqt/core/core.l) - $(call message,,rm -f $(dcf_root)/import/libqt/core/core.l.cpp-options) - -endif diff --git a/build/import/libqt/core/stub.make b/build/import/libqt/core/stub.make deleted file mode 100644 index 1a13bde..0000000 --- a/build/import/libqt/core/stub.make +++ /dev/null @@ -1,35 +0,0 @@ -# file : build/import/libqt/core/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/libqt/configuration-rules.make,$(dcf_root)) - -libqt_version := -libqt_installed := - -$(call -include,$(dcf_root)/import/libqt/configuration-dynamic.make) - -ifdef libqt_installed - -ifeq ($(libqt_installed),y) - -$(call export,\ - l: $(libqt_core_libs),\ - cpp-options: ,\ - cpp-options-inline: $(libqt_core_cppflags)) - -else - -$(call include-once,$(scf_root)/import/libqt/core/rules.make,$(dcf_root)) - -$(call export,\ - l: $(dcf_root)/import/libqt/core/core.l,\ - cpp-options: $(dcf_root)/import/libqt/core/core.l.cpp-options,\ - cpp-options-inline: ) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/import/libqt/version b/build/import/libqt/version deleted file mode 100644 index 6e8bf73..0000000 --- a/build/import/libqt/version +++ /dev/null @@ -1 +0,0 @@ -0.1.0 diff --git a/build/import/odb/configuration-rules.make b/build/import/odb/configuration-rules.make deleted file mode 100644 index eef9b0e..0000000 --- a/build/import/odb/configuration-rules.make +++ /dev/null @@ -1,13 +0,0 @@ -# file : build/import/odb/configuration-rules.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(dcf_root)/import/odb/configuration-dynamic.make: | $(dcf_root)/import/odb/. - $(call message,,$(scf_root)/import/odb/configure $@) - -ifndef %foreign% - -$(dcf_root)/.disfigure:: - $(call message,rm $(dcf_root)/import/odb/configuration-dynamic.make,\ -rm -f $(dcf_root)/import/odb/configuration-dynamic.make) - -endif diff --git a/build/import/odb/configure b/build/import/odb/configure deleted file mode 100755 index ee0cdfa..0000000 --- a/build/import/odb/configure +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/import/odb/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 'odb' for '$project_name'." -$echo - -$echo -$echo "Would you like to configure dependency on the installed " -$echo "version of 'odb' 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 'odb'." -$echo - -src_root=`read_path --directory --exist` - -$echo -$echo "Please enter the out_root for 'odb'." -$eche - -out_root=`read_path --directory $src_root` - -fi - -echo odb_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/odb/hxx-cxx.make b/build/import/odb/hxx-cxx.make deleted file mode 100644 index 987acc0..0000000 --- a/build/import/odb/hxx-cxx.make +++ /dev/null @@ -1,127 +0,0 @@ -# file : build/import/odb/hxx-cxx.make -# license : GNU GPL v3; see accompanying LICENSE file - -# Here we are operating in the importing project's space, not in odb's. -# - -# Get the C++ configuration (file extensions, and extra CPP options). -# -$(call include,$(bld_root)/cxx/configuration.make) - -odb_databases := mysql sqlite pgsql oracle mssql - -odb_pattern := \ -$(out_base)/%-odb.$(cxx_s_suffix) \ -$(out_base)/%-odb.$(cxx_h_suffix) \ -$(out_base)/%-odb.$(cxx_i_suffix) \ -$(out_base)/%.sql - -odb_patterns := $(odb_pattern) - -define odb-db-pattern -odb_$1_pattern := \ -$$(out_base)/%-odb-$1.$$(cxx_s_suffix) \ -$$(out_base)/%-odb-$1.$$(cxx_h_suffix) \ -$$(out_base)/%-odb-$1.$$(cxx_i_suffix) \ -$$(out_base)/%-$1.sql - -odb_patterns += $$(odb_$1_pattern) - -endef # Trailing newline is important. - -$(foreach d,$(odb_databases),$(eval $(call odb-db-pattern,$d))) - -$(odb_patterns): odb_options := \ ---hxx-suffix .$(cxx_h_suffix) \ ---ixx-suffix .$(cxx_i_suffix) \ ---cxx-suffix .$(cxx_s_suffix) - -$(odb_patterns): odb-expand-cpp-options-impl = \ -$(if $1,$(shell sed -e 's%include: \(.*\)%\1%' -e t -e d $1)) - -$(odb_patterns): odb-expand-cpp-options = \ -$(call odb-expand-cpp-options-impl,$(filter %.cpp-options,$1)) - -# We only check for the long option name to avoid false positives. -# -$(odb_pattern): odb-default-database = \ -$(if $(filter --multi-database ,$(odb_options)),--database common ) - -$(odb_pattern): odb-default-database-message = \ -$(if $(filter --multi-database ,$(odb_options)),[common] ) - -.PRECIOUS: $(odb_patterns) - -ifeq ($(out_base),$(src_base)) - -$(odb_pattern): $(src_base)/%.$(cxx_h_suffix) - $(call message,odb $(call odb-default-database-message)$<,$(odb) \ -$(cpp_options) $(call odb-expand-cpp-options,$^) $(cxx_pp_extra_options) \ -$(odb_options) $(call odb-default-database)--output-dir $(dir $@) $<) - -define odb-db-rule -$$(odb_$1_pattern): $$(src_base)/%.$$(cxx_h_suffix) - $$(call message,odb [$1] $$<,$$(odb) $$(cpp_options) \ -$$(call odb-expand-cpp-options,$$^) $$(cxx_pp_extra_options) $$(odb_options) \ ---database $1 --output-dir $$(dir $$@) $$<) - -endef # Trailing newline is important. - -else - -$(odb_pattern): $(src_base)/%.$(cxx_h_suffix) | $$(dir $$@). - $(call message,odb $(call odb-default-database-message)$<,$(odb) \ -$(cpp_options) $(call odb-expand-cpp-options,$^) $(cxx_pp_extra_options) \ -$(odb_options) $(call odb-default-database)--output-dir $(dir $@) $<) - -$(odb_pattern): $(out_base)/%.$(cxx_h_suffix) | $$(dir $$@). - $(call message,odb $(call odb-default-database-message)$<,$(odb) \ -$(cpp_options) $(call odb-expand-cpp-options,$^) $(cxx_pp_extra_options) \ -$(odb_options) $(call odb-default-database) --output-dir $(dir $@) $<) - -define odb-db-rule -$$(odb_$1_pattern): $$(src_base)/%.$$(cxx_h_suffix) | $$$$(dir $$$$@). - $$(call message,odb [$1] $$<,$$(odb) $$(cpp_options) \ -$$(call odb-expand-cpp-options,$$^) $$(cxx_pp_extra_options) $$(odb_options) \ ---database $1 --output-dir $$(dir $$@) $$<) - -$$(odb_$1_pattern): $$(out_base)/%.$$(cxx_h_suffix) | $$$$(dir $$$$@). - $$(call message,odb [$1] $$<,$$(odb) $$(cpp_options) \ -$$(call odb-expand-cpp-options,$$^) $$(cxx_pp_extra_options) $$(odb_options) \ ---database $1 --output-dir $$(dir $$@) $$<) - -endef # Trailing newline is important. -endif - -$(foreach d,$(odb_databases),$(eval $(call odb-db-rule,$d))) - -# Clean. -# -.PHONY: $(out_base)/%-odb.cxx.hxx.clean - -$(out_base)/%-odb.cxx.hxx.clean: cxx_s_suffix := $(cxx_s_suffix) -$(out_base)/%-odb.cxx.hxx.clean: cxx_h_suffix := $(cxx_h_suffix) -$(out_base)/%-odb.cxx.hxx.clean: cxx_i_suffix := $(cxx_i_suffix) - -$(out_base)/%-odb.cxx.hxx.clean: - $(call message,rm $$1,rm -f $$1,$(@:.cxx.hxx.clean=.$(cxx_s_suffix))) - $(call message,rm $$1,rm -f $$1,$(@:.cxx.hxx.clean=.$(cxx_h_suffix))) - $(call message,rm $$1,rm -f $$1,$(@:.cxx.hxx.clean=.$(cxx_i_suffix))) - $(call message,rm $$1,rm -f $$1,$(@:-odb.cxx.hxx.clean=.sql)) - -define odb-db-clean-rule -.PHONY: $$(out_base)/%-odb-$1.cxx.hxx.clean - -$$(out_base)/%-odb-$1.cxx.hxx.clean: cxx_s_suffix := $$(cxx_s_suffix) -$$(out_base)/%-odb-$1.cxx.hxx.clean: cxx_h_suffix := $$(cxx_h_suffix) -$$(out_base)/%-odb-$1.cxx.hxx.clean: cxx_i_suffix := $$(cxx_i_suffix) - -$$(out_base)/%-odb-$1.cxx.hxx.clean: - $$(call message,rm $$$$1,rm -f $$$$1,$$(@:.cxx.hxx.clean=.$$(cxx_s_suffix))) - $$(call message,rm $$$$1,rm -f $$$$1,$$(@:.cxx.hxx.clean=.$$(cxx_h_suffix))) - $$(call message,rm $$$$1,rm -f $$$$1,$$(@:.cxx.hxx.clean=.$$(cxx_i_suffix))) - $$(call message,rm $$$$1,rm -f $$$$1,$$(@:-odb-$1.cxx.hxx.clean=-$1.sql)) - -endef # Trailing newline is important. - -$(foreach d,$(odb_databases),$(eval $(call odb-db-clean-rule,$d))) diff --git a/build/import/odb/stub.make b/build/import/odb/stub.make deleted file mode 100644 index 21ff9f2..0000000 --- a/build/import/odb/stub.make +++ /dev/null @@ -1,28 +0,0 @@ -# file : build/import/odb/stub.make -# license : GNU GPL v2; see accompanying LICENSE file - -$(call include-once,$(scf_root)/import/odb/configuration-rules.make,$(dcf_root)) - -odb_installed := - -$(call -include,$(dcf_root)/import/odb/configuration-dynamic.make) - -ifdef odb_installed - -ifeq ($(odb_installed),y) - -$(call export,odb: odb,odb-rules: $(scf_root)/import/odb/hxx-cxx.make) - -else - -# Include export stub. -# -$(call include,$(scf_root)/export/odb/stub.make) - -endif - -else - -.NOTPARALLEL: - -endif diff --git a/build/mssql/configure b/build/mssql/configure deleted file mode 100755 index 52cf34b..0000000 --- a/build/mssql/configure +++ /dev/null @@ -1,52 +0,0 @@ -#! /usr/bin/env bash - -# file : build/mssql/configure -# license : GNU GPL v2; see accompanying LICENSE file - -# -# dcf_root - dynamic configuration root -# - -$echo -$echo "Please enter the SQL Server client program path." -$echo - -driver=`read_path --command sqlcmd` - -$echo -$echo "Please enter the SQL Server database user." -$echo - -user=`read_value "odb_test"` - -$echo -$echo "Please enter the SQL Server database password." -$echo - -passwd=`read_value "odb_test"` - -$echo -$echo "Please enter the SQL Server database name. Note that it WILL BE" -$echo "MODIFIED by the tests." -$echo - -db=`read_value "odb_test"` - -$echo -$echo "Please enter the SQL Server instance address." -$echo - -server=`read_value ""` - -opt=$dcf_root/mssql.options -drv=$dcf_root/mssql-driver - -echo "--user '$user'" >$opt -echo "--password '$passwd'" >>$opt -echo "--database '$db'" >>$opt -echo "--server '$server'" >>$opt - -echo "#!/bin/sh" >$drv -echo "opt=\`cat $opt\`" >>$drv -echo "eval $scf_root/mssql/mssql --driver $driver \$opt \$*" >>$drv -chmod 755 $drv diff --git a/build/mssql/mssql b/build/mssql/mssql deleted file mode 100755 index 37792f6..0000000 --- a/build/mssql/mssql +++ /dev/null @@ -1,51 +0,0 @@ -#! /usr/bin/env bash - -# file : build/mssql/mssql -# license : GNU GPL v2; see accompanying LICENSE file - -# -# SQL Server driver wrapper. -# - -opt= -driver= - -while [ $# -gt 0 ]; do - case $1 in - --driver) - driver=$2 - shift 2 - ;; - --user) - opt="$opt -U $2" - shift 2 - ;; - --password) - opt="$opt -P $2" - shift 2 - ;; - --database) - opt="$opt -d $2" - shift 2 - ;; - --server) - opt="$opt -S $2" - shift 2 - ;; - *) - break - ;; - esac -done - -if [ -z "$driver" ]; then - driver=sqlcmd -fi - -opt="-x -r -b $opt" - -if [ -n "$1" ]; then - exec $driver $opt -i $1 -else - exec $driver $opt -fi diff --git a/build/mysql/configure b/build/mysql/configure deleted file mode 100755 index 0ea5120..0000000 --- a/build/mysql/configure +++ /dev/null @@ -1,75 +0,0 @@ -#! /usr/bin/env bash - -# file : build/mysql/configure -# license : GNU GPL v2; see accompanying LICENSE file - -# -# dcf_root - dynamic configuration root -# - -$echo -$echo "Please enter the MySQL client program path." -$echo - -driver=`read_path --command mysql` - -$echo -$echo "Please enter the MySQL database user." -$echo - -user=`read_value "odb_test"` - -$echo -$echo "Please enter the MySQL database password. Enter NULL for" -$echo "unspecified password as opposed to the empty password." -$echo - -passwd=`read_value "NULL"` - -$echo -$echo "Please enter the MySQL database name. Note that it WILL BE" -$echo "MODIFIED by the tests." -$echo - -db=`read_value "odb_test"` - -$echo -$echo "Please enter the MySQL database host." -$echo - -host=`read_value ""` - -$echo -$echo "Please enter the MySQL database port." -$echo - -port=`read_value "0"` - -$echo -$echo "Please enter the MySQL database socket name. Enter NULL for" -$echo "unspecified name as opposed to the empty name." -$echo - -socket=`read_value "NULL"` - -opt=$dcf_root/mysql.options -drv=$dcf_root/mysql-driver - -echo "--user '$user'" >$opt - -if [ "$passwd" != "NULL" ]; then -echo "--password '$passwd'" >>$opt -fi - -echo "--database '$db'" >>$opt -echo "--host '$host'" >>$opt -echo "--port $port" >>$opt - -if [ "$socket" != "NULL" ]; then -echo "--socket '$socket'" >>$opt -fi - -echo "#!/bin/sh" >$drv -echo "opt=\`cat $opt\`" >>$drv -echo "eval $scf_root/mysql/mysql --driver $driver \$opt \$*" >>$drv -chmod 755 $drv diff --git a/build/mysql/mysql b/build/mysql/mysql deleted file mode 100755 index 7d224c8..0000000 --- a/build/mysql/mysql +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env bash - -# file : build/mysql/mysql -# license : GNU GPL v2; see accompanying LICENSE file - -# -# MySQL driver wrapper. -# - -opt= -driver= - -while [ $# -gt 0 ]; do - case $1 in - --driver) - driver=$2 - shift 2 - ;; - --user) - opt="$opt --user=$2" - shift 2 - ;; - --password) - opt="$opt --password=$2" - shift 2 - ;; - --database) - opt="$opt --database=$2" - shift 2 - ;; - --host) - opt="$opt --host=$2" - shift 2 - ;; - --port) - opt="$opt --port=$2" - shift 2 - ;; - --socket) - opt="$opt --socket=$2" - shift 2 - ;; - *) - break - ;; - esac -done - -if [ -z "$driver" ]; then - driver=mysql -fi - -if [ -n "$1" ]; then - exec $driver $opt <$1 -else - exec $driver $opt -fi diff --git a/build/oracle/configure b/build/oracle/configure deleted file mode 100755 index 4a87e51..0000000 --- a/build/oracle/configure +++ /dev/null @@ -1,97 +0,0 @@ -#! /usr/bin/env bash - -# file : build/oracle/configure -# license : GNU GPL v2; see accompanying LICENSE file - -# -# dcf_root - dynamic configuration root -# - -$echo -$echo "Please enter the Oracle client program path." -$echo - -driver=`read_path --command sqlplus` - -$echo -$echo "Please enter the Oracle database user." -$echo - -user=`read_value "odb_test"` - -$echo -$echo "Please enter the Oracle database password." -$echo - -# If the user is odb_test then default to odb_test as a password since -# it is unlikely there is the odb_test user with external authentication. -# -if [ "$user" = "odb_test" ]; then - def_passwd=odb_test -else - def_passwd= -fi - -passwd=`read_value "$def_passwd"` - -$echo -$echo "Please enter the Oracle listener host (localhost if left empty)." -$echo - -host=`read_value ""` - -$echo -$echo "Please enter the Oracle listener port (default port if left empty)." -$echo - -port=`read_value ""` - -$echo -$echo "Please enter the Oracle service to use (default service if left" -$echo "empty). Note that the database associated with user $user on this" -$echo "service WILL BE MODIFIED." -$echo - -service=`read_value ""` - -opt=$dcf_root/oracle.options -drv=$dcf_root/oracle-driver - -if [ -n "$user" ]; then -echo "--user '$user'" >$opt -fi - -if [ -n "$passwd" ]; then -echo "--password '$passwd'" >>$opt -fi - -if [ -n "$service" ]; then -echo "--service '$service'" >>$opt -fi - -if [ -n "$host" ]; then -echo "--host '$host'" >>$opt -fi - -if [ -n "$port" ]; then -echo "--port '$port'" >>$opt -fi - -echo "#!/bin/sh" >$drv - -dir=`dirname $driver` -if [ "$dir" != "." ]; then - echo >>$drv - echo 'LD_LIBRARY_PATH="'$dir':$LD_LIBRARY_PATH"' >>$drv - echo "export LD_LIBRARY_PATH" >>$drv - echo >>$drv - echo 'if [ -z "$SQLPATH" ]; then' >>$drv - echo ' SQLPATH="'$dir'"' >>$drv - echo " export SQLPATH" >>$drv - echo "fi" >>$drv - echo >>$drv -fi - -echo "opt=\`cat $opt\`" >>$drv -echo "eval $scf_root/oracle/oracle --driver $driver \$opt \$*" >>$drv -chmod 755 $drv diff --git a/build/oracle/oracle b/build/oracle/oracle deleted file mode 100755 index 58e94f2..0000000 --- a/build/oracle/oracle +++ /dev/null @@ -1,80 +0,0 @@ -#! /usr/bin/env bash - -# file : build/oracle/oracle -# license : GNU GPL v2; see accompanying LICENSE file - -# -# Oracle driver wrapper. -# - -driver= -user= -passwd= -service= -host= -port= - -while [ $# -gt 0 ]; do - case $1 in - --driver) - driver=$2 - shift 2 - ;; - --user) - user="$2" - shift 2 - ;; - --password) - passwd="$2" - shift 2 - ;; - --service) - service="$2" - shift 2 - ;; - --host) - host="$2" - shift 2 - ;; - --port) - port="$2" - shift 2 - ;; - *) - break - ;; - esac -done - -if [ -z "$driver" ]; then - driver=sqlplus -fi - -conn=$user - -if [ -n "$passwd" ]; then - conn="$conn/$passwd" -fi - -if [ -n "$host" ]; then - conn="$conn@//$host" - - if [ -n "$port" ]; then - conn="$conn:$port" - fi - - if [ -n "$service" ]; then - conn="$conn/$service" - fi -elif [ -n "$service" ]; then - conn="$conn@$service" -fi - -opt="-L" - -if [ -n "$1" ]; then - opt="-S $opt" - exec $driver $opt $conn @$1 -else - exec $driver $opt $conn -fi diff --git a/build/pgsql/configure b/build/pgsql/configure deleted file mode 100755 index 9673c15..0000000 --- a/build/pgsql/configure +++ /dev/null @@ -1,63 +0,0 @@ -#! /usr/bin/env bash - -# file : build/pgsql/configure -# license : GNU GPL v2; see accompanying LICENSE file - -# -# dcf_root - dynamic configuration root -# - -$echo -$echo "Please enter the PostgreSQL client program path." -$echo - -driver=`read_path --command psql` - -$echo -$echo "Please enter the PostgreSQL database user. Note that the named" -$echo "user must be allowed to connect to the database server without" -$echo "specifying credentials." -$echo - -user=`read_value "odb_test"` - -$echo -$echo "Please enter the PostgreSQL database name. Note that it WILL BE" -$echo "MODIFIED by the tests." -$echo - -db=`read_value "odb_test"` - -$echo -$echo "Please enter the PostgreSQL database host. Leaving this field" -$echo "blank results in using Unix-domain sockets. Machines without" -$echo "Unix-domain sockets will connect to localhost." -$echo - -host=`read_value ""` - -$echo -$echo "Please enter the PostgreSQL database port or the socket file name" -$echo "extension for Unix-domain connections." -$echo - -port=`read_value ""` - -opt=$dcf_root/pgsql.options -drv=$dcf_root/pgsql-driver - -echo "--user '$user'" >$opt -echo "--database '$db'" >>$opt - -if [ -n "$host" ]; then -echo "--host '$host'" >>$opt -fi - -if [ -n "$port" ]; then -echo "--port '$port'" >>$opt -fi - -echo "#!/bin/sh" >$drv -echo "opt=\`cat $opt\`" >>$drv -echo "eval $scf_root/pgsql/pgsql --driver $driver \$opt \$*" >>$drv -chmod 755 $drv diff --git a/build/pgsql/pgsql b/build/pgsql/pgsql deleted file mode 100755 index d30a102..0000000 --- a/build/pgsql/pgsql +++ /dev/null @@ -1,53 +0,0 @@ -#! /usr/bin/env bash - -# file : build/pgsql/pgsql -# license : GNU GPL v2; see accompanying LICENSE file - -# -# PostgreSQL driver wrapper. -# - -driver= -opt= - -while [ $# -gt 0 ]; do - case $1 in - --driver) - driver=$2 - shift 2 - ;; - --user) - opt="$opt --user=$2" - shift 2 - ;; - --database) - opt="$opt --dbname=$2" - shift 2 - ;; - --host) - opt="$opt --host=$2" - shift 2 - ;; - --port) - opt="$opt --port=$2" - shift 2 - ;; - *) - break - ;; - esac -done - -if [ -z "$driver" ]; then - driver=psql -fi - -opt="--quiet $opt" - -export PGOPTIONS=--client-min-messages=warning - -if [ -n "$1" ]; then - exec $driver $opt --set ON_ERROR_STOP=1 -f $1 -else - exec $driver $opt -fi diff --git a/build/sqlite/configure b/build/sqlite/configure deleted file mode 100755 index 24cc288..0000000 --- a/build/sqlite/configure +++ /dev/null @@ -1,20 +0,0 @@ -#! /usr/bin/env bash - -# file : build/sqlite/configure -# license : GNU GPL v2; see accompanying LICENSE file - -# -# dcf_root - dynamic configuration root -# - -$echo -$echo "Please enter the SQLite database file name. Note that it WILL" -$echo "BE MODIFIED by the tests. You can also specify ':memory:' as a" -$echo "file name to use a temporary in-memory database." -$echo - -db=`read_value "/tmp/odb-test.db"` - -opt=$dcf_root/sqlite.options - -echo "--database '$db'" >$opt diff --git a/c++11/README b/c++11/README deleted file mode 100644 index fa8780b..0000000 --- a/c++11/README +++ /dev/null @@ -1,78 +0,0 @@ -This example shows how to use ODB with C++11. In particular, this example -examines ODB support for the new std::unique_ptr and std::shared_ptr smart -pointers and their lazy variants as well as the unordered containers. It -also shows how to use new C++11 features such as the range-based for-loop -when working with persistent objects and handling query results. - -The example consists of the following files: - -employee.hxx - Header file defining the 'employee', 'employer', and 'pension_fund' - persistent classes. We use the standard std::shared_ptr/weak_ptr smart - pointers as well as their lazy versions provided by ODB to establish a - bidirectional employee-employer relationship. We also enable session - support for these two classes using the 'db session' pragma. Because - we don't share the 'pension_fund' objects, we use std::unique_ptr - as an object pointer for this persistent class. We also use the - std::unordered_set container to keep track of the employee's email - addresses. - -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx -employee.sql - The first three files contain the database support code and the last file - contains the database schema for the employee.hxx header. - - These files are generated by the ODB compiler from employee.hxx using the - following command line: - - odb -d --std c++11 --generate-schema --generate-query employee.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The --std c++11 option is used to instruct the ODB compiler to compile in - the C++11 mode. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. Unlike - other examples, here we use std::unique_ptr instead of std::auto_ptr to - return the created database. - -driver.cxx - Driver for the example. It includes the employee.hxx and employee-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then creates a number of 'employee', 'employer', and - 'pension_fund' objects and persists them in the database. Then the driver - loads and prints some information about various objects and their - relationships. Finally, the driver performs a database query and iterates - over the result printing basic information about the returned objects. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++ -std=c++11' -with your C++ compiler in C++11 mode): - -c++ -std=c++11 -c employee-odb.cxx -c++ -std=c++11 -DDATABASE_MYSQL -c driver.cxx -c++ -std=c++11 -o driver driver.o employee-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < employee.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/c++11/database.hxx b/c++11/database.hxx deleted file mode 100644 index f97448f..0000000 --- a/c++11/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : c++11/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::unique_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::unique_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - unique_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - unique_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - unique_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - unique_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - unique_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/c++11/driver.cxx b/c++11/driver.cxx deleted file mode 100644 index 68793b1..0000000 --- a/c++11/driver.cxx +++ /dev/null @@ -1,207 +0,0 @@ -// file : c++11/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::unique_ptr -#include - -#include -#include -#include - -#include "database.hxx" // create_database - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - unique_ptr db (create_database (argc, argv)); - - // Create a few persistent objects. - // - { - pension_fund bf ("Bright Future"); - - // Simple Tech Ltd. - // - { - shared_ptr er (new employer ("Simple Tech Ltd")); - - shared_ptr john (new employee ("John", "Doe", er)); - shared_ptr jane (new employee ("Jane", "Doe", er)); - - john->emails ().insert ("john_d@example.com"); - john->emails ().insert ("john.doe@example.com"); - - jane->emails ().insert ("jane_d@example.com"); - jane->emails ().insert ("jane.doe@example.com"); - - // Set the inverse side of the employee-employer relationship. - // - er->employees ().push_back (john); - er->employees ().push_back (jane); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (john); - db->persist (jane); - - t.commit (); - - bf.members ().push_back (lazy_shared_ptr (*db, john)); - } - - // Complex Systems Inc. - // - { - shared_ptr er (new employer ("Complex Systems Inc")); - - shared_ptr john (new employee ("John", "Smith", er)); - shared_ptr jane (new employee ("Jane", "Smith", er)); - - john->emails ().insert ("john_s@example.com"); - john->emails ().insert ("john.smith@example.com"); - - jane->emails ().insert ("jane_s@example.com"); - jane->emails ().insert ("jane.smith@example.com"); - - // Set the inverse side of the employee-employer relationship. - // - er->employees ().push_back (john); - er->employees ().push_back (jane); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (john); - db->persist (jane); - - t.commit (); - - bf.members ().push_back (lazy_shared_ptr (*db, jane)); - } - - transaction t (db->begin ()); - db->persist (bf); - t.commit (); - } - - // Load the Bright Future pension fund and print its members. - // - { - session s; - transaction t (db->begin ()); - - unique_ptr bf (db->load ("Bright Future")); - - for (auto i (bf->members ().begin ()); i != bf->members ().end (); ++i) - { - lazy_shared_ptr& p (*i); - p.load (); - - cout << p->first () << ' ' << p->last () << ", " << - p->employer ()->name () << endl; - } - - // Alternative implementation using range-based for-loop. - // - /* - for (lazy_shared_ptr& p: bf->members ()) - { - p.load (); - cout << p->first () << ' ' << p->last () << ", " << - p->employer ()->name () << endl; - } - */ - - cout << endl; - } - - // Load Simple Tech Ltd and print its employees. - // - { - session s; - transaction t (db->begin ()); - - shared_ptr st (db->load ("Simple Tech Ltd")); - - for (auto i (st->employees ().begin ()); - i != st->employees ().end (); - ++i) - { - lazy_weak_ptr& lwp (*i); - shared_ptr p (lwp.load ()); // Load and lock. - - cout << p->first () << ' ' << p->last () << endl - << " employer: " << p->employer ()->name () << endl; - - for (auto j (p->emails ().begin ()); j != p->emails ().end (); ++j) - { - cout << " email: " << *j << endl; - } - - cout << endl; - } - - // Alternative implementation using range-based for-loop. - // - /* - for (lazy_weak_ptr& lwp: st->employees ()) - { - shared_ptr p (lwp.load ()); // Load and lock. - - cout << p->first () << ' ' << p->last () << endl - << " employer: " << p->employer ()->name () << endl; - - for (const string& e: p->emails ()) - cout << " email: " << e << endl; - - cout << endl; - } - */ - - t.commit (); - } - - - // Search for Complex Systems Inc employees with the John first name. - // - { - typedef odb::query query; - typedef odb::result result; - - session s; - transaction t (db->begin ()); - - result r (db->query ( - query::employer->name == "Complex Systems Inc" && - query::first == "John")); - - for (auto i (r.begin ()); i != r.end (); ++i) - cout << i->first () << ' ' << i->last () << endl; - - // Alternative implementation using range-based for-loop. - // - /* - for (const employee& e: r) - cout << e.first () << ' ' << e.last () << endl; - */ - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/c++11/employee.hxx b/c++11/employee.hxx deleted file mode 100644 index 0c2abc7..0000000 --- a/c++11/employee.hxx +++ /dev/null @@ -1,182 +0,0 @@ -// file : boost/employee.hxx -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include -#include // std::unique_ptr, std::shared_ptr -#include -#include - -#include -#include // odb::lazy_shared_ptr, odb::lazy_weak_ptr - -// Forward declarations. -// -class employer; -class employee; - -#pragma db object pointer(std::shared_ptr) session -class employer -{ -public: - employer (const std::string& name) - : name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - - // Employees of this employer. - // - typedef std::vector> employees_type; - - const employees_type& - employees () const - { - return employees_; - } - - employees_type& - employees () - { - return employees_; - } - -private: - friend class odb::access; - - employer () {} - - #pragma db id - std::string name_; - - #pragma db value_not_null inverse(employer_) - employees_type employees_; -}; - -#pragma db object pointer(std::shared_ptr) session -class employee -{ -public: - typedef ::employer employer_type; - - employee (const std::string& first, - const std::string& last, - std::shared_ptr employer) - : first_ (first), last_ (last), employer_ (employer) - { - } - - // Name. - // - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - // Emails. - // - typedef std::unordered_set emails_type; - - const emails_type& - emails () const - { - return emails_; - } - - emails_type& - emails () - { - return emails_; - } - - // Employer. - // - std::shared_ptr - employer () const - { - return employer_; - } - - void - employer (std::shared_ptr employer) - { - employer_ = employer; - } - -private: - friend class odb::access; - - employee () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - emails_type emails_; - - #pragma db not_null - std::shared_ptr employer_; -}; - -// std::unique_ptr is a good choice for an object pointer if we are -// not planning to do any sharing. -// -#pragma db object pointer(std::unique_ptr) -class pension_fund -{ -public: - pension_fund (const std::string& name) - : name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - - // Members of this fund. - // - typedef std::vector> members_type; - - const members_type& - members () const - { - return members_; - } - - members_type& - members () - { - return members_; - } - -private: - friend class odb::access; - - pension_fund () {} - - #pragma db id - std::string name_; - - #pragma db value_not_null - members_type members_; -}; - -#endif // EMPLOYEE_HXX diff --git a/c++11/makefile b/c++11/makefile deleted file mode 100644 index baee22b..0000000 --- a/c++11/makefile +++ /dev/null @@ -1,139 +0,0 @@ -# file : c++11/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := employee.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libodb-boost/stub.make,\ - l: odb_boost.l,cpp-options: odb_boost.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libboost/header-only/stub.make,\ - cpp-options: boost.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libboost/date-time/stub.make,\ - l: boost_date_time.l) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb_boost.l) $(odb.l) $(boost_date_time.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_boost.l.cpp-options) \ -$(odb_db.l.cpp-options) $(boost.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-query --generate-schema \ ---table-prefix boost_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) $(odb_boost.l.cpp-options) $(boost.l.cpp-options) - -# Don't generate dependencies unless we are in the C++11 mode. -# -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard - -ifeq ($(cxx_standard),c++11) -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) -endif - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc10projs,$(name)) \ -$(call vc11projs,$(name)) $(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/composite/README b/composite/README deleted file mode 100644 index bcb72e3..0000000 --- a/composite/README +++ /dev/null @@ -1,69 +0,0 @@ -This example shows how to use composite value types as data members in objects -(including as object id members) and other value types, as element types in -containers, and as base types for other composite value types. It also shows -how to use composite value type data members in queries. - -The example consists of the following files: - -person.hxx - Header file defining the 'basic_name', 'name_extras', 'name', and - 'email_address' composite value types. It also defines the 'phone_numbers' - composite value type as an instantiation of the 'std::pair' class template - Finally it defines the 'person' persistent class which uses 'email_address' - as its object id as well as 'name' and 'phone_numbers' in its other data - members. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-schema --generate-query person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then persists a 'person' object, loads it and updates its - nickname and aliases which reside in a composite value type, then re-loads - the object and prints its name to verify that the changes have been made - persistent. Finally, the driver performs a database query which uses a - data member from the composite value type in its criterion. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/composite/database.hxx b/composite/database.hxx deleted file mode 100644 index ae7caf4..0000000 --- a/composite/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : composite/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/composite/driver.cxx b/composite/driver.cxx deleted file mode 100644 index fc228bf..0000000 --- a/composite/driver.cxx +++ /dev/null @@ -1,108 +0,0 @@ -// file : composite/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - // Create a person object. - // - email_address id; - { - person p ("joe@example.com", - "Joe", - "Dirt", - "Mr", - phone_numbers ("555 5555", "666 6666")); - - transaction t (db->begin ()); - id = db->persist (p); - t.commit (); - } - - // Update the extra name information. - // - { - transaction t (db->begin ()); - - auto_ptr joe (db->load (id)); - name_extras& ne (joe->name ().extras ()); - ne.nickname ("Squeaky"); - ne.aliases ().push_back (basic_name ("Anthony", "Clean")); - - db->update (*joe); - - t.commit (); - } - - // Print the name and phone numbers. - // - { - transaction t (db->begin ()); - auto_ptr joe (db->load (id)); - t.commit (); - - name& n (joe->name ()); - - cout << n.title () << " " << n.first () << " " << n.last () << " " - << '<' << joe->email ().address () << '>' << endl; - - name_extras& ne (n.extras ()); - - if (!ne.nickname ().empty ()) - cout << " nickname: " << ne.nickname () << endl; - - for (basic_names::iterator i (ne.aliases ().begin ()); - i != ne.aliases ().end (); - ++i) - { - cout << " alias: " << i->first () << " " << i->last () << endl; - } - - cout << " phone 1: " << joe->phone ().first << endl; - cout << " phone 2: " << joe->phone ().second << endl; - } - - // Query the database for a person object. - // - { - typedef odb::query query; - - transaction t (db->begin ()); - - auto_ptr p ( - db->query_one ( - query::name.extras.nickname == "Squeaky")); - - if (p.get () != 0) - { - name& n (p->name ()); - cout << n.title () << " " << n.first () << " " << n.last () << endl; - } - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/composite/makefile b/composite/makefile deleted file mode 100644 index a619b1b..0000000 --- a/composite/makefile +++ /dev/null @@ -1,125 +0,0 @@ -# file : composite/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --generate-query \ ---table-prefix c_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/composite/person.hxx b/composite/person.hxx deleted file mode 100644 index f0626e5..0000000 --- a/composite/person.hxx +++ /dev/null @@ -1,228 +0,0 @@ -// file : composite/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include -#include - -#include - -#pragma db value -class basic_name -{ -public: - basic_name (const std::string& first, const std::string& last) - : first_ (first), last_ (last) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - -private: - friend class odb::access; - - basic_name () {} // Needed for storing basic_name in containers. - - std::string first_; - std::string last_; -}; - -typedef std::vector basic_names; - - -#pragma db value -class name_extras -{ -public: - // Nickname. - // - const std::string& - nickname () const - { - return nickname_; - } - - void - nickname (const std::string& nickname) - { - nickname_ = nickname; - } - - // Aliases. - // - const basic_names& - aliases () const - { - return aliases_; - } - - basic_names& - aliases () - { - return aliases_; - } - -private: - friend class odb::access; - - std::string nickname_; - basic_names aliases_; -}; - - -#pragma db value -class name: public basic_name -{ -public: - name (const std::string& first, - const std::string& last, - const std::string& title) - : basic_name (first, last), title_ (title) - { - } - - // Title. - // - const std::string& - title () const - { - return title_; - } - - // Extras. - // - const name_extras& - extras () const - { - return extras_; - } - - name_extras& - extras () - { - return extras_; - } - -private: - friend class odb::access; - - std::string title_; - name_extras extras_; -}; - -// We can also define a composite value type as a class template -// instantiation. Here we use std::pair to store person's phone -// numbers, in the order of preference. -// -typedef std::pair phone_numbers; -#pragma db value(phone_numbers) - -// We can also use a composite value type as an object id. -// -#pragma db value -class email_address -{ -public: - email_address () {} - email_address (const std::string& address) - { - std::string::size_type p (address.find ('@')); - recipient_.assign (address, 0, p); - domain_.assign (address, p + 1, std::string::npos); - } - - const std::string& - recipient () const - { - return recipient_; - } - - const std::string& - domain () const - { - return domain_; - } - - std::string - address () const - { - return recipient_ + '@' + domain_; - } - -private: - friend class odb::access; - - std::string recipient_; - std::string domain_; -}; - -#pragma db object -class person -{ -public: - person (const std::string& email, - const std::string& first, - const std::string& last, - const std::string& title, - const phone_numbers& phone) - : email_ (email), name_ (first, last, title), phone_ (phone) - { - } - - // Email address. - // - const email_address& - email () const - { - return email_; - } - - // Name. - // - typedef ::name name_type; - - const name_type& - name () const - { - return name_; - } - - name_type& - name () - { - return name_; - } - - // Phone. - // - const phone_numbers& - phone () const - { - return phone_; - } - -private: - friend class odb::access; - - person (): name_ ("", "", "") {} - - #pragma db id - email_address email_; - - name_type name_; - phone_numbers phone_; -}; - -#endif // PERSON_HXX diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 9895953..0000000 --- a/configure.ac +++ /dev/null @@ -1,106 +0,0 @@ -# file : configure.ac -# license : GNU GPL v2; see accompanying LICENSE file - -AC_PREREQ(2.60) -AC_INIT([odb-examples], [__value__(version)], [odb-users@codesynthesis.com]) -AC_CONFIG_AUX_DIR([config]) -AC_CONFIG_MACRO_DIR([m4]) -AC_CONFIG_SRCDIR([hello/driver.cxx]) - -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 - -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 - -AM_CONDITIONAL([ODB_EXAMPLES_THREADS], [test x$threads != xnone]) - -# Check for C++11. -# -CXX11([HAVE_CXX11], [Compiling in the C++11 mode.]) - -# Check for the ODB compiler. -# -ODB_COMPILER([], [AC_MSG_ERROR([odb compiler is not found; consider setting ODB variable or using --with-odb=DIR])]) - -# Check for the ODB libs. -# -LIBODB([], [AC_MSG_ERROR([libodb is not found; consider using --with-libodb=DIR])]) - -# Check for TR1 availability (has to be after libodb). -# -TR1_MEMORY - -# Check for boost. -# -odb_examples_boost=yes -LIBBOOST([], [odb_examples_boost=no]) -LIBBOOST_SYSTEM -LIBBOOST_SMART_PTR([], [odb_examples_boost=no]) -LIBBOOST_UNORDERED([], [odb_examples_boost=no]) -LIBBOOST_DATE_TIME([], [odb_examples_boost=no]) - -# Check for libodb-boost. -# -LIBODB_BOOST([], [odb_examples_boost=no]) - -AM_CONDITIONAL([ODB_EXAMPLES_BOOST], [test x$odb_examples_boost != xno]) - -# Check for Qt. -# -odb_examples_qt=yes -LIBQTCORE([], [odb_examples_qt=no]) - -# Check for libodb-qt. -# -LIBODB_QT([], [odb_examples_qt=no]) - -AM_CONDITIONAL([ODB_EXAMPLES_QT], [test x$odb_examples_qt != xno]) - -# Check which database we are using. -# -DATABASE - -case $database in - mysql) - LIBODB_MYSQL([], [AC_MSG_ERROR([libodb-mysql is not found; consider using --with-libodb-mysql=DIR])]) - MYSQL - ;; - sqlite) - LIBODB_SQLITE([], [AC_MSG_ERROR([libodb-sqlite is not found; consider using --with-libodb-sqlite=DIR])]) - SQLITE - ;; - pgsql) - LIBODB_PGSQL([], [AC_MSG_ERROR([libodb-pgsql is not found; consider using --with-libodb-pgsql=DIR])]) - PGSQL - ;; - oracle) - LIBODB_ORACLE([], [AC_MSG_ERROR([libodb-oracle is not found; consider using --with-libodb-oracle=DIR])]) - ORACLE - ;; - mssql) - LIBODB_MSSQL([], [AC_MSG_ERROR([libodb-mssql is not found; consider using --with-libodb-mssql=DIR])]) - MSSQL - ;; -esac - -# Output. -# -AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_FILES([__path__(config_files)]) -AC_CONFIG_COMMANDS([tester-mode], [chmod +x tester]) -AC_OUTPUT diff --git a/container/README b/container/README deleted file mode 100644 index 058b001..0000000 --- a/container/README +++ /dev/null @@ -1,62 +0,0 @@ -This example shows how to use containers as data members in persistent objects. - -The example consists of the following files: - -person.hxx - Header file defining the 'person' persistent class. It contains a number of - data members of various container types. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-schema person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then persists a 'person' object, loads it back, and prints the - contents of its members. Finally, the driver modifies the object by adding, - removing, and updating elements in its container members, stores the changes - in the database, then re-loads and prints the object to verify that the - changes have been made persistent. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/container/database.hxx b/container/database.hxx deleted file mode 100644 index 5756f97..0000000 --- a/container/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : container/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/container/driver.cxx b/container/driver.cxx deleted file mode 100644 index 566f89e..0000000 --- a/container/driver.cxx +++ /dev/null @@ -1,119 +0,0 @@ -// file : container/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -void -print (const person& p) -{ - cout << p.first () << " " << p.last () << endl; - - // Print nicknames. - // - for (names::const_iterator i (p.nicknames ().begin ()); - i != p.nicknames ().end (); ++i) - { - cout << " nickname: " << *i << endl; - } - - // Print emails. - // - for (emails::const_iterator i (p.emails ().begin ()); - i != p.emails ().end (); ++i) - { - cout << " email: " << *i << endl; - } - - // Print weights. - // - for (age_weight_map::const_iterator i (p.age_weight ().begin ()); - i != p.age_weight ().end (); ++i) - { - cout << " weight at " << i->first << ": " << i->second << endl; - } -} - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - unsigned long id; - - // Create a persistent person object. - // - { - person joe ("Joe", "Dirt"); - - joe.nicknames ().push_back ("JD"); - joe.nicknames ().push_back ("Squeaky"); - - joe.emails ().insert ("joe@example.com"); - joe.emails ().insert ("joe.dirt@example.com"); - - joe.age_weight ()[5] = 15.6F; - joe.age_weight ()[10] = 23.3F; - joe.age_weight ()[15] = 29.8F; - - transaction t (db->begin ()); - id = db->persist (joe); - t.commit (); - } - - // Load the object and print what we've got. Then change some - // information and update it in the database. - // - { - transaction t1 (db->begin ()); - auto_ptr j (db->load (id)); - t1.commit (); - - print (*j); - - // Ann another nickname. - // - j->nicknames ().push_back ("Cleaner"); - - // The joe@example.com email is no longer working. - // - j->emails ().erase ("joe@example.com"); - - // Update a weight sample. - // - j->age_weight ()[15] = 28.8F; - - transaction t2 (db->begin ()); - db->update (*j); - t2.commit (); - } - - // Load and print the updated object. - // - { - transaction t (db->begin ()); - auto_ptr j (db->load (id)); - t.commit (); - - print (*j); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/container/makefile b/container/makefile deleted file mode 100644 index 65aa4fb..0000000 --- a/container/makefile +++ /dev/null @@ -1,125 +0,0 @@ -# file : container/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema \ ---table-prefix container_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/container/person.hxx b/container/person.hxx deleted file mode 100644 index 31b90a5..0000000 --- a/container/person.hxx +++ /dev/null @@ -1,99 +0,0 @@ -// file : container/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include -#include -#include -#include - -#include - -typedef std::vector names; -typedef std::set emails; -typedef std::map age_weight_map; - -#pragma db object -class person -{ -public: - person (const std::string& first, const std::string& last) - : first_ (first), last_ (last) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - // Nicknames. - // - const names& - nicknames () const - { - return nicknames_; - } - - names& - nicknames () - { - return nicknames_; - } - - // Emails. - // - typedef ::emails emails_type; - - const emails_type& - emails () const - { - return emails_; - } - - emails_type& - emails () - { - return emails_; - } - - // Age-to-weight map. - // - const age_weight_map& - age_weight () const - { - return age_weight_; - } - - age_weight_map& - age_weight () - { - return age_weight_; - } - -private: - friend class odb::access; - - person () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - - names nicknames_; - emails_type emails_; - age_weight_map age_weight_; -}; - -#endif // PERSON_HXX diff --git a/hello/README b/hello/README deleted file mode 100644 index a068898..0000000 --- a/hello/README +++ /dev/null @@ -1,63 +0,0 @@ -This is a "Hello World" example that shows how to use ODB to perform basic -database operations, such as making objects persistent, loading, updating -and deleting persistent objects, as well as querying the database for -objects matching a certain criteria. It also includes an example of a -simple view. - -The example consists of the following files: - -person.hxx - Header file defining the 'person' persistent class as well as the - 'person_stat' view. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-query --generate-schema person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. Then it executes a number of database transactions on persistent - objects. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/hello/database.hxx b/hello/database.hxx deleted file mode 100644 index 283f5cb..0000000 --- a/hello/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : hello/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/hello/driver.cxx b/hello/driver.cxx deleted file mode 100644 index 3a4de8c..0000000 --- a/hello/driver.cxx +++ /dev/null @@ -1,130 +0,0 @@ -// file : hello/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - unsigned long john_id, joe_id; - - // Create a few persistent person objects. - // - { - person john ("John", "Doe", 33); - person jane ("Jane", "Doe", 32); - person joe ("Joe", "Dirt", 30); - - transaction t (db->begin ()); - - // Make objects persistent and save their ids for later use. - // - john_id = db->persist (john); - db->persist (jane); - joe_id = db->persist (joe); - - t.commit (); - } - - typedef odb::query query; - typedef odb::result result; - - // Say hello to those over 30. - // - { - transaction t (db->begin ()); - - result r (db->query (query::age > 30)); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - cout << "Hello, " << i->first () << " " << i->last () << "!" << endl; - } - - t.commit (); - } - - // Joe Dirt just had a birthday, so update his age. - // - { - transaction t (db->begin ()); - - auto_ptr joe (db->load (joe_id)); - joe->age (joe->age () + 1); - db->update (*joe); - - t.commit (); - } - - // Alternative implementation without using the id. - // - /* - { - transaction t (db->begin ()); - - // Here we know that there can be only one Joe Dirt in our - // database so we use the query_one() shortcut instead of - // manually iterating over the result returned by query(). - // - auto_ptr joe ( - db->query_one (query::first == "Joe" && - query::last == "Dirt")); - - if (joe.get () != 0) - { - joe->age (joe->age () + 1); - db->update (*joe); - } - - t.commit (); - } - */ - - // Print some statistics about all the people in our database. - // - { - transaction t (db->begin ()); - - // The result of this (aggregate) query always has exactly one element - // so use the query_value() shortcut. - // - person_stat ps (db->query_value ()); - - cout << endl - << "count : " << ps.count << endl - << "min age: " << ps.min_age << endl - << "max age: " << ps.max_age << endl; - - t.commit (); - } - - // John Doe is no longer in our database. - // - { - transaction t (db->begin ()); - db->erase (john_id); - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/hello/makefile b/hello/makefile deleted file mode 100644 index 3f540a1..0000000 --- a/hello/makefile +++ /dev/null @@ -1,124 +0,0 @@ -# file : hello/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-query --generate-schema -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/hello/person.hxx b/hello/person.hxx deleted file mode 100644 index 81a9321..0000000 --- a/hello/person.hxx +++ /dev/null @@ -1,73 +0,0 @@ -// file : hello/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include -#include // std::size_t - -#include - -#pragma db object -class person -{ -public: - person (const std::string& first, - const std::string& last, - unsigned short age) - : first_ (first), last_ (last), age_ (age) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - unsigned short - age () const - { - return age_; - } - - void - age (unsigned short age) - { - age_ = age; - } - -private: - friend class odb::access; - - person () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - unsigned short age_; -}; - -#pragma db view object(person) -struct person_stat -{ - #pragma db column("count(" + person::id_ + ")") - std::size_t count; - - #pragma db column("min(" + person::age_ + ")") - unsigned short min_age; - - #pragma db column("max(" + person::age_ + ")") - unsigned short max_age; -}; - -#endif // PERSON_HXX diff --git a/inheritance/polymorphism/README b/inheritance/polymorphism/README deleted file mode 100644 index 8a013b3..0000000 --- a/inheritance/polymorphism/README +++ /dev/null @@ -1,78 +0,0 @@ -This example shows how to use polymorphism inheritance with ODB. This -inheritance style is normally used to provide polymorphic behavior through -a common interface. The base class defines a number of virtual functions and, -normally, a virtual destructor while the derived classes provide specific -implementations of these virtual functions. - -The other commonly used inheritance style is reuse inheritance. Refer to the -inheritance/reuse example for more information on this style. - -The example consists of the following files: - -employee.hxx -employee.cxx - Header and source files defining the 'person' abstract polymorphic - persistent class as well as the 'employee' and 'contractor' concrete - persistent classes. - -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx -employee.sql - The first three files contain the database support code and the last file - contains the database schema for the employee.hxx header. - - These files are generated by the ODB compiler from employee.hxx using the - following command line: - - odb -d --generate-schema --generate-query employee.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the employee.hxx and employee-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then persists a number of employee and contractor objects - via their common base (person). The next transaction loads these objects, - also via their common base. Once loaded, the driver calls the print() - virtual function on each of them. Next, the driver changes an employee - from temporary to permanent and updates its state in the database, again - using the base class interface. The driver then queries the database for - all the person objects that have Doe as the last name. The result set of - this query contains a mix of employee and contractor objects. The driver - iterates over this result set and calls the print() virtual function for - each object. Finally, the driver erases the state of the persistent - objects from the database, again using the base class interface. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c employee.cxx -c++ -c employee-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o employee.o employee-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < employee.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/inheritance/polymorphism/database.hxx b/inheritance/polymorphism/database.hxx deleted file mode 100644 index 4c65d2d..0000000 --- a/inheritance/polymorphism/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : inheritance/polymorphism/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/inheritance/polymorphism/driver.cxx b/inheritance/polymorphism/driver.cxx deleted file mode 100644 index e0c9952..0000000 --- a/inheritance/polymorphism/driver.cxx +++ /dev/null @@ -1,102 +0,0 @@ -// file : inheritance/polymorphism/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - unsigned long id1, id2; - - // Add a few employee and contractor objects to the database. - // - { - auto_ptr p1 (new employee ("John", "Doe", true)); - auto_ptr p2 (new contractor ("Jane", "Doe", "jane@doe.com")); - - transaction t (db->begin ()); - id1 = db->persist (*p1); // Stores employee. - id2 = db->persist (*p2); // Stores contractor. - t.commit (); - } - - // Load polymorphic objects given their object ids. - // - { - transaction t (db->begin ()); - auto_ptr p1 (db->load (id1)); // Loads employee. - auto_ptr p2 (db->load (id2)); // Loads contractor. - t.commit (); - - p1->print (); - p2->print (); - } - - // Make John Doe a permanent employee. - // - { - transaction t (db->begin ()); - - auto_ptr e (db->load (id1)); - e->temporary (false); - person& p (*e); - db->update (p); // Updates employee. - - t.commit (); - } - - // Query all the person objects that have Doe as the last name. - // - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - result r (db->query (query::last == "Doe")); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - // We can check the discriminator before loading the object. - // - string d (i.discriminator ()); - cout << "discriminator: " << d << endl; - - i->print (); // Can be employee or contractor. - } - - t.commit (); - } - - // Erase the objects from the database. - // - { - transaction t (db->begin ()); - auto_ptr p (db->load (id1)); // Loads employee. - db->erase (*p); // Erases employee. - db->erase (id2); // Erases contractor. - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/inheritance/polymorphism/employee.cxx b/inheritance/polymorphism/employee.cxx deleted file mode 100644 index 83a51e6..0000000 --- a/inheritance/polymorphism/employee.cxx +++ /dev/null @@ -1,27 +0,0 @@ -// file : inheritance/polymorphism/employee.cxx -// copyright : not copyrighted - public domain - -#include - -#include "employee.hxx" - -using namespace std; - -person:: -~person () -{ -} - -void employee:: -print () -{ - cout << first_ << ' ' << last_ - << (temporary_ ? " temporary " : " permanent ") - << "employee" << endl; -} - -void contractor:: -print () -{ - cout << first_ << ' ' << last_ << ' ' << email_ << " contractor" << endl; -} diff --git a/inheritance/polymorphism/employee.hxx b/inheritance/polymorphism/employee.hxx deleted file mode 100644 index efb2c1c..0000000 --- a/inheritance/polymorphism/employee.hxx +++ /dev/null @@ -1,109 +0,0 @@ -// file : inheritance/polymorphism/employee.hxx -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include - -#include - -#pragma db object polymorphic -class person -{ -public: - person (const std::string& first, const std::string& last) - : first_ (first), last_ (last) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - virtual - ~person () = 0; - - virtual void - print () = 0; - -protected: - friend class odb::access; - person () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; -}; - -#pragma db object -class employee: public person -{ -public: - employee (const std::string& first, - const std::string& last, - bool temporary) - : person (first, last), temporary_ (temporary) - { - } - - bool - temporary () const - { - return temporary_; - } - - void - temporary (bool t) - { - temporary_ = t; - } - - virtual void - print (); - -private: - friend class odb::access; - employee () {} - - bool temporary_; -}; - -#pragma db object -class contractor: public person -{ -public: - contractor (const std::string& first, - const std::string& last, - const std::string& email) - : person (first, last), email_ (email) - { - } - - const std::string& - email () const - { - return email_; - } - - virtual void - print (); - -private: - friend class odb::access; - contractor () {} - - std::string email_; -}; - -#endif // EMPLOYEE_HXX diff --git a/inheritance/polymorphism/makefile b/inheritance/polymorphism/makefile deleted file mode 100644 index 38ef06a..0000000 --- a/inheritance/polymorphism/makefile +++ /dev/null @@ -1,126 +0,0 @@ -# file : inheritance/polymorphism/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make - -cxx_tun := driver.cxx employee.cxx -odb_hdr := employee.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --generate-query \ ---table-prefix inh_poly_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export extra_sources := $(filter-out driver.cxx,$(cxx_tun)) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../../template/Makefile.am) - $(call meta-vc8projs,../../template/template,$(name)) - $(call meta-vc9projs,../../template/template,$(name)) - $(call meta-vc10projs,../../template/template,$(name)) - $(call meta-vc11projs,../../template/template,$(name)) - $(call meta-vc12projs,../../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/inheritance/reuse/README b/inheritance/reuse/README deleted file mode 100644 index 53e0d90..0000000 --- a/inheritance/reuse/README +++ /dev/null @@ -1,69 +0,0 @@ -This example shows how to use reuse inheritance with ODB. This inheritance -style normally lacks virtual functions and a virtual destructor in the base -class. The application code is normally written in terms of the derived -classes instead of the base. - -The other commonly used inheritance style is polymorphism inheritance. Refer -to the inheritance/polymorphism example for more information on this style. - -The example consists of the following files: - -employee.hxx - Header file defining the 'person' and 'employee' abstract persistent - classes as well as the 'permanent_employee', 'temporary_employee', and - 'contractor' concrete persistent classes. - -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx -employee.sql - The first three files contain the database support code and the last file - contains the database schema for the employee.hxx header. - - These files are generated by the ODB compiler from employee.hxx using the - following command line: - - odb -d --generate-schema --generate-query employee.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the employee.hxx and employee-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then persists a number of permanent and temporary employee - objects as well as a number of contractor objects. The next transaction - looks up a contractor based on the email address. Finally, the driver - performs a database query which uses a data member from the base class - in its criterion. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c employee-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < employee.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/inheritance/reuse/database.hxx b/inheritance/reuse/database.hxx deleted file mode 100644 index 6fd1bda..0000000 --- a/inheritance/reuse/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : inheritance/reuse/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/inheritance/reuse/driver.cxx b/inheritance/reuse/driver.cxx deleted file mode 100644 index b9a22da..0000000 --- a/inheritance/reuse/driver.cxx +++ /dev/null @@ -1,81 +0,0 @@ -// file : inheritance/reuse/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - // Add a few employees and contractors to the database. - // - { - permanent_employee p1 ("John", "Doe"); - permanent_employee p2 ("Jane", "Doe"); - - temporary_employee t1 ("John", "Smith", 6); - temporary_employee t2 ("Jane", "Smith", 12); - - contractor c1 ("Joe", "Doe", "j.doe@example.com"); - contractor c2 ("Joe", "Smith", "j.smith@example.com"); - - transaction t (db->begin ()); - db->persist (p1); - db->persist (p2); - db->persist (t1); - db->persist (t2); - db->persist (c1); - db->persist (c2); - t.commit (); - } - - // Lookup a contractor based on the email address. - // - { - transaction t (db->begin ()); - auto_ptr c (db->load ("j.smith@example.com")); - t.commit (); - - cout << c->first () << " " << c->last () << " " << c->email () << endl; - } - - // Query for temporary employees that have John as the first name. - // - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - result r (db->query (query::first == "John")); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - cout << i->first () << " " << i->last () << " " - << i->duration () << " months" << endl; - } - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/inheritance/reuse/employee.hxx b/inheritance/reuse/employee.hxx deleted file mode 100644 index 7de3989..0000000 --- a/inheritance/reuse/employee.hxx +++ /dev/null @@ -1,143 +0,0 @@ -// file : inheritance/reuse/employee.hxx -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include - -#include - -// Abstract person class. Note that it does not declare the object id. -// -#pragma db object abstract -class person -{ -public: - person (const std::string& first, const std::string& last) - : first_ (first), last_ (last) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - -protected: - friend class odb::access; - person () {} - -private: - std::string first_; - std::string last_; -}; - -// Abstract employee class. It derives from the person class and declares -// the object id for all the concrete employee types. -// -#pragma db object abstract -class employee: public person -{ -public: - employee (const std::string& first, const std::string& last) - : person (first, last) - { - } - - unsigned long - number () const - { - return id_; - } - -protected: - friend class odb::access; - employee () {} - -private: - #pragma db id auto - unsigned long id_; -}; - -// Concrete permanent_employee class. Note that it doesn't define any -// data members of its own. -// -#pragma db object -class permanent_employee: public employee -{ -public: - permanent_employee (const std::string& first, const std::string& last) - : employee (first, last) - { - } - -private: - friend class odb::access; - permanent_employee () {} -}; - -// Concrete temporary_employee class. It adds the employment duration in -// months. -// -#pragma db object -class temporary_employee: public employee -{ -public: - temporary_employee (const std::string& first, - const std::string& last, - unsigned long duration) - : employee (first, last), duration_ (duration) - { - } - - unsigned long - duration () const - { - return duration_; - } - -private: - friend class odb::access; - temporary_employee () {} - - unsigned long duration_; -}; - -// Concrete contractor class. It derives from the person class (and not -// employee; an independent contractor is not considered an employee). -// We use the contractor's external email address as the object id. -// -#pragma db object -class contractor: public person -{ -public: - contractor (const std::string& first, - const std::string& last, - const std::string& email) - : person (first, last), email_ (email) - { - } - - const std::string& - email () const - { - return email_; - } - -private: - friend class odb::access; - contractor () {} - - #pragma db id - std::string email_; -}; - -#endif // EMPLOYEE_HXX diff --git a/inheritance/reuse/makefile b/inheritance/reuse/makefile deleted file mode 100644 index 9477844..0000000 --- a/inheritance/reuse/makefile +++ /dev/null @@ -1,125 +0,0 @@ -# file : inheritance/reuse/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := employee.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --generate-query \ ---table-prefix inh_reuse_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../../template/Makefile.am) - $(call meta-vc8projs,../../template/template,$(name)) - $(call meta-vc9projs,../../template/template,$(name)) - $(call meta-vc10projs,../../template/template,$(name)) - $(call meta-vc11projs,../../template/template,$(name)) - $(call meta-vc12projs,../../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/inverse/README b/inverse/README deleted file mode 100644 index e75d9dc..0000000 --- a/inverse/README +++ /dev/null @@ -1,78 +0,0 @@ -This example shows how to declare and use bidirectional one-to-one, one-to- -many, and many-to-many relationships between persistent objects. It also -shows how to work with lazy pointers. All the relationships presented in -this example declare one side as inverse in order to produce canonical -database schema. - -The example uses the shared_ptr and weak_ptr smart pointers from TR1 and -requires a C++ compiler with TR1 support or an external TR1 implementation, -such as the one provided by Boost. - -The example consists of the following files: - -employee.hxx - Header file defining the 'employee', 'employer', 'position', and 'project' - persistent classes as well as the employer-employee (one-to-many), - employee-position (one-to-one), and employee-project (many-to-many) - bidirectional relationships between them. - -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx -employee.sql - The first three files contain the database support code and the last file - contains the database schema for the employee.hxx header. - - These files are generated by the ODB compiler from employee.hxx using the - following command line: - - odb -d --generate-schema --generate-query --generate-session \ - --default-pointer std::tr1::shared_ptr employee.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The --generate-session option is used to enable session support for all - the persistent classes in employee.hxx. The --default-pointer option is - used to make TR1 shared_ptr the default object pointer. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the employee.hxx and employee-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then creates a number of 'employee', 'employer', 'position', - and 'project' objects, sets the relationships between them, and persists - them in the database. In the next few transactions the driver loads various - objects, then accesses and modifies the relationships between them. Finally, - the driver performs a database query which uses a data member from a related - object in its criterion. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c employee-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < employee.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/inverse/database.hxx b/inverse/database.hxx deleted file mode 100644 index f4e8599..0000000 --- a/inverse/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : inverse/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/inverse/driver.cxx b/inverse/driver.cxx deleted file mode 100644 index 5a613e1..0000000 --- a/inverse/driver.cxx +++ /dev/null @@ -1,258 +0,0 @@ -// file : inverse/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include -#include - -#include "database.hxx" // create_database - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace odb::core; - -void -print (const employee& e) -{ - cout << e.first () << " " << e.last () << endl - << " employer: " << e.employer ().load ()->name () << endl - << " position: " << e.position ().load ()->title () << endl; - - const projects& ps (e.projects ()); - - for (projects::const_iterator i (ps.begin ()); i != ps.end (); ++i) - { - const lazy_shared_ptr& p (*i); - p.load (); - - cout << " project: " << p->name () << endl; - } - - cout << endl; -} - -int -main (int argc, char* argv[]) -{ - using tr1::shared_ptr; - - try - { - auto_ptr db (create_database (argc, argv)); - - // Create a few persistent objects. - // - { - // Simple Tech Ltd. - // - { - shared_ptr er (new employer ("Simple Tech Ltd")); - - shared_ptr he (new position ("Hardware Engineer")); - shared_ptr se (new position ("Software Engineer")); - - shared_ptr sh (new project ("Simple Hardware")); - shared_ptr ss (new project ("Simple Software")); - - shared_ptr john (new employee ("John", "Doe", er, he)); - shared_ptr jane (new employee ("Jane", "Doe", er, se)); - - // Set the inverse side of the employee-employer relationship. - // - er->employees ().push_back (john); - er->employees ().push_back (jane); - - // Set the inverse side of the employee-position relationship. - // - he->employee (john); - se->employee (jane); - - // Set the employee-project relationship (both directions). - // - john->projects ().push_back (sh); - john->projects ().push_back (ss); - jane->projects ().push_back (ss); - - sh->employees ().push_back (john); - ss->employees ().push_back (john); - ss->employees ().push_back (jane); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (he); - db->persist (se); - - db->persist (sh); - db->persist (ss); - - db->persist (john); - db->persist (jane); - - t.commit (); - } - - // Complex Systems Inc. - // - { - shared_ptr er (new employer ("Complex Systems Inc")); - - shared_ptr he (new position ("Hardware Engineer")); - shared_ptr se (new position ("Software Engineer")); - - shared_ptr ch (new project ("Complex Hardware")); - shared_ptr cs (new project ("Complex Software")); - - shared_ptr john (new employee ("John", "Smith", er, se)); - shared_ptr jane (new employee ("Jane", "Smith", er, he)); - - // Set the inverse side of the employee-employer relationship. - // - er->employees ().push_back (john); - er->employees ().push_back (jane); - - // Set the inverse side of the employee-position relationship. - // - he->employee (john); - se->employee (jane); - - // Set the employee-project relationship (both directions). - // - john->projects ().push_back (cs); - jane->projects ().push_back (ch); - jane->projects ().push_back (cs); - - ch->employees ().push_back (jane); - cs->employees ().push_back (john); - cs->employees ().push_back (jane); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (he); - db->persist (se); - - db->persist (ch); - db->persist (cs); - - db->persist (john); - db->persist (jane); - - t.commit (); - } - } - - // Load Simple Tech Ltd and print its employees. We use a session in this - // and subsequent transactions to make sure that a single instance of any - // particular object (e.g., employer) is shared among all objects (e.g., - // employee) that relate to it. - // - { - session s; - transaction t (db->begin ()); - - shared_ptr stl (db->load ("Simple Tech Ltd")); - - employees& es (stl->employees ()); - - for (employees::iterator i (es.begin ()); i != es.end (); ++i) - { - lazy_weak_ptr& lwp (*i); - shared_ptr p (lwp.load ()); // Load and lock. - print (*p); - } - - t.commit (); - } - - // Find all Software Engineers. - // - { - typedef odb::query query; - typedef odb::result result; - - session s; - transaction t (db->begin ()); - - result r (db->query (query::title == "Software Engineer")); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - const lazy_weak_ptr& lwp (i->employee ()); - shared_ptr p (lwp.load ()); // Load and lock. - - // Employee can be NULL if the position is vacant. - // - if (p) - print (*p); - } - - t.commit (); - } - - // John Doe has moved to Complex Systems Inc and is now working as - // a Software Engineer on Complex Software. - // - { - typedef odb::query query; - - session s; - transaction t (db->begin ()); - - // Create "unloaded" pointers to the employer and project objects. - // - lazy_shared_ptr csi (*db, std::string ("Complex Systems Inc")); - lazy_shared_ptr cs (*db, std::string ("Complex Software")); - - // Create a new Software Engineer position. - // - shared_ptr se (new position ("Software Engineer")); - - shared_ptr john ( - db->query_one (query::first == "John" && - query::last == "Doe")); - - john->employer (csi); - john->position (se); - john->projects ().clear (); - john->projects ().push_back (cs); - - db->persist (se); - db->update (john); - - t.commit (); - } - - // Print Complex Systems Inc's employees. This time, instead of loading - // the employer object, we use a query which shows how we can use members - // of the pointed-to objects in the queries. - // - { - typedef odb::query query; - typedef odb::result result; - - session s; - transaction t (db->begin ()); - - result r (db->query ( - query::employer->name == "Complex Systems Inc")); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - print (*i); - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/inverse/employee.hxx b/inverse/employee.hxx deleted file mode 100644 index 2c23789..0000000 --- a/inverse/employee.hxx +++ /dev/null @@ -1,274 +0,0 @@ -// file : inverse/employee.hxx -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include -#include - -#include - -// Include TR1 header in a compiler-specific fashion. Fall back -// on the Boost implementation if the compiler does not support TR1. -// -#include - -#include - -using std::tr1::shared_ptr; - -using odb::tr1::lazy_shared_ptr; -using odb::tr1::lazy_weak_ptr; - -// The "pointer architecture" in this object model is as follows: All -// object pointers are lazy. The employee class holds shared pointers -// to employer, position, and projects. All other objects hold weak -// pointers back to the employee object. The weak sides are also the -// ones that are made inverse. -// -// The following bidirectional relationships are used: -// -// many-to-one : employee <--> employer -// one-to-one : employee <--> position -// many-to-many : employee <--> project -// - -// Forward declarations. -// -class employer; -class position; -class project; -class employee; - -typedef std::vector > projects; -typedef std::vector > employees; - -#pragma db object -class employer -{ -public: - employer (const std::string& name) - : name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - - // Employees of this employer. - // - typedef ::employees employees_type; - - const employees_type& - employees () const - { - return employees_; - } - - employees_type& - employees () - { - return employees_; - } - -private: - friend class odb::access; - - employer () {} - - #pragma db id - std::string name_; - - #pragma db value_not_null inverse(employer_) - employees_type employees_; -}; - -#pragma db object -class position -{ -public: - position (const std::string& title) - : title_ (title) - { - } - - const std::string& - title () const - { - return title_; - } - - // Employee that fills this position. NULL if the position is vacant. - // - typedef ::employee employee_type; - - const lazy_weak_ptr& - employee () const - { - return employee_; - } - - void - employee (lazy_weak_ptr employee) - { - employee_ = employee; - } - -private: - friend class odb::access; - - position () {} - - #pragma db id auto - unsigned long id_; - - std::string title_; - - #pragma db inverse(position_) - lazy_weak_ptr employee_; -}; - -#pragma db object -class project -{ -public: - project (const std::string& name) - : name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - - // Employees working on this project. - // - typedef ::employees employees_type; - - const employees_type& - employees () const - { - return employees_; - } - - employees_type& - employees () - { - return employees_; - } - -private: - friend class odb::access; - - project () {} - - #pragma db id - std::string name_; - - #pragma db value_not_null inverse(projects_) - employees_type employees_; -}; - -#pragma db object -class employee -{ -public: - typedef ::employer employer_type; - typedef ::position position_type; - - employee (const std::string& first, - const std::string& last, - lazy_shared_ptr employer, - lazy_shared_ptr position) - : first_ (first), last_ (last), - employer_ (employer), - position_ (position) - { - } - - // Name. - // - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - // Employer. - // - const lazy_shared_ptr& - employer () const - { - return employer_; - } - - void - employer (lazy_shared_ptr employer) - { - employer_ = employer; - } - - // Position. - // - const lazy_shared_ptr& - position () const - { - return position_; - } - - void - position (lazy_shared_ptr position) - { - position_ = position; - } - - // Projects. - // - typedef ::projects projects_type; - - const projects_type& - projects () const - { - return projects_; - } - - projects_type& - projects () - { - return projects_; - } - -private: - friend class odb::access; - - employee () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - - #pragma db not_null - lazy_shared_ptr employer_; - - #pragma db not_null - lazy_shared_ptr position_; - - #pragma db value_not_null unordered - projects_type projects_; -}; - -#endif // EMPLOYEE_HXX diff --git a/inverse/makefile b/inverse/makefile deleted file mode 100644 index 385cdf1..0000000 --- a/inverse/makefile +++ /dev/null @@ -1,126 +0,0 @@ -# file : inverse/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := employee.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-query --generate-schema \ ---generate-session --default-pointer std::tr1::shared_ptr \ ---table-prefix inverse_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - 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/c++11.m4 b/m4/c++11.m4 deleted file mode 100644 index 42d38ad..0000000 --- a/m4/c++11.m4 +++ /dev/null @@ -1,37 +0,0 @@ -dnl file : m4/cxx11.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl CXX11(MACRO, DESCRIPTION) -dnl -dnl Check if we are compiling in the C++11 mode. If we are, define MACRO as -dnl both a macro and conditional as well as set the cxx11 variable to 'yes'. -dnl -AC_DEFUN([CXX11], -[ -cxx11=no - -AC_MSG_CHECKING([whether we are in C++11 mode]) - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -int -main () -{ - std::shared_ptr p (new int (10)); - *p = 11; -} -])], -[cxx11=yes]) - -if test x"$cxx11" = xyes; then - AC_MSG_RESULT([yes]) - AC_DEFINE([$1], [1], [$2]) -else - AC_MSG_RESULT([no]) -fi - -AM_CONDITIONAL([$1], [test x$cxx11 = xyes]) - -])dnl diff --git a/m4/database.m4 b/m4/database.m4 deleted file mode 100644 index baa0fb5..0000000 --- a/m4/database.m4 +++ /dev/null @@ -1,59 +0,0 @@ -dnl file : m4/database.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl DATABASE -dnl -AC_DEFUN([DATABASE], [ -database=none - -AC_MSG_CHECKING([for database to use]) - -AC_ARG_WITH( - [database], - [AC_HELP_STRING([--with-database=DB], - [database to use for tests; valid values are: 'mysql', 'sqlite', 'pgsql', 'oracle', and 'mssql'])], - [case $withval in - no | yes) - AC_MSG_RESULT([]) - AC_MSG_ERROR([no database specified in the --with-database option]) - ;; - mysql) - database=mysql - AC_DEFINE([DATABASE_MYSQL], [1], [Using MySQL.]) - ;; - sqlite) - database=sqlite - AC_DEFINE([DATABASE_SQLITE], [1], [Using SQLite.]) - ;; - pgsql) - database=pgsql - AC_DEFINE([DATABASE_PGSQL], [1], [Using PostgreSQL.]) - ;; - oracle) - database=oracle - AC_DEFINE([DATABASE_ORACLE], [1], [Using Oracle.]) - ;; - mssql) - database=mssql - AC_DEFINE([DATABASE_MSSQL], [1], [Using SQL Server.]) - ;; - *) - AC_MSG_RESULT([]) - AC_MSG_ERROR([unknown database $withval]) - ;; - esac], - [ - AC_MSG_RESULT([]) - AC_MSG_ERROR([no database specified with the --with-database option]) - ]) - -AC_MSG_RESULT([$database]) -AC_SUBST([database]) - -AM_CONDITIONAL([DATABASE_MYSQL], [test x$database = xmysql]) -AM_CONDITIONAL([DATABASE_SQLITE], [test x$database = xsqlite]) -AM_CONDITIONAL([DATABASE_PGSQL], [test x$database = xpgsql]) -AM_CONDITIONAL([DATABASE_ORACLE], [test x$database = xoracle]) -AM_CONDITIONAL([DATABASE_MSSQL], [test x$database = xmssql]) - -])dnl diff --git a/m4/libboost.m4 b/m4/libboost.m4 deleted file mode 100644 index 2223493..0000000 --- a/m4/libboost.m4 +++ /dev/null @@ -1,184 +0,0 @@ -dnl file : m4/libboost.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBBOOST([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBBOOST], [ -libboost_found=no - -AC_MSG_CHECKING([for boost base headers]) - -AC_ARG_WITH( - [boost], - [AC_HELP_STRING([--with-boost=DIR],[location of boost build directory])], - [libboost_dir=${withval}], - [libboost_dir=]) - -# If libboost_dir was given, add the necessary preprocessor and linker flags. -# -if test x"$libboost_dir" != x; then - save_CPPFLAGS="$CPPFLAGS" - save_LDFLAGS="$LDFLAGS" - - AS_SET_CATFILE([abs_libboost_dir], [$ac_pwd], [$libboost_dir]) - - CPPFLAGS="$CPPFLAGS -I$abs_libboost_dir" - LDFLAGS="$LDFLAGS -L$abs_libboost_dir/stage/lib" -fi - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -#ifndef BOOST_VERSION -# error BOOST_VERSION not defined -#endif - -int -main () -{ -} -])], -[ -libboost_found=yes -]) - -if test x"$libboost_found" = xno; then - if test x"$libboost_dir" != x; then - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - fi -fi - -if test x"$libboost_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - AC_MSG_RESULT([no]) - $2 -fi -])dnl -dnl -dnl LIBBOOST_HEADER_LIB(NAME, SOURCE, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND) -dnl -AC_DEFUN([LIBBOOST_HEADER_LIB], [ -libboost_$1_found=no - -AC_MSG_CHECKING([for boost $1 library]) -CXX_LIBTOOL_LINK_IFELSE([$2],[libboost_$1_found=yes]) - -if test x"$libboost_$1_found" = xyes; then - AC_MSG_RESULT([yes]) - [$3] -else - AC_MSG_RESULT([no]) - [$4] -fi -])dnl -dnl -dnl LIBBOOST_LIB(NAME, SOURCE, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND) -dnl -AC_DEFUN([LIBBOOST_LIB], [ -libboost_$1_found=no - -AC_MSG_CHECKING([for boost $1 library]) - -save_LIBS="$LIBS" -LIBS="-lboost_$1 $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([$2],[libboost_$1_found=yes]) - -# Try to fall back on the -mt version for backwards-compatibility. -# -if test x"$libboost_$1_found" = xno; then - LIBS="-lboost_$1-mt $save_LIBS" - CXX_LIBTOOL_LINK_IFELSE([$2],[libboost_$1_found=yes]) -fi - -if test x"$libboost_$1_found" = xno; then - LIBS="$save_LIBS" -fi - -if test x"$libboost_$1_found" = xyes; then - AC_MSG_RESULT([yes]) - [$3] -else - AC_MSG_RESULT([no]) - [$4] -fi -])dnl -dnl -dnl LIBBOOST_SMART_PTR([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -AC_DEFUN([LIBBOOST_SMART_PTR], [ -LIBBOOST_HEADER_LIB([smart_ptr],[ -AC_LANG_SOURCE([ -#include -#include - -int -main () -{ - boost::shared_ptr sp (new int (10)); - boost::weak_ptr wp (sp); -} -])], -[$1], -[$2]) -])dnl -dnl -dnl LIBBOOST_UNORDERED([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -AC_DEFUN([LIBBOOST_UNORDERED], [ -LIBBOOST_HEADER_LIB([unordered],[ -AC_LANG_SOURCE([ -#include -#include - -int -main () -{ - boost::unordered_set s; - boost::unordered_map m; - - s.insert (1); - return m.find (1) != m.end (); -} -])], -[$1], -[$2]) -])dnl -dnl -dnl LIBBOOST_SYSTEM([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -AC_DEFUN([LIBBOOST_SYSTEM], [ -LIBBOOST_LIB([system],[ -AC_LANG_SOURCE([ -int -main () -{ -} -])], -[$1], -[$2]) -])dnl -dnl -dnl LIBBOOST_DATE_TIME([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -AC_DEFUN([LIBBOOST_DATE_TIME], [ -LIBBOOST_LIB([date_time],[ -AC_LANG_SOURCE([ -#include - -int -main () -{ - boost::gregorian::greg_month m (1); - const char* s (m.as_short_string ()); - return s == 0; -} -])], -[$1], -[$2]) -])dnl diff --git a/m4/libodb-boost.m4 b/m4/libodb-boost.m4 deleted file mode 100644 index 454bd90..0000000 --- a/m4/libodb-boost.m4 +++ /dev/null @@ -1,82 +0,0 @@ -dnl file : m4/libodb-boost.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBODB_BOOST([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBODB_BOOST], [ -libodb_boost_found=no - -AC_ARG_WITH( - [libodb-boost], - [AC_HELP_STRING([--with-libodb-boost=DIR],[location of libodb-boost build directory])], - [libodb_boost_dir=${withval}], - [libodb_boost_dir=]) - -AC_MSG_CHECKING([for libodb-boost]) - -# If libodb_boost_dir was given, add the necessary preprocessor and -# linker flags. -# -if test x"$libodb_boost_dir" != x; then - save_CPPFLAGS="$CPPFLAGS" - save_LDFLAGS="$LDFLAGS" - - AS_SET_CATFILE([abs_libodb_boost_dir], [$ac_pwd], [$libodb_boost_dir]) - - CPPFLAGS="$CPPFLAGS -I$abs_libodb_boost_dir" - LDFLAGS="$LDFLAGS -L$abs_libodb_boost_dir/odb/boost" -fi - -save_LIBS="$LIBS" -LIBS="-lodb-boost $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -void -f () -{ -} - -const char* -g () -{ - try - { - f (); - } - catch (const odb::boost::exception& e) - { - return e.what (); - } - return 0; -} - -int -main () -{ - const char* m (g ()); - return m != 0; -} -])], -[libodb_boost_found=yes]) - -if test x"$libodb_boost_found" = xno; then - LIBS="$save_LIBS" - - if test x"$libodb_boost_dir" != x; then - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - fi -fi - -if test x"$libodb_boost_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - AC_MSG_RESULT([no]) - $2 -fi -])dnl diff --git a/m4/libodb-mssql.m4 b/m4/libodb-mssql.m4 deleted file mode 100644 index 7ab52d8..0000000 --- a/m4/libodb-mssql.m4 +++ /dev/null @@ -1,82 +0,0 @@ -dnl file : m4/libodb-mssql.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBODB_MSSQL([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBODB_MSSQL], [ -libodb_mssql_found=no - -AC_ARG_WITH( - [libodb-mssql], - [AC_HELP_STRING([--with-libodb-mssql=DIR],[location of libodb-mssql build directory])], - [libodb_mssql_dir=${withval}], - [libodb_mssql_dir=]) - -AC_MSG_CHECKING([for libodb-mssql]) - -# If libodb_mssql_dir was given, add the necessary preprocessor and -# linker flags. -# -if test x"$libodb_mssql_dir" != x; then - save_CPPFLAGS="$CPPFLAGS" - save_LDFLAGS="$LDFLAGS" - - AS_SET_CATFILE([abs_libodb_mssql_dir], [$ac_pwd], [$libodb_mssql_dir]) - - CPPFLAGS="$CPPFLAGS -I$abs_libodb_mssql_dir" - LDFLAGS="$LDFLAGS -L$abs_libodb_mssql_dir/odb/mssql" -fi - -save_LIBS="$LIBS" -LIBS="-lodb-mssql $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -void -f () -{ -} - -const char* -g () -{ - try - { - f (); - } - catch (const odb::mssql::database_exception& e) - { - return e.what (); - } - return 0; -} - -int -main () -{ - const char* m (g ()); - return m != 0; -} -])], -[libodb_mssql_found=yes]) - -if test x"$libodb_mssql_found" = xno; then - LIBS="$save_LIBS" - - if test x"$libodb_mssql_dir" != x; then - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - fi -fi - -if test x"$libodb_mssql_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - AC_MSG_RESULT([no]) - $2 -fi -])dnl diff --git a/m4/libodb-mysql.m4 b/m4/libodb-mysql.m4 deleted file mode 100644 index f0f6d1b..0000000 --- a/m4/libodb-mysql.m4 +++ /dev/null @@ -1,82 +0,0 @@ -dnl file : m4/libodb-mysql.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBODB_MYSQL([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBODB_MYSQL], [ -libodb_mysql_found=no - -AC_ARG_WITH( - [libodb-mysql], - [AC_HELP_STRING([--with-libodb-mysql=DIR],[location of libodb-mysql build directory])], - [libodb_mysql_dir=${withval}], - [libodb_mysql_dir=]) - -AC_MSG_CHECKING([for libodb-mysql]) - -# If libodb_mysql_dir was given, add the necessary preprocessor and -# linker flags. -# -if test x"$libodb_mysql_dir" != x; then - save_CPPFLAGS="$CPPFLAGS" - save_LDFLAGS="$LDFLAGS" - - AS_SET_CATFILE([abs_libodb_mysql_dir], [$ac_pwd], [$libodb_mysql_dir]) - - CPPFLAGS="$CPPFLAGS -I$abs_libodb_mysql_dir" - LDFLAGS="$LDFLAGS -L$abs_libodb_mysql_dir/odb/mysql" -fi - -save_LIBS="$LIBS" -LIBS="-lodb-mysql $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -void -f () -{ -} - -const char* -g () -{ - try - { - f (); - } - catch (const odb::mysql::database_exception& e) - { - return e.what (); - } - return 0; -} - -int -main () -{ - const char* m (g ()); - return m != 0; -} -])], -[libodb_mysql_found=yes]) - -if test x"$libodb_mysql_found" = xno; then - LIBS="$save_LIBS" - - if test x"$libodb_mysql_dir" != x; then - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - fi -fi - -if test x"$libodb_mysql_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - AC_MSG_RESULT([no]) - $2 -fi -])dnl diff --git a/m4/libodb-oracle.m4 b/m4/libodb-oracle.m4 deleted file mode 100644 index 10028ff..0000000 --- a/m4/libodb-oracle.m4 +++ /dev/null @@ -1,82 +0,0 @@ -dnl file : m4/libodb-oracle.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBODB_ORACLE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBODB_ORACLE], [ -libodb_oracle_found=no - -AC_ARG_WITH( - [libodb-oracle], - [AC_HELP_STRING([--with-libodb-oracle=DIR],[location of libodb-oracle build directory])], - [libodb_oracle_dir=${withval}], - [libodb_oracle_dir=]) - -AC_MSG_CHECKING([for libodb-oracle]) - -# If libodb_oracle_dir was given, add the necessary preprocessor and -# linker flags. -# -if test x"$libodb_oracle_dir" != x; then - save_CPPFLAGS="$CPPFLAGS" - save_LDFLAGS="$LDFLAGS" - - AS_SET_CATFILE([abs_libodb_oracle_dir], [$ac_pwd], [$libodb_oracle_dir]) - - CPPFLAGS="$CPPFLAGS -I$abs_libodb_oracle_dir" - LDFLAGS="$LDFLAGS -L$abs_libodb_oracle_dir/odb/oracle" -fi - -save_LIBS="$LIBS" -LIBS="-lodb-oracle $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -void -f () -{ -} - -const char* -g () -{ - try - { - f (); - } - catch (const odb::oracle::database_exception& e) - { - return e.what (); - } - return 0; -} - -int -main () -{ - const char* m (g ()); - return m != 0; -} -])], -[libodb_oracle_found=yes]) - -if test x"$libodb_oracle_found" = xno; then - LIBS="$save_LIBS" - - if test x"$libodb_oracle_dir" != x; then - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - fi -fi - -if test x"$libodb_oracle_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - AC_MSG_RESULT([no]) - $2 -fi -])dnl diff --git a/m4/libodb-pgsql.m4 b/m4/libodb-pgsql.m4 deleted file mode 100644 index cd6495d..0000000 --- a/m4/libodb-pgsql.m4 +++ /dev/null @@ -1,82 +0,0 @@ -dnl file : m4/libodb-pgsql.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBODB_PGSQL([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBODB_PGSQL], [ -libodb_pgsql_found=no - -AC_ARG_WITH( - [libodb-pgsql], - [AC_HELP_STRING([--with-libodb-pgsql=DIR],[location of libodb-pgsql build directory])], - [libodb_pgsql_dir=${withval}], - [libodb_pgsql_dir=]) - -AC_MSG_CHECKING([for libodb-pgsql]) - -# If libodb_pgsql_dir was given, add the necessary preprocessor and -# linker flags. -# -if test x"$libodb_pgsql_dir" != x; then - save_CPPFLAGS="$CPPFLAGS" - save_LDFLAGS="$LDFLAGS" - - AS_SET_CATFILE([abs_libodb_pgsql_dir], [$ac_pwd], [$libodb_pgsql_dir]) - - CPPFLAGS="$CPPFLAGS -I$abs_libodb_pgsql_dir" - LDFLAGS="$LDFLAGS -L$abs_libodb_pgsql_dir/odb/pgsql" -fi - -save_LIBS="$LIBS" -LIBS="-lodb-pgsql $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -void -f () -{ -} - -const char* -g () -{ - try - { - f (); - } - catch (const odb::pgsql::database_exception& e) - { - return e.what (); - } - return 0; -} - -int -main () -{ - const char* m (g ()); - return m != 0; -} -])], -[libodb_pgsql_found=yes]) - -if test x"$libodb_pgsql_found" = xno; then - LIBS="$save_LIBS" - - if test x"$libodb_pgsql_dir" != x; then - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - fi -fi - -if test x"$libodb_pgsql_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - AC_MSG_RESULT([no]) - $2 -fi -])dnl diff --git a/m4/libodb-qt.m4 b/m4/libodb-qt.m4 deleted file mode 100644 index 76ebfb3..0000000 --- a/m4/libodb-qt.m4 +++ /dev/null @@ -1,82 +0,0 @@ -dnl file : m4/libodb-qt.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBODB_QT([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBODB_QT], [ -libodb_qt_found=no - -AC_ARG_WITH( - [libodb-qt], - [AC_HELP_STRING([--with-libodb-qt=DIR],[location of libodb-qt build directory])], - [libodb_qt_dir=${withval}], - [libodb_qt_dir=]) - -AC_MSG_CHECKING([for libodb-qt]) - -# If libodb_qt_dir was given, add the necessary preprocessor and -# linker flags. -# -if test x"$libodb_qt_dir" != x; then - save_CPPFLAGS="$CPPFLAGS" - save_LDFLAGS="$LDFLAGS" - - AS_SET_CATFILE([abs_libodb_qt_dir], [$ac_pwd], [$libodb_qt_dir]) - - CPPFLAGS="$CPPFLAGS -I$abs_libodb_qt_dir" - LDFLAGS="$LDFLAGS -L$abs_libodb_qt_dir/odb/qt" -fi - -save_LIBS="$LIBS" -LIBS="-lodb-qt $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -void -f () -{ -} - -const char* -g () -{ - try - { - f (); - } - catch (const odb::qt::exception& e) - { - return e.what (); - } - return 0; -} - -int -main () -{ - const char* m (g ()); - return m != 0; -} -])], -[libodb_qt_found=yes]) - -if test x"$libodb_qt_found" = xno; then - LIBS="$save_LIBS" - - if test x"$libodb_qt_dir" != x; then - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - fi -fi - -if test x"$libodb_qt_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - AC_MSG_RESULT([no]) - $2 -fi -])dnl diff --git a/m4/libodb-sqlite.m4 b/m4/libodb-sqlite.m4 deleted file mode 100644 index 46ea966..0000000 --- a/m4/libodb-sqlite.m4 +++ /dev/null @@ -1,82 +0,0 @@ -dnl file : m4/libodb-sqlite.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl LIBODB_SQLITE([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBODB_SQLITE], [ -libodb_sqlite_found=no - -AC_ARG_WITH( - [libodb-sqlite], - [AC_HELP_STRING([--with-libodb-sqlite=DIR],[location of libodb-sqlite build directory])], - [libodb_sqlite_dir=${withval}], - [libodb_sqlite_dir=]) - -AC_MSG_CHECKING([for libodb-sqlite]) - -# If libodb_sqlite_dir was given, add the necessary preprocessor and -# linker flags. -# -if test x"$libodb_sqlite_dir" != x; then - save_CPPFLAGS="$CPPFLAGS" - save_LDFLAGS="$LDFLAGS" - - AS_SET_CATFILE([abs_libodb_sqlite_dir], [$ac_pwd], [$libodb_sqlite_dir]) - - CPPFLAGS="$CPPFLAGS -I$abs_libodb_sqlite_dir" - LDFLAGS="$LDFLAGS -L$abs_libodb_sqlite_dir/odb/sqlite" -fi - -save_LIBS="$LIBS" -LIBS="-lodb-sqlite $LIBS" - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -void -f () -{ -} - -const char* -g () -{ - try - { - f (); - } - catch (const odb::sqlite::database_exception& e) - { - return e.what (); - } - return 0; -} - -int -main () -{ - const char* m (g ()); - return m != 0; -} -])], -[libodb_sqlite_found=yes]) - -if test x"$libodb_sqlite_found" = xno; then - LIBS="$save_LIBS" - - if test x"$libodb_sqlite_dir" != x; then - CPPFLAGS="$save_CPPFLAGS" - LDFLAGS="$save_LDFLAGS" - fi -fi - -if test x"$libodb_sqlite_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - AC_MSG_RESULT([no]) - $2 -fi -])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/libqt.m4 b/m4/libqt.m4 deleted file mode 100644 index c2be2e7..0000000 --- a/m4/libqt.m4 +++ /dev/null @@ -1,121 +0,0 @@ -dnl file : m4/libqt.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl -dnl LIBQTCORE_COMPILE() -dnl -AC_DEFUN([LIBQTCORE_COMPILE], [ -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -// See libodb-qt/odb/qt/details/config.hxx for more information on -// what's going on here. -// -# if defined(__ELF__) && !defined(__PIC__) && !defined(__PIE__) -# include // QT_REDUCE_RELOCATIONS -# ifdef QT_REDUCE_RELOCATIONS -# define __PIE__ -# endif -# endif -#include -#include - -int -main () -{ - QString qs ("test"); - std::string ss (qs.toStdString ()); - return ss.size () != 0; -} -])], -[libqt_found=yes]) -])dnl -dnl -dnl LIBQTCORE([ACTION-IF-FOUND[,ACTION-IF-NOT-FOUND]]) -dnl -dnl -AC_DEFUN([LIBQTCORE], [ -libqt_found=no - -# QtCore libraries and pkg-config names in the order we should try -# them. -# -libqt_lib_names="Qt5Core QtCore5 QtCore Qt4Core QtCore4" -libqt_pkg_names="Qt5Core QtCore" - -AC_PATH_PROG([pkg_config],[pkg-config]) - -AC_MSG_CHECKING([for QtCore]) - -# First check for QtCore using default CPPFLAGS/LDFLAGS/LIBS. This -# test allows the user to override the QtCore library name (e.g., -# QtCored4, Qt5Core) via the LIBS variable. -# -LIBQTCORE_COMPILE - -# Then check for QtCore using default CPPFLAGS/LDFLAGS. -# -if test x"$libqt_found" = xno; then - for lib in $libqt_lib_names; do - save_LIBS="$LIBS" - LIBS="-l$lib $LIBS" - - LIBQTCORE_COMPILE - - if test x"$libqt_found" = xno; then - LIBS="$save_LIBS" - else - break - fi - done -fi - -# Try framework in case we are on Mac OS X. -# -if test x"$libqt_found" = xno; then - save_LIBS="$LIBS" - LIBS="-framework QtCore $LIBS" - - LIBQTCORE_COMPILE - - if test x"$libqt_found" = xno; then - LIBS="$save_LIBS" - fi -fi - -# If default CPPFLAGS/LDFLAGS didn't work, try to discover -# them using pkg-config. -# -if test x"$libqt_found" = xno; then - if test x"$pkg_config" != x; then - for pkg in $libqt_pkg_names; do - if $pkg_config --exists $pkg; then - save_CPPFLAGS="$CPPFLAGS" - save_LIBS="$LIBS" - - CPPFLAGS=`$pkg_config --cflags $pkg` - LIBS=`$pkg_config --libs $pkg` - - CPPFLAGS="$CPPFLAGS $save_CPPFLAGS" - LIBS="$LIBS $save_LIBS" - - LIBQTCORE_COMPILE - - if test x"$libqt_found" = xno; then - CPPFLAGS="$save_CPPFLAGS" - LIBS="$save_LIBS" - else - break - fi - fi - done - fi -fi - -if test x"$libqt_found" = xyes; then - AC_MSG_RESULT([yes]) - $1 -else - 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/mssql.m4 b/m4/mssql.m4 deleted file mode 100644 index 5debeb2..0000000 --- a/m4/mssql.m4 +++ /dev/null @@ -1,224 +0,0 @@ -dnl file : m4/mssql.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl MSSQL -dnl -AC_DEFUN([MSSQL], [ - -# Client. -# -AC_MSG_CHECKING([for mssql client program]) -AC_ARG_WITH( - [mssql-client], - [AC_HELP_STRING([--with-mssql-client=PATH], [SQL Server client program path (sqlcmd by default)])], - [case $withval in - yes) - mssql_client=sqlcmd - ;; - no) - AC_MSG_RESULT([]) - AC_MSG_ERROR([need mssql client to run the tests]) - ;; - *) - mssql_client=$withval - ;; - esac], - [mssql_client=sqlcmd]) - -$mssql_client -? 2>/dev/null 1>&2 - -if test x"$?" = x0; then - AC_MSG_RESULT([$mssql_client]) -else - AC_MSG_RESULT([no]) - AC_MSG_ERROR([mssql client is not found; consider using --with-mssql-client=PATH]) -fi - -# User. If 'no' is specified, then use Windows authentication. -# -AC_MSG_CHECKING([for mssql database user]) -AC_ARG_WITH( - [mssql-user], - [AC_HELP_STRING([--with-mssql-user=NAME], [SQL Server database user (odb_test by default)])], - [case $withval in - yes) - mssql_user=odb_test - mssql_user_set=yes - ;; - no) - mssql_user_set=no - ;; - *) - mssql_user=$withval - mssql_user_set=yes - ;; - esac], - [mssql_user=odb_test - mssql_user_set=yes]) - -if test x$mssql_user_set = xyes; then - AC_MSG_RESULT(['$mssql_user']) -else - AC_MSG_RESULT([none]) -fi - -# Password. Can be left unspecified if using Windows authentication. -# -AC_MSG_CHECKING([for mssql database password]) -AC_ARG_WITH( - [mssql-password], - [AC_HELP_STRING([--with-mssql-password=PASS], [SQL Server database password (odb_test by default)])], - [case $withval in - yes) - mssql_password=odb_test - mssql_password_set=yes - ;; - no) - mssql_password_set=no - ;; - *) - mssql_password=$withval - mssql_password_set=yes - ;; - esac], - [mssql_password_set=no]) - -if test x$mssql_password_set = xyes; then - AC_MSG_RESULT(['$mssql_password']) -elif test x$mssql_user = xodb_test; then - mssql_password=odb_test - mssql_password_set=yes - AC_MSG_RESULT(['$mssql_password']) -else - AC_MSG_RESULT([none]) - if test x$mssql_user_set = xyes; then - AC_MSG_ERROR([password not specified; SQL Server requires a password (--with-mssql-password=PASS)]) - fi -fi - -# Database. If not specified, use the user's default. -# -AC_MSG_CHECKING([for mssql database name]) -AC_ARG_WITH( - [mssql-db], - [AC_HELP_STRING([--with-mssql-db=NAME], [SQL Server database name (odb_test by default). Note that all data in this database WILL BE LOST!])], - [case $withval in - yes) - mssql_db=odb_test - mssql_db_set=yes - ;; - no) - mssql_db_set=no - ;; - *) - mssql_db=$withval - mssql_db_set=yes - ;; - esac], - [mssql_db=odb_test - mssql_db_set=yes]) - -if test x$mssql_db_set = xyes; then - AC_MSG_RESULT(['$mssql_db']) -else - AC_MSG_RESULT([default]) -fi - -# Server. -# -AC_MSG_CHECKING([for mssql instance address]) -AC_ARG_WITH( - [mssql-server], - [AC_HELP_STRING([--with-mssql-server=ADDR], [SQL Server instance address])], - [case $withval in - yes | no) - mssql_server_set=no - ;; - *) - mssql_server=$withval - mssql_server_set=yes - ;; - esac], - [mssql_server_set=no]) - -if test x$mssql_server_set = xyes; then - AC_MSG_RESULT(['$mssql_server']) -else - AC_MSG_RESULT([none]) - AC_MSG_ERROR([instance address not specified; SQL Server instance address is required (--with-mssql-server=ADDR)]) -fi - -# Driver. -# -AC_MSG_CHECKING([for mssql native client odbc driver]) -AC_ARG_WITH( - [mssql-driver], - [AC_HELP_STRING([--with-mssql-driver=NAME], [SQL Server Native Client ODBC driver (latest available by default)])], - [case $withval in - yes | no) - mssql_driver_set=no - ;; - *) - mssql_driver=$withval - mssql_driver_set=yes - ;; - esac], - [mssql_driver_set=no]) - -if test x$mssql_driver_set = xyes; then - AC_MSG_RESULT(['$mssql_driver']) -else - AC_MSG_RESULT([latest]) -fi - -# Create options file. -# -AC_CONFIG_COMMANDS([mssql.options], - [ - rm -f mssql.options - echo '#! /bin/sh' >mssql-driver - - echo 'opt=' >>mssql-driver - - if test x$mssql_user_set = xyes; then - echo "--user '$mssql_user'" >>mssql.options - echo 'opt="$opt -U '"$mssql_user"'"' >>mssql-driver - - echo "--password '$mssql_password'" >>mssql.options - echo 'opt="$opt -P '"$mssql_password"'"' >>mssql-driver - fi - - if test x$mssql_db_set = xyes; then - echo "--database '$mssql_db'" >>mssql.options - echo 'opt="$opt -d '"$mssql_db"'"' >>mssql-driver - fi - - echo "--server '$mssql_server'" >>mssql.options - echo 'opt="$opt -S '"$mssql_server"'"' >>mssql-driver - - if test x$mssql_driver_set = xyes; then - echo "--driver '$mssql_driver'" >>mssql.options - fi - - echo 'opt="$opt -x -r -b"' >>mssql-driver - echo 'if test x$[]1 != x; then' >>mssql-driver - echo " exec $mssql_client "'$opt -i $[]1' >>mssql-driver - echo "else" >>mssql-driver - echo " exec $mssql_client "'$opt' >>mssql-driver - echo "fi" >>mssql-driver - - chmod +x mssql-driver - ], - [ - mssql_client="$mssql_client" - mssql_user="$mssql_user" - mssql_user_set="$mssql_user_set" - mssql_password="$mssql_password" - mssql_db="$mssql_db" - mssql_db_set="$mssql_db_set" - mssql_server="$mssql_server" - mssql_driver="$mssql_driver" - mssql_driver_set="$mssql_driver_set" - ]) - -])dnl diff --git a/m4/mysql.m4 b/m4/mysql.m4 deleted file mode 100644 index 7564726..0000000 --- a/m4/mysql.m4 +++ /dev/null @@ -1,270 +0,0 @@ -dnl file : m4/mysql.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl MYSQL -dnl -AC_DEFUN([MYSQL], [ - -# Client. -# -AC_MSG_CHECKING([for mysql client program]) -AC_ARG_WITH( - [mysql-client], - [AC_HELP_STRING([--with-mysql-client=PATH], [MySQL client program path (mysql by default)])], - [case $withval in - yes) - mysql_client=mysql - ;; - no) - AC_MSG_RESULT([]) - AC_MSG_ERROR([need mysql client to run the tests]) - ;; - *) - mysql_client=$withval - ;; - esac], - [mysql_client=mysql]) - -$mysql_client --version 2>/dev/null 1>&2 - -if test x"$?" = x0; then - AC_MSG_RESULT([$mysql_client]) -else - AC_MSG_RESULT([no]) - AC_MSG_ERROR([mysql client is not found; consider using --with-mysql-client=PATH]) -fi - -# User. -# -AC_MSG_CHECKING([for mysql database user]) -AC_ARG_WITH( - [mysql-user], - [AC_HELP_STRING([--with-mysql-user=NAME], [MySQL database user (odb_test by default)])], - [case $withval in - yes) - mysql_user=odb_test - mysql_user_set=yes - ;; - no) - mysql_user_set=no - ;; - *) - mysql_user=$withval - mysql_user_set=yes - ;; - esac], - [mysql_user=odb_test - mysql_user_set=yes]) - -if test x$mysql_user_set = xyes; then - AC_MSG_RESULT(['$mysql_user']) -else - AC_MSG_RESULT([none]) -fi - -# Password. -# -AC_MSG_CHECKING([for mysql database password]) -AC_ARG_WITH( - [mysql-password], - [AC_HELP_STRING([--with-mysql-password=PASS], [MySQL database password (no password by default)])], - [case $withval in - yes) - mysql_password= - mysql_password_set=yes - ;; - no) - mysql_password_set=no - ;; - *) - mysql_password=$withval - mysql_password_set=yes - ;; - esac], - [mysql_password_set=no]) - -if test x$mysql_password_set = xyes; then - AC_MSG_RESULT(['$mysql_password']) -else - AC_MSG_RESULT([none]) -fi - -# Database name. -# -AC_MSG_CHECKING([for mysql database name]) -AC_ARG_WITH( - [mysql-db], - [AC_HELP_STRING([--with-mysql-db=NAME], [MySQL database name (odb_test by default). Note that all data in this database WILL BE LOST!])], - [case $withval in - yes) - mysql_db=odb_test - mysql_db_set=yes - ;; - no) - mysql_db_set=no - ;; - *) - mysql_db=$withval - mysql_db_set=yes - ;; - esac], - [mysql_db=odb_test - mysql_db_set=yes]) - -if test x$mysql_db_set = xyes; then - AC_MSG_RESULT(['$mysql_db']) -else - AC_MSG_RESULT([none]) -fi - -# Host. -# -AC_MSG_CHECKING([for mysql database host]) -AC_ARG_WITH( - [mysql-host], - [AC_HELP_STRING([--with-mysql-host=HOST], [MySQL database host (localhost by default)])], - [case $withval in - yes) - mysql_host=localhost - mysql_host_set=yes - ;; - no) - mysql_host_set=no - ;; - *) - mysql_host=$withval - mysql_host_set=yes - ;; - esac], - [mysql_host_set=no]) - -if test x$mysql_host_set = xyes; then - AC_MSG_RESULT(['$mysql_host']) -else - AC_MSG_RESULT([localhost]) -fi - -# Port. -# -AC_MSG_CHECKING([for mysql database port]) -AC_ARG_WITH( - [mysql-port], - [AC_HELP_STRING([--with-mysql-port=PORT], [MySQL database port (standard MySQL port by default)])], - [case $withval in - yes) - mysql_port=0 - mysql_port_set=yes - ;; - no) - mysql_port_set=no - ;; - *) - mysql_port=$withval - mysql_port_set=yes - ;; - esac], - [mysql_port_set=no]) - -if test x$mysql_port_set = xyes; then - AC_MSG_RESULT(['$mysql_port']) -else - AC_MSG_RESULT([default]) -fi - -# Socket. -# -AC_MSG_CHECKING([for mysql database socket]) -AC_ARG_WITH( - [mysql-socket], - [AC_HELP_STRING([--with-mysql-socket=SOCKET], [MySQL database socket (standard MySQL socket by default)])], - [case $withval in - yes) - mysql_socket= - mysql_socket_set=yes - ;; - no) - mysql_socket_set=no - ;; - *) - mysql_socket=$withval - mysql_socket_set=yes - ;; - esac], - [mysql_socket_set=no]) - -if test x$mysql_socket_set = xyes; then - AC_MSG_RESULT(['$mysql_socket']) -else - AC_MSG_RESULT([default]) -fi - -# Create options file. -# -AC_CONFIG_COMMANDS([mysql.options], - [ - rm -f mysql.options - echo '#! /bin/sh' >mysql-driver - - echo 'opt=' >>mysql-driver - - if test x$mysql_user_set = xyes; then - echo "--user '$mysql_user'" >>mysql.options - echo 'opt="$opt --user='"$mysql_user"'"' >>mysql-driver - fi - - if test x$mysql_password_set = xyes; then - echo "--password '$mysql_password'" >>mysql.options - echo 'opt="$opt --password='"$mysql_password"'"' >>mysql-driver - fi - - if test x$mysql_db_set = xyes; then - echo "--database '$mysql_db'" >>mysql.options - echo 'opt="$opt --database='"$mysql_db"'"' >>mysql-driver - fi - - if test x$mysql_host_set = xyes; then - echo "--host '$mysql_host'" >>mysql.options - echo 'opt="$opt --host='"$mysql_host"'"' >>mysql-driver - fi - - if test x$mysql_port_set = xyes; then - echo "--port '$mysql_port'" >>mysql.options - echo 'opt="$opt --port='"$mysql_port"'"' >>mysql-driver - fi - - if test x$mysql_socket_set = xyes; then - echo "--socket '$mysql_socket'" >>mysql.options - echo 'opt="$opt --socket='"$mysql_socket"'"' >>mysql-driver - fi - - echo 'if test x$[]1 != x; then' >>mysql-driver - echo " exec $mysql_client "'$opt <$[]1' >>mysql-driver - echo "else" >>mysql-driver - echo " exec $mysql_client "'$opt' >>mysql-driver - echo "fi" >>mysql-driver - - chmod +x mysql-driver - ], - [ - mysql_client="$mysql_client" - - mysql_user="$mysql_user" - mysql_user_set="$mysql_user_set" - - mysql_password="$mysql_password" - mysql_password_set="$mysql_password_set" - - mysql_db="$mysql_db" - mysql_db_set="$mysql_db_set" - - mysql_host="$mysql_host" - mysql_host_set="$mysql_host_set" - - mysql_port="$mysql_port" - mysql_port_set="$mysql_port_set" - - mysql_socket="$mysql_socket" - mysql_socket_set="$mysql_socket_set" - ]) - -])dnl diff --git a/m4/odb.m4 b/m4/odb.m4 deleted file mode 100644 index 3e1b19b..0000000 --- a/m4/odb.m4 +++ /dev/null @@ -1,43 +0,0 @@ -dnl file : m4/odb.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl ODB_COMPILER([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) -dnl -AC_DEFUN([ODB_COMPILER], [ -odb_found=no - -AC_ARG_VAR([ODB],[ODB compiler command]) -AC_ARG_VAR([ODBFLAGS],[ODB compiler flags]) -AC_ARG_VAR([ODBCPPFLAGS],[ODB-specific C++ preprocessor flags]) - -AC_ARG_WITH( - [odb], - [AC_HELP_STRING([--with-odb=DIR],[location of odb compiler build directory])], - [odb_dir=${withval}], - [odb_dir=]) - -AC_MSG_CHECKING([for odb]) - -save_ODB="$ODB" - -if test x"$ODB" = x; then - if test x"$odb_dir" != x; then - AS_SET_CATFILE([abs_odb_dir], [$ac_pwd], [$odb_dir]) - ODB="$abs_odb_dir/odb/odb" - else - ODB=odb - fi -fi - -$ODB --version 2>/dev/null 1>&2 - -if test x"$?" = x0; then - AC_MSG_RESULT([$ODB]) - $1 -else - AC_MSG_RESULT([no]) - ODB="$save_ODB" - $2 -fi - -])dnl diff --git a/m4/oracle.m4 b/m4/oracle.m4 deleted file mode 100644 index c095214..0000000 --- a/m4/oracle.m4 +++ /dev/null @@ -1,243 +0,0 @@ -dnl file : m4/oracle.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl ORACLE -dnl -AC_DEFUN([ORACLE], [ - -# Client. -# -AC_MSG_CHECKING([for oracle client program]) -AC_ARG_WITH( - [oracle-client], - [AC_HELP_STRING([--with-oracle-client=PATH], [Oracle client program path (sqlplus by default)])], - [case $withval in - yes) - oracle_client=sqlplus - ;; - no) - AC_MSG_RESULT([]) - AC_MSG_ERROR([need oracle client to run the tests]) - ;; - *) - oracle_client=$withval - ;; - esac], - [oracle_client=sqlplus]) - -$oracle_client -V 2>/dev/null 1>&2 - -if test x"$?" = x0; then - AC_MSG_RESULT([$oracle_client]) -else - AC_MSG_RESULT([no]) - AC_MSG_ERROR([oracle client is not found; consider using --with-oracle-client=PATH]) -fi - -# User. -# -AC_MSG_CHECKING([for oracle database user]) -AC_ARG_WITH( - [oracle-user], - [AC_HELP_STRING([--with-oracle-user=NAME], [Oracle database user (odb_test by default)])], - [case $withval in - yes) - oracle_user=odb_test - oracle_user_set=yes - ;; - no) - oracle_user_set=no - ;; - *) - oracle_user=$withval - oracle_user_set=yes - ;; - esac], - [oracle_user=odb_test - oracle_user_set=yes]) - -if test x$oracle_user_set = xyes; then - AC_MSG_RESULT(['$oracle_user']) -else - AC_MSG_RESULT([none]) -fi - -# Password. -# -AC_MSG_CHECKING([for oracle database password]) -AC_ARG_WITH( - [oracle-password], - [AC_HELP_STRING([--with-oracle-password=PASS], [Oracle database password (odb_test by default)])], - [case $withval in - yes) - oracle_password=odb_test - oracle_password_set=yes - ;; - no) - oracle_password_set=no - ;; - *) - oracle_password=$withval - oracle_password_set=yes - ;; - esac], - [oracle_password_set=no]) - -if test x$oracle_password_set = xyes; then - AC_MSG_RESULT(['$oracle_password']) -elif test x$oracle_user = xodb_test; then - oracle_password=odb_test - oracle_password_set=yes - AC_MSG_RESULT(['$oracle_password']) -elif test x$oracle_user != x/; then - AC_MSG_RESULT([none]) - AC_MSG_ERROR([password not specified; Oracle requires a password (--with-oracle-password=PASS)]) -fi - -# Service name. -# -AC_MSG_CHECKING([for oracle service name]) -AC_ARG_WITH( - [oracle-service], - [AC_HELP_STRING([--with-oracle-service=NAME], [Oracle service name (default service if left empty). Note that all data associated with this user on this service WILL BE LOST!])], - [case $withval in - yes) - oracle_service= - oracle_service_set=yes - ;; - no) - oracle_service_set=no - ;; - *) - oracle_service=$withval - oracle_service_set=yes - ;; - esac], - [oracle_service_set=no]) - -if test x$oracle_service_set = xyes; then - AC_MSG_RESULT(['$oracle_service']) -else - AC_MSG_RESULT([default]) -fi - -# Host. -# -AC_MSG_CHECKING([for oracle database host]) -AC_ARG_WITH( - [oracle-host], - [AC_HELP_STRING([--with-oracle-host=HOST], [Oracle database host (localhost by default)])], - [case $withval in - yes) - oracle_host=localhost - oracle_host_set=yes - ;; - no) - oracle_host_set=no - ;; - *) - oracle_host=$withval - oracle_host_set=yes - ;; - esac], - [oracle_host_set=no]) - -if test x$oracle_host_set = xyes; then - AC_MSG_RESULT(['$oracle_host']) -else - AC_MSG_RESULT([localhost]) -fi - -# Port. -# -AC_MSG_CHECKING([for oracle database port]) -AC_ARG_WITH( - [oracle-port], - [AC_HELP_STRING([--with-oracle-port=PORT], [Oracle database port (standard Oracle port by default)])], - [case $withval in - yes) - oracle_port=1521 - oracle_port_set=yes - ;; - no) - oracle_port_set=no - ;; - *) - oracle_port=$withval - oracle_port_set=yes - ;; - esac], - [oracle_port_set=no]) - -if test x$oracle_port_set = xyes; then - AC_MSG_RESULT(['$oracle_port']) -else - AC_MSG_RESULT([default]) -fi - -# Create options file. -# -AC_CONFIG_COMMANDS([oracle.options], - [ - rm -f oracle.options - echo '#! /bin/sh' >oracle-driver - - echo 'conn_str=' >>oracle-driver - - if test x$oracle_user_set = xyes; then - echo "--user '$oracle_user'" >>oracle.options - echo 'conn_str="'"$oracle_user"'"' >>oracle-driver - fi - - if test x$oracle_password_set = xyes; then - echo "--password '$oracle_password'" >>oracle.options - echo 'conn_str="$conn_str/'"$oracle_password"'"' >>oracle-driver - fi - - if test x$oracle_host_set = xyes; then - echo "--host '$oracle_host'" >>oracle.options - echo 'conn_str="$conn_str@//'"$oracle_host"'"' >>oracle-driver - - if test x$oracle_port_set = xyes; then - echo "--port '$oracle_port'" >>oracle.options - echo 'conn_str="$conn_str:'"$oracle_port"'"' >>oracle-driver - fi - fi - - if test x$oracle_service != x; then - if test x$oracle_host_set = xno; then - echo 'conn_str="$conn_str@"' >>oracle-driver - fi - - echo "--service '$oracle_service'" >>oracle.options - echo 'conn_str="$conn_str/'"$oracle_service"'"' >>oracle-driver - fi - - echo 'if test x$[]1 != x; then' >>oracle-driver - echo " exec $oracle_client -L -S "'$conn_str @$[]1' >>oracle-driver - echo "else" >>oracle-driver - echo " exec $oracle_client -L -S "'$conn_str' >>oracle-driver - echo "fi" >>oracle-driver - - chmod +x oracle-driver - ], - [ - oracle_client="$oracle_client" - - oracle_user="$oracle_user" - oracle_user_set="$oracle_user_set" - - oracle_password="$oracle_password" - oracle_password_set="$oracle_password_set" - - oracle_service="$oracle_service" - oracle_service_set="$oracle_service_set" - - oracle_host="$oracle_host" - oracle_host_set="$oracle_host_set" - - oracle_port="$oracle_port" - oracle_port_set="$oracle_port_set" - ]) - -])dnl diff --git a/m4/pgsql.m4 b/m4/pgsql.m4 deleted file mode 100644 index eb29a62..0000000 --- a/m4/pgsql.m4 +++ /dev/null @@ -1,204 +0,0 @@ -dnl file : m4/pgsql.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl PGSQL -dnl -AC_DEFUN([PGSQL], [ - -# Client. -# -AC_MSG_CHECKING([for pgsql client program]) -AC_ARG_WITH( - [pgsql-client], - [AC_HELP_STRING([--with-pgsql-client=PATH], [PostgreSQL client program path (psql by default)])], - [case $withval in - yes) - pgsql_client=psql - ;; - no) - AC_MSG_RESULT([]) - AC_MSG_ERROR([need pgsql client to run the tests]) - ;; - *) - pgsql_client=$withval - ;; - esac], - [pgsql_client=psql]) - -$pgsql_client --version 2>/dev/null 1>&2 - -if test x"$?" = x0; then - AC_MSG_RESULT([$pgsql_client]) -else - AC_MSG_RESULT([no]) - AC_MSG_ERROR([pgsql client is not found; consider using --with-pgsql-client=PATH]) -fi - -# User. -# -AC_MSG_CHECKING([for pgsql database user]) -AC_ARG_WITH( - [pgsql-user], - [AC_HELP_STRING([--with-pgsql-user=NAME], [PostgreSQL database user (odb_test by default). The user must be able to login without specifying a password.])], - [case $withval in - yes) - pgsql_user=odb_test - pgsql_user_set=yes - ;; - no) - pgsql_user_set=no - ;; - *) - pgsql_user=$withval - pgsql_user_set=yes - ;; - esac], - [pgsql_user=odb_test - pgsql_user_set=yes]) - -if test x$pgsql_user_set = xyes; then - AC_MSG_RESULT(['$pgsql_user']) -else - AC_MSG_RESULT([none]) -fi - -# Database name. -# -AC_MSG_CHECKING([for pgsql database name]) -AC_ARG_WITH( - [pgsql-db], - [AC_HELP_STRING([--with-pgsql-db=NAME], [PostgreSQL database name (odb_test by default). Note that all data in this database WILL BE LOST!])], - [case $withval in - yes) - pgsql_db=odb_test - pgsql_db_set=yes - ;; - no) - pgsql_db_set=no - ;; - *) - pgsql_db=$withval - pgsql_db_set=yes - ;; - esac], - [pgsql_db=odb_test - pgsql_db_set=yes]) - -if test x$pgsql_db_set = xyes; then - AC_MSG_RESULT(['$pgsql_db']) -else - AC_MSG_RESULT([none]) -fi - -# Host. -# -AC_MSG_CHECKING([for pgsql database host]) -AC_ARG_WITH( - [pgsql-host], - [AC_HELP_STRING([--with-pgsql-host=HOST], [PostgreSQL database host (local host by default)])], - [case $withval in - yes) - pgsql_host= - pgsql_host_set=yes - ;; - no) - pgsql_host_set=no - ;; - *) - pgsql_host=$withval - pgsql_host_set=yes - ;; - esac], - [pgsql_host_set=no]) - -if test x$pgsql_host_set = xyes; then - AC_MSG_RESULT(['$pgsql_host']) -else - AC_MSG_RESULT([localhost]) -fi - -# Port. -# -AC_MSG_CHECKING([for pgsql database port]) -AC_ARG_WITH( - [pgsql-port], - [AC_HELP_STRING([--with-pgsql-port=PORT], [PostgreSQL database port (standard PostgreSQL port by default)])], - [case $withval in - yes) - pgsql_port=0 - pgsql_port_set=yes - ;; - no) - pgsql_port_set=no - ;; - *) - pgsql_port=$withval - pgsql_port_set=yes - ;; - esac], - [pgsql_port_set=no]) - -if test x$pgsql_port_set = xyes; then - AC_MSG_RESULT(['$pgsql_port']) -else - AC_MSG_RESULT([default]) -fi - -# Create options file. -# -AC_CONFIG_COMMANDS([pgsql.options], - [ - rm -f pgsql.options - echo '#! /bin/sh' >pgsql-driver - - echo 'opt=' >>pgsql-driver - - if test x$pgsql_user_set = xyes; then - echo "--username '$pgsql_user'" >>pgsql.options - echo 'opt="$opt --username='"$pgsql_user"'"' >>pgsql-driver - fi - - if test x$pgsql_db_set = xyes; then - echo "--dbname '$pgsql_db'" >>pgsql.options - echo 'opt="$opt --dbname='"$pgsql_db"'"' >>pgsql-driver - fi - - if test x$pgsql_host_set = xyes; then - echo "--host '$pgsql_host'" >>pgsql.options - echo 'opt="$opt --host='"$pgsql_host"'"' >>pgsql-driver - fi - - if test x$pgsql_port_set = xyes; then - echo "--port '$pgsql_port'" >>pgsql.options - echo 'opt="$opt --port='"$pgsql_port"'"' >>pgsql-driver - fi - - echo 'opt="$opt --quiet"' >>pgsql-driver - echo 'PGOPTIONS=--client-min-messages=warning' >>pgsql-driver - echo 'export PGOPTIONS' >>pgsql-driver - - echo 'if test x$[]1 != x; then' >>pgsql-driver - echo " exec $pgsql_client "'$opt --set ON_ERROR_STOP=1 -f $[]1' >>pgsql-driver - echo "else" >>pgsql-driver - echo " exec $pgsql_client "'$opt' >>pgsql-driver - echo "fi" >>pgsql-driver - - chmod +x pgsql-driver - ], - [ - pgsql_client="$pgsql_client" - - pgsql_user="$pgsql_user" - pgsql_user_set="$pgsql_user_set" - - pgsql_db="$pgsql_db" - pgsql_db_set="$pgsql_db_set" - - pgsql_host="$pgsql_host" - pgsql_host_set="$pgsql_host_set" - - pgsql_port="$pgsql_port" - pgsql_port_set="$pgsql_port_set" - ]) - -])dnl diff --git a/m4/sqlite.m4 b/m4/sqlite.m4 deleted file mode 100644 index 7c1a53e..0000000 --- a/m4/sqlite.m4 +++ /dev/null @@ -1,59 +0,0 @@ -dnl file : m4/sqlite.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl SQLITE -dnl -AC_DEFUN([SQLITE], [ - -# Database file. -# -AC_MSG_CHECKING([for sqlite database file]) -AC_ARG_WITH( - [sqlite-db], - [AC_HELP_STRING([--with-sqlite-db=FILE], [SQLite database file (odb-test.db by default). Note that all data in this database WILL BE LOST!])], - [case $withval in - yes) - sqlite_db=odb-test.db - sqlite_db_set=yes - ;; - no) - sqlite_db_set=no - ;; - *) - sqlite_db=$withval - sqlite_db_set=yes - ;; - esac], - [sqlite_db=odb-test.db - sqlite_db_set=yes]) - -if test x$sqlite_db_set = xyes; then - - # Make it an absolute path unless it is one of the special values. - # - if test x$sqlite_db != x -a x$sqlite_db != x:memory:; then - AS_SET_CATFILE([abs_sqlite_db], [$ac_pwd], [$sqlite_db]) - sqlite_db=$abs_sqlite_db - fi - - AC_MSG_RESULT(['$sqlite_db']) -else - AC_MSG_RESULT([none]) -fi - -# Create options file. -# -AC_CONFIG_COMMANDS([sqlite.options], - [ - rm -f sqlite.options - - if test x$sqlite_db_set = xyes; then - echo "--database '$sqlite_db'" >>sqlite.options - fi - ], - [ - sqlite_db="$sqlite_db" - sqlite_db_set="$sqlite_db_set" - ]) - -])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/m4/tr1-memory.m4 b/m4/tr1-memory.m4 deleted file mode 100644 index a70f397..0000000 --- a/m4/tr1-memory.m4 +++ /dev/null @@ -1,38 +0,0 @@ -dnl file : m4/tr1-memory.m4 -dnl license : GNU GPL v2; see accompanying LICENSE file -dnl -dnl TR1_MEMORY -dnl -dnl Check for TR1 availability. If successful, define HAVE_TR1_MEMORY -dnl as both a macro and conditional as well as set the tr1_memory variable -dnl to 'yes'. -dnl -AC_DEFUN([TR1_MEMORY], -[ -tr1_memory=no - -AC_MSG_CHECKING([for TR1 ]) - -CXX_LIBTOOL_LINK_IFELSE([ -AC_LANG_SOURCE([ -#include - -int -main () -{ - std::tr1::shared_ptr p (new int (10)); - *p = 11; -} -])], -[tr1_memory=yes]) - -if test x"$tr1_memory" = xyes; then - AC_MSG_RESULT([yes]) - AC_DEFINE([HAVE_TR1_MEMORY], [1], [Have TR1 .]) -else - AC_MSG_RESULT([no]) -fi - -AM_CONDITIONAL([HAVE_TR1_MEMORY], [test x$tr1_memory = xyes]) - -])dnl diff --git a/makefile b/makefile deleted file mode 100644 index a9f4eec..0000000 --- a/makefile +++ /dev/null @@ -1,88 +0,0 @@ -# file : makefile -# license : GNU GPL; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))build/bootstrap.make - -dirs := \ -access \ -composite \ -container \ -hello \ -inheritance/polymorphism \ -inheritance/reuse \ -query \ -mapping \ -optimistic \ -pimpl \ -prepared \ -schema/embedded \ -section - -tr1_dirs := relationship inverse schema/custom view -cxx11_dirs := c++11 -boost_dirs := boost -qt_dirs := qt - -default := $(out_base)/ -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -$(default): -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard - -dist_dirs := $(dirs) $(tr1_dirs) $(cxx11_dirs) $(boost_dirs) $(qt_dirs) -all_dirs := $(dirs) $(tr1_dirs) $(cxx11_dirs) $(boost_dirs) $(qt_dirs) \ -template - -build_dirs := $(dirs) $(tr1_dirs) $(boost_dirs) $(qt_dirs) template - -ifeq ($(cxx_standard),c++11) -build_dirs += $(cxx11_dirs) -endif - -$(default): $(addprefix $(out_base)/,$(addsuffix /,$(build_dirs))) - -$(dist): name := examples -$(dist): export dirs := $(dirs) -$(dist): export tr1_dirs := $(tr1_dirs) -$(dist): export cxx11_dirs := $(cxx11_dirs) -$(dist): export boost_dirs := $(boost_dirs) -$(dist): export qt_dirs := $(qt_dirs) -$(dist): data_dist := GPLv2 LICENSE README NEWS INSTALL version tester.bat \ -mysql-driver.bat mysql.options sqlite-driver.bat sqlite.options \ -pgsql-driver.bat pgsql.options oracle-driver.bat oracle.options \ -mssql-driver.bat mssql.options -$(dist): exec_dist := bootstrap tester.in -$(dist): export extra_dist := $(data_dist) $(exec_dist) test.bat \ -$(call vc8slns,$(name)) $(call vc9slns,$(name)) $(call vc10slns,$(name)) \ -$(call vc11slns,$(name)) $(call vc12slns,$(name)) -$(dist): export version = $(shell cat $(src_root)/version) - -$(dist): $(addprefix $(out_base)/,$(addsuffix /.dist,$(dist_dirs))) - $(call dist-data,$(data_dist)) - $(call dist-exec,$(exec_dist)) - $(call dist-dir,m4) - $(call meta-automake) - $(call meta-autoconf) - $(call meta-vc8slns,$(name)) - $(call meta-vc9slns,$(name)) - $(call meta-vc10slns,$(name)) - $(call meta-vc11slns,$(name)) - $(call meta-vc12slns,$(name)) - $(call meta-vctest,$(name)-mysql-vc10.sln,test.bat) - -$(test): $(addprefix $(out_base)/,$(addsuffix /.test,$(build_dirs))) -$(clean): $(addprefix $(out_base)/,$(addsuffix /.clean,$(all_dirs))) - -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8sln.make) -$(call include,$(bld_root)/meta/vc9sln.make) -$(call include,$(bld_root)/meta/vc10sln.make) -$(call include,$(bld_root)/meta/vc11sln.make) -$(call include,$(bld_root)/meta/vc12sln.make) -$(call include,$(bld_root)/meta/vctest.make) -$(call include,$(bld_root)/meta/automake.make) -$(call include,$(bld_root)/meta/autoconf.make) - -$(foreach d,$(all_dirs),$(call import,$(src_base)/$d/makefile)) diff --git a/mapping/README b/mapping/README deleted file mode 100644 index 52b7e5b..0000000 --- a/mapping/README +++ /dev/null @@ -1,76 +0,0 @@ -This examples shows how to customize the mapping between C++ value types -and database types. The example changes the default mapping for the 'bool' -type which is now stored in the database as the "true" or "false" string. -It also maps the user-defined 'date' type to a suitable database date type. - -The example consists of the following files: - -person.hxx - Header file defining the 'date' value type and the 'person' persistent - class. It also uses the ODB value type pragma to map 'bool' to the - 'VARCHAR(5)' database type and 'date' to the 'DATE' database type. - -traits.hxx -traits-mysql.hxx -traits-sqlite.hxx - ODB 'value_traits' template specializations for the 'bool' and 'date' - types. These specializations implement conversion between these types - and their database counterparts. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-query --generate-schema \ - --hxx-prologue "#include \"traits.hxx\"" person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The --hxx-prologue option included the traits.hxx header at the beginning - of the generated person-odb.hxx file. This makes the 'value_traits' - specializations defined in traits.hxx known to the generated database - support code. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then persists a number of 'person' objects in the database - and executes a query to find objects matching certain criteria. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -DDATABASE_MYSQL -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/mapping/database.hxx b/mapping/database.hxx deleted file mode 100644 index fe210d8..0000000 --- a/mapping/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : mapping/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/mapping/driver.cxx b/mapping/driver.cxx deleted file mode 100644 index ea392d5..0000000 --- a/mapping/driver.cxx +++ /dev/null @@ -1,65 +0,0 @@ -// file : mapping/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - // Create a few persistent person objects. - // - { - person john ("John", "Doe", date (1978, 10, 13), true); - person jane ("Jane", "Doe", date (1975, 9, 23), false); - person joe ("Joe", "Dirt", date (1973, 12, 3), true); - - transaction t (db->begin ()); - - db->persist (john); - db->persist (jane); - db->persist (joe); - - t.commit (); - } - - // Query for a person using data members of our custom-mapped types. - // - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - result r (db->query (query::married && - query::born == date (1978, 10, 13))); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - cout << i->first () << " " << i->last () << " " << i->born () << endl; - } - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/mapping/makefile b/mapping/makefile deleted file mode 100644 index 0e4d97a..0000000 --- a/mapping/makefile +++ /dev/null @@ -1,127 +0,0 @@ -# file : mapping/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --generate-query \ ---hxx-prologue '\#include "traits.hxx"' --table-prefix mapping_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export extra_headers := traits.hxx $(databases:%=traits-%.hxx) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) $(extra_headers) \ -README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/mapping/person.hxx b/mapping/person.hxx deleted file mode 100644 index c1a43b9..0000000 --- a/mapping/person.hxx +++ /dev/null @@ -1,106 +0,0 @@ -// file : mapping/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include -#include - -#include - -// In our database boolean values are stored as strings with valid -// values being "true" and "false". -// -#pragma db value(bool) type("VARCHAR(5)") - -#pragma db value type("DATE") -class date -{ -public: - date (unsigned int year, unsigned int month, unsigned int day) - : year_ (year), month_ (month), day_ (day) - { - } - - unsigned int - year () const - { - return year_; - } - - unsigned int - month () const - { - return month_; - } - - unsigned int - day () const - { - return day_; - } - -private: - unsigned int year_; - unsigned int month_; - unsigned int day_; -}; - -inline std::ostream& -operator<< (std::ostream& os, const date& d) -{ - return os << d.year () << '-' << d.month () << '-' << d.day (); -} - -#pragma db object -class person -{ -public: - person (const std::string& first, - const std::string& last, - const date& born, - bool married) - : first_ (first), last_ (last), born_ (born), married_ (married) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - const date& - born () const - { - return born_; - } - - bool - married () const - { - return married_; - } - -private: - friend class odb::access; - - person (): born_ (0, 0, 0) {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - date born_; - bool married_; -}; - -#endif // PERSON_HXX diff --git a/mapping/traits-mssql.hxx b/mapping/traits-mssql.hxx deleted file mode 100644 index 3713f82..0000000 --- a/mapping/traits-mssql.hxx +++ /dev/null @@ -1,85 +0,0 @@ -// file : mapping/traits-mssql.hxx -// copyright : not copyrighted - public domain - -#ifndef TRAITS_MSSQL_HXX -#define TRAITS_MSSQL_HXX - -// -// SQL Server implementation. -// - -#include // std::size_t -#include // std::strncmp, std::memcpy -#include - -#include - -#include "person.hxx" // date - -namespace odb -{ - namespace mssql - { - template <> - class value_traits - { - public: - typedef bool value_type; - typedef bool query_type; - typedef char* image_type; - - static void - set_value (bool& v, - const char* b, - std::size_t n, - bool is_null) - { - v = (!is_null && n == 4 && std::strncmp ("true", b, n) == 0); - } - - static void - set_image (char* b, - std::size_t c, - std::size_t& n, - bool& is_null, - bool v) - { - is_null = false; - n = v ? 4 : 5; - - assert (n <= c); - - std::memcpy (b, (v ? "true" : "false"), n); - } - }; - - template <> - class value_traits< ::date, id_date> - { - public: - typedef ::date value_type; - typedef ::date query_type; - typedef mssql::date image_type; - - static void - set_value (value_type& v, const image_type& i, bool is_null) - { - if (!is_null) - v = value_type (static_cast (i.year), i.month, i.day); - else - v = value_type (0, 0, 0); - } - - static void - set_image (image_type& i, bool& is_null, const value_type& v) - { - is_null = false; - i.year = static_cast (v.year ()); - i.month = static_cast (v.month ()); - i.day = static_cast (v.day ()); - } - }; - } -} - -#endif // TRAITS_MSSQL_HXX diff --git a/mapping/traits-mysql.hxx b/mapping/traits-mysql.hxx deleted file mode 100644 index a15d1c9..0000000 --- a/mapping/traits-mysql.hxx +++ /dev/null @@ -1,85 +0,0 @@ -// file : mapping/traits-mysql.hxx -// copyright : not copyrighted - public domain - -#ifndef TRAITS_MYSQL_HXX -#define TRAITS_MYSQL_HXX - -// -// MySQL implementation. -// - -#include // std::size_t -#include // std::strncmp, std::memcpy - -#include - -#include "person.hxx" // date - -namespace odb -{ - namespace mysql - { - template <> - class value_traits - { - public: - typedef bool value_type; - typedef bool query_type; - typedef details::buffer image_type; - - static void - set_value (bool& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - v = (!is_null && n == 4 && std::strncmp ("true", b.data (), n) == 0); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - bool v) - { - is_null = false; - n = v ? 4 : 5; - - if (n > b.capacity ()) - b.capacity (n); - - std::memcpy (b.data (), (v ? "true" : "false"), n); - } - }; - - template <> - class value_traits - { - public: - typedef date value_type; - typedef date query_type; - typedef MYSQL_TIME image_type; - - static void - set_value (date& v, const MYSQL_TIME& i, bool is_null) - { - if (!is_null) - v = date (i.year, i.month, i.day); - else - v = date (0, 0, 0); - } - - static void - set_image (MYSQL_TIME& i, bool& is_null, const date& v) - { - is_null = false; - i.neg = false; - i.year = v.year (); - i.month = v.month (); - i.day = v.day (); - } - }; - } -} - -#endif // TRAITS_MYSQL_HXX diff --git a/mapping/traits-oracle.hxx b/mapping/traits-oracle.hxx deleted file mode 100644 index a5683c6..0000000 --- a/mapping/traits-oracle.hxx +++ /dev/null @@ -1,95 +0,0 @@ -// file : mapping/traits-oracle.hxx -// copyright : not copyrighted - public domain - -#ifndef TRAITS_ORACLE_HXX -#define TRAITS_ORACLE_HXX - -// -// Oracle implementation. -// - -#include // std::size_t -#include // std::strncmp, std::memcpy -#include - -#include -#include - -#include "person.hxx" // date - -namespace odb -{ - namespace oracle - { - template <> - class value_traits - { - public: - typedef bool value_type; - typedef bool query_type; - typedef char* image_type; - - static void - set_value (bool& v, - const char* b, - std::size_t n, - bool is_null) - { - v = (!is_null && n == 4 && std::strncmp ("true", b, n) == 0); - } - - static void - set_image (char* b, - std::size_t c, - std::size_t& n, - bool& is_null, - bool v) - { - is_null = false; - n = v ? 4 : 5; - - assert (n <= c); - - std::memcpy (b, (v ? "true" : "false"), n); - } - }; - - template <> - class value_traits - { - public: - typedef date value_type; - typedef date query_type; - typedef char* image_type; - - static void - set_value (date& v, const char* b, bool is_null) - { - if (!is_null) - { - short y; - unsigned char m, d, h, min, s; - details::get_date (b, y, m, d, h, min, s); - - v = date (y, m, d); - } - else - v = date (0, 0, 0); - } - - static void - set_image (char* b, bool& is_null, const date& v) - { - is_null = false; - - short y (static_cast (v.year ())); - unsigned char m (static_cast (v.month ())); - unsigned char d (static_cast (v.day ())); - - details::set_date (b, y, m, d, 0, 0, 0); - } - }; - } -} - -#endif // TRAITS_ORACLE_HXX diff --git a/mapping/traits-pgsql.hxx b/mapping/traits-pgsql.hxx deleted file mode 100644 index aeefa52..0000000 --- a/mapping/traits-pgsql.hxx +++ /dev/null @@ -1,118 +0,0 @@ -// file : mapping/traits-pgsql.hxx -// copyright : not copyrighted - public domain - -#ifndef TRAITS_PGSQL_HXX -#define TRAITS_PGSQL_HXX - -// -// PostgreSQL implementation. -// - -#include // std::size_t -#include // std::strncmp, std::memset, std::memcpy -#include // localtime, mktime, time_t, tm - -#include -#include - -#include "person.hxx" // date - -namespace odb -{ - namespace pgsql - { - template <> - class value_traits - { - public: - typedef bool value_type; - typedef bool query_type; - typedef details::buffer image_type; - - static void - set_value (bool& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - v = (!is_null && n == 4 && std::strncmp ("true", b.data (), n) == 0); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - bool v) - { - is_null = false; - n = v ? 4 : 5; - - if (n > b.capacity ()) - b.capacity (n); - - std::memcpy (b.data (), (v ? "true" : "false"), n); - } - }; - - // Mapping of date to PostgreSQL DATE. DATE is stored as the number - // of days since the PostgreSQL epoch 2000-01-01. - // - template <> - class value_traits - { - public: - typedef date value_type; - typedef date query_type; - typedef int image_type; - - // The difference between the PostgreSQL epoch and the Unix epoch - // in seconds. - // - static const time_t epoch_diff = 946684800; - - static const time_t seconds_per_day = 86400; - - static void - set_value (date& v, const int& i, bool is_null) - { - if (is_null) - { - v = date (0, 0, 0); - return; - } - - time_t v_tt (epoch_diff + - static_cast (details::endian_traits::ntoh (i)) * - seconds_per_day); - - // Assume that the date is specified as UTC. Use localtime so as - // to avoid any timeshift that could be introduced by the system - // time locale not being UTC. - // - tm v_tm (*localtime (&v_tt)); - - v = date (v_tm.tm_year + 1900, v_tm.tm_mon + 1, v_tm.tm_mday); - } - - static void - set_image (int& i, bool& is_null, const date& v) - { - is_null = false; - - tm v_tm; - std::memset (&v_tm, 0, sizeof (v_tm)); - - v_tm.tm_mday = v.day (); - v_tm.tm_mon = v.month () - 1; - v_tm.tm_year = v.year () - 1900; - - time_t v_tt (mktime (&v_tm)); - - i = details::endian_traits::hton ( - static_cast ((v_tt - epoch_diff) / seconds_per_day)); - } - }; - } -} - -#endif // TRAITS_PGSQL_HXX diff --git a/mapping/traits-sqlite.hxx b/mapping/traits-sqlite.hxx deleted file mode 100644 index cd7afc3..0000000 --- a/mapping/traits-sqlite.hxx +++ /dev/null @@ -1,127 +0,0 @@ -// file : mapping/traits-sqlite.hxx -// copyright : not copyrighted - public domain - -#ifndef TRAITS_SQLITE_HXX -#define TRAITS_SQLITE_HXX - -// -// SQLite implementation. -// - -#include // std::size_t -#include // std::strncmp, std::memcpy -#include - -#include - -#include "person.hxx" // date - -namespace odb -{ - namespace sqlite - { - template <> - class value_traits - { - public: - typedef bool value_type; - typedef bool query_type; - typedef details::buffer image_type; - - static void - set_value (bool& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - v = (!is_null && n == 4 && std::strncmp ("true", b.data (), n) == 0); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - bool v) - { - is_null = false; - n = v ? 4 : 5; - - if (n > b.capacity ()) - b.capacity (n); - - std::memcpy (b.data (), (v ? "true" : "false"), n); - } - }; - - // In SQLite there is no built-in DATE type. Rather, this type is - // mapped to TEXT in the YYYY-MM-DD format. The below implementation - // doesn't do any error checking for brevity. - // - template <> - class value_traits - { - public: - typedef date value_type; - typedef date query_type; - typedef details::buffer image_type; - - static void - set_value (date& v, - const details::buffer& b, - std::size_t n, - bool is_null) - { - using namespace std; - - if (!is_null) - { - istringstream is (string (b.data (), n)); - unsigned int y, m, d; - - is >> y; - is.ignore (1); - is >> m; - is.ignore (1); - is >> d; - - v = date (y, m, d); - } - else - v = date (0, 0, 0); - } - - static void - set_image (details::buffer& b, - std::size_t& n, - bool& is_null, - const date& v) - { - using namespace std; - - ostringstream os; - os.fill ('0'); - - os.width (4); - os << v.year () << '-'; - - os.width (2); - os << v.month () << '-'; - - os.width (2); - os << v.day (); - - const string& s (os.str ()); - - is_null = false; - n = s.size (); - - if (n > b.capacity ()) - b.capacity (n); - - memcpy (b.data (), s.c_str (), n); - } - }; - } -} - -#endif // TRAITS_SQLITE_HXX diff --git a/mapping/traits.hxx b/mapping/traits.hxx deleted file mode 100644 index 533b2e3..0000000 --- a/mapping/traits.hxx +++ /dev/null @@ -1,23 +0,0 @@ -// file : mapping/traits.hxx -// copyright : not copyrighted - public domain - -#ifndef TRAITS_HXX -#define TRAITS_HXX - -// Include one of the database system-specific traits implementations. -// -#if defined(DATABASE_MYSQL) -# include "traits-mysql.hxx" -#elif defined(DATABASE_SQLITE) -# include "traits-sqlite.hxx" -#elif defined(DATABASE_PGSQL) -# include "traits-pgsql.hxx" -#elif defined(DATABASE_ORACLE) -# include "traits-oracle.hxx" -#elif defined(DATABASE_MSSQL) -# include "traits-mssql.hxx" -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -#endif // TRAITS_HXX diff --git a/mssql-driver.bat b/mssql-driver.bat deleted file mode 100644 index 174cbf0..0000000 --- a/mssql-driver.bat +++ /dev/null @@ -1,61 +0,0 @@ -@echo off -rem file : mssql-driver.bat -rem license : GNU GPL v2; see accompanying LICENSE file - -rem -rem mssql-driver.bat sql-file -rem -rem Run the mssql client on the SQL file specified. Adjust the -rem options below to match your SQL Server setup. -rem - -setlocal - -set "options=%MSSQL_OPTIONS%" - -rem User. -rem -set "options=%options% -U odb_test" - -rem Password. -rem -set "options=%options% -P odb_test" - -rem Database name. -rem -set "options=%options% -d odb_test" - -rem SQL Server instance address. -rem -rem set "options=%options% -S host\instance" -rem set "options=%options% -S tcp:host,port" - -rem Standard options. -rem -set "options=%options% -x -r -b" - -set "mssql=%MSSQL_CLIENT%" - -if "_%mssql%_" == "__" set "mssql=sqlcmd" - -if "_%1_" == "__" ( - echo no sql file specified - goto usage -) - -%mssql% %options% -i %1 - -if errorlevel 1 goto error -goto end - -:usage -echo. -echo usage: mssql-driver.bat sql-file -echo. - -:error -endlocal -exit /b 1 - -:end -endlocal diff --git a/mssql.options b/mssql.options deleted file mode 100644 index 6e201e2..0000000 --- a/mssql.options +++ /dev/null @@ -1,10 +0,0 @@ -# Sample Microsoft SQL Server options file used to run the tests. Adjust to -# match your SQL Server setup. -# - ---user odb_test ---password odb_test ---database odb_test -# --server host\instance -# --server tcp:host,port -# --driver diff --git a/mysql-driver.bat b/mysql-driver.bat deleted file mode 100644 index 8dde6f9..0000000 --- a/mysql-driver.bat +++ /dev/null @@ -1,46 +0,0 @@ -@echo off -rem file : mysql-driver.bat -rem license : GNU GPL v2; see accompanying LICENSE file - -rem -rem mysql-driver.bat sql-file -rem -rem Run the mysql client on the SQL file specified. Adjust the -rem options below to match your MySQL setup. -rem - -setlocal - -set "options=%MYSQL_OPTIONS%" -set "options=%options% --user=odb_test" -set "options=%options% --database=odb_test" -rem set "options=%options% --password=" -rem set "options=%options% --host=" -rem set "options=%options% --port=" -rem set "options=%options% --socket=" - -set "mysql=%MYSQL_CLIENT%" - -if "_%mysql%_" == "__" set "mysql=mysql" - -if "_%1_" == "__" ( - echo no sql file specified - goto usage -) - -%mysql% %options% < %1 - -if errorlevel 1 goto error -goto end - -:usage -echo. -echo usage: mysql-driver.bat sql-file -echo. - -:error -endlocal -exit /b 1 - -:end -endlocal diff --git a/mysql.options b/mysql.options deleted file mode 100644 index fe79a7c..0000000 --- a/mysql.options +++ /dev/null @@ -1,10 +0,0 @@ -# Sample MySQL options file used to run the tests. Adjust to -# match your MySQL setup. -# - ---user odb_test ---database odb_test -# --password -# --host -# --port -# --socket diff --git a/odb-examples/.gitignore b/odb-examples/.gitignore new file mode 100644 index 0000000..4f5aa7a --- /dev/null +++ b/odb-examples/.gitignore @@ -0,0 +1,39 @@ +# 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 + +# Example executables. +# +driver + +# ODB-generated files. +# +*-odb.?xx +*.sql + +# Testscript output directories (can be symlinks). +# +test +test-driver diff --git a/odb-examples/GPLv2 b/odb-examples/GPLv2 new file mode 100644 index 0000000..3912109 --- /dev/null +++ b/odb-examples/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/odb-examples/LICENSE b/odb-examples/LICENSE new file mode 100644 index 0000000..9d92da1 --- /dev/null +++ b/odb-examples/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/odb-examples/README.md b/odb-examples/README.md new file mode 100644 index 0000000..45b24c1 --- /dev/null +++ b/odb-examples/README.md @@ -0,0 +1,102 @@ +# odb-examples - ODB compiler usage examples + +This package contains examples of using `odb`, object-relational mapping (ORM) +compiler for C++. The following list gives an overview of the available +examples. See the `README` file accompanying each example for more +information. See `odb-tests/README.md` for instructions on setting up various +databases to run these examples. + +Note also that most of the examples use the --table-prefix ODB compiler +option to assign a unique prefix to tables created by each example. This +is done to allow examples to run against the same database without +causing any schema conflicts. You don't have to use this option in your +own applications. + +## hello + +A "Hello World" example that shows how to use ODB to perform basic database +operations. + +## query + +Shows how to use the ODB Query Language to search the database for persistent +objects matching certain criteria. + +## composite + +Shows how to declare and use composite value types. + +## container + +Shows how to use containers as data members in persistent objects. + +## relationship + +Shows how to declare and use unidirectional to-one and to-many relationships. + +## inverse + +Shows how to declare and use bidirectional one-to-one, one-to-many, and +many-to-many relationships. + +## inheritance/reuse + +Shows how to use reuse inheritance with ODB. + +## inheritance/polymorphism + +Shows how to use polymorphism inheritance with ODB. + +## section + +Shows how to use object sections to implement lazy-loading and change-updating +of a subset of data members in a persistent class. + +## view + +Shows how to define and use object, table, mixed, and native views. + +## prepared + +Shows how to use prepared queries. + +## optimistic + +Shows how to use optimistic concurrency in ODB. + +## pimpl + +Shows how to use virtual data members to implement a persistent class that +employs the pimpl C++ idiom. + +## c++11 + +Shows how to use ODB with C++11. + +## access + +Shows various approaches used by ODB to access data members that cannot be +accessed directly. + +## boost + +Shows how to persist objects that use Boost smart pointers, containers, and +value types with the help of the Boost profile library (libodb-boost). + +## qt + +Shows how to persist objects that use Qt smart pointers, containers, and value +types with the help of the Qt profile library (libodb-qt). + +## schema/embedded + +Shows how to generate and use a database schema that is embedded into the +application. + +## schema/custom + +Shows how to map persistent C++ classes to a custom database schema. + +## mapping + +Shows how to customize the mapping between C++ value types and database types. diff --git a/odb-examples/access/README b/odb-examples/access/README new file mode 100644 index 0000000..7fb8b0e --- /dev/null +++ b/odb-examples/access/README @@ -0,0 +1,63 @@ +This example shows various approaches used by ODB to access data members +that cannot be accessed directly. Approaches that are illustrated by this +example include the automatic discovery of suitable accessor/modifier +functions, explicit specification of the accessor/modifier functions, +explicit specification of more complex accessor/modifier expressions, and +use of virtual data members. + +The example consists of the following files: + +person.hxx + Header file implementing the 'person' persistent class. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-query --generate-schema person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent class and its database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. Then it executes a number of database transactions on the 'person' + objects. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/access/buildfile b/odb-examples/access/buildfile new file mode 100644 index 0000000..e59adda --- /dev/null +++ b/odb-examples/access/buildfile @@ -0,0 +1,44 @@ +# file : access/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --output-dir $out_base \ + --table-prefix access_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/access/database.hxx b/odb-examples/access/database.hxx new file mode 100644 index 0000000..2180735 --- /dev/null +++ b/odb-examples/access/database.hxx @@ -0,0 +1,95 @@ +// file : access/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/access/driver.cxx b/odb-examples/access/driver.cxx new file mode 100644 index 0000000..b477d6f --- /dev/null +++ b/odb-examples/access/driver.cxx @@ -0,0 +1,56 @@ +// file : access/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + { + person john ("john@doe.com", "John", "X", "Doe", 31); + person jane ("jane@doe.com", "Jane", "Y", "Doe", 29); + + transaction t (db->begin ()); + db->persist (john); + db->persist (jane); + t.commit (); + } + + { + typedef odb::result result; + + transaction t (db->begin ()); + result r (db->query ()); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << i->getFirst () << ' ' + << i->g_middle () << ' ' + << i->last () << ' ' + << i->email () << ' ' + << i->age () << endl; + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/access/person.hxx b/odb-examples/access/person.hxx new file mode 100644 index 0000000..a0e37ea --- /dev/null +++ b/odb-examples/access/person.hxx @@ -0,0 +1,125 @@ +// file : access/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include + +#include + +#pragma db object +class person +{ +public: + person () {} + person (const std::string& email, + const std::string& first, + const std::string& middle, + const std::string& last, + unsigned short age) + : email_ (email), first_ (first), middle_ (middle), last_ (last) + { + data_.age = age; + } + + // Standard accessor/modifier names. Auto-discovered by ODB. + // + const std::string& + email () const + { + return email_; + } + + void + email (const std::string& email) + { + email_ = email; + } + + // Get/set-style accessor/modifier names. Also auto-discovered + // by ODB. + // + const std::string& + getFirst () const + { + return first_; + } + + std::string& + setFirst () + { + return first_; + } + + // Unconventional accessor/modifier names which ODB is unable to + // auto-discover (but see also the --{accessor,modifier}-regex + // options). We have to specify these names explicitly (see below). + // + const std::string& + g_middle () const + { + return middle_; + } + + void + s_middle (const std::string& middle) + { + middle_ = middle; + } + + // Accessor/modifier types do not match data member type. Again, + // we have to specify accessor/modifier expressions that perform + // the necessary conversions (see below). + // + const char* + last () const + { + return last_.c_str (); + } + + void + last (const char* last) + { + last_ = last; + } + + // Accessor/modifier for a data member that is wrapped in an + // anonymous struct. We use a virtual data member to handle + // this case. + // + unsigned short + age () const + { + return data_.age; + } + + void + age (unsigned short age) + { + data_.age = age; + } + +private: + #pragma db id + std::string email_; // Accessor and modifier are auto-discovered. + + std::string first_; // Accessor and modifier are auto-discovered. + + #pragma db get(g_middle) set(s_middle) + std::string middle_; + + #pragma db get(std::string (this.last ())) set(last ((?).c_str ())) + std::string last_; + + #pragma db transient + struct + { + unsigned short age; + } data_; + + #pragma db member(age) virtual(unsigned short) // Accessor and modifier + // are auto-discovered. +}; + +#endif // PERSON_HXX diff --git a/odb-examples/access/testscript b/odb-examples/access/testscript new file mode 100644 index 0000000..33a0392 --- /dev/null +++ b/odb-examples/access/testscript @@ -0,0 +1,13 @@ +# file : access/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/boost/README b/odb-examples/boost/README new file mode 100644 index 0000000..64942bb --- /dev/null +++ b/odb-examples/boost/README @@ -0,0 +1,77 @@ +This example shows how to persist objects that use Boost smart pointers, +containers, and value types with the help of the Boost profile library +(libodb-boost). + +The example consists of the following files: + +employee.hxx + Header file defining the 'employee' and 'employer' persistent classes. + We use shared_ptr/weak_ptr smart pointers provided by Boost (as well + as their lazy versions provided by the Boost profile library) to + establish a bidirectional employee-employer relationship. We also use + the boost::gregorian::date type to store the employee's date of birth + and the boost::unordered_set container to keep track of the employee's + email addresses. The employee's object id is boost::uuids::uuid. Finally, + we use boost::optional for the optional middle name. If the middle name + is not present, it will be represented in the database as a NULL value. + +employee-odb.hxx +employee-odb.ixx +employee-odb.cxx +employee.sql + The first three files contain the database support code and the last file + contains the database schema for the employee.hxx header. + + These files are generated by the ODB compiler from employee.hxx using the + following command line: + + odb -d --profile boost --generate-schema --generate-query \ + --generate-session employee.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + + The -p option is used to instruct the ODB compiler to load the Boost + profile. The --generate-session option is used to enable session support + for all the persistent classes in employee.hxx. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the employee.hxx and employee-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then creates a number of 'employee' and 'employer' objects and + persists them in the database. The next transaction loads all the employees + of a particular employer using the employee-employer relationship. Finally, + the driver performs a few database queries which use data members of the + various Boost value types in their criterion. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c employee-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o employee-odb.o -lodb-boost -lodb-mysql -lodb \ +-lboost_date_time + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < employee.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/boost/database.hxx b/odb-examples/boost/database.hxx new file mode 100644 index 0000000..293f592 --- /dev/null +++ b/odb-examples/boost/database.hxx @@ -0,0 +1,94 @@ +// file : boost/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::auto_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::auto_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + auto_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + auto_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + auto_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + auto_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + auto_ptr db (new odb::mssql::database (argc, argv)); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/boost/driver.cxx b/odb-examples/boost/driver.cxx new file mode 100644 index 0000000..5a096f6 --- /dev/null +++ b/odb-examples/boost/driver.cxx @@ -0,0 +1,176 @@ +// file : boost/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::auto_ptr +#include + +#include + +#include +#include +#include + +#include "database.hxx" // create_database + +#include "employee.hxx" +#include "employee-odb.hxx" + +using namespace std; +using namespace boost::gregorian; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + using boost::shared_ptr; + + try + { + auto_ptr db (create_database (argc, argv)); + + // Create a few persistent objects. + // + { + // Simple Tech Ltd. + // + { + shared_ptr er (new employer ("Simple Tech Ltd")); + + shared_ptr john ( + new employee ("John", "Doe", date (1975, Jan, 1), er)); + + shared_ptr jane ( + new employee ("Jane", "Q", "Doe", date (1976, Feb, 2), er)); + + john->emails ().insert ("john_d@example.com"); + john->emails ().insert ("john.doe@example.com"); + jane->emails ().insert ("jane_d@example.com"); + jane->emails ().insert ("jane.doe@example.com"); + + // Set the inverse side of the employee-employer relationship. + // + er->employees ().push_back (john); + er->employees ().push_back (jane); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (john); + db->persist (jane); + + t.commit (); + } + + // Complex Systems Inc. + // + { + shared_ptr er (new employer ("Complex Systems Inc")); + + shared_ptr john ( + new employee ("John", "Z", "Smith", date (1977, Mar, 3), er)); + + shared_ptr jane ( + new employee ("Jane", "Smith", date (1978, Apr, 4), er)); + + john->emails ().insert ("john_s@example.com"); + john->emails ().insert ("john.smith@example.com"); + jane->emails ().insert ("jane_s@example.com"); + jane->emails ().insert ("jane.smith@example.com"); + + // Set the inverse side of the employee-employer relationship. + // + er->employees ().push_back (john); + er->employees ().push_back (jane); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (john); + db->persist (jane); + + t.commit (); + } + } + + + // Load Simple Tech Ltd and print its employees. + // + { + session s; + transaction t (db->begin ()); + + shared_ptr stl (db->load ("Simple Tech Ltd")); + + employees& es (stl->employees ()); + + for (employees::iterator i (es.begin ()); i != es.end (); ++i) + { + lazy_weak_ptr& lwp (*i); + shared_ptr p (lwp.load ()); // Load and lock. + + cout << p->first () << " "; + + if (p->middle ()) + cout << *p->middle () << " "; + + cout << p->last () << endl; + + cout << " born: " << p->born () << endl + << " employer: " << p->employer ()->name () << endl; + + for (emails::const_iterator j (p->emails ().begin ()); + j != p->emails ().end (); ++j) + { + cout << " email: " << *j << endl; + } + + cout << " id: {" << p->id () << '}' << endl + << endl; + } + + t.commit (); + } + + typedef odb::query query; + typedef odb::result result; + + // Search for Complex Systems Inc employees that were born before + // April 1978. + // + { + session s; + transaction t (db->begin ()); + + result r (db->query ( + query::employer->name == "Complex Systems Inc" && + query::born < date (1978, Apr, 1))); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << i->first () << " " << i->last () << " " << i->born () << endl; + + cout << endl; + t.commit (); + } + + // Search for all the employees that don't have a middle name. + // + { + session s; + transaction t (db->begin ()); + + result r (db->query (query::middle.is_null ())); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << i->first () << " " << i->last () << endl; + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/boost/employee.hxx b/odb-examples/boost/employee.hxx new file mode 100644 index 0000000..8d6173a --- /dev/null +++ b/odb-examples/boost/employee.hxx @@ -0,0 +1,196 @@ +// file : boost/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +using boost::shared_ptr; +using boost::weak_ptr; + +using odb::boost::lazy_shared_ptr; +using odb::boost::lazy_weak_ptr; + +using boost::uuids::uuid; +using boost::gregorian::date; + +// Forward declarations. +// +class employer; +class employee; + +typedef boost::unordered_set emails; +typedef std::vector > employees; + +#pragma db object +class employer +{ +public: + employer (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + + // Employees of this employer. + // + typedef ::employees employees_type; + + const employees_type& + employees () const + { + return employees_; + } + + employees_type& + employees () + { + return employees_; + } + +private: + friend class odb::access; + + employer () {} + + #pragma db id + std::string name_; + + #pragma db value_not_null inverse(employer_) + employees_type employees_; +}; + +#pragma db object +class employee +{ +public: + typedef ::employer employer_type; + + employee (const std::string& first, + const std::string& last, + const date& born, + shared_ptr employer) + : id_ (boost::uuids::random_generator () ()), + first_ (first), last_ (last), + born_ (born), + employer_ (employer) + { + } + + employee (const std::string& first, + const std::string& middle, + const std::string& last, + const date& born, + shared_ptr employer) + : id_ (boost::uuids::random_generator () ()), + first_ (first), middle_ (middle), last_ (last), + born_ (born), + employer_ (employer) + { + } + + // Id. + // + const uuid& + id () const + { + return id_; + } + + // Name. + // + const std::string& + first () const + { + return first_; + } + + const boost::optional& + middle () const + { + return middle_; + } + + const std::string& + last () const + { + return last_; + } + + // Date of birth. + // + const date& + born () const + { + return born_; + } + + // Emails. + // + typedef ::emails emails_type; + + const emails_type& + emails () const + { + return emails_; + } + + emails_type& + emails () + { + return emails_; + } + + // Employer. + // + shared_ptr + employer () const + { + return employer_; + } + + void + employer (shared_ptr employer) + { + employer_ = employer; + } + +private: + friend class odb::access; + + employee () {} + + #pragma db id + uuid id_; + + std::string first_; + boost::optional middle_; + std::string last_; + + date born_; + emails_type emails_; + + #pragma db not_null + shared_ptr employer_; +}; + +#endif // EMPLOYEE_HXX diff --git a/odb-examples/build/.gitignore b/odb-examples/build/.gitignore new file mode 100644 index 0000000..4a730a3 --- /dev/null +++ b/odb-examples/build/.gitignore @@ -0,0 +1,3 @@ +config.build +root/ +bootstrap/ diff --git a/odb-examples/build/bootstrap.build b/odb-examples/build/bootstrap.build new file mode 100644 index 0000000..0425a89 --- /dev/null +++ b/odb-examples/build/bootstrap.build @@ -0,0 +1,9 @@ +# file : build/bootstrap.build +# license : GNU GPL v2; see accompanying LICENSE file + +project = odb-examples + +using version +using config +using dist +using test diff --git a/odb-examples/build/root.build b/odb-examples/build/root.build new file mode 100644 index 0000000..ef6df52 --- /dev/null +++ b/odb-examples/build/root.build @@ -0,0 +1,274 @@ +# file : build/root.build +# license : GNU GPL v2; see accompanying LICENSE file + +cxx.std = latest + +using cxx + +hxx{*}: extension = hxx +ixx{*}: extension = ixx +txx{*}: extension = txx +cxx{*}: extension = cxx + +define sql: file +sql{*}: extension = sql + +define xml: file +xml{*}: extension = xml + +skeleton = ($build.mode == 'skeleton') + +# The identifier of the database to compile and run the examples against. The +# valid identifiers are mysql, sqlite, pgsql, oracle, and mssql. +# +# Note: can be specified by the user but is also conditionally reflected by +# the libodb-* libraries' examples manifest values. +# +config [string] config.odb_examples.database + +database = [string] ($defined(config.odb_examples.database) \ + ? $config.odb_examples.database \ + : '') + +mysql = false +sqlite = false +pgsql = false +oracle = false +mssql = false + +switch $database +{ + case 'mysql' + mysql = true + + case 'sqlite' + sqlite = true + + case 'pgsql' + pgsql = true + + case 'oracle' + oracle = true + + case 'mssql' + mssql = true + + case '' + assert ($skeleton) \ + 'database must be configured via config.odb_examples.database variable' + + default + fail "invalid database '$database' specified in config.odb_examples.database value" +} + +# If true, then this package is enabled as external examples for libodb +# library (see libodb's manifest for details). +# +# Note that this variable is not used in this package itself. +# +config [bool] config.odb_examples.libodb_example ?= false + +# Database connections. +# + +# MySQL +# +# The database user. +# +config [string] config.odb_examples.mysql.user ?= 'odb_test' + +# The database password. +# +config [string] config.odb_examples.mysql.passwd + +# The database name. Note that it WILL BE MODIFIED by the examples. +# +config [string] config.odb_examples.mysql.database ?= 'odb_test' + +# The database host. +# +config [string] config.odb_examples.mysql.host + +# The database port. +# +config [uint64] config.odb_examples.mysql.port + +# The database socket path. +# +config [path] config.odb_examples.mysql.socket + +# PostgreSQL +# +# The database user. Note that the named user must be allowed to connect to +# the database server without specifying credentials. +# +config [string] config.odb_examples.pgsql.user ?= 'odb_test' + +# The database name. Note that it WILL BE MODIFIED by the examples. +# +config [string] config.odb_examples.pgsql.database ?= 'odb_test' + +# The database host or directory of Unix-domain socket. Leaving this variable +# undefined results in using Unix-domain sockets. Machines without Unix-domain +# sockets will connect to localhost. +# +config [string] config.odb_examples.pgsql.host + +# The database port or the socket file name extension for Unix-domain +# connections. +# +# For example, specifying: +# +# config.odb_examples.pgsql.host=/var/run/postgresql +# config.odb_examples.pgsql.port=5433 +# +# Will result in the /var/run/postgresql/.s.PGSQL.5433 socket being used. +# +config [string] config.odb_examples.pgsql.port + +# Oracle +# +# The database user. +# +config [string] config.odb_examples.oracle.user ?= 'odb_test' + +# The database password. +# +config [string] config.odb_examples.oracle.passwd + +# The database host. +# +config [string] config.odb_examples.oracle.host + +# The database port. +# +config [uint64] config.odb_examples.oracle.port + +# The service name. Note that the database associated with this user on this +# service WILL BE MODIFIED by the examples. +# +config [string] config.odb_examples.oracle.service + +# Microsoft SQL Server +# +# The database user. +# +config [string] config.odb_examples.mssql.user ?= 'odb_test' + +# The database password. +# +config [string] config.odb_examples.mssql.passwd + +# The database name. Note that it WILL BE MODIFIED by the examples. +# +config [string] config.odb_examples.mssql.database ?= 'odb_test' + +# The database host. +# +config [string] config.odb_examples.mssql.host + +# The database port. +# +config [uint64] config.odb_examples.mssql.port + +# The SQL Server instance address. +# +# Note: mutually exclusive with config.odb_examples.mssql.{host,port}. +# +config [string] config.odb_examples.mssql.server + +assert (!$defined(config.odb_examples.mssql.server) || \ + !$defined(config.odb_examples.mssql.host)) \ + 'variables config.odb_examples.mssql.server and config.odb_examples.mssql.host cannot be specified both' + +assert (!$defined(config.odb_examples.mssql.server) || \ + !$defined(config.odb_examples.mssql.port)) \ + 'variables config.odb_examples.mssql.server and config.odb_examples.mssql.port cannot be specified both' + +# The SQL Server ODBC Driver. +# +config [string, null] config.odb_examples.mssql.driver + +if! $skeleton +{ + if ($cxx.target.system == 'win32-msvc') + cxx.poptions += -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS + + switch $cxx.class + { + case 'gcc' + { + cxx.coptions += -Wno-unknown-pragmas + } + case 'msvc' + { + cxx.coptions += /wd4068 /wd4251 /wd4275 /wd4800 + } + } + + # Import odb that we are using. + # + import! [metadata] odb = odb%exe{odb} + + # Import the mysql client for creating the database schemas, etc. + # + if $mysql + { + import! mysql_client = mysql-client%exe{mysql} + testscript{*}: mysql_client = $mysql_client + } + # + # Import the psql client for creating the database schemas, etc. + # + elif $pgsql + { + import! pgsql_client = psql%exe{psql} + testscript{*}: pgsql_client = $pgsql_client + } + # + # Import the sqlplus client for creating the database schemas, etc. + # + # Note: expected to be system-installed. + # + elif $oracle + { + import! oracle_client = sqlplus%exe{sqlplus} + testscript{*}: oracle_client = $oracle_client + } + # + # Import the sqlcmd client for creating the database schemas, etc. + # + # Note: expected to be system-installed. + # + elif $mssql + { + import! mssql_client = sqlcmd%exe{sqlcmd} + testscript{*}: mssql_client = $mssql_client + } + + # Every exe{} in this project is by default a test. + # + exe{*}: test = true + + # Specify the test target for cross-testing. + # + test.target = $cxx.target +} + +# The helper targets which can be used as prerequisites of test drivers which +# require either a specific database client or multiple clients for all the +# enabled databases. +# +alias{mysql-client}: $mysql_client: +{ + include = $mysql + clean = false +} + +alias{pgsql-client}: $pgsql_client: +{ + include = $pgsql + clean = false +} + +alias{database-client}: alias{mysql-client pgsql-client} diff --git a/odb-examples/buildfile b/odb-examples/buildfile new file mode 100644 index 0000000..91a47b6 --- /dev/null +++ b/odb-examples/buildfile @@ -0,0 +1,6 @@ +# file : buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +./: {*/ -build/ -boost/ -qt/} doc{README.md} legal{GPLv2 LICENSE} manifest + +./: testscript{*}: include = adhoc diff --git a/odb-examples/c++11/README b/odb-examples/c++11/README new file mode 100644 index 0000000..7db6a44 --- /dev/null +++ b/odb-examples/c++11/README @@ -0,0 +1,74 @@ +This example shows how to use ODB with C++11. In particular, this example +examines ODB support for the new std::unique_ptr and std::shared_ptr smart +pointers and their lazy variants as well as the unordered containers. It +also shows how to use new C++11 features such as the range-based for-loop +when working with persistent objects and handling query results. + +The example consists of the following files: + +employee.hxx + Header file defining the 'employee', 'employer', and 'pension_fund' + persistent classes. We use the standard std::shared_ptr/weak_ptr smart + pointers as well as their lazy versions provided by ODB to establish a + bidirectional employee-employer relationship. We also enable session + support for these two classes using the 'db session' pragma. Because + we don't share the 'pension_fund' objects, we use std::unique_ptr + as an object pointer for this persistent class. We also use the + std::unordered_set container to keep track of the employee's email + addresses. + +employee-odb.hxx +employee-odb.ixx +employee-odb.cxx +employee.sql + The first three files contain the database support code and the last file + contains the database schema for the employee.hxx header. + + These files are generated by the ODB compiler from employee.hxx using the + following command line: + + odb --std c++11 -d --std c++11 --generate-schema \ + --generate-query employee.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the employee.hxx and employee-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then creates a number of 'employee', 'employer', and + 'pension_fund' objects and persists them in the database. Then the driver + loads and prints some information about various objects and their + relationships. Finally, the driver performs a database query and iterates + over the result printing basic information about the returned objects. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++ -std=c++11' +with your C++ compiler in C++11 mode): + +c++ -c employee-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < employee.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/c++11/buildfile b/odb-examples/c++11/buildfile new file mode 100644 index 0000000..5287801 --- /dev/null +++ b/odb-examples/c++11/buildfile @@ -0,0 +1,44 @@ +# file : c++11/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{employee-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{employee-meta}: $libodb + +exe{driver}: libue{employee-meta} $libs + +<{hxx ixx cxx}{employee-odb}>: hxx{employee} libue{employee-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/employee.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --output-dir $out_base \ + --table-prefix cxx11_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = employee diff --git a/odb-examples/c++11/database.hxx b/odb-examples/c++11/database.hxx new file mode 100644 index 0000000..084f8cf --- /dev/null +++ b/odb-examples/c++11/database.hxx @@ -0,0 +1,95 @@ +// file : c++11/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/c++11/driver.cxx b/odb-examples/c++11/driver.cxx new file mode 100644 index 0000000..68793b1 --- /dev/null +++ b/odb-examples/c++11/driver.cxx @@ -0,0 +1,207 @@ +// file : c++11/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include +#include + +#include "database.hxx" // create_database + +#include "employee.hxx" +#include "employee-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Create a few persistent objects. + // + { + pension_fund bf ("Bright Future"); + + // Simple Tech Ltd. + // + { + shared_ptr er (new employer ("Simple Tech Ltd")); + + shared_ptr john (new employee ("John", "Doe", er)); + shared_ptr jane (new employee ("Jane", "Doe", er)); + + john->emails ().insert ("john_d@example.com"); + john->emails ().insert ("john.doe@example.com"); + + jane->emails ().insert ("jane_d@example.com"); + jane->emails ().insert ("jane.doe@example.com"); + + // Set the inverse side of the employee-employer relationship. + // + er->employees ().push_back (john); + er->employees ().push_back (jane); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (john); + db->persist (jane); + + t.commit (); + + bf.members ().push_back (lazy_shared_ptr (*db, john)); + } + + // Complex Systems Inc. + // + { + shared_ptr er (new employer ("Complex Systems Inc")); + + shared_ptr john (new employee ("John", "Smith", er)); + shared_ptr jane (new employee ("Jane", "Smith", er)); + + john->emails ().insert ("john_s@example.com"); + john->emails ().insert ("john.smith@example.com"); + + jane->emails ().insert ("jane_s@example.com"); + jane->emails ().insert ("jane.smith@example.com"); + + // Set the inverse side of the employee-employer relationship. + // + er->employees ().push_back (john); + er->employees ().push_back (jane); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (john); + db->persist (jane); + + t.commit (); + + bf.members ().push_back (lazy_shared_ptr (*db, jane)); + } + + transaction t (db->begin ()); + db->persist (bf); + t.commit (); + } + + // Load the Bright Future pension fund and print its members. + // + { + session s; + transaction t (db->begin ()); + + unique_ptr bf (db->load ("Bright Future")); + + for (auto i (bf->members ().begin ()); i != bf->members ().end (); ++i) + { + lazy_shared_ptr& p (*i); + p.load (); + + cout << p->first () << ' ' << p->last () << ", " << + p->employer ()->name () << endl; + } + + // Alternative implementation using range-based for-loop. + // + /* + for (lazy_shared_ptr& p: bf->members ()) + { + p.load (); + cout << p->first () << ' ' << p->last () << ", " << + p->employer ()->name () << endl; + } + */ + + cout << endl; + } + + // Load Simple Tech Ltd and print its employees. + // + { + session s; + transaction t (db->begin ()); + + shared_ptr st (db->load ("Simple Tech Ltd")); + + for (auto i (st->employees ().begin ()); + i != st->employees ().end (); + ++i) + { + lazy_weak_ptr& lwp (*i); + shared_ptr p (lwp.load ()); // Load and lock. + + cout << p->first () << ' ' << p->last () << endl + << " employer: " << p->employer ()->name () << endl; + + for (auto j (p->emails ().begin ()); j != p->emails ().end (); ++j) + { + cout << " email: " << *j << endl; + } + + cout << endl; + } + + // Alternative implementation using range-based for-loop. + // + /* + for (lazy_weak_ptr& lwp: st->employees ()) + { + shared_ptr p (lwp.load ()); // Load and lock. + + cout << p->first () << ' ' << p->last () << endl + << " employer: " << p->employer ()->name () << endl; + + for (const string& e: p->emails ()) + cout << " email: " << e << endl; + + cout << endl; + } + */ + + t.commit (); + } + + + // Search for Complex Systems Inc employees with the John first name. + // + { + typedef odb::query query; + typedef odb::result result; + + session s; + transaction t (db->begin ()); + + result r (db->query ( + query::employer->name == "Complex Systems Inc" && + query::first == "John")); + + for (auto i (r.begin ()); i != r.end (); ++i) + cout << i->first () << ' ' << i->last () << endl; + + // Alternative implementation using range-based for-loop. + // + /* + for (const employee& e: r) + cout << e.first () << ' ' << e.last () << endl; + */ + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/c++11/employee.hxx b/odb-examples/c++11/employee.hxx new file mode 100644 index 0000000..a921e31 --- /dev/null +++ b/odb-examples/c++11/employee.hxx @@ -0,0 +1,182 @@ +// file : c++11/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include +#include // std::unique_ptr, std::shared_ptr +#include +#include + +#include +#include // odb::lazy_shared_ptr, odb::lazy_weak_ptr + +// Forward declarations. +// +class employer; +class employee; + +#pragma db object pointer(std::shared_ptr) session +class employer +{ +public: + employer (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + + // Employees of this employer. + // + typedef std::vector> employees_type; + + const employees_type& + employees () const + { + return employees_; + } + + employees_type& + employees () + { + return employees_; + } + +private: + friend class odb::access; + + employer () {} + + #pragma db id + std::string name_; + + #pragma db value_not_null inverse(employer_) + employees_type employees_; +}; + +#pragma db object pointer(std::shared_ptr) session +class employee +{ +public: + typedef ::employer employer_type; + + employee (const std::string& first, + const std::string& last, + std::shared_ptr employer) + : first_ (first), last_ (last), employer_ (employer) + { + } + + // Name. + // + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + // Emails. + // + typedef std::unordered_set emails_type; + + const emails_type& + emails () const + { + return emails_; + } + + emails_type& + emails () + { + return emails_; + } + + // Employer. + // + std::shared_ptr + employer () const + { + return employer_; + } + + void + employer (std::shared_ptr employer) + { + employer_ = employer; + } + +private: + friend class odb::access; + + employee () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + emails_type emails_; + + #pragma db not_null + std::shared_ptr employer_; +}; + +// std::unique_ptr is a good choice for an object pointer if we are +// not planning to do any sharing. +// +#pragma db object pointer(std::unique_ptr) +class pension_fund +{ +public: + pension_fund (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + + // Members of this fund. + // + typedef std::vector> members_type; + + const members_type& + members () const + { + return members_; + } + + members_type& + members () + { + return members_; + } + +private: + friend class odb::access; + + pension_fund () {} + + #pragma db id + std::string name_; + + #pragma db value_not_null + members_type members_; +}; + +#endif // EMPLOYEE_HXX diff --git a/odb-examples/c++11/testscript b/odb-examples/c++11/testscript new file mode 100644 index 0000000..cb942f6 --- /dev/null +++ b/odb-examples/c++11/testscript @@ -0,0 +1,13 @@ +# file : cxx11/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/composite/README b/odb-examples/composite/README new file mode 100644 index 0000000..c6228a3 --- /dev/null +++ b/odb-examples/composite/README @@ -0,0 +1,69 @@ +This example shows how to use composite value types as data members in objects +(including as object id members) and other value types, as element types in +containers, and as base types for other composite value types. It also shows +how to use composite value type data members in queries. + +The example consists of the following files: + +person.hxx + Header file defining the 'basic_name', 'name_extras', 'name', and + 'email_address' composite value types. It also defines the 'phone_numbers' + composite value type as an instantiation of the 'std::pair' class template + Finally it defines the 'person' persistent class which uses 'email_address' + as its object id as well as 'name' and 'phone_numbers' in its other data + members. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-schema --generate-query person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then persists a 'person' object, loads it and updates its + nickname and aliases which reside in a composite value type, then re-loads + the object and prints its name to verify that the changes have been made + persistent. Finally, the driver performs a database query which uses a + data member from the composite value type in its criterion. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/composite/buildfile b/odb-examples/composite/buildfile new file mode 100644 index 0000000..5eb45ad --- /dev/null +++ b/odb-examples/composite/buildfile @@ -0,0 +1,44 @@ +# file : composite/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --output-dir $out_base \ + --table-prefix c_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/composite/database.hxx b/odb-examples/composite/database.hxx new file mode 100644 index 0000000..4520c32 --- /dev/null +++ b/odb-examples/composite/database.hxx @@ -0,0 +1,95 @@ +// file : composite/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/composite/driver.cxx b/odb-examples/composite/driver.cxx new file mode 100644 index 0000000..5cac553 --- /dev/null +++ b/odb-examples/composite/driver.cxx @@ -0,0 +1,108 @@ +// file : composite/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Create a person object. + // + email_address id; + { + person p ("joe@example.com", + "Joe", + "Dirt", + "Mr", + phone_numbers ("555 5555", "666 6666")); + + transaction t (db->begin ()); + id = db->persist (p); + t.commit (); + } + + // Update the extra name information. + // + { + transaction t (db->begin ()); + + unique_ptr joe (db->load (id)); + name_extras& ne (joe->name ().extras ()); + ne.nickname ("Squeaky"); + ne.aliases ().push_back (basic_name ("Anthony", "Clean")); + + db->update (*joe); + + t.commit (); + } + + // Print the name and phone numbers. + // + { + transaction t (db->begin ()); + unique_ptr joe (db->load (id)); + t.commit (); + + name& n (joe->name ()); + + cout << n.title () << " " << n.first () << " " << n.last () << " " + << '<' << joe->email ().address () << '>' << endl; + + name_extras& ne (n.extras ()); + + if (!ne.nickname ().empty ()) + cout << " nickname: " << ne.nickname () << endl; + + for (basic_names::iterator i (ne.aliases ().begin ()); + i != ne.aliases ().end (); + ++i) + { + cout << " alias: " << i->first () << " " << i->last () << endl; + } + + cout << " phone 1: " << joe->phone ().first << endl; + cout << " phone 2: " << joe->phone ().second << endl; + } + + // Query the database for a person object. + // + { + typedef odb::query query; + + transaction t (db->begin ()); + + unique_ptr p ( + db->query_one ( + query::name.extras.nickname == "Squeaky")); + + if (p.get () != 0) + { + name& n (p->name ()); + cout << n.title () << " " << n.first () << " " << n.last () << endl; + } + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/composite/person.hxx b/odb-examples/composite/person.hxx new file mode 100644 index 0000000..f0626e5 --- /dev/null +++ b/odb-examples/composite/person.hxx @@ -0,0 +1,228 @@ +// file : composite/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include +#include + +#include + +#pragma db value +class basic_name +{ +public: + basic_name (const std::string& first, const std::string& last) + : first_ (first), last_ (last) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + +private: + friend class odb::access; + + basic_name () {} // Needed for storing basic_name in containers. + + std::string first_; + std::string last_; +}; + +typedef std::vector basic_names; + + +#pragma db value +class name_extras +{ +public: + // Nickname. + // + const std::string& + nickname () const + { + return nickname_; + } + + void + nickname (const std::string& nickname) + { + nickname_ = nickname; + } + + // Aliases. + // + const basic_names& + aliases () const + { + return aliases_; + } + + basic_names& + aliases () + { + return aliases_; + } + +private: + friend class odb::access; + + std::string nickname_; + basic_names aliases_; +}; + + +#pragma db value +class name: public basic_name +{ +public: + name (const std::string& first, + const std::string& last, + const std::string& title) + : basic_name (first, last), title_ (title) + { + } + + // Title. + // + const std::string& + title () const + { + return title_; + } + + // Extras. + // + const name_extras& + extras () const + { + return extras_; + } + + name_extras& + extras () + { + return extras_; + } + +private: + friend class odb::access; + + std::string title_; + name_extras extras_; +}; + +// We can also define a composite value type as a class template +// instantiation. Here we use std::pair to store person's phone +// numbers, in the order of preference. +// +typedef std::pair phone_numbers; +#pragma db value(phone_numbers) + +// We can also use a composite value type as an object id. +// +#pragma db value +class email_address +{ +public: + email_address () {} + email_address (const std::string& address) + { + std::string::size_type p (address.find ('@')); + recipient_.assign (address, 0, p); + domain_.assign (address, p + 1, std::string::npos); + } + + const std::string& + recipient () const + { + return recipient_; + } + + const std::string& + domain () const + { + return domain_; + } + + std::string + address () const + { + return recipient_ + '@' + domain_; + } + +private: + friend class odb::access; + + std::string recipient_; + std::string domain_; +}; + +#pragma db object +class person +{ +public: + person (const std::string& email, + const std::string& first, + const std::string& last, + const std::string& title, + const phone_numbers& phone) + : email_ (email), name_ (first, last, title), phone_ (phone) + { + } + + // Email address. + // + const email_address& + email () const + { + return email_; + } + + // Name. + // + typedef ::name name_type; + + const name_type& + name () const + { + return name_; + } + + name_type& + name () + { + return name_; + } + + // Phone. + // + const phone_numbers& + phone () const + { + return phone_; + } + +private: + friend class odb::access; + + person (): name_ ("", "", "") {} + + #pragma db id + email_address email_; + + name_type name_; + phone_numbers phone_; +}; + +#endif // PERSON_HXX diff --git a/odb-examples/composite/testscript b/odb-examples/composite/testscript new file mode 100644 index 0000000..d66ce0f --- /dev/null +++ b/odb-examples/composite/testscript @@ -0,0 +1,13 @@ +# file : composite/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/container/README b/odb-examples/container/README new file mode 100644 index 0000000..87f9bc6 --- /dev/null +++ b/odb-examples/container/README @@ -0,0 +1,62 @@ +This example shows how to use containers as data members in persistent objects. + +The example consists of the following files: + +person.hxx + Header file defining the 'person' persistent class. It contains a number of + data members of various container types. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-schema person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then persists a 'person' object, loads it back, and prints the + contents of its members. Finally, the driver modifies the object by adding, + removing, and updating elements in its container members, stores the changes + in the database, then re-loads and prints the object to verify that the + changes have been made persistent. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/container/buildfile b/odb-examples/container/buildfile new file mode 100644 index 0000000..c850acc --- /dev/null +++ b/odb-examples/container/buildfile @@ -0,0 +1,43 @@ +# file : container/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --output-dir $out_base \ + --table-prefix container_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/container/database.hxx b/odb-examples/container/database.hxx new file mode 100644 index 0000000..3d23d86 --- /dev/null +++ b/odb-examples/container/database.hxx @@ -0,0 +1,95 @@ +// file : container/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/container/driver.cxx b/odb-examples/container/driver.cxx new file mode 100644 index 0000000..b3d50c6 --- /dev/null +++ b/odb-examples/container/driver.cxx @@ -0,0 +1,119 @@ +// file : container/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +void +print (const person& p) +{ + cout << p.first () << " " << p.last () << endl; + + // Print nicknames. + // + for (names::const_iterator i (p.nicknames ().begin ()); + i != p.nicknames ().end (); ++i) + { + cout << " nickname: " << *i << endl; + } + + // Print emails. + // + for (emails::const_iterator i (p.emails ().begin ()); + i != p.emails ().end (); ++i) + { + cout << " email: " << *i << endl; + } + + // Print weights. + // + for (age_weight_map::const_iterator i (p.age_weight ().begin ()); + i != p.age_weight ().end (); ++i) + { + cout << " weight at " << i->first << ": " << i->second << endl; + } +} + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + unsigned long id; + + // Create a persistent person object. + // + { + person joe ("Joe", "Dirt"); + + joe.nicknames ().push_back ("JD"); + joe.nicknames ().push_back ("Squeaky"); + + joe.emails ().insert ("joe@example.com"); + joe.emails ().insert ("joe.dirt@example.com"); + + joe.age_weight ()[5] = 15.6F; + joe.age_weight ()[10] = 23.3F; + joe.age_weight ()[15] = 29.8F; + + transaction t (db->begin ()); + id = db->persist (joe); + t.commit (); + } + + // Load the object and print what we've got. Then change some + // information and update it in the database. + // + { + transaction t1 (db->begin ()); + unique_ptr j (db->load (id)); + t1.commit (); + + print (*j); + + // Ann another nickname. + // + j->nicknames ().push_back ("Cleaner"); + + // The joe@example.com email is no longer working. + // + j->emails ().erase ("joe@example.com"); + + // Update a weight sample. + // + j->age_weight ()[15] = 28.8F; + + transaction t2 (db->begin ()); + db->update (*j); + t2.commit (); + } + + // Load and print the updated object. + // + { + transaction t (db->begin ()); + unique_ptr j (db->load (id)); + t.commit (); + + print (*j); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/container/person.hxx b/odb-examples/container/person.hxx new file mode 100644 index 0000000..31b90a5 --- /dev/null +++ b/odb-examples/container/person.hxx @@ -0,0 +1,99 @@ +// file : container/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include +#include +#include +#include + +#include + +typedef std::vector names; +typedef std::set emails; +typedef std::map age_weight_map; + +#pragma db object +class person +{ +public: + person (const std::string& first, const std::string& last) + : first_ (first), last_ (last) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + // Nicknames. + // + const names& + nicknames () const + { + return nicknames_; + } + + names& + nicknames () + { + return nicknames_; + } + + // Emails. + // + typedef ::emails emails_type; + + const emails_type& + emails () const + { + return emails_; + } + + emails_type& + emails () + { + return emails_; + } + + // Age-to-weight map. + // + const age_weight_map& + age_weight () const + { + return age_weight_; + } + + age_weight_map& + age_weight () + { + return age_weight_; + } + +private: + friend class odb::access; + + person () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + + names nicknames_; + emails_type emails_; + age_weight_map age_weight_; +}; + +#endif // PERSON_HXX diff --git a/odb-examples/container/testscript b/odb-examples/container/testscript new file mode 100644 index 0000000..3068677 --- /dev/null +++ b/odb-examples/container/testscript @@ -0,0 +1,13 @@ +# file : container/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/database-options.testscript b/odb-examples/database-options.testscript new file mode 100644 index 0000000..db93b45 --- /dev/null +++ b/odb-examples/database-options.testscript @@ -0,0 +1,148 @@ +# file : database-options.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# For the enabled databases create the example driver option lists (*_options) +# for subsequent use in the examples. Also create the database-specific client +# option lists (*_client_options) and command lines (*_client_cmd) which can +# be used as a base for the data manipulation commands. +# ++if $mysql + mysql_options = --user $config.odb_examples.mysql.user \ + --database $config.odb_examples.mysql.database + + mysql_client_options = --user $config.odb_examples.mysql.user \ + --database $config.odb_examples.mysql.database + + if $defined(config.odb_examples.mysql.passwd) + mysql_options += --password $config.odb_examples.mysql.passwd + mysql_client_options += --password=$config.odb_examples.mysql.passwd + end + + if $defined(config.odb_examples.mysql.host) + mysql_options += --host $config.odb_examples.mysql.host + mysql_client_options += --host $config.odb_examples.mysql.host + end + + if $defined(config.odb_examples.mysql.port) + mysql_options += --port $config.odb_examples.mysql.port + mysql_client_options += --port $config.odb_examples.mysql.port + end + + if $defined(config.odb_examples.mysql.socket) + mysql_options += --socket $config.odb_examples.mysql.socket + mysql_client_options += --socket $config.odb_examples.mysql.socket + end + + mysql_client_cmd = $path($mysql_client) $mysql_client_options +end + ++if $sqlite + sqlite_options = --database odb-test.db + + # Note that we currently don't manipulate the data using the sqlite3 + # utility. Thus, we don't create the sqlite client option list and command + # line. + # +end + ++if $pgsql + pgsql_options = --user $config.odb_examples.pgsql.user \ + --database $config.odb_examples.pgsql.database + + pgsql_client_options = --quiet \ + --set ON_ERROR_STOP=1 \ + --username $config.odb_examples.pgsql.user \ + --dbname $config.odb_examples.pgsql.database + + if $defined(config.odb_examples.pgsql.host) + pgsql_options += --host $config.odb_examples.pgsql.host + pgsql_client_options += --host $config.odb_examples.pgsql.host + end + + if $defined(config.odb_examples.pgsql.port) + pgsql_options += --port $config.odb_examples.pgsql.port + pgsql_client_options += --port $config.odb_examples.pgsql.port + end + + pgsql_client_cmd = $path($pgsql_client) $pgsql_client_options + + export PGOPTIONS=--client-min-messages=warning +end + ++if $oracle + oracle_options = --user $config.odb_examples.oracle.user + + oracle_client_options = -L -S + oracle_logon = $config.odb_examples.oracle.user + + if $defined(config.odb_examples.oracle.passwd) + oracle_options += --password $config.odb_examples.oracle.passwd + oracle_logon = "$oracle_logon/$config.odb_examples.oracle.passwd" + end + + if ($defined(config.odb_examples.oracle.host) || \ + $defined(config.odb_examples.oracle.port)) + if $defined(config.odb_examples.oracle.host) + oracle_options += --host $config.odb_examples.oracle.host + oracle_logon = "$oracle_logon@//$config.odb_examples.oracle.host" + else + oracle_logon = "$oracle_logon@//localhost" + end + + if $defined(config.odb_examples.oracle.port) + oracle_options += --port $config.odb_examples.oracle.port + oracle_logon = "$oracle_logon:$config.odb_examples.oracle.port" + end + + if $defined(config.odb_examples.oracle.service) + oracle_options += --service $config.odb_examples.oracle.service + oracle_logon = "$oracle_logon/$config.odb_examples.oracle.service" + end + elif $defined(config.odb_examples.oracle.service) + oracle_options += --service $config.odb_examples.oracle.service + oracle_logon = "$oracle_logon@$config.odb_examples.oracle.service" + end + + oracle_client_cmd = $path($oracle_client) $oracle_client_options $oracle_logon +end + ++if $mssql + mssql_options = --user $config.odb_examples.mssql.user \ + --database $config.odb_examples.mssql.database + + mssql_client_options = -C -x -r 1 -b \ + -U $config.odb_examples.mssql.user \ + -d $config.odb_examples.mssql.database + + if $defined(config.odb_examples.mssql.passwd) + mssql_options += --password $config.odb_examples.mssql.passwd + mssql_client_options += -P $config.odb_examples.mssql.passwd + end + + if ($defined(config.odb_examples.mssql.host) || \ + $defined(config.odb_examples.mssql.port)) + mssql_server = \ + "tcp:($defined(config.odb_examples.mssql.host) ? $config.odb_examples.mssql.host : localhost)" + + if $defined(config.odb_examples.mssql.port) + mssql_server = "$mssql_server,$config.odb_examples.mssql.port" + end + elif $defined(config.odb_examples.mssql.server) + mssql_server = $config.odb_examples.mssql.server + else + mssql_server = [null] + end + + if ($mssql_server != [null]) + mssql_options += --server $mssql_server + mssql_client_options += -S $mssql_server + end + + if ($defined(config.odb_examples.mssql.driver) && \ + $config.odb_examples.mssql.driver != [null] && \ + $config.odb_examples.mssql.driver != '') + mssql_options += --driver $config.odb_examples.mssql.driver + end + + mssql_client_cmd = $path($mssql_client) $mssql_client_options +end diff --git a/odb-examples/hello/README b/odb-examples/hello/README new file mode 100644 index 0000000..61c71b7 --- /dev/null +++ b/odb-examples/hello/README @@ -0,0 +1,63 @@ +This is a "Hello World" example that shows how to use ODB to perform basic +database operations, such as making objects persistent, loading, updating +and deleting persistent objects, as well as querying the database for +objects matching a certain criteria. It also includes an example of a +simple view. + +The example consists of the following files: + +person.hxx + Header file defining the 'person' persistent class as well as the + 'person_stat' view. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-query --generate-schema person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. Then it executes a number of database transactions on persistent + objects. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/hello/buildfile b/odb-examples/hello/buildfile new file mode 100644 index 0000000..db76837 --- /dev/null +++ b/odb-examples/hello/buildfile @@ -0,0 +1,44 @@ +# file : hello/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --output-dir $out_base \ + --table-prefix hello_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/hello/database.hxx b/odb-examples/hello/database.hxx new file mode 100644 index 0000000..cdfc033 --- /dev/null +++ b/odb-examples/hello/database.hxx @@ -0,0 +1,95 @@ +// file : hello/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/hello/driver.cxx b/odb-examples/hello/driver.cxx new file mode 100644 index 0000000..175ced1 --- /dev/null +++ b/odb-examples/hello/driver.cxx @@ -0,0 +1,130 @@ +// file : hello/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + unsigned long john_id, joe_id; + + // Create a few persistent person objects. + // + { + person john ("John", "Doe", 33); + person jane ("Jane", "Doe", 32); + person joe ("Joe", "Dirt", 30); + + transaction t (db->begin ()); + + // Make objects persistent and save their ids for later use. + // + john_id = db->persist (john); + db->persist (jane); + joe_id = db->persist (joe); + + t.commit (); + } + + typedef odb::query query; + typedef odb::result result; + + // Say hello to those over 30. + // + { + transaction t (db->begin ()); + + result r (db->query (query::age > 30)); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + cout << "Hello, " << i->first () << " " << i->last () << "!" << endl; + } + + t.commit (); + } + + // Joe Dirt just had a birthday, so update his age. + // + { + transaction t (db->begin ()); + + unique_ptr joe (db->load (joe_id)); + joe->age (joe->age () + 1); + db->update (*joe); + + t.commit (); + } + + // Alternative implementation without using the id. + // + /* + { + transaction t (db->begin ()); + + // Here we know that there can be only one Joe Dirt in our + // database so we use the query_one() shortcut instead of + // manually iterating over the result returned by query(). + // + unique_ptr joe ( + db->query_one (query::first == "Joe" && + query::last == "Dirt")); + + if (joe.get () != 0) + { + joe->age (joe->age () + 1); + db->update (*joe); + } + + t.commit (); + } + */ + + // Print some statistics about all the people in our database. + // + { + transaction t (db->begin ()); + + // The result of this (aggregate) query always has exactly one element + // so use the query_value() shortcut. + // + person_stat ps (db->query_value ()); + + cout << endl + << "count : " << ps.count << endl + << "min age: " << ps.min_age << endl + << "max age: " << ps.max_age << endl; + + t.commit (); + } + + // John Doe is no longer in our database. + // + { + transaction t (db->begin ()); + db->erase (john_id); + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/hello/person.hxx b/odb-examples/hello/person.hxx new file mode 100644 index 0000000..81a9321 --- /dev/null +++ b/odb-examples/hello/person.hxx @@ -0,0 +1,73 @@ +// file : hello/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include +#include // std::size_t + +#include + +#pragma db object +class person +{ +public: + person (const std::string& first, + const std::string& last, + unsigned short age) + : first_ (first), last_ (last), age_ (age) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + unsigned short + age () const + { + return age_; + } + + void + age (unsigned short age) + { + age_ = age; + } + +private: + friend class odb::access; + + person () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + unsigned short age_; +}; + +#pragma db view object(person) +struct person_stat +{ + #pragma db column("count(" + person::id_ + ")") + std::size_t count; + + #pragma db column("min(" + person::age_ + ")") + unsigned short min_age; + + #pragma db column("max(" + person::age_ + ")") + unsigned short max_age; +}; + +#endif // PERSON_HXX diff --git a/odb-examples/hello/testscript b/odb-examples/hello/testscript new file mode 100644 index 0000000..2d72ba5 --- /dev/null +++ b/odb-examples/hello/testscript @@ -0,0 +1,13 @@ +# file : hello/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/inheritance/polymorphism/README b/odb-examples/inheritance/polymorphism/README new file mode 100644 index 0000000..15a8543 --- /dev/null +++ b/odb-examples/inheritance/polymorphism/README @@ -0,0 +1,78 @@ +This example shows how to use polymorphism inheritance with ODB. This +inheritance style is normally used to provide polymorphic behavior through +a common interface. The base class defines a number of virtual functions and, +normally, a virtual destructor while the derived classes provide specific +implementations of these virtual functions. + +The other commonly used inheritance style is reuse inheritance. Refer to the +inheritance/reuse example for more information on this style. + +The example consists of the following files: + +employee.hxx +employee.cxx + Header and source files defining the 'person' abstract polymorphic + persistent class as well as the 'employee' and 'contractor' concrete + persistent classes. + +employee-odb.hxx +employee-odb.ixx +employee-odb.cxx +employee.sql + The first three files contain the database support code and the last file + contains the database schema for the employee.hxx header. + + These files are generated by the ODB compiler from employee.hxx using the + following command line: + + odb --std c++11 -d --generate-schema --generate-query employee.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the employee.hxx and employee-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then persists a number of employee and contractor objects + via their common base (person). The next transaction loads these objects, + also via their common base. Once loaded, the driver calls the print() + virtual function on each of them. Next, the driver changes an employee + from temporary to permanent and updates its state in the database, again + using the base class interface. The driver then queries the database for + all the person objects that have Doe as the last name. The result set of + this query contains a mix of employee and contractor objects. The driver + iterates over this result set and calls the print() virtual function for + each object. Finally, the driver erases the state of the persistent + objects from the database, again using the base class interface. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c employee.cxx +c++ -c employee-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o employee.o employee-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < employee.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/inheritance/polymorphism/buildfile b/odb-examples/inheritance/polymorphism/buildfile new file mode 100644 index 0000000..a501043 --- /dev/null +++ b/odb-examples/inheritance/polymorphism/buildfile @@ -0,0 +1,44 @@ +# file : inheritance/polymorphism/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{employee-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{employee-meta}: $libodb + +exe{driver}: libue{employee-meta} $libs + +<{hxx ixx cxx}{employee-odb}>: hxx{employee} libue{employee-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/employee.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --output-dir $out_base \ + --table-prefix inh_poly_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../../alias{database-client}: include = adhoc + +testscript@./: schema = employee diff --git a/odb-examples/inheritance/polymorphism/database.hxx b/odb-examples/inheritance/polymorphism/database.hxx new file mode 100644 index 0000000..7b415b7 --- /dev/null +++ b/odb-examples/inheritance/polymorphism/database.hxx @@ -0,0 +1,95 @@ +// file : inheritance/polymorphism/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/inheritance/polymorphism/driver.cxx b/odb-examples/inheritance/polymorphism/driver.cxx new file mode 100644 index 0000000..8d24e81 --- /dev/null +++ b/odb-examples/inheritance/polymorphism/driver.cxx @@ -0,0 +1,102 @@ +// file : inheritance/polymorphism/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "employee.hxx" +#include "employee-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + unsigned long id1, id2; + + // Add a few employee and contractor objects to the database. + // + { + unique_ptr p1 (new employee ("John", "Doe", true)); + unique_ptr p2 (new contractor ("Jane", "Doe", "jane@doe.com")); + + transaction t (db->begin ()); + id1 = db->persist (*p1); // Stores employee. + id2 = db->persist (*p2); // Stores contractor. + t.commit (); + } + + // Load polymorphic objects given their object ids. + // + { + transaction t (db->begin ()); + unique_ptr p1 (db->load (id1)); // Loads employee. + unique_ptr p2 (db->load (id2)); // Loads contractor. + t.commit (); + + p1->print (); + p2->print (); + } + + // Make John Doe a permanent employee. + // + { + transaction t (db->begin ()); + + unique_ptr e (db->load (id1)); + e->temporary (false); + person& p (*e); + db->update (p); // Updates employee. + + t.commit (); + } + + // Query all the person objects that have Doe as the last name. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + + result r (db->query (query::last == "Doe")); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + // We can check the discriminator before loading the object. + // + string d (i.discriminator ()); + cout << "discriminator: " << d << endl; + + i->print (); // Can be employee or contractor. + } + + t.commit (); + } + + // Erase the objects from the database. + // + { + transaction t (db->begin ()); + unique_ptr p (db->load (id1)); // Loads employee. + db->erase (*p); // Erases employee. + db->erase (id2); // Erases contractor. + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/inheritance/polymorphism/employee.cxx b/odb-examples/inheritance/polymorphism/employee.cxx new file mode 100644 index 0000000..83a51e6 --- /dev/null +++ b/odb-examples/inheritance/polymorphism/employee.cxx @@ -0,0 +1,27 @@ +// file : inheritance/polymorphism/employee.cxx +// copyright : not copyrighted - public domain + +#include + +#include "employee.hxx" + +using namespace std; + +person:: +~person () +{ +} + +void employee:: +print () +{ + cout << first_ << ' ' << last_ + << (temporary_ ? " temporary " : " permanent ") + << "employee" << endl; +} + +void contractor:: +print () +{ + cout << first_ << ' ' << last_ << ' ' << email_ << " contractor" << endl; +} diff --git a/odb-examples/inheritance/polymorphism/employee.hxx b/odb-examples/inheritance/polymorphism/employee.hxx new file mode 100644 index 0000000..efb2c1c --- /dev/null +++ b/odb-examples/inheritance/polymorphism/employee.hxx @@ -0,0 +1,109 @@ +// file : inheritance/polymorphism/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include + +#include + +#pragma db object polymorphic +class person +{ +public: + person (const std::string& first, const std::string& last) + : first_ (first), last_ (last) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + virtual + ~person () = 0; + + virtual void + print () = 0; + +protected: + friend class odb::access; + person () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; +}; + +#pragma db object +class employee: public person +{ +public: + employee (const std::string& first, + const std::string& last, + bool temporary) + : person (first, last), temporary_ (temporary) + { + } + + bool + temporary () const + { + return temporary_; + } + + void + temporary (bool t) + { + temporary_ = t; + } + + virtual void + print (); + +private: + friend class odb::access; + employee () {} + + bool temporary_; +}; + +#pragma db object +class contractor: public person +{ +public: + contractor (const std::string& first, + const std::string& last, + const std::string& email) + : person (first, last), email_ (email) + { + } + + const std::string& + email () const + { + return email_; + } + + virtual void + print (); + +private: + friend class odb::access; + contractor () {} + + std::string email_; +}; + +#endif // EMPLOYEE_HXX diff --git a/odb-examples/inheritance/polymorphism/testscript b/odb-examples/inheritance/polymorphism/testscript new file mode 100644 index 0000000..5c7bdcd --- /dev/null +++ b/odb-examples/inheritance/polymorphism/testscript @@ -0,0 +1,13 @@ +# file : inheritance/polymorphism/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../../database-options.testscript +.include ../../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/inheritance/reuse/README b/odb-examples/inheritance/reuse/README new file mode 100644 index 0000000..83f7bd5 --- /dev/null +++ b/odb-examples/inheritance/reuse/README @@ -0,0 +1,69 @@ +This example shows how to use reuse inheritance with ODB. This inheritance +style normally lacks virtual functions and a virtual destructor in the base +class. The application code is normally written in terms of the derived +classes instead of the base. + +The other commonly used inheritance style is polymorphism inheritance. Refer +to the inheritance/polymorphism example for more information on this style. + +The example consists of the following files: + +employee.hxx + Header file defining the 'person' and 'employee' abstract persistent + classes as well as the 'permanent_employee', 'temporary_employee', and + 'contractor' concrete persistent classes. + +employee-odb.hxx +employee-odb.ixx +employee-odb.cxx +employee.sql + The first three files contain the database support code and the last file + contains the database schema for the employee.hxx header. + + These files are generated by the ODB compiler from employee.hxx using the + following command line: + + odb --std c++11 -d --generate-schema --generate-query employee.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the employee.hxx and employee-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then persists a number of permanent and temporary employee + objects as well as a number of contractor objects. The next transaction + looks up a contractor based on the email address. Finally, the driver + performs a database query which uses a data member from the base class + in its criterion. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c employee-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < employee.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/inheritance/reuse/buildfile b/odb-examples/inheritance/reuse/buildfile new file mode 100644 index 0000000..15df240 --- /dev/null +++ b/odb-examples/inheritance/reuse/buildfile @@ -0,0 +1,44 @@ +# file : inheritance/reuse/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{employee-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{employee-meta}: $libodb + +exe{driver}: libue{employee-meta} $libs + +<{hxx ixx cxx}{employee-odb}>: hxx{employee} libue{employee-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/employee.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --output-dir $out_base \ + --table-prefix inh_reuse_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../../alias{database-client}: include = adhoc + +testscript@./: schema = employee diff --git a/odb-examples/inheritance/reuse/database.hxx b/odb-examples/inheritance/reuse/database.hxx new file mode 100644 index 0000000..f9d3a61 --- /dev/null +++ b/odb-examples/inheritance/reuse/database.hxx @@ -0,0 +1,95 @@ +// file : inheritance/reuse/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/inheritance/reuse/driver.cxx b/odb-examples/inheritance/reuse/driver.cxx new file mode 100644 index 0000000..b56a368 --- /dev/null +++ b/odb-examples/inheritance/reuse/driver.cxx @@ -0,0 +1,81 @@ +// file : inheritance/reuse/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "employee.hxx" +#include "employee-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Add a few employees and contractors to the database. + // + { + permanent_employee p1 ("John", "Doe"); + permanent_employee p2 ("Jane", "Doe"); + + temporary_employee t1 ("John", "Smith", 6); + temporary_employee t2 ("Jane", "Smith", 12); + + contractor c1 ("Joe", "Doe", "j.doe@example.com"); + contractor c2 ("Joe", "Smith", "j.smith@example.com"); + + transaction t (db->begin ()); + db->persist (p1); + db->persist (p2); + db->persist (t1); + db->persist (t2); + db->persist (c1); + db->persist (c2); + t.commit (); + } + + // Lookup a contractor based on the email address. + // + { + transaction t (db->begin ()); + unique_ptr c (db->load ("j.smith@example.com")); + t.commit (); + + cout << c->first () << " " << c->last () << " " << c->email () << endl; + } + + // Query for temporary employees that have John as the first name. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + + result r (db->query (query::first == "John")); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + cout << i->first () << " " << i->last () << " " + << i->duration () << " months" << endl; + } + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/inheritance/reuse/employee.hxx b/odb-examples/inheritance/reuse/employee.hxx new file mode 100644 index 0000000..7de3989 --- /dev/null +++ b/odb-examples/inheritance/reuse/employee.hxx @@ -0,0 +1,143 @@ +// file : inheritance/reuse/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include + +#include + +// Abstract person class. Note that it does not declare the object id. +// +#pragma db object abstract +class person +{ +public: + person (const std::string& first, const std::string& last) + : first_ (first), last_ (last) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + +protected: + friend class odb::access; + person () {} + +private: + std::string first_; + std::string last_; +}; + +// Abstract employee class. It derives from the person class and declares +// the object id for all the concrete employee types. +// +#pragma db object abstract +class employee: public person +{ +public: + employee (const std::string& first, const std::string& last) + : person (first, last) + { + } + + unsigned long + number () const + { + return id_; + } + +protected: + friend class odb::access; + employee () {} + +private: + #pragma db id auto + unsigned long id_; +}; + +// Concrete permanent_employee class. Note that it doesn't define any +// data members of its own. +// +#pragma db object +class permanent_employee: public employee +{ +public: + permanent_employee (const std::string& first, const std::string& last) + : employee (first, last) + { + } + +private: + friend class odb::access; + permanent_employee () {} +}; + +// Concrete temporary_employee class. It adds the employment duration in +// months. +// +#pragma db object +class temporary_employee: public employee +{ +public: + temporary_employee (const std::string& first, + const std::string& last, + unsigned long duration) + : employee (first, last), duration_ (duration) + { + } + + unsigned long + duration () const + { + return duration_; + } + +private: + friend class odb::access; + temporary_employee () {} + + unsigned long duration_; +}; + +// Concrete contractor class. It derives from the person class (and not +// employee; an independent contractor is not considered an employee). +// We use the contractor's external email address as the object id. +// +#pragma db object +class contractor: public person +{ +public: + contractor (const std::string& first, + const std::string& last, + const std::string& email) + : person (first, last), email_ (email) + { + } + + const std::string& + email () const + { + return email_; + } + +private: + friend class odb::access; + contractor () {} + + #pragma db id + std::string email_; +}; + +#endif // EMPLOYEE_HXX diff --git a/odb-examples/inheritance/reuse/testscript b/odb-examples/inheritance/reuse/testscript new file mode 100644 index 0000000..9b24b63 --- /dev/null +++ b/odb-examples/inheritance/reuse/testscript @@ -0,0 +1,13 @@ +# file : inheritance/reuse/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../../database-options.testscript +.include ../../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/inverse/README b/odb-examples/inverse/README new file mode 100644 index 0000000..e2c43f7 --- /dev/null +++ b/odb-examples/inverse/README @@ -0,0 +1,74 @@ +This example shows how to declare and use bidirectional one-to-one, one-to- +many, and many-to-many relationships between persistent objects. It also +shows how to work with lazy pointers. All the relationships presented in +this example declare one side as inverse in order to produce canonical +database schema. + +The example consists of the following files: + +employee.hxx + Header file defining the 'employee', 'employer', 'position', and 'project' + persistent classes as well as the employer-employee (one-to-many), + employee-position (one-to-one), and employee-project (many-to-many) + bidirectional relationships between them. + +employee-odb.hxx +employee-odb.ixx +employee-odb.cxx +employee.sql + The first three files contain the database support code and the last file + contains the database schema for the employee.hxx header. + + These files are generated by the ODB compiler from employee.hxx using the + following command line: + + odb --std c++11 -d --generate-schema --generate-query \ + --generate-session --default-pointer std::shared_ptr employee.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + + The --generate-session option is used to enable session support for all + the persistent classes in employee.hxx. The --default-pointer option is + used to make shared_ptr the default object pointer. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the employee.hxx and employee-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then creates a number of 'employee', 'employer', 'position', + and 'project' objects, sets the relationships between them, and persists + them in the database. In the next few transactions the driver loads various + objects, then accesses and modifies the relationships between them. Finally, + the driver performs a database query which uses a data member from a related + object in its criterion. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c employee-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < employee.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/inverse/buildfile b/odb-examples/inverse/buildfile new file mode 100644 index 0000000..3661ed3 --- /dev/null +++ b/odb-examples/inverse/buildfile @@ -0,0 +1,46 @@ +# file : inverse/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{employee-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{employee-meta}: $libodb + +exe{driver}: libue{employee-meta} $libs + +<{hxx ixx cxx}{employee-odb}>: hxx{employee} libue{employee-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/employee.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --generate-session \ + --default-pointer std::shared_ptr \ + --output-dir $out_base \ + --table-prefix inverse_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = employee diff --git a/odb-examples/inverse/database.hxx b/odb-examples/inverse/database.hxx new file mode 100644 index 0000000..d9f9f8b --- /dev/null +++ b/odb-examples/inverse/database.hxx @@ -0,0 +1,95 @@ +// file : inverse/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/inverse/driver.cxx b/odb-examples/inverse/driver.cxx new file mode 100644 index 0000000..be9b946 --- /dev/null +++ b/odb-examples/inverse/driver.cxx @@ -0,0 +1,256 @@ +// file : inverse/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include +#include + +#include "database.hxx" // create_database + +#include "employee.hxx" +#include "employee-odb.hxx" + +using namespace std; +using namespace odb::core; + +void +print (const employee& e) +{ + cout << e.first () << " " << e.last () << endl + << " employer: " << e.employer ().load ()->name () << endl + << " position: " << e.position ().load ()->title () << endl; + + const projects& ps (e.projects ()); + + for (projects::const_iterator i (ps.begin ()); i != ps.end (); ++i) + { + const lazy_shared_ptr& p (*i); + p.load (); + + cout << " project: " << p->name () << endl; + } + + cout << endl; +} + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Create a few persistent objects. + // + { + // Simple Tech Ltd. + // + { + shared_ptr er (new employer ("Simple Tech Ltd")); + + shared_ptr he (new position ("Hardware Engineer")); + shared_ptr se (new position ("Software Engineer")); + + shared_ptr sh (new project ("Simple Hardware")); + shared_ptr ss (new project ("Simple Software")); + + shared_ptr john (new employee ("John", "Doe", er, he)); + shared_ptr jane (new employee ("Jane", "Doe", er, se)); + + // Set the inverse side of the employee-employer relationship. + // + er->employees ().push_back (john); + er->employees ().push_back (jane); + + // Set the inverse side of the employee-position relationship. + // + he->employee (john); + se->employee (jane); + + // Set the employee-project relationship (both directions). + // + john->projects ().push_back (sh); + john->projects ().push_back (ss); + jane->projects ().push_back (ss); + + sh->employees ().push_back (john); + ss->employees ().push_back (john); + ss->employees ().push_back (jane); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (he); + db->persist (se); + + db->persist (sh); + db->persist (ss); + + db->persist (john); + db->persist (jane); + + t.commit (); + } + + // Complex Systems Inc. + // + { + shared_ptr er (new employer ("Complex Systems Inc")); + + shared_ptr he (new position ("Hardware Engineer")); + shared_ptr se (new position ("Software Engineer")); + + shared_ptr ch (new project ("Complex Hardware")); + shared_ptr cs (new project ("Complex Software")); + + shared_ptr john (new employee ("John", "Smith", er, se)); + shared_ptr jane (new employee ("Jane", "Smith", er, he)); + + // Set the inverse side of the employee-employer relationship. + // + er->employees ().push_back (john); + er->employees ().push_back (jane); + + // Set the inverse side of the employee-position relationship. + // + he->employee (john); + se->employee (jane); + + // Set the employee-project relationship (both directions). + // + john->projects ().push_back (cs); + jane->projects ().push_back (ch); + jane->projects ().push_back (cs); + + ch->employees ().push_back (jane); + cs->employees ().push_back (john); + cs->employees ().push_back (jane); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (he); + db->persist (se); + + db->persist (ch); + db->persist (cs); + + db->persist (john); + db->persist (jane); + + t.commit (); + } + } + + // Load Simple Tech Ltd and print its employees. We use a session in this + // and subsequent transactions to make sure that a single instance of any + // particular object (e.g., employer) is shared among all objects (e.g., + // employee) that relate to it. + // + { + session s; + transaction t (db->begin ()); + + shared_ptr stl (db->load ("Simple Tech Ltd")); + + employees& es (stl->employees ()); + + for (employees::iterator i (es.begin ()); i != es.end (); ++i) + { + lazy_weak_ptr& lwp (*i); + shared_ptr p (lwp.load ()); // Load and lock. + print (*p); + } + + t.commit (); + } + + // Find all Software Engineers. + // + { + typedef odb::query query; + typedef odb::result result; + + session s; + transaction t (db->begin ()); + + result r (db->query (query::title == "Software Engineer")); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + const lazy_weak_ptr& lwp (i->employee ()); + shared_ptr p (lwp.load ()); // Load and lock. + + // Employee can be NULL if the position is vacant. + // + if (p) + print (*p); + } + + t.commit (); + } + + // John Doe has moved to Complex Systems Inc and is now working as + // a Software Engineer on Complex Software. + // + { + typedef odb::query query; + + session s; + transaction t (db->begin ()); + + // Create "unloaded" pointers to the employer and project objects. + // + lazy_shared_ptr csi (*db, std::string ("Complex Systems Inc")); + lazy_shared_ptr cs (*db, std::string ("Complex Software")); + + // Create a new Software Engineer position. + // + shared_ptr se (new position ("Software Engineer")); + + shared_ptr john ( + db->query_one (query::first == "John" && + query::last == "Doe")); + + john->employer (csi); + john->position (se); + john->projects ().clear (); + john->projects ().push_back (cs); + + db->persist (se); + db->update (john); + + t.commit (); + } + + // Print Complex Systems Inc's employees. This time, instead of loading + // the employer object, we use a query which shows how we can use members + // of the pointed-to objects in the queries. + // + { + typedef odb::query query; + typedef odb::result result; + + session s; + transaction t (db->begin ()); + + result r (db->query ( + query::employer->name == "Complex Systems Inc")); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + print (*i); + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/inverse/employee.hxx b/odb-examples/inverse/employee.hxx new file mode 100644 index 0000000..89451a7 --- /dev/null +++ b/odb-examples/inverse/employee.hxx @@ -0,0 +1,263 @@ +// file : inverse/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include +#include + +#include +#include + +// The "pointer architecture" in this object model is as follows: All +// object pointers are lazy. The employee class holds shared pointers +// to employer, position, and projects. All other objects hold weak +// pointers back to the employee object. The weak sides are also the +// ones that are made inverse. +// +// The following bidirectional relationships are used: +// +// many-to-one : employee <--> employer +// one-to-one : employee <--> position +// many-to-many : employee <--> project +// + +// Forward declarations. +// +class employer; +class position; +class project; +class employee; + +typedef std::vector> projects; +typedef std::vector> employees; + +#pragma db object +class employer +{ +public: + employer (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + + // Employees of this employer. + // + typedef ::employees employees_type; + + const employees_type& + employees () const + { + return employees_; + } + + employees_type& + employees () + { + return employees_; + } + +private: + friend class odb::access; + + employer () {} + + #pragma db id + std::string name_; + + #pragma db value_not_null inverse(employer_) + employees_type employees_; +}; + +#pragma db object +class position +{ +public: + position (const std::string& title) + : title_ (title) + { + } + + const std::string& + title () const + { + return title_; + } + + // Employee that fills this position. NULL if the position is vacant. + // + typedef ::employee employee_type; + + const odb::lazy_weak_ptr& + employee () const + { + return employee_; + } + + void + employee (odb::lazy_weak_ptr employee) + { + employee_ = employee; + } + +private: + friend class odb::access; + + position () {} + + #pragma db id auto + unsigned long id_; + + std::string title_; + + #pragma db inverse(position_) + odb::lazy_weak_ptr employee_; +}; + +#pragma db object +class project +{ +public: + project (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + + // Employees working on this project. + // + typedef ::employees employees_type; + + const employees_type& + employees () const + { + return employees_; + } + + employees_type& + employees () + { + return employees_; + } + +private: + friend class odb::access; + + project () {} + + #pragma db id + std::string name_; + + #pragma db value_not_null inverse(projects_) + employees_type employees_; +}; + +#pragma db object +class employee +{ +public: + typedef ::employer employer_type; + typedef ::position position_type; + + employee (const std::string& first, + const std::string& last, + odb::lazy_shared_ptr employer, + odb::lazy_shared_ptr position) + : first_ (first), last_ (last), + employer_ (employer), + position_ (position) + { + } + + // Name. + // + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + // Employer. + // + const odb::lazy_shared_ptr& + employer () const + { + return employer_; + } + + void + employer (odb::lazy_shared_ptr employer) + { + employer_ = employer; + } + + // Position. + // + const odb::lazy_shared_ptr& + position () const + { + return position_; + } + + void + position (odb::lazy_shared_ptr position) + { + position_ = position; + } + + // Projects. + // + typedef ::projects projects_type; + + const projects_type& + projects () const + { + return projects_; + } + + projects_type& + projects () + { + return projects_; + } + +private: + friend class odb::access; + + employee () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + + #pragma db not_null + odb::lazy_shared_ptr employer_; + + #pragma db not_null + odb::lazy_shared_ptr position_; + + #pragma db value_not_null unordered + projects_type projects_; +}; + +#endif // EMPLOYEE_HXX diff --git a/odb-examples/inverse/testscript b/odb-examples/inverse/testscript new file mode 100644 index 0000000..04a89a4 --- /dev/null +++ b/odb-examples/inverse/testscript @@ -0,0 +1,13 @@ +# file : inverse/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/manifest b/odb-examples/manifest new file mode 100644 index 0000000..1b8909b --- /dev/null +++ b/odb-examples/manifest @@ -0,0 +1,98 @@ +: 1 +name: odb-examples +version: 2.5.0-b.26.z +project: odb +type: examples +language: c++ +summary: ODB compiler usage examples +license: GPL-2.0-only +description-file: README.md +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 ; Mailing list + +# @@ TMP Bump the toolchain version to 0.17.0 after it is released. +# +depends: * build2 >= 0.16.0- +depends: * bpkg >= 0.16.0- + +depends: * odb == $ + +depends: libodb == $ +depends: libodb-mysql == $ ? ($mysql) +depends: libodb-sqlite == $ ? ($sqlite) +depends: libodb-pgsql == $ ? ($pgsql) +depends: libodb-oracle == $ ? ($oracle) +depends: libodb-mssql == $ ? ($mssql) + +# @@ TODO/LATER: use an alternative to automatically detect whether we are +# using MySQL or MariaDB? But maybe we don't need to know? + +depends: * mysql-client >= 5.0.3 ? ($mysql) +depends: * psql >= 7.4.0 ? ($pgsql) +requires: * sqlplus ? ($oracle) +requires: * sqlcmd ? ($mssql) + +# This package configuration is for building with the default bots on target +# configurations where GCC is the host compiler. +# +builds: all +builds: -( +windows -gcc ) ; Requires MinGW GCC. +builds: &gcc ; Requires GCC with plugin support enabled. +builds: &gcc-5+ ; Requires GCC 5 or later. +builds: -static ; Implementation uses plugins and requires -fPIC. + +# These package configurations are for building with the custom bots on target +# configurations that were customized to use GCC as the host compiler and/or +# provide proprietary database clients. +# +# Note that they serve dual function: they make sure the default configuration +# is not used (i.e., they match the corresponding configurations in libodb*). +# And they allow CI'ing odb-examples by itself (thus we specify the bot keys +# both in libodb* and here). +# +custom-builds: latest ; Requires latest config with GCC as host compiler. +custom-builds: -static ; Implementation uses plugins and requires -fPIC. +#custom-build-bot: -- see below. + +multi-builds: none ; Multiple databases cannot be configured. +custom-multi-builds: none ; Multiple databases cannot be configured. +custom-multi-oracle-builds: none ; Multiple databases cannot be configured. +custom-multi-mssql-builds: none ; Multiple databases cannot be configured. + +custom-build-bot: +\ +-----BEGIN PUBLIC KEY----- +MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAuF4YmJmPHY52Q6N+YO0M +lt/fCovdezleb2tVplyTnvbyAiPdmYCIIjVrsqUn3y46PdFtWEiSdsrCcncoxi6H +8KelOB/oQ9pNTyEvwGKEH5ZIU7noLZYdXEfoNdvdL/pbY/7uLBZOSekfdQShZtbe +uOZCM2Mhg2DD76TP/VAwaXuDCnEvxxU/yneUl5ZaBo62AWNrYJuSGAliCOpVpl6X +X1kbHOvnCx7c9e3LxgaVivPaeZRKYg0OaFt96SBYEZzNPvjA8pMuKuj/vatHaCQ3 +NO9+r3TJ+4dQd7qN6Ju3zUJq9J/ndSh4lPvUalvvhdykecefhcyHwRZOG4xyFMFE +nJM4sM+aZu6WoKATIKtk7On70inVr0sZJXwJ4Lt4oqaK2VthcSTby3wf2Yv4p5hL +zNo31cCPmBRYzABcIc6ADYvexVK4uCwaim8xs7RK5Ug2Gv6vUWoRNZW8grIgDwUY +5pZ4Zk3hW4ii2vehTaVrrmdW6XipIsT+ayiVX7eWuHHNxAeCojXVjOJu9B0ExMlD +5tHZCs+SNdV5MceexecbptB7fZtRebP120yjLiSnZ5FpaQ1stusr0hSg+VQaX4np +f5m1W/CcDr53PKWg/ayY9nWMUQaIwH4b69kLM+VTpYSbzu5UQJkmNBNq2EOHgoTv +9MLA+cE/nNJ/rMI//MZ1+kcCAwEAAQ== +-----END PUBLIC KEY----- +\ + +custom-build-bot: +\ +-----BEGIN PUBLIC KEY----- +MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAuLYZ68rotGDAtWViFHOe +XEsmZB8BGI+af1ixh9JOy9BE4ohGTfPr1YsjGDzh+PhOVLAtyykOoT/qG7cuGB0T +gBInoRrgVB2/ZKTMwxeDGb/TA3uykaXxcw7/liTsizHAY+phCNTbke8iER5Y78js +9GlnTPmNhwFqEj2fwCz+2o08eyZvZ9Vj1fH/bFDCmDmU33JR3crtJlC8wPiF70Ho +FJzHFdaFQl3MxvEV92HjOsyqozMi6tAVVefN1vapVQeNtjkB0Di18p0/EMugEuGU +OxktjDHQWNaV8Ao6cCDk6OkJnM3ZNL1no3cV4cuF+/xI8UZzwfPoBnwg/s183Qzu +pHHKOSHmuO0oVE/XohJhepSw3tb+wf5BwejRhYHikIjqCxJdm9H0QTiqXT82y24K +yg3gkRMOgqnVxERKKP4ZknLSMQCEKiND/t2zdLJ/lxH9eHZdPHKk3OZZG292j+Bh +fknxcTKNk1Dmf32Irs5hVrjsoU8eAutbItovzXdBaj//rn/ry/kUlCa1Ov6iLIDJ +gyxmsDlgKNR/uE9ogmDn0ishJIoCmxeqenRfJkttr9pEsDsUFuB425QGqiSxa1jh +PCNca3iRtO44wADXaQMTGpvLzBfdfVc8LoFpn+kynN0V1MvxAX4mHRXxw8ERXd3U +dpHDhOthPLolJQrYKb/YyW8CAwEAAQ== +-----END PUBLIC KEY----- +\ diff --git a/odb-examples/mapping/README b/odb-examples/mapping/README new file mode 100644 index 0000000..21c0e77 --- /dev/null +++ b/odb-examples/mapping/README @@ -0,0 +1,76 @@ +This examples shows how to customize the mapping between C++ value types +and database types. The example changes the default mapping for the 'bool' +type which is now stored in the database as the "true" or "false" string. +It also maps the user-defined 'date' type to a suitable database date type. + +The example consists of the following files: + +person.hxx + Header file defining the 'date' value type and the 'person' persistent + class. It also uses the ODB value type pragma to map 'bool' to the + 'VARCHAR(5)' database type and 'date' to the 'DATE' database type. + +traits.hxx +traits-mysql.hxx +traits-sqlite.hxx + ODB 'value_traits' template specializations for the 'bool' and 'date' + types. These specializations implement conversion between these types + and their database counterparts. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-query --generate-schema \ + --hxx-prologue "#include \"traits.hxx\"" person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + + The --hxx-prologue option included the traits.hxx header at the beginning + of the generated person-odb.hxx file. This makes the 'value_traits' + specializations defined in traits.hxx known to the generated database + support code. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then persists a number of 'person' objects in the database + and executes a query to find objects matching certain criteria. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -DDATABASE_MYSQL -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/mapping/buildfile b/odb-examples/mapping/buildfile new file mode 100644 index 0000000..f7803f4 --- /dev/null +++ b/odb-examples/mapping/buildfile @@ -0,0 +1,45 @@ +# file : mapping/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --hxx-prologue '#include "traits.hxx"' \ + --output-dir $out_base \ + --table-prefix mapping_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/mapping/database.hxx b/odb-examples/mapping/database.hxx new file mode 100644 index 0000000..94b4991 --- /dev/null +++ b/odb-examples/mapping/database.hxx @@ -0,0 +1,95 @@ +// file : mapping/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/mapping/driver.cxx b/odb-examples/mapping/driver.cxx new file mode 100644 index 0000000..5e9d067 --- /dev/null +++ b/odb-examples/mapping/driver.cxx @@ -0,0 +1,65 @@ +// file : mapping/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Create a few persistent person objects. + // + { + person john ("John", "Doe", date (1978, 10, 13), true); + person jane ("Jane", "Doe", date (1975, 9, 23), false); + person joe ("Joe", "Dirt", date (1973, 12, 3), true); + + transaction t (db->begin ()); + + db->persist (john); + db->persist (jane); + db->persist (joe); + + t.commit (); + } + + // Query for a person using data members of our custom-mapped types. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + + result r (db->query (query::married && + query::born == date (1978, 10, 13))); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + cout << i->first () << " " << i->last () << " " << i->born () << endl; + } + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/mapping/person.hxx b/odb-examples/mapping/person.hxx new file mode 100644 index 0000000..c1a43b9 --- /dev/null +++ b/odb-examples/mapping/person.hxx @@ -0,0 +1,106 @@ +// file : mapping/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include +#include + +#include + +// In our database boolean values are stored as strings with valid +// values being "true" and "false". +// +#pragma db value(bool) type("VARCHAR(5)") + +#pragma db value type("DATE") +class date +{ +public: + date (unsigned int year, unsigned int month, unsigned int day) + : year_ (year), month_ (month), day_ (day) + { + } + + unsigned int + year () const + { + return year_; + } + + unsigned int + month () const + { + return month_; + } + + unsigned int + day () const + { + return day_; + } + +private: + unsigned int year_; + unsigned int month_; + unsigned int day_; +}; + +inline std::ostream& +operator<< (std::ostream& os, const date& d) +{ + return os << d.year () << '-' << d.month () << '-' << d.day (); +} + +#pragma db object +class person +{ +public: + person (const std::string& first, + const std::string& last, + const date& born, + bool married) + : first_ (first), last_ (last), born_ (born), married_ (married) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + const date& + born () const + { + return born_; + } + + bool + married () const + { + return married_; + } + +private: + friend class odb::access; + + person (): born_ (0, 0, 0) {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + date born_; + bool married_; +}; + +#endif // PERSON_HXX diff --git a/odb-examples/mapping/testscript b/odb-examples/mapping/testscript new file mode 100644 index 0000000..f9bac50 --- /dev/null +++ b/odb-examples/mapping/testscript @@ -0,0 +1,13 @@ +# file : mapping/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/mapping/traits-mssql.hxx b/odb-examples/mapping/traits-mssql.hxx new file mode 100644 index 0000000..3713f82 --- /dev/null +++ b/odb-examples/mapping/traits-mssql.hxx @@ -0,0 +1,85 @@ +// file : mapping/traits-mssql.hxx +// copyright : not copyrighted - public domain + +#ifndef TRAITS_MSSQL_HXX +#define TRAITS_MSSQL_HXX + +// +// SQL Server implementation. +// + +#include // std::size_t +#include // std::strncmp, std::memcpy +#include + +#include + +#include "person.hxx" // date + +namespace odb +{ + namespace mssql + { + template <> + class value_traits + { + public: + typedef bool value_type; + typedef bool query_type; + typedef char* image_type; + + static void + set_value (bool& v, + const char* b, + std::size_t n, + bool is_null) + { + v = (!is_null && n == 4 && std::strncmp ("true", b, n) == 0); + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + bool v) + { + is_null = false; + n = v ? 4 : 5; + + assert (n <= c); + + std::memcpy (b, (v ? "true" : "false"), n); + } + }; + + template <> + class value_traits< ::date, id_date> + { + public: + typedef ::date value_type; + typedef ::date query_type; + typedef mssql::date image_type; + + static void + set_value (value_type& v, const image_type& i, bool is_null) + { + if (!is_null) + v = value_type (static_cast (i.year), i.month, i.day); + else + v = value_type (0, 0, 0); + } + + static void + set_image (image_type& i, bool& is_null, const value_type& v) + { + is_null = false; + i.year = static_cast (v.year ()); + i.month = static_cast (v.month ()); + i.day = static_cast (v.day ()); + } + }; + } +} + +#endif // TRAITS_MSSQL_HXX diff --git a/odb-examples/mapping/traits-mysql.hxx b/odb-examples/mapping/traits-mysql.hxx new file mode 100644 index 0000000..a15d1c9 --- /dev/null +++ b/odb-examples/mapping/traits-mysql.hxx @@ -0,0 +1,85 @@ +// file : mapping/traits-mysql.hxx +// copyright : not copyrighted - public domain + +#ifndef TRAITS_MYSQL_HXX +#define TRAITS_MYSQL_HXX + +// +// MySQL implementation. +// + +#include // std::size_t +#include // std::strncmp, std::memcpy + +#include + +#include "person.hxx" // date + +namespace odb +{ + namespace mysql + { + template <> + class value_traits + { + public: + typedef bool value_type; + typedef bool query_type; + typedef details::buffer image_type; + + static void + set_value (bool& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + v = (!is_null && n == 4 && std::strncmp ("true", b.data (), n) == 0); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + bool v) + { + is_null = false; + n = v ? 4 : 5; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), (v ? "true" : "false"), n); + } + }; + + template <> + class value_traits + { + public: + typedef date value_type; + typedef date query_type; + typedef MYSQL_TIME image_type; + + static void + set_value (date& v, const MYSQL_TIME& i, bool is_null) + { + if (!is_null) + v = date (i.year, i.month, i.day); + else + v = date (0, 0, 0); + } + + static void + set_image (MYSQL_TIME& i, bool& is_null, const date& v) + { + is_null = false; + i.neg = false; + i.year = v.year (); + i.month = v.month (); + i.day = v.day (); + } + }; + } +} + +#endif // TRAITS_MYSQL_HXX diff --git a/odb-examples/mapping/traits-oracle.hxx b/odb-examples/mapping/traits-oracle.hxx new file mode 100644 index 0000000..a5683c6 --- /dev/null +++ b/odb-examples/mapping/traits-oracle.hxx @@ -0,0 +1,95 @@ +// file : mapping/traits-oracle.hxx +// copyright : not copyrighted - public domain + +#ifndef TRAITS_ORACLE_HXX +#define TRAITS_ORACLE_HXX + +// +// Oracle implementation. +// + +#include // std::size_t +#include // std::strncmp, std::memcpy +#include + +#include +#include + +#include "person.hxx" // date + +namespace odb +{ + namespace oracle + { + template <> + class value_traits + { + public: + typedef bool value_type; + typedef bool query_type; + typedef char* image_type; + + static void + set_value (bool& v, + const char* b, + std::size_t n, + bool is_null) + { + v = (!is_null && n == 4 && std::strncmp ("true", b, n) == 0); + } + + static void + set_image (char* b, + std::size_t c, + std::size_t& n, + bool& is_null, + bool v) + { + is_null = false; + n = v ? 4 : 5; + + assert (n <= c); + + std::memcpy (b, (v ? "true" : "false"), n); + } + }; + + template <> + class value_traits + { + public: + typedef date value_type; + typedef date query_type; + typedef char* image_type; + + static void + set_value (date& v, const char* b, bool is_null) + { + if (!is_null) + { + short y; + unsigned char m, d, h, min, s; + details::get_date (b, y, m, d, h, min, s); + + v = date (y, m, d); + } + else + v = date (0, 0, 0); + } + + static void + set_image (char* b, bool& is_null, const date& v) + { + is_null = false; + + short y (static_cast (v.year ())); + unsigned char m (static_cast (v.month ())); + unsigned char d (static_cast (v.day ())); + + details::set_date (b, y, m, d, 0, 0, 0); + } + }; + } +} + +#endif // TRAITS_ORACLE_HXX diff --git a/odb-examples/mapping/traits-pgsql.hxx b/odb-examples/mapping/traits-pgsql.hxx new file mode 100644 index 0000000..aeefa52 --- /dev/null +++ b/odb-examples/mapping/traits-pgsql.hxx @@ -0,0 +1,118 @@ +// file : mapping/traits-pgsql.hxx +// copyright : not copyrighted - public domain + +#ifndef TRAITS_PGSQL_HXX +#define TRAITS_PGSQL_HXX + +// +// PostgreSQL implementation. +// + +#include // std::size_t +#include // std::strncmp, std::memset, std::memcpy +#include // localtime, mktime, time_t, tm + +#include +#include + +#include "person.hxx" // date + +namespace odb +{ + namespace pgsql + { + template <> + class value_traits + { + public: + typedef bool value_type; + typedef bool query_type; + typedef details::buffer image_type; + + static void + set_value (bool& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + v = (!is_null && n == 4 && std::strncmp ("true", b.data (), n) == 0); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + bool v) + { + is_null = false; + n = v ? 4 : 5; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), (v ? "true" : "false"), n); + } + }; + + // Mapping of date to PostgreSQL DATE. DATE is stored as the number + // of days since the PostgreSQL epoch 2000-01-01. + // + template <> + class value_traits + { + public: + typedef date value_type; + typedef date query_type; + typedef int image_type; + + // The difference between the PostgreSQL epoch and the Unix epoch + // in seconds. + // + static const time_t epoch_diff = 946684800; + + static const time_t seconds_per_day = 86400; + + static void + set_value (date& v, const int& i, bool is_null) + { + if (is_null) + { + v = date (0, 0, 0); + return; + } + + time_t v_tt (epoch_diff + + static_cast (details::endian_traits::ntoh (i)) * + seconds_per_day); + + // Assume that the date is specified as UTC. Use localtime so as + // to avoid any timeshift that could be introduced by the system + // time locale not being UTC. + // + tm v_tm (*localtime (&v_tt)); + + v = date (v_tm.tm_year + 1900, v_tm.tm_mon + 1, v_tm.tm_mday); + } + + static void + set_image (int& i, bool& is_null, const date& v) + { + is_null = false; + + tm v_tm; + std::memset (&v_tm, 0, sizeof (v_tm)); + + v_tm.tm_mday = v.day (); + v_tm.tm_mon = v.month () - 1; + v_tm.tm_year = v.year () - 1900; + + time_t v_tt (mktime (&v_tm)); + + i = details::endian_traits::hton ( + static_cast ((v_tt - epoch_diff) / seconds_per_day)); + } + }; + } +} + +#endif // TRAITS_PGSQL_HXX diff --git a/odb-examples/mapping/traits-sqlite.hxx b/odb-examples/mapping/traits-sqlite.hxx new file mode 100644 index 0000000..cd7afc3 --- /dev/null +++ b/odb-examples/mapping/traits-sqlite.hxx @@ -0,0 +1,127 @@ +// file : mapping/traits-sqlite.hxx +// copyright : not copyrighted - public domain + +#ifndef TRAITS_SQLITE_HXX +#define TRAITS_SQLITE_HXX + +// +// SQLite implementation. +// + +#include // std::size_t +#include // std::strncmp, std::memcpy +#include + +#include + +#include "person.hxx" // date + +namespace odb +{ + namespace sqlite + { + template <> + class value_traits + { + public: + typedef bool value_type; + typedef bool query_type; + typedef details::buffer image_type; + + static void + set_value (bool& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + v = (!is_null && n == 4 && std::strncmp ("true", b.data (), n) == 0); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + bool v) + { + is_null = false; + n = v ? 4 : 5; + + if (n > b.capacity ()) + b.capacity (n); + + std::memcpy (b.data (), (v ? "true" : "false"), n); + } + }; + + // In SQLite there is no built-in DATE type. Rather, this type is + // mapped to TEXT in the YYYY-MM-DD format. The below implementation + // doesn't do any error checking for brevity. + // + template <> + class value_traits + { + public: + typedef date value_type; + typedef date query_type; + typedef details::buffer image_type; + + static void + set_value (date& v, + const details::buffer& b, + std::size_t n, + bool is_null) + { + using namespace std; + + if (!is_null) + { + istringstream is (string (b.data (), n)); + unsigned int y, m, d; + + is >> y; + is.ignore (1); + is >> m; + is.ignore (1); + is >> d; + + v = date (y, m, d); + } + else + v = date (0, 0, 0); + } + + static void + set_image (details::buffer& b, + std::size_t& n, + bool& is_null, + const date& v) + { + using namespace std; + + ostringstream os; + os.fill ('0'); + + os.width (4); + os << v.year () << '-'; + + os.width (2); + os << v.month () << '-'; + + os.width (2); + os << v.day (); + + const string& s (os.str ()); + + is_null = false; + n = s.size (); + + if (n > b.capacity ()) + b.capacity (n); + + memcpy (b.data (), s.c_str (), n); + } + }; + } +} + +#endif // TRAITS_SQLITE_HXX diff --git a/odb-examples/mapping/traits.hxx b/odb-examples/mapping/traits.hxx new file mode 100644 index 0000000..533b2e3 --- /dev/null +++ b/odb-examples/mapping/traits.hxx @@ -0,0 +1,23 @@ +// file : mapping/traits.hxx +// copyright : not copyrighted - public domain + +#ifndef TRAITS_HXX +#define TRAITS_HXX + +// Include one of the database system-specific traits implementations. +// +#if defined(DATABASE_MYSQL) +# include "traits-mysql.hxx" +#elif defined(DATABASE_SQLITE) +# include "traits-sqlite.hxx" +#elif defined(DATABASE_PGSQL) +# include "traits-pgsql.hxx" +#elif defined(DATABASE_ORACLE) +# include "traits-oracle.hxx" +#elif defined(DATABASE_MSSQL) +# include "traits-mssql.hxx" +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +#endif // TRAITS_HXX diff --git a/odb-examples/mssql-schema.testscript b/odb-examples/mssql-schema.testscript new file mode 100644 index 0000000..5f56536 --- /dev/null +++ b/odb-examples/mssql-schema.testscript @@ -0,0 +1,6 @@ +# file : mssql-schema.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# Create the Microsoft SQL Server database schema creation canned command base. +# +create_schema_cmd = [cmdline] $mssql_client_cmd diff --git a/odb-examples/mssql.testscript b/odb-examples/mssql.testscript new file mode 100644 index 0000000..671cb7a --- /dev/null +++ b/odb-examples/mssql.testscript @@ -0,0 +1,12 @@ +# file : mssql.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# Create the Microsoft SQL Server database schema creation canned command and +# setup the example driver command line for the subsequent examples. +# +.include mssql-schema.testscript + +schema_file = [path] $out_base/"$schema".sql +create_schema = [cmdline] $create_schema_cmd -i $schema_file + +test.arguments += $mssql_options diff --git a/odb-examples/mysql-schema.testscript b/odb-examples/mysql-schema.testscript new file mode 100644 index 0000000..dfa7852 --- /dev/null +++ b/odb-examples/mysql-schema.testscript @@ -0,0 +1,9 @@ +# file : mysql-schema.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# Create the MySQL database schema creation canned command base. +# +create_schema_cmd = [cmdline] \ + $mysql_client_cmd 2>&1 | \ + sed -e "'"'s/^mysql: \[Warning\] Using a password on the command .*//'"'" | \ + sed -n -e "'"'s/(.+)/\1/p'"'" >&2 diff --git a/odb-examples/mysql.testscript b/odb-examples/mysql.testscript new file mode 100644 index 0000000..3ee78ea --- /dev/null +++ b/odb-examples/mysql.testscript @@ -0,0 +1,12 @@ +# file : mysql.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# Create the MySQL database schema creation canned command and setup the +# example driver command line for the subsequent examples. +# +.include mysql-schema.testscript + +schema_file = [path] $out_base/"$schema".sql +create_schema = [cmdline] cat "'""$schema_file""'" | $create_schema_cmd + +test.arguments += $mysql_options diff --git a/odb-examples/optimistic/README b/odb-examples/optimistic/README new file mode 100644 index 0000000..dfa2bd5 --- /dev/null +++ b/odb-examples/optimistic/README @@ -0,0 +1,64 @@ +This example shows how to use optimistic concurrency in ODB. + +The example consists of the following files: + +person.hxx + Header file defining the 'person' persistent class. Besides the standard + persistent class pragmas, this definition also uses the 'optimistic' + pragma to indicate to the ODB compiler that the class must support + optimistic concurrency. It also uses the 'version' pragma to specify + which data member will contain the object version. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-schema person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance and persists a sample 'person' object. It then emulates the + parallel execution of two processes that try to concurrently update or + delete this object. For each step the driver prints the versions of the + object as seen by each process. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/optimistic/buildfile b/odb-examples/optimistic/buildfile new file mode 100644 index 0000000..505068e --- /dev/null +++ b/odb-examples/optimistic/buildfile @@ -0,0 +1,43 @@ +# file : optimistic/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --output-dir $out_base \ + --table-prefix optimistic_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/optimistic/database.hxx b/odb-examples/optimistic/database.hxx new file mode 100644 index 0000000..162c688 --- /dev/null +++ b/odb-examples/optimistic/database.hxx @@ -0,0 +1,95 @@ +// file : optimistic/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/optimistic/driver.cxx b/odb-examples/optimistic/driver.cxx new file mode 100644 index 0000000..968648c --- /dev/null +++ b/odb-examples/optimistic/driver.cxx @@ -0,0 +1,158 @@ +// file : optimistic/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Persist the object. + // + // At this point the initial version (1) is assigned. + // + unsigned long id; + { + person p ("John", "Doe", 21); + + transaction t (db->begin ()); + id = db->persist (p); + t.commit (); + + cout << "version after persist: " << p.version () << endl; + } + + // Process 1: load the object. + // + person p1; + { + transaction t (db->begin ()); + db->load (id, p1); + t.commit (); + + cout << "process 1 version after load: " << p1.version () << endl; + } + + // Process 2: load the object. + // + person p2; + { + transaction t (db->begin ()); + db->load (id, p2); + t.commit (); + + cout << "process 2 version after load: " << p2.version () << endl; + } + + // Process 1: update the object. + // + // At this point the version is incremented and becomes 2. + // + { + p1.age (20); // Correct the wrong age. + + transaction t (db->begin ()); + db->update (p1); + t.commit (); + + cout << "process 1 version after update: " << p1.version () << endl; + } + + // Process 2: update the object. + // + // Since the object version in this process is 1 while in the database + // it is 2, this operation will fail. + // + { + p2.age (p2.age () + 1); // Increment the age. + + transaction t (db->begin ()); + + try + { + db->update (p2); + } + catch (const object_changed&) + { + cout << "process 2 version is out of date: " << p2.version () << endl; + + // Reload the object and retry the operation. Note that the second + // update call cannot throw object_changed since we reloaded the + // object and are trying to update it in a single transaction. + // + db->reload (p2); + + cout << "process 2 version after reload: " << p2.version () << endl; + + p2.age (p2.age () + 1); + db->update (p2); + } + + t.commit (); + + cout << "process 2 version after update: " << p2.version () << endl; + cout << "final age value: " << p2.age () << endl; + } + + // Process 1: delete the object if the person is younger than 21. + // + // Since the object version in this process is 2 while in the database + // it is 3, this operation will fail. Note that this will only hold + // true if we are deleting the object by passing an object instance + // to the erase() function. If instead we pass object id, then the + // object will be deleted regardless of the version. + // + if (p1.age () < 21) + { + transaction t (db->begin ()); + + try + { + db->erase (p1); + // db->erase (id); // Never throws object_changed. + } + catch (const object_changed&) + { + cout << "process 1 version is out of date: " << p1.version () << endl; + + // Reload the object and retry the operation. Similar to update, the + // second erase call cannot throw object_changed since we reloaded + // the object and are trying to erase it in a single transaction. + // + db->reload (p1); + + cout << "process 1 version after reload: " << p2.version () << endl; + + if (p1.age () < 21) + { + db->erase (p1); + cout << "object deleted" << endl; + } + else + cout << "object not deleted" << endl; + } + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/optimistic/person.hxx b/odb-examples/optimistic/person.hxx new file mode 100644 index 0000000..5b7177f --- /dev/null +++ b/odb-examples/optimistic/person.hxx @@ -0,0 +1,67 @@ +// file : optimistic/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include + +#include + +#pragma db object optimistic +class person +{ +public: + person () {} + person (const std::string& first, + const std::string& last, + unsigned short age) + : first_ (first), last_ (last), age_ (age) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + unsigned short + age () const + { + return age_; + } + + void + age (unsigned short age) + { + age_ = age; + } + + unsigned long + version () const + { + return version_; + } + +private: + friend class odb::access; + + #pragma db id auto + unsigned long id_; + + #pragma db version + unsigned long version_; + + std::string first_; + std::string last_; + unsigned short age_; +}; + +#endif // PERSON_HXX diff --git a/odb-examples/optimistic/testscript b/odb-examples/optimistic/testscript new file mode 100644 index 0000000..0db3221 --- /dev/null +++ b/odb-examples/optimistic/testscript @@ -0,0 +1,13 @@ +# file : optimistic/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/oracle-schema.testscript b/odb-examples/oracle-schema.testscript new file mode 100644 index 0000000..29a95f1 --- /dev/null +++ b/odb-examples/oracle-schema.testscript @@ -0,0 +1,6 @@ +# file : oracle-schema.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# Create the Oracle database schema creation canned command base. +# +create_schema_cmd = [cmdline] $oracle_client_cmd diff --git a/odb-examples/oracle.testscript b/odb-examples/oracle.testscript new file mode 100644 index 0000000..f8ee224 --- /dev/null +++ b/odb-examples/oracle.testscript @@ -0,0 +1,12 @@ +# file : oracle.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# Create the Oracle database schema creation canned command and setup the +# example driver command line for the subsequent examples. +# +.include oracle-schema.testscript + +schema_file = [path] $out_base/"$schema".sql +create_schema = [cmdline] $create_schema_cmd "@$schema_file" + +test.arguments += $oracle_options diff --git a/odb-examples/pgsql-schema.testscript b/odb-examples/pgsql-schema.testscript new file mode 100644 index 0000000..8659bcd --- /dev/null +++ b/odb-examples/pgsql-schema.testscript @@ -0,0 +1,6 @@ +# file : pgsql-schema.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# Create the PostgreSQL database schema creation canned command base. +# +create_schema_cmd = [cmdline] $pgsql_client_cmd diff --git a/odb-examples/pgsql.testscript b/odb-examples/pgsql.testscript new file mode 100644 index 0000000..3ae9219 --- /dev/null +++ b/odb-examples/pgsql.testscript @@ -0,0 +1,12 @@ +# file : pgsql.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# Create the PostgreSQL database schema creation canned command and setup the +# example driver command line for the subsequent tests. +# +.include pgsql-schema.testscript + +schema_file = [path] $out_base/"$schema".sql +create_schema = [cmdline] $create_schema_cmd -f $schema_file + +test.arguments += $pgsql_options diff --git a/odb-examples/pimpl/README b/odb-examples/pimpl/README new file mode 100644 index 0000000..47bfbc8 --- /dev/null +++ b/odb-examples/pimpl/README @@ -0,0 +1,62 @@ +This example shows how to use virtual data members to implement a persistent +class that employs the pimpl C++ idiom. + +The example consists of the following files: + +person.hxx +person.cxx + Header and source file implementing the 'person' persistent class that + uses the pimpl idiom. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-query --generate-schema person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent class and its database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. Then it executes a number of database transactions on the 'person' + objects. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person.cxx +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/pimpl/buildfile b/odb-examples/pimpl/buildfile new file mode 100644 index 0000000..b6f8a88 --- /dev/null +++ b/odb-examples/pimpl/buildfile @@ -0,0 +1,44 @@ +# file : pimpl/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --output-dir $out_base \ + --table-prefix pimpl_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/pimpl/database.hxx b/odb-examples/pimpl/database.hxx new file mode 100644 index 0000000..46c3ba9 --- /dev/null +++ b/odb-examples/pimpl/database.hxx @@ -0,0 +1,95 @@ +// file : pimpl/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/pimpl/driver.cxx b/odb-examples/pimpl/driver.cxx new file mode 100644 index 0000000..50fb62a --- /dev/null +++ b/odb-examples/pimpl/driver.cxx @@ -0,0 +1,52 @@ +// file : pimpl/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + { + person john ("john@doe.com", "John Doe", 31); + person jane ("jane@doe.com", "Jane Doe", 29); + + transaction t (db->begin ()); + db->persist (john); + db->persist (jane); + t.commit (); + } + + { + typedef odb::result result; + + transaction t (db->begin ()); + result r (db->query ()); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << i->name () << ' ' << i->email () << ' ' << i->age () << endl; + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/pimpl/person.cxx b/odb-examples/pimpl/person.cxx new file mode 100644 index 0000000..6922afc --- /dev/null +++ b/odb-examples/pimpl/person.cxx @@ -0,0 +1,71 @@ +// file : pimpl/person.cxx +// copyright : not copyrighted - public domain + +#include "person.hxx" + +using namespace std; + +struct person::impl +{ + impl () {} + impl (const string& e, const string& n, unsigned short a) + : email (e), name (n), age (a) {} + + string email; + string name; + unsigned short age; +}; + +person:: +~person () +{ + delete pimpl_; +} + +person:: +person () + : pimpl_ (new impl) +{ +} + +person:: +person (const string& e, const string& n, unsigned short a) + : pimpl_ (new impl (e, n, a)) +{ +} + +const string& person:: +email () const +{ + return pimpl_->email; +} + +void person:: +email (const string& e) +{ + pimpl_->email = e; +} + +const string& person:: +name () const +{ + return pimpl_->name; +} + +void person:: +name (const string& n) +{ + pimpl_->name = n; +} + +unsigned short person:: +age () const +{ + return pimpl_->age; +} + +void person:: +age (unsigned short a) const +{ + pimpl_->age = a; +} diff --git a/odb-examples/pimpl/person.hxx b/odb-examples/pimpl/person.hxx new file mode 100644 index 0000000..d296c28 --- /dev/null +++ b/odb-examples/pimpl/person.hxx @@ -0,0 +1,56 @@ +// file : pimpl/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include + +#include + +#pragma db object +class person +{ +public: + ~person (); + person (const std::string& email, + const std::string& name, + unsigned short age); + + const std::string& + email () const; + + void + email (const std::string&); + + const std::string& + name () const; + + void + name (const std::string&); + + unsigned short + age () const; + + void + age (unsigned short) const; + +private: + person (const person&); + person& operator= (const person&); + +private: + friend class odb::access; + person (); + + struct impl; + + #pragma db transient + impl* pimpl_; + + #pragma db member(email) virtual(std::string) id + #pragma db member(name) virtual(std::string) + #pragma db member(age) virtual(unsigned short) +}; + +#endif // PERSON_HXX diff --git a/odb-examples/pimpl/testscript b/odb-examples/pimpl/testscript new file mode 100644 index 0000000..d4cbfd4 --- /dev/null +++ b/odb-examples/pimpl/testscript @@ -0,0 +1,13 @@ +# file : pimpl/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/prepared/README b/odb-examples/prepared/README new file mode 100644 index 0000000..644e11a --- /dev/null +++ b/odb-examples/prepared/README @@ -0,0 +1,65 @@ +This example shows how to use prepared queries. In particular, it includes +examples of cached and uncached queries, with and without by-reference +parameters, as well as the use of a prepared query factory. + +The example consists of the following files: + +person.hxx + Header file defining the 'person' persistent class as well as the + 'person_count' view. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-query --generate-prepared \ + --generate-schema person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + + The --generate-prepared option requests the generation of the prepared + query support code. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance and creates a number of persistent objects. It then prepares and + executes a number of queries to illustrate various usage scenarios. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/prepared/buildfile b/odb-examples/prepared/buildfile new file mode 100644 index 0000000..1347236 --- /dev/null +++ b/odb-examples/prepared/buildfile @@ -0,0 +1,45 @@ +# file : prepared/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --generate-prepared \ + --output-dir $out_base \ + --table-prefix prepared_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/prepared/database.hxx b/odb-examples/prepared/database.hxx new file mode 100644 index 0000000..2c60a47 --- /dev/null +++ b/odb-examples/prepared/database.hxx @@ -0,0 +1,95 @@ +// file : prepared/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/prepared/driver.cxx b/odb-examples/prepared/driver.cxx new file mode 100644 index 0000000..73b3993 --- /dev/null +++ b/odb-examples/prepared/driver.cxx @@ -0,0 +1,232 @@ +// file : prepared/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include +#include // std::move() +#include + +#include +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +struct params +{ + unsigned short age; + string first; +}; + +static void +query_factory (const char* name, connection& c) +{ + typedef odb::query query; + + unique_ptr p (new params); + query q (query::age > query::_ref (p->age) && + query::first == query::_ref (p->first)); + prepared_query pq (c.prepare_query (name, q)); + c.cache_query (pq, move (p)); +} + +static void +print_ages (unsigned short age, odb::result r) +{ + cout << "over " << age << ':'; + + for (odb::result::iterator i (r.begin ()); i != r.end (); ++i) + cout << ' ' << i->age (); + + cout << endl; +} + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Create a few persistent person objects. + // + { + person p1 ("John", "First", 91); + person p2 ("John", "Second", 81); + person p3 ("John", "Third", 71); + person p4 ("John", "Fourth", 61); + person p5 ("John", "Fifth", 51); + + transaction t (db->begin ()); + db->persist (p1); + db->persist (p2); + db->persist (p3); + db->persist (p4); + db->persist (p5); + t.commit (); + } + + typedef odb::query query; + typedef odb::prepared_query prep_query; + typedef odb::result result; + + // Example of an uncached prepared query in the same transaction. + // + { + transaction t (db->begin ()); + + unsigned short age (0); + query q (query::age > query::_ref (age)); + prep_query pq (db->prepare_query ("person-age-query", q)); + + for (age = 90; age > 40; age -= 10) + { + result r (pq.execute ()); + print_ages (age, r); + } + + t.commit (); + } + + // Example of an uncached prepared query in multiple transactions. + // + // Note that here we have to first obtain a connection, then prepare + // the query using this connection, and finally start each transaction + // that uses the prepared query on this connection. + // + { + connection_ptr conn (db->connection ()); + + unsigned short age (0); + query q (query::age > query::_ref (age)); + prep_query pq (conn->prepare_query ("person-age-query", q)); + + for (age = 90; age > 40; age -= 10) + { + transaction t (conn->begin ()); + + result r (pq.execute ()); + print_ages (age, r); + + t.commit (); + } + } + + // Example of a cached prepared query without by-reference parameters. + // + for (unsigned short i (0); i < 5; ++i) + { + transaction t (db->begin ()); + + prep_query pq (db->lookup_query ("person-val-age-query")); + + if (!pq) + { + pq = db->prepare_query ( + "person-val-age-query", query::age > 50); + db->cache_query (pq); + } + + result r (pq.execute ()); + print_ages (50, r); + + t.commit (); + } + + // Example of a cached prepared query with by-reference parameters. + // + for (unsigned short age (90); age > 40; age -= 10) + { + transaction t (db->begin ()); + + unsigned short* age_param; + prep_query pq ( + db->lookup_query ("person-ref-age-query", age_param)); + + if (!pq) + { + unique_ptr p (new unsigned short); + age_param = p.get (); + query q (query::age > query::_ref (*age_param)); + pq = db->prepare_query ("person-ref-age-query", q); + db->cache_query (pq, move (p)); + } + + *age_param = age; // Initialize the parameter. + result r (pq.execute ()); + print_ages (age, r); + + t.commit (); + } + + // Example of a cached prepared query that uses a query factory. + // + db->query_factory ("person-age-name-query", &query_factory); + + for (unsigned short age (90); age > 40; age -= 10) + { + transaction t (db->begin ()); + + params* p; + prep_query pq (db->lookup_query ("person-age-name-query", p)); + assert (pq); + + p->age = age; + p->first = "John"; + result r (pq.execute ()); + print_ages (age, r); + + t.commit (); + } + + // In C++11 the above call to query_factory() can be re-written to + // use a lambda function, for example: + // + /* + db->query_factory ( + "person-age-name-query", + [] (const char* name, connection& c) + { + unique_ptr p (new params); + query q (query::age > query::_ref (p->age) && + query::first == query::_ref (p->first)); + prepared_query pq (c.prepare_query (name, q)); + c.cache_query (pq, std::move (p)); + }); + */ + + // Prepared queries can also be used with views, as shown in the + // following example. + // + { + typedef odb::query query; + typedef odb::prepared_query prep_query; + + transaction t (db->begin ()); + + unsigned short age (0); + query q (query::age > query::_ref (age)); + prep_query pq ( + db->prepare_query ("person-count-age-query", q)); + + // Because an aggregate query result always contains one element, + // we use execute_value() insetad of execute() as a shortcut: + // + for (age = 90; age > 40; age -= 10) + cout << "over " << age << ": " << pq.execute_value ().count << endl; + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/prepared/person.hxx b/odb-examples/prepared/person.hxx new file mode 100644 index 0000000..dc8e6fe --- /dev/null +++ b/odb-examples/prepared/person.hxx @@ -0,0 +1,61 @@ +// file : prepared/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include +#include // std::size_t + +#include + +#pragma db object +class person +{ +public: + person (const std::string& first, + const std::string& last, + unsigned short age) + : first_ (first), last_ (last), age_ (age) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + unsigned short + age () const + { + return age_; + } + +private: + friend class odb::access; + + person () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + unsigned short age_; +}; + +#pragma db view object(person) +struct person_count +{ + #pragma db column("count(" + person::id_ + ")") + std::size_t count; +}; + +#endif // PERSON_HXX diff --git a/odb-examples/prepared/testscript b/odb-examples/prepared/testscript new file mode 100644 index 0000000..af2d0c0 --- /dev/null +++ b/odb-examples/prepared/testscript @@ -0,0 +1,13 @@ +# file : prepared/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/qt/README b/odb-examples/qt/README new file mode 100644 index 0000000..bfbe632 --- /dev/null +++ b/odb-examples/qt/README @@ -0,0 +1,77 @@ +This example shows how to persist objects that use Qt smart pointers, +containers, and value types with the help of the Qt profile library +(libodb-qt). + +The example consists of the following files: + +employee.hxx + Header file defining the 'employee' and 'employer' persistent classes. + We use QSharedPointer/QWeakPointer smart pointers provided by Qt (as + well as their lazy versions provided by the Qt profile library) to + establish a bidirectional employee-employer relationship. The QList + type is used to store the collection of employees employed by the + employer. We also use the QDateTime type to store the employee's date + of birth and QString to store the employee's first and last name. While + the employee's object id is QUuid and a QSet instance keeps track of + the employee's email addresses. Finally we use QByteArray to store the + employee's public key. + +employee-odb.hxx +employee-odb.ixx +employee-odb.cxx +employee.sql + The first three files contain the database support code and the last file + contains the database schema for the employee.hxx header. + + These files are generated by the ODB compiler from employee.hxx using the + following command line: + + odb -d --profile qt --generate-schema --generate-query \ + --generate-session employee.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + + The -p option is used to instruct the ODB compiler to load the Qt profile. + The --generate-session option is used to enable session support for all + the persistent classes in employee.hxx. + +database.hxx + Contains the createDatabase() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the employee.hxx and employee-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the createDatabase() function + declaration. + + In main() the driver first calls createDatabase() to obtain the database + instance. It then creates a number of 'Employee' and 'Employer' objects and + persists them in the database. The next transaction loads all the employees + of a particular employer using the employee-employer relationship. Finally, + the driver performs a database query which uses data member of the Qt + QString and QDate types in its criterion. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c employee-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o employee-odb.o -lodb-qt -lodb-mysql -lodb -lQtCore + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < employee.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/qt/database.hxx b/odb-examples/qt/database.hxx new file mode 100644 index 0000000..3823c5d --- /dev/null +++ b/odb-examples/qt/database.hxx @@ -0,0 +1,94 @@ +// file : qt/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::auto_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::auto_ptr +createDatabase (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + auto_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + auto_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + auto_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + auto_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + auto_ptr db (new odb::mssql::database (argc, argv)); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/qt/driver.cxx b/odb-examples/qt/driver.cxx new file mode 100644 index 0000000..377594f --- /dev/null +++ b/odb-examples/qt/driver.cxx @@ -0,0 +1,180 @@ +// file : qt/driver.cxx +// copyright : not copyrighted - public domain + +#include + +#include + +#include +#include +#include + +#include "database.hxx" // createDatabase + +#include "employee.hxx" +#include "employee-odb.hxx" + +using namespace std; +using namespace odb::core; + +ostream& +operator<< (ostream& os, const QString& s) +{ + return os << s.toStdString (); +} + +int +main (int argc, char* argv[]) +{ + QCoreApplication app (argc, argv); + + try + { + auto_ptr db (createDatabase (argc, argv)); + + // Create a few persistent objects. + // + { + // Simple Tech Ltd. + // + { + QSharedPointer er (new Employer ("Simple Tech Ltd")); + + QSharedPointer john ( + new Employee ("John", + "Doe", + QDate (1975, 1, 1), + QByteArray ("\0xF1\0x00\0x34\0x45\0x00\0xDE", 6), + er)); + + QSharedPointer jane ( + new Employee ("Jane", + "Doe", + QDate (1976, 2, 2), + QByteArray ("\0xD7\0x00\0x14", 3), + er)); + + john->emails ().insert ("john_d@example.com"); + john->emails ().insert ("john.doe@simple.com"); + jane->emails ().insert ("jane_d@example.com"); + jane->emails ().insert ("jane.doe@simple.com"); + + // Set the inverse side of the employee-employer relationship. + // + er->employees ().push_back (john); + er->employees ().push_back (jane); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (john); + db->persist (jane); + + t.commit (); + } + + // Complex Systems Inc. + // + { + QSharedPointer er (new Employer ("Complex Systems Inc")); + + QSharedPointer john ( + new Employee ("John", + "Smith", + QDate (1977, 3, 3), + QByteArray ("\0x23\0xFD\0x8F\0x00", 4), + er)); + + QSharedPointer jane ( + new Employee ("Jane", + "Smith", + QDate (1978, 4, 4), + QByteArray ("0x00\0x32\0x00\0x01\0x00", 5), + er)); + + john->emails ().insert ("john_s@example.com"); + john->emails ().insert ("john.smith@complex.com"); + jane->emails ().insert ("jane_s@example.com"); + jane->emails ().insert ("jane.smith@complex.com"); + + // Set the inverse side of the employee-employer relationship. + // + er->employees ().push_back (john); + er->employees ().push_back (jane); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (john); + db->persist (jane); + + t.commit (); + } + } + + // Load Simple Tech Ltd and print its employees. + // + { + session s; + transaction t (db->begin ()); + + QSharedPointer stl (db->load ("Simple Tech Ltd")); + + Employees& es (stl->employees ()); + + for (Employees::iterator i (es.begin ()); i != es.end (); ++i) + { + QLazyWeakPointer& lwp (*i); + + // Load and lock the employee and his employer. + // + QSharedPointer p (lwp.load ()); + QSharedPointer pe (p->employer ().load ()); + + cout << p->first () << " " << p->last () << endl + << " born: " << p->born ().toString () << endl; + + for (Emails::const_iterator j (p->emails ().begin ()), + e (p->emails ().end ()); j != e; ++j) + { + cout << " email: " << *j << endl; + } + + cout << " public key length: " << p->publicKey ().size () << endl + << " employer: " << pe->name () << endl + << " id: " << p->id ().toString () << endl + << endl; + } + + t.commit (); + } + + // Search for Complex Systems Inc employees that were born before + // April 1978. + // + { + typedef odb::query query; + typedef odb::result result; + + session s; + transaction t (db->begin ()); + + result r (db->query ( + query::employer->name == "Complex Systems Inc" && + query::born < QDate (1978, 4, 1))); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << i->first () << " " << i->last () + << " " << i->born ().toString () << endl; + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/qt/employee.hxx b/odb-examples/qt/employee.hxx new file mode 100644 index 0000000..82bbcfb --- /dev/null +++ b/odb-examples/qt/employee.hxx @@ -0,0 +1,167 @@ +// file : qt/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +// Forward declarations. +// +class Employee; + +typedef QSet Emails; +typedef QList > Employees; + +#pragma db object +class Employer +{ +public: + + Employer (const QString& name) + : name_ (name) + { + } + + const QString& + name () const + { + return name_; + } + + const Employees& + employees () const + { + return employees_; + } + + Employees& + employees () + { + return employees_; + } + +private: + friend class odb::access; + + Employer () {} + + #pragma db id + QString name_; + + #pragma db value_not_null inverse(employer_) + Employees employees_; +}; + +#pragma db object +class Employee +{ +public: + + Employee (const QString& first, + const QString& last, + const QDate& born, + const QByteArray& publicKey, + QSharedPointer employer) + : id_ (QUuid::createUuid ()), + first_ (first), + last_ (last), + born_ (born), + publicKey_ (publicKey), + employer_ (employer) + { + } + + // Id. + // + const QUuid& + id () const + { + return id_; + } + + // Name. + // + const QString& + first () const + { + return first_; + } + + const QString& + last () const + { + return last_; + } + + // Date of birth. + // + const QDate& + born () const + { + return born_; + } + + const Emails& + emails () const + { + return emails_; + } + + Emails& + emails () + { + return emails_; + } + + // Public key. + // + const QByteArray& + publicKey () const + { + return publicKey_; + } + + // Employer. + // + QLazySharedPointer + employer () const + { + return employer_; + } + + void + employer (QSharedPointer employer) + { + employer_ = employer; + } + +private: + friend class odb::access; + + Employee () {} + + #pragma db id + QUuid id_; + + QString first_; + QString last_; + QDate born_; + Emails emails_; + QByteArray publicKey_; + + #pragma db not_null + QLazySharedPointer employer_; +}; + +#endif // EMPLOYEE_HXX diff --git a/odb-examples/query/README b/odb-examples/query/README new file mode 100644 index 0000000..175ef21 --- /dev/null +++ b/odb-examples/query/README @@ -0,0 +1,59 @@ +This example shows how to use the ODB Query Language to search the database +for persistent objects matching certain criteria. + +The example consists of the following files: + +person.hxx + Header file defining the 'person' persistent class. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-query --generate-schema person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then persists a number of 'person' objects in the database + and executes a number of queries to find objects matching various criteria. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/query/buildfile b/odb-examples/query/buildfile new file mode 100644 index 0000000..2585145 --- /dev/null +++ b/odb-examples/query/buildfile @@ -0,0 +1,44 @@ +# file : query/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --output-dir $out_base \ + --table-prefix query_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/query/database.hxx b/odb-examples/query/database.hxx new file mode 100644 index 0000000..5216e98 --- /dev/null +++ b/odb-examples/query/database.hxx @@ -0,0 +1,95 @@ +// file : query/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/query/driver.cxx b/odb-examples/query/driver.cxx new file mode 100644 index 0000000..67f872b --- /dev/null +++ b/odb-examples/query/driver.cxx @@ -0,0 +1,230 @@ +// file : query/driver.cxx +// copyright : not copyrighted - public domain + +#include +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; + +using odb::database; +using odb::transaction; + +typedef odb::query query; +typedef odb::result result; + +static void +print (person& p) +{ + cout << p.first () << " "; + + if (!p.middle ().null ()) + cout << p.middle ().get () << " "; + + cout << p.last () << " " << p.age () << endl; +} + +static void +print (result& r) +{ + for (result::iterator i (r.begin ()); i != r.end (); ++i) + print (*i); + + cout << endl; +} + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + { + typedef vector people; + + people p; + + p.push_back (person ("John", "Doe", 21)); + p.push_back (person ("John", "Smith", 22)); + p.push_back (person ("Jack", "Johnson", 31)); + p.push_back (person ("John", "JJ", "Jackson", 32)); + p.push_back (person ("Jane", "JD", "Doe", 23)); + p.push_back (person ("Jane", "JS", "Smith", 24)); + + transaction t (db->begin ()); + + for (people::iterator i (p.begin ()); i != p.end (); ++i) + db->persist (*i); + + t.commit (); + } + + // A simple query and result handling. + // + { + transaction t (db->begin ()); + + result r (db->query (query::age < 30)); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + cout << i->first () << " " << i->last () << " " << i->age () << endl; + } + + // Alternatively we can get a dynamically-allocated object. + // + /* + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + unique_ptr p (i.load ()); + cout << p->first () << " " << p->last () << " " << p->age () << endl; + } + */ + + // Or we can load the state into an existing object. + // + /* + person p ("", "", 0); + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + i.load (p); + cout << p.first () << " " << p.last () << " " << p.age () << endl; + } + */ + + cout << endl; + + t.commit (); + } + + // Use query_one() as a shortcut when there's no more than one element + // in the result. + // + { + transaction t (db->begin ()); + + unique_ptr p (db->query_one (query::age == 21)); + + if (p.get () != 0) + { + print (*p); + cout << endl; + } + + // Or we can load the state into an existing object. + // + /* + person p ("", "", 0); + + if (db->query_one (query::age == 21, p)) + { + print (p); + cout << endl; + } + */ + + t.commit (); + } + + // Query that shows how to combine expressions with &&, ||, and ! + // as well as use paranthesis to control evaluation order. + // + { + transaction t (db->begin ()); + + result r ( + db->query ( + (query::first == "John" || query::first == "Jane") && + !(query::last != "Doe" || query::age > 30))); + + print (r); + t.commit (); + } + + // Query that shows how to use by-reference parameter binding. + // + { + transaction t (db->begin ()); + + unsigned short lower (0), upper (0); + + query q (query::age >= query::_ref (lower) && + query::age < query::_ref (upper)); + + for (unsigned short band (0); band < 10; ++band) + { + lower = band * 10; + upper = lower + 10; + + result r (db->query (q)); + + if (!r.empty ()) + { + cout << lower << '-' << (upper - 1) << ':' << endl; + print (r); + } + } + + t.commit (); + } + + // Query that shows how to use the in() function. + // + { + transaction t (db->begin ()); + + result r ( + db->query ( + query::last.in ("Smith", "Johnson", "Jockson"))); + + print (r); + + t.commit (); + } + + // The same query but using the in_range() function. + // + { + vector names; + + names.push_back ("Smith"); + names.push_back ("Johnson"); + names.push_back ("Jockson"); + + transaction t (db->begin ()); + + result r ( + db->query ( + query::last.in_range (names.begin (), names.end ()))); + + print (r); + + t.commit (); + } + + // Query that shows how to test for NULL values using the + // is_null()/is_not_null() functions. + // + { + transaction t (db->begin ()); + result r (db->query (query::middle.is_not_null ())); + print (r); + t.commit (); + } + + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/query/person.hxx b/odb-examples/query/person.hxx new file mode 100644 index 0000000..59e0721 --- /dev/null +++ b/odb-examples/query/person.hxx @@ -0,0 +1,69 @@ +// file : query/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include + +#include +#include + +#pragma db object +class person +{ +public: + person (const std::string& first, + const std::string& last, + unsigned short age) + : first_ (first), last_ (last), age_ (age) + { + } + + person (const std::string& first, + const std::string& middle, + const std::string& last, + unsigned short age) + : first_ (first), middle_ (middle), last_ (last), age_ (age) + { + } + + const std::string& + first () const + { + return first_; + } + + const odb::nullable& + middle () const + { + return middle_; + } + + const std::string& + last () const + { + return last_; + } + + unsigned short + age () const + { + return age_; + } + +private: + friend class odb::access; + + person () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + odb::nullable middle_; + std::string last_; + unsigned short age_; +}; + +#endif // PERSON_HXX diff --git a/odb-examples/query/testscript b/odb-examples/query/testscript new file mode 100644 index 0000000..b644c55 --- /dev/null +++ b/odb-examples/query/testscript @@ -0,0 +1,13 @@ +# file : query/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/relationship/README b/odb-examples/relationship/README new file mode 100644 index 0000000..0e175b3 --- /dev/null +++ b/odb-examples/relationship/README @@ -0,0 +1,70 @@ +This example shows how to declare and use unidirectional to-one and to-many +relationships between persistent objects. + +The example consists of the following files: + +employee.hxx + Header file defining the 'employee', 'employer', and 'project' persistent + classes as well as the employee-employer (to-one) and employee-project (to- + many) unidirectional relationships between them. + +employee-odb.hxx +employee-odb.ixx +employee-odb.cxx +employee.sql + The first three files contain the database support code and the last file + contains the database schema for the employee.hxx header. + + These files are generated by the ODB compiler from employee.hxx using the + following command line: + + odb --std c++11 -d --generate-schema --generate-query \ + --generate-session --default-pointer std::shared_ptr employee.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + + The --generate-session option is used to enable session support for all + the persistent classes in employee.hxx. The --default-pointer option is + used to make shared_ptr the default object pointer. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the employee.hxx and employee-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then creates a number of 'employee', 'employer', and 'project' + objects, sets the relationships between them, and persists them in the + database. In the next few transactions the driver loads various objects, + then accesses and modifies the relationships between them. Finally, the + driver performs a database query which uses a data member from a related + object in its criterion. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c employee-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < employee.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/relationship/buildfile b/odb-examples/relationship/buildfile new file mode 100644 index 0000000..32d292a --- /dev/null +++ b/odb-examples/relationship/buildfile @@ -0,0 +1,46 @@ +# file : relationship/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{employee-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{employee-meta}: $libodb + +exe{driver}: libue{employee-meta} $libs + +<{hxx ixx cxx}{employee-odb}>: hxx{employee} libue{employee-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/employee.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --generate-session \ + --default-pointer std::shared_ptr \ + --output-dir $out_base \ + --table-prefix relation_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = employee diff --git a/odb-examples/relationship/database.hxx b/odb-examples/relationship/database.hxx new file mode 100644 index 0000000..17d8393 --- /dev/null +++ b/odb-examples/relationship/database.hxx @@ -0,0 +1,95 @@ +// file : relationship/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/relationship/driver.cxx b/odb-examples/relationship/driver.cxx new file mode 100644 index 0000000..1f74824 --- /dev/null +++ b/odb-examples/relationship/driver.cxx @@ -0,0 +1,167 @@ +// file : relationship/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr, std::shared_ptr +#include + +#include +#include +#include + +#include "database.hxx" // create_database + +#include "employee.hxx" +#include "employee-odb.hxx" + +using namespace std; +using namespace odb::core; + +void +print (const employee& e) +{ + cout << e.first () << " " << e.last () << endl + << " employer: " << e.employer ()->name () << endl; + + const projects& ps (e.projects ()); + + for (projects::const_iterator i (ps.begin ()); i != ps.end (); ++i) + { + shared_ptr p (*i); + cout << " project: " << p->name () << endl; + } + + cout << endl; +} + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Create a few persistent objects. + // + { + // Simple Tech Ltd. + // + { + shared_ptr er (new employer ("Simple Tech Ltd")); + + shared_ptr sh (new project ("Simple Hardware")); + shared_ptr ss (new project ("Simple Software")); + + shared_ptr john (new employee ("John", "Doe", er)); + shared_ptr jane (new employee ("Jane", "Doe", er)); + + john->projects ().push_back (sh); + john->projects ().push_back (ss); + jane->projects ().push_back (ss); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (sh); + db->persist (ss); + + db->persist (john); + db->persist (jane); + + t.commit (); + } + + // Complex Systems Inc. + // + { + shared_ptr er (new employer ("Complex Systems Inc")); + + shared_ptr ch (new project ("Complex Hardware")); + shared_ptr cs (new project ("Complex Software")); + + shared_ptr john (new employee ("John", "Smith", er)); + shared_ptr jane (new employee ("Jane", "Smith", er)); + + john->projects ().push_back (cs); + jane->projects ().push_back (ch); + jane->projects ().push_back (cs); + + transaction t (db->begin ()); + + db->persist (er); + + db->persist (ch); + db->persist (cs); + + db->persist (john); + db->persist (jane); + + t.commit (); + } + } + + typedef odb::query query; + typedef odb::result result; + + // Load employees with "Doe" as the last name and print what we've got. + // We use a session in this and subsequent transactions to make sure + // that a single instance of any particular object (e.g., employer) is + // shared among all objects (e.g., employee) that relate to it. + // + { + session s; + transaction t (db->begin ()); + + result r (db->query (query::last == "Doe")); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + print (*i); + + t.commit (); + } + + // John Doe has moved to Complex Systems Inc and is now working on + // Complex Hardware. + // + { + session s; + transaction t (db->begin ()); + + shared_ptr csi (db->load ("Complex Systems Inc")); + shared_ptr ch (db->load ("Complex Hardware")); + + shared_ptr john ( + db->query_one (query::first == "John" && + query::last == "Doe")); + + john->employer (csi); + john->projects ().clear (); + john->projects ().push_back (ch); + + db->update (john); + + t.commit (); + } + + // We can also use members of the pointed-to objects in the queries. The + // following transaction prints all the employees of Complex Systems Inc. + // + { + session s; + transaction t (db->begin ()); + + result r (db->query ( + query::employer->name == "Complex Systems Inc")); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + print (*i); + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/relationship/employee.hxx b/odb-examples/relationship/employee.hxx new file mode 100644 index 0000000..cc03971 --- /dev/null +++ b/odb-examples/relationship/employee.hxx @@ -0,0 +1,154 @@ +// file : relationship/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include +#include +#include // shared_ptr + +#include + +// The "pointer architecture" in this object model is as follows: All +// object pointers are eager. The employee class holds shared pointers +// to employer and projects. +// +// The following unidirectional relationships are used: +// +// to-one : employee -> employer +// to-many : employee -> project +// + +// Forward declarations. +// +class employer; +class project; +class employee; + +typedef std::vector> projects; + +#pragma db object +class employer +{ +public: + employer (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + +private: + friend class odb::access; + + employer () {} + + #pragma db id + std::string name_; +}; + +#pragma db object +class project +{ +public: + project (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + +private: + friend class odb::access; + + project () {} + + #pragma db id + std::string name_; +}; + +#pragma db object +class employee +{ +public: + typedef ::employer employer_type; + + employee (const std::string& first, + const std::string& last, + std::shared_ptr employer) + : first_ (first), last_ (last), employer_ (employer) + { + } + + // Name. + // + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + // Employer. + // + std::shared_ptr + employer () const + { + return employer_; + } + + void + employer (std::shared_ptr employer) + { + employer_ = employer; + } + + // Projects. + // + typedef ::projects projects_type; + + const projects_type& + projects () const + { + return projects_; + } + + projects_type& + projects () + { + return projects_; + } + +private: + friend class odb::access; + + employee () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + + #pragma db not_null + std::shared_ptr employer_; + + #pragma db value_not_null unordered + projects_type projects_; +}; + +#endif // EMPLOYEE_HXX diff --git a/odb-examples/relationship/testscript b/odb-examples/relationship/testscript new file mode 100644 index 0000000..d23eb2d --- /dev/null +++ b/odb-examples/relationship/testscript @@ -0,0 +1,13 @@ +# file : relationship/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/schema/custom/README b/odb-examples/schema/custom/README new file mode 100644 index 0000000..b5e9af4 --- /dev/null +++ b/odb-examples/schema/custom/README @@ -0,0 +1,61 @@ +This example shows how to map persistent C++ classes to a custom database +schema. In particular, it shows how to map all the commonly-used constructs, +including containers, object relationships, and composite value types. + +The example consists of the following files: + +employee.hxx + Header file defining the 'employee' and 'employer' persistent classes + as well as the 'name' composite value type. ODB pragmas are used to + assign custom database tables to persistent classes as well as custom + database types and columns to data members. + +employee-odb.hxx +employee-odb.ixx +employee-odb.cxx + These files contain the database support code for the employee.hxx header + and are generated by the ODB compiler from employee.hxx using the following + command line: + + odb --std c++11 -d --generate-query --generate-session \ + --default-pointer std::shared_ptr employee.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + + The --generate-session option is used to enable session support for all + the persistent classes in employee.hxx. The --default-pointer option is + used to make shared_ptr the default object pointer. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the employee.hxx and employee-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then programmatically creates the database schema by executing + a series of SQL statements. After that the driver creates a number of + 'employee' and 'employer' objects, sets the relationships between them, + and persists them in the database. Finally, the driver performs a database + query and prints the information about the returned objects. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c employee-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb + +To run the driver, using MySQL as an example, we can execute the following +command: + +./driver --user odb_test --database odb_test + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. diff --git a/odb-examples/schema/custom/buildfile b/odb-examples/schema/custom/buildfile new file mode 100644 index 0000000..8248866 --- /dev/null +++ b/odb-examples/schema/custom/buildfile @@ -0,0 +1,44 @@ +# file : schema/custom/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{employee-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{employee-meta}: $libodb + +exe{driver}: libue{employee-meta} $libs + +<{hxx ixx cxx}{employee-odb}>: hxx{employee} libue{employee-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/employee.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --default-pointer std::shared_ptr \ + --output-dir $out_base \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../../alias{database-client}: include = adhoc + +testscript@./: schema = employee diff --git a/odb-examples/schema/custom/database.hxx b/odb-examples/schema/custom/database.hxx new file mode 100644 index 0000000..db6543c --- /dev/null +++ b/odb-examples/schema/custom/database.hxx @@ -0,0 +1,76 @@ +// file : schema/custom/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/schema/custom/driver.cxx b/odb-examples/schema/custom/driver.cxx new file mode 100644 index 0000000..f9d40e2 --- /dev/null +++ b/odb-examples/schema/custom/driver.cxx @@ -0,0 +1,238 @@ +// file : schema/custom/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include +#include +#include + +#include "database.hxx" // create_database + +#include "employee.hxx" +#include "employee-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Create the database schema. + // +#if defined(DATABASE_MYSQL) || \ + defined(DATABASE_SQLITE) || \ + defined(DATABASE_MSSQL) + { + + // Due to bugs in SQLite foreign key support for DDL statements, + // we need to temporarily disable foreign keys. + // + connection_ptr c (db->connection ()); + +#ifdef DATABASE_SQLITE + c->execute ("PRAGMA foreign_keys=OFF"); +#endif + + transaction t (c->begin ()); + + // Try to drop the tables if they exist and ignore the error + // if they don't. + // + try + { + db->execute ("DROP TABLE EmployeeDegree"); + db->execute ("DROP TABLE Employee"); + db->execute ("DROP TABLE Employer"); + } + catch (const odb::exception&) + { + } + + db->execute ( + "CREATE TABLE Employer (" + "name VARCHAR (255) NOT NULL PRIMARY KEY)"); + + db->execute ( + "CREATE TABLE Employee (" + "ssn INTEGER NOT NULL PRIMARY KEY," + "first_name VARCHAR (255) NOT NULL," + "last_name VARCHAR (255) NOT NULL," + "employer VARCHAR (255) NOT NULL REFERENCES Employer (name))"); + + db->execute ( + "CREATE TABLE EmployeeDegree (" + "ssn INTEGER NOT NULL REFERENCES Employee (ssn)," + "degree VARCHAR (255) NOT NULL)"); + + t.commit (); + +#ifdef DATABASE_SQLITE + c->execute ("PRAGMA foreign_keys=ON"); +#endif + } +#elif defined(DATABASE_PGSQL) + { + // PostgreSQL-specific SQL. + // + transaction t (db->begin ()); + + db->execute ("DROP TABLE IF EXISTS \"Employer\" CASCADE"); + db->execute ("DROP TABLE IF EXISTS \"Employee\" CASCADE"); + db->execute ("DROP TABLE IF EXISTS \"EmployeeDegree\" CASCADE"); + + db->execute ( + "CREATE TABLE \"Employer\" (" + "name VARCHAR (255) NOT NULL PRIMARY KEY)"); + + db->execute ( + "CREATE TABLE \"Employee\" (" + "ssn INTEGER NOT NULL PRIMARY KEY," + "first_name VARCHAR (255) NOT NULL," + "last_name VARCHAR (255) NOT NULL," + "employer VARCHAR (255) NOT NULL)"); + + db->execute ( + "CREATE TABLE \"EmployeeDegree\" (" + "ssn INTEGER NOT NULL," + "degree VARCHAR (255) NOT NULL)"); + + db->execute ( + "ALTER TABLE \"Employee\" " + "ADD FOREIGN KEY (employer) " + "REFERENCES \"Employer\" " + "INITIALLY DEFERRED"); + + db->execute ( + "ALTER TABLE \"EmployeeDegree\" " + "ADD FOREIGN KEY (ssn) " + "REFERENCES \"Employee\" " + "INITIALLY DEFERRED"); + + t.commit (); + } +#elif defined(DATABASE_ORACLE) + { + // Oracle-specific PL/SQL. + // + transaction t (db->begin ()); + + db->execute ("BEGIN " + " EXECUTE IMMEDIATE " + " 'DROP TABLE \"Employer\" CASCADE CONSTRAINTS';" + " EXCEPTION " + " WHEN OTHERS THEN " + " IF SQLCODE != -942 THEN RAISE; END IF;" + "END;"); + + db->execute ("BEGIN " + " EXECUTE IMMEDIATE " + " 'DROP TABLE \"Employee\" CASCADE CONSTRAINTS';" + " EXCEPTION " + " WHEN OTHERS THEN " + " IF SQLCODE != -942 THEN RAISE; END IF;" + "END;"); + + db->execute ("BEGIN " + " EXECUTE IMMEDIATE 'DROP TABLE \"EmployeeDegree\"';" + " EXCEPTION " + " WHEN OTHERS THEN " + " IF SQLCODE != -942 THEN RAISE; END IF;" + "END;"); + + db->execute ( + "CREATE TABLE \"Employer\" (" + "\"name\" VARCHAR (255) PRIMARY KEY)"); + + db->execute ( + "CREATE TABLE \"Employee\" (" + "\"ssn\" NUMBER(10) PRIMARY KEY," + "\"first_name\" VARCHAR (255) NOT NULL," + "\"last_name\" VARCHAR (255) NOT NULL," + "\"employer\" VARCHAR (255) NOT NULL)"); + + db->execute ( + "CREATE TABLE \"EmployeeDegree\" (" + "\"ssn\" NUMBER(10) NOT NULL," + "\"degree\" VARCHAR (255) NOT NULL)"); + + db->execute ( + "ALTER TABLE \"Employee\" " + "ADD FOREIGN KEY (\"employer\") " + "REFERENCES \"Employer\" " + "INITIALLY DEFERRED"); + + db->execute ( + "ALTER TABLE \"EmployeeDegree\" " + "ADD FOREIGN KEY (\"ssn\") " + "REFERENCES \"Employee\" " + "INITIALLY DEFERRED"); + + t.commit (); + } +#else +# error unknown database +#endif + + // Create a few persistent objects. + // + { + shared_ptr st (new employer ("Simple Tech Ltd")); + + shared_ptr john (new employee (1, "John", "Doe", st)); + shared_ptr jane (new employee (2, "Jane", "Doe", st)); + + john->degrees ().push_back ("BA"); + john->degrees ().push_back ("MSc"); + jane->degrees ().push_back ("Ph.D."); + + transaction t (db->begin ()); + + db->persist (st); + db->persist (john); + db->persist (jane); + + t.commit (); + } + + // Load employees with "Doe" as the last name and print what we've got. + // + { + typedef odb::query query; + typedef odb::result result; + + session s; + transaction t (db->begin ()); + + result r (db->query (query::name.last == "Doe")); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + cout << i->name ().first () << " " << i->name ().last () << endl + << " employer: " << i->employer ()->name () << endl; + + for (degrees::iterator j (i->degrees ().begin ()); + j != i->degrees ().end (); + ++j) + { + cout << " degree: " << *j << endl; + } + + cout << endl; + } + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/schema/custom/employee.hxx b/odb-examples/schema/custom/employee.hxx new file mode 100644 index 0000000..200017d --- /dev/null +++ b/odb-examples/schema/custom/employee.hxx @@ -0,0 +1,143 @@ +// file : schema/custom/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include +#include +#include // std::shared_ptr + +#include + +typedef std::vector degrees; + +#pragma db value +class name +{ +public: + name (const std::string& first, const std::string& last) + : first_ (first), last_ (last) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + +private: + friend class odb::access; + + #pragma db type("VARCHAR(255)") column("first_name") + std::string first_; + + #pragma db type("VARCHAR(255)") column("last_name") + std::string last_; +}; + +#pragma db object table("Employer") +class employer +{ +public: + employer (const std::string& name) + : name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + +private: + friend class odb::access; + + employer () {} + + #pragma db id type("VARCHAR(255)") column("name") + std::string name_; +}; + +#pragma db object table("Employee") +class employee +{ +public: + typedef ::employer employer_type; + + employee (unsigned long id, + const std::string& first, + const std::string& last, + std::shared_ptr employer) + : id_ (id), name_ (first, last), employer_ (employer) + { + } + + // Name. + // + typedef ::name name_type; + + const name_type& + name () const + { + return name_; + } + + // Degrees. + // + typedef ::degrees degrees_type; + + const degrees_type& + degrees () const + { + return degrees_; + } + + degrees_type& + degrees () + { + return degrees_; + } + + // Employer. + // + std::shared_ptr + employer () const + { + return employer_; + } + + void + employer (std::shared_ptr employer) + { + employer_ = employer; + } + +private: + friend class odb::access; + + employee (): name_ ("", "") {} + + #pragma db id type("INTEGER") column("ssn") + unsigned long id_; + + #pragma db column("") // No column prefix. + name_type name_; + + #pragma db unordered table("EmployeeDegree") id_column("ssn") \ + value_type("VARCHAR(255)") value_column("degree") + degrees_type degrees_; + + #pragma db not_null column("employer") + std::shared_ptr employer_; +}; + +#endif // EMPLOYEE_HXX diff --git a/odb-examples/schema/custom/testscript b/odb-examples/schema/custom/testscript new file mode 100644 index 0000000..0f5cafc --- /dev/null +++ b/odb-examples/schema/custom/testscript @@ -0,0 +1,13 @@ +# file : schema/custom/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../../database-options.testscript +.include ../../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/schema/embedded/README b/odb-examples/schema/embedded/README new file mode 100644 index 0000000..10084a3 --- /dev/null +++ b/odb-examples/schema/embedded/README @@ -0,0 +1,63 @@ +This example shows how to generate and use a database schema that is embedded +into the application rather than stored as a separate SQL file. + +The example consists of the following files: + +person.hxx + Header file defining the 'person' persistent class. + +person-odb.hxx +person-odb.ixx +person-odb.cxx + These files contain the database support code as well as the embedded + database schema for the person.hxx header. They are generated by the ODB + compiler from person.hxx using the following command line: + + odb --std c++11 -d --generate-schema --schema-format embedded \ + --generate-query person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + + The --generate-schema option requests the generation of the database schema. + The --schema-format option is used to instruct the ODB compiler to embed the + schema into the generated C++ files. It is also possible to generate the + schema creation code into a separate source file by passing the 'separate' + value instead of 'embedded' to the --schema-format option. This is primarily + useful if you want to place the schema creation functionality into a + separate program or library. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then uses the ODB schema catalog to create the database + schema. During this step the generated code issues a number of SQL + statements that drop and create necessary database tables, etc. + + After the database schema is ready, the driver persists a number of 'person' + objects, performs a database query, and prints the information about the + returned objects. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the driver, using MySQL as an example, we can execute the following +command: + +./driver --user odb_test --database odb_test + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. diff --git a/odb-examples/schema/embedded/buildfile b/odb-examples/schema/embedded/buildfile new file mode 100644 index 0000000..b1bc449 --- /dev/null +++ b/odb-examples/schema/embedded/buildfile @@ -0,0 +1,42 @@ +# file : schema/embedded/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --schema-format embedded \ + --generate-query \ + --output-dir $out_base \ + --table-prefix schema_embedded_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/schema/embedded/database.hxx b/odb-examples/schema/embedded/database.hxx new file mode 100644 index 0000000..922db8b --- /dev/null +++ b/odb-examples/schema/embedded/database.hxx @@ -0,0 +1,76 @@ +// file : schema/embedded/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/schema/embedded/driver.cxx b/odb-examples/schema/embedded/driver.cxx new file mode 100644 index 0000000..3aadef0 --- /dev/null +++ b/odb-examples/schema/embedded/driver.cxx @@ -0,0 +1,96 @@ +// file : schema/embedded/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + typedef odb::query query; + typedef odb::result result; + + unique_ptr db (create_database (argc, argv)); + + // Create the database schema. + // + { + transaction t (db->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + } + + // The following alternative version only creates the schema if it + // hasn't already been created. To detect the existence of the schema + // this version tries to query the database for a person object. If + // the corresponding table does not exist, then an exceptions will be + // thrown in which case we proceed to creating the schema. + // + /* + { + transaction t (db->begin ()); + + try + { + db->query (false); + } + catch (const odb::exception& e) + { + schema_catalog::create_schema (*db); + } + + t.commit (); + } + */ + + // Create a few persistent person objects. + // + { + person john ("John", "Doe", 33); + person jane ("Jane", "Doe", 32); + person joe ("Joe", "Dirt", 30); + + transaction t (db->begin ()); + + db->persist (john); + db->persist (jane); + db->persist (joe); + + t.commit (); + } + + // Print those over 30. + // + { + transaction t (db->begin ()); + + result r (db->query (query::age > 30)); + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + cout << i->first () << " " << i->last () << endl; + } + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/schema/embedded/person.hxx b/odb-examples/schema/embedded/person.hxx new file mode 100644 index 0000000..e73ddcf --- /dev/null +++ b/odb-examples/schema/embedded/person.hxx @@ -0,0 +1,59 @@ +// file : schema/embedded/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include + +#include + +#pragma db object +class person +{ +public: + person (const std::string& first, + const std::string& last, + unsigned short age) + : first_ (first), last_ (last), age_ (age) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + unsigned short + age () const + { + return age_; + } + + void + age (unsigned short age) + { + age_ = age; + } + +private: + friend class odb::access; + + person () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + unsigned short age_; +}; + +#endif // PERSON_HXX diff --git a/odb-examples/schema/embedded/testscript b/odb-examples/schema/embedded/testscript new file mode 100644 index 0000000..7d403e6 --- /dev/null +++ b/odb-examples/schema/embedded/testscript @@ -0,0 +1,9 @@ +# file : schema/embedded/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../../database-options.testscript +.include ../../$(database).testscript + +: basics +: +$* >| diff --git a/odb-examples/section/README b/odb-examples/section/README new file mode 100644 index 0000000..bcbf522 --- /dev/null +++ b/odb-examples/section/README @@ -0,0 +1,63 @@ +This example shows how to use object sections to implement lazy-loading +and change-updating of a subset of data members in a persistent class. + +The example consists of the following files: + +person.hxx + Header file defining the 'person' persistent class. It contains a number of + data members some of which are made to belong to a section. + +person-odb.hxx +person-odb.ixx +person-odb.cxx +person.sql + The first three files contain the database support code and the last file + contains the database schema for the person.hxx header. + + These files are generated by the ODB compiler from person.hxx using the + following command line: + + odb --std c++11 -d --generate-schema person.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the person.hxx and person-odb.hxx + headers to gain access to the persistent classes and their database support + code. It also includes database.hxx for the create_database() function + declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then persists a 'person' object, loads it back, including + the section, and prints the contents of its members. Finally, the driver + shows how to update the state of the section data members in various ways, + then re-loads and prints the object to verify that the changes have been + made persistent. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c person-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o person-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < person.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/section/buildfile b/odb-examples/section/buildfile new file mode 100644 index 0000000..09bf305 --- /dev/null +++ b/odb-examples/section/buildfile @@ -0,0 +1,43 @@ +# file : section/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{person-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{person-meta}: $libodb + +exe{driver}: libue{person-meta} $libs + +<{hxx ixx cxx}{person-odb}>: hxx{person} libue{person-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/person.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --output-dir $out_base \ + --table-prefix section_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = person diff --git a/odb-examples/section/database.hxx b/odb-examples/section/database.hxx new file mode 100644 index 0000000..8aaafbe --- /dev/null +++ b/odb-examples/section/database.hxx @@ -0,0 +1,95 @@ +// file : section/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/section/driver.cxx b/odb-examples/section/driver.cxx new file mode 100644 index 0000000..900127b --- /dev/null +++ b/odb-examples/section/driver.cxx @@ -0,0 +1,133 @@ +// file : section/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr +#include + +#include +#include + +#include "database.hxx" // create_database + +#include "person.hxx" +#include "person-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + unsigned long id; + + // Create a persistent person object. + // + { + person joe ("Joe", "Dirt"); + joe.bio ("Joe Dirt is a very strange man indeed..."); + joe.nicknames ().push_back ("JD"); + + // At this point the state of a section is undefined since the + // object is transient. + + transaction t (db->begin ()); + id = db->persist (joe); + t.commit (); + + // Now, since the object is persistent, the state of the section + // is loaded and unchanged. + } + + // Load the object and print what we've got. Then update the bio. + // + { + transaction t (db->begin ()); + unique_ptr p (db->load (id)); + + // Now, while the object is loaded, the section is not. If (and + // when) we need to access the section data members, we have to + // load them explicitly. + + cout << p->first () << " " << p->last () << endl; + + db->load (*p, p->extras_section ()); + + // Now the section is loaded and unchanged. + + cout << " " << p->bio () << endl + << " " << p->nicknames ().size () << " nickname(s)" << endl; + + // Update the bio. + // + p->bio ("Joe Dirt is a very clean man indeed..."); + + // Now, the section is marked changed by the bio() modifier. + // Because of that, the following object update will also + // update the section. + // + db->update (*p); + + t.commit (); + } + + // Add a new nickname. + // + { + transaction t (db->begin ()); + + unique_ptr p (db->load (id)); + db->load (*p, p->extras_section ()); + + // Add a new nickname. The nicknames container is now marked + // changed. + // + p->nicknames ().push_back ("Squeaky Clean"); + + // While the section hasn't been marked as changed, a change- + // tracking container that belongs to it has been. As a result, + // the following object update call will automatically mark the + // section as changed and update its state in the database. + // + db->update (*p); + + t.commit (); + } + + // We can also update just the section if we know the rest of + // the object hasn't changed. + // + { + transaction t (db->begin ()); + + unique_ptr p (db->load (id)); + db->load (*p, p->extras_section ()); + + p->nicknames ().push_back ("Dirty Joe"); + db->update (*p, p->extras_section ()); + + t.commit (); + } + + // Load and print the updated object. + // + { + transaction t (db->begin ()); + unique_ptr p (db->load (id)); + db->load (*p, p->extras_section ()); + t.commit (); + + cout << p->first () << " " << p->last () << endl + << " " << p->bio () << endl + << " " << p->nicknames ().size () << " nickname(s)" << endl; + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/section/person.hxx b/odb-examples/section/person.hxx new file mode 100644 index 0000000..996fc19 --- /dev/null +++ b/odb-examples/section/person.hxx @@ -0,0 +1,105 @@ +// file : section/person.hxx +// copyright : not copyrighted - public domain + +#ifndef PERSON_HXX +#define PERSON_HXX + +#include + +#include +#include +#include + +#pragma db object +class person +{ +public: + person (const std::string& first, const std::string& last) + : first_ (first), last_ (last) + { + } + + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + // Biography. + // + const std::string& + bio () const + { + return bio_; + } + + void + bio (const std::string& bio) + { + bio_ = bio; + extras_.change (); // Mark the section as changed. + } + + // Nicknames. + // + typedef odb::vector names; + + const names& + nicknames () const + { + return nicknames_; + } + + names& + nicknames () + { + // Because we are using a change-tracking container (odb::vector), + // ODB will automatically mark the section as changed if we update + // the nicknames. + // + return nicknames_; + } + + // The extras section accessor and modifier. Notice that they are + // by-reference. + // + const odb::section& + extras_section () const + { + return extras_; + } + + odb::section& + extras_section () + { + return extras_; + } + +private: + friend class odb::access; + + person () {} + + #pragma db id auto + unsigned long id_; + + std::string first_; + std::string last_; + + #pragma db section(extras_) + std::string bio_; + + #pragma db section(extras_) + names nicknames_; + + #pragma db load(lazy) update(change) + odb::section extras_; +}; + +#endif // PERSON_HXX diff --git a/odb-examples/section/testscript b/odb-examples/section/testscript new file mode 100644 index 0000000..81566a1 --- /dev/null +++ b/odb-examples/section/testscript @@ -0,0 +1,13 @@ +# file : section/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/odb-examples/sqlite-schema.testscript b/odb-examples/sqlite-schema.testscript new file mode 100644 index 0000000..687f594 --- /dev/null +++ b/odb-examples/sqlite-schema.testscript @@ -0,0 +1,5 @@ +# Note that we currently don't manipulate the data using the sqlite3 utility. +# The database schema is created implicitly by the database object creation +# function called by the test driver. +# +#create_schema_cmd = diff --git a/odb-examples/sqlite.testscript b/odb-examples/sqlite.testscript new file mode 100644 index 0000000..95b2da8 --- /dev/null +++ b/odb-examples/sqlite.testscript @@ -0,0 +1,10 @@ +# file : sqlite.testscript +# license : GNU GPL v2; see accompanying LICENSE file + +# Setup the example driver command line for the subsequent SQLite examples. +# +# Note that for SQLite the schema is created implicitly by the database object +# creation function called by the test driver. +# +test.arguments += $sqlite_options +test.cleanups += &odb-test.db # See database-options.testscript for details. diff --git a/odb-examples/view/README b/odb-examples/view/README new file mode 100644 index 0000000..ef47dfe --- /dev/null +++ b/odb-examples/view/README @@ -0,0 +1,73 @@ +This example shows how to define and use views in ODB. It includes views +that show how to load a subset of data members from objects or columns +from tables, perform aggregate queries, and join multiple objects and +tables using object relationships and custom join conditions. + +The example consists of the following files: + +employee.hxx + Header file defining the 'country', 'employer', and 'employee' persistent + classes. The example also uses the "legacy" 'employee_extra' table that is + not mapped to a persistent class. + + After the persistent classes, this header defines a number of views that + show how to obtain various information from the above object model. + +employee-odb.hxx +employee-odb.ixx +employee-odb.cxx +employee.sql + The first three files contain the database support code and the last file + contains the database schema for the employee.hxx header. + + These files are generated by the ODB compiler from employee.hxx using the + following command line: + + odb --std c++11 -d --generate-schema --generate-query \ + --default-pointer std::shared_ptr --generate-session employee.hxx + + Where stands for the database system we are using, for example, + 'mysql'. + + The --default-pointer option is used to make shared_ptr the default object + pointer. The --generate-session option is used to enable session support + for all the objects which is required to use object loading views. + +database.hxx + Contains the create_database() function which instantiates the concrete + database class corresponding to the database system we are using. + +driver.cxx + Driver for the example. It includes the employee.hxx and employee-odb.hxx + headers to gain access to the persistent classes and views as well as + their database support code. It also includes database.hxx for the + create_database() function declaration. + + In main() the driver first calls create_database() to obtain the database + instance. It then creates the legacy 'employee_extra' table and proceeds + to populate the database with a number of 'country', 'employer', and + 'employee' objects. Once this is done, the driver uses views defined in + employee.hxx to load and print various information about the object model. + +To compile and link the example manually from the command line we can use +the following commands (using MySQL as an example; replace 'c++' with your +C++ compiler name): + +c++ -c employee-odb.cxx +c++ -DDATABASE_MYSQL -c driver.cxx +c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb + +To run the example we may first need to create the database schema (for some +database systems, such as SQLite, the schema is embedded into the generated +code which makes this step unnecessary). Using MySQL as an example, this +can be achieved with the following command: + +mysql --user=odb_test --database=odb_test < employee.sql + +Here we use 'odb_test' as the database login and also 'odb_test' as the +database name. + +Once the database schema is ready, we can run the example (using MySQL as +the database): + +./driver --user odb_test --database odb_test diff --git a/odb-examples/view/buildfile b/odb-examples/view/buildfile new file mode 100644 index 0000000..11f5d5b --- /dev/null +++ b/odb-examples/view/buildfile @@ -0,0 +1,46 @@ +# file : view/buildfile +# license : GNU GPL v2; see accompanying LICENSE file + +import libodb = libodb%lib{odb} + +import libs = libodb-$database%lib{odb-$database} + +exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{employee-odb} testscript + +# The metadata library target which we use to extract the poptions variable +# value for specifying the contained options on the ODB compiler command line. +# +libue{employee-meta}: $libodb + +exe{driver}: libue{employee-meta} $libs + +<{hxx ixx cxx}{employee-odb}>: hxx{employee} libue{employee-meta} $odb +{{ + pops = $cxx.lib_poptions($<[1]) + depdb hash $pops + + depdb dyndep --dyn-target --target-what 'generated schema' --format lines \ + -- echo ($sqlite ? '' : "$out_base/employee.sql") + + $odb --std c++11 \ + --database $database \ + --generate-schema \ + --generate-query \ + --default-pointer std::shared_ptr \ + --generate-session \ + --output-dir $out_base \ + --table-prefix view_ \ + "-I$src_base" $pops \ + $path($<[0]) +}} + +cxx.poptions =+ "-I$out_base" "-I$src_base" -DDATABASE_$ucase($database) + +# Testscript's run-time prerequisites. +# +# @@ BUILD2: Eventually we should be able to mark it as test.input once +# this is supported for testscript tests. +# +exe{driver}: ../alias{database-client}: include = adhoc + +testscript@./: schema = employee diff --git a/odb-examples/view/database.hxx b/odb-examples/view/database.hxx new file mode 100644 index 0000000..6a9a77d --- /dev/null +++ b/odb-examples/view/database.hxx @@ -0,0 +1,95 @@ +// file : view/database.hxx +// copyright : not copyrighted - public domain + +// +// Create concrete database instance based on the DATABASE_* macros. +// + +#ifndef DATABASE_HXX +#define DATABASE_HXX + +#include +#include // std::unique_ptr +#include // std::exit +#include + +#include + +#if defined(DATABASE_MYSQL) +# include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include +#elif defined(DATABASE_PGSQL) +# include +#elif defined(DATABASE_ORACLE) +# include +#elif defined(DATABASE_MSSQL) +# include +#else +# error unknown database; did you forget to define the DATABASE_* macros? +#endif + +inline std::unique_ptr +create_database (int& argc, char* argv[]) +{ + using namespace std; + using namespace odb::core; + + if (argc > 1 && argv[1] == string ("--help")) + { + cout << "Usage: " << argv[0] << " [options]" << endl + << "Options:" << endl; + +#if defined(DATABASE_MYSQL) + odb::mysql::database::print_usage (cout); +#elif defined(DATABASE_SQLITE) + odb::sqlite::database::print_usage (cout); +#elif defined(DATABASE_PGSQL) + odb::pgsql::database::print_usage (cout); +#elif defined(DATABASE_ORACLE) + odb::oracle::database::print_usage (cout); +#elif defined(DATABASE_MSSQL) + odb::mssql::database::print_usage (cout); +#endif + + exit (0); + } + +#if defined(DATABASE_MYSQL) + unique_ptr db (new odb::mysql::database (argc, argv)); +#elif defined(DATABASE_SQLITE) + unique_ptr db ( + new odb::sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + + // Create the database schema. Due to bugs in SQLite foreign key + // support for DDL statements, we need to temporarily disable + // foreign keys. + // + { + connection_ptr c (db->connection ()); + + c->execute ("PRAGMA foreign_keys=OFF"); + + transaction t (c->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + + c->execute ("PRAGMA foreign_keys=ON"); + } +#elif defined(DATABASE_PGSQL) + unique_ptr db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + unique_ptr db (new odb::oracle::database (argc, argv)); +#elif defined(DATABASE_MSSQL) + unique_ptr db ( + new odb::mssql::database (argc, argv, false, "TrustServerCertificate=yes")); +#endif + + return db; +} + +#endif // DATABASE_HXX diff --git a/odb-examples/view/driver.cxx b/odb-examples/view/driver.cxx new file mode 100644 index 0000000..eed0d4b --- /dev/null +++ b/odb-examples/view/driver.cxx @@ -0,0 +1,416 @@ +// file : view/driver.cxx +// copyright : not copyrighted - public domain + +#include // std::unique_ptr, std::shared_ptr +#include + +#include +#include +#include + +#include "database.hxx" // create_database + +#include "employee.hxx" +#include "employee-odb.hxx" + +using namespace std; +using namespace odb::core; + +int +main (int argc, char* argv[]) +{ + try + { + unique_ptr db (create_database (argc, argv)); + + // Create the legacy employee_extra table. + // + { + // First try to drop the table if it exists. + // + { + transaction t (db->begin ()); + try + { +#ifndef DATABASE_ORACLE + db->execute ("DROP TABLE view_employee_extra"); +#else + db->execute ("DROP TABLE \"view_employee_extra\""); +#endif + t.commit (); + } + catch (const odb::exception&) + { + } + } + + { + transaction t (db->begin ()); + +#ifndef DATABASE_ORACLE + db->execute ( + "CREATE TABLE view_employee_extra (" + "employee_id INTEGER NOT NULL," + "vacation_days INTEGER NOT NULL," + "previous_employer_id INTEGER)"); +#else + db->execute ( + "CREATE TABLE \"view_employee_extra\" (" + "\"employee_id\" INTEGER NOT NULL," + "\"vacation_days\" INTEGER NOT NULL," + "\"previous_employer_id\" INTEGER)"); +#endif + + t.commit (); + } + } + + // Create a few persistent objects. + // + { + shared_ptr ca (new country ("CA", "Canada")); + shared_ptr za (new country ("ZA", "South Africa")); + shared_ptr us (new country ("US", "United States")); + shared_ptr se (new country ("SE", "Sweden")); + + shared_ptr st (new employer (1, "Simple Tech Ltd")); + shared_ptr cs (new employer (2, "Complex Systems Inc")); + + shared_ptr e1 ( + new employee (1, "John", "Doe", 29, ca, ca, st)); + + shared_ptr e2 ( + new employee (2, "Jane", "Doe", 30, za, us, cs)); + + shared_ptr e3 ( + new employee (3, "Joe", "Dirt", 31, us, za, st)); + + shared_ptr e4 ( + new employee (4, "Johan", "Johansen", 32, se, se, cs)); + + transaction t (db->begin ()); + + db->persist (ca); + db->persist (za); + db->persist (us); + db->persist (se); + + db->persist (st); + db->persist (cs); + + db->persist (e1); + db->persist (e2); + db->persist (e3); + db->persist (e4); + + // Populate the legacy table. + // +#ifndef DATABASE_ORACLE + db->execute ("INSERT INTO view_employee_extra (" + "employee_id, vacation_days, previous_employer_id) " + "VALUES (1, 5, 2)"); + + db->execute ("INSERT INTO view_employee_extra (" + "employee_id, vacation_days, previous_employer_id) " + "VALUES (2, 10, NULL)"); + + db->execute ("INSERT INTO view_employee_extra (" + "employee_id, vacation_days, previous_employer_id) " + "VALUES (3, 0, NULL)"); + + db->execute ("INSERT INTO view_employee_extra (" + "employee_id, vacation_days, previous_employer_id) " + "VALUES (4, 15, 1)"); +#else + db->execute ("INSERT INTO \"view_employee_extra\" (" + "\"employee_id\", " + "\"vacation_days\", " + "\"previous_employer_id\") " + "VALUES (1, 5, 2)"); + + db->execute ("INSERT INTO \"view_employee_extra\" (" + "\"employee_id\", " + "\"vacation_days\", " + "\"previous_employer_id\") " + "VALUES (2, 10, NULL)"); + + db->execute ("INSERT INTO \"view_employee_extra\" (" + "\"employee_id\", " + "\"vacation_days\", " + "\"previous_employer_id\") " + "VALUES (3, 0, NULL)"); + + db->execute ("INSERT INTO \"view_employee_extra\" (" + "\"employee_id\", " + "\"vacation_days\", " + "\"previous_employer_id\") " + "VALUES (4, 15, 1)"); +#endif + + t.commit (); + } + + // Load names of the employees that are under 31 using the employee_name + // view. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + + result r (db->query (query::age < 31)); + + cout << "Employees under 31" << endl; + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << " " << i->first << " " << i->last << endl; + + cout << endl; + + t.commit (); + } + + // Count the number of employees which has the Doe last name using the + // employee_count view. + // + { + transaction t (db->begin ()); + + // Result of an aggregate query contains only one element so let's + // use the query_value() shortcut. + // + employee_count ec ( + db->query_value ( + query::last == "Doe")); + + cout << ec.count << " employees with the Doe last name" << endl + << endl; + + t.commit (); + } + + // Load the employee-employer information for all the employees with the + // Doe last name using the employee_employer view. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + + // Note that we need to add the object name after query::. + // + result r (db->query (query::employee::last == "Doe")); + + cout << "Employees with the Doe last name" << endl; + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << " " << i->first << " " << i->last << " " + << i->employer_name << endl; + + cout << endl; + + t.commit (); + } + + // Calculate min/max employee ages for each employer. + // + { + typedef odb::result result; + + transaction t (db->begin ()); + + result r (db->query ()); + + // Some other interesting queries to try: + // + // This one restricts the calculation to a specific employer: + // + // typedef odb::query query; + // + // result r (db->query ( + // query::employer::name == "Simple Tech Ltd")); + // + // And this one filters the employees based on certain criteria. + // + // result r (db->query ( + // query::employee::last == "Doe")); + // + + cout << "Min/max employee ages" << endl; + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << " " << i->employer_name << " " + << i->min_age << '/' << i->max_age << endl; + + cout << endl; + + t.commit (); + } + + // Load the country information for employees with different residence + // and nationality. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + + // Note that we use the alias given in the db object pragma after + // query::. + // + result r (db->query ( + query::res_country::name != query::nat_country::name)); + + cout << "Employees residing outside of country of nationality" << endl; + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << " " << i->first << " " << i->last << " " + << i->res_country_name << " " << i->nat_country_name << endl; + + cout << endl; + + t.commit (); + } + + // The same but using the object loading view. + // + { + typedef odb::query query; + typedef odb::result result; + + transaction t (db->begin ()); + + // We have to use a session in order for the object pointers + // in our view and object pointers inside objects that we load + // to point to the same instances, where appropriate. + // + session s; + + result r (db->query ( + query::res::name == query::nat::name)); + + cout << "Employees residing inside the country of nationality" << endl; + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + assert (i->e->nationality () == i->nat); + assert (i->e->residence () == i->res); + + const employee& e (*i->e); + const country& r (*i->res); + const country& n (*i->nat); + + cout << " " << e.first () << " " << e.last () << " " + << r.name () << " " << n.name () << endl; + } + + cout << endl; + + t.commit (); + } + + // Get the list of employers that have any employees. + // + { + typedef odb::result result; + + shared_ptr es (new employer (3, "Empty Shell LLC")); + + transaction t (db->begin ()); + db->persist (es); + + result r (db->query ()); + + cout << "Employers with employees" << endl; + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << " " << i->e->name () << endl; + + cout << endl; + + db->erase (es); + t.commit (); + } + + // Get the list of employees that have accumulated vacation days. + // + { + typedef odb::result result; + + transaction t (db->begin ()); + + // With native views we have to use the native SQL query syntax. + // +#ifndef DATABASE_ORACLE + result r (db->query ("vacation_days <> 0")); +#else + result r (db->query ("\"vacation_days\" <> 0")); +#endif + + cout << "Employees with accumulated vacation days" << endl; + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << " " << i->id << " " << i->days << endl; + + cout << endl; + + t.commit (); + } + + // Get the list of employees that have accumulated vacation days, this + // time using the improved employee_vacation2 view. + // + { + typedef odb::result result; + + transaction t (db->begin ()); + +#ifndef DATABASE_ORACLE + result r (db->query ("vacation_days <> 0")); +#else + result r (db->query ("\"vacation_days\" <> 0")); +#endif + + cout << "Employees with accumulated vacation days (take 2)" << endl; + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + cout << " " << i->first << " " << i->last << " " << i->days << endl; + + cout << endl; + + t.commit (); + } + + // Show the previous employers using the employee_prev_employer view. + // + { + typedef odb::result result; + + transaction t (db->begin ()); + + result r (db->query ()); + + cout << "Previous employees" << endl; + + for (result::iterator i (r.begin ()); i != r.end (); ++i) + { + const nullable& pe (i->prev_employer_name); + + cout << " " << i->first << " " << i->last << " " + << (pe.null () ? string ("N/A") : *pe) << endl; + } + + cout << endl; + + t.commit (); + } + } + catch (const odb::exception& e) + { + cerr << e.what () << endl; + return 1; + } +} diff --git a/odb-examples/view/employee.hxx b/odb-examples/view/employee.hxx new file mode 100644 index 0000000..3087b62 --- /dev/null +++ b/odb-examples/view/employee.hxx @@ -0,0 +1,350 @@ +// file : view/employee.hxx +// copyright : not copyrighted - public domain + +#ifndef EMPLOYEE_HXX +#define EMPLOYEE_HXX + +#include +#include // shared_ptr +#include // std::size_t + +#include +#include + +#pragma db object +class country +{ +public: + country (const std::string& code, const std::string& name) + : code_ (code), name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + +private: + friend class odb::access; + + country () {} + + #pragma db id + std::string code_; // ISO 2-letter country code. + + std::string name_; +}; + +#pragma db object +class employer +{ +public: + employer (unsigned long id, const std::string& name) + : id_ (id), name_ (name) + { + } + + const std::string& + name () const + { + return name_; + } + +private: + friend class odb::access; + + employer () {} + + #pragma db id + unsigned long id_; + + std::string name_; +}; + +#pragma db object +class employee +{ +public: + employee (unsigned long id, + const std::string& first, + const std::string& last, + unsigned short age, + std::shared_ptr res, + std::shared_ptr nat, + std::shared_ptr e) + : id_ (id), first_ (first), last_ (last), age_ (age), + residence_ (res), + nationality_ (nat), + employed_by_ (e) + { + } + + // Name. + // + const std::string& + first () const + { + return first_; + } + + const std::string& + last () const + { + return last_; + } + + // Age. + // + unsigned short + age () const + { + return age_; + } + + // Employer. + // + std::shared_ptr + employed_by () const + { + return employed_by_; + } + + // Residence and nationality. + // + std::shared_ptr + residence () const + { + return residence_; + } + + std::shared_ptr + nationality () const + { + return nationality_; + } + +private: + friend class odb::access; + + employee () {} + + #pragma db id + unsigned long id_; + + std::string first_; + std::string last_; + + unsigned short age_; + + std::shared_ptr residence_; + std::shared_ptr nationality_; + + std::shared_ptr employed_by_; +}; + +// We also have the "legacy" employee_extra table that is not mapped to any +// persistent class. It has the following columns: +// +// CREATE TABLE employee_extra( +// employee_id INTEGER NOT NULL, +// vacation_days INTEGER NOT NULL, +// previous_employer_id INTEGER) +// + +// A simple view with a single associated object. It allows us to get +// the name of an employee without loading any of the other parts, such +// as the referenced country and employer objects. The first and last +// data members in the view are automatically associated to the first_ +// and last_ members in the employee object. +// +#pragma db view object(employee) +struct employee_name +{ + std::string first; + std::string last; +}; + +// A simple aggregate view. It allows us to count the number of employees +// matching certain criteria. Here we use a column expression with a +// reference to the id_ data member in the employee object. +// +#pragma db view object(employee) +struct employee_count +{ + #pragma db column("count(" + employee::id_ + ")") + std::size_t count; +}; + +// A simple view with two associated object. It allows us to get the +// name of an employee and its employer without loading any other parts. +// Because there is an unambiguous relationship between the employee and +// employer objects (employee::employed_by_), the ODB compiler is able to +// automatically use this relationship as a join condition. Also, similar +// to the employee_name view, the first and last data members are auto- +// associated to the first_ and last_ members in the employee object. +// For the employer_name member we provide an explicit member reference. +// +#pragma db view object(employee) object(employer) +struct employee_employer +{ + std::string first; + std::string last; + + #pragma db column(employer::name_) + std::string employer_name; +}; + +// A more interesting aggregate view that uses the GROUP BY clause. It +// allows us to calculate the min/max ages of employees for each employer. +// Here we use the query condition with a placeholder (?). +// +#pragma db view object(employee) object(employer) \ + query ((?) + "GROUP BY" + employer::name_) +struct employer_age +{ + #pragma db column(employer::name_) + std::string employer_name; + + #pragma db column("min(" + employee::age_ + ")") + unsigned short min_age; + + #pragma db column("max(" + employee::age_ + ")") + unsigned short max_age; +}; + +// A more complex view with three associated objects, two of which are +// of the same type. This requires us to use aliases and disambiguate +// the relationships used to associate each object. +// +#pragma db view object(employee) \ + object(country = res_country: employee::residence_) \ + object(country = nat_country: employee::nationality_) +struct employee_country +{ + std::string first; + std::string last; + + #pragma db column(res_country::name_) + std::string res_country_name; + + #pragma db column(nat_country::name_) + std::string nat_country_name; +}; + +// An example of an object loading view. It is a different version of +// the above view that loads the complete objects instead of a subset +// of their data members. +// +#pragma db view object(employee) \ + object(country = res: employee::residence_) \ + object(country = nat: employee::nationality_) +struct employee_country_objects +{ + std::shared_ptr e; + std::shared_ptr res; + std::shared_ptr nat; +}; + +// An example of using inner join type. Here we want to find employers +// that have any employees. If we were to use the default left join type, +// then we would have gotten all the employers, regardless of whether +// they have any employees. By using the inner join, we make sure that +// only matching employers are returned. +// +// It is also likely that there will be more than one employee for any +// particular employer which will lead to duplicate employer records +// being returned. To avoid this we use the 'distinct' result modifier. +// +// Try to change the join type or remove 'distinct' to observe the +// change in behavior. +// +#pragma db view object(employer) object(employee inner) query(distinct) +struct employer_with_employees +{ + std::shared_ptr e; +}; + +// An example of a native view that provides a complete query and is based +// on an ad-hoc table. This view allows us to load the employee vacation +// information from the legacy employee_extra table. +// +#ifndef ODB_DATABASE_ORACLE + #pragma db view query("SELECT employee_id, vacation_days " \ + "FROM view_employee_extra") +#else + #pragma db view query("SELECT \"employee_id\", \"vacation_days\" " \ + "FROM \"view_employee_extra\"") +#endif +struct employee_vacation +{ + #pragma db type("INTEGER") + unsigned long id; + + #pragma db type("INTEGER") + unsigned short days; +}; + +// A more robust implementation of the above view as a table view instead +// of a native view. +// +#pragma db view table("view_employee_extra") +struct employee_vacation1 +{ + #pragma db column("employee_id") type("INTEGER") + unsigned long id; + + #pragma db column("vacation_days") type("INTEGER") + unsigned short days; +}; + +// An improved version of the previous view that extracts the employee +// first and last names instead of the id. To get the names we need to +// add the employee object to this view and use a custom join condition +// to tie it up with our legacy table. +// +#ifndef ODB_DATABASE_ORACLE + #pragma db view table("view_employee_extra") \ + object(employee: "view_employee_extra.employee_id = " + employee::id_) +#else + #pragma db view table("view_employee_extra") \ + object(employee: "\"view_employee_extra\".\"employee_id\" = " + \ + employee::id_) +#endif +struct employee_vacation2 +{ + std::string first; + std::string last; + + #pragma db column("view_employee_extra.vacation_days") type("INTEGER") + unsigned short days; +}; + +// A mixed view that associates two objects and a legacy table. It returns +// the previous employer information for each employee. +// +#ifndef ODB_DATABASE_ORACLE + #pragma db view object(employee) \ + table("view_employee_extra" = "extra": \ + "extra.employee_id = " + employee::id_) \ + object(employer: "extra.previous_employer_id = " + employer::id_) +#else + #pragma db view object(employee) \ + table("view_employee_extra" = "extra": \ + "\"extra\".\"employee_id\" = " + employee::id_) \ + object(employer: "\"extra\".\"previous_employer_id\" = " + employer::id_) +#endif +struct employee_prev_employer +{ + std::string first; + std::string last; + + // If previous_employer_id is NULL, then the name will be NULL as well. + // We use the odb::nullable wrapper to handle this. + // + #pragma db column(employer::name_) + odb::nullable prev_employer_name; +}; + +#endif // EMPLOYEE_HXX diff --git a/odb-examples/view/testscript b/odb-examples/view/testscript new file mode 100644 index 0000000..d8be673 --- /dev/null +++ b/odb-examples/view/testscript @@ -0,0 +1,13 @@ +# file : view/testscript +# license : GNU GPL v2; see accompanying LICENSE file + +.include ../database-options.testscript +.include ../$(database).testscript + ++if! $sqlite + $create_schema +end + +: basics +: +$* >| diff --git a/optimistic/README b/optimistic/README deleted file mode 100644 index 0c16ed2..0000000 --- a/optimistic/README +++ /dev/null @@ -1,64 +0,0 @@ -This example shows how to use optimistic concurrency in ODB. - -The example consists of the following files: - -person.hxx - Header file defining the 'person' persistent class. Besides the standard - persistent class pragmas, this definition also uses the 'optimistic' - pragma to indicate to the ODB compiler that the class must support - optimistic concurrency. It also uses the 'version' pragma to specify - which data member will contain the object version. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-schema person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance and persists a sample 'person' object. It then emulates the - parallel execution of two processes that try to concurrently update or - delete this object. For each step the driver prints the versions of the - object as seen by each process. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/optimistic/database.hxx b/optimistic/database.hxx deleted file mode 100644 index e81f6a7..0000000 --- a/optimistic/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : optimistic/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/optimistic/driver.cxx b/optimistic/driver.cxx deleted file mode 100644 index 25bc9af..0000000 --- a/optimistic/driver.cxx +++ /dev/null @@ -1,158 +0,0 @@ -// file : optimistic/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - // Persist the object. - // - // At this point the initial version (1) is assigned. - // - unsigned long id; - { - person p ("John", "Doe", 21); - - transaction t (db->begin ()); - id = db->persist (p); - t.commit (); - - cout << "version after persist: " << p.version () << endl; - } - - // Process 1: load the object. - // - person p1; - { - transaction t (db->begin ()); - db->load (id, p1); - t.commit (); - - cout << "process 1 version after load: " << p1.version () << endl; - } - - // Process 2: load the object. - // - person p2; - { - transaction t (db->begin ()); - db->load (id, p2); - t.commit (); - - cout << "process 2 version after load: " << p2.version () << endl; - } - - // Process 1: update the object. - // - // At this point the version is incremented and becomes 2. - // - { - p1.age (20); // Correct the wrong age. - - transaction t (db->begin ()); - db->update (p1); - t.commit (); - - cout << "process 1 version after update: " << p1.version () << endl; - } - - // Process 2: update the object. - // - // Since the object version in this process is 1 while in the database - // it is 2, this operation will fail. - // - { - p2.age (p2.age () + 1); // Increment the age. - - transaction t (db->begin ()); - - try - { - db->update (p2); - } - catch (const object_changed&) - { - cout << "process 2 version is out of date: " << p2.version () << endl; - - // Reload the object and retry the operation. Note that the second - // update call cannot throw object_changed since we reloaded the - // object and are trying to update it in a single transaction. - // - db->reload (p2); - - cout << "process 2 version after reload: " << p2.version () << endl; - - p2.age (p2.age () + 1); - db->update (p2); - } - - t.commit (); - - cout << "process 2 version after update: " << p2.version () << endl; - cout << "final age value: " << p2.age () << endl; - } - - // Process 1: delete the object if the person is younger than 21. - // - // Since the object version in this process is 2 while in the database - // it is 3, this operation will fail. Note that this will only hold - // true if we are deleting the object by passing an object instance - // to the erase() function. If instead we pass object id, then the - // object will be deleted regardless of the version. - // - if (p1.age () < 21) - { - transaction t (db->begin ()); - - try - { - db->erase (p1); - // db->erase (id); // Never throws object_changed. - } - catch (const object_changed&) - { - cout << "process 1 version is out of date: " << p1.version () << endl; - - // Reload the object and retry the operation. Similar to update, the - // second erase call cannot throw object_changed since we reloaded - // the object and are trying to erase it in a single transaction. - // - db->reload (p1); - - cout << "process 1 version after reload: " << p2.version () << endl; - - if (p1.age () < 21) - { - db->erase (p1); - cout << "object deleted" << endl; - } - else - cout << "object not deleted" << endl; - } - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/optimistic/makefile b/optimistic/makefile deleted file mode 100644 index a9db03e..0000000 --- a/optimistic/makefile +++ /dev/null @@ -1,125 +0,0 @@ -# file : optimistic/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema \ ---table-prefix optimistic_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/optimistic/person.hxx b/optimistic/person.hxx deleted file mode 100644 index 5b7177f..0000000 --- a/optimistic/person.hxx +++ /dev/null @@ -1,67 +0,0 @@ -// file : optimistic/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include - -#include - -#pragma db object optimistic -class person -{ -public: - person () {} - person (const std::string& first, - const std::string& last, - unsigned short age) - : first_ (first), last_ (last), age_ (age) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - unsigned short - age () const - { - return age_; - } - - void - age (unsigned short age) - { - age_ = age; - } - - unsigned long - version () const - { - return version_; - } - -private: - friend class odb::access; - - #pragma db id auto - unsigned long id_; - - #pragma db version - unsigned long version_; - - std::string first_; - std::string last_; - unsigned short age_; -}; - -#endif // PERSON_HXX diff --git a/oracle-driver.bat b/oracle-driver.bat deleted file mode 100644 index cf08e46..0000000 --- a/oracle-driver.bat +++ /dev/null @@ -1,42 +0,0 @@ -@echo off -rem file : oracle-driver.bat -rem license : GNU GPL v2; see accompanying LICENSE file - -rem -rem oracle-driver.bat sql-file -rem -rem Run the oracle client on the SQL file specified. Adjust the -rem options below to match your Oracle setup. -rem - -setlocal - -set "options=%ORACLE_OPTIONS% -L -S" -set "options=%options% odb_test/odb_test" -rem set "options=%options% odb_test/odb_test@//192.168.0.5:1521/xe" - -set "oracle=%ORACLE_CLIENT%" - -if "_%oracle%_" == "__" set "oracle=sqlplus" - -if "_%1_" == "__" ( - echo no sql file specified - goto usage -) - -%oracle% %options% @%1 - -if errorlevel 1 goto error -goto end - -:usage -echo. -echo usage: oracle-driver.bat sql-file -echo. - -:error -endlocal -exit /b 1 - -:end -endlocal diff --git a/oracle.options b/oracle.options deleted file mode 100644 index f01413e..0000000 --- a/oracle.options +++ /dev/null @@ -1,9 +0,0 @@ -# Sample Oracle options file used to run the tests. Adjust to -# match your Oracle setup. -# - ---user odb_test ---password odb_test -# --host -# --port -# --service diff --git a/pgsql-driver.bat b/pgsql-driver.bat deleted file mode 100644 index 5240bc5..0000000 --- a/pgsql-driver.bat +++ /dev/null @@ -1,50 +0,0 @@ -@echo off -rem file : pgsql-driver.bat -rem license : GNU GPL v2; see accompanying LICENSE file - -rem -rem pgsql-driver.bat sql-file -rem -rem Run the pgsql client on the SQL file specified. Adjust the -rem options below to match your PostgreSQL setup. -rem - -setlocal - -set "options=%PGSQL_OPTIONS%" - -rem This user must be able to login without specifying a password. -rem -set "options=%options% --username=odb_test" - -set "options=%options% --dbname=odb_test" -rem set "options=%options% --host=" -rem set "options=%options% --port=" -set "options=%options% --quiet" -set "PGOPTIONS=--client-min-messages=warning" - -set "pgsql=%PGSQL_CLIENT%" - -if "_%pgsql%_" == "__" set "pgsql=psql" - -if "_%1_" == "__" ( - echo no sql file specified - goto usage -) - -%pgsql% %options% < %1 - -if errorlevel 1 goto error -goto end - -:usage -echo. -echo usage: pgsql-driver.bat sql-file -echo. - -:error -endlocal -exit /b 1 - -:end -endlocal diff --git a/pgsql.options b/pgsql.options deleted file mode 100644 index 841de56..0000000 --- a/pgsql.options +++ /dev/null @@ -1,10 +0,0 @@ -# Sample PostgreSQL options file used to run the tests. Adjust to -# match your PostgreSQL setup. -# - -# This use must be able to login without specifying a password. -# ---user odb_test ---database odb_test -# --host -# --port diff --git a/pimpl/README b/pimpl/README deleted file mode 100644 index da12899..0000000 --- a/pimpl/README +++ /dev/null @@ -1,62 +0,0 @@ -This example shows how to use virtual data members to implement a persistent -class that employs the pimpl C++ idiom. - -The example consists of the following files: - -person.hxx -person.cxx - Header and source file implementing the 'person' persistent class that - uses the pimpl idiom. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-query --generate-schema person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent class and its database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. Then it executes a number of database transactions on the 'person' - objects. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person.cxx -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/pimpl/database.hxx b/pimpl/database.hxx deleted file mode 100644 index 7b054ea..0000000 --- a/pimpl/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : pimpl/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/pimpl/driver.cxx b/pimpl/driver.cxx deleted file mode 100644 index b97fd92..0000000 --- a/pimpl/driver.cxx +++ /dev/null @@ -1,52 +0,0 @@ -// file : pimpl/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - { - person john ("john@doe.com", "John Doe", 31); - person jane ("jane@doe.com", "Jane Doe", 29); - - transaction t (db->begin ()); - db->persist (john); - db->persist (jane); - t.commit (); - } - - { - typedef odb::result result; - - transaction t (db->begin ()); - result r (db->query ()); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << i->name () << ' ' << i->email () << ' ' << i->age () << endl; - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/pimpl/makefile b/pimpl/makefile deleted file mode 100644 index a0aa290..0000000 --- a/pimpl/makefile +++ /dev/null @@ -1,126 +0,0 @@ -# file : pimpl/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx person.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --generate-query \ ---table-prefix pimpl_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_sources := $(filter-out driver.cxx,$(cxx_tun)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/pimpl/person.cxx b/pimpl/person.cxx deleted file mode 100644 index 6922afc..0000000 --- a/pimpl/person.cxx +++ /dev/null @@ -1,71 +0,0 @@ -// file : pimpl/person.cxx -// copyright : not copyrighted - public domain - -#include "person.hxx" - -using namespace std; - -struct person::impl -{ - impl () {} - impl (const string& e, const string& n, unsigned short a) - : email (e), name (n), age (a) {} - - string email; - string name; - unsigned short age; -}; - -person:: -~person () -{ - delete pimpl_; -} - -person:: -person () - : pimpl_ (new impl) -{ -} - -person:: -person (const string& e, const string& n, unsigned short a) - : pimpl_ (new impl (e, n, a)) -{ -} - -const string& person:: -email () const -{ - return pimpl_->email; -} - -void person:: -email (const string& e) -{ - pimpl_->email = e; -} - -const string& person:: -name () const -{ - return pimpl_->name; -} - -void person:: -name (const string& n) -{ - pimpl_->name = n; -} - -unsigned short person:: -age () const -{ - return pimpl_->age; -} - -void person:: -age (unsigned short a) const -{ - pimpl_->age = a; -} diff --git a/pimpl/person.hxx b/pimpl/person.hxx deleted file mode 100644 index d296c28..0000000 --- a/pimpl/person.hxx +++ /dev/null @@ -1,56 +0,0 @@ -// file : pimpl/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include - -#include - -#pragma db object -class person -{ -public: - ~person (); - person (const std::string& email, - const std::string& name, - unsigned short age); - - const std::string& - email () const; - - void - email (const std::string&); - - const std::string& - name () const; - - void - name (const std::string&); - - unsigned short - age () const; - - void - age (unsigned short) const; - -private: - person (const person&); - person& operator= (const person&); - -private: - friend class odb::access; - person (); - - struct impl; - - #pragma db transient - impl* pimpl_; - - #pragma db member(email) virtual(std::string) id - #pragma db member(name) virtual(std::string) - #pragma db member(age) virtual(unsigned short) -}; - -#endif // PERSON_HXX diff --git a/prepared/README b/prepared/README deleted file mode 100644 index 1fc6a0f..0000000 --- a/prepared/README +++ /dev/null @@ -1,65 +0,0 @@ -This example shows how to use prepared queries. In particular, it includes -examples of cached and uncached queries, with and without by-reference -parameters, as well as the use of a prepared query factory. - -The example consists of the following files: - -person.hxx - Header file defining the 'person' persistent class as well as the - 'person_count' view. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-query --generate-prepared \ ---generate-schema person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The --generate-prepared option requests the generation of the prepared - query support code. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance and creates a number of persistent objects. It then prepares and - executes a number of queries to illustrate various usage scenarios. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/prepared/database.hxx b/prepared/database.hxx deleted file mode 100644 index 2e9316a..0000000 --- a/prepared/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : prepared/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/prepared/driver.cxx b/prepared/driver.cxx deleted file mode 100644 index c5b5b22..0000000 --- a/prepared/driver.cxx +++ /dev/null @@ -1,250 +0,0 @@ -// file : prepared/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr/unique_ptr -#include -#include // std::move() -#include - -#include -#include -#include - -#include // ODB_CXX11 - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -struct params -{ - unsigned short age; - string first; -}; - -static void -query_factory (const char* name, connection& c) -{ - typedef odb::query query; - -#ifdef ODB_CXX11 - unique_ptr p (new params); - query q (query::age > query::_ref (p->age) && - query::first == query::_ref (p->first)); - prepared_query pq (c.prepare_query (name, q)); - c.cache_query (pq, move (p)); -#else - auto_ptr p (new params); - query q (query::age > query::_ref (p->age) && - query::first == query::_ref (p->first)); - prepared_query pq (c.prepare_query (name, q)); - c.cache_query (pq, p); -#endif -} - -static void -print_ages (unsigned short age, odb::result r) -{ - cout << "over " << age << ':'; - - for (odb::result::iterator i (r.begin ()); i != r.end (); ++i) - cout << ' ' << i->age (); - - cout << endl; -} - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - // Create a few persistent person objects. - // - { - person p1 ("John", "First", 91); - person p2 ("John", "Second", 81); - person p3 ("John", "Third", 71); - person p4 ("John", "Fourth", 61); - person p5 ("John", "Fifth", 51); - - transaction t (db->begin ()); - db->persist (p1); - db->persist (p2); - db->persist (p3); - db->persist (p4); - db->persist (p5); - t.commit (); - } - - typedef odb::query query; - typedef odb::prepared_query prep_query; - typedef odb::result result; - - // Example of an uncached prepared query in the same transaction. - // - { - transaction t (db->begin ()); - - unsigned short age; - query q (query::age > query::_ref (age)); - prep_query pq (db->prepare_query ("person-age-query", q)); - - for (age = 90; age > 40; age -= 10) - { - result r (pq.execute ()); - print_ages (age, r); - } - - t.commit (); - } - - // Example of an uncached prepared query in multiple transactions. - // - // Note that here we have to first obtain a connection, then prepare - // the query using this connection, and finally start each transaction - // that uses the prepared query on this connection. - // - { - connection_ptr conn (db->connection ()); - - unsigned short age; - query q (query::age > query::_ref (age)); - prep_query pq (conn->prepare_query ("person-age-query", q)); - - for (age = 90; age > 40; age -= 10) - { - transaction t (conn->begin ()); - - result r (pq.execute ()); - print_ages (age, r); - - t.commit (); - } - } - - // Example of a cached prepared query without by-reference parameters. - // - for (unsigned short i (0); i < 5; ++i) - { - transaction t (db->begin ()); - - prep_query pq (db->lookup_query ("person-val-age-query")); - - if (!pq) - { - pq = db->prepare_query ( - "person-val-age-query", query::age > 50); - db->cache_query (pq); - } - - result r (pq.execute ()); - print_ages (50, r); - - t.commit (); - } - - // Example of a cached prepared query with by-reference parameters. - // - for (unsigned short age (90); age > 40; age -= 10) - { - transaction t (db->begin ()); - - unsigned short* age_param; - prep_query pq ( - db->lookup_query ("person-ref-age-query", age_param)); - - if (!pq) - { -#ifdef ODB_CXX11 - unique_ptr p (new unsigned short); - age_param = p.get (); - query q (query::age > query::_ref (*age_param)); - pq = db->prepare_query ("person-ref-age-query", q); - db->cache_query (pq, move (p)); -#else - auto_ptr p (new unsigned short); - age_param = p.get (); - query q (query::age > query::_ref (*age_param)); - pq = db->prepare_query ("person-ref-age-query", q); - db->cache_query (pq, p); // Assumes ownership of p. -#endif - } - - *age_param = age; // Initialize the parameter. - result r (pq.execute ()); - print_ages (age, r); - - t.commit (); - } - - // Example of a cached prepared query that uses a query factory. - // - db->query_factory ("person-age-name-query", &query_factory); - - for (unsigned short age (90); age > 40; age -= 10) - { - transaction t (db->begin ()); - - params* p; - prep_query pq (db->lookup_query ("person-age-name-query", p)); - assert (pq); - - p->age = age; - p->first = "John"; - result r (pq.execute ()); - print_ages (age, r); - - t.commit (); - } - - // In C++11 the above call to query_factory() can be re-written to - // use a lambda function, for example: - // - /* - db->query_factory ( - "person-age-name-query", - [] (const char* name, connection& c) - { - unique_ptr p (new params); - query q (query::age > query::_ref (p->age) && - query::first == query::_ref (p->first)); - prepared_query pq (c.prepare_query (name, q)); - c.cache_query (pq, std::move (p)); - }); - */ - - // Prepared queries can also be used with views, as shown in the - // following example. - // - { - typedef odb::query query; - typedef odb::prepared_query prep_query; - - transaction t (db->begin ()); - - unsigned short age; - query q (query::age > query::_ref (age)); - prep_query pq ( - db->prepare_query ("person-count-age-query", q)); - - // Because an aggregate query result always contains one element, - // we use execute_value() insetad of execute() as a shortcut: - // - for (age = 90; age > 40; age -= 10) - cout << "over " << age << ": " << pq.execute_value ().count << endl; - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/prepared/makefile b/prepared/makefile deleted file mode 100644 index d8ebcf5..0000000 --- a/prepared/makefile +++ /dev/null @@ -1,125 +0,0 @@ -# file : prepared/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-query --generate-schema \ ---generate-prepared -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/prepared/person.hxx b/prepared/person.hxx deleted file mode 100644 index dc8e6fe..0000000 --- a/prepared/person.hxx +++ /dev/null @@ -1,61 +0,0 @@ -// file : prepared/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include -#include // std::size_t - -#include - -#pragma db object -class person -{ -public: - person (const std::string& first, - const std::string& last, - unsigned short age) - : first_ (first), last_ (last), age_ (age) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - unsigned short - age () const - { - return age_; - } - -private: - friend class odb::access; - - person () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - unsigned short age_; -}; - -#pragma db view object(person) -struct person_count -{ - #pragma db column("count(" + person::id_ + ")") - std::size_t count; -}; - -#endif // PERSON_HXX diff --git a/qt/README b/qt/README deleted file mode 100644 index bfbe632..0000000 --- a/qt/README +++ /dev/null @@ -1,77 +0,0 @@ -This example shows how to persist objects that use Qt smart pointers, -containers, and value types with the help of the Qt profile library -(libodb-qt). - -The example consists of the following files: - -employee.hxx - Header file defining the 'employee' and 'employer' persistent classes. - We use QSharedPointer/QWeakPointer smart pointers provided by Qt (as - well as their lazy versions provided by the Qt profile library) to - establish a bidirectional employee-employer relationship. The QList - type is used to store the collection of employees employed by the - employer. We also use the QDateTime type to store the employee's date - of birth and QString to store the employee's first and last name. While - the employee's object id is QUuid and a QSet instance keeps track of - the employee's email addresses. Finally we use QByteArray to store the - employee's public key. - -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx -employee.sql - The first three files contain the database support code and the last file - contains the database schema for the employee.hxx header. - - These files are generated by the ODB compiler from employee.hxx using the - following command line: - - odb -d --profile qt --generate-schema --generate-query \ - --generate-session employee.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The -p option is used to instruct the ODB compiler to load the Qt profile. - The --generate-session option is used to enable session support for all - the persistent classes in employee.hxx. - -database.hxx - Contains the createDatabase() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the employee.hxx and employee-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the createDatabase() function - declaration. - - In main() the driver first calls createDatabase() to obtain the database - instance. It then creates a number of 'Employee' and 'Employer' objects and - persists them in the database. The next transaction loads all the employees - of a particular employer using the employee-employer relationship. Finally, - the driver performs a database query which uses data member of the Qt - QString and QDate types in its criterion. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c employee-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o employee-odb.o -lodb-qt -lodb-mysql -lodb -lQtCore - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < employee.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/qt/database.hxx b/qt/database.hxx deleted file mode 100644 index 3823c5d..0000000 --- a/qt/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : qt/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -createDatabase (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/qt/driver.cxx b/qt/driver.cxx deleted file mode 100644 index 377594f..0000000 --- a/qt/driver.cxx +++ /dev/null @@ -1,180 +0,0 @@ -// file : qt/driver.cxx -// copyright : not copyrighted - public domain - -#include - -#include - -#include -#include -#include - -#include "database.hxx" // createDatabase - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace odb::core; - -ostream& -operator<< (ostream& os, const QString& s) -{ - return os << s.toStdString (); -} - -int -main (int argc, char* argv[]) -{ - QCoreApplication app (argc, argv); - - try - { - auto_ptr db (createDatabase (argc, argv)); - - // Create a few persistent objects. - // - { - // Simple Tech Ltd. - // - { - QSharedPointer er (new Employer ("Simple Tech Ltd")); - - QSharedPointer john ( - new Employee ("John", - "Doe", - QDate (1975, 1, 1), - QByteArray ("\0xF1\0x00\0x34\0x45\0x00\0xDE", 6), - er)); - - QSharedPointer jane ( - new Employee ("Jane", - "Doe", - QDate (1976, 2, 2), - QByteArray ("\0xD7\0x00\0x14", 3), - er)); - - john->emails ().insert ("john_d@example.com"); - john->emails ().insert ("john.doe@simple.com"); - jane->emails ().insert ("jane_d@example.com"); - jane->emails ().insert ("jane.doe@simple.com"); - - // Set the inverse side of the employee-employer relationship. - // - er->employees ().push_back (john); - er->employees ().push_back (jane); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (john); - db->persist (jane); - - t.commit (); - } - - // Complex Systems Inc. - // - { - QSharedPointer er (new Employer ("Complex Systems Inc")); - - QSharedPointer john ( - new Employee ("John", - "Smith", - QDate (1977, 3, 3), - QByteArray ("\0x23\0xFD\0x8F\0x00", 4), - er)); - - QSharedPointer jane ( - new Employee ("Jane", - "Smith", - QDate (1978, 4, 4), - QByteArray ("0x00\0x32\0x00\0x01\0x00", 5), - er)); - - john->emails ().insert ("john_s@example.com"); - john->emails ().insert ("john.smith@complex.com"); - jane->emails ().insert ("jane_s@example.com"); - jane->emails ().insert ("jane.smith@complex.com"); - - // Set the inverse side of the employee-employer relationship. - // - er->employees ().push_back (john); - er->employees ().push_back (jane); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (john); - db->persist (jane); - - t.commit (); - } - } - - // Load Simple Tech Ltd and print its employees. - // - { - session s; - transaction t (db->begin ()); - - QSharedPointer stl (db->load ("Simple Tech Ltd")); - - Employees& es (stl->employees ()); - - for (Employees::iterator i (es.begin ()); i != es.end (); ++i) - { - QLazyWeakPointer& lwp (*i); - - // Load and lock the employee and his employer. - // - QSharedPointer p (lwp.load ()); - QSharedPointer pe (p->employer ().load ()); - - cout << p->first () << " " << p->last () << endl - << " born: " << p->born ().toString () << endl; - - for (Emails::const_iterator j (p->emails ().begin ()), - e (p->emails ().end ()); j != e; ++j) - { - cout << " email: " << *j << endl; - } - - cout << " public key length: " << p->publicKey ().size () << endl - << " employer: " << pe->name () << endl - << " id: " << p->id ().toString () << endl - << endl; - } - - t.commit (); - } - - // Search for Complex Systems Inc employees that were born before - // April 1978. - // - { - typedef odb::query query; - typedef odb::result result; - - session s; - transaction t (db->begin ()); - - result r (db->query ( - query::employer->name == "Complex Systems Inc" && - query::born < QDate (1978, 4, 1))); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << i->first () << " " << i->last () - << " " << i->born ().toString () << endl; - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/qt/employee.hxx b/qt/employee.hxx deleted file mode 100644 index 82bbcfb..0000000 --- a/qt/employee.hxx +++ /dev/null @@ -1,167 +0,0 @@ -// file : qt/employee.hxx -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -// Forward declarations. -// -class Employee; - -typedef QSet Emails; -typedef QList > Employees; - -#pragma db object -class Employer -{ -public: - - Employer (const QString& name) - : name_ (name) - { - } - - const QString& - name () const - { - return name_; - } - - const Employees& - employees () const - { - return employees_; - } - - Employees& - employees () - { - return employees_; - } - -private: - friend class odb::access; - - Employer () {} - - #pragma db id - QString name_; - - #pragma db value_not_null inverse(employer_) - Employees employees_; -}; - -#pragma db object -class Employee -{ -public: - - Employee (const QString& first, - const QString& last, - const QDate& born, - const QByteArray& publicKey, - QSharedPointer employer) - : id_ (QUuid::createUuid ()), - first_ (first), - last_ (last), - born_ (born), - publicKey_ (publicKey), - employer_ (employer) - { - } - - // Id. - // - const QUuid& - id () const - { - return id_; - } - - // Name. - // - const QString& - first () const - { - return first_; - } - - const QString& - last () const - { - return last_; - } - - // Date of birth. - // - const QDate& - born () const - { - return born_; - } - - const Emails& - emails () const - { - return emails_; - } - - Emails& - emails () - { - return emails_; - } - - // Public key. - // - const QByteArray& - publicKey () const - { - return publicKey_; - } - - // Employer. - // - QLazySharedPointer - employer () const - { - return employer_; - } - - void - employer (QSharedPointer employer) - { - employer_ = employer; - } - -private: - friend class odb::access; - - Employee () {} - - #pragma db id - QUuid id_; - - QString first_; - QString last_; - QDate born_; - Emails emails_; - QByteArray publicKey_; - - #pragma db not_null - QLazySharedPointer employer_; -}; - -#endif // EMPLOYEE_HXX diff --git a/qt/makefile b/qt/makefile deleted file mode 100644 index 99cf1c5..0000000 --- a/qt/makefile +++ /dev/null @@ -1,168 +0,0 @@ -# file : qt/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := employee.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libodb-qt/stub.make,\ - l: odb_qt.l,cpp-options: odb_qt.l.cpp-options) - -$(call import,\ - $(scf_root)/import/libqt/core/stub.make,\ - l: qt_core.l,cpp-options: qt_core.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb_qt.l) $(odb.l) $(qt_core.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_qt.l.cpp-options) \ -$(odb_db.l.cpp-options) $(qt_core.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --generate-query \ ---generate-session --profile qt --table-prefix qt_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) $(odb_qt.l.cpp-options) $(qt_core.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README \ -$(call vc8projs,$(name)4) \ -$(call vc9projs,$(name)4) \ -$(call vc10projs,$(name)4) \ -$(call vc11projs,$(name)4) \ -$(call vc12projs,$(name)4) \ -$(call vc9projs,$(name)5) \ -$(call vc10projs,$(name)5) \ -$(call vc11projs,$(name)5) \ -$(call vc12projs,$(name)5) \ -$(call vc8slns,$(name)4) \ -$(call vc9slns,$(name)4) \ -$(call vc10slns,$(name)4) \ -$(call vc11slns,$(name)4) \ -$(call vc12slns,$(name)4) \ -$(call vc9slns,$(name)5) \ -$(call vc10slns,$(name)5) \ -$(call vc11slns,$(name)5) \ -$(call vc12slns,$(name)5) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,$(name)4,$(name)4) - $(call meta-vc9projs,$(name)4,$(name)4) - $(call meta-vc9projs,$(name)5,$(name)5) - $(call meta-vc10projs,$(name)4,$(name)4) - $(call meta-vc10projs,$(name)5,$(name)5) - $(call meta-vc11projs,$(name)4,$(name)4) - $(call meta-vc11projs,$(name)5,$(name)5) - $(call meta-vc12projs,$(name)4,$(name)4) - $(call meta-vc12projs,$(name)5,$(name)5) - $(call meta-vc8slns,$(name)4,4) - $(call meta-vc9slns,$(name)4,4) - $(call meta-vc9slns,$(name)5,5) - $(call meta-vc10slns,$(name)4,4) - $(call meta-vc10slns,$(name)5,5) - $(call meta-vc11slns,$(name)4,4) - $(call meta-vc11slns,$(name)5,5) - $(call meta-vc12slns,$(name)4,4) - $(call meta-vc12slns,$(name)5,5) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8sln.make) -$(call include,$(bld_root)/meta/vc9sln.make) -$(call include,$(bld_root)/meta/vc10sln.make) -$(call include,$(bld_root)/meta/vc11sln.make) -$(call include,$(bld_root)/meta/vc12sln.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/qt/qt4-vc10.vcxproj b/qt/qt4-vc10.vcxproj deleted file mode 100644 index ec48faf..0000000 --- a/qt/qt4-vc10.vcxproj +++ /dev/null @@ -1,174 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - Unicode - - - Application - true - Unicode - - - Application - false - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;QtCored4.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;QtCored4.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;QtCore4.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;QtCore4.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/qt/qt4-vc10.vcxproj.filters b/qt/qt4-vc10.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/qt/qt4-vc10.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/qt/qt4-vc11.vcxproj b/qt/qt4-vc11.vcxproj deleted file mode 100644 index 34d9630..0000000 --- a/qt/qt4-vc11.vcxproj +++ /dev/null @@ -1,178 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - v110 - Unicode - - - Application - true - v110 - Unicode - - - Application - false - v110 - true - Unicode - - - Application - false - v110 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;QtCored4.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;QtCored4.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;QtCore4.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;QtCore4.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/qt/qt4-vc11.vcxproj.filters b/qt/qt4-vc11.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/qt/qt4-vc11.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/qt/qt4-vc12.vcxproj b/qt/qt4-vc12.vcxproj deleted file mode 100644 index a01cf8d..0000000 --- a/qt/qt4-vc12.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - v120 - Unicode - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;QtCored4.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;QtCored4.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;QtCore4.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;QtCore4.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/qt/qt4-vc12.vcxproj.filters b/qt/qt4-vc12.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/qt/qt4-vc12.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/qt/qt4-vc8.vcproj b/qt/qt4-vc8.vcproj deleted file mode 100644 index 3bccc27..0000000 --- a/qt/qt4-vc8.vcproj +++ /dev/null @@ -1,350 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - -__file_entry_custom_build__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) -__file_entry__(__path__(odb_header_stem)-odb.hxx) -__file_entry__(__path__(odb_header_stem)-odb.ixx) -__file_entry__(database.hxx) -__file_entries__(extra_headers) - - - - - diff --git a/qt/qt4-vc9.vcproj b/qt/qt4-vc9.vcproj deleted file mode 100644 index f8b4cce..0000000 --- a/qt/qt4-vc9.vcproj +++ /dev/null @@ -1,357 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - -__file_entry_custom_build__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) -__file_entry__(__path__(odb_header_stem)-odb.hxx) -__file_entry__(__path__(odb_header_stem)-odb.ixx) -__file_entry__(database.hxx) -__file_entries__(extra_headers) - - - - - diff --git a/qt/qt5-vc10.vcxproj b/qt/qt5-vc10.vcxproj deleted file mode 100644 index 08696f8..0000000 --- a/qt/qt5-vc10.vcxproj +++ /dev/null @@ -1,174 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - Unicode - - - Application - true - Unicode - - - Application - false - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;Qt5Cored.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;Qt5Cored.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;Qt5Core.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;Qt5Core.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/qt/qt5-vc10.vcxproj.filters b/qt/qt5-vc10.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/qt/qt5-vc10.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/qt/qt5-vc11.vcxproj b/qt/qt5-vc11.vcxproj deleted file mode 100644 index 2f96cbd..0000000 --- a/qt/qt5-vc11.vcxproj +++ /dev/null @@ -1,178 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - v110 - Unicode - - - Application - true - v110 - Unicode - - - Application - false - v110 - true - Unicode - - - Application - false - v110 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;Qt5Cored.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;Qt5Cored.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;Qt5Core.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;Qt5Core.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/qt/qt5-vc11.vcxproj.filters b/qt/qt5-vc11.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/qt/qt5-vc11.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/qt/qt5-vc12.vcxproj b/qt/qt5-vc12.vcxproj deleted file mode 100644 index f5839bb..0000000 --- a/qt/qt5-vc12.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - v120 - Unicode - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;Qt5Cored.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database)-d.lib;odb-qt-d.lib;odb-d.lib;Qt5Cored.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;Qt5Core.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database).lib;odb-qt.lib;odb.lib;Qt5Core.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/qt/qt5-vc12.vcxproj.filters b/qt/qt5-vc12.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/qt/qt5-vc12.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/qt/qt5-vc9.vcproj b/qt/qt5-vc9.vcproj deleted file mode 100644 index cbfba14..0000000 --- a/qt/qt5-vc9.vcproj +++ /dev/null @@ -1,357 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - -__file_entry_custom_build__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) -__file_entry__(__path__(odb_header_stem)-odb.hxx) -__file_entry__(__path__(odb_header_stem)-odb.ixx) -__file_entry__(database.hxx) -__file_entries__(extra_headers) - - - - - diff --git a/query/README b/query/README deleted file mode 100644 index 6886b8e..0000000 --- a/query/README +++ /dev/null @@ -1,59 +0,0 @@ -This example shows how to use the ODB Query Language to search the database -for persistent objects matching certain criteria. - -The example consists of the following files: - -person.hxx - Header file defining the 'person' persistent class. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-query --generate-schema person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then persists a number of 'person' objects in the database - and executes a number of queries to find objects matching various criteria. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/query/database.hxx b/query/database.hxx deleted file mode 100644 index 61bb5ba..0000000 --- a/query/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : query/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/query/driver.cxx b/query/driver.cxx deleted file mode 100644 index aec8ac8..0000000 --- a/query/driver.cxx +++ /dev/null @@ -1,230 +0,0 @@ -// file : query/driver.cxx -// copyright : not copyrighted - public domain - -#include -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; - -using odb::database; -using odb::transaction; - -typedef odb::query query; -typedef odb::result result; - -static void -print (person& p) -{ - cout << p.first () << " "; - - if (!p.middle ().null ()) - cout << p.middle ().get () << " "; - - cout << p.last () << " " << p.age () << endl; -} - -static void -print (result& r) -{ - for (result::iterator i (r.begin ()); i != r.end (); ++i) - print (*i); - - cout << endl; -} - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - { - typedef vector people; - - people p; - - p.push_back (person ("John", "Doe", 21)); - p.push_back (person ("John", "Smith", 22)); - p.push_back (person ("Jack", "Johnson", 31)); - p.push_back (person ("John", "JJ", "Jackson", 32)); - p.push_back (person ("Jane", "JD", "Doe", 23)); - p.push_back (person ("Jane", "JS", "Smith", 24)); - - transaction t (db->begin ()); - - for (people::iterator i (p.begin ()); i != p.end (); ++i) - db->persist (*i); - - t.commit (); - } - - // A simple query and result handling. - // - { - transaction t (db->begin ()); - - result r (db->query (query::age < 30)); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - cout << i->first () << " " << i->last () << " " << i->age () << endl; - } - - // Alternatively we can get a dynamically-allocated object. - // - /* - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - auto_ptr p (i.load ()); - cout << p->first () << " " << p->last () << " " << p->age () << endl; - } - */ - - // Or we can load the state into an existing object. - // - /* - person p ("", "", 0); - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - i.load (p); - cout << p.first () << " " << p.last () << " " << p.age () << endl; - } - */ - - cout << endl; - - t.commit (); - } - - // Use query_one() as a shortcut when there's no more than one element - // in the result. - // - { - transaction t (db->begin ()); - - auto_ptr p (db->query_one (query::age == 21)); - - if (p.get () != 0) - { - print (*p); - cout << endl; - } - - // Or we can load the state into an existing object. - // - /* - person p ("", "", 0); - - if (db->query_one (query::age == 21, p)) - { - print (p); - cout << endl; - } - */ - - t.commit (); - } - - // Query that shows how to combine expressions with &&, ||, and ! - // as well as use paranthesis to control evaluation order. - // - { - transaction t (db->begin ()); - - result r ( - db->query ( - (query::first == "John" || query::first == "Jane") && - !(query::last != "Doe" || query::age > 30))); - - print (r); - t.commit (); - } - - // Query that shows how to use by-reference parameter binding. - // - { - transaction t (db->begin ()); - - unsigned short lower, upper; - - query q (query::age >= query::_ref (lower) && - query::age < query::_ref (upper)); - - for (unsigned short band (0); band < 10; ++band) - { - lower = band * 10; - upper = lower + 10; - - result r (db->query (q)); - - if (!r.empty ()) - { - cout << lower << '-' << (upper - 1) << ':' << endl; - print (r); - } - } - - t.commit (); - } - - // Query that shows how to use the in() function. - // - { - transaction t (db->begin ()); - - result r ( - db->query ( - query::last.in ("Smith", "Johnson", "Jockson"))); - - print (r); - - t.commit (); - } - - // The same query but using the in_range() function. - // - { - vector names; - - names.push_back ("Smith"); - names.push_back ("Johnson"); - names.push_back ("Jockson"); - - transaction t (db->begin ()); - - result r ( - db->query ( - query::last.in_range (names.begin (), names.end ()))); - - print (r); - - t.commit (); - } - - // Query that shows how to test for NULL values using the - // is_null()/is_not_null() functions. - // - { - transaction t (db->begin ()); - result r (db->query (query::middle.is_not_null ())); - print (r); - t.commit (); - } - - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/query/makefile b/query/makefile deleted file mode 100644 index cc2afe5..0000000 --- a/query/makefile +++ /dev/null @@ -1,125 +0,0 @@ -# file : query/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --generate-query \ ---table-prefix query_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/query/person.hxx b/query/person.hxx deleted file mode 100644 index 59e0721..0000000 --- a/query/person.hxx +++ /dev/null @@ -1,69 +0,0 @@ -// file : query/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include - -#include -#include - -#pragma db object -class person -{ -public: - person (const std::string& first, - const std::string& last, - unsigned short age) - : first_ (first), last_ (last), age_ (age) - { - } - - person (const std::string& first, - const std::string& middle, - const std::string& last, - unsigned short age) - : first_ (first), middle_ (middle), last_ (last), age_ (age) - { - } - - const std::string& - first () const - { - return first_; - } - - const odb::nullable& - middle () const - { - return middle_; - } - - const std::string& - last () const - { - return last_; - } - - unsigned short - age () const - { - return age_; - } - -private: - friend class odb::access; - - person () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - odb::nullable middle_; - std::string last_; - unsigned short age_; -}; - -#endif // PERSON_HXX diff --git a/relationship/README b/relationship/README deleted file mode 100644 index eea26aa..0000000 --- a/relationship/README +++ /dev/null @@ -1,74 +0,0 @@ -This example shows how to declare and use unidirectional to-one and to-many -relationships between persistent objects. - -The example uses the shared_ptr smart pointer from TR1 and requires a C++ -compiler with TR1 support or an external TR1 implementation, such as the -one provided by Boost. - -The example consists of the following files: - -employee.hxx - Header file defining the 'employee', 'employer', and 'project' persistent - classes as well as the employee-employer (to-one) and employee-project (to- - many) unidirectional relationships between them. - -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx -employee.sql - The first three files contain the database support code and the last file - contains the database schema for the employee.hxx header. - - These files are generated by the ODB compiler from employee.hxx using the - following command line: - - odb -d --generate-schema --generate-query --generate-session \ - --default-pointer std::tr1::shared_ptr employee.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The --generate-session option is used to enable session support for all - the persistent classes in employee.hxx. The --default-pointer option is - used to make TR1 shared_ptr the default object pointer. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the employee.hxx and employee-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then creates a number of 'employee', 'employer', and 'project' - objects, sets the relationships between them, and persists them in the - database. In the next few transactions the driver loads various objects, - then accesses and modifies the relationships between them. Finally, the - driver performs a database query which uses a data member from a related - object in its criterion. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c employee-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < employee.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/relationship/database.hxx b/relationship/database.hxx deleted file mode 100644 index 6b0e852..0000000 --- a/relationship/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : relationship/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/relationship/driver.cxx b/relationship/driver.cxx deleted file mode 100644 index 27a31b2..0000000 --- a/relationship/driver.cxx +++ /dev/null @@ -1,169 +0,0 @@ -// file : relationship/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include -#include - -#include "database.hxx" // create_database - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace odb::core; - -void -print (const employee& e) -{ - cout << e.first () << " " << e.last () << endl - << " employer: " << e.employer ()->name () << endl; - - const projects& ps (e.projects ()); - - for (projects::const_iterator i (ps.begin ()); i != ps.end (); ++i) - { - tr1::shared_ptr p (*i); - cout << " project: " << p->name () << endl; - } - - cout << endl; -} - -int -main (int argc, char* argv[]) -{ - using tr1::shared_ptr; - - try - { - auto_ptr db (create_database (argc, argv)); - - // Create a few persistent objects. - // - { - // Simple Tech Ltd. - // - { - shared_ptr er (new employer ("Simple Tech Ltd")); - - shared_ptr sh (new project ("Simple Hardware")); - shared_ptr ss (new project ("Simple Software")); - - shared_ptr john (new employee ("John", "Doe", er)); - shared_ptr jane (new employee ("Jane", "Doe", er)); - - john->projects ().push_back (sh); - john->projects ().push_back (ss); - jane->projects ().push_back (ss); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (sh); - db->persist (ss); - - db->persist (john); - db->persist (jane); - - t.commit (); - } - - // Complex Systems Inc. - // - { - shared_ptr er (new employer ("Complex Systems Inc")); - - shared_ptr ch (new project ("Complex Hardware")); - shared_ptr cs (new project ("Complex Software")); - - shared_ptr john (new employee ("John", "Smith", er)); - shared_ptr jane (new employee ("Jane", "Smith", er)); - - john->projects ().push_back (cs); - jane->projects ().push_back (ch); - jane->projects ().push_back (cs); - - transaction t (db->begin ()); - - db->persist (er); - - db->persist (ch); - db->persist (cs); - - db->persist (john); - db->persist (jane); - - t.commit (); - } - } - - typedef odb::query query; - typedef odb::result result; - - // Load employees with "Doe" as the last name and print what we've got. - // We use a session in this and subsequent transactions to make sure - // that a single instance of any particular object (e.g., employer) is - // shared among all objects (e.g., employee) that relate to it. - // - { - session s; - transaction t (db->begin ()); - - result r (db->query (query::last == "Doe")); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - print (*i); - - t.commit (); - } - - // John Doe has moved to Complex Systems Inc and is now working on - // Complex Hardware. - // - { - session s; - transaction t (db->begin ()); - - shared_ptr csi (db->load ("Complex Systems Inc")); - shared_ptr ch (db->load ("Complex Hardware")); - - shared_ptr john ( - db->query_one (query::first == "John" && - query::last == "Doe")); - - john->employer (csi); - john->projects ().clear (); - john->projects ().push_back (ch); - - db->update (john); - - t.commit (); - } - - // We can also use members of the pointed-to objects in the queries. The - // following transaction prints all the employees of Complex Systems Inc. - // - { - session s; - transaction t (db->begin ()); - - result r (db->query ( - query::employer->name == "Complex Systems Inc")); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - print (*i); - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/relationship/employee.hxx b/relationship/employee.hxx deleted file mode 100644 index 213047f..0000000 --- a/relationship/employee.hxx +++ /dev/null @@ -1,160 +0,0 @@ -// file : relationship/employee.hxx -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include -#include - -#include - -// Include TR1 header in a compiler-specific fashion. Fall back -// on the Boost implementation if the compiler does not support TR1. -// -#include - -using std::tr1::shared_ptr; - -// The "pointer architecture" in this object model is as follows: All -// object pointers are eager. The employee class holds shared pointers -// to employer and projects. -// -// The following unidirectional relationships are used: -// -// to-one : employee -> employer -// to-many : employee -> project -// - -// Forward declarations. -// -class employer; -class project; -class employee; - -typedef std::vector > projects; - -#pragma db object -class employer -{ -public: - employer (const std::string& name) - : name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - -private: - friend class odb::access; - - employer () {} - - #pragma db id - std::string name_; -}; - -#pragma db object -class project -{ -public: - project (const std::string& name) - : name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - -private: - friend class odb::access; - - project () {} - - #pragma db id - std::string name_; -}; - -#pragma db object -class employee -{ -public: - typedef ::employer employer_type; - - employee (const std::string& first, - const std::string& last, - shared_ptr employer) - : first_ (first), last_ (last), employer_ (employer) - { - } - - // Name. - // - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - // Employer. - // - shared_ptr - employer () const - { - return employer_; - } - - void - employer (shared_ptr employer) - { - employer_ = employer; - } - - // Projects. - // - typedef ::projects projects_type; - - const projects_type& - projects () const - { - return projects_; - } - - projects_type& - projects () - { - return projects_; - } - -private: - friend class odb::access; - - employee () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - - #pragma db not_null - shared_ptr employer_; - - #pragma db value_not_null unordered - projects_type projects_; -}; - -#endif // EMPLOYEE_HXX diff --git a/relationship/makefile b/relationship/makefile deleted file mode 100644 index c5383ed..0000000 --- a/relationship/makefile +++ /dev/null @@ -1,126 +0,0 @@ -# file : relationship/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := employee.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-query --generate-schema \ ---generate-session --default-pointer std::tr1::shared_ptr \ ---table-prefix relation_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/schema/custom/README b/schema/custom/README deleted file mode 100644 index 22a14cb..0000000 --- a/schema/custom/README +++ /dev/null @@ -1,65 +0,0 @@ -This example shows how to map persistent C++ classes to a custom database -schema. In particular, it shows how to map all the commonly-used constructs, -including containers, object relationships, and composite value types. - -The example uses the shared_ptr smart pointer from TR1 and requires a C++ -compiler with TR1 support or an external TR1 implementation, such as the -one provided by Boost. - -The example consists of the following files: - -employee.hxx - Header file defining the 'employee' and 'employer' persistent classes - as well as the 'name' composite value type. ODB pragmas are used to - assign custom database tables to persistent classes as well as custom - database types and columns to data members. - -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx - These files contain the database support code for the employee.hxx header - and are generated by the ODB compiler from employee.hxx using the following - command line: - - odb -d --generate-query --generate-session \ - --default-pointer std::tr1::shared_ptr employee.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The --generate-session option is used to enable session support for all - the persistent classes in employee.hxx. The --default-pointer option is - used to make TR1 shared_ptr the default object pointer. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the employee.hxx and employee-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then programmatically creates the database schema by executing - a series of SQL statements. After that the driver creates a number of - 'employee' and 'employer' objects, sets the relationships between them, - and persists them in the database. Finally, the driver performs a database - query and prints the information about the returned objects. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c employee-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb - -To run the driver, using MySQL as an example, we can execute the following -command: - -./driver --user odb_test --database odb_test - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. diff --git a/schema/custom/database.hxx b/schema/custom/database.hxx deleted file mode 100644 index e4847ec..0000000 --- a/schema/custom/database.hxx +++ /dev/null @@ -1,75 +0,0 @@ -// file : schema/custom/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/schema/custom/driver.cxx b/schema/custom/driver.cxx deleted file mode 100644 index 6c02f99..0000000 --- a/schema/custom/driver.cxx +++ /dev/null @@ -1,240 +0,0 @@ -// file : schema/custom/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include -#include -#include - -#include "database.hxx" // create_database - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - using tr1::shared_ptr; - - try - { - auto_ptr db (create_database (argc, argv)); - - // Create the database schema. - // -#if defined(DATABASE_MYSQL) || \ - defined(DATABASE_SQLITE) || \ - defined(DATABASE_MSSQL) - { - - // Due to bugs in SQLite foreign key support for DDL statements, - // we need to temporarily disable foreign keys. - // - connection_ptr c (db->connection ()); - -#ifdef DATABASE_SQLITE - c->execute ("PRAGMA foreign_keys=OFF"); -#endif - - transaction t (c->begin ()); - - // Try to drop the tables if they exist and ignore the error - // if they don't. - // - try - { - db->execute ("DROP TABLE EmployeeDegree"); - db->execute ("DROP TABLE Employee"); - db->execute ("DROP TABLE Employer"); - } - catch (const odb::exception&) - { - } - - db->execute ( - "CREATE TABLE Employer (" - "name VARCHAR (255) NOT NULL PRIMARY KEY)"); - - db->execute ( - "CREATE TABLE Employee (" - "ssn INTEGER NOT NULL PRIMARY KEY," - "first_name VARCHAR (255) NOT NULL," - "last_name VARCHAR (255) NOT NULL," - "employer VARCHAR (255) NOT NULL REFERENCES Employer (name))"); - - db->execute ( - "CREATE TABLE EmployeeDegree (" - "ssn INTEGER NOT NULL REFERENCES Employee (ssn)," - "degree VARCHAR (255) NOT NULL)"); - - t.commit (); - -#ifdef DATABASE_SQLITE - c->execute ("PRAGMA foreign_keys=ON"); -#endif - } -#elif defined(DATABASE_PGSQL) - { - // PostgreSQL-specific SQL. - // - transaction t (db->begin ()); - - db->execute ("DROP TABLE IF EXISTS \"Employer\" CASCADE"); - db->execute ("DROP TABLE IF EXISTS \"Employee\" CASCADE"); - db->execute ("DROP TABLE IF EXISTS \"EmployeeDegree\" CASCADE"); - - db->execute ( - "CREATE TABLE \"Employer\" (" - "name VARCHAR (255) NOT NULL PRIMARY KEY)"); - - db->execute ( - "CREATE TABLE \"Employee\" (" - "ssn INTEGER NOT NULL PRIMARY KEY," - "first_name VARCHAR (255) NOT NULL," - "last_name VARCHAR (255) NOT NULL," - "employer VARCHAR (255) NOT NULL)"); - - db->execute ( - "CREATE TABLE \"EmployeeDegree\" (" - "ssn INTEGER NOT NULL," - "degree VARCHAR (255) NOT NULL)"); - - db->execute ( - "ALTER TABLE \"Employee\" " - "ADD FOREIGN KEY (employer) " - "REFERENCES \"Employer\" " - "INITIALLY DEFERRED"); - - db->execute ( - "ALTER TABLE \"EmployeeDegree\" " - "ADD FOREIGN KEY (ssn) " - "REFERENCES \"Employee\" " - "INITIALLY DEFERRED"); - - t.commit (); - } -#elif defined(DATABASE_ORACLE) - { - // Oracle-specific PL/SQL. - // - transaction t (db->begin ()); - - db->execute ("BEGIN " - " EXECUTE IMMEDIATE " - " 'DROP TABLE \"Employer\" CASCADE CONSTRAINTS';" - " EXCEPTION " - " WHEN OTHERS THEN " - " IF SQLCODE != -942 THEN RAISE; END IF;" - "END;"); - - db->execute ("BEGIN " - " EXECUTE IMMEDIATE " - " 'DROP TABLE \"Employee\" CASCADE CONSTRAINTS';" - " EXCEPTION " - " WHEN OTHERS THEN " - " IF SQLCODE != -942 THEN RAISE; END IF;" - "END;"); - - db->execute ("BEGIN " - " EXECUTE IMMEDIATE 'DROP TABLE \"EmployeeDegree\"';" - " EXCEPTION " - " WHEN OTHERS THEN " - " IF SQLCODE != -942 THEN RAISE; END IF;" - "END;"); - - db->execute ( - "CREATE TABLE \"Employer\" (" - "\"name\" VARCHAR (255) PRIMARY KEY)"); - - db->execute ( - "CREATE TABLE \"Employee\" (" - "\"ssn\" NUMBER(10) PRIMARY KEY," - "\"first_name\" VARCHAR (255) NOT NULL," - "\"last_name\" VARCHAR (255) NOT NULL," - "\"employer\" VARCHAR (255) NOT NULL)"); - - db->execute ( - "CREATE TABLE \"EmployeeDegree\" (" - "\"ssn\" NUMBER(10) NOT NULL," - "\"degree\" VARCHAR (255) NOT NULL)"); - - db->execute ( - "ALTER TABLE \"Employee\" " - "ADD FOREIGN KEY (\"employer\") " - "REFERENCES \"Employer\" " - "INITIALLY DEFERRED"); - - db->execute ( - "ALTER TABLE \"EmployeeDegree\" " - "ADD FOREIGN KEY (\"ssn\") " - "REFERENCES \"Employee\" " - "INITIALLY DEFERRED"); - - t.commit (); - } -#else -# error unknown database -#endif - - // Create a few persistent objects. - // - { - shared_ptr st (new employer ("Simple Tech Ltd")); - - shared_ptr john (new employee (1, "John", "Doe", st)); - shared_ptr jane (new employee (2, "Jane", "Doe", st)); - - john->degrees ().push_back ("BA"); - john->degrees ().push_back ("MSc"); - jane->degrees ().push_back ("Ph.D."); - - transaction t (db->begin ()); - - db->persist (st); - db->persist (john); - db->persist (jane); - - t.commit (); - } - - // Load employees with "Doe" as the last name and print what we've got. - // - { - typedef odb::query query; - typedef odb::result result; - - session s; - transaction t (db->begin ()); - - result r (db->query (query::name.last == "Doe")); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - cout << i->name ().first () << " " << i->name ().last () << endl - << " employer: " << i->employer ()->name () << endl; - - for (degrees::iterator j (i->degrees ().begin ()); - j != i->degrees ().end (); - ++j) - { - cout << " degree: " << *j << endl; - } - - cout << endl; - } - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/schema/custom/employee.hxx b/schema/custom/employee.hxx deleted file mode 100644 index e149192..0000000 --- a/schema/custom/employee.hxx +++ /dev/null @@ -1,149 +0,0 @@ -// file : schema/custom/employee.hxx -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include -#include - -#include - -// Include TR1 header in a compiler-specific fashion. Fall back -// on the Boost implementation if the compiler does not support TR1. -// -#include - -using std::tr1::shared_ptr; - -typedef std::vector degrees; - -#pragma db value -class name -{ -public: - name (const std::string& first, const std::string& last) - : first_ (first), last_ (last) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - -private: - friend class odb::access; - - #pragma db type("VARCHAR(255)") column("first_name") - std::string first_; - - #pragma db type("VARCHAR(255)") column("last_name") - std::string last_; -}; - -#pragma db object table("Employer") -class employer -{ -public: - employer (const std::string& name) - : name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - -private: - friend class odb::access; - - employer () {} - - #pragma db id type("VARCHAR(255)") column("name") - std::string name_; -}; - -#pragma db object table("Employee") -class employee -{ -public: - typedef ::employer employer_type; - - employee (unsigned long id, - const std::string& first, - const std::string& last, - shared_ptr employer) - : id_ (id), name_ (first, last), employer_ (employer) - { - } - - // Name. - // - typedef ::name name_type; - - const name_type& - name () const - { - return name_; - } - - // Degrees. - // - typedef ::degrees degrees_type; - - const degrees_type& - degrees () const - { - return degrees_; - } - - degrees_type& - degrees () - { - return degrees_; - } - - // Employer. - // - shared_ptr - employer () const - { - return employer_; - } - - void - employer (shared_ptr employer) - { - employer_ = employer; - } - -private: - friend class odb::access; - - employee (): name_ ("", "") {} - - #pragma db id type("INTEGER") column("ssn") - unsigned long id_; - - #pragma db column("") // No column prefix. - name_type name_; - - #pragma db unordered table("EmployeeDegree") id_column("ssn") \ - value_type("VARCHAR(255)") value_column("degree") - degrees_type degrees_; - - #pragma db not_null column("employer") - shared_ptr employer_; -}; - -#endif // EMPLOYEE_HXX diff --git a/schema/custom/makefile b/schema/custom/makefile deleted file mode 100644 index eeac39b..0000000 --- a/schema/custom/makefile +++ /dev/null @@ -1,123 +0,0 @@ -# file : schema/custom/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := employee.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-query --generate-session \ ---default-pointer std::tr1::shared_ptr -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../../template/Makefile.am) - $(call meta-vc8projs,../../template/template,$(name)) - $(call meta-vc9projs,../../template/template,$(name)) - $(call meta-vc10projs,../../template/template,$(name)) - $(call meta-vc11projs,../../template/template,$(name)) - $(call meta-vc12projs,../../template/template,$(name)) - -# Test. -# -$(test): $(driver) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/schema/embedded/README b/schema/embedded/README deleted file mode 100644 index da99173..0000000 --- a/schema/embedded/README +++ /dev/null @@ -1,63 +0,0 @@ -This example shows how to generate and use a database schema that is embedded -into the application rather than stored as a separate SQL file. - -The example consists of the following files: - -person.hxx - Header file defining the 'person' persistent class. - -person-odb.hxx -person-odb.ixx -person-odb.cxx - These files contain the database support code as well as the embedded - database schema for the person.hxx header. They are generated by the ODB - compiler from person.hxx using the following command line: - - odb -d --generate-schema --schema-format embedded \ - --generate-query person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The --generate-schema option requests the generation of the database schema. - The --schema-format option is used to instruct the ODB compiler to embed the - schema into the generated C++ files. It is also possible to generate the - schema creation code into a separate source file by passing the 'separate' - value instead of 'embedded' to the --schema-format option. This is primarily - useful if you want to place the schema creation functionality into a - separate program or library. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then uses the ODB schema catalog to create the database - schema. During this step the generated code issues a number of SQL - statements that drop and create necessary database tables, etc. - - After the database schema is ready, the driver persists a number of 'person' - objects, performs a database query, and prints the information about the - returned objects. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the driver, using MySQL as an example, we can execute the following -command: - -./driver --user odb_test --database odb_test - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. diff --git a/schema/embedded/database.hxx b/schema/embedded/database.hxx deleted file mode 100644 index 22ac21a..0000000 --- a/schema/embedded/database.hxx +++ /dev/null @@ -1,75 +0,0 @@ -// file : schema/embedded/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/schema/embedded/driver.cxx b/schema/embedded/driver.cxx deleted file mode 100644 index 16ed426..0000000 --- a/schema/embedded/driver.cxx +++ /dev/null @@ -1,96 +0,0 @@ -// file : schema/embedded/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - typedef odb::query query; - typedef odb::result result; - - auto_ptr db (create_database (argc, argv)); - - // Create the database schema. - // - { - transaction t (db->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - } - - // The following alternative version only creates the schema if it - // hasn't already been created. To detect the existence of the schema - // this version tries to query the database for a person object. If - // the corresponding table does not exist, then an exceptions will be - // thrown in which case we proceed to creating the schema. - // - /* - { - transaction t (db->begin ()); - - try - { - db->query (false); - } - catch (const odb::exception& e) - { - schema_catalog::create_schema (*db); - } - - t.commit (); - } - */ - - // Create a few persistent person objects. - // - { - person john ("John", "Doe", 33); - person jane ("Jane", "Doe", 32); - person joe ("Joe", "Dirt", 30); - - transaction t (db->begin ()); - - db->persist (john); - db->persist (jane); - db->persist (joe); - - t.commit (); - } - - // Print those over 30. - // - { - transaction t (db->begin ()); - - result r (db->query (query::age > 30)); - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - cout << i->first () << " " << i->last () << endl; - } - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/schema/embedded/makefile b/schema/embedded/makefile deleted file mode 100644 index afe6f98..0000000 --- a/schema/embedded/makefile +++ /dev/null @@ -1,124 +0,0 @@ -# file : schema/embedded/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-query --generate-schema \ ---schema-format embedded --table-prefix schema_embedded_ - -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../../template/Makefile.am) - $(call meta-vc8projs,../../template/template,$(name)) - $(call meta-vc9projs,../../template/template,$(name)) - $(call meta-vc10projs,../../template/template,$(name)) - $(call meta-vc11projs,../../template/template,$(name)) - $(call meta-vc12projs,../../template/template,$(name)) - -# Test. -# -$(test): $(driver) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/schema/embedded/person.hxx b/schema/embedded/person.hxx deleted file mode 100644 index e73ddcf..0000000 --- a/schema/embedded/person.hxx +++ /dev/null @@ -1,59 +0,0 @@ -// file : schema/embedded/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include - -#include - -#pragma db object -class person -{ -public: - person (const std::string& first, - const std::string& last, - unsigned short age) - : first_ (first), last_ (last), age_ (age) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - unsigned short - age () const - { - return age_; - } - - void - age (unsigned short age) - { - age_ = age; - } - -private: - friend class odb::access; - - person () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - unsigned short age_; -}; - -#endif // PERSON_HXX diff --git a/section/README b/section/README deleted file mode 100644 index 34be589..0000000 --- a/section/README +++ /dev/null @@ -1,63 +0,0 @@ -This example shows how to use object sections to implement lazy-loading -and change-updating of a subset of data members in a persistent class. - -The example consists of the following files: - -person.hxx - Header file defining the 'person' persistent class. It contains a number of - data members some of which are made to belong to a section. - -person-odb.hxx -person-odb.ixx -person-odb.cxx -person.sql - The first three files contain the database support code and the last file - contains the database schema for the person.hxx header. - - These files are generated by the ODB compiler from person.hxx using the - following command line: - - odb -d --generate-schema person.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the person.hxx and person-odb.hxx - headers to gain access to the persistent classes and their database support - code. It also includes database.hxx for the create_database() function - declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then persists a 'person' object, loads it back, including - the section, and prints the contents of its members. Finally, the driver - shows how to update the state of the section data members in various ways, - then re-loads and prints the object to verify that the changes have been - made persistent. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c person-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o person-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < person.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/section/database.hxx b/section/database.hxx deleted file mode 100644 index 4a1a350..0000000 --- a/section/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : section/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/section/driver.cxx b/section/driver.cxx deleted file mode 100644 index b01454e..0000000 --- a/section/driver.cxx +++ /dev/null @@ -1,133 +0,0 @@ -// file : section/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - unsigned long id; - - // Create a persistent person object. - // - { - person joe ("Joe", "Dirt"); - joe.bio ("Joe Dirt is a very strange man indeed..."); - joe.nicknames ().push_back ("JD"); - - // At this point the state of a section is undefined since the - // object is transient. - - transaction t (db->begin ()); - id = db->persist (joe); - t.commit (); - - // Now, since the object is persistent, the state of the section - // is loaded and unchanged. - } - - // Load the object and print what we've got. Then update the bio. - // - { - transaction t (db->begin ()); - auto_ptr p (db->load (id)); - - // Now, while the object is loaded, the section is not. If (and - // when) we need to access the section data members, we have to - // load them explicitly. - - cout << p->first () << " " << p->last () << endl; - - db->load (*p, p->extras_section ()); - - // Now the section is loaded and unchanged. - - cout << " " << p->bio () << endl - << " " << p->nicknames ().size () << " nickname(s)" << endl; - - // Update the bio. - // - p->bio ("Joe Dirt is a very clean man indeed..."); - - // Now, the section is marked changed by the bio() modifier. - // Because of that, the following object update will also - // update the section. - // - db->update (*p); - - t.commit (); - } - - // Add a new nickname. - // - { - transaction t (db->begin ()); - - auto_ptr p (db->load (id)); - db->load (*p, p->extras_section ()); - - // Add a new nickname. The nicknames container is now marked - // changed. - // - p->nicknames ().push_back ("Squeaky Clean"); - - // While the section hasn't been marked as changed, a change- - // tracking container that belongs to it has been. As a result, - // the following object update call will automatically mark the - // section as changed and update its state in the database. - // - db->update (*p); - - t.commit (); - } - - // We can also update just the section if we know the rest of - // the object hasn't changed. - // - { - transaction t (db->begin ()); - - auto_ptr p (db->load (id)); - db->load (*p, p->extras_section ()); - - p->nicknames ().push_back ("Dirty Joe"); - db->update (*p, p->extras_section ()); - - t.commit (); - } - - // Load and print the updated object. - // - { - transaction t (db->begin ()); - auto_ptr p (db->load (id)); - db->load (*p, p->extras_section ()); - t.commit (); - - cout << p->first () << " " << p->last () << endl - << " " << p->bio () << endl - << " " << p->nicknames ().size () << " nickname(s)" << endl; - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/section/makefile b/section/makefile deleted file mode 100644 index b25cc87..0000000 --- a/section/makefile +++ /dev/null @@ -1,124 +0,0 @@ -# file : section/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema --table-prefix section_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/section/person.hxx b/section/person.hxx deleted file mode 100644 index 996fc19..0000000 --- a/section/person.hxx +++ /dev/null @@ -1,105 +0,0 @@ -// file : section/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include - -#include -#include -#include - -#pragma db object -class person -{ -public: - person (const std::string& first, const std::string& last) - : first_ (first), last_ (last) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - // Biography. - // - const std::string& - bio () const - { - return bio_; - } - - void - bio (const std::string& bio) - { - bio_ = bio; - extras_.change (); // Mark the section as changed. - } - - // Nicknames. - // - typedef odb::vector names; - - const names& - nicknames () const - { - return nicknames_; - } - - names& - nicknames () - { - // Because we are using a change-tracking container (odb::vector), - // ODB will automatically mark the section as changed if we update - // the nicknames. - // - return nicknames_; - } - - // The extras section accessor and modifier. Notice that they are - // by-reference. - // - const odb::section& - extras_section () const - { - return extras_; - } - - odb::section& - extras_section () - { - return extras_; - } - -private: - friend class odb::access; - - person () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - - #pragma db section(extras_) - std::string bio_; - - #pragma db section(extras_) - names nicknames_; - - #pragma db load(lazy) update(change) - odb::section extras_; -}; - -#endif // PERSON_HXX diff --git a/sqlite-driver.bat b/sqlite-driver.bat deleted file mode 100644 index c5f1187..0000000 --- a/sqlite-driver.bat +++ /dev/null @@ -1,2 +0,0 @@ -rem Client driver is not used for SQLite so you don't need to -rem change anything here. diff --git a/sqlite.options b/sqlite.options deleted file mode 100644 index 208a7d7..0000000 --- a/sqlite.options +++ /dev/null @@ -1,5 +0,0 @@ -# Sample SQLite options file used to run the tests. Adjust to -# match your SQLite setup. -# - ---database C:\Temp\odb_test.db diff --git a/template-vc10.sln b/template-vc10.sln deleted file mode 100644 index 9a5dc32..0000000 --- a/template-vc10.sln +++ /dev/null @@ -1,15 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -__projects__ -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution -__solution_configurations__ - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution -__project_configurations__ - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/template-vc11.sln b/template-vc11.sln deleted file mode 100644 index 436eeea..0000000 --- a/template-vc11.sln +++ /dev/null @@ -1,15 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -__projects__ -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution -__solution_configurations__ - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution -__project_configurations__ - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/template-vc12.sln b/template-vc12.sln deleted file mode 100644 index 446d701..0000000 --- a/template-vc12.sln +++ /dev/null @@ -1,17 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.21005.1 -MinimumVisualStudioVersion = 10.0.40219.1 -__projects__ -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution -__solution_configurations__ - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution -__project_configurations__ - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/template-vc8.sln b/template-vc8.sln deleted file mode 100644 index f38bad2..0000000 --- a/template-vc8.sln +++ /dev/null @@ -1,15 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -__projects__ -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution -__solution_configurations__ - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution -__project_configurations__ - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/template-vc9.sln b/template-vc9.sln deleted file mode 100644 index 2ec9432..0000000 --- a/template-vc9.sln +++ /dev/null @@ -1,15 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -__projects__ -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution -__solution_configurations__ - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution -__project_configurations__ - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/template/Makefile.am b/template/Makefile.am deleted file mode 100644 index 0cfe62d..0000000 --- a/template/Makefile.am +++ /dev/null @@ -1,50 +0,0 @@ -# file : template/Makefile.am -# copyright : not copyrighted - public domain - -EXTRA_DIST = __file__(extra_dist) - -noinst_PROGRAMS = driver -driver_SOURCES = driver.cxx database.hxx __path__(extra_sources) __path__(extra_headers) - -AM_CPPFLAGS = -I'$(builddir)' -I'$(srcdir)' - -if DATABASE_MYSQL -AM_CPPFLAGS += -DDATABASE_MYSQL -endif - -if DATABASE_SQLITE -AM_CPPFLAGS += -DDATABASE_SQLITE -endif - -if DATABASE_PGSQL -AM_CPPFLAGS += -DDATABASE_PGSQL -endif - -if DATABASE_ORACLE -AM_CPPFLAGS += -DDATABASE_ORACLE -endif - -if DATABASE_MSSQL -AM_CPPFLAGS += -DDATABASE_MSSQL -endif - -TESTS=$(top_builddir)/tester -TESTS_ENVIRONMENT=top_builddir=$(top_builddir); export top_builddir; - -# ODB compilation. -# -driver_SOURCES += __path__(odb_header_stem).hxx -nodist_driver_SOURCES = __path__(odb_header_stem)-odb.cxx -BUILT_SOURCES = __path__(odb_header_stem)-odb.hxx -CLEANFILES = __path__(odb_header_stem)-odb.hxx __path__(odb_header_stem)-odb.ixx __path__(odb_header_stem)-odb.cxx - -ODB = @ODB@ -ODBFLAGS = @ODBFLAGS@ -ODBCPPFLAGS = @ODBCPPFLAGS@ - -if HAVE_CXX11 -ODBFLAGS += --std c++11 -endif - -__path__(odb_header_stem)-odb.hxx: __path__(odb_header_stem).hxx - $(ODB) $(ODBCPPFLAGS) $(CPPFLAGS) $(ODBFLAGS) --database @database@ __value__(odb_options) $< diff --git a/template/database.hxx b/template/database.hxx deleted file mode 100644 index dfe6562..0000000 --- a/template/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : template/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/template/driver.cxx b/template/driver.cxx deleted file mode 100644 index 7160587..0000000 --- a/template/driver.cxx +++ /dev/null @@ -1,38 +0,0 @@ -// file : template/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include - -#include "database.hxx" // create_database - -#include "person.hxx" -#include "person-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - try - { - auto_ptr db (create_database (argc, argv)); - - { - person p ("John", "Doe", 21); - - transaction t (db->begin ()); - db->persist (p); - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/template/makefile b/template/makefile deleted file mode 100644 index dc9e328..0000000 --- a/template/makefile +++ /dev/null @@ -1,125 +0,0 @@ -# file : template/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := person.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-schema \ ---table-prefix template_ #@@ CHANGE THIS -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - diff --git a/template/person.hxx b/template/person.hxx deleted file mode 100644 index 7b7a50a..0000000 --- a/template/person.hxx +++ /dev/null @@ -1,53 +0,0 @@ -// file : template/person.hxx -// copyright : not copyrighted - public domain - -#ifndef PERSON_HXX -#define PERSON_HXX - -#include - -#include - -#pragma db object -class person -{ -public: - person (const std::string& first, - const std::string& last, - unsigned short age) - : first_ (first), last_ (last), age_ (age) - { - } - - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - unsigned short - age () const - { - return age_; - } - -private: - friend class odb::access; - - person () {} - - #pragma db id auto - unsigned long id_; - - std::string first_; - std::string last_; - unsigned short age_; -}; - -#endif // PERSON_HXX diff --git a/template/template-vc10.vcxproj b/template/template-vc10.vcxproj deleted file mode 100644 index cda7935..0000000 --- a/template/template-vc10.vcxproj +++ /dev/null @@ -1,174 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - Unicode - - - Application - true - Unicode - - - Application - false - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/template/template-vc10.vcxproj.filters b/template/template-vc10.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/template/template-vc10.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/template/template-vc11.vcxproj b/template/template-vc11.vcxproj deleted file mode 100644 index 4cd24bc..0000000 --- a/template/template-vc11.vcxproj +++ /dev/null @@ -1,178 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - v110 - Unicode - - - Application - true - v110 - Unicode - - - Application - false - v110 - true - Unicode - - - Application - false - v110 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - - - odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/template/template-vc11.vcxproj.filters b/template/template-vc11.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/template/template-vc11.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/template/template-vc12.vcxproj b/template/template-vc12.vcxproj deleted file mode 100644 index da21d1c..0000000 --- a/template/template-vc12.vcxproj +++ /dev/null @@ -1,182 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {__uuid__()} - Win32Proj - __value__(name) - - - - Application - true - v120 - Unicode - - - Application - true - v120 - Unicode - - - Application - false - v120 - true - Unicode - - - Application - false - v120 - true - Unicode - - - - - - - - - - - - - - - - - - - true - $(Configuration)\ - driver - - - true - $(Platform)\$(Configuration)\ - driver - - - false - $(Configuration)\ - driver - - - false - $(Platform)\$(Configuration)\ - driver - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database)-d.lib;odb-d.lib;%(AdditionalDependencies) - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE;__upcase__(database_)__upcase__(__value__(database));%(PreprocessorDefinitions) - 4068;4355;4800;4290;%(DisableSpecificWarnings) - true - - - odb-__value__(database).lib;odb.lib;%(AdditionalDependencies) - Console - true - true - true - - - -__custom_build_entry__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --std c++11 --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) - - -__header_entry__(__path__(odb_header_stem)-odb.hxx) -__header_entry__(__path__(odb_header_stem)-odb.ixx) -__header_entry__(database.hxx) -__header_entries__(extra_headers) - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - - - - diff --git a/template/template-vc12.vcxproj.filters b/template/template-vc12.vcxproj.filters deleted file mode 100644 index f754d41..0000000 --- a/template/template-vc12.vcxproj.filters +++ /dev/null @@ -1,25 +0,0 @@ - - - - - {__uuid__()} - cxx - - - {__uuid__()} - h;hxx;ixx;txx - - - -__header_filter_entry__(__path__(odb_header_stem).hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.hxx) -__header_filter_entry__(__path__(odb_header_stem)-odb.ixx) -__header_filter_entries__(database.hxx) -__header_filter_entries__(extra_headers) - - -__source_filter_entry__(driver.cxx) -__source_filter_entry__(__path__(odb_header_stem)-odb.cxx) -__source_filter_entries__(extra_sources) - - diff --git a/template/template-vc8.vcproj b/template/template-vc8.vcproj deleted file mode 100644 index 24f9831..0000000 --- a/template/template-vc8.vcproj +++ /dev/null @@ -1,350 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - -__file_entry_custom_build__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) -__file_entry__(__path__(odb_header_stem)-odb.hxx) -__file_entry__(__path__(odb_header_stem)-odb.ixx) -__file_entry__(database.hxx) -__file_entries__(extra_headers) - - - - - diff --git a/template/template-vc9.vcproj b/template/template-vc9.vcproj deleted file mode 100644 index dc98b07..0000000 --- a/template/template-vc9.vcproj +++ /dev/null @@ -1,357 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -__source_entry__(driver.cxx) -__source_entry__(__path__(odb_header_stem)-odb.cxx) -__source_entries__(extra_sources) - - -__file_entry_custom_build__( -__path__(odb_header_stem).hxx, -odb __path__(odb_header_stem).hxx, -odb.exe --database __value__(database) __xml__(__shell_quotes__(__value__(odb_options))) __path__(odb_header_stem).hxx, -__path__(odb_header_stem)-odb.hxx;__path__(odb_header_stem)-odb.ixx;__path__(odb_header_stem)-odb.cxx) -__file_entry__(__path__(odb_header_stem)-odb.hxx) -__file_entry__(__path__(odb_header_stem)-odb.ixx) -__file_entry__(database.hxx) -__file_entries__(extra_headers) - - - - - diff --git a/test.bat b/test.bat deleted file mode 100644 index 2885723..0000000 --- a/test.bat +++ /dev/null @@ -1,79 +0,0 @@ -@echo off -rem file : test.bat -rem license : GNU GPL v2; see accompanying LICENSE file - -setlocal - -set "tests=__path__(dirs) __path__(tr1_dirs) __path__(boost_dirs) __path__(qt_dirs)" -set "confs=__path__(configurations)" -set "plats=__path__(platforms)" -set "curdir=%CD%" -set "topdir=%curdir%" -set "failed=" - -if "_%1_" == "__" ( - echo no database specified - goto usage -) - -goto start - -rem -rem %1 - test directory -rem %2 - configuration -rem %3 - platform -rem %4 - database -rem -:run_test - cd %1 - - if "_%3_" == "_Win32_" ( - set "dir=%2" - ) else ( - set "dir=%3\%2" - ) - - if exist %dir%\driver.exe ( - echo %1\%3\%2 - call %topdir%\tester.bat %4 %2 %3 - if errorlevel 1 ( - set "failed=%failed% %1\%3\%2" - ) - ) - - cd %curdir% -goto :eof - -:start - -for %%t in (%tests%) do ( - for %%c in (%confs%) do ( - for %%p in (%plats%) do ( - call :run_test %%t %%c %%p %1 - ) - ) -) - -if not "_%failed%_" == "__" goto error - -echo. -echo ALL EXAMPLES PASSED -echo. -goto end - -:usage -echo. -echo usage: test.bat database -echo. - -:error -if not "_%failed%_" == "__" ( - echo. - for %%t in (%failed%) do echo FAILED: %%t - echo. -) -endlocal -exit /b 1 - -:end -endlocal diff --git a/tester.bat b/tester.bat deleted file mode 100644 index ad8f8f3..0000000 --- a/tester.bat +++ /dev/null @@ -1,41 +0,0 @@ -@echo off -rem file : tester.bat -rem license : GNU GPL v2; see accompanying LICENSE file - -rem -rem Run an ODB example. The example directory is the current directory. -rem -rem %1 database -rem %2 configuration, for example, Debug or Release -rem %3 platform, for example Win32 or x64 -rem topdir variable containing the path to top project directory -rem - -setlocal - -if "_%3_" == "_Win32_" ( - set "dir=%2" -) else ( - set "dir=%3\%2" -) - -rem Globbing returns files in alphabetic order. -rem -if exist *.sql ( - for %%f in (*.sql) do ( - call %topdir%\%1-driver.bat %%f - if errorlevel 1 goto error - ) -) - -%dir%\driver.exe --options-file %topdir%\%1.options -if errorlevel 1 goto error - -goto end - -:error -endlocal -exit /b 1 - -:end -endlocal diff --git a/tester.in b/tester.in deleted file mode 100755 index 5169f8f..0000000 --- a/tester.in +++ /dev/null @@ -1,27 +0,0 @@ -#! /bin/sh - -# file : tester.in -# license : GNU GPL v2; see accompanying LICENSE file - -# -# Run an ODB example. The example driver is in the current directory. -# The data files, if any, are in $srcdir. -# - -db_driver="$top_builddir/@database@-driver" -db_options="$top_builddir/@database@.options" - -# Globbing returns files in alphabetic order. -# -for f in `echo *.sql`; do - if test -f $f; then - $db_driver $f - - if test $? -ne 0; then - exit 1 - fi - fi -done - -echo ./driver --options-file "$db_options" -./driver --options-file "$db_options" diff --git a/version b/version deleted file mode 100644 index 6bc2f39..0000000 --- a/version +++ /dev/null @@ -1 +0,0 @@ -2.5.0-b.26 diff --git a/view/README b/view/README deleted file mode 100644 index cba23b9..0000000 --- a/view/README +++ /dev/null @@ -1,77 +0,0 @@ -This example shows how to define and use views in ODB. It includes views -that show how to load a subset of data members from objects or columns -from tables, perform aggregate queries, and join multiple objects and -tables using object relationships and custom join conditions. - -The example uses the shared_ptr smart pointer from TR1 and requires a C++ -compiler with TR1 support or an external TR1 implementation, such as the -one provided by Boost. - -The example consists of the following files: - -employee.hxx - Header file defining the 'country', 'employer', and 'employee' persistent - classes. The example also uses the "legacy" 'employee_extra' table that is - not mapped to a persistent class. - - After the persistent classes, this header defines a number of views that - show how to obtain various information from the above object model. - -employee-odb.hxx -employee-odb.ixx -employee-odb.cxx -employee.sql - The first three files contain the database support code and the last file - contains the database schema for the employee.hxx header. - - These files are generated by the ODB compiler from employee.hxx using the - following command line: - - odb -d --generate-schema --generate-query \ - --default-pointer std::tr1::shared_ptr --generate-session employee.hxx - - Where stands for the database system we are using, for example, - 'mysql'. - - The --default-pointer option is used to make TR1 shared_ptr the default - object pointer. The --generate-session option is used to enable session - support for all the objects which is required to use object loading views. - -database.hxx - Contains the create_database() function which instantiates the concrete - database class corresponding to the database system we are using. - -driver.cxx - Driver for the example. It includes the employee.hxx and employee-odb.hxx - headers to gain access to the persistent classes and views as well as - their database support code. It also includes database.hxx for the - create_database() function declaration. - - In main() the driver first calls create_database() to obtain the database - instance. It then creates the legacy 'employee_extra' table and proceeds - to populate the database with a number of 'country', 'employer', and - 'employee' objects. Once this is done, the driver uses views defined in - employee.hxx to load and print various information about the object model. - -To compile and link the example manually from the command line we can use -the following commands (using MySQL as an example; replace 'c++' with your -C++ compiler name): - -c++ -c employee-odb.cxx -c++ -DDATABASE_MYSQL -c driver.cxx -c++ -o driver driver.o employee-odb.o -lodb-mysql -lodb - -To run the example we may first need to create the database schema (for some -database systems, such as SQLite, the schema is embedded into the generated -code which makes this step unnecessary). Using MySQL as an example, this -can be achieved with the following command: - -mysql --user=odb_test --database=odb_test < employee.sql - -Here we use 'odb_test' as the database login and also 'odb_test' as the -database name. - -Once the database schema is ready, we can run the example (using MySQL as -the database): - -./driver --user odb_test --database odb_test diff --git a/view/database.hxx b/view/database.hxx deleted file mode 100644 index 1fc18f7..0000000 --- a/view/database.hxx +++ /dev/null @@ -1,94 +0,0 @@ -// file : view/database.hxx -// copyright : not copyrighted - public domain - -// -// Create concrete database instance based on the DATABASE_* macros. -// - -#ifndef DATABASE_HXX -#define DATABASE_HXX - -#include -#include // std::auto_ptr -#include // std::exit -#include - -#include - -#if defined(DATABASE_MYSQL) -# include -#elif defined(DATABASE_SQLITE) -# include -# include -# include -# include -#elif defined(DATABASE_PGSQL) -# include -#elif defined(DATABASE_ORACLE) -# include -#elif defined(DATABASE_MSSQL) -# include -#else -# error unknown database; did you forget to define the DATABASE_* macros? -#endif - -inline std::auto_ptr -create_database (int& argc, char* argv[]) -{ - using namespace std; - using namespace odb::core; - - if (argc > 1 && argv[1] == string ("--help")) - { - cout << "Usage: " << argv[0] << " [options]" << endl - << "Options:" << endl; - -#if defined(DATABASE_MYSQL) - odb::mysql::database::print_usage (cout); -#elif defined(DATABASE_SQLITE) - odb::sqlite::database::print_usage (cout); -#elif defined(DATABASE_PGSQL) - odb::pgsql::database::print_usage (cout); -#elif defined(DATABASE_ORACLE) - odb::oracle::database::print_usage (cout); -#elif defined(DATABASE_MSSQL) - odb::mssql::database::print_usage (cout); -#endif - - exit (0); - } - -#if defined(DATABASE_MYSQL) - auto_ptr db (new odb::mysql::database (argc, argv)); -#elif defined(DATABASE_SQLITE) - auto_ptr db ( - new odb::sqlite::database ( - argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); - - // Create the database schema. Due to bugs in SQLite foreign key - // support for DDL statements, we need to temporarily disable - // foreign keys. - // - { - connection_ptr c (db->connection ()); - - c->execute ("PRAGMA foreign_keys=OFF"); - - transaction t (c->begin ()); - schema_catalog::create_schema (*db); - t.commit (); - - c->execute ("PRAGMA foreign_keys=ON"); - } -#elif defined(DATABASE_PGSQL) - auto_ptr db (new odb::pgsql::database (argc, argv)); -#elif defined(DATABASE_ORACLE) - auto_ptr db (new odb::oracle::database (argc, argv)); -#elif defined(DATABASE_MSSQL) - auto_ptr db (new odb::mssql::database (argc, argv)); -#endif - - return db; -} - -#endif // DATABASE_HXX diff --git a/view/driver.cxx b/view/driver.cxx deleted file mode 100644 index d975cc4..0000000 --- a/view/driver.cxx +++ /dev/null @@ -1,418 +0,0 @@ -// file : view/driver.cxx -// copyright : not copyrighted - public domain - -#include // std::auto_ptr -#include - -#include -#include -#include - -#include "database.hxx" // create_database - -#include "employee.hxx" -#include "employee-odb.hxx" - -using namespace std; -using namespace odb::core; - -int -main (int argc, char* argv[]) -{ - using tr1::shared_ptr; - - try - { - auto_ptr db (create_database (argc, argv)); - - // Create the legacy employee_extra table. - // - { - // First try to drop the table if it exists. - // - { - transaction t (db->begin ()); - try - { -#ifndef DATABASE_ORACLE - db->execute ("DROP TABLE view_employee_extra"); -#else - db->execute ("DROP TABLE \"view_employee_extra\""); -#endif - t.commit (); - } - catch (const odb::exception&) - { - } - } - - { - transaction t (db->begin ()); - -#ifndef DATABASE_ORACLE - db->execute ( - "CREATE TABLE view_employee_extra (" - "employee_id INTEGER NOT NULL," - "vacation_days INTEGER NOT NULL," - "previous_employer_id INTEGER)"); -#else - db->execute ( - "CREATE TABLE \"view_employee_extra\" (" - "\"employee_id\" INTEGER NOT NULL," - "\"vacation_days\" INTEGER NOT NULL," - "\"previous_employer_id\" INTEGER)"); -#endif - - t.commit (); - } - } - - // Create a few persistent objects. - // - { - shared_ptr ca (new country ("CA", "Canada")); - shared_ptr za (new country ("ZA", "South Africa")); - shared_ptr us (new country ("US", "United States")); - shared_ptr se (new country ("SE", "Sweden")); - - shared_ptr st (new employer (1, "Simple Tech Ltd")); - shared_ptr cs (new employer (2, "Complex Systems Inc")); - - shared_ptr e1 ( - new employee (1, "John", "Doe", 29, ca, ca, st)); - - shared_ptr e2 ( - new employee (2, "Jane", "Doe", 30, za, us, cs)); - - shared_ptr e3 ( - new employee (3, "Joe", "Dirt", 31, us, za, st)); - - shared_ptr e4 ( - new employee (4, "Johan", "Johansen", 32, se, se, cs)); - - transaction t (db->begin ()); - - db->persist (ca); - db->persist (za); - db->persist (us); - db->persist (se); - - db->persist (st); - db->persist (cs); - - db->persist (e1); - db->persist (e2); - db->persist (e3); - db->persist (e4); - - // Populate the legacy table. - // -#ifndef DATABASE_ORACLE - db->execute ("INSERT INTO view_employee_extra (" - "employee_id, vacation_days, previous_employer_id) " - "VALUES (1, 5, 2)"); - - db->execute ("INSERT INTO view_employee_extra (" - "employee_id, vacation_days, previous_employer_id) " - "VALUES (2, 10, NULL)"); - - db->execute ("INSERT INTO view_employee_extra (" - "employee_id, vacation_days, previous_employer_id) " - "VALUES (3, 0, NULL)"); - - db->execute ("INSERT INTO view_employee_extra (" - "employee_id, vacation_days, previous_employer_id) " - "VALUES (4, 15, 1)"); -#else - db->execute ("INSERT INTO \"view_employee_extra\" (" - "\"employee_id\", " - "\"vacation_days\", " - "\"previous_employer_id\") " - "VALUES (1, 5, 2)"); - - db->execute ("INSERT INTO \"view_employee_extra\" (" - "\"employee_id\", " - "\"vacation_days\", " - "\"previous_employer_id\") " - "VALUES (2, 10, NULL)"); - - db->execute ("INSERT INTO \"view_employee_extra\" (" - "\"employee_id\", " - "\"vacation_days\", " - "\"previous_employer_id\") " - "VALUES (3, 0, NULL)"); - - db->execute ("INSERT INTO \"view_employee_extra\" (" - "\"employee_id\", " - "\"vacation_days\", " - "\"previous_employer_id\") " - "VALUES (4, 15, 1)"); -#endif - - t.commit (); - } - - // Load names of the employees that are under 31 using the employee_name - // view. - // - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - result r (db->query (query::age < 31)); - - cout << "Employees under 31" << endl; - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << " " << i->first << " " << i->last << endl; - - cout << endl; - - t.commit (); - } - - // Count the number of employees which has the Doe last name using the - // employee_count view. - // - { - transaction t (db->begin ()); - - // Result of an aggregate query contains only one element so let's - // use the query_value() shortcut. - // - employee_count ec ( - db->query_value ( - query::last == "Doe")); - - cout << ec.count << " employees with the Doe last name" << endl - << endl; - - t.commit (); - } - - // Load the employee-employer information for all the employees with the - // Doe last name using the employee_employer view. - // - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - // Note that we need to add the object name after query::. - // - result r (db->query (query::employee::last == "Doe")); - - cout << "Employees with the Doe last name" << endl; - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << " " << i->first << " " << i->last << " " - << i->employer_name << endl; - - cout << endl; - - t.commit (); - } - - // Calculate min/max employee ages for each employer. - // - { - typedef odb::result result; - - transaction t (db->begin ()); - - result r (db->query ()); - - // Some other interesting queries to try: - // - // This one restricts the calculation to a specific employer: - // - // typedef odb::query query; - // - // result r (db->query ( - // query::employer::name == "Simple Tech Ltd")); - // - // And this one filters the employees based on certain criteria. - // - // result r (db->query ( - // query::employee::last == "Doe")); - // - - cout << "Min/max employee ages" << endl; - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << " " << i->employer_name << " " - << i->min_age << '/' << i->max_age << endl; - - cout << endl; - - t.commit (); - } - - // Load the country information for employees with different residence - // and nationality. - // - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - // Note that we use the alias given in the db object pragma after - // query::. - // - result r (db->query ( - query::res_country::name != query::nat_country::name)); - - cout << "Employees residing outside of country of nationality" << endl; - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << " " << i->first << " " << i->last << " " - << i->res_country_name << " " << i->nat_country_name << endl; - - cout << endl; - - t.commit (); - } - - // The same but using the object loading view. - // - { - typedef odb::query query; - typedef odb::result result; - - transaction t (db->begin ()); - - // We have to use a session in order for the object pointers - // in our view and object pointers inside objects that we load - // to point to the same instances, where appropriate. - // - session s; - - result r (db->query ( - query::res::name == query::nat::name)); - - cout << "Employees residing inside the country of nationality" << endl; - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - assert (i->e->nationality () == i->nat); - assert (i->e->residence () == i->res); - - const employee& e (*i->e); - const country& r (*i->res); - const country& n (*i->nat); - - cout << " " << e.first () << " " << e.last () << " " - << r.name () << " " << n.name () << endl; - } - - cout << endl; - - t.commit (); - } - - // Get the list of employers that have any employees. - // - { - typedef odb::result result; - - shared_ptr es (new employer (3, "Empty Shell LLC")); - - transaction t (db->begin ()); - db->persist (es); - - result r (db->query ()); - - cout << "Employers with employees" << endl; - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << " " << i->e->name () << endl; - - cout << endl; - - db->erase (es); - t.commit (); - } - - // Get the list of employees that have accumulated vacation days. - // - { - typedef odb::result result; - - transaction t (db->begin ()); - - // With native views we have to use the native SQL query syntax. - // -#ifndef DATABASE_ORACLE - result r (db->query ("vacation_days <> 0")); -#else - result r (db->query ("\"vacation_days\" <> 0")); -#endif - - cout << "Employees with accumulated vacation days" << endl; - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << " " << i->id << " " << i->days << endl; - - cout << endl; - - t.commit (); - } - - // Get the list of employees that have accumulated vacation days, this - // time using the improved employee_vacation2 view. - // - { - typedef odb::result result; - - transaction t (db->begin ()); - -#ifndef DATABASE_ORACLE - result r (db->query ("vacation_days <> 0")); -#else - result r (db->query ("\"vacation_days\" <> 0")); -#endif - - cout << "Employees with accumulated vacation days (take 2)" << endl; - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - cout << " " << i->first << " " << i->last << " " << i->days << endl; - - cout << endl; - - t.commit (); - } - - // Show the previous employers using the employee_prev_employer view. - // - { - typedef odb::result result; - - transaction t (db->begin ()); - - result r (db->query ()); - - cout << "Previous employees" << endl; - - for (result::iterator i (r.begin ()); i != r.end (); ++i) - { - const nullable& pe (i->prev_employer_name); - - cout << " " << i->first << " " << i->last << " " - << (pe.null () ? string ("N/A") : *pe) << endl; - } - - cout << endl; - - t.commit (); - } - } - catch (const odb::exception& e) - { - cerr << e.what () << endl; - return 1; - } -} diff --git a/view/employee.hxx b/view/employee.hxx deleted file mode 100644 index d73f9f2..0000000 --- a/view/employee.hxx +++ /dev/null @@ -1,356 +0,0 @@ -// file : view/employee.hxx -// copyright : not copyrighted - public domain - -#ifndef EMPLOYEE_HXX -#define EMPLOYEE_HXX - -#include -#include // std::size_t - -#include -#include - -// Include TR1 header in a compiler-specific fashion. Fall back -// on the Boost implementation if the compiler does not support TR1. -// -#include - -using std::tr1::shared_ptr; - -#pragma db object -class country -{ -public: - country (const std::string& code, const std::string& name) - : code_ (code), name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - -private: - friend class odb::access; - - country () {} - - #pragma db id - std::string code_; // ISO 2-letter country code. - - std::string name_; -}; - -#pragma db object -class employer -{ -public: - employer (unsigned long id, const std::string& name) - : id_ (id), name_ (name) - { - } - - const std::string& - name () const - { - return name_; - } - -private: - friend class odb::access; - - employer () {} - - #pragma db id - unsigned long id_; - - std::string name_; -}; - -#pragma db object -class employee -{ -public: - employee (unsigned long id, - const std::string& first, - const std::string& last, - unsigned short age, - shared_ptr res, - shared_ptr nat, - shared_ptr e) - : id_ (id), first_ (first), last_ (last), age_ (age), - residence_ (res), - nationality_ (nat), - employed_by_ (e) - { - } - - // Name. - // - const std::string& - first () const - { - return first_; - } - - const std::string& - last () const - { - return last_; - } - - // Age. - // - unsigned short - age () const - { - return age_; - } - - // Employer. - // - shared_ptr - employed_by () const - { - return employed_by_; - } - - // Residence and nationality. - // - shared_ptr - residence () const - { - return residence_; - } - - shared_ptr - nationality () const - { - return nationality_; - } - -private: - friend class odb::access; - - employee () {} - - #pragma db id - unsigned long id_; - - std::string first_; - std::string last_; - - unsigned short age_; - - shared_ptr residence_; - shared_ptr nationality_; - - shared_ptr employed_by_; -}; - -// We also have the "legacy" employee_extra table that is not mapped to any -// persistent class. It has the following columns: -// -// CREATE TABLE employee_extra( -// employee_id INTEGER NOT NULL, -// vacation_days INTEGER NOT NULL, -// previous_employer_id INTEGER) -// - -// A simple view with a single associated object. It allows us to get -// the name of an employee without loading any of the other parts, such -// as the referenced country and employer objects. The first and last -// data members in the view are automatically associated to the first_ -// and last_ members in the employee object. -// -#pragma db view object(employee) -struct employee_name -{ - std::string first; - std::string last; -}; - -// A simple aggregate view. It allows us to count the number of employees -// matching certain criteria. Here we use a column expression with a -// reference to the id_ data member in the employee object. -// -#pragma db view object(employee) -struct employee_count -{ - #pragma db column("count(" + employee::id_ + ")") - std::size_t count; -}; - -// A simple view with two associated object. It allows us to get the -// name of an employee and its employer without loading any other parts. -// Because there is an unambiguous relationship between the employee and -// employer objects (employee::employed_by_), the ODB compiler is able to -// automatically use this relationship as a join condition. Also, similar -// to the employee_name view, the first and last data members are auto- -// associated to the first_ and last_ members in the employee object. -// For the employer_name member we provide an explicit member reference. -// -#pragma db view object(employee) object(employer) -struct employee_employer -{ - std::string first; - std::string last; - - #pragma db column(employer::name_) - std::string employer_name; -}; - -// A more interesting aggregate view that uses the GROUP BY clause. It -// allows us to calculate the min/max ages of employees for each employer. -// Here we use the query condition with a placeholder (?). -// -#pragma db view object(employee) object(employer) \ - query ((?) + "GROUP BY" + employer::name_) -struct employer_age -{ - #pragma db column(employer::name_) - std::string employer_name; - - #pragma db column("min(" + employee::age_ + ")") - unsigned short min_age; - - #pragma db column("max(" + employee::age_ + ")") - unsigned short max_age; -}; - -// A more complex view with three associated objects, two of which are -// of the same type. This requires us to use aliases and disambiguate -// the relationships used to associate each object. -// -#pragma db view object(employee) \ - object(country = res_country: employee::residence_) \ - object(country = nat_country: employee::nationality_) -struct employee_country -{ - std::string first; - std::string last; - - #pragma db column(res_country::name_) - std::string res_country_name; - - #pragma db column(nat_country::name_) - std::string nat_country_name; -}; - -// An example of an object loading view. It is a different version of -// the above view that loads the complete objects instead of a subset -// of their data members. -// -#pragma db view object(employee) \ - object(country = res: employee::residence_) \ - object(country = nat: employee::nationality_) -struct employee_country_objects -{ - shared_ptr e; - shared_ptr res; - shared_ptr nat; -}; - -// An example of using inner join type. Here we want to find employers -// that have any employees. If we were to use the default left join type, -// then we would have gotten all the employers, regardless of whether -// they have any employees. By using the inner join, we make sure that -// only matching employers are returned. -// -// It is also likely that there will be more than one employee for any -// particular employer which will lead to duplicate employer records -// being returned. To avoid this we use the 'distinct' result modifier. -// -// Try to change the join type or remove 'distinct' to observe the -// change in behavior. -// -#pragma db view object(employer) object(employee inner) query(distinct) -struct employer_with_employees -{ - shared_ptr e; -}; - -// An example of a native view that provides a complete query and is based -// on an ad-hoc table. This view allows us to load the employee vacation -// information from the legacy employee_extra table. -// -#ifndef ODB_DATABASE_ORACLE - #pragma db view query("SELECT employee_id, vacation_days " \ - "FROM view_employee_extra") -#else - #pragma db view query("SELECT \"employee_id\", \"vacation_days\" " \ - "FROM \"view_employee_extra\"") -#endif -struct employee_vacation -{ - #pragma db type("INTEGER") - unsigned long id; - - #pragma db type("INTEGER") - unsigned short days; -}; - -// A more robust implementation of the above view as a table view instead -// of a native view. -// -#pragma db view table("view_employee_extra") -struct employee_vacation1 -{ - #pragma db column("employee_id") type("INTEGER") - unsigned long id; - - #pragma db column("vacation_days") type("INTEGER") - unsigned short days; -}; - -// An improved version of the previous view that extracts the employee -// first and last names instead of the id. To get the names we need to -// add the employee object to this view and use a custom join condition -// to tie it up with our legacy table. -// -#ifndef ODB_DATABASE_ORACLE - #pragma db view table("view_employee_extra") \ - object(employee: "view_employee_extra.employee_id = " + employee::id_) -#else - #pragma db view table("view_employee_extra") \ - object(employee: "\"view_employee_extra\".\"employee_id\" = " + \ - employee::id_) -#endif -struct employee_vacation2 -{ - std::string first; - std::string last; - - #pragma db column("view_employee_extra.vacation_days") type("INTEGER") - unsigned short days; -}; - -// A mixed view that associates two objects and a legacy table. It returns -// the previous employer information for each employee. -// -#ifndef ODB_DATABASE_ORACLE - #pragma db view object(employee) \ - table("view_employee_extra" = "extra": \ - "extra.employee_id = " + employee::id_) \ - object(employer: "extra.previous_employer_id = " + employer::id_) -#else - #pragma db view object(employee) \ - table("view_employee_extra" = "extra": \ - "\"extra\".\"employee_id\" = " + employee::id_) \ - object(employer: "\"extra\".\"previous_employer_id\" = " + employer::id_) -#endif -struct employee_prev_employer -{ - std::string first; - std::string last; - - // If previous_employer_id is NULL, then the name will be NULL as well. - // We use the odb::nullable wrapper to handle this. - // - #pragma db column(employer::name_) - odb::nullable prev_employer_name; -}; - -#endif // EMPLOYEE_HXX diff --git a/view/makefile b/view/makefile deleted file mode 100644 index 7dcd62f..0000000 --- a/view/makefile +++ /dev/null @@ -1,125 +0,0 @@ -# file : view/makefile -# license : GNU GPL v2; see accompanying LICENSE file - -include $(dir $(lastword $(MAKEFILE_LIST)))../build/bootstrap.make - -cxx_tun := driver.cxx -odb_hdr := employee.hxx -cxx_obj := $(addprefix $(out_base)/,$(cxx_tun:.cxx=.o) $(odb_hdr:.hxx=-odb.o)) -cxx_od := $(cxx_obj:.o=.o.d) - -driver := $(out_base)/driver -dist := $(out_base)/.dist -test := $(out_base)/.test -clean := $(out_base)/.clean - -# Import. -# -$(call import,\ - $(scf_root)/import/odb/stub.make,\ - odb: odb,odb-rules: odb_rules) - -$(call import,\ - $(scf_root)/import/libodb/stub.make,\ - l: odb.l,cpp-options: odb.l.cpp-options) - -ifdef db_id -$(call import,\ - $(scf_root)/import/libodb-$(db_id)/stub.make,\ - l: odb_db.l,cpp-options: odb_db.l.cpp-options) -endif - -ifeq ($(odb_db.l.cpp-options),) -odb_db.l.cpp-options := $(out_base)/.unbuildable -endif - -# Build. -# -$(driver): $(cxx_obj) $(odb_db.l) $(odb.l) -$(cxx_obj) $(cxx_od): cpp_options := -I$(out_base) -I$(src_base) -D$(db_macro) -$(cxx_obj) $(cxx_od): $(odb.l.cpp-options) $(odb_db.l.cpp-options) - -genf := $(addprefix $(odb_hdr:.hxx=-odb),.hxx .ixx .cxx) $(odb_hdr:.hxx=.sql) -gen := $(addprefix $(out_base)/,$(genf)) - -$(gen): $(odb) -$(gen): odb := $(odb) -$(gen) $(dist): export odb_options += --generate-query --generate-schema \ ---default-pointer std::tr1::shared_ptr --generate-session --table-prefix view_ -$(gen): cpp_options := -I$(src_base) -$(gen): $(odb.l.cpp-options) - -$(gen): odb_options += --database $(db_id) - -$(call include-dep,$(cxx_od),$(cxx_obj),$(gen)) - -# Alias for default target. -# -$(out_base)/: $(driver) - -# Dist -# -name := $(subst /,-,$(subst $(src_root)/,,$(src_base))) - -$(dist): sources := $(cxx_tun) -$(dist): headers := $(odb_hdr) -$(dist): export name := $(name) -$(dist): export odb_header_stem := $(basename $(odb_hdr)) -$(dist): export extra_dist := README $(call vc8projs,$(name)) \ -$(call vc9projs,$(name)) $(call vc10projs,$(name)) $(call vc11projs,$(name)) \ -$(call vc12projs,$(name)) -$(dist): - $(call dist-data,$(sources) $(headers) README database.hxx) - $(call meta-automake,../template/Makefile.am) - $(call meta-vc8projs,../template/template,$(name)) - $(call meta-vc9projs,../template/template,$(name)) - $(call meta-vc10projs,../template/template,$(name)) - $(call meta-vc11projs,../template/template,$(name)) - $(call meta-vc12projs,../template/template,$(name)) - -# Test. -# -$(test): header := $(odb_hdr) -$(test): $(driver) - $(call schema) - $(call message,test $<,$< --options-file $(dcf_root)/$(db_id).options) - -# Clean. -# -$(clean): \ - $(driver).o.clean \ - $(addsuffix .cxx.clean,$(cxx_obj)) \ - $(addsuffix .cxx.clean,$(cxx_od)) \ - $(addprefix $(out_base)/,$(odb_hdr:.hxx=-odb.cxx.hxx.clean)) - -# Generated .gitignore. -# -ifeq ($(out_base),$(src_base)) -$(driver): | $(out_base)/.gitignore - -$(out_base)/.gitignore: files := driver $(genf) -$(clean): $(out_base)/.gitignore.clean - -$(call include,$(bld_root)/git/gitignore.make) -endif - -# How to. -# -$(call include,$(bld_root)/dist.make) -$(call include,$(bld_root)/meta/vc8proj.make) -$(call include,$(bld_root)/meta/vc9proj.make) -$(call include,$(bld_root)/meta/vc10proj.make) -$(call include,$(bld_root)/meta/vc11proj.make) -$(call include,$(bld_root)/meta/vc12proj.make) -$(call include,$(bld_root)/meta/automake.make) - -$(call include,$(bld_root)/cxx/standard.make) # cxx_standard -ifdef cxx_standard -$(gen): odb_options += --std $(cxx_standard) -$(call include,$(odb_rules)) -endif - -$(call include,$(bld_root)/cxx/cxx-d.make) -$(call include,$(bld_root)/cxx/cxx-o.make) -$(call include,$(bld_root)/cxx/o-e.make) - -- cgit v1.1