[odb-users] Sqlite and foreign key exception

Philipp Maluta ensoreus at mail.ru
Mon Nov 4 03:25:58 EST 2013


Hello, Boris.

I have some trouble with the subj - my app using sqlite and bidirectional relationships. 

class TagEntity;
class NoteEntity;

typedef std::vector<lazy_shared_ptr<TagEntity> > tags;
typedef std::vector<lazy_weak_ptr<NoteEntity> > notes;
…

#pragma db object
class NoteEntity
{
private:
    NoteEntity(){}
    friend class odb::access;

#pragma db id auto type("INTEGER")
    unsigned long _id;
...
#pragma db value_not_null unordered
    tags_type _tags;
};

#pragma db object
class TagEntity
{
…
private:
    TagEntity(){}
    friend class odb::access;
#pragma db id auto type("INTEGER")
    unsigned long _id;
...
#pragma db value_not_null inverse(_tags)
    notes_type _notes;
};


 So, I’m considered the foreign key bug and it’s workaround you suggests but it still not work. 
I’m using database.hxx from examples and even made some mark 
{
    connection_ptr c (db->connection ());
    qDebug() << "forein key ...";

    c->execute ("PRAGMA foreign_keys=OFF");

    transaction t (c->begin ());
    schema_catalog::create_schema (*db);
    t.commit ();

    c->execute ("PRAGMA foreign_keys=ON");
  }

But the output is 
./rpersistant --create --database notes.db
forein key ...
19: foreign key constraint failed

Would you like to provide some help, I found odb extremely cool and useful but the problem really gets me down. 
Thank you very much, Boris and your team.

Philipp


More information about the odb-users mailing list