summaryrefslogtreecommitdiff
path: root/odb/relational/oracle/schema.cxx
diff options
context:
space:
mode:
authorConstantin Michael <constantin@codesynthesis.com>2011-10-14 15:05:49 +0200
committerConstantin Michael <constantin@codesynthesis.com>2011-10-21 11:47:13 +0200
commit7470a1aeb62f13a9834c566c1bdafa53f80c78ac (patch)
tree1392d31130864b6cc3c68a1b2ae5ef72c6ac4700 /odb/relational/oracle/schema.cxx
parent8c37ec27c06341572d947342869345e59f7bdcf5 (diff)
Specialize schema_emitter for Oracle
SQLPlus scripts are required to indicate PL/SQL block terminations with a trail '/'.
Diffstat (limited to 'odb/relational/oracle/schema.cxx')
-rw-r--r--odb/relational/oracle/schema.cxx47
1 files changed, 47 insertions, 0 deletions
diff --git a/odb/relational/oracle/schema.cxx b/odb/relational/oracle/schema.cxx
index 7b8a622..acc512f 100644
--- a/odb/relational/oracle/schema.cxx
+++ b/odb/relational/oracle/schema.cxx
@@ -3,11 +3,15 @@
// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC
// license : GNU GPL v3; see accompanying LICENSE file
+#include <string>
+
#include <odb/relational/schema.hxx>
#include <odb/relational/oracle/common.hxx>
#include <odb/relational/oracle/context.hxx>
+using namespace std;
+
namespace relational
{
namespace oracle
@@ -16,6 +20,48 @@ namespace relational
{
namespace relational = relational::schema;
+ struct schema_emitter: relational::schema_emitter
+ {
+ schema_emitter (const base& x): base (x) {}
+
+ virtual void
+ pre ()
+ {
+ first_ = true;
+ }
+
+ virtual void
+ line (const std::string& l)
+ {
+ if (first_)
+ first_ = false;
+ else
+ os << endl;
+
+ last_ = l;
+ os << l;
+ }
+
+ virtual void
+ post ()
+ {
+ if (!first_) // Ignore empty statements.
+ {
+ if (last_ == "END;")
+ os << endl
+ << '/' << endl;
+ else
+ os << ';' << endl
+ << endl;
+ }
+ }
+
+ private:
+ bool first_;
+ string last_;
+ };
+ entry<schema_emitter> schema_emitter_;
+
//
// Drop.
//
@@ -44,6 +90,7 @@ namespace relational
<< " WHEN OTHERS THEN" << endl
<< " IF SQLCODE != -2289 THEN RAISE; END IF;" << endl
<< " END;" << endl
+ << " BEGIN" << endl
<< " EXECUTE IMMEDIATE 'DROP TRIGGER " <<
quote_id (table + "_trig") << "';" << endl
<< " EXCEPTION" << endl