diff options
Diffstat (limited to 'view')
-rw-r--r-- | view/database.hxx | 7 | ||||
-rw-r--r-- | view/driver.cxx | 55 | ||||
-rw-r--r-- | view/employee.hxx | 34 |
3 files changed, 87 insertions, 9 deletions
diff --git a/view/database.hxx b/view/database.hxx index c68e3e1..dbf573d 100644 --- a/view/database.hxx +++ b/view/database.hxx @@ -25,6 +25,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> @@ -44,6 +46,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); @@ -73,6 +77,9 @@ create_database (int& argc, char* argv[]) } #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/view/driver.cxx b/view/driver.cxx index bc32513..118b126 100644 --- a/view/driver.cxx +++ b/view/driver.cxx @@ -33,7 +33,18 @@ main (int argc, char* argv[]) transaction t (db->begin ()); try { - db->execute ("DROP TABLE view_employee_extra"); +#ifndef DATABASE_ORACLE + db->execute ("DROP TABLE \"view_employee_extra\""); +#else + db->execute ("BEGIN " + " EXECUTE IMMEDIATE " + " 'DROP TABLE \"view_employee_extra\" " + " CASCADE CONSTRAINTS';" + " EXCEPTION " + " WHEN OTHERS THEN " + " IF SQLCODE != -942 THEN RAISE; END IF;" + "END;"); +#endif t.commit (); } catch (const odb::exception&) @@ -44,11 +55,19 @@ main (int argc, char* argv[]) { 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 (); } @@ -94,6 +113,7 @@ main (int argc, char* argv[]) // 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)"); @@ -109,6 +129,31 @@ main (int argc, char* argv[]) 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 (); } @@ -244,7 +289,11 @@ main (int argc, char* argv[]) // With native views we have to use the native SQL query syntax. // +#ifndef DATABASE_ORACLE result r (db->query<employee_vacation> ("vacation_days <> 0")); +#else + result r (db->query<employee_vacation> ("\"vacation_days\" <> 0")); +#endif cout << "Employees with accumulated vacation days" << endl; @@ -264,7 +313,11 @@ main (int argc, char* argv[]) transaction t (db->begin ()); +#ifndef DATABASE_ORACLE result r (db->query<employee_vacation2> ("vacation_days <> 0")); +#else + result r (db->query<employee_vacation2> ("\"vacation_days\" <> 0")); +#endif cout << "Employees with accumulated vacation days (take 2)" << endl; diff --git a/view/employee.hxx b/view/employee.hxx index 110cb9e..848a30c 100644 --- a/view/employee.hxx +++ b/view/employee.hxx @@ -236,8 +236,13 @@ struct employee_country // on an ad-hoc table. This view allows us to load the employee vacation // information from the legacy employee_extra table. // -#pragma db view query("SELECT employee_id, vacation_days " \ - "FROM view_employee_extra") +#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") @@ -265,8 +270,14 @@ struct employee_vacation1 // add the employee object to this view and use a custom join condition // to tie it up with our legacy table. // -#pragma db view table("view_employee_extra") \ - object(employee: "view_employee_extra.employee_id = " + employee::id_) +#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; @@ -279,10 +290,17 @@ struct employee_vacation2 // A mixed view that associates two objects and a legacy table. It returns // the previous employer information for each employee. // -#pragma db view object(employee) \ - table("view_employee_extra" = "extra": \ - "extra.employee_id = " + employee::id_) \ - object(employer: "extra.previous_employer_id = " + employer::id_) +#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; |