aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-21 20:59:43 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-21 20:59:43 +0200
commit18bdee2363a1f7d605c150059019a5133affc57d (patch)
tree327723468f4da84fde9c701a2e89ed41f48c37fb /src/main/java/de/pixart
parent8ac9f957dea8f12cafc8c9d532e4541df691dbb3 (diff)
move enabling of foreign key support to onConfigure
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*."
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
index c5d6b398b..c8ecf2f6b 100644
--- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java
@@ -185,8 +185,12 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
@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,"
@@ -861,13 +865,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()};