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*."
This commit is contained in:
Alexander 2018-05-20 16:54:56 +03:00 committed by Daniel Gultsch
parent e948d12085
commit 9bff9900d1
1 changed files with 5 additions and 8 deletions

View File

@ -187,9 +187,13 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return instance; return instance;
} }
@Override
public void onConfigure(SQLiteDatabase db) {
db.execSQL("PRAGMA foreign_keys=ON");
}
@Override @Override
public void onCreate(SQLiteDatabase db) { public void onCreate(SQLiteDatabase db) {
db.execSQL("PRAGMA foreign_keys=ON;");
db.execSQL("create table " + Account.TABLENAME + "(" + Account.UUID + " TEXT PRIMARY KEY," db.execSQL("create table " + Account.TABLENAME + "(" + Account.UUID + " TEXT PRIMARY KEY,"
+ Account.USERNAME + " TEXT," + Account.USERNAME + " TEXT,"
+ Account.SERVER + " TEXT," + Account.SERVER + " TEXT,"
@ -848,13 +852,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return rows == 1; 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) { public boolean updateMessage(Message message, boolean includeBody) {
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
String[] args = {message.getUuid()}; String[] args = {message.getUuid()};