pheromix
pheromix

Reputation: 19347

How to enable programatically sqlite foreign key support?

In the documentation of sqlite this syntax PRAGMA foreign_keys = ON; enables foreign key support. What is the code in Android ?

Upvotes: 1

Views: 154

Answers (1)

azertiti
azertiti

Reputation: 3150

You can override onOpen in your class that extends SQLiteOpenHelper like this:

@Override
public void onOpen(SQLiteDatabase db) {
    super.onOpen(db);
    if (!db.isReadOnly()) {     
        db.execSQL("PRAGMA foreign_keys=ON;");
    }
}

Upvotes: 3

Related Questions