aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-10-07 18:21:39 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-10-07 18:21:39 +0200
commitb1020d6a60050bd0e84f32a79739f0bf16935a51 (patch)
tree96b4717f2cf67127e3696288ec2609ca9668e715 /odb/mysql
parent1171fb0f0f85d3d8fea40dc182fda61ea0f51504 (diff)
Add support for persistent classes without default ctors
New test: common/ctor.
Diffstat (limited to 'odb/mysql')
-rw-r--r--odb/mysql/header.cxx10
-rw-r--r--odb/mysql/source.cxx49
2 files changed, 33 insertions, 26 deletions
diff --git a/odb/mysql/header.cxx b/odb/mysql/header.cxx
index b22efbb..cc13264 100644
--- a/odb/mysql/header.cxx
+++ b/odb/mysql/header.cxx
@@ -3,6 +3,8 @@
// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
// license : GNU GPL v3; see accompanying LICENSE file
+#include <odb/gcc.hxx>
+
#include <odb/mysql/common.hxx>
#include <odb/mysql/header.hxx>
@@ -207,6 +209,7 @@ namespace mysql
return;
string const& type (c.fq_name ());
+ bool def_ctor (TYPE_HAS_DEFAULT_CONSTRUCTOR (c.tree_node ()));
id_member_.traverse (c);
semantics::data_member& id (*id_member_.member ());
@@ -340,9 +343,10 @@ namespace mysql
// find ()
//
- os << "static pointer_type" << endl
- << "find (database&, const id_type&);"
- << endl;
+ if (def_ctor)
+ os << "static pointer_type" << endl
+ << "find (database&, const id_type&);"
+ << endl;
os << "static bool" << endl
<< "find (database&, const id_type&, object_type&);"
diff --git a/odb/mysql/source.cxx b/odb/mysql/source.cxx
index e2cf0e8..c0ce773 100644
--- a/odb/mysql/source.cxx
+++ b/odb/mysql/source.cxx
@@ -3,7 +3,8 @@
// copyright : Copyright (c) 2009-2010 Code Synthesis Tools CC
// license : GNU GPL v3; see accompanying LICENSE file
-#include <cstddef> // std::size_t
+#include <odb/gcc.hxx>
+
#include <sstream>
#include <odb/mysql/common.hxx>
@@ -697,6 +698,7 @@ namespace mysql
string const& type (c.fq_name ());
string traits ("access::object_traits< " + type + " >");
+ bool def_ctor (TYPE_HAS_DEFAULT_CONSTRUCTOR (c.tree_node ()));
id_member_.traverse (c);
semantics::data_member& id (*id_member_.member ());
@@ -950,28 +952,29 @@ namespace mysql
// find ()
//
- os << traits << "::pointer_type" << endl
- << traits << "::" << endl
- << "find (database&, const id_type& id)"
- << "{"
- << "using namespace mysql;"
- << endl
- << "connection& conn (mysql::transaction::current ().connection ());"
- << "object_statements<object_type>& sts (" << endl
- << "conn.statement_cache ().find<object_type> ());"
- << endl
- << "if (find (sts, id))"
- << "{"
- << "pointer_type p (access::object_factory< " << type <<
- " >::create ());"
- << "pointer_traits< pointer_type >::guard g (p);"
- << "init (pointer_traits< pointer_type >::get_ref (p), " <<
- "sts.image ());"
- << "g.release ();"
- << "return p;"
- << "}"
- << "return pointer_type ();"
- << "}";
+ if (def_ctor)
+ os << traits << "::pointer_type" << endl
+ << traits << "::" << endl
+ << "find (database&, const id_type& id)"
+ << "{"
+ << "using namespace mysql;"
+ << endl
+ << "connection& conn (mysql::transaction::current ().connection ());"
+ << "object_statements<object_type>& sts (" << endl
+ << "conn.statement_cache ().find<object_type> ());"
+ << endl
+ << "if (find (sts, id))"
+ << "{"
+ << "pointer_type p (access::object_factory< " << type <<
+ " >::create ());"
+ << "pointer_traits< pointer_type >::guard g (p);"
+ << "init (pointer_traits< pointer_type >::get_ref (p), " <<
+ "sts.image ());"
+ << "g.release ();"
+ << "return p;"
+ << "}"
+ << "return pointer_type ();"
+ << "}";
os << "bool " << traits << "::" << endl
<< "find (database&, const id_type& id, object_type& obj)"