From 4a183889228b19c9f9f98038d7a5526a02cd1742 Mon Sep 17 00:00:00 2001 From: peet Date: Wed, 7 Oct 2020 19:56:54 +0200 Subject: [PATCH] Expanded DataBase Integration --- .../wdg/vokabel_trainer/DataBaseHelper.java | 3 ++- .../git/wdg/vokabel_trainer/DataHandler.java | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataBaseHelper.java b/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataBaseHelper.java index d895489..5009d51 100644 --- a/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataBaseHelper.java +++ b/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataBaseHelper.java @@ -7,13 +7,14 @@ import android.database.sqlite.SQLiteOpenHelper; import androidx.annotation.Nullable; public class DataBaseHelper extends SQLiteOpenHelper { + public DataBaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) { super(context, name, factory, version); } @Override public void onCreate(SQLiteDatabase db) { - db.execSQL(""); + db.execSQL("create table if not exists vocTable(deutsch text not null , englisch text not null);"); } @Override diff --git a/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataHandler.java b/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataHandler.java index 341323a..4874739 100644 --- a/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataHandler.java +++ b/app/src/main/java/org/ddnss/sfs/git/wdg/vokabel_trainer/DataHandler.java @@ -1,6 +1,7 @@ package org.ddnss.sfs.git.wdg.vokabel_trainer; import android.content.Context; +import android.database.sqlite.SQLiteDatabase; public class DataHandler { public static final String DATABASENAME = "vocabDB"; @@ -9,7 +10,29 @@ public class DataHandler { public static final String TABLE_NAME = "vocabTable"; public static final String DEUTSCH = "deutsch"; public static final String ENGLISH = "english"; - public DataHandler(Context ctx){ + private Context ctx; + private DataBaseHelper dbHelper; + private SQLiteDatabase db; + + public DataHandler(Context ctx){ + this.ctx = ctx; + dbHelper = new DataBaseHelper(ctx,DATABASENAME,null,DATABASE_VERSION); + } + + public void openWrite(){ + db = dbHelper.getWritableDatabase(); + } + + public void openRead(){ + db = dbHelper.getReadableDatabase(); + } + + public void close(){ + dbHelper.close(); + } + + public void addEntry(String voc1, String voc2){ + db.execSQL("insert into vocabTable (deutsch, english) values ('vocab1', 'vocab2')"); } }