[odb-users] problem dereferncing result pointer ...
Roberto Alejandro Espí Muñoz
teratux at gmail.com
Thu Oct 6 17:17:26 EDT 2016
Hi ... I wrote a simple program that connects to a PGSQL database and
persists and executes a query later on, following up on the provided
examples.
The part where I persist works perfectly:
boost::shared_ptr< Guest > g ( new Guest() );
boost::shared_ptr< Hotel > l ( new Hotel() );
boost::shared_ptr< Room > r ( new Room() );
l->Rooms_.push_back ( r );
boost::shared_ptr< Stay > s1 ( new Stay );
s1->Guests_.push_back ( g );
s1->Rooms_.push_back ( r );
g->Stay_ = s1;
r->Stay_ = s1;
r->Location_ = l;
{
odb::transaction t ( Central::getInstance()->getDB()->begin() );
Central::getInstance()->getDB()->persist ( l );
Central::getInstance()->getDB()->persist ( s1 );
Central::getInstance()->getDB()->persist ( g );
Central::getInstance()->getDB()->persist ( r );
t.commit();
}
Up to here everything perfect.
When I execute a query I experience an interesting behaviour:
typedef odb::query< Location > query;
typedef odb::result< Location > result;
{
odb::transaction t ( Central::getInstance()->getDB()->begin() );
result r = Central::getInstance()->getDB()->query< Location > ();
if ( !r.empty() )
{
for ( auto i ( r.begin() ); i != r.end(); ++i )
{
std::cout << "ID " << i.id() << std::endl;
//(*i);
}
}
t.commit();
}
Notice the //(*i) part? If I run it with that line commented, I get a
correct std::cout with the id of the results, if I uncomment it then
my programs hangs in that line and later crashes.
I don't think there's a problem with my entities since I managed to
persist them ok.
Any advice?, thanks in advance
--
teratux
------------
More information about the odb-users
mailing list