Created
July 26, 2017 14:28
-
-
Save gruessung/8b2af656fe4ebe309123f056e5d57ee2 to your computer and use it in GitHub Desktop.
Android DatabaseHelper Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.gvisions.solardorf.service; | |
import android.content.Context; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.database.sqlite.SQLiteOpenHelper; | |
import android.util.Log; | |
public class DatabaseHelper extends SQLiteOpenHelper { | |
private Context context; | |
private final static String DB_NAME = "solardorfRss"; | |
private final static int DB_VERSION = 4; | |
public DatabaseHelper(Context context) { | |
super( | |
context, | |
DB_NAME, | |
null, | |
DB_VERSION | |
); | |
this.context=context; | |
Log.d("DB_DEBUG", "DB Helper start"); | |
} | |
@Override | |
public void onCreate(SQLiteDatabase db) { | |
Log.d("DB_DEBUG", "onCreate"); | |
db.execSQL("CREATE TABLE IF NOT EXISTS rss (id INTEGER PRIMARY KEY, title TEXT, text TEXT, date TEXT, author TEXT, link TEXT, picture TEXT);"); | |
} | |
@Override | |
public void onUpgrade(SQLiteDatabase db, int VOld, int VNew) { | |
Log.d("DB_DEBUG", String.valueOf(VNew)); | |
switch(VNew) | |
{ | |
case 3: | |
db.execSQL("ALTER TABLE rss ADD COLUMN picture TEXT;"); | |
break; | |
default: break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment