summaryrefslogtreecommitdiff
path: root/odb-tests/common/schema/embedded
diff options
context:
space:
mode:
Diffstat (limited to 'odb-tests/common/schema/embedded')
-rw-r--r--odb-tests/common/schema/embedded/basics/buildfile42
-rw-r--r--odb-tests/common/schema/embedded/basics/driver.cxx59
-rw-r--r--odb-tests/common/schema/embedded/basics/test.hxx23
-rw-r--r--odb-tests/common/schema/embedded/basics/testscript31
-rw-r--r--odb-tests/common/schema/embedded/order/.gitignore6
-rw-r--r--odb-tests/common/schema/embedded/order/buildfile48
-rw-r--r--odb-tests/common/schema/embedded/order/driver.cxx65
-rw-r--r--odb-tests/common/schema/embedded/order/test1.hxx23
-rw-r--r--odb-tests/common/schema/embedded/order/test2.hxx17
-rw-r--r--odb-tests/common/schema/embedded/order/testscript31
10 files changed, 345 insertions, 0 deletions
diff --git a/odb-tests/common/schema/embedded/basics/buildfile b/odb-tests/common/schema/embedded/basics/buildfile
new file mode 100644
index 0000000..0cfe85e
--- /dev/null
+++ b/odb-tests/common/schema/embedded/basics/buildfile
@@ -0,0 +1,42 @@
+# file : common/schema/embedded/basics/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+import libodb = libodb%lib{odb}
+
+libs =
+
+for db: $databases
+ import libs += libodb-$db%lib{odb-$db}
+
+import libs += lib{common}
+
+exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} {hxx ixx cxx}{test-odb} testscript
+
+# Introduce the metadata library target to make sure the libodb library is
+# resolved for the odb_compile ad hoc rule (see build/root.build for details).
+#
+libue{test-meta}: $libodb
+
+<{hxx ixx cxx}{test-odb}>: hxx{test} libue{test-meta}
+
+for db: $databases
+{
+ exe{driver}: {hxx ixx cxx}{test-odb-$db}: include = $multi
+ <{hxx ixx cxx}{test-odb-$db}>: hxx{test} libue{test-meta}
+}
+
+exe{driver}: libue{test-meta} $libs
+
+# Specify the ODB custom options to be used by the odb_compile ad hoc rule
+# (see build/root.build for details).
+#
+odb_options = --table-prefix schema_embd_bscs_ \
+ --generate-schema \
+ --schema-format embedded \
+ --schema-name test
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../../../alias{database-client}: include = adhoc
diff --git a/odb-tests/common/schema/embedded/basics/driver.cxx b/odb-tests/common/schema/embedded/basics/driver.cxx
new file mode 100644
index 0000000..7ba2bce
--- /dev/null
+++ b/odb-tests/common/schema/embedded/basics/driver.cxx
@@ -0,0 +1,59 @@
+// file : common/schema/embedded/basics/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test basic embedded schema functionality.
+//
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+#include <odb/schema-catalog.hxx>
+
+#include <libcommon/common.hxx>
+
+#include "test.hxx"
+#include "test-odb.hxx"
+
+#undef NDEBUG
+#include <cassert>
+
+using namespace std;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv, false));
+
+ // Create the database schema.
+ //
+ {
+ connection_ptr c (db->connection ());
+
+ // Temporarily disable foreign key constraints for SQLite.
+ //
+ if (db->id () == odb::id_sqlite)
+ c->execute ("PRAGMA foreign_keys=OFF");
+
+ assert (schema_catalog::exists (*db, "test"));
+ assert (!schema_catalog::exists (*db, "test1"));
+ assert (!schema_catalog::exists (*db, ""));
+
+ transaction t (c->begin ());
+ schema_catalog::create_schema (*db, "test");
+ t.commit ();
+
+ if (db->id () == odb::id_sqlite)
+ c->execute ("PRAGMA foreign_keys=ON");
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/common/schema/embedded/basics/test.hxx b/odb-tests/common/schema/embedded/basics/test.hxx
new file mode 100644
index 0000000..43331f9
--- /dev/null
+++ b/odb-tests/common/schema/embedded/basics/test.hxx
@@ -0,0 +1,23 @@
+// file : common/schema/embedded/basics/test.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST_HXX
+#define TEST_HXX
+
+#include <string>
+#include <vector>
+
+#include <odb/core.hxx>
+
+#pragma db object
+struct object
+{
+ #pragma db auto id
+ unsigned long id;
+
+ std::string str;
+
+ std::vector<int> nums;
+};
+
+#endif // TEST_HXX
diff --git a/odb-tests/common/schema/embedded/basics/testscript b/odb-tests/common/schema/embedded/basics/testscript
new file mode 100644
index 0000000..24448c0
--- /dev/null
+++ b/odb-tests/common/schema/embedded/basics/testscript
@@ -0,0 +1,31 @@
+# file : common/schema/embedded/basics/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../../../database-options.testscript
+
+: mysql
+:
+if $mysql
+{
+ .include ../../../../mysql.testscript
+
+ $*
+}
+
+: sqlite
+:
+if $sqlite
+{
+ .include ../../../../sqlite.testscript
+
+ $*
+}
+
+: pgsql
+:
+if $pgsql
+{
+ .include ../../../../pgsql.testscript
+
+ $*
+}
diff --git a/odb-tests/common/schema/embedded/order/.gitignore b/odb-tests/common/schema/embedded/order/.gitignore
new file mode 100644
index 0000000..5d39d39
--- /dev/null
+++ b/odb-tests/common/schema/embedded/order/.gitignore
@@ -0,0 +1,6 @@
+# ODB-generated files.
+#
+test1-odb.?xx
+test1-odb-*.?xx
+test2-odb.?xx
+test2-odb-*.?xx
diff --git a/odb-tests/common/schema/embedded/order/buildfile b/odb-tests/common/schema/embedded/order/buildfile
new file mode 100644
index 0000000..57ad7dd
--- /dev/null
+++ b/odb-tests/common/schema/embedded/order/buildfile
@@ -0,0 +1,48 @@
+# file : common/schema/embedded/order/buildfile
+# license : GNU GPL v2; see accompanying LICENSE file
+
+import libodb = libodb%lib{odb}
+
+libs =
+
+for db: $databases
+ import libs += libodb-$db%lib{odb-$db}
+
+import libs += lib{common}
+
+hs = test1 test2
+
+exe{driver}: {hxx cxx}{* -*-odb -*-odb-*} testscript
+
+# Introduce the metadata library target to make sure the libodb library is
+# resolved for the odb_compile ad hoc rule (see build/root.build for details).
+#
+libue{test-meta}: $libodb
+
+for h: $hs
+{
+ exe{driver}: {hxx ixx cxx}{$h-odb}
+
+ <{hxx ixx cxx}{$h-odb}>: hxx{$h} libue{test-meta}
+
+ for db: $databases
+ {
+ exe{driver}: {hxx ixx cxx}{$h-odb-$db}: include = $multi
+ <{hxx ixx cxx}{$h-odb-$db}>: hxx{$h} libue{test-meta}
+ }
+}
+
+exe{driver}: libue{test-meta} $libs
+
+# Specify the ODB custom options to be used by the odb_compile ad hoc rule
+# (see build/root.build for details).
+#
+odb_options = --table-prefix schema_embd_ordr_ \
+ --generate-schema \
+ --schema-format embedded
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
+
+# Testscript's run-time prerequisites.
+#
+exe{driver}: ../../../../alias{database-client}: include = adhoc
diff --git a/odb-tests/common/schema/embedded/order/driver.cxx b/odb-tests/common/schema/embedded/order/driver.cxx
new file mode 100644
index 0000000..fde5e96
--- /dev/null
+++ b/odb-tests/common/schema/embedded/order/driver.cxx
@@ -0,0 +1,65 @@
+// file : common/schema/embedded/order/driver.cxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+// Test statement execution order in embedded schemas.
+//
+
+#include <memory> // std::unique_ptr
+#include <iostream>
+
+#include <odb/database.hxx>
+#include <odb/transaction.hxx>
+#include <odb/schema-catalog.hxx>
+
+#include <libcommon/common.hxx>
+
+#include "test1.hxx"
+#include "test2.hxx"
+
+#include "test1-odb.hxx"
+#include "test2-odb.hxx"
+
+#undef NDEBUG
+#include <cassert>
+
+using namespace std;
+using namespace odb::core;
+
+int
+main (int argc, char* argv[])
+{
+ try
+ {
+ unique_ptr<database> db (create_database (argc, argv, false));
+ odb::database_id db_id (db->id ());
+
+ // Create the database schema.
+ //
+ {
+ connection_ptr c (db->connection ());
+
+ // Temporarily disable foreign key constraints for MySQL and SQLite.
+ // For MySQL we can actually create the tables in any order. It is
+ // dropping them that's the problem (there is no IF EXISTS).
+ //
+ if (db_id == odb::id_mysql)
+ c->execute ("SET FOREIGN_KEY_CHECKS=0");
+ else if (db_id == odb::id_sqlite)
+ c->execute ("PRAGMA foreign_keys=OFF");
+
+ transaction t (c->begin ());
+ schema_catalog::create_schema (*db);
+ t.commit ();
+
+ if (db_id == odb::id_mysql)
+ c->execute ("SET FOREIGN_KEY_CHECKS=1");
+ else if (db_id == odb::id_sqlite)
+ c->execute ("PRAGMA foreign_keys=ON");
+ }
+ }
+ catch (const odb::exception& e)
+ {
+ cerr << e.what () << endl;
+ return 1;
+ }
+}
diff --git a/odb-tests/common/schema/embedded/order/test1.hxx b/odb-tests/common/schema/embedded/order/test1.hxx
new file mode 100644
index 0000000..b35074b
--- /dev/null
+++ b/odb-tests/common/schema/embedded/order/test1.hxx
@@ -0,0 +1,23 @@
+// file : common/schema/embedded/order/test1.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST1_HXX
+#define TEST1_HXX
+
+#include <string>
+
+#include <odb/core.hxx>
+
+#pragma db object polymorphic
+struct base
+{
+ virtual
+ ~base () {}
+
+ #pragma db auto id
+ unsigned long id;
+
+ std::string str;
+};
+
+#endif // TEST1_HXX
diff --git a/odb-tests/common/schema/embedded/order/test2.hxx b/odb-tests/common/schema/embedded/order/test2.hxx
new file mode 100644
index 0000000..b4e6d20
--- /dev/null
+++ b/odb-tests/common/schema/embedded/order/test2.hxx
@@ -0,0 +1,17 @@
+// file : common/schema/embedded/order/test2.hxx
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#ifndef TEST2_HXX
+#define TEST2_HXX
+
+#include <odb/core.hxx>
+
+#include "test1.hxx"
+
+#pragma db object
+struct derived: base
+{
+ int num;
+};
+
+#endif // TEST2_HXX
diff --git a/odb-tests/common/schema/embedded/order/testscript b/odb-tests/common/schema/embedded/order/testscript
new file mode 100644
index 0000000..6dfe58c
--- /dev/null
+++ b/odb-tests/common/schema/embedded/order/testscript
@@ -0,0 +1,31 @@
+# file : common/schema/embedded/order/testscript
+# license : GNU GPL v2; see accompanying LICENSE file
+
+.include ../../../../database-options.testscript
+
+: mysql
+:
+if $mysql
+{
+ .include ../../../../mysql.testscript
+
+ $*
+}
+
+: sqlite
+:
+if $sqlite
+{
+ .include ../../../../sqlite.testscript
+
+ $*
+}
+
+: pgsql
+:
+if $pgsql
+{
+ .include ../../../../pgsql.testscript
+
+ $*
+}