// This file was generated by ODB, object-relational mapping (ORM) // compiler for C++. // #include #include "Agent-odb.hxx" #include #include // std::memcpy #include #include #include #include #include #include #include #include #include #include namespace odb { // Agent // struct access::object_traits_impl< ::models::Agent, id_sqlite >::extra_statement_cache_type { extra_statement_cache_type ( sqlite::connection&, image_type&, id_image_type&, sqlite::binding&, sqlite::binding&) { } }; access::object_traits_impl< ::models::Agent, id_sqlite >::id_type access::object_traits_impl< ::models::Agent, id_sqlite >:: id (const image_type& i) { sqlite::database* db (0); ODB_POTENTIALLY_UNUSED (db); id_type id; { sqlite::value_traits< ::std::string, sqlite::id_text >::set_value ( id, i.id_value, i.id_size, i.id_null); } return id; } bool access::object_traits_impl< ::models::Agent, id_sqlite >:: grow (image_type& i, bool* t) { ODB_POTENTIALLY_UNUSED (i); ODB_POTENTIALLY_UNUSED (t); bool grew (false); // id // if (t[0UL]) { i.id_value.capacity (i.id_size); grew = true; } // role // if (t[1UL]) { i.role_value.capacity (i.role_size); grew = true; } // persistent // t[2UL] = false; // displayName // if (t[3UL]) { i.displayName_value.capacity (i.displayName_size); grew = true; } return grew; } void access::object_traits_impl< ::models::Agent, id_sqlite >:: bind (sqlite::bind* b, image_type& i, sqlite::statement_kind sk) { ODB_POTENTIALLY_UNUSED (sk); using namespace sqlite; std::size_t n (0); // id // if (sk != statement_update) { b[n].type = sqlite::image_traits< ::std::string, sqlite::id_text>::bind_value; b[n].buffer = i.id_value.data (); b[n].size = &i.id_size; b[n].capacity = i.id_value.capacity (); b[n].is_null = &i.id_null; n++; } // role // b[n].type = sqlite::image_traits< ::std::string, sqlite::id_text>::bind_value; b[n].buffer = i.role_value.data (); b[n].size = &i.role_size; b[n].capacity = i.role_value.capacity (); b[n].is_null = &i.role_null; n++; // persistent // b[n].type = sqlite::bind::integer; b[n].buffer = &i.persistent_value; b[n].is_null = &i.persistent_null; n++; // displayName // b[n].type = sqlite::image_traits< ::std::string, sqlite::id_text>::bind_value; b[n].buffer = i.displayName_value.data (); b[n].size = &i.displayName_size; b[n].capacity = i.displayName_value.capacity (); b[n].is_null = &i.displayName_null; n++; } void access::object_traits_impl< ::models::Agent, id_sqlite >:: bind (sqlite::bind* b, id_image_type& i) { std::size_t n (0); b[n].type = sqlite::image_traits< ::std::string, sqlite::id_text>::bind_value; b[n].buffer = i.id_value.data (); b[n].size = &i.id_size; b[n].capacity = i.id_value.capacity (); b[n].is_null = &i.id_null; } bool access::object_traits_impl< ::models::Agent, id_sqlite >:: init (image_type& i, const object_type& o, sqlite::statement_kind sk) { ODB_POTENTIALLY_UNUSED (i); ODB_POTENTIALLY_UNUSED (o); ODB_POTENTIALLY_UNUSED (sk); using namespace sqlite; bool grew (false); // id // if (sk == statement_insert) { ::std::string const& v = o.id; bool is_null (false); std::size_t cap (i.id_value.capacity ()); sqlite::value_traits< ::std::string, sqlite::id_text >::set_image ( i.id_value, i.id_size, is_null, v); i.id_null = is_null; grew = grew || (cap != i.id_value.capacity ()); } // role // { ::std::string const& v = o.role; bool is_null (false); std::size_t cap (i.role_value.capacity ()); sqlite::value_traits< ::std::string, sqlite::id_text >::set_image ( i.role_value, i.role_size, is_null, v); i.role_null = is_null; grew = grew || (cap != i.role_value.capacity ()); } // persistent // { bool const& v = o.persistent; bool is_null (false); sqlite::value_traits< bool, sqlite::id_integer >::set_image ( i.persistent_value, is_null, v); i.persistent_null = is_null; } // displayName // { ::std::string const& v = o.displayName; bool is_null (false); std::size_t cap (i.displayName_value.capacity ()); sqlite::value_traits< ::std::string, sqlite::id_text >::set_image ( i.displayName_value, i.displayName_size, is_null, v); i.displayName_null = is_null; grew = grew || (cap != i.displayName_value.capacity ()); } return grew; } void access::object_traits_impl< ::models::Agent, id_sqlite >:: init (object_type& o, const image_type& i, database* db) { ODB_POTENTIALLY_UNUSED (o); ODB_POTENTIALLY_UNUSED (i); ODB_POTENTIALLY_UNUSED (db); // id // { ::std::string& v = o.id; sqlite::value_traits< ::std::string, sqlite::id_text >::set_value ( v, i.id_value, i.id_size, i.id_null); } // role // { ::std::string& v = o.role; sqlite::value_traits< ::std::string, sqlite::id_text >::set_value ( v, i.role_value, i.role_size, i.role_null); } // persistent // { bool& v = o.persistent; sqlite::value_traits< bool, sqlite::id_integer >::set_value ( v, i.persistent_value, i.persistent_null); } // displayName // { ::std::string& v = o.displayName; sqlite::value_traits< ::std::string, sqlite::id_text >::set_value ( v, i.displayName_value, i.displayName_size, i.displayName_null); } } void access::object_traits_impl< ::models::Agent, id_sqlite >:: init (id_image_type& i, const id_type& id) { bool grew (false); { bool is_null (false); std::size_t cap (i.id_value.capacity ()); sqlite::value_traits< ::std::string, sqlite::id_text >::set_image ( i.id_value, i.id_size, is_null, id); i.id_null = is_null; grew = grew || (cap != i.id_value.capacity ()); } if (grew) i.version++; } const char access::object_traits_impl< ::models::Agent, id_sqlite >::persist_statement[] = "INSERT INTO \"Agent\" " "(\"id\", " "\"role\", " "\"persistent\", " "\"displayName\") " "VALUES " "(?, ?, ?, ?)"; const char access::object_traits_impl< ::models::Agent, id_sqlite >::find_statement[] = "SELECT " "\"Agent\".\"id\", " "\"Agent\".\"role\", " "\"Agent\".\"persistent\", " "\"Agent\".\"displayName\" " "FROM \"Agent\" " "WHERE \"Agent\".\"id\"=?"; const char access::object_traits_impl< ::models::Agent, id_sqlite >::update_statement[] = "UPDATE \"Agent\" " "SET " "\"role\"=?, " "\"persistent\"=?, " "\"displayName\"=? " "WHERE \"id\"=?"; const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_statement[] = "DELETE FROM \"Agent\" " "WHERE \"id\"=?"; const char access::object_traits_impl< ::models::Agent, id_sqlite >::query_statement[] = "SELECT " "\"Agent\".\"id\", " "\"Agent\".\"role\", " "\"Agent\".\"persistent\", " "\"Agent\".\"displayName\" " "FROM \"Agent\""; const char access::object_traits_impl< ::models::Agent, id_sqlite >::erase_query_statement[] = "DELETE FROM \"Agent\""; const char access::object_traits_impl< ::models::Agent, id_sqlite >::table_name[] = "\"Agent\""; void access::object_traits_impl< ::models::Agent, id_sqlite >:: persist (database& db, const object_type& obj) { ODB_POTENTIALLY_UNUSED (db); using namespace sqlite; sqlite::connection& conn ( sqlite::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); callback (db, obj, callback_event::pre_persist); 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 (); callback (db, obj, callback_event::post_persist); } void access::object_traits_impl< ::models::Agent, id_sqlite >:: update (database& db, const object_type& obj) { ODB_POTENTIALLY_UNUSED (db); using namespace sqlite; using sqlite::update_statement; callback (db, obj, callback_event::pre_update); sqlite::transaction& tr (sqlite::transaction::current ()); sqlite::connection& conn (tr.connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); const id_type& id ( obj.id); id_image_type& idi (sts.id_image ()); init (idi, 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 (idi.version != sts.update_id_image_version () || idb.version == 0) { if (idi.version != sts.id_image_version () || idb.version == 0) { bind (idb.bind, idi); sts.id_image_version (idi.version); idb.version++; } sts.update_id_image_version (idi.version); if (!u) imb.version++; } update_statement& st (sts.update_statement ()); if (st.execute () == 0) throw object_not_persistent (); callback (db, obj, callback_event::post_update); pointer_cache_traits::update (db, obj); } void access::object_traits_impl< ::models::Agent, id_sqlite >:: erase (database& db, const id_type& id) { using namespace sqlite; ODB_POTENTIALLY_UNUSED (db); sqlite::connection& conn ( sqlite::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); 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 (); pointer_cache_traits::erase (db, id); } access::object_traits_impl< ::models::Agent, id_sqlite >::pointer_type access::object_traits_impl< ::models::Agent, id_sqlite >:: find (database& db, const id_type& id) { using namespace sqlite; { pointer_type p (pointer_cache_traits::find (db, id)); if (!pointer_traits::null_ptr (p)) return p; } sqlite::connection& conn ( sqlite::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); statements_type::auto_lock l (sts); if (l.locked ()) { if (!find_ (sts, &id)) return pointer_type (); } pointer_type p ( access::object_factory::create ()); pointer_traits::guard pg (p); pointer_cache_traits::insert_guard ig ( pointer_cache_traits::insert (db, id, p)); object_type& obj (pointer_traits::get_ref (p)); if (l.locked ()) { select_statement& st (sts.find_statement ()); ODB_POTENTIALLY_UNUSED (st); callback (db, obj, callback_event::pre_load); init (obj, sts.image (), &db); load_ (sts, obj, false); sts.load_delayed (0); l.unlock (); callback (db, obj, callback_event::post_load); pointer_cache_traits::load (ig.position ()); } else sts.delay_load (id, obj, ig.position ()); ig.release (); pg.release (); return p; } bool access::object_traits_impl< ::models::Agent, id_sqlite >:: find (database& db, const id_type& id, object_type& obj) { using namespace sqlite; sqlite::connection& conn ( sqlite::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); statements_type::auto_lock l (sts); if (!find_ (sts, &id)) return false; select_statement& st (sts.find_statement ()); ODB_POTENTIALLY_UNUSED (st); reference_cache_traits::position_type pos ( reference_cache_traits::insert (db, id, obj)); reference_cache_traits::insert_guard ig (pos); callback (db, obj, callback_event::pre_load); init (obj, sts.image (), &db); load_ (sts, obj, false); sts.load_delayed (0); l.unlock (); callback (db, obj, callback_event::post_load); reference_cache_traits::load (pos); ig.release (); return true; } bool access::object_traits_impl< ::models::Agent, id_sqlite >:: reload (database& db, object_type& obj) { using namespace sqlite; sqlite::connection& conn ( sqlite::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); statements_type::auto_lock l (sts); const id_type& id ( obj.id); if (!find_ (sts, &id)) return false; select_statement& st (sts.find_statement ()); ODB_POTENTIALLY_UNUSED (st); callback (db, obj, callback_event::pre_load); init (obj, sts.image (), &db); load_ (sts, obj, true); sts.load_delayed (0); l.unlock (); callback (db, obj, callback_event::post_load); return true; } bool access::object_traits_impl< ::models::Agent, id_sqlite >:: find_ (statements_type& sts, const id_type* id) { using namespace sqlite; 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 (); auto_result ar (st); 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 (); } } return r != select_statement::no_data; } result< access::object_traits_impl< ::models::Agent, id_sqlite >::object_type > access::object_traits_impl< ::models::Agent, id_sqlite >:: query (database&, const query_base_type& q) { using namespace sqlite; using odb::details::shared; using odb::details::shared_ptr; sqlite::connection& conn ( sqlite::transaction::current ().connection ()); statements_type& sts ( conn.statement_cache ().find_object ()); 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++; } std::string text (query_statement); if (!q.empty ()) { text += " "; text += q.clause (); } q.init_parameters (); shared_ptr st ( new (shared) select_statement ( conn, text, false, true, q.parameters_binding (), imb)); st->execute (); shared_ptr< odb::object_result_impl > r ( new (shared) sqlite::object_result_impl ( q, st, sts, 0)); return result (r); } unsigned long long access::object_traits_impl< ::models::Agent, id_sqlite >:: erase_query (database&, const query_base_type& q) { using namespace sqlite; sqlite::connection& conn ( sqlite::transaction::current ().connection ()); std::string text (erase_query_statement); if (!q.empty ()) { text += ' '; text += q.clause (); } q.init_parameters (); delete_statement st ( conn, text, q.parameters_binding ()); return st.execute (); } } #include