aboutsummaryrefslogtreecommitdiff
path: root/schema/custom
diff options
context:
space:
mode:
Diffstat (limited to 'schema/custom')
-rw-r--r--schema/custom/database.hxx7
-rw-r--r--schema/custom/driver.cxx59
-rw-r--r--schema/custom/employee.hxx4
3 files changed, 68 insertions, 2 deletions
diff --git a/schema/custom/database.hxx b/schema/custom/database.hxx
index 76dedb6..5bca839 100644
--- a/schema/custom/database.hxx
+++ b/schema/custom/database.hxx
@@ -22,6 +22,8 @@
# include <odb/sqlite/database.hxx>
#elif defined(DATABASE_PGSQL)
# include <odb/pgsql/database.hxx>
+#elif defined(DATABASE_ORACLE)
+# include <odb/oracle/database.hxx>
#endif
inline std::auto_ptr<odb::database>
@@ -41,6 +43,8 @@ create_database (int& argc, char* argv[])
odb::sqlite::database::print_usage (cerr);
#elif defined(DATABASE_PGSQL)
odb::pgsql::database::print_usage (cerr);
+#elif defined(DATABASE_ORACLE)
+ odb::oracle::database::print_usage (cerr);
#endif
exit (0);
@@ -54,6 +58,9 @@ create_database (int& argc, char* argv[])
argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE));
#elif defined(DATABASE_PGSQL)
auto_ptr<database> db (new odb::pgsql::database (argc, argv));
+#elif defined(DATABASE_ORACLE)
+ auto_ptr<database> db (
+ new odb::oracle::database (argc, argv, false, 873, 873));
#endif
return db;
diff --git a/schema/custom/driver.cxx b/schema/custom/driver.cxx
index 9d049ed..a140ee1 100644
--- a/schema/custom/driver.cxx
+++ b/schema/custom/driver.cxx
@@ -116,6 +116,65 @@ main (int argc, char* argv[])
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
diff --git a/schema/custom/employee.hxx b/schema/custom/employee.hxx
index 651f8c3..0f15cf8 100644
--- a/schema/custom/employee.hxx
+++ b/schema/custom/employee.hxx
@@ -133,8 +133,8 @@ private:
employee (): name_ ("", "") {}
- #pragma db id type("INTEGER UNSIGNED") column("ssn")
- unsigned long id_;
+ #pragma db id type("INTEGER") column("ssn")
+ long id_;
#pragma db column("") // No column prefix.
name_type name_;