Question

I tried to use the code below to ensure referential integrity in my database, but seems not to be working with GreenDao. I can still delete all the records. On the other hand, when I try to delete in Sqlitemanager, the trigger is raised and delete operation fails.

DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, Common.DBNAME, null)
{

    @Override
    public void onCreate(SQLiteDatabase db) {

    super.onCreate(db);

    db.execSQL("CREATE TRIGGER grupe_artikli BEFORE DELETE ON groups "+
        "FOR EACH ROW BEGIN "+
        "SELECT CASE " +
        "WHEN ((SELECT id_group FROM products WHERE id_group = OLD._id) IS NOT NULL) "+
        "THEN RAISE(ABORT, 'error') "+
        "END; END;");

    DaoSession session = new DaoMaster(db).newSession();
}

Does GreenDao support triggers, or is there another method to maintain database referential integrity?

Was it helpful?

Solution

greenDAO has no built-in trigger support. However, I cannot think of any reason why your approach should not work. greenDAO does not hijack the database or something, so you should be able to work directly with the database just like you wouldn't use greenDAO at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top