From defe5aec4edc065546d44ad17b48a2dd5290144d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 12 Oct 2012 17:24:45 +0200 Subject: Completion of prepared query support --- odb/relational/header.cxx | 240 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 235 insertions(+), 5 deletions(-) (limited to 'odb/relational/header.cxx') diff --git a/odb/relational/header.cxx b/odb/relational/header.cxx index a78697f..c6fc9a5 100644 --- a/odb/relational/header.cxx +++ b/odb/relational/header.cxx @@ -685,13 +685,13 @@ traverse_object (type& c) os << "static result" << endl << "query (database&, const query_base_type&);" << endl; - - os << "static unsigned long long" << endl - << "erase_query (database&, const query_base_type&);" - << endl; } - if (!options.omit_prepared ()) + os << "static unsigned long long" << endl + << "erase_query (database&, const query_base_type&);" + << endl; + + if (options.generate_prepared ()) { os << "static odb::details::shared_ptr" << endl << "prepare_query (connection&, const char*, const query_base_type&);" @@ -823,6 +823,236 @@ traverse_object (type& c) << "};"; } +void relational::header::class1:: +traverse_view (type& c) +{ + string const& type (class_fq_name (c)); + + os << "// " << class_name (c) << endl + << "//" << endl; + + // class_traits + // + os << "template <>" << endl + << "struct class_traits< " << type << " >" + << "{" + << "static const class_kind kind = class_view;" + << "};"; + + // view_traits + // + os << "template <>" << endl + << "class access::view_traits< " << type << " >" + << "{" + << "public:" << endl; + + // view_type & pointer_type + // + os << "typedef " << type << " view_type;" + << "typedef " << c.get ("object-pointer") << " pointer_type;"; + + os << "};"; + + // view_traits_impl + // + os << "template <>" << endl + << "class access::view_traits_impl< " << type << ", id_" << + db << " >:" << endl + << " public access::view_traits< " << type << " >" + << "{" + << "public:" << endl; + + view_public_extra_pre (c); + + // image_type + // + image_type_->traverse (c); + + os << "typedef " << db << "::view_statements statements_type;" + << endl; + + // + // Query. + // + + // query_base_type and query_columns (definition generated by class2). + // + os << "typedef " << db << "::query_base query_base_type;" + << "struct query_columns"; + + if (c.get ("object-count") == 0) + os << "{" + << "};"; + else + os << ";" + << endl; + + // + // Functions. + // + + // grow () + // + if (generate_grow) + { + os << "static bool" << endl + << "grow (image_type&, " << truncated_vector << ");" + << endl; + } + + // bind (image_type) + // + os << "static void" << endl + << "bind (" << bind_vector << ", image_type&);" + << endl; + + // init (view, image) + // + os << "static void" << endl + << "init (view_type&, const image_type&, database*);" + << endl; + + // column_count + // + os << "static const std::size_t column_count = " << + column_count (c).total << "UL;" + << endl; + + // Statements. + // + view_query& vq (c.get ("query")); + + if (vq.kind != view_query::runtime) + { + os << "static query_base_type" << endl + << "query_statement (const query_base_type&);" + << endl; + } + + // + // Functions. + // + + // callback () + // + os << "static void" << endl + << "callback (database&, view_type&, callback_event);" + << endl; + + // query () + // + if (!options.omit_unprepared ()) + os << "static result" << endl + << "query (database&, const query_base_type&);" + << endl; + + if (options.generate_prepared ()) + { + os << "static odb::details::shared_ptr" << endl + << "prepare_query (connection&, const char*, const query_base_type&);" + << endl; + + os << "static odb::details::shared_ptr" << endl + << "execute_query (prepared_query_impl&);" + << endl; + } + + view_public_extra_post (c); + + os << "};"; + + // view_traits_impl< , id_default> + // + os << "template <>" << endl + << "class access::view_traits_impl< " << type << ", id_default >:" << endl + << " public access::view_traits_impl< " << type << ", " << + "id_" << db << " >" + << "{" + << "};"; +} + +void relational::header::class1:: +traverse_composite (type& c) +{ + string const& type (class_fq_name (c)); + + os << "// " << class_name (c) << endl + << "//" << endl; + + os << "template <>" << endl + << "struct class_traits< " << type << " >" + << "{" + << "static const class_kind kind = class_composite;" + << "};"; + + os << "template <>" << endl + << "class access::composite_value_traits< " << type << ", " << + "id_" << db << " >" + << "{" + << "public:" << endl; + + // value_type + // + os << "typedef " << type << " value_type;" + << endl; + + // image_type + // + image_type_->traverse (c); + + // Containers. + // + { + instance t (c); + t->traverse (c); + } + + // grow () + // + if (generate_grow) + { + os << "static bool" << endl + << "grow (image_type&, " << truncated_vector << ");" + << endl; + } + + // bind (image_type) + // + os << "static void" << endl + << "bind (" << bind_vector << ", image_type&, " << + db << "::statement_kind);" + << endl; + + // init (image, value) + // + os << "static " << (generate_grow ? "bool" : "void") << endl + << "init (image_type&, const value_type&, " << db << "::statement_kind);" + << endl; + + // init (value, image) + // + os << "static void" << endl + << "init (value_type&, const image_type&, database*);" + << endl; + + if (!has_a (c, test_container)) + { + // get_null (image) + // + os << "static bool" << endl + << "get_null (const image_type&);" + << endl; + + // set_null (image) + // + os << "static void" << endl + << "set_null (image_type&, " << db << "::statement_kind);" + << endl; + } + + os << "};"; +} + void relational::header:: generate () { -- cgit v1.1