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 --- view/driver.cxx | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'view/driver.cxx') 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 ("vacation_days <> 0")); +#else + result r (db->query ("\"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 ("vacation_days <> 0")); +#else + result r (db->query ("\"vacation_days\" <> 0")); +#endif cout << "Employees with accumulated vacation days (take 2)" << endl; -- cgit v1.1