[odb-users] Compile error with static multi DB and lazy_weak_ptr

Beni Urech benjamin.urech at bfh.ch
Thu Aug 13 03:02:35 EDT 2015


Hi there

We are currently moving a project from single DB to a static multi DB
setup. When we now add the multi DB parameters to the ODB compiler,
the resulting cxx files fail to compile in GCC. The problem seems to
be the the relations with odb::lazy_weak_ptr we use. When we replace
them with lazy_shared_ptr, the generated files compile. Is this a
limitation of ODB or did I miss something?

Compile error:
In file included from /usr/local/include/odb/lazy-ptr.hxx:14:0,
                 from example.h:16,
                 from example-odb-sqlite.hxx:16:
/usr/local/include/odb/traits.hxx: In instantiation of ‘struct
odb::object_traits_impl<Process, (odb::database_id)5u>’:
/usr/local/include/odb/database.ixx:753:54:   required from ‘typename
odb::object_traits<T>::pointer_type odb::database::find_(const
typename odb::object_traits<T>::id_type&) [with T = Process;
odb::database_id DB = (odb::database_id)5u; typename
odb::object_traits<T>::pointer_type = std::shared_ptr<Process>;
typename odb::object_traits<T>::id_type = unsigned int]’
/usr/local/include/odb/database.txx:239:37:   required from ‘typename
odb::object_traits<T>::pointer_type odb::database::load_(const
typename odb::object_traits<T>::id_type&) [with T = Process;
odb::database_id DB = (odb::database_id)5u; typename
odb::object_traits<T>::pointer_type = std::shared_ptr<Process>;
typename odb::object_traits<T>::id_type = unsigned int]’
/usr/local/include/odb/database.ixx:249:35:   required from ‘typename
odb::object_traits<T>::pointer_type odb::database::load(const typename
odb::object_traits<T>::id_type&) [with T = Process; typename
odb::object_traits<T>::pointer_type = std::shared_ptr<Process>;
typename odb::object_traits<T>::id_type = unsigned int]’
/usr/local/include/odb/lazy-ptr-impl.txx:31:54:   required from
‘static typename odb::object_traits<T>::pointer_type
odb::lazy_ptr_base::loader(odb::lazy_ptr_base::database_type&, const
typename odb::object_traits<T>::id_type&) [with T = Process; DB =
odb::database; typename odb::object_traits<T>::pointer_type =
std::shared_ptr<Process>; odb::lazy_ptr_base::database_type =
odb::database; typename odb::object_traits<T>::id_type = unsigned int]’
/usr/local/include/odb/lazy-ptr-impl.ixx:361:36:   required from ‘void
odb::lazy_ptr_impl<T>::reset_db(DB&) [with DB = odb::database; T =
Process]’
/usr/local/include/odb/lazy-ptr.ixx:1232:7:   required from
‘odb::lazy_shared_ptr<T>::lazy_shared_ptr(DB&, const
std::shared_ptr<Y>&) [with DB = odb::database; Y = Process; T = Process]’
/usr/local/include/odb/lazy-ptr.txx:127:43:   required from
‘odb::lazy_shared_ptr<T> odb::lazy_weak_ptr<T>::lock() const [with T =
Process]’
/usr/local/include/odb/lazy-pointer-traits.hxx:132:22:   required from
‘static odb::pointer_traits<odb::lazy_weak_ptr<T>
> ::strong_pointer_type odb::pointer_traits<odb::lazy_weak_ptr<T> 
> ::lock(const pointer_type&) [with T = Process;
odb::pointer_traits<odb::lazy_weak_ptr<T> >::strong_pointer_type =
odb::lazy_shared_ptr<Process>;
odb::pointer_traits<odb::lazy_weak_ptr<T> >::pointer_type =
odb::lazy_weak_ptr<Process>]’
example-odb-sqlite.cxx:1305:57:   required from here
/usr/local/include/odb/traits.hxx:177:10: error: invalid use of
incomplete type ‘class odb::access::object_traits_impl<Process,
(odb::database_id)5u>’
   struct object_traits_impl:
          ^
In file included from /usr/local/include/odb/core.hxx:17:0,
                 from example.h:15,
                 from example-odb-sqlite.hxx:16:
/usr/local/include/odb/forward.hxx:99:11: error: declaration of ‘class
odb::access::object_traits_impl<Process, (odb::database_id)5u>’
     class object_traits_impl;
           ^
In file included from /usr/local/include/odb/database.hxx:631:0,
                 from /usr/local/include/odb/lazy-ptr-impl.txx:5,
                 from /usr/local/include/odb/lazy-ptr-impl.hxx:186,
                 from /usr/local/include/odb/lazy-ptr.hxx:15,
                 from example.h:16,
                 from example-odb-sqlite.hxx:16:
/usr/local/include/odb/database.ixx: In instantiation of ‘typename
odb::object_traits<T>::pointer_type odb::database::find_(const
typename odb::object_traits<T>::id_type&) [with T = Process;
odb::database_id DB = (odb::database_id)5u; typename
odb::object_traits<T>::pointer_type = std::shared_ptr<Process>;
typename odb::object_traits<T>::id_type = unsigned int]’:
/usr/local/include/odb/database.txx:239:37:   required from ‘typename
odb::object_traits<T>::pointer_type odb::database::load_(const
typename odb::object_traits<T>::id_type&) [with T = Process;
odb::database_id DB = (odb::database_id)5u; typename
odb::object_traits<T>::pointer_type = std::shared_ptr<Process>;
typename odb::object_traits<T>::id_type = unsigned int]’
/usr/local/include/odb/database.ixx:249:35:   required from ‘typename
odb::object_traits<T>::pointer_type odb::database::load(const typename
odb::object_traits<T>::id_type&) [with T = Process; typename
odb::object_traits<T>::pointer_type = std::shared_ptr<Process>;
typename odb::object_traits<T>::id_type = unsigned int]’
/usr/local/include/odb/lazy-ptr-impl.txx:31:54:   required from
‘static typename odb::object_traits<T>::pointer_type
odb::lazy_ptr_base::loader(odb::lazy_ptr_base::database_type&, const
typename odb::object_traits<T>::id_type&) [with T = Process; DB =
odb::database; typename odb::object_traits<T>::pointer_type =
std::shared_ptr<Process>; odb::lazy_ptr_base::database_type =
odb::database; typename odb::object_traits<T>::id_type = unsigned int]’
/usr/local/include/odb/lazy-ptr-impl.ixx:361:36:   required from ‘void
odb::lazy_ptr_impl<T>::reset_db(DB&) [with DB = odb::database; T =
Process]’
/usr/local/include/odb/lazy-ptr.ixx:1232:7:   required from
‘odb::lazy_shared_ptr<T>::lazy_shared_ptr(DB&, const
std::shared_ptr<Y>&) [with DB = odb::database; Y = Process; T = Process]’
/usr/local/include/odb/lazy-ptr.txx:127:43:   required from
‘odb::lazy_shared_ptr<T> odb::lazy_weak_ptr<T>::lock() const [with T =
Process]’
/usr/local/include/odb/lazy-pointer-traits.hxx:132:22:   required from
‘static odb::pointer_traits<odb::lazy_weak_ptr<T>
> ::strong_pointer_type odb::pointer_traits<odb::lazy_weak_ptr<T> 
> ::lock(const pointer_type&) [with T = Process;
odb::pointer_traits<odb::lazy_weak_ptr<T> >::strong_pointer_type =
odb::lazy_shared_ptr<Process>;
odb::pointer_traits<odb::lazy_weak_ptr<T> >::pointer_type =
odb::lazy_weak_ptr<Process>]’
example-odb-sqlite.cxx:1305:57:   required from here
/usr/local/include/odb/database.ixx:753:54: error: ‘find’ is not a
member of ‘odb::object_traits_impl<Process, (odb::database_id)5u>’
     return object_traits_impl<T, DB>::find (*this, id);
                                                      ^

DB model file (example which fails)
#include <odb/core.hxx>
#include <odb/lazy-ptr.hxx>


using odb::lazy_shared_ptr;
using odb::lazy_weak_ptr;
using std::string;
using std::vector;

class Process;

class Heap;


#pragma db object
class Process {
public:

    Process()  { }

#pragma db id auto
    unsigned int id;

#pragma db type("VARCHAR(255)")
    string name;

};


#pragma db object
class Heap {
public:
    Heap()  { }

#pragma db id auto index
    unsigned int id;

#pragma db null index
    odb::lazy_weak_ptr<Process> process; // <-- does result in compile
error
//    odb::lazy_shared_ptr<Process> process; <-- this works

};


Thanks for you help
Beni



More information about the odb-users mailing list