From 0a6a2fe64508497d287aa3341e667fe313912774 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 25 Jul 2012 15:52:26 +0200 Subject: Simplify auto id implementation in Oracle Specifically, instead of using a trigger to assign the next id from the sequence, get the next value directly in the INSERT statement. --- odb/relational/oracle/context.cxx | 2 +- odb/relational/oracle/schema.cxx | 37 +++---------------------------------- odb/relational/oracle/source.cxx | 18 +++++++++--------- 3 files changed, 13 insertions(+), 44 deletions(-) (limited to 'odb/relational/oracle') diff --git a/odb/relational/oracle/context.cxx b/odb/relational/oracle/context.cxx index c0a7199..01b690a 100644 --- a/odb/relational/oracle/context.cxx +++ b/odb/relational/oracle/context.cxx @@ -79,7 +79,7 @@ namespace relational generate_grow = false; need_alias_as = false; - insert_send_auto_id = true; + insert_send_auto_id = false; delay_freeing_statement_result = false; need_image_clone = true; data_->bind_vector_ = "oracle::bind*"; diff --git a/odb/relational/oracle/schema.cxx b/odb/relational/oracle/schema.cxx index bf040e0..ce2c470 100644 --- a/odb/relational/oracle/schema.cxx +++ b/odb/relational/oracle/schema.cxx @@ -114,7 +114,7 @@ namespace relational << " IF SQLCODE != -942 THEN RAISE; END IF;" << endl << " END;" << endl; - // Drop the sequence and trigger if we have auto primary key. + // Drop the sequence if we have auto primary key. // using sema_rel::primary_key; @@ -131,13 +131,6 @@ namespace relational << " EXCEPTION" << endl << " WHEN OTHERS THEN" << endl << " IF SQLCODE != -2289 THEN RAISE; END IF;" << endl - << " END;" << endl - << " BEGIN" << endl - << " EXECUTE IMMEDIATE 'DROP TRIGGER " << - quote_id (table + "_trg") << "';" << endl - << " EXCEPTION" << endl - << " WHEN OTHERS THEN" << endl - << " IF SQLCODE != -4080 THEN RAISE; END IF;" << endl << " END;" << endl; } @@ -283,7 +276,7 @@ namespace relational tables_.insert (t.name ()); // Add it before to cover self-refs. base::traverse (t); - // Create the sequence and trigger if we have auto primary key. + // Create the sequence if we have auto primary key. // using sema_rel::primary_key; @@ -294,33 +287,9 @@ namespace relational if (pk != 0 && pk->auto_ ()) { - qname const& tname (t.name ()); - string const& cname (pk->contains_begin ()->column ().name ()); - - qname seq_name (tname + "_seq"); - qname trg_name (tname + "_trg"); - - // Sequence. - // pre_statement (); - - os_ << "CREATE SEQUENCE " << quote_id (seq_name) << endl + os_ << "CREATE SEQUENCE " << quote_id (t.name () + "_seq") << endl << " START WITH 1 INCREMENT BY 1" << endl; - - post_statement (); - - // Trigger. - // - pre_statement (); - - os_ << "CREATE TRIGGER " << quote_id (trg_name) << endl - << " BEFORE INSERT ON " << quote_id (tname) << endl - << " FOR EACH ROW" << endl - << "BEGIN" << endl - << " SELECT " << quote_id (seq_name) << ".nextval " << - "INTO :new." << quote_id (cname) << " FROM DUAL;" << endl - << "END;" << endl; - post_statement (); } diff --git a/odb/relational/oracle/source.cxx b/odb/relational/oracle/source.cxx index cfbdbac..780dc06 100644 --- a/odb/relational/oracle/source.cxx +++ b/odb/relational/oracle/source.cxx @@ -19,10 +19,7 @@ namespace relational struct query_parameters: relational::query_parameters { - query_parameters (base const& x) - : base (x), i_ (0) - { - } + query_parameters (base const& x): base (x), i_ (0) {} virtual string next () @@ -33,6 +30,14 @@ namespace relational return ss.str (); } + virtual string + auto_id () + { + // The same sequence name as used in schema.cxx. + // + return quote_id (table_ + "_seq") + ".nextval"; + } + private: size_t i_; }; @@ -509,11 +514,6 @@ namespace relational class_ (base const& x): base (x) {} virtual void - init_auto_id (semantics::data_member&, string const&) - { - } - - virtual void init_image_pre (type& c) { if (options.generate_query () && -- cgit v1.1