From 3b53b9157b610805b0d5c436bb01c0fe275390b9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 25 Mar 2011 13:06:51 +0200 Subject: Further generalization work for SQLite support --- odb/relational/common.cxx | 6 +++--- odb/relational/inline.hxx | 3 ++- odb/relational/source.hxx | 23 ++++++++++++++++------- odb/relational/sqlite/context.cxx | 2 +- odb/relational/sqlite/source.cxx | 15 +++++++++++++++ 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/odb/relational/common.cxx b/odb/relational/common.cxx index 1416305..dcae220 100644 --- a/odb/relational/common.cxx +++ b/odb/relational/common.cxx @@ -107,7 +107,7 @@ namespace relational string db_type_id (database_type_id (m)); string type ( - "mysql::value_traits< " + string (db.string ()) + "::value_traits< " + m.type ().fq_name (m.belongs ().hint ()) + ", " + im_type + ", " + db_type_id @@ -117,7 +117,7 @@ namespace relational { os << "// " << name << endl << "//" << endl - << "static const mysql::query_column<" << endl + << "static const " << db << "::query_column<" << endl << " " << type << "," << endl << " " << db_type_id << ">" << endl << name << ";" @@ -127,7 +127,7 @@ namespace relational { string column (table_ + '.' + quote_id (col_name)); - os << "const mysql::query_column<" << endl + os << "const " << db << "::query_column<" << endl << " " << type << "," << endl << " " << db_type_id << ">" << endl << scope_ << "::" << name << " (" << endl diff --git a/odb/relational/inline.hxx b/odb/relational/inline.hxx index ef0e32e..1b3c492 100644 --- a/odb/relational/inline.hxx +++ b/odb/relational/inline.hxx @@ -81,7 +81,8 @@ namespace relational { os << "inline" << endl << "void " << traits << "::" << endl - << "load_ (mysql::object_statements< object_type >&, object_type&)" + << "load_ (" << db << "::object_statements< object_type >&, " << + "object_type&)" << "{" << "}"; } diff --git a/odb/relational/source.hxx b/odb/relational/source.hxx index 3bb238a..da66b11 100644 --- a/odb/relational/source.hxx +++ b/odb/relational/source.hxx @@ -548,6 +548,15 @@ namespace relational obj_scope_ = "access::object_traits< " + obj.fq_name () + " >"; } + // Unless the database system can execute several interleaving + // statements, cache the result set. + // + virtual void + cache_result (string const& statement) + { + os << statement << ".cache ();"; + } + virtual void container (semantics::data_member& m) { @@ -1396,11 +1405,11 @@ namespace relational << "select_statement& st (sts.select_all_statement ());" << "st.execute ();"; - // If we are loading eager object pointers, cache the result - // since we will be loading other objects. + // If we are loading eager object pointers, we may need to cache + // the result since we will be loading other objects. // if (eager_ptr) - os << "st.cache ();"; + cache_result ("st"); os << "select_statement::result r (st.fetch ());"; @@ -2275,7 +2284,7 @@ namespace relational << endl << "details::shared_ptr > r (" << endl << "new (details::shared) " << db << - "::result_impl (st, sts));" + "::result_impl (q, st, sts));" << "return result (r);" << "}"; @@ -2299,14 +2308,14 @@ namespace relational << endl << "details::shared_ptr > r (" << endl << "new (details::shared) " << db << - "::result_impl (st, sts));" + "::result_impl (q, st, sts));" << "return result (r);" << "}"; os << "void " << traits << "::" << endl << "query_ (database&," << endl << "const query_type& q," << endl - << db << "::object_statements< object_type >& sts," + << db << "::object_statements< object_type >& sts," << endl << "details::shared_ptr<" << db << "::select_statement>& st)" << "{" << "using namespace " << db << ";" @@ -2323,7 +2332,7 @@ namespace relational << "st.reset (new (details::shared) select_statement (" << endl << "sts.connection ()," << endl << "query_clause + q.clause ()," << endl - << "q.parameters ()," << endl + << "q.parameters_binding ()," << endl << "imb));" << "st->execute ();" << "}"; diff --git a/odb/relational/sqlite/context.cxx b/odb/relational/sqlite/context.cxx index 6ed1740..7803298 100644 --- a/odb/relational/sqlite/context.cxx +++ b/odb/relational/sqlite/context.cxx @@ -323,7 +323,7 @@ namespace relational if (t.punctuation () == sql_token::p_rparen) break; - if (t.type () != sql_token::t_eos) + if (t.type () == sql_token::t_eos) { cerr << m_.file () << ":" << m_.line () << ":" << m_.column () << ": error: missing ')' in SQLite type declaration" diff --git a/odb/relational/sqlite/source.cxx b/odb/relational/sqlite/source.cxx index 418a5e3..810f384 100644 --- a/odb/relational/sqlite/source.cxx +++ b/odb/relational/sqlite/source.cxx @@ -558,6 +558,21 @@ namespace relational }; entry init_value_member_; + struct container_traits: relational::container_traits, context + { + container_traits (base const& x): base (x) {} + + virtual void + cache_result (string const&) + { + // Caching is not necessary since SQLite can execute several + // interleaving statements. + // + } + }; + entry container_traits_; + + struct class_: relational::class_, context { class_ (base const& x): base (x) {} -- cgit v1.1