I am really struggling with using the SqlLite in my App;
I have set up a database helper class that extends from SQLiteOpenHelper
public class DatabaseHelper extends SQLiteOpenHelper {
In the OnCreate I am Creating about 6 tables:
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE myTestTable (Id INTEGER PRIMARY KEY , "
+ "info TEXT," +
+ "TopLeft TEXT")); <-- example insert
}
When my App starts I am parsing some xml and entering the data into the table, and I have checked the database and all is in there and my tables created correctly.
When I go to call the data it is gone!
I have lots of different queries within my dbhelper class and on each activity I;m re initilizing the class so I can get at my function within the class.
I assume this is not the way to do it as it runs my oncreate again and wipes all my tables (or at least this is when it appears to be doing as I check the DB after I’ve tried calling data from it and it’s empty!
I was under the impression the oncreate only ran once, but this is obviously not the case as it appears to be recreating my DB everytime and wiping my data!
Where are you meant to initialize the the dbhelper class and how do you stop it recreating the tables? I need the data to persist even when the app closes!
I’m confused!
If this doesn’t make sense please ask specific questions on how I can clarify it!
UPDATE
I have found I can add
CREATE TABLE IF NOT EXISTS
Which stops it recreating the tables, but it still doesn’t seem right calling the oncreate every time..
You could put a wrapper class around it?