From 1f14eecfed1303d5d7bf5febcba29e06c2d19d9e Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Wed, 26 Oct 2011 10:05:25 +0200 Subject: Quote schema object identifiers for Oracle where necessary Oracle converts all alphabetical characters in unquoted schema object identifiers to uppercase. This behaviour cannot be disabled. --- common/view/driver.cxx | 42 +++++++++++++++++++-- common/view/test.hxx | 99 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 121 insertions(+), 20 deletions(-) (limited to 'common/view') diff --git a/common/view/driver.cxx b/common/view/driver.cxx index 2ede99c..b671e46 100644 --- a/common/view/driver.cxx +++ b/common/view/driver.cxx @@ -14,6 +14,7 @@ #include #include +#include // DATABASE_XXX #include "test.hxx" #include "test-odb.hxx" @@ -58,7 +59,8 @@ view2_test (const auto_ptr& db) } { - result r (db->query ("age < 31")); + result r (db->query (query::age + " < 31")); + iterator i (r.begin ()); assert (i != r.end ()); assert (i->count == 2); @@ -85,7 +87,10 @@ view4_test (const auto_ptr& db) transaction t (db->begin ()); { - result r (db->query ("age > 30 ORDER BY age")); + result r (db->query ( + (query::person::age > 30) + + "ORDER BY " + + query::person::age)); iterator i (r.begin ()); @@ -102,7 +107,9 @@ view4_test (const auto_ptr& db) { result r (db->query ( - (query::person::age > 30) + "ORDER BY age")); + (query::person::age > 30) + + "ORDER BY " + + query::person::age)); iterator i (r.begin ()); @@ -229,12 +236,20 @@ main (int argc, char* argv[]) } { +#ifndef DATABASE_ORACLE result r (db->query ("ORDER BY age")); +#else + result r (db->query ("ORDER BY \"age\"")); +#endif assert (size (r) == 4); } { +#ifndef DATABASE_ORACLE result r (db->query ("age < 31 ORDER BY age")); +#else + result r (db->query ("\"age\" < 31 ORDER BY \"age\"")); +#endif view1_check (r); } @@ -277,7 +292,12 @@ main (int argc, char* argv[]) { transaction t (db->begin ()); +#ifndef DATABASE_ORACLE result r (db->query ("first = " + query::_val ("Jane"))); +#else + result r (db->query ("\"first\" = " + query::_val ("Jane"))); +#endif + result::iterator i (r.begin ()); assert (i != r.end ()); @@ -298,11 +318,19 @@ main (int argc, char* argv[]) { transaction t (db->begin ()); +#ifndef DATABASE_ORACLE result r ( db->query ( "SELECT first, last, age " "FROM t_view_person " "WHERE age < 31 ORDER BY age")); +#else + result r ( + db->query ( + "SELECT \"first\", \"last\", \"age\" " + "FROM \"t_view_person\" " + "WHERE \"age\" < 31 ORDER BY \"age\"")); +#endif view1_check (r); @@ -320,7 +348,11 @@ main (int argc, char* argv[]) transaction t (db->begin ()); { +#ifndef DATABASE_ORACLE result r (db->query ("age < 31 ORDER BY age")); +#else + result r (db->query ("\"age\" < 31 ORDER BY \"age\"")); +#endif view1_check (r); } @@ -438,7 +470,11 @@ main (int argc, char* argv[]) db, odb::query::employer::name == "Simple Tech, Inc"); view6_test ( +#ifndef DATABASE_ORACLE db, "e.name = " + odb::query::_val ("Simple Tech, Inc")); +#else + db, "\"e\".\"name\" = " + odb::query::_val ("Simple Tech, Inc")); +#endif // view7 // diff --git a/common/view/test.hxx b/common/view/test.hxx index 5efbd1c..dee121c 100644 --- a/common/view/test.hxx +++ b/common/view/test.hxx @@ -13,6 +13,8 @@ #include #include +#include // DATABASE_XXX + struct employer; #pragma db object @@ -130,7 +132,12 @@ struct employer // Complete suffix query template. // -#pragma db view query("SELECT first, last, age FROM t_view_person") +#ifndef DATABASE_ORACLE +# pragma db view query("SELECT first, last, age FROM t_view_person") +#else +# pragma db view query("SELECT \"first\", \"last\", \"age\" " \ + "FROM \"t_view_person\"") +#endif struct view1 { std::string first; @@ -140,9 +147,15 @@ struct view1 // Complete query. // -#pragma db view query("SELECT first, last, age " \ - "FROM t_view_person " \ - "WHERE age < 31 ORDER BY age") +#ifndef DATABASE_ORACLE +# pragma db view query("SELECT first, last, age " \ + "FROM t_view_person " \ + "WHERE age < 31 ORDER BY age") +#else +# pragma db view query("SELECT \"first\", \"last\", \"age\" " \ + "FROM \"t_view_person\" " \ + "WHERE \"age\" < 31 ORDER BY \"age\"") +#endif struct view1a { std::string first; @@ -152,9 +165,15 @@ struct view1a // Complete placeholder query template. // -#pragma db view query("SELECT first, last, age " \ - "FROM t_view_person " \ - "WHERE age < 31 AND (?) ORDER BY age") +#ifndef DATABASE_ORACLE +# pragma db view query("SELECT first, last, age " \ + "FROM t_view_person " \ + "WHERE age < 31 AND (?) ORDER BY age") +#else +# pragma db view query("SELECT \"first\", \"last\", \"age\" " \ + "FROM \"t_view_person\" " \ + "WHERE \"age\" < 31 AND (?) ORDER BY \"age\"") +#endif struct view1b { std::string first; @@ -193,8 +212,13 @@ struct view1d // Complete suffix query. // -#pragma db view object(person) \ +#ifndef DATABASE_ORACLE +# pragma db view object(person) \ query("SELECT count(id) FROM t_view_person") +#else +# pragma db view object(person) \ + query("SELECT count(\"id\") FROM \"t_view_person\"") +#endif struct view2 { std::size_t count; @@ -205,7 +229,11 @@ struct view2 #pragma db view object(person) struct view2a { +#ifndef DATABASE_ORACLE #pragma db column("count(id)") +#else + #pragma db column("count(\"id\")") +#endif std::size_t count; }; @@ -214,7 +242,11 @@ struct view2a #pragma db view object(person) struct view2b { +#ifndef DATABASE_ORACLE #pragma db column("count(t_view_person.id)") +#else + #pragma db column("count(\"t_view_person\".\"id\")") +#endif std::size_t count; }; @@ -233,10 +265,17 @@ struct view2c // Complete suffix query. // -#pragma db view object(person = test) \ - query("SELECT last, count(last) " \ - "FROM t_view_person " \ +#ifndef DATABASE_ORACLE +# pragma db view object(person = test) \ + query("SELECT last, count(last) " \ + "FROM t_view_person " \ "GROUP BY last") +#else +# pragma db view object(person = test) \ + query("SELECT \"last\", count(\"last\") " \ + "FROM \"t_view_person\" " \ + "GROUP BY \"last\"") +#endif struct view3 { std::string last_name; @@ -263,11 +302,19 @@ struct view3a // Complete suffix query. // -#pragma db view object(person) object(country = residence) \ - query("SELECT first, last, residence.name " \ - "FROM t_view_person " \ - "LEFT JOIN t_view_country AS residence " \ +#ifndef DATABASE_ORACLE +# pragma db view object(person) object(country = residence) \ + query("SELECT first, last, residence.name " \ + "FROM t_view_person " \ + "LEFT JOIN t_view_country AS residence " \ "ON t_view_person.residence = residence.code") +#else +# pragma db view object(person) object(country = residence) \ + query("SELECT \"first\", \"last\", \"residence\".\"name\" " \ + "FROM \"t_view_person\" " \ + "LEFT JOIN \"t_view_country\" \"residence\" " \ + "ON \"t_view_person\".\"residence\" = \"residence\".\"code\"") +#endif struct view4 { std::string first_name; @@ -347,18 +394,36 @@ struct view6b // The same using tables. // -#pragma db view table("t_view_person" = "p") \ +#ifndef DATABASE_ORACLE +# pragma db view table("t_view_person" = "p") \ table("t_view_employer_employees" = "ee": "ee.value = p.id") \ table("t_view_employer" = "e": "ee.object_id = e.name") +#else +# pragma db view table("t_view_person" = "p") \ + table("t_view_employer_employees" = "ee": "\"ee\".\"value\" = \"p\".\"id\"")\ + table("t_view_employer" = "e": "\"ee\".\"object_id\" = \"e\".\"name\"") +#endif struct view6c { +#ifndef DATABASE_ORACLE #pragma db column("p.first") +#else + #pragma db column("\"p\".\"first\"") +#endif std::string first_name; - #pragma db column("p"."last") +#ifndef DATABASE_ORACLE + #pragma db column("p.last") +#else + #pragma db column("\"p\".\"last\"") +#endif std::string last_name; +#ifndef DATABASE_ORACLE #pragma db column("e.name") +#else + #pragma db column("\"e\".\"name\"") +#endif std::string employer; }; -- cgit v1.1