Expanded DataBase Integration

This commit is contained in:
peet 2020-10-07 19:56:54 +02:00
parent 1dad828f67
commit 4a18388922
2 changed files with 26 additions and 2 deletions

View File

@ -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

View File

@ -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')");
}
}