From 9616e3e84946c23f64448978d9459d2a25202833 Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Thu, 17 Nov 2011 11:44:45 +0200 Subject: Add examples for Oracle --- schema/custom/database.hxx | 7 ++++++ schema/custom/driver.cxx | 59 ++++++++++++++++++++++++++++++++++++++++++++ schema/custom/employee.hxx | 4 +-- schema/embedded/database.hxx | 7 ++++++ 4 files changed, 75 insertions(+), 2 deletions(-) (limited to 'schema') 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 #elif defined(DATABASE_PGSQL) # include +#elif defined(DATABASE_ORACLE) +# include #endif inline std::auto_ptr @@ -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 db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + auto_ptr 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_; diff --git a/schema/embedded/database.hxx b/schema/embedded/database.hxx index 9a2cbed..f1cf1e5 100644 --- a/schema/embedded/database.hxx +++ b/schema/embedded/database.hxx @@ -22,6 +22,8 @@ # include #elif defined(DATABASE_PGSQL) # include +#elif defined(DATABASE_ORACLE) +# include #endif inline std::auto_ptr @@ -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 db (new odb::pgsql::database (argc, argv)); +#elif defined(DATABASE_ORACLE) + auto_ptr db ( + new odb::oracle::database (argc, argv, false, 873, 873)); #endif return db; -- cgit v1.1