aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-08-13 15:34:58 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-08-13 15:34:58 +0200
commit5e17d609ae59dc07514e2af945db05be05db968c (patch)
treeed107da1fe7585a3c0285fa48f5414052f2d70e2
parentead623bfdd2004988f13d7cade7deaea1b71f7e8 (diff)
Do not generate query support code by default
Add the --generate-query option to explicitly request this functionality.
-rw-r--r--odb/mysql/header.cxx64
-rw-r--r--odb/mysql/inline.cxx37
-rw-r--r--odb/mysql/source.cxx86
-rw-r--r--odb/options.cli6
-rw-r--r--odb/options.cxx9
-rw-r--r--odb/options.hxx4
-rw-r--r--odb/options.ixx6
7 files changed, 132 insertions, 80 deletions
diff --git a/odb/mysql/header.cxx b/odb/mysql/header.cxx
index 0d3e3f7..bbf12bb 100644
--- a/odb/mysql/header.cxx
+++ b/odb/mysql/header.cxx
@@ -288,22 +288,27 @@ namespace mysql
//
id_image_type_.traverse (c);
- // query_base_type
+ // query_type & query_base_type
//
- os << "typedef mysql::query query_base_type;"
- << endl;
+ if (options.generate_query ())
+ {
+ // query_base_type
+ //
+ os << "typedef mysql::query query_base_type;"
+ << endl;
- // query_type
- //
- os << "struct query_type: query_base_type"
- << "{";
+ // query_type
+ //
+ os << "struct query_type: query_base_type"
+ << "{";
- names (c, query_column_names_);
+ names (c, query_column_names_);
- os << "query_type ();"
- << "query_type (const std::string&);"
- << "query_type (const query_base_type&);"
- << "};";
+ os << "query_type ();"
+ << "query_type (const std::string&);"
+ << "query_type (const query_base_type&);"
+ << "};";
+ }
// id_source
//
@@ -321,9 +326,12 @@ namespace mysql
os << "static const char* const insert_query;"
<< "static const char* const select_query;"
<< "static const char* const update_query;"
- << "static const char* const delete_query;"
- << "static const char* const select_prefix;"
- << endl;
+ << "static const char* const delete_query;";
+
+ if (options.generate_query ())
+ os << "static const char* const select_prefix;";
+
+ os << endl;
// id ()
//
@@ -391,9 +399,10 @@ namespace mysql
// query ()
//
- os << "static result<object_type>" << endl
- << "query (database&, const query_type&);"
- << endl;
+ if (options.generate_query ())
+ os << "static result<object_type>" << endl
+ << "query (database&, const query_type&);"
+ << endl;
// Helpers.
//
@@ -439,14 +448,19 @@ namespace mysql
ctx.os << "#include <odb/core.hxx>" << endl
<< "#include <odb/traits.hxx>" << endl
- << "#include <odb/buffer.hxx>" << endl
- << "#include <odb/shared-ptr.hxx>" << endl
- << "#include <odb/result.hxx>" << endl
- << endl
+ << "#include <odb/buffer.hxx>" << endl;
+
+ if (ctx.options.generate_query ())
+ ctx.os << "#include <odb/result.hxx>" << endl;
+
+ ctx.os << endl
<< "#include <odb/mysql/version.hxx>" << endl
- << "#include <odb/mysql/forward.hxx>" << endl
- << "#include <odb/mysql/query.hxx>" << endl
- << endl;
+ << "#include <odb/mysql/forward.hxx>" << endl;
+
+ if (ctx.options.generate_query ())
+ ctx.os << "#include <odb/mysql/query.hxx>" << endl;
+
+ ctx.os << endl;
ctx.os << "namespace odb"
<< "{";
diff --git a/odb/mysql/inline.cxx b/odb/mysql/inline.cxx
index 0924077..1bb5fef 100644
--- a/odb/mysql/inline.cxx
+++ b/odb/mysql/inline.cxx
@@ -47,25 +47,28 @@ namespace mysql
// query_type
//
- os << "inline" << endl
- << traits << "::query_type::" << endl
- << "query_type ()"
- << "{"
- << "}";
+ if (options.generate_query ())
+ {
+ os << "inline" << endl
+ << traits << "::query_type::" << endl
+ << "query_type ()"
+ << "{"
+ << "}";
- os << "inline" << endl
- << traits << "::query_type::" << endl
- << "query_type (const std::string& q)" << endl
- << " : query_base_type (q)"
- << "{"
- << "}";
+ os << "inline" << endl
+ << traits << "::query_type::" << endl
+ << "query_type (const std::string& q)" << endl
+ << " : query_base_type (q)"
+ << "{"
+ << "}";
- os << "inline" << endl
- << traits << "::query_type::" << endl
- << "query_type (const query_base_type& q)" << endl
- << " : query_base_type (q)"
- << "{"
- << "}";
+ os << "inline" << endl
+ << traits << "::query_type::" << endl
+ << "query_type (const query_base_type& q)" << endl
+ << " : query_base_type (q)"
+ << "{"
+ << "}";
+ }
// id ()
//
diff --git a/odb/mysql/source.cxx b/odb/mysql/source.cxx
index 0e8d420..a9f8a99 100644
--- a/odb/mysql/source.cxx
+++ b/odb/mysql/source.cxx
@@ -674,6 +674,7 @@ namespace mysql
// query columns
//
+ if (options.generate_query ())
{
query_column t (*this, c);
traversal::names n (t);
@@ -740,18 +741,21 @@ namespace mysql
// select_prefix
//
- os << "const char* const " << traits << "::select_prefix =" << endl
- << "\"SELECT \"" << endl;
-
+ if (options.generate_query ())
{
- member_column m (*this);
- traversal::names n (m);
- names (c, n);
- }
+ os << "const char* const " << traits << "::select_prefix =" << endl
+ << "\"SELECT \"" << endl;
- os << "\"" << endl
- << "\" FROM `" << table_name (c) << "` \";"
- << endl;
+ {
+ member_column m (*this);
+ traversal::names n (m);
+ names (c, n);
+ }
+
+ os << "\"" << endl
+ << "\" FROM `" << table_name (c) << "` \";"
+ << endl;
+ }
// grow ()
//
@@ -971,31 +975,34 @@ namespace mysql
// query ()
//
- os << "result< " << traits << "::object_type >" << endl
- << traits << "::" << endl
- << "query (database&, const query_type& q)"
- << "{"
- << "using namespace mysql;"
- << endl
- << "connection& conn (mysql::transaction::current ().connection ());"
- << "object_statements<object_type>& sts (" << endl
- << "conn.statement_cache ().find<object_type> ());"
- << endl
- << "binding& imb (sts.image_binding ());"
- << "if (imb.version == 0)" << endl
- << "bind (imb, sts.image ());"
- << endl
- << "shared_ptr<query_statement> st (" << endl
- << "new (shared) query_statement (conn," << endl
- << "select_prefix + q.clause ()," << endl
- << "imb," << endl
- << "q.parameters ()));"
- << "st->execute ();"
- << endl
- << "shared_ptr<odb::result_impl<object_type> > r (" << endl
- << "new (shared) mysql::result_impl<object_type> (st, sts));"
- << "return result<object_type> (r);"
- << "}";
+ if (options.generate_query ())
+ {
+ os << "result< " << traits << "::object_type >" << endl
+ << traits << "::" << endl
+ << "query (database&, const query_type& q)"
+ << "{"
+ << "using namespace mysql;"
+ << endl
+ << "connection& conn (mysql::transaction::current ().connection ());"
+ << "object_statements<object_type>& sts (" << endl
+ << "conn.statement_cache ().find<object_type> ());"
+ << endl
+ << "binding& imb (sts.image_binding ());"
+ << "if (imb.version == 0)" << endl
+ << "bind (imb, sts.image ());"
+ << endl
+ << "shared_ptr<query_statement> st (" << endl
+ << "new (shared) query_statement (conn," << endl
+ << "select_prefix + q.clause ()," << endl
+ << "imb," << endl
+ << "q.parameters ()));"
+ << "st->execute ();"
+ << endl
+ << "shared_ptr<odb::result_impl<object_type> > r (" << endl
+ << "new (shared) mysql::result_impl<object_type> (st, sts));"
+ << "return result<object_type> (r);"
+ << "}";
+ }
}
private:
@@ -1034,9 +1041,12 @@ namespace mysql
<< "#include <odb/mysql/transaction.hxx>" << endl
<< "#include <odb/mysql/connection.hxx>" << endl
<< "#include <odb/mysql/statement.hxx>" << endl
- << "#include <odb/mysql/result.hxx>" << endl
- << "#include <odb/mysql/exceptions.hxx>" << endl
- << endl;
+ << "#include <odb/mysql/exceptions.hxx>" << endl;
+
+ if (ctx.options.generate_query ())
+ ctx.os << "#include <odb/mysql/result.hxx>" << endl;
+
+ ctx.os << endl;
ctx.os << "namespace odb"
<< "{";
diff --git a/odb/options.cli b/odb/options.cli
index 6ac44e1..bd8f0d7 100644
--- a/odb/options.cli
+++ b/odb/options.cli
@@ -27,6 +27,12 @@ class options
\cb{tracer}."
};
+ bool --generate-query
+ {
+ "Generate query support code. Without this support you can only
+ load objects via their ids."
+ };
+
bool --generate-schema
{
"Generate database schema. The resulting SQL file creates database
diff --git a/odb/options.cxx b/odb/options.cxx
index f426f7c..02e7201 100644
--- a/odb/options.cxx
+++ b/odb/options.cxx
@@ -541,6 +541,7 @@ options (int& argc,
version_ (),
database_ (),
database_specified_ (false),
+ generate_query_ (),
generate_schema_ (),
output_dir_ (),
output_dir_specified_ (false),
@@ -612,6 +613,7 @@ options (int start,
version_ (),
database_ (),
database_specified_ (false),
+ generate_query_ (),
generate_schema_ (),
output_dir_ (),
output_dir_specified_ (false),
@@ -683,6 +685,7 @@ options (int& argc,
version_ (),
database_ (),
database_specified_ (false),
+ generate_query_ (),
generate_schema_ (),
output_dir_ (),
output_dir_specified_ (false),
@@ -756,6 +759,7 @@ options (int start,
version_ (),
database_ (),
database_specified_ (false),
+ generate_query_ (),
generate_schema_ (),
output_dir_ (),
output_dir_specified_ (false),
@@ -825,6 +829,7 @@ options (::cli::scanner& s,
version_ (),
database_ (),
database_specified_ (false),
+ generate_query_ (),
generate_schema_ (),
output_dir_ (),
output_dir_specified_ (false),
@@ -893,6 +898,8 @@ print_usage (::std::ostream& os)
os << "--database|-d <db> Generate code for the <db> database." << ::std::endl;
+ os << "--generate-query Generate query support code." << ::std::endl;
+
os << "--generate-schema Generate database schema." << ::std::endl;
os << "--output-dir|-o <dir> Write the generated files to <dir> instead of the" << ::std::endl
@@ -1001,6 +1008,8 @@ struct _cli_options_map_init
_cli_options_map_["-d"] =
&::cli::thunk< options, ::database, &options::database_,
&options::database_specified_ >;
+ _cli_options_map_["--generate-query"] =
+ &::cli::thunk< options, bool, &options::generate_query_ >;
_cli_options_map_["--generate-schema"] =
&::cli::thunk< options, bool, &options::generate_schema_ >;
_cli_options_map_["--output-dir"] =
diff --git a/odb/options.hxx b/odb/options.hxx
index 036b96a..488eca2 100644
--- a/odb/options.hxx
+++ b/odb/options.hxx
@@ -331,6 +331,9 @@ class options
database_specified () const;
const bool&
+ generate_query () const;
+
+ const bool&
generate_schema () const;
const std::string&
@@ -511,6 +514,7 @@ class options
bool version_;
::database database_;
bool database_specified_;
+ bool generate_query_;
bool generate_schema_;
std::string output_dir_;
bool output_dir_specified_;
diff --git a/odb/options.ixx b/odb/options.ixx
index ea575c3..f92d217 100644
--- a/odb/options.ixx
+++ b/odb/options.ixx
@@ -186,6 +186,12 @@ database_specified () const
}
inline const bool& options::
+generate_query () const
+{
+ return this->generate_query_;
+}
+
+inline const bool& options::
generate_schema () const
{
return this->generate_schema_;