[odb-users] Problem: odb.exe fails to generate valid hxx/cxx file, not adding shared_ptr<T> in typedef

Wayne Hackle hacklew at hotmail.com
Tue Mar 13 00:02:53 EDT 2012





Hi all,
Thanks for taking time on reading this post.
problem: odb.exe does not correctly implement "inverse" #pragma keyword in generating -odb.hxx/-odb.cxx files, and in turn causes VISUAL STUDIO failure to build.
My problem occurs when I was trying out the "inverse" keyword in one-to-many relationships. My own project fails so I resort to the samples that I downloaded from the official website.
The "inverse" sample runs correctly without changes. So I dug a bit deeper, ran "odb --database mysql --generate-query employee.hxx", then the project fails to build.
error message: error C2679: binary "=": cannot find right operator that accpets "employee *" as a right oprant (this is a translation from the original chinese message: 错误	1	error C2679: 二进制“=”: 没有找到接受“employee *”类型的右操作数的运算符(或没有可接受的转换)	e:\all.files\library\odb\libodb\odb\tr1\lazy-ptr.ixx	540	inverse)So i compared the newly generated employee-odb.cxx/employee-odb.hxx file with the old ones. here are the differencesFile:Position (row number):Valid codeInvalid codeEmployee-odb.hxx743typedef ::std::tr1::shared_ptr<
  ::employee > pointer_type;typedef ::employee* pointer_type;Employee-odb.hxx469typedef ::std::tr1::shared_ptr<
  ::project > pointer_type;typedef ::project* pointer_type;Employee-odb.hxx311 typedef ::std::tr1::shared_ptr<
  ::position > pointer_type; typedef ::position* pointer_type;Employee-odb.hxx85typedef ::std::tr1::shared_ptr<
  ::employer > pointer_type;typedef ::employer* pointer_type;Employee-odb.cxx43-44"`inverse_employee`.`id`" 
  " FROM `inverse_employee` WHERE
  `inverse_employee`.`employer`=?";"`inverse_employee`.`id`" 
  " FROM `inverse_employee` WHERE
  `inverse_employee`.`employer`=?";  Much more likes as above, basically valid
  file with “inverse_” prefix but invalid file without. 
I did not make any changes to the "employee.hxx" file in the "inverse" example, so I think it's either a problem with the "odb.exe" command, or there is a secret parameter that I fail to use.
Did anyone run into the same/similar problem? Any information is appreciated.
Thanks.
Hackle Wayne

 		 	   		  
-------------- next part --------------
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//

#include <odb/pre.hxx>

// Begin prologue.
//
//
// End prologue.

#include "employee-odb.hxx"

#include <cassert>
#include <cstring> // std::memcpy

#include <odb/cache-traits.hxx>
#include <odb/details/shared-ptr.hxx>

#include <odb/mysql/binding.hxx>
#include <odb/mysql/traits.hxx>
#include <odb/mysql/database.hxx>
#include <odb/mysql/transaction.hxx>
#include <odb/mysql/connection.hxx>
#include <odb/mysql/statement.hxx>
#include <odb/mysql/statement-cache.hxx>
#include <odb/mysql/object-statements.hxx>
#include <odb/mysql/container-statements.hxx>
#include <odb/mysql/exceptions.hxx>
#include <odb/mysql/result.hxx>
#include <odb/mysql/enum.hxx>

namespace odb
{
  // employer
  //

  // employees_
  //

  const char access::object_traits< ::employer >::employees_traits::select_all_statement[] =
  "SELECT "
  "`employee`.`id`"
  " FROM `employee` WHERE `employee`.`employer`=?";

  const char access::object_traits< ::employer >::employees_traits::insert_one_statement[] =
  "";

  const char access::object_traits< ::employer >::employees_traits::delete_all_statement[] =
  "";

  void access::object_traits< ::employer >::employees_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        cond_image_type& c)
  {
    ODB_POTENTIALLY_UNUSED (c);

    std::size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;
  }

  void access::object_traits< ::employer >::employees_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        data_image_type& d)
  {
    using namespace mysql;

    statement_kind sk (statement_select);
    ODB_POTENTIALLY_UNUSED (sk);

    size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;

    // value
    //
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &d.value_value;
    b[n].is_null = &d.value_null;
  }

  void access::object_traits< ::employer >::employees_traits::
  grow (data_image_type& i, my_bool* t)
  {
    bool grew (false);

    // value
    //
    t[0UL] = 0;

    if (grew)
      i.version++;
  }

  void access::object_traits< ::employer >::employees_traits::
  init (value_type& v, const data_image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (db);

    // value
    //
    {
      typedef object_traits< ::employee > obj_traits;
      typedef pointer_traits< value_type > ptr_traits;

      if (i.value_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_value (
          id,
          i.value_value,
          i.value_null);

        v = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::employer >::employees_traits::
  insert_one (index_type, const value_type&, void*)
  {
  }

  bool access::object_traits< ::employer >::employees_traits::
  load_all (index_type&, value_type& v, void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    data_image_type& di (sts.data_image ());
    init (v, di, sts.connection ().database ());

    select_statement& st (sts.select_all_statement ());
    select_statement::result r (st.fetch ());
    if (r == select_statement::no_data)
    {
      st.free_result ();
      return false;
    }

    return true;
  }

  void access::object_traits< ::employer >::employees_traits::
  delete_all (void*)
  {
  }

  void access::object_traits< ::employer >::employees_traits::
  load (container_type& c,
        const mysql::binding& id,
        statements_type& sts)
  {
    using namespace mysql;

    binding& db (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || db.version == 0)
    {
      bind (db.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      db.version++;
      sts.select_image_binding ().version++;
    }

    binding& cb (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || cb.version == 0)
    {
      bind (cb.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      cb.version++;
    }

    select_statement& st (sts.select_all_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());
    bool more (r != select_statement::no_data);

    if (!more)
      st.free_result ();

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::load (c, more, fs);
  }

  access::object_traits< ::employer >::id_type
  access::object_traits< ::employer >::
  id (const image_type& i)
  {
    id_type id;
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      id,
      i.name_value,
      i.name_size,
      i.name_null);

    return id;
  }

  bool access::object_traits< ::employer >::
  grow (image_type& i, my_bool* t)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (t);

    bool grew (false);

    // name_
    //
    if (t[0UL])
    {
      i.name_value.capacity (i.name_size);
      grew = true;
    }

    return grew;
  }

  void access::object_traits< ::employer >::
  bind (MYSQL_BIND* b, image_type& i, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    std::size_t n (0);

    // name_
    //
    if (sk != statement_update)
    {
      b[n].buffer_type = MYSQL_TYPE_STRING;
      b[n].buffer = i.name_value.data ();
      b[n].buffer_length = static_cast<unsigned long> (
        i.name_value.capacity ());
      b[n].length = &i.name_size;
      b[n].is_null = &i.name_null;
      n++;
    }
  }

  void access::object_traits< ::employer >::
  bind (MYSQL_BIND* b, id_image_type& i)
  {
    std::size_t n (0);
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.id_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.id_value.capacity ());
    b[n].length = &i.id_size;
    b[n].is_null = &i.id_null;
  }

  bool access::object_traits< ::employer >::
  init (image_type& i, const object_type& o, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    bool grew (false);

    // name_
    //
    if (sk == statement_insert)
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.name_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.name_value,
        size,
        is_null,
        o.name_);
      i.name_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.name_value.capacity ());
      i.name_null = is_null;
    }

    return grew;
  }

  void access::object_traits< ::employer >::
  init (object_type& o, const image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (db);

    // name_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.name_,
      i.name_value,
      i.name_size,
      i.name_null);
  }

  void access::object_traits< ::employer >::
  init (id_image_type& i, const id_type& id)
  {
    bool grew (false);

    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.id_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.id_value,
        size,
        is_null,
        id);
      i.id_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.id_value.capacity ());
      i.id_null = is_null;
    }

    if (grew)
      i.version++;
  }

  struct access::object_traits< ::employer >::container_statement_cache_type
  {
    mysql::container_statements_impl< employees_traits > employees_;

    container_statement_cache_type (mysql::connection& c)
    : employees_ (c)
    {
    }
  };

  const char access::object_traits< ::employer >::persist_statement[] =
  "INSERT INTO `employer` ("
  "`name`)"
  " VALUES (?)";

  const char access::object_traits< ::employer >::find_statement[] =
  "SELECT "
  "`employer`.`name`"
  " FROM `employer`"
  " WHERE `employer`.`name`=?";

  const char access::object_traits< ::employer >::erase_statement[] =
  "DELETE FROM `employer`"
  " WHERE `name`=?";

  const char access::object_traits< ::employer >::query_statement[] =
  "SELECT "
  "`employer`.`name`"
  " FROM `employer`"
  " ";

  const char access::object_traits< ::employer >::erase_query_statement[] =
  "DELETE FROM `employer`"
  " ";

  const char access::object_traits< ::employer >::table_name[] =
  "`employer`";

  void access::object_traits< ::employer >::
  persist (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    image_type& im (sts.image ());
    binding& imb (sts.insert_image_binding ());

    if (init (im, obj, statement_insert))
      im.version++;

    if (im.version != sts.insert_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_insert);
      sts.insert_image_version (im.version);
      imb.version++;
    }

    insert_statement& st (sts.persist_statement ());
    if (!st.execute ())
      throw object_already_persistent ();
  }

  void access::object_traits< ::employer >::
  update (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    if (!find_ (sts, obj.name_))
      throw object_not_persistent ();
  }

  void access::object_traits< ::employer >::
  erase (database&, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    if (sts.erase_statement ().execute () != 1)
      throw object_not_persistent ();
  }

  access::object_traits< ::employer >::pointer_type
  access::object_traits< ::employer >::
  find (database& db, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    object_statements< object_type >::auto_lock l (sts);

    if (l.locked ())
    {
      if (!find_ (sts, id))
        return pointer_type ();
    }

    pointer_type p (
      access::object_factory< object_type, pointer_type  >::create ());
    pointer_traits< pointer_type >::guard pg (p);
    pointer_cache_traits< pointer_type >::insert_guard ig (
      pointer_cache_traits< pointer_type >::insert (db, id, p));
    object_type& obj (pointer_traits< pointer_type >::get_ref (p));

    if (l.locked ())
    {
      callback (db, obj, callback_event::pre_load);
      init (obj, sts.image (), db);
      load_ (sts, obj);
      sts.load_delayed ();
      l.unlock ();
      callback (db, obj, callback_event::post_load);
    }
    else
      sts.delay_load (id, obj, ig.position ());

    ig.release ();
    pg.release ();
    return p;
  }

  bool access::object_traits< ::employer >::
  find (database& db, const id_type& id, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, id))
      return false;

    reference_cache_traits< object_type >::insert_guard ig (
      reference_cache_traits< object_type >::insert (db, id, obj));

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    ig.release ();
    return true;
  }

  bool access::object_traits< ::employer >::
  reload (database& db, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, obj.name_))
      return false;

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    return true;
  }

  bool access::object_traits< ::employer >::
  find_ (mysql::object_statements< object_type >& sts, const id_type& id)
  {
    using namespace mysql;

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    select_statement& st (sts.find_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      if (grow (im, sts.select_image_truncated ()))
        im.version++;

      if (im.version != sts.select_image_version ())
      {
        bind (imb.bind, im, statement_select);
        sts.select_image_version (im.version);
        imb.version++;
        st.refetch ();
      }
    }

    st.free_result ();
    return r != select_statement::no_data;
  }

  void access::object_traits< ::employer >::
  load_ (mysql::object_statements< object_type >& sts, object_type& obj)
  {
    mysql::binding& idb (sts.id_image_binding ());

    employees_traits::load (
      obj.employees_,
      idb,
      sts.container_statment_cache ().employees_);
  }

  result< access::object_traits< ::employer >::object_type >
  access::object_traits< ::employer >::
  query (database&, const query_base_type& q)
  {
    using namespace mysql;
    using odb::details::shared;
    using odb::details::shared_ptr;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    shared_ptr<select_statement> st (
      new (shared) select_statement (
        sts.connection (),
        query_statement + q.clause (),
        q.parameters_binding (),
        imb));

    st->execute ();

    shared_ptr< odb::object_result_impl<object_type> > r (
      new (shared) mysql::object_result_impl<object_type> (
        q, st, sts));

    return result<object_type> (r);
  }

  unsigned long long access::object_traits< ::employer >::
  erase_query (database&, const query_base_type& q)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    delete_statement st (
      conn,
      erase_query_statement + q.clause (),
      q.parameters_binding ());

    return st.execute ();
  }

  // position
  //

  const char query_columns_base< ::position >::employee_alias_[] = "`employee`";

  const query_columns_base< ::position >::employee_type_
  query_columns_base< ::position >::employee;

  access::object_traits< ::position >::id_type
  access::object_traits< ::position >::
  id (const image_type& i)
  {
    id_type id;
    mysql::value_traits<
        long unsigned int,
        mysql::id_ulonglong >::set_value (
      id,
      i.id_value,
      i.id_null);

    return id;
  }

  bool access::object_traits< ::position >::
  grow (image_type& i, my_bool* t)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (t);

    bool grew (false);

    // id_
    //
    t[0UL] = 0;

    // title_
    //
    if (t[1UL])
    {
      i.title_value.capacity (i.title_size);
      grew = true;
    }

    // employee_
    //
    t[2UL] = 0;

    return grew;
  }

  void access::object_traits< ::position >::
  bind (MYSQL_BIND* b, image_type& i, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    std::size_t n (0);

    // id_
    //
    if (sk != statement_update)
    {
      b[n].buffer_type = MYSQL_TYPE_LONGLONG;
      b[n].is_unsigned = 1;
      b[n].buffer = &i.id_value;
      b[n].is_null = &i.id_null;
      n++;
    }

    // title_
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.title_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.title_value.capacity ());
    b[n].length = &i.title_size;
    b[n].is_null = &i.title_null;
    n++;

    // employee_
    //
    if (sk == statement_select)
    {
      b[n].buffer_type = MYSQL_TYPE_LONGLONG;
      b[n].is_unsigned = 1;
      b[n].buffer = &i.employee_value;
      b[n].is_null = &i.employee_null;
      n++;
    }
  }

  void access::object_traits< ::position >::
  bind (MYSQL_BIND* b, id_image_type& i)
  {
    std::size_t n (0);
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &i.id_value;
    b[n].is_null = &i.id_null;
  }

  bool access::object_traits< ::position >::
  init (image_type& i, const object_type& o, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    bool grew (false);

    // id_
    //
    if (sk == statement_insert)
    {
      bool is_null;
      mysql::value_traits<
          long unsigned int,
          mysql::id_ulonglong >::set_image (
        i.id_value, is_null, o.id_);
      i.id_null = is_null;
    }

    // title_
    //
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.title_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.title_value,
        size,
        is_null,
        o.title_);
      i.title_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.title_value.capacity ());
      i.title_null = is_null;
    }

    return grew;
  }

  void access::object_traits< ::position >::
  init (object_type& o, const image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (db);

    // id_
    //
    mysql::value_traits<
        long unsigned int,
        mysql::id_ulonglong >::set_value (
      o.id_,
      i.id_value,
      i.id_null);

    // title_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.title_,
      i.title_value,
      i.title_size,
      i.title_null);

    // employee_
    //
    {
      typedef object_traits< ::employee > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_weak_ptr< ::employee > > ptr_traits;

      if (i.employee_null)
        o.employee_ = ptr_traits::pointer_type ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_value (
          id,
          i.employee_value,
          i.employee_null);

        o.employee_ = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::position >::
  init (id_image_type& i, const id_type& id)
  {
    {
      bool is_null;
      mysql::value_traits<
          long unsigned int,
          mysql::id_ulonglong >::set_image (
        i.id_value, is_null, id);
      i.id_null = is_null;
    }
  }

  struct access::object_traits< ::position >::container_statement_cache_type
  {
    container_statement_cache_type (mysql::connection&)
    {
    }
  };

  const char access::object_traits< ::position >::persist_statement[] =
  "INSERT INTO `position` ("
  "`id`,"
  "`title`)"
  " VALUES (?,?)";

  const char access::object_traits< ::position >::find_statement[] =
  "SELECT "
  "`position`.`id`,"
  "`position`.`title`,"
  "`employee`.`id`"
  " FROM `position`"
  " LEFT JOIN `employee` AS `employee` ON `employee`.`position` = `position`.`id`"
  " WHERE `position`.`id`=?";

  const char access::object_traits< ::position >::update_statement[] =
  "UPDATE `position` SET "
  "`title`=?"
  " WHERE `id`=?";

  const char access::object_traits< ::position >::erase_statement[] =
  "DELETE FROM `position`"
  " WHERE `id`=?";

  const char access::object_traits< ::position >::query_statement[] =
  "SELECT "
  "`position`.`id`,"
  "`position`.`title`,"
  "`employee`.`id`"
  " FROM `position`"
  " LEFT JOIN `employee` AS `employee` ON `employee`.`position` = `position`.`id`"
  " ";

  const char access::object_traits< ::position >::erase_query_statement[] =
  "DELETE FROM `position`"
  " ";

  const char access::object_traits< ::position >::table_name[] =
  "`position`";

  void access::object_traits< ::position >::
  persist (database&, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    image_type& im (sts.image ());
    binding& imb (sts.insert_image_binding ());

    if (init (im, obj, statement_insert))
      im.version++;

    im.id_value = 0;

    if (im.version != sts.insert_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_insert);
      sts.insert_image_version (im.version);
      imb.version++;
    }

    insert_statement& st (sts.persist_statement ());
    if (!st.execute ())
      throw object_already_persistent ();

    obj.id_ = static_cast< id_type > (st.id ());
  }

  void access::object_traits< ::position >::
  update (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, obj.id_);

    image_type& im (sts.image ());
    if (init (im, obj, statement_update))
      im.version++;

    bool u (false);
    binding& imb (sts.update_image_binding ());
    if (im.version != sts.update_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_update);
      sts.update_image_version (im.version);
      imb.version++;
      u = true;
    }

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.update_id_image_version () || idb.version == 0)
    {
      if (i.version != sts.id_image_version () || idb.version == 0)
      {
        bind (idb.bind, i);
        sts.id_image_version (i.version);
        idb.version++;
      }

      sts.update_id_image_version (i.version);

      if (!u)
        imb.version++;
    }

    if (sts.update_statement ().execute () == 0)
      throw object_not_persistent ();
  }

  void access::object_traits< ::position >::
  erase (database&, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    if (sts.erase_statement ().execute () != 1)
      throw object_not_persistent ();
  }

  access::object_traits< ::position >::pointer_type
  access::object_traits< ::position >::
  find (database& db, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    object_statements< object_type >::auto_lock l (sts);

    if (l.locked ())
    {
      if (!find_ (sts, id))
        return pointer_type ();
    }

    pointer_type p (
      access::object_factory< object_type, pointer_type  >::create ());
    pointer_traits< pointer_type >::guard pg (p);
    pointer_cache_traits< pointer_type >::insert_guard ig (
      pointer_cache_traits< pointer_type >::insert (db, id, p));
    object_type& obj (pointer_traits< pointer_type >::get_ref (p));

    if (l.locked ())
    {
      callback (db, obj, callback_event::pre_load);
      init (obj, sts.image (), db);
      load_ (sts, obj);
      sts.load_delayed ();
      l.unlock ();
      callback (db, obj, callback_event::post_load);
    }
    else
      sts.delay_load (id, obj, ig.position ());

    ig.release ();
    pg.release ();
    return p;
  }

  bool access::object_traits< ::position >::
  find (database& db, const id_type& id, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, id))
      return false;

    reference_cache_traits< object_type >::insert_guard ig (
      reference_cache_traits< object_type >::insert (db, id, obj));

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    ig.release ();
    return true;
  }

  bool access::object_traits< ::position >::
  reload (database& db, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, obj.id_))
      return false;

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    return true;
  }

  bool access::object_traits< ::position >::
  find_ (mysql::object_statements< object_type >& sts, const id_type& id)
  {
    using namespace mysql;

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    select_statement& st (sts.find_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      if (grow (im, sts.select_image_truncated ()))
        im.version++;

      if (im.version != sts.select_image_version ())
      {
        bind (imb.bind, im, statement_select);
        sts.select_image_version (im.version);
        imb.version++;
        st.refetch ();
      }
    }

    st.free_result ();
    return r != select_statement::no_data;
  }

  result< access::object_traits< ::position >::object_type >
  access::object_traits< ::position >::
  query (database&, const query_base_type& q)
  {
    using namespace mysql;
    using odb::details::shared;
    using odb::details::shared_ptr;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    shared_ptr<select_statement> st (
      new (shared) select_statement (
        sts.connection (),
        query_statement + q.clause (),
        q.parameters_binding (),
        imb));

    st->execute ();

    shared_ptr< odb::object_result_impl<object_type> > r (
      new (shared) mysql::object_result_impl<object_type> (
        q, st, sts));

    return result<object_type> (r);
  }

  unsigned long long access::object_traits< ::position >::
  erase_query (database&, const query_base_type& q)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    delete_statement st (
      conn,
      erase_query_statement + q.clause (),
      q.parameters_binding ());

    return st.execute ();
  }

  // project
  //

  // employees_
  //

  const char access::object_traits< ::project >::employees_traits::select_all_statement[] =
  "SELECT "
  "`employee_projects`.`object_id`"
  " FROM `employee_projects` WHERE `employee_projects`.`value`=?";

  const char access::object_traits< ::project >::employees_traits::insert_one_statement[] =
  "";

  const char access::object_traits< ::project >::employees_traits::delete_all_statement[] =
  "";

  void access::object_traits< ::project >::employees_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        cond_image_type& c)
  {
    ODB_POTENTIALLY_UNUSED (c);

    std::size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;
  }

  void access::object_traits< ::project >::employees_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        data_image_type& d)
  {
    using namespace mysql;

    statement_kind sk (statement_select);
    ODB_POTENTIALLY_UNUSED (sk);

    size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;

    // value
    //
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &d.value_value;
    b[n].is_null = &d.value_null;
  }

  void access::object_traits< ::project >::employees_traits::
  grow (data_image_type& i, my_bool* t)
  {
    bool grew (false);

    // value
    //
    t[0UL] = 0;

    if (grew)
      i.version++;
  }

  void access::object_traits< ::project >::employees_traits::
  init (value_type& v, const data_image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (db);

    // value
    //
    {
      typedef object_traits< ::employee > obj_traits;
      typedef pointer_traits< value_type > ptr_traits;

      if (i.value_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_value (
          id,
          i.value_value,
          i.value_null);

        v = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::project >::employees_traits::
  insert_one (index_type, const value_type&, void*)
  {
  }

  bool access::object_traits< ::project >::employees_traits::
  load_all (index_type&, value_type& v, void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    data_image_type& di (sts.data_image ());
    init (v, di, sts.connection ().database ());

    select_statement& st (sts.select_all_statement ());
    select_statement::result r (st.fetch ());
    if (r == select_statement::no_data)
    {
      st.free_result ();
      return false;
    }

    return true;
  }

  void access::object_traits< ::project >::employees_traits::
  delete_all (void*)
  {
  }

  void access::object_traits< ::project >::employees_traits::
  load (container_type& c,
        const mysql::binding& id,
        statements_type& sts)
  {
    using namespace mysql;

    binding& db (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || db.version == 0)
    {
      bind (db.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      db.version++;
      sts.select_image_binding ().version++;
    }

    binding& cb (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || cb.version == 0)
    {
      bind (cb.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      cb.version++;
    }

    select_statement& st (sts.select_all_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());
    bool more (r != select_statement::no_data);

    if (!more)
      st.free_result ();

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::load (c, more, fs);
  }

  access::object_traits< ::project >::id_type
  access::object_traits< ::project >::
  id (const image_type& i)
  {
    id_type id;
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      id,
      i.name_value,
      i.name_size,
      i.name_null);

    return id;
  }

  bool access::object_traits< ::project >::
  grow (image_type& i, my_bool* t)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (t);

    bool grew (false);

    // name_
    //
    if (t[0UL])
    {
      i.name_value.capacity (i.name_size);
      grew = true;
    }

    return grew;
  }

  void access::object_traits< ::project >::
  bind (MYSQL_BIND* b, image_type& i, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    std::size_t n (0);

    // name_
    //
    if (sk != statement_update)
    {
      b[n].buffer_type = MYSQL_TYPE_STRING;
      b[n].buffer = i.name_value.data ();
      b[n].buffer_length = static_cast<unsigned long> (
        i.name_value.capacity ());
      b[n].length = &i.name_size;
      b[n].is_null = &i.name_null;
      n++;
    }
  }

  void access::object_traits< ::project >::
  bind (MYSQL_BIND* b, id_image_type& i)
  {
    std::size_t n (0);
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.id_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.id_value.capacity ());
    b[n].length = &i.id_size;
    b[n].is_null = &i.id_null;
  }

  bool access::object_traits< ::project >::
  init (image_type& i, const object_type& o, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    bool grew (false);

    // name_
    //
    if (sk == statement_insert)
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.name_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.name_value,
        size,
        is_null,
        o.name_);
      i.name_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.name_value.capacity ());
      i.name_null = is_null;
    }

    return grew;
  }

  void access::object_traits< ::project >::
  init (object_type& o, const image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (db);

    // name_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.name_,
      i.name_value,
      i.name_size,
      i.name_null);
  }

  void access::object_traits< ::project >::
  init (id_image_type& i, const id_type& id)
  {
    bool grew (false);

    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.id_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.id_value,
        size,
        is_null,
        id);
      i.id_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.id_value.capacity ());
      i.id_null = is_null;
    }

    if (grew)
      i.version++;
  }

  struct access::object_traits< ::project >::container_statement_cache_type
  {
    mysql::container_statements_impl< employees_traits > employees_;

    container_statement_cache_type (mysql::connection& c)
    : employees_ (c)
    {
    }
  };

  const char access::object_traits< ::project >::persist_statement[] =
  "INSERT INTO `project` ("
  "`name`)"
  " VALUES (?)";

  const char access::object_traits< ::project >::find_statement[] =
  "SELECT "
  "`project`.`name`"
  " FROM `project`"
  " WHERE `project`.`name`=?";

  const char access::object_traits< ::project >::erase_statement[] =
  "DELETE FROM `project`"
  " WHERE `name`=?";

  const char access::object_traits< ::project >::query_statement[] =
  "SELECT "
  "`project`.`name`"
  " FROM `project`"
  " ";

  const char access::object_traits< ::project >::erase_query_statement[] =
  "DELETE FROM `project`"
  " ";

  const char access::object_traits< ::project >::table_name[] =
  "`project`";

  void access::object_traits< ::project >::
  persist (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    image_type& im (sts.image ());
    binding& imb (sts.insert_image_binding ());

    if (init (im, obj, statement_insert))
      im.version++;

    if (im.version != sts.insert_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_insert);
      sts.insert_image_version (im.version);
      imb.version++;
    }

    insert_statement& st (sts.persist_statement ());
    if (!st.execute ())
      throw object_already_persistent ();
  }

  void access::object_traits< ::project >::
  update (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    if (!find_ (sts, obj.name_))
      throw object_not_persistent ();
  }

  void access::object_traits< ::project >::
  erase (database&, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    if (sts.erase_statement ().execute () != 1)
      throw object_not_persistent ();
  }

  access::object_traits< ::project >::pointer_type
  access::object_traits< ::project >::
  find (database& db, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    object_statements< object_type >::auto_lock l (sts);

    if (l.locked ())
    {
      if (!find_ (sts, id))
        return pointer_type ();
    }

    pointer_type p (
      access::object_factory< object_type, pointer_type  >::create ());
    pointer_traits< pointer_type >::guard pg (p);
    pointer_cache_traits< pointer_type >::insert_guard ig (
      pointer_cache_traits< pointer_type >::insert (db, id, p));
    object_type& obj (pointer_traits< pointer_type >::get_ref (p));

    if (l.locked ())
    {
      callback (db, obj, callback_event::pre_load);
      init (obj, sts.image (), db);
      load_ (sts, obj);
      sts.load_delayed ();
      l.unlock ();
      callback (db, obj, callback_event::post_load);
    }
    else
      sts.delay_load (id, obj, ig.position ());

    ig.release ();
    pg.release ();
    return p;
  }

  bool access::object_traits< ::project >::
  find (database& db, const id_type& id, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, id))
      return false;

    reference_cache_traits< object_type >::insert_guard ig (
      reference_cache_traits< object_type >::insert (db, id, obj));

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    ig.release ();
    return true;
  }

  bool access::object_traits< ::project >::
  reload (database& db, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, obj.name_))
      return false;

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    return true;
  }

  bool access::object_traits< ::project >::
  find_ (mysql::object_statements< object_type >& sts, const id_type& id)
  {
    using namespace mysql;

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    select_statement& st (sts.find_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      if (grow (im, sts.select_image_truncated ()))
        im.version++;

      if (im.version != sts.select_image_version ())
      {
        bind (imb.bind, im, statement_select);
        sts.select_image_version (im.version);
        imb.version++;
        st.refetch ();
      }
    }

    st.free_result ();
    return r != select_statement::no_data;
  }

  void access::object_traits< ::project >::
  load_ (mysql::object_statements< object_type >& sts, object_type& obj)
  {
    mysql::binding& idb (sts.id_image_binding ());

    employees_traits::load (
      obj.employees_,
      idb,
      sts.container_statment_cache ().employees_);
  }

  result< access::object_traits< ::project >::object_type >
  access::object_traits< ::project >::
  query (database&, const query_base_type& q)
  {
    using namespace mysql;
    using odb::details::shared;
    using odb::details::shared_ptr;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    shared_ptr<select_statement> st (
      new (shared) select_statement (
        sts.connection (),
        query_statement + q.clause (),
        q.parameters_binding (),
        imb));

    st->execute ();

    shared_ptr< odb::object_result_impl<object_type> > r (
      new (shared) mysql::object_result_impl<object_type> (
        q, st, sts));

    return result<object_type> (r);
  }

  unsigned long long access::object_traits< ::project >::
  erase_query (database&, const query_base_type& q)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    delete_statement st (
      conn,
      erase_query_statement + q.clause (),
      q.parameters_binding ());

    return st.execute ();
  }

  // employee
  //

  const char query_columns_base< ::employee >::employer_alias_[] = "`employer`";

  const char query_columns_base< ::employee >::position_alias_[] = "`position`";

  // projects_
  //

  const char access::object_traits< ::employee >::projects_traits::select_all_statement[] =
  "SELECT "
  "`employee_projects`.`value`"
  " FROM `employee_projects` WHERE `employee_projects`.`object_id`=?";

  const char access::object_traits< ::employee >::projects_traits::insert_one_statement[] =
  "INSERT INTO `employee_projects` ("
  "`object_id`,"
  "`value`)"
  " VALUES (?,?)";

  const char access::object_traits< ::employee >::projects_traits::delete_all_statement[] =
  "DELETE FROM `employee_projects`"
  " WHERE `object_id`=?";

  void access::object_traits< ::employee >::projects_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        cond_image_type& c)
  {
    ODB_POTENTIALLY_UNUSED (c);

    std::size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;
  }

  void access::object_traits< ::employee >::projects_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        data_image_type& d)
  {
    using namespace mysql;

    statement_kind sk (statement_select);
    ODB_POTENTIALLY_UNUSED (sk);

    size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;

    // value
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = d.value_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      d.value_value.capacity ());
    b[n].length = &d.value_size;
    b[n].is_null = &d.value_null;
  }

  void access::object_traits< ::employee >::projects_traits::
  grow (data_image_type& i, my_bool* t)
  {
    bool grew (false);

    // value
    //
    if (t[0UL])
    {
      i.value_value.capacity (i.value_size);
      grew = true;
    }

    if (grew)
      i.version++;
  }

  void access::object_traits< ::employee >::projects_traits::
  init (data_image_type& i, const value_type& v)
  {
    using namespace mysql;

    statement_kind sk (statement_insert);
    ODB_POTENTIALLY_UNUSED (sk);

    bool grew (false);

    // value
    //
    {
      typedef object_traits< ::project > obj_traits;
      typedef pointer_traits< value_type > ptr_traits;

      bool is_null (ptr_traits::null_ptr (v));
      if (!is_null)
      {
        const obj_traits::id_type& id (
          ptr_traits::object_id< ptr_traits::element_type  > (v));

        std::size_t size (0);
        std::size_t cap (i.value_value.capacity ());
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_string >::set_image (
          i.value_value,
          size,
          is_null,
          id);
        i.value_size = static_cast<unsigned long> (size);
        grew = grew || (cap != i.value_value.capacity ());
      }
      else
        throw null_pointer ();
      i.value_null = is_null;
    }

    if (grew)
      i.version++;
  }

  void access::object_traits< ::employee >::projects_traits::
  init (value_type& v, const data_image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (db);

    // value
    //
    {
      typedef object_traits< ::project > obj_traits;
      typedef pointer_traits< value_type > ptr_traits;

      if (i.value_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_string >::set_value (
          id,
          i.value_value,
          i.value_size,
          i.value_null);

        v = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::employee >::projects_traits::
  insert_one (index_type, const value_type& v, void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    binding& b (sts.data_image_binding ());
    data_image_type& di (sts.data_image ());

    init (di, v);

    if (di.version != sts.data_image_version ())
    {
      bind (b.bind, 0, sts.id_binding ().count, di);
      sts.data_image_version (di.version);
      b.version++;
      sts.select_image_binding ().version++;
    }

    if (!sts.insert_one_statement ().execute ())
      throw object_already_persistent ();
  }

  bool access::object_traits< ::employee >::projects_traits::
  load_all (index_type&, value_type& v, void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    data_image_type& di (sts.data_image ());
    init (v, di, sts.connection ().database ());

    select_statement& st (sts.select_all_statement ());
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      grow (di, sts.data_image_truncated ());

      if (di.version != sts.data_image_version ())
      {
        binding& b (sts.data_image_binding ());
        bind (b.bind, 0, sts.id_binding ().count, di);
        sts.data_image_version (di.version);
        b.version++;
        sts.select_image_binding ().version++;
        st.refetch ();
      }
    }

    if (r == select_statement::no_data)
    {
      st.free_result ();
      return false;
    }

    return true;
  }

  void access::object_traits< ::employee >::projects_traits::
  delete_all (void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    sts.delete_all_statement ().execute ();
  }

  void access::object_traits< ::employee >::projects_traits::
  persist (const container_type& c,
           const mysql::binding& id,
           statements_type& sts)
  {
    using namespace mysql;

    binding& b (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || b.version == 0)
    {
      bind (b.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      b.version++;
      sts.select_image_binding ().version++;
    }

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::persist (c, fs);
  }

  void access::object_traits< ::employee >::projects_traits::
  load (container_type& c,
        const mysql::binding& id,
        statements_type& sts)
  {
    using namespace mysql;

    binding& db (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || db.version == 0)
    {
      bind (db.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      db.version++;
      sts.select_image_binding ().version++;
    }

    binding& cb (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || cb.version == 0)
    {
      bind (cb.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      cb.version++;
    }

    select_statement& st (sts.select_all_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      data_image_type& di (sts.data_image ());
      grow (di, sts.data_image_truncated ());

      if (di.version != sts.data_image_version ())
      {
        bind (db.bind, 0, id.count, sts.data_image ());
        sts.data_image_version (di.version);
        db.version++;
        sts.select_image_binding ().version++;
        st.refetch ();
      }
    }

    bool more (r != select_statement::no_data);

    if (!more)
      st.free_result ();

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::load (c, more, fs);
  }

  void access::object_traits< ::employee >::projects_traits::
  update (const container_type& c,
          const mysql::binding& id,
          statements_type& sts)
  {
    using namespace mysql;

    binding& db (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || db.version == 0)
    {
      bind (db.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      db.version++;
      sts.select_image_binding ().version++;
    }

    binding& cb (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || cb.version == 0)
    {
      bind (cb.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      cb.version++;
    }

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::update (c, fs);
  }

  void access::object_traits< ::employee >::projects_traits::
  erase (const mysql::binding& id, statements_type& sts)
  {
    using namespace mysql;

    binding& b (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || b.version == 0)
    {
      bind (b.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      b.version++;
    }

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::erase (fs);
  }

  access::object_traits< ::employee >::id_type
  access::object_traits< ::employee >::
  id (const image_type& i)
  {
    id_type id;
    mysql::value_traits<
        long unsigned int,
        mysql::id_ulonglong >::set_value (
      id,
      i.id_value,
      i.id_null);

    return id;
  }

  bool access::object_traits< ::employee >::
  grow (image_type& i, my_bool* t)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (t);

    bool grew (false);

    // id_
    //
    t[0UL] = 0;

    // first_
    //
    if (t[1UL])
    {
      i.first_value.capacity (i.first_size);
      grew = true;
    }

    // last_
    //
    if (t[2UL])
    {
      i.last_value.capacity (i.last_size);
      grew = true;
    }

    // employer_
    //
    if (t[3UL])
    {
      i.employer_value.capacity (i.employer_size);
      grew = true;
    }

    // position_
    //
    t[4UL] = 0;

    return grew;
  }

  void access::object_traits< ::employee >::
  bind (MYSQL_BIND* b, image_type& i, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    std::size_t n (0);

    // id_
    //
    if (sk != statement_update)
    {
      b[n].buffer_type = MYSQL_TYPE_LONGLONG;
      b[n].is_unsigned = 1;
      b[n].buffer = &i.id_value;
      b[n].is_null = &i.id_null;
      n++;
    }

    // first_
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.first_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.first_value.capacity ());
    b[n].length = &i.first_size;
    b[n].is_null = &i.first_null;
    n++;

    // last_
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.last_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.last_value.capacity ());
    b[n].length = &i.last_size;
    b[n].is_null = &i.last_null;
    n++;

    // employer_
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.employer_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.employer_value.capacity ());
    b[n].length = &i.employer_size;
    b[n].is_null = &i.employer_null;
    n++;

    // position_
    //
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &i.position_value;
    b[n].is_null = &i.position_null;
    n++;
  }

  void access::object_traits< ::employee >::
  bind (MYSQL_BIND* b, id_image_type& i)
  {
    std::size_t n (0);
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &i.id_value;
    b[n].is_null = &i.id_null;
  }

  bool access::object_traits< ::employee >::
  init (image_type& i, const object_type& o, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    bool grew (false);

    // id_
    //
    if (sk == statement_insert)
    {
      bool is_null;
      mysql::value_traits<
          long unsigned int,
          mysql::id_ulonglong >::set_image (
        i.id_value, is_null, o.id_);
      i.id_null = is_null;
    }

    // first_
    //
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.first_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.first_value,
        size,
        is_null,
        o.first_);
      i.first_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.first_value.capacity ());
      i.first_null = is_null;
    }

    // last_
    //
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.last_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.last_value,
        size,
        is_null,
        o.last_);
      i.last_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.last_value.capacity ());
      i.last_null = is_null;
    }

    // employer_
    //
    {
      typedef object_traits< ::employer > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_shared_ptr< ::employer > > ptr_traits;

      bool is_null (ptr_traits::null_ptr (o.employer_));
      if (!is_null)
      {
        const obj_traits::id_type& id (
          ptr_traits::object_id< ptr_traits::element_type  > (o.employer_));

        std::size_t size (0);
        std::size_t cap (i.employer_value.capacity ());
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_string >::set_image (
          i.employer_value,
          size,
          is_null,
          id);
        i.employer_size = static_cast<unsigned long> (size);
        grew = grew || (cap != i.employer_value.capacity ());
      }
      else
        throw null_pointer ();
      i.employer_null = is_null;
    }

    // position_
    //
    {
      typedef object_traits< ::position > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_shared_ptr< ::position > > ptr_traits;

      bool is_null (ptr_traits::null_ptr (o.position_));
      if (!is_null)
      {
        const obj_traits::id_type& id (
          ptr_traits::object_id< ptr_traits::element_type  > (o.position_));

        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_image (
          i.position_value, is_null, id);
      }
      else
        throw null_pointer ();
      i.position_null = is_null;
    }

    return grew;
  }

  void access::object_traits< ::employee >::
  init (object_type& o, const image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (db);

    // id_
    //
    mysql::value_traits<
        long unsigned int,
        mysql::id_ulonglong >::set_value (
      o.id_,
      i.id_value,
      i.id_null);

    // first_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.first_,
      i.first_value,
      i.first_size,
      i.first_null);

    // last_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.last_,
      i.last_value,
      i.last_size,
      i.last_null);

    // employer_
    //
    {
      typedef object_traits< ::employer > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_shared_ptr< ::employer > > ptr_traits;

      if (i.employer_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_string >::set_value (
          id,
          i.employer_value,
          i.employer_size,
          i.employer_null);

        o.employer_ = ptr_traits::pointer_type (db, id);
      }
    }

    // position_
    //
    {
      typedef object_traits< ::position > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_shared_ptr< ::position > > ptr_traits;

      if (i.position_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_value (
          id,
          i.position_value,
          i.position_null);

        o.position_ = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::employee >::
  init (id_image_type& i, const id_type& id)
  {
    {
      bool is_null;
      mysql::value_traits<
          long unsigned int,
          mysql::id_ulonglong >::set_image (
        i.id_value, is_null, id);
      i.id_null = is_null;
    }
  }

  struct access::object_traits< ::employee >::container_statement_cache_type
  {
    mysql::container_statements_impl< projects_traits > projects_;

    container_statement_cache_type (mysql::connection& c)
    : projects_ (c)
    {
    }
  };

  const char access::object_traits< ::employee >::persist_statement[] =
  "INSERT INTO `employee` ("
  "`id`,"
  "`first`,"
  "`last`,"
  "`employer`,"
  "`position`)"
  " VALUES (?,?,?,?,?)";

  const char access::object_traits< ::employee >::find_statement[] =
  "SELECT "
  "`employee`.`id`,"
  "`employee`.`first`,"
  "`employee`.`last`,"
  "`employee`.`employer`,"
  "`employee`.`position`"
  " FROM `employee`"
  " WHERE `employee`.`id`=?";

  const char access::object_traits< ::employee >::update_statement[] =
  "UPDATE `employee` SET "
  "`first`=?,"
  "`last`=?,"
  "`employer`=?,"
  "`position`=?"
  " WHERE `id`=?";

  const char access::object_traits< ::employee >::erase_statement[] =
  "DELETE FROM `employee`"
  " WHERE `id`=?";

  const char access::object_traits< ::employee >::query_statement[] =
  "SELECT "
  "`employee`.`id`,"
  "`employee`.`first`,"
  "`employee`.`last`,"
  "`employee`.`employer`,"
  "`employee`.`position`"
  " FROM `employee`"
  " LEFT JOIN `employer` AS `employer` ON `employer`.`name` = `employee`.`employer`"
  " LEFT JOIN `position` AS `position` ON `position`.`id` = `employee`.`position`"
  " ";

  const char access::object_traits< ::employee >::erase_query_statement[] =
  "DELETE FROM `employee`"
  " ";

  const char access::object_traits< ::employee >::table_name[] =
  "`employee`";

  void access::object_traits< ::employee >::
  persist (database&, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    image_type& im (sts.image ());
    binding& imb (sts.insert_image_binding ());

    if (init (im, obj, statement_insert))
      im.version++;

    im.id_value = 0;

    if (im.version != sts.insert_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_insert);
      sts.insert_image_version (im.version);
      imb.version++;
    }

    insert_statement& st (sts.persist_statement ());
    if (!st.execute ())
      throw object_already_persistent ();

    obj.id_ = static_cast< id_type > (st.id ());

    id_image_type& i (sts.id_image ());
    init (i, obj.id_);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    projects_traits::persist (
      obj.projects_,
      idb,
      sts.container_statment_cache ().projects_);
  }

  void access::object_traits< ::employee >::
  update (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, obj.id_);

    image_type& im (sts.image ());
    if (init (im, obj, statement_update))
      im.version++;

    bool u (false);
    binding& imb (sts.update_image_binding ());
    if (im.version != sts.update_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_update);
      sts.update_image_version (im.version);
      imb.version++;
      u = true;
    }

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.update_id_image_version () || idb.version == 0)
    {
      if (i.version != sts.id_image_version () || idb.version == 0)
      {
        bind (idb.bind, i);
        sts.id_image_version (i.version);
        idb.version++;
      }

      sts.update_id_image_version (i.version);

      if (!u)
        imb.version++;
    }

    if (sts.update_statement ().execute () == 0)
      throw object_not_persistent ();

    projects_traits::update (
      obj.projects_,
      idb,
      sts.container_statment_cache ().projects_);
  }

  void access::object_traits< ::employee >::
  erase (database&, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    projects_traits::erase (
      idb,
      sts.container_statment_cache ().projects_);

    if (sts.erase_statement ().execute () != 1)
      throw object_not_persistent ();
  }

  access::object_traits< ::employee >::pointer_type
  access::object_traits< ::employee >::
  find (database& db, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    object_statements< object_type >::auto_lock l (sts);

    if (l.locked ())
    {
      if (!find_ (sts, id))
        return pointer_type ();
    }

    pointer_type p (
      access::object_factory< object_type, pointer_type  >::create ());
    pointer_traits< pointer_type >::guard pg (p);
    pointer_cache_traits< pointer_type >::insert_guard ig (
      pointer_cache_traits< pointer_type >::insert (db, id, p));
    object_type& obj (pointer_traits< pointer_type >::get_ref (p));

    if (l.locked ())
    {
      callback (db, obj, callback_event::pre_load);
      init (obj, sts.image (), db);
      load_ (sts, obj);
      sts.load_delayed ();
      l.unlock ();
      callback (db, obj, callback_event::post_load);
    }
    else
      sts.delay_load (id, obj, ig.position ());

    ig.release ();
    pg.release ();
    return p;
  }

  bool access::object_traits< ::employee >::
  find (database& db, const id_type& id, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, id))
      return false;

    reference_cache_traits< object_type >::insert_guard ig (
      reference_cache_traits< object_type >::insert (db, id, obj));

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    ig.release ();
    return true;
  }

  bool access::object_traits< ::employee >::
  reload (database& db, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, obj.id_))
      return false;

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    return true;
  }

  bool access::object_traits< ::employee >::
  find_ (mysql::object_statements< object_type >& sts, const id_type& id)
  {
    using namespace mysql;

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    select_statement& st (sts.find_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      if (grow (im, sts.select_image_truncated ()))
        im.version++;

      if (im.version != sts.select_image_version ())
      {
        bind (imb.bind, im, statement_select);
        sts.select_image_version (im.version);
        imb.version++;
        st.refetch ();
      }
    }

    st.free_result ();
    return r != select_statement::no_data;
  }

  void access::object_traits< ::employee >::
  load_ (mysql::object_statements< object_type >& sts, object_type& obj)
  {
    mysql::binding& idb (sts.id_image_binding ());

    projects_traits::load (
      obj.projects_,
      idb,
      sts.container_statment_cache ().projects_);
  }

  result< access::object_traits< ::employee >::object_type >
  access::object_traits< ::employee >::
  query (database&, const query_base_type& q)
  {
    using namespace mysql;
    using odb::details::shared;
    using odb::details::shared_ptr;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    shared_ptr<select_statement> st (
      new (shared) select_statement (
        sts.connection (),
        query_statement + q.clause (),
        q.parameters_binding (),
        imb));

    st->execute ();

    shared_ptr< odb::object_result_impl<object_type> > r (
      new (shared) mysql::object_result_impl<object_type> (
        q, st, sts));

    return result<object_type> (r);
  }

  unsigned long long access::object_traits< ::employee >::
  erase_query (database&, const query_base_type& q)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    delete_statement st (
      conn,
      erase_query_statement + q.clause (),
      q.parameters_binding ());

    return st.execute ();
  }
}

// Begin epilogue.
//
//
// End epilogue.

#include <odb/post.hxx>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: employee-odb.hxx
Type: application/octet-stream
Size: 29150 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20120313/2b1767cf/employee-odb-0002.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: employee-odb.ixx
Type: application/octet-stream
Size: 6034 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20120313/2b1767cf/employee-odb-0003.obj
-------------- next part --------------
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//

#include <odb/pre.hxx>

// Begin prologue.
//
//
// End prologue.

#include "employee-odb.hxx"

#include <cassert>
#include <cstring> // std::memcpy

#include <odb/cache-traits.hxx>
#include <odb/details/shared-ptr.hxx>

#include <odb/mysql/binding.hxx>
#include <odb/mysql/traits.hxx>
#include <odb/mysql/database.hxx>
#include <odb/mysql/transaction.hxx>
#include <odb/mysql/connection.hxx>
#include <odb/mysql/statement.hxx>
#include <odb/mysql/statement-cache.hxx>
#include <odb/mysql/object-statements.hxx>
#include <odb/mysql/container-statements.hxx>
#include <odb/mysql/exceptions.hxx>
#include <odb/mysql/result.hxx>
#include <odb/mysql/enum.hxx>

namespace odb
{
  // employer
  //

  // employees_
  //

  const char access::object_traits< ::employer >::employees_traits::select_all_statement[] =
  "SELECT "
  "`inverse_employee`.`id`"
  " FROM `inverse_employee` WHERE `inverse_employee`.`employer`=?";

  const char access::object_traits< ::employer >::employees_traits::insert_one_statement[] =
  "";

  const char access::object_traits< ::employer >::employees_traits::delete_all_statement[] =
  "";

  void access::object_traits< ::employer >::employees_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        cond_image_type& c)
  {
    ODB_POTENTIALLY_UNUSED (c);

    std::size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;
  }

  void access::object_traits< ::employer >::employees_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        data_image_type& d)
  {
    using namespace mysql;

    statement_kind sk (statement_select);
    ODB_POTENTIALLY_UNUSED (sk);

    size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;

    // value
    //
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &d.value_value;
    b[n].is_null = &d.value_null;
  }

  void access::object_traits< ::employer >::employees_traits::
  grow (data_image_type& i, my_bool* t)
  {
    bool grew (false);

    // value
    //
    t[0UL] = 0;

    if (grew)
      i.version++;
  }

  void access::object_traits< ::employer >::employees_traits::
  init (value_type& v, const data_image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (db);

    // value
    //
    {
      typedef object_traits< ::employee > obj_traits;
      typedef pointer_traits< value_type > ptr_traits;

      if (i.value_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_value (
          id,
          i.value_value,
          i.value_null);

        v = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::employer >::employees_traits::
  insert_one (index_type, const value_type&, void*)
  {
  }

  bool access::object_traits< ::employer >::employees_traits::
  load_all (index_type&, value_type& v, void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    data_image_type& di (sts.data_image ());
    init (v, di, sts.connection ().database ());

    select_statement& st (sts.select_all_statement ());
    select_statement::result r (st.fetch ());
    if (r == select_statement::no_data)
    {
      st.free_result ();
      return false;
    }

    return true;
  }

  void access::object_traits< ::employer >::employees_traits::
  delete_all (void*)
  {
  }

  void access::object_traits< ::employer >::employees_traits::
  load (container_type& c,
        const mysql::binding& id,
        statements_type& sts)
  {
    using namespace mysql;

    binding& db (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || db.version == 0)
    {
      bind (db.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      db.version++;
      sts.select_image_binding ().version++;
    }

    binding& cb (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || cb.version == 0)
    {
      bind (cb.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      cb.version++;
    }

    select_statement& st (sts.select_all_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());
    bool more (r != select_statement::no_data);

    if (!more)
      st.free_result ();

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::load (c, more, fs);
  }

  access::object_traits< ::employer >::id_type
  access::object_traits< ::employer >::
  id (const image_type& i)
  {
    id_type id;
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      id,
      i.name_value,
      i.name_size,
      i.name_null);

    return id;
  }

  bool access::object_traits< ::employer >::
  grow (image_type& i, my_bool* t)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (t);

    bool grew (false);

    // name_
    //
    if (t[0UL])
    {
      i.name_value.capacity (i.name_size);
      grew = true;
    }

    return grew;
  }

  void access::object_traits< ::employer >::
  bind (MYSQL_BIND* b, image_type& i, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    std::size_t n (0);

    // name_
    //
    if (sk != statement_update)
    {
      b[n].buffer_type = MYSQL_TYPE_STRING;
      b[n].buffer = i.name_value.data ();
      b[n].buffer_length = static_cast<unsigned long> (
        i.name_value.capacity ());
      b[n].length = &i.name_size;
      b[n].is_null = &i.name_null;
      n++;
    }
  }

  void access::object_traits< ::employer >::
  bind (MYSQL_BIND* b, id_image_type& i)
  {
    std::size_t n (0);
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.id_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.id_value.capacity ());
    b[n].length = &i.id_size;
    b[n].is_null = &i.id_null;
  }

  bool access::object_traits< ::employer >::
  init (image_type& i, const object_type& o, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    bool grew (false);

    // name_
    //
    if (sk == statement_insert)
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.name_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.name_value,
        size,
        is_null,
        o.name_);
      i.name_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.name_value.capacity ());
      i.name_null = is_null;
    }

    return grew;
  }

  void access::object_traits< ::employer >::
  init (object_type& o, const image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (db);

    // name_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.name_,
      i.name_value,
      i.name_size,
      i.name_null);
  }

  void access::object_traits< ::employer >::
  init (id_image_type& i, const id_type& id)
  {
    bool grew (false);

    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.id_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.id_value,
        size,
        is_null,
        id);
      i.id_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.id_value.capacity ());
      i.id_null = is_null;
    }

    if (grew)
      i.version++;
  }

  struct access::object_traits< ::employer >::container_statement_cache_type
  {
    mysql::container_statements_impl< employees_traits > employees_;

    container_statement_cache_type (mysql::connection& c)
    : employees_ (c)
    {
    }
  };

  const char access::object_traits< ::employer >::persist_statement[] =
  "INSERT INTO `inverse_employer` ("
  "`name`)"
  " VALUES (?)";

  const char access::object_traits< ::employer >::find_statement[] =
  "SELECT "
  "`inverse_employer`.`name`"
  " FROM `inverse_employer`"
  " WHERE `inverse_employer`.`name`=?";

  const char access::object_traits< ::employer >::erase_statement[] =
  "DELETE FROM `inverse_employer`"
  " WHERE `name`=?";

  const char access::object_traits< ::employer >::query_statement[] =
  "SELECT "
  "`inverse_employer`.`name`"
  " FROM `inverse_employer`"
  " ";

  const char access::object_traits< ::employer >::erase_query_statement[] =
  "DELETE FROM `inverse_employer`"
  " ";

  const char access::object_traits< ::employer >::table_name[] =
  "`inverse_employer`";

  void access::object_traits< ::employer >::
  persist (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    image_type& im (sts.image ());
    binding& imb (sts.insert_image_binding ());

    if (init (im, obj, statement_insert))
      im.version++;

    if (im.version != sts.insert_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_insert);
      sts.insert_image_version (im.version);
      imb.version++;
    }

    insert_statement& st (sts.persist_statement ());
    if (!st.execute ())
      throw object_already_persistent ();
  }

  void access::object_traits< ::employer >::
  update (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    if (!find_ (sts, obj.name_))
      throw object_not_persistent ();
  }

  void access::object_traits< ::employer >::
  erase (database&, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    if (sts.erase_statement ().execute () != 1)
      throw object_not_persistent ();
  }

  access::object_traits< ::employer >::pointer_type
  access::object_traits< ::employer >::
  find (database& db, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    object_statements< object_type >::auto_lock l (sts);

    if (l.locked ())
    {
      if (!find_ (sts, id))
        return pointer_type ();
    }

    pointer_type p (
      access::object_factory< object_type, pointer_type  >::create ());
    pointer_traits< pointer_type >::guard pg (p);
    pointer_cache_traits< pointer_type >::insert_guard ig (
      pointer_cache_traits< pointer_type >::insert (db, id, p));
    object_type& obj (pointer_traits< pointer_type >::get_ref (p));

    if (l.locked ())
    {
      callback (db, obj, callback_event::pre_load);
      init (obj, sts.image (), db);
      load_ (sts, obj);
      sts.load_delayed ();
      l.unlock ();
      callback (db, obj, callback_event::post_load);
    }
    else
      sts.delay_load (id, obj, ig.position ());

    ig.release ();
    pg.release ();
    return p;
  }

  bool access::object_traits< ::employer >::
  find (database& db, const id_type& id, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, id))
      return false;

    reference_cache_traits< object_type >::insert_guard ig (
      reference_cache_traits< object_type >::insert (db, id, obj));

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    ig.release ();
    return true;
  }

  bool access::object_traits< ::employer >::
  reload (database& db, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, obj.name_))
      return false;

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    return true;
  }

  bool access::object_traits< ::employer >::
  find_ (mysql::object_statements< object_type >& sts, const id_type& id)
  {
    using namespace mysql;

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    select_statement& st (sts.find_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      if (grow (im, sts.select_image_truncated ()))
        im.version++;

      if (im.version != sts.select_image_version ())
      {
        bind (imb.bind, im, statement_select);
        sts.select_image_version (im.version);
        imb.version++;
        st.refetch ();
      }
    }

    st.free_result ();
    return r != select_statement::no_data;
  }

  void access::object_traits< ::employer >::
  load_ (mysql::object_statements< object_type >& sts, object_type& obj)
  {
    mysql::binding& idb (sts.id_image_binding ());

    employees_traits::load (
      obj.employees_,
      idb,
      sts.container_statment_cache ().employees_);
  }

  result< access::object_traits< ::employer >::object_type >
  access::object_traits< ::employer >::
  query (database&, const query_base_type& q)
  {
    using namespace mysql;
    using odb::details::shared;
    using odb::details::shared_ptr;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    shared_ptr<select_statement> st (
      new (shared) select_statement (
        sts.connection (),
        query_statement + q.clause (),
        q.parameters_binding (),
        imb));

    st->execute ();

    shared_ptr< odb::object_result_impl<object_type> > r (
      new (shared) mysql::object_result_impl<object_type> (
        q, st, sts));

    return result<object_type> (r);
  }

  unsigned long long access::object_traits< ::employer >::
  erase_query (database&, const query_base_type& q)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    delete_statement st (
      conn,
      erase_query_statement + q.clause (),
      q.parameters_binding ());

    return st.execute ();
  }

  // position
  //

  const char query_columns_base< ::position >::employee_alias_[] = "`employee`";

  const query_columns_base< ::position >::employee_type_
  query_columns_base< ::position >::employee;

  access::object_traits< ::position >::id_type
  access::object_traits< ::position >::
  id (const image_type& i)
  {
    id_type id;
    mysql::value_traits<
        long unsigned int,
        mysql::id_ulonglong >::set_value (
      id,
      i.id_value,
      i.id_null);

    return id;
  }

  bool access::object_traits< ::position >::
  grow (image_type& i, my_bool* t)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (t);

    bool grew (false);

    // id_
    //
    t[0UL] = 0;

    // title_
    //
    if (t[1UL])
    {
      i.title_value.capacity (i.title_size);
      grew = true;
    }

    // employee_
    //
    t[2UL] = 0;

    return grew;
  }

  void access::object_traits< ::position >::
  bind (MYSQL_BIND* b, image_type& i, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    std::size_t n (0);

    // id_
    //
    if (sk != statement_update)
    {
      b[n].buffer_type = MYSQL_TYPE_LONGLONG;
      b[n].is_unsigned = 1;
      b[n].buffer = &i.id_value;
      b[n].is_null = &i.id_null;
      n++;
    }

    // title_
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.title_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.title_value.capacity ());
    b[n].length = &i.title_size;
    b[n].is_null = &i.title_null;
    n++;

    // employee_
    //
    if (sk == statement_select)
    {
      b[n].buffer_type = MYSQL_TYPE_LONGLONG;
      b[n].is_unsigned = 1;
      b[n].buffer = &i.employee_value;
      b[n].is_null = &i.employee_null;
      n++;
    }
  }

  void access::object_traits< ::position >::
  bind (MYSQL_BIND* b, id_image_type& i)
  {
    std::size_t n (0);
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &i.id_value;
    b[n].is_null = &i.id_null;
  }

  bool access::object_traits< ::position >::
  init (image_type& i, const object_type& o, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    bool grew (false);

    // id_
    //
    if (sk == statement_insert)
    {
      bool is_null;
      mysql::value_traits<
          long unsigned int,
          mysql::id_ulonglong >::set_image (
        i.id_value, is_null, o.id_);
      i.id_null = is_null;
    }

    // title_
    //
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.title_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.title_value,
        size,
        is_null,
        o.title_);
      i.title_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.title_value.capacity ());
      i.title_null = is_null;
    }

    return grew;
  }

  void access::object_traits< ::position >::
  init (object_type& o, const image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (db);

    // id_
    //
    mysql::value_traits<
        long unsigned int,
        mysql::id_ulonglong >::set_value (
      o.id_,
      i.id_value,
      i.id_null);

    // title_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.title_,
      i.title_value,
      i.title_size,
      i.title_null);

    // employee_
    //
    {
      typedef object_traits< ::employee > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_weak_ptr< ::employee > > ptr_traits;

      if (i.employee_null)
        o.employee_ = ptr_traits::pointer_type ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_value (
          id,
          i.employee_value,
          i.employee_null);

        o.employee_ = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::position >::
  init (id_image_type& i, const id_type& id)
  {
    {
      bool is_null;
      mysql::value_traits<
          long unsigned int,
          mysql::id_ulonglong >::set_image (
        i.id_value, is_null, id);
      i.id_null = is_null;
    }
  }

  struct access::object_traits< ::position >::container_statement_cache_type
  {
    container_statement_cache_type (mysql::connection&)
    {
    }
  };

  const char access::object_traits< ::position >::persist_statement[] =
  "INSERT INTO `inverse_position` ("
  "`id`,"
  "`title`)"
  " VALUES (?,?)";

  const char access::object_traits< ::position >::find_statement[] =
  "SELECT "
  "`inverse_position`.`id`,"
  "`inverse_position`.`title`,"
  "`employee`.`id`"
  " FROM `inverse_position`"
  " LEFT JOIN `inverse_employee` AS `employee` ON `employee`.`position` = `inverse_position`.`id`"
  " WHERE `inverse_position`.`id`=?";

  const char access::object_traits< ::position >::update_statement[] =
  "UPDATE `inverse_position` SET "
  "`title`=?"
  " WHERE `id`=?";

  const char access::object_traits< ::position >::erase_statement[] =
  "DELETE FROM `inverse_position`"
  " WHERE `id`=?";

  const char access::object_traits< ::position >::query_statement[] =
  "SELECT "
  "`inverse_position`.`id`,"
  "`inverse_position`.`title`,"
  "`employee`.`id`"
  " FROM `inverse_position`"
  " LEFT JOIN `inverse_employee` AS `employee` ON `employee`.`position` = `inverse_position`.`id`"
  " ";

  const char access::object_traits< ::position >::erase_query_statement[] =
  "DELETE FROM `inverse_position`"
  " ";

  const char access::object_traits< ::position >::table_name[] =
  "`inverse_position`";

  void access::object_traits< ::position >::
  persist (database&, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    image_type& im (sts.image ());
    binding& imb (sts.insert_image_binding ());

    if (init (im, obj, statement_insert))
      im.version++;

    im.id_value = 0;

    if (im.version != sts.insert_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_insert);
      sts.insert_image_version (im.version);
      imb.version++;
    }

    insert_statement& st (sts.persist_statement ());
    if (!st.execute ())
      throw object_already_persistent ();

    obj.id_ = static_cast< id_type > (st.id ());
  }

  void access::object_traits< ::position >::
  update (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, obj.id_);

    image_type& im (sts.image ());
    if (init (im, obj, statement_update))
      im.version++;

    bool u (false);
    binding& imb (sts.update_image_binding ());
    if (im.version != sts.update_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_update);
      sts.update_image_version (im.version);
      imb.version++;
      u = true;
    }

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.update_id_image_version () || idb.version == 0)
    {
      if (i.version != sts.id_image_version () || idb.version == 0)
      {
        bind (idb.bind, i);
        sts.id_image_version (i.version);
        idb.version++;
      }

      sts.update_id_image_version (i.version);

      if (!u)
        imb.version++;
    }

    if (sts.update_statement ().execute () == 0)
      throw object_not_persistent ();
  }

  void access::object_traits< ::position >::
  erase (database&, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    if (sts.erase_statement ().execute () != 1)
      throw object_not_persistent ();
  }

  access::object_traits< ::position >::pointer_type
  access::object_traits< ::position >::
  find (database& db, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    object_statements< object_type >::auto_lock l (sts);

    if (l.locked ())
    {
      if (!find_ (sts, id))
        return pointer_type ();
    }

    pointer_type p (
      access::object_factory< object_type, pointer_type  >::create ());
    pointer_traits< pointer_type >::guard pg (p);
    pointer_cache_traits< pointer_type >::insert_guard ig (
      pointer_cache_traits< pointer_type >::insert (db, id, p));
    object_type& obj (pointer_traits< pointer_type >::get_ref (p));

    if (l.locked ())
    {
      callback (db, obj, callback_event::pre_load);
      init (obj, sts.image (), db);
      load_ (sts, obj);
      sts.load_delayed ();
      l.unlock ();
      callback (db, obj, callback_event::post_load);
    }
    else
      sts.delay_load (id, obj, ig.position ());

    ig.release ();
    pg.release ();
    return p;
  }

  bool access::object_traits< ::position >::
  find (database& db, const id_type& id, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, id))
      return false;

    reference_cache_traits< object_type >::insert_guard ig (
      reference_cache_traits< object_type >::insert (db, id, obj));

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    ig.release ();
    return true;
  }

  bool access::object_traits< ::position >::
  reload (database& db, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, obj.id_))
      return false;

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    return true;
  }

  bool access::object_traits< ::position >::
  find_ (mysql::object_statements< object_type >& sts, const id_type& id)
  {
    using namespace mysql;

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    select_statement& st (sts.find_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      if (grow (im, sts.select_image_truncated ()))
        im.version++;

      if (im.version != sts.select_image_version ())
      {
        bind (imb.bind, im, statement_select);
        sts.select_image_version (im.version);
        imb.version++;
        st.refetch ();
      }
    }

    st.free_result ();
    return r != select_statement::no_data;
  }

  result< access::object_traits< ::position >::object_type >
  access::object_traits< ::position >::
  query (database&, const query_base_type& q)
  {
    using namespace mysql;
    using odb::details::shared;
    using odb::details::shared_ptr;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    shared_ptr<select_statement> st (
      new (shared) select_statement (
        sts.connection (),
        query_statement + q.clause (),
        q.parameters_binding (),
        imb));

    st->execute ();

    shared_ptr< odb::object_result_impl<object_type> > r (
      new (shared) mysql::object_result_impl<object_type> (
        q, st, sts));

    return result<object_type> (r);
  }

  unsigned long long access::object_traits< ::position >::
  erase_query (database&, const query_base_type& q)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    delete_statement st (
      conn,
      erase_query_statement + q.clause (),
      q.parameters_binding ());

    return st.execute ();
  }

  // project
  //

  // employees_
  //

  const char access::object_traits< ::project >::employees_traits::select_all_statement[] =
  "SELECT "
  "`inverse_employee_projects`.`object_id`"
  " FROM `inverse_employee_projects` WHERE `inverse_employee_projects`.`value`=?";

  const char access::object_traits< ::project >::employees_traits::insert_one_statement[] =
  "";

  const char access::object_traits< ::project >::employees_traits::delete_all_statement[] =
  "";

  void access::object_traits< ::project >::employees_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        cond_image_type& c)
  {
    ODB_POTENTIALLY_UNUSED (c);

    std::size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;
  }

  void access::object_traits< ::project >::employees_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        data_image_type& d)
  {
    using namespace mysql;

    statement_kind sk (statement_select);
    ODB_POTENTIALLY_UNUSED (sk);

    size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;

    // value
    //
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &d.value_value;
    b[n].is_null = &d.value_null;
  }

  void access::object_traits< ::project >::employees_traits::
  grow (data_image_type& i, my_bool* t)
  {
    bool grew (false);

    // value
    //
    t[0UL] = 0;

    if (grew)
      i.version++;
  }

  void access::object_traits< ::project >::employees_traits::
  init (value_type& v, const data_image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (db);

    // value
    //
    {
      typedef object_traits< ::employee > obj_traits;
      typedef pointer_traits< value_type > ptr_traits;

      if (i.value_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_value (
          id,
          i.value_value,
          i.value_null);

        v = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::project >::employees_traits::
  insert_one (index_type, const value_type&, void*)
  {
  }

  bool access::object_traits< ::project >::employees_traits::
  load_all (index_type&, value_type& v, void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    data_image_type& di (sts.data_image ());
    init (v, di, sts.connection ().database ());

    select_statement& st (sts.select_all_statement ());
    select_statement::result r (st.fetch ());
    if (r == select_statement::no_data)
    {
      st.free_result ();
      return false;
    }

    return true;
  }

  void access::object_traits< ::project >::employees_traits::
  delete_all (void*)
  {
  }

  void access::object_traits< ::project >::employees_traits::
  load (container_type& c,
        const mysql::binding& id,
        statements_type& sts)
  {
    using namespace mysql;

    binding& db (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || db.version == 0)
    {
      bind (db.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      db.version++;
      sts.select_image_binding ().version++;
    }

    binding& cb (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || cb.version == 0)
    {
      bind (cb.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      cb.version++;
    }

    select_statement& st (sts.select_all_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());
    bool more (r != select_statement::no_data);

    if (!more)
      st.free_result ();

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::load (c, more, fs);
  }

  access::object_traits< ::project >::id_type
  access::object_traits< ::project >::
  id (const image_type& i)
  {
    id_type id;
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      id,
      i.name_value,
      i.name_size,
      i.name_null);

    return id;
  }

  bool access::object_traits< ::project >::
  grow (image_type& i, my_bool* t)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (t);

    bool grew (false);

    // name_
    //
    if (t[0UL])
    {
      i.name_value.capacity (i.name_size);
      grew = true;
    }

    return grew;
  }

  void access::object_traits< ::project >::
  bind (MYSQL_BIND* b, image_type& i, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    std::size_t n (0);

    // name_
    //
    if (sk != statement_update)
    {
      b[n].buffer_type = MYSQL_TYPE_STRING;
      b[n].buffer = i.name_value.data ();
      b[n].buffer_length = static_cast<unsigned long> (
        i.name_value.capacity ());
      b[n].length = &i.name_size;
      b[n].is_null = &i.name_null;
      n++;
    }
  }

  void access::object_traits< ::project >::
  bind (MYSQL_BIND* b, id_image_type& i)
  {
    std::size_t n (0);
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.id_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.id_value.capacity ());
    b[n].length = &i.id_size;
    b[n].is_null = &i.id_null;
  }

  bool access::object_traits< ::project >::
  init (image_type& i, const object_type& o, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    bool grew (false);

    // name_
    //
    if (sk == statement_insert)
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.name_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.name_value,
        size,
        is_null,
        o.name_);
      i.name_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.name_value.capacity ());
      i.name_null = is_null;
    }

    return grew;
  }

  void access::object_traits< ::project >::
  init (object_type& o, const image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (db);

    // name_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.name_,
      i.name_value,
      i.name_size,
      i.name_null);
  }

  void access::object_traits< ::project >::
  init (id_image_type& i, const id_type& id)
  {
    bool grew (false);

    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.id_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.id_value,
        size,
        is_null,
        id);
      i.id_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.id_value.capacity ());
      i.id_null = is_null;
    }

    if (grew)
      i.version++;
  }

  struct access::object_traits< ::project >::container_statement_cache_type
  {
    mysql::container_statements_impl< employees_traits > employees_;

    container_statement_cache_type (mysql::connection& c)
    : employees_ (c)
    {
    }
  };

  const char access::object_traits< ::project >::persist_statement[] =
  "INSERT INTO `inverse_project` ("
  "`name`)"
  " VALUES (?)";

  const char access::object_traits< ::project >::find_statement[] =
  "SELECT "
  "`inverse_project`.`name`"
  " FROM `inverse_project`"
  " WHERE `inverse_project`.`name`=?";

  const char access::object_traits< ::project >::erase_statement[] =
  "DELETE FROM `inverse_project`"
  " WHERE `name`=?";

  const char access::object_traits< ::project >::query_statement[] =
  "SELECT "
  "`inverse_project`.`name`"
  " FROM `inverse_project`"
  " ";

  const char access::object_traits< ::project >::erase_query_statement[] =
  "DELETE FROM `inverse_project`"
  " ";

  const char access::object_traits< ::project >::table_name[] =
  "`inverse_project`";

  void access::object_traits< ::project >::
  persist (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    image_type& im (sts.image ());
    binding& imb (sts.insert_image_binding ());

    if (init (im, obj, statement_insert))
      im.version++;

    if (im.version != sts.insert_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_insert);
      sts.insert_image_version (im.version);
      imb.version++;
    }

    insert_statement& st (sts.persist_statement ());
    if (!st.execute ())
      throw object_already_persistent ();
  }

  void access::object_traits< ::project >::
  update (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    if (!find_ (sts, obj.name_))
      throw object_not_persistent ();
  }

  void access::object_traits< ::project >::
  erase (database&, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    if (sts.erase_statement ().execute () != 1)
      throw object_not_persistent ();
  }

  access::object_traits< ::project >::pointer_type
  access::object_traits< ::project >::
  find (database& db, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    object_statements< object_type >::auto_lock l (sts);

    if (l.locked ())
    {
      if (!find_ (sts, id))
        return pointer_type ();
    }

    pointer_type p (
      access::object_factory< object_type, pointer_type  >::create ());
    pointer_traits< pointer_type >::guard pg (p);
    pointer_cache_traits< pointer_type >::insert_guard ig (
      pointer_cache_traits< pointer_type >::insert (db, id, p));
    object_type& obj (pointer_traits< pointer_type >::get_ref (p));

    if (l.locked ())
    {
      callback (db, obj, callback_event::pre_load);
      init (obj, sts.image (), db);
      load_ (sts, obj);
      sts.load_delayed ();
      l.unlock ();
      callback (db, obj, callback_event::post_load);
    }
    else
      sts.delay_load (id, obj, ig.position ());

    ig.release ();
    pg.release ();
    return p;
  }

  bool access::object_traits< ::project >::
  find (database& db, const id_type& id, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, id))
      return false;

    reference_cache_traits< object_type >::insert_guard ig (
      reference_cache_traits< object_type >::insert (db, id, obj));

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    ig.release ();
    return true;
  }

  bool access::object_traits< ::project >::
  reload (database& db, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, obj.name_))
      return false;

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    return true;
  }

  bool access::object_traits< ::project >::
  find_ (mysql::object_statements< object_type >& sts, const id_type& id)
  {
    using namespace mysql;

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    select_statement& st (sts.find_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      if (grow (im, sts.select_image_truncated ()))
        im.version++;

      if (im.version != sts.select_image_version ())
      {
        bind (imb.bind, im, statement_select);
        sts.select_image_version (im.version);
        imb.version++;
        st.refetch ();
      }
    }

    st.free_result ();
    return r != select_statement::no_data;
  }

  void access::object_traits< ::project >::
  load_ (mysql::object_statements< object_type >& sts, object_type& obj)
  {
    mysql::binding& idb (sts.id_image_binding ());

    employees_traits::load (
      obj.employees_,
      idb,
      sts.container_statment_cache ().employees_);
  }

  result< access::object_traits< ::project >::object_type >
  access::object_traits< ::project >::
  query (database&, const query_base_type& q)
  {
    using namespace mysql;
    using odb::details::shared;
    using odb::details::shared_ptr;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    shared_ptr<select_statement> st (
      new (shared) select_statement (
        sts.connection (),
        query_statement + q.clause (),
        q.parameters_binding (),
        imb));

    st->execute ();

    shared_ptr< odb::object_result_impl<object_type> > r (
      new (shared) mysql::object_result_impl<object_type> (
        q, st, sts));

    return result<object_type> (r);
  }

  unsigned long long access::object_traits< ::project >::
  erase_query (database&, const query_base_type& q)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    delete_statement st (
      conn,
      erase_query_statement + q.clause (),
      q.parameters_binding ());

    return st.execute ();
  }

  // employee
  //

  const char query_columns_base< ::employee >::employer_alias_[] = "`employer`";

  const char query_columns_base< ::employee >::position_alias_[] = "`position`";

  // projects_
  //

  const char access::object_traits< ::employee >::projects_traits::select_all_statement[] =
  "SELECT "
  "`inverse_employee_projects`.`value`"
  " FROM `inverse_employee_projects` WHERE `inverse_employee_projects`.`object_id`=?";

  const char access::object_traits< ::employee >::projects_traits::insert_one_statement[] =
  "INSERT INTO `inverse_employee_projects` ("
  "`object_id`,"
  "`value`)"
  " VALUES (?,?)";

  const char access::object_traits< ::employee >::projects_traits::delete_all_statement[] =
  "DELETE FROM `inverse_employee_projects`"
  " WHERE `object_id`=?";

  void access::object_traits< ::employee >::projects_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        cond_image_type& c)
  {
    ODB_POTENTIALLY_UNUSED (c);

    std::size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;
  }

  void access::object_traits< ::employee >::projects_traits::
  bind (MYSQL_BIND* b,
        const MYSQL_BIND* id,
        std::size_t id_size,
        data_image_type& d)
  {
    using namespace mysql;

    statement_kind sk (statement_select);
    ODB_POTENTIALLY_UNUSED (sk);

    size_t n (0);

    // object_id
    //
    if (id != 0)
      std::memcpy (&b[n], id, id_size * sizeof (id[0]));
    n += id_size;

    // value
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = d.value_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      d.value_value.capacity ());
    b[n].length = &d.value_size;
    b[n].is_null = &d.value_null;
  }

  void access::object_traits< ::employee >::projects_traits::
  grow (data_image_type& i, my_bool* t)
  {
    bool grew (false);

    // value
    //
    if (t[0UL])
    {
      i.value_value.capacity (i.value_size);
      grew = true;
    }

    if (grew)
      i.version++;
  }

  void access::object_traits< ::employee >::projects_traits::
  init (data_image_type& i, const value_type& v)
  {
    using namespace mysql;

    statement_kind sk (statement_insert);
    ODB_POTENTIALLY_UNUSED (sk);

    bool grew (false);

    // value
    //
    {
      typedef object_traits< ::project > obj_traits;
      typedef pointer_traits< value_type > ptr_traits;

      bool is_null (ptr_traits::null_ptr (v));
      if (!is_null)
      {
        const obj_traits::id_type& id (
          ptr_traits::object_id< ptr_traits::element_type  > (v));

        std::size_t size (0);
        std::size_t cap (i.value_value.capacity ());
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_string >::set_image (
          i.value_value,
          size,
          is_null,
          id);
        i.value_size = static_cast<unsigned long> (size);
        grew = grew || (cap != i.value_value.capacity ());
      }
      else
        throw null_pointer ();
      i.value_null = is_null;
    }

    if (grew)
      i.version++;
  }

  void access::object_traits< ::employee >::projects_traits::
  init (value_type& v, const data_image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (db);

    // value
    //
    {
      typedef object_traits< ::project > obj_traits;
      typedef pointer_traits< value_type > ptr_traits;

      if (i.value_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_string >::set_value (
          id,
          i.value_value,
          i.value_size,
          i.value_null);

        v = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::employee >::projects_traits::
  insert_one (index_type, const value_type& v, void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    binding& b (sts.data_image_binding ());
    data_image_type& di (sts.data_image ());

    init (di, v);

    if (di.version != sts.data_image_version ())
    {
      bind (b.bind, 0, sts.id_binding ().count, di);
      sts.data_image_version (di.version);
      b.version++;
      sts.select_image_binding ().version++;
    }

    if (!sts.insert_one_statement ().execute ())
      throw object_already_persistent ();
  }

  bool access::object_traits< ::employee >::projects_traits::
  load_all (index_type&, value_type& v, void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    data_image_type& di (sts.data_image ());
    init (v, di, sts.connection ().database ());

    select_statement& st (sts.select_all_statement ());
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      grow (di, sts.data_image_truncated ());

      if (di.version != sts.data_image_version ())
      {
        binding& b (sts.data_image_binding ());
        bind (b.bind, 0, sts.id_binding ().count, di);
        sts.data_image_version (di.version);
        b.version++;
        sts.select_image_binding ().version++;
        st.refetch ();
      }
    }

    if (r == select_statement::no_data)
    {
      st.free_result ();
      return false;
    }

    return true;
  }

  void access::object_traits< ::employee >::projects_traits::
  delete_all (void* d)
  {
    using namespace mysql;

    statements_type& sts (*static_cast< statements_type* > (d));
    sts.delete_all_statement ().execute ();
  }

  void access::object_traits< ::employee >::projects_traits::
  persist (const container_type& c,
           const mysql::binding& id,
           statements_type& sts)
  {
    using namespace mysql;

    binding& b (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || b.version == 0)
    {
      bind (b.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      b.version++;
      sts.select_image_binding ().version++;
    }

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::persist (c, fs);
  }

  void access::object_traits< ::employee >::projects_traits::
  load (container_type& c,
        const mysql::binding& id,
        statements_type& sts)
  {
    using namespace mysql;

    binding& db (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || db.version == 0)
    {
      bind (db.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      db.version++;
      sts.select_image_binding ().version++;
    }

    binding& cb (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || cb.version == 0)
    {
      bind (cb.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      cb.version++;
    }

    select_statement& st (sts.select_all_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      data_image_type& di (sts.data_image ());
      grow (di, sts.data_image_truncated ());

      if (di.version != sts.data_image_version ())
      {
        bind (db.bind, 0, id.count, sts.data_image ());
        sts.data_image_version (di.version);
        db.version++;
        sts.select_image_binding ().version++;
        st.refetch ();
      }
    }

    bool more (r != select_statement::no_data);

    if (!more)
      st.free_result ();

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::load (c, more, fs);
  }

  void access::object_traits< ::employee >::projects_traits::
  update (const container_type& c,
          const mysql::binding& id,
          statements_type& sts)
  {
    using namespace mysql;

    binding& db (sts.data_image_binding ());
    if (id.version != sts.data_id_binding_version () || db.version == 0)
    {
      bind (db.bind, id.bind, id.count, sts.data_image ());
      sts.data_id_binding_version (id.version);
      db.version++;
      sts.select_image_binding ().version++;
    }

    binding& cb (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || cb.version == 0)
    {
      bind (cb.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      cb.version++;
    }

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::update (c, fs);
  }

  void access::object_traits< ::employee >::projects_traits::
  erase (const mysql::binding& id, statements_type& sts)
  {
    using namespace mysql;

    binding& b (sts.cond_image_binding ());
    if (id.version != sts.cond_id_binding_version () || b.version == 0)
    {
      bind (b.bind, id.bind, id.count, sts.cond_image ());
      sts.cond_id_binding_version (id.version);
      b.version++;
    }

    sts.id_binding (id);
    functions_type& fs (sts.functions ());
    fs.ordered (false);
    container_traits_type::erase (fs);
  }

  access::object_traits< ::employee >::id_type
  access::object_traits< ::employee >::
  id (const image_type& i)
  {
    id_type id;
    mysql::value_traits<
        long unsigned int,
        mysql::id_ulonglong >::set_value (
      id,
      i.id_value,
      i.id_null);

    return id;
  }

  bool access::object_traits< ::employee >::
  grow (image_type& i, my_bool* t)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (t);

    bool grew (false);

    // id_
    //
    t[0UL] = 0;

    // first_
    //
    if (t[1UL])
    {
      i.first_value.capacity (i.first_size);
      grew = true;
    }

    // last_
    //
    if (t[2UL])
    {
      i.last_value.capacity (i.last_size);
      grew = true;
    }

    // employer_
    //
    if (t[3UL])
    {
      i.employer_value.capacity (i.employer_size);
      grew = true;
    }

    // position_
    //
    t[4UL] = 0;

    return grew;
  }

  void access::object_traits< ::employee >::
  bind (MYSQL_BIND* b, image_type& i, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    std::size_t n (0);

    // id_
    //
    if (sk != statement_update)
    {
      b[n].buffer_type = MYSQL_TYPE_LONGLONG;
      b[n].is_unsigned = 1;
      b[n].buffer = &i.id_value;
      b[n].is_null = &i.id_null;
      n++;
    }

    // first_
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.first_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.first_value.capacity ());
    b[n].length = &i.first_size;
    b[n].is_null = &i.first_null;
    n++;

    // last_
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.last_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.last_value.capacity ());
    b[n].length = &i.last_size;
    b[n].is_null = &i.last_null;
    n++;

    // employer_
    //
    b[n].buffer_type = MYSQL_TYPE_STRING;
    b[n].buffer = i.employer_value.data ();
    b[n].buffer_length = static_cast<unsigned long> (
      i.employer_value.capacity ());
    b[n].length = &i.employer_size;
    b[n].is_null = &i.employer_null;
    n++;

    // position_
    //
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &i.position_value;
    b[n].is_null = &i.position_null;
    n++;
  }

  void access::object_traits< ::employee >::
  bind (MYSQL_BIND* b, id_image_type& i)
  {
    std::size_t n (0);
    b[n].buffer_type = MYSQL_TYPE_LONGLONG;
    b[n].is_unsigned = 1;
    b[n].buffer = &i.id_value;
    b[n].is_null = &i.id_null;
  }

  bool access::object_traits< ::employee >::
  init (image_type& i, const object_type& o, mysql::statement_kind sk)
  {
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (sk);

    using namespace mysql;

    bool grew (false);

    // id_
    //
    if (sk == statement_insert)
    {
      bool is_null;
      mysql::value_traits<
          long unsigned int,
          mysql::id_ulonglong >::set_image (
        i.id_value, is_null, o.id_);
      i.id_null = is_null;
    }

    // first_
    //
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.first_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.first_value,
        size,
        is_null,
        o.first_);
      i.first_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.first_value.capacity ());
      i.first_null = is_null;
    }

    // last_
    //
    {
      bool is_null;
      std::size_t size (0);
      std::size_t cap (i.last_value.capacity ());
      mysql::value_traits<
          ::std::string,
          mysql::id_string >::set_image (
        i.last_value,
        size,
        is_null,
        o.last_);
      i.last_size = static_cast<unsigned long> (size);
      grew = grew || (cap != i.last_value.capacity ());
      i.last_null = is_null;
    }

    // employer_
    //
    {
      typedef object_traits< ::employer > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_shared_ptr< ::employer > > ptr_traits;

      bool is_null (ptr_traits::null_ptr (o.employer_));
      if (!is_null)
      {
        const obj_traits::id_type& id (
          ptr_traits::object_id< ptr_traits::element_type  > (o.employer_));

        std::size_t size (0);
        std::size_t cap (i.employer_value.capacity ());
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_string >::set_image (
          i.employer_value,
          size,
          is_null,
          id);
        i.employer_size = static_cast<unsigned long> (size);
        grew = grew || (cap != i.employer_value.capacity ());
      }
      else
        throw null_pointer ();
      i.employer_null = is_null;
    }

    // position_
    //
    {
      typedef object_traits< ::position > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_shared_ptr< ::position > > ptr_traits;

      bool is_null (ptr_traits::null_ptr (o.position_));
      if (!is_null)
      {
        const obj_traits::id_type& id (
          ptr_traits::object_id< ptr_traits::element_type  > (o.position_));

        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_image (
          i.position_value, is_null, id);
      }
      else
        throw null_pointer ();
      i.position_null = is_null;
    }

    return grew;
  }

  void access::object_traits< ::employee >::
  init (object_type& o, const image_type& i, database& db)
  {
    ODB_POTENTIALLY_UNUSED (o);
    ODB_POTENTIALLY_UNUSED (i);
    ODB_POTENTIALLY_UNUSED (db);

    // id_
    //
    mysql::value_traits<
        long unsigned int,
        mysql::id_ulonglong >::set_value (
      o.id_,
      i.id_value,
      i.id_null);

    // first_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.first_,
      i.first_value,
      i.first_size,
      i.first_null);

    // last_
    //
    mysql::value_traits<
        ::std::string,
        mysql::id_string >::set_value (
      o.last_,
      i.last_value,
      i.last_size,
      i.last_null);

    // employer_
    //
    {
      typedef object_traits< ::employer > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_shared_ptr< ::employer > > ptr_traits;

      if (i.employer_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_string >::set_value (
          id,
          i.employer_value,
          i.employer_size,
          i.employer_null);

        o.employer_ = ptr_traits::pointer_type (db, id);
      }
    }

    // position_
    //
    {
      typedef object_traits< ::position > obj_traits;
      typedef pointer_traits< ::odb::tr1::lazy_shared_ptr< ::position > > ptr_traits;

      if (i.position_null)
        throw null_pointer ();
      else
      {
        obj_traits::id_type id;
        mysql::value_traits<
            obj_traits::id_type,
            mysql::id_ulonglong >::set_value (
          id,
          i.position_value,
          i.position_null);

        o.position_ = ptr_traits::pointer_type (db, id);
      }
    }
  }

  void access::object_traits< ::employee >::
  init (id_image_type& i, const id_type& id)
  {
    {
      bool is_null;
      mysql::value_traits<
          long unsigned int,
          mysql::id_ulonglong >::set_image (
        i.id_value, is_null, id);
      i.id_null = is_null;
    }
  }

  struct access::object_traits< ::employee >::container_statement_cache_type
  {
    mysql::container_statements_impl< projects_traits > projects_;

    container_statement_cache_type (mysql::connection& c)
    : projects_ (c)
    {
    }
  };

  const char access::object_traits< ::employee >::persist_statement[] =
  "INSERT INTO `inverse_employee` ("
  "`id`,"
  "`first`,"
  "`last`,"
  "`employer`,"
  "`position`)"
  " VALUES (?,?,?,?,?)";

  const char access::object_traits< ::employee >::find_statement[] =
  "SELECT "
  "`inverse_employee`.`id`,"
  "`inverse_employee`.`first`,"
  "`inverse_employee`.`last`,"
  "`inverse_employee`.`employer`,"
  "`inverse_employee`.`position`"
  " FROM `inverse_employee`"
  " WHERE `inverse_employee`.`id`=?";

  const char access::object_traits< ::employee >::update_statement[] =
  "UPDATE `inverse_employee` SET "
  "`first`=?,"
  "`last`=?,"
  "`employer`=?,"
  "`position`=?"
  " WHERE `id`=?";

  const char access::object_traits< ::employee >::erase_statement[] =
  "DELETE FROM `inverse_employee`"
  " WHERE `id`=?";

  const char access::object_traits< ::employee >::query_statement[] =
  "SELECT "
  "`inverse_employee`.`id`,"
  "`inverse_employee`.`first`,"
  "`inverse_employee`.`last`,"
  "`inverse_employee`.`employer`,"
  "`inverse_employee`.`position`"
  " FROM `inverse_employee`"
  " LEFT JOIN `inverse_employer` AS `employer` ON `employer`.`name` = `inverse_employee`.`employer`"
  " LEFT JOIN `inverse_position` AS `position` ON `position`.`id` = `inverse_employee`.`position`"
  " ";

  const char access::object_traits< ::employee >::erase_query_statement[] =
  "DELETE FROM `inverse_employee`"
  " ";

  const char access::object_traits< ::employee >::table_name[] =
  "`inverse_employee`";

  void access::object_traits< ::employee >::
  persist (database&, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    image_type& im (sts.image ());
    binding& imb (sts.insert_image_binding ());

    if (init (im, obj, statement_insert))
      im.version++;

    im.id_value = 0;

    if (im.version != sts.insert_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_insert);
      sts.insert_image_version (im.version);
      imb.version++;
    }

    insert_statement& st (sts.persist_statement ());
    if (!st.execute ())
      throw object_already_persistent ();

    obj.id_ = static_cast< id_type > (st.id ());

    id_image_type& i (sts.id_image ());
    init (i, obj.id_);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    projects_traits::persist (
      obj.projects_,
      idb,
      sts.container_statment_cache ().projects_);
  }

  void access::object_traits< ::employee >::
  update (database&, const object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, obj.id_);

    image_type& im (sts.image ());
    if (init (im, obj, statement_update))
      im.version++;

    bool u (false);
    binding& imb (sts.update_image_binding ());
    if (im.version != sts.update_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_update);
      sts.update_image_version (im.version);
      imb.version++;
      u = true;
    }

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.update_id_image_version () || idb.version == 0)
    {
      if (i.version != sts.id_image_version () || idb.version == 0)
      {
        bind (idb.bind, i);
        sts.id_image_version (i.version);
        idb.version++;
      }

      sts.update_id_image_version (i.version);

      if (!u)
        imb.version++;
    }

    if (sts.update_statement ().execute () == 0)
      throw object_not_persistent ();

    projects_traits::update (
      obj.projects_,
      idb,
      sts.container_statment_cache ().projects_);
  }

  void access::object_traits< ::employee >::
  erase (database&, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    projects_traits::erase (
      idb,
      sts.container_statment_cache ().projects_);

    if (sts.erase_statement ().execute () != 1)
      throw object_not_persistent ();
  }

  access::object_traits< ::employee >::pointer_type
  access::object_traits< ::employee >::
  find (database& db, const id_type& id)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());
    object_statements< object_type >::auto_lock l (sts);

    if (l.locked ())
    {
      if (!find_ (sts, id))
        return pointer_type ();
    }

    pointer_type p (
      access::object_factory< object_type, pointer_type  >::create ());
    pointer_traits< pointer_type >::guard pg (p);
    pointer_cache_traits< pointer_type >::insert_guard ig (
      pointer_cache_traits< pointer_type >::insert (db, id, p));
    object_type& obj (pointer_traits< pointer_type >::get_ref (p));

    if (l.locked ())
    {
      callback (db, obj, callback_event::pre_load);
      init (obj, sts.image (), db);
      load_ (sts, obj);
      sts.load_delayed ();
      l.unlock ();
      callback (db, obj, callback_event::post_load);
    }
    else
      sts.delay_load (id, obj, ig.position ());

    ig.release ();
    pg.release ();
    return p;
  }

  bool access::object_traits< ::employee >::
  find (database& db, const id_type& id, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, id))
      return false;

    reference_cache_traits< object_type >::insert_guard ig (
      reference_cache_traits< object_type >::insert (db, id, obj));

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    ig.release ();
    return true;
  }

  bool access::object_traits< ::employee >::
  reload (database& db, object_type& obj)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());
    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    object_statements< object_type >::auto_lock l (sts);

    if (!find_ (sts, obj.id_))
      return false;

    callback (db, obj, callback_event::pre_load);
    init (obj, sts.image (), db);
    load_ (sts, obj);
    sts.load_delayed ();
    l.unlock ();
    callback (db, obj, callback_event::post_load);
    return true;
  }

  bool access::object_traits< ::employee >::
  find_ (mysql::object_statements< object_type >& sts, const id_type& id)
  {
    using namespace mysql;

    id_image_type& i (sts.id_image ());
    init (i, id);

    binding& idb (sts.id_image_binding ());
    if (i.version != sts.id_image_version () || idb.version == 0)
    {
      bind (idb.bind, i);
      sts.id_image_version (i.version);
      idb.version++;
    }

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    select_statement& st (sts.find_statement ());
    st.execute ();
    select_statement::result r (st.fetch ());

    if (r == select_statement::truncated)
    {
      if (grow (im, sts.select_image_truncated ()))
        im.version++;

      if (im.version != sts.select_image_version ())
      {
        bind (imb.bind, im, statement_select);
        sts.select_image_version (im.version);
        imb.version++;
        st.refetch ();
      }
    }

    st.free_result ();
    return r != select_statement::no_data;
  }

  void access::object_traits< ::employee >::
  load_ (mysql::object_statements< object_type >& sts, object_type& obj)
  {
    mysql::binding& idb (sts.id_image_binding ());

    projects_traits::load (
      obj.projects_,
      idb,
      sts.container_statment_cache ().projects_);
  }

  result< access::object_traits< ::employee >::object_type >
  access::object_traits< ::employee >::
  query (database&, const query_base_type& q)
  {
    using namespace mysql;
    using odb::details::shared;
    using odb::details::shared_ptr;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    object_statements< object_type >& sts (
      conn.statement_cache ().find_object<object_type> ());

    image_type& im (sts.image ());
    binding& imb (sts.select_image_binding ());

    if (im.version != sts.select_image_version () || imb.version == 0)
    {
      bind (imb.bind, im, statement_select);
      sts.select_image_version (im.version);
      imb.version++;
    }

    shared_ptr<select_statement> st (
      new (shared) select_statement (
        sts.connection (),
        query_statement + q.clause (),
        q.parameters_binding (),
        imb));

    st->execute ();

    shared_ptr< odb::object_result_impl<object_type> > r (
      new (shared) mysql::object_result_impl<object_type> (
        q, st, sts));

    return result<object_type> (r);
  }

  unsigned long long access::object_traits< ::employee >::
  erase_query (database&, const query_base_type& q)
  {
    using namespace mysql;

    mysql::connection& conn (
      mysql::transaction::current ().connection ());

    delete_statement st (
      conn,
      erase_query_statement + q.clause (),
      q.parameters_binding ());

    return st.execute ();
  }
}

// Begin epilogue.
//
//
// End epilogue.

#include <odb/post.hxx>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: valid employee-odb.hxx
Type: application/octet-stream
Size: 29328 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20120313/2b1767cf/validemployee-odb-0002.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: valid employee-odb.ixx
Type: application/octet-stream
Size: 6034 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20120313/2b1767cf/validemployee-odb-0003.obj


More information about the odb-users mailing list