[odb-users] Sqlite and foreign key exception

Philipp Maluta ensoreus at mail.ru
Tue Nov 19 03:27:52 EST 2013


Wow, sorry, I missed up the 
 --default-pointer std::tr1::shared_ptr --table-prefix inverse_ $<
options in odd compiler's line
Now compiles fine. thx
Thank for your great work. 
Wish it become more and more popular hence its awesome.

19 нояб. 2013, в 09:21, Philipp Maluta <ensoreus at mail.ru> написал(а):

> Hello, Boris!
> Thank your for your attention, you are really helped me. 
> The bug was in the DB fulfilling.
> 
> So another trouble came up.
> I have a code like this 
> shared_ptr<TagEntity> tag1( new TagEntity("tag1", "common1") );
>     shared_ptr<TagEntity> tag2( new TagEntity("tag2", "common1") );
> 
>     shared_ptr<NoteEntity> note1( new NoteEntity("vis1", "text1", "acts1") );
>     shared_ptr<NoteEntity> note2( new NoteEntity("vis2", "text2", "acts2") );
> 
>     note1->get_tags().push_back(tag1);
>     note1->get_tags().push_back(tag2);
>     note2->get_tags().push_back(tag2);
> 
>     tag1->get_notes().push_back(note1);
>     tag2->get_notes().push_back(note1);
>     tag2->get_notes().push_back(note2);
> 
>    odb::transaction t( db->begin() );
> 
>    db->persist(tag1);
>    db->persist(tag2);
> 
>    db->persist(note1);
>    db->persist(note2);
> 
>    t.commit();
> 
> 
> But how do you think, what this error message means?
> /opt/local/include/odb/database.ixx:106:27: error: no viable conversion from 'const shared_ptr<NoteEntity>' to 'const object_pointer' (aka 'NoteEntity *const')
> const object_pointer& pobj (p);
> ^ ~
> /opt/local/include/odb/database.ixx:131:12: note: in instantiation of function template specialization 'odb::database::persist<NoteEntity, shared_ptr>' requested here
> return persist<T, P> (cr);
> ^
> ../rpersistant/main.cpp:51:9: note: in instantiation of function template specialization 'odb::database::persist<NoteEntity, shared_ptr>' requested here
> db->persist(note1);
> ^
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1/tr1/boost_shared_ptr.h:678:7: note: candidate function
> operator __unspecified_bool_type() const // never throws
> 
> 
> 8 нояб. 2013, в 09:22, Boris Kolpackov <boris at codesynthesis.com> написал(а):
> 
>> Hi Philipp,
>> 
>> Philipp Maluta <ensoreus at mail.ru> writes:
>> 
>>> I added a lines you provided and:
>>> ./rpersistant --create --database notes.db
>>> forein key ...
>>> schema created
>>> foreign keys enabled
>>> 19: foreign key constraint failed
>> 
>> Which confirms my suspicion: the exception is thrown by some other
>> code in your application.
>> 
>> Try to find out which transaction causes it (the exception will be
>> thrown from commit()). Then make sure all the objects that you
>> point to are actually made persistent. The common cause of the
>> foreign key exception is forgetting to call persist() for the
>> other end of the relationship (or calling it in incorrect order
>> if you use auto ids).
>> 
>> Boris
>> 
> 
> 



More information about the odb-users mailing list