From 9bff9900d1445c72c16af1177521b569fd90c53f Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 20 May 2018 16:54:56 +0300 Subject: [PATCH] move enabling of foreign key support to onConfigure (#3038) This way we avoid repeating the code. Unlike getWritableDatabase, onConfigure is intended to be overridden. In fact, onConfigure documentation specifically says: "Called when the database connection is being configured, to enable features such as write-ahead logging or *foreign key support*." --- .../conversations/persistance/DatabaseBackend.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index aabf6f25a..3fd34d5ca 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -187,9 +187,13 @@ public class DatabaseBackend extends SQLiteOpenHelper { return instance; } + @Override + public void onConfigure(SQLiteDatabase db) { + db.execSQL("PRAGMA foreign_keys=ON"); + } + @Override public void onCreate(SQLiteDatabase db) { - db.execSQL("PRAGMA foreign_keys=ON;"); db.execSQL("create table " + Account.TABLENAME + "(" + Account.UUID + " TEXT PRIMARY KEY," + Account.USERNAME + " TEXT," + Account.SERVER + " TEXT," @@ -848,13 +852,6 @@ public class DatabaseBackend extends SQLiteOpenHelper { return rows == 1; } - @Override - public SQLiteDatabase getWritableDatabase() { - SQLiteDatabase db = super.getWritableDatabase(); - db.execSQL("PRAGMA foreign_keys=ON;"); - return db; - } - public boolean updateMessage(Message message, boolean includeBody) { SQLiteDatabase db = this.getWritableDatabase(); String[] args = {message.getUuid()};