Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created Mar 11, 2017
Embed
What would you like to do?
base methods
public class CoNaObiadDbHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 2;
public static final String DATABASE_NAME = "CoNaObiad.db";
public static final String TABLE_NAME = "meal";
public static final String COLUMN_NAME_NAME = "name";
public static final String COLUMN_NAME_ID = "_id";
private static final String SQL_CREATE_ENTRIES =
"CREATE TABLE " + TABLE_NAME + " (" +
COLUMN_NAME_ID + " INTEGER PRIMARY KEY," +
COLUMN_NAME_NAME + " TEXT)";
private static final String SQL_DROP_TABLE = "DROP TABLE IF EXISTS " + TABLE_NAME;
private static final String SQL_DELETE_ENTRIES = "DELETE FROM " + TABLE_NAME;
public CoNaObiadDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(SQL_DROP_TABLE);
onCreate(db);
}
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(SQL_DROP_TABLE);
onCreate(db);
}
public void cleanData() {
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL(SQL_DELETE_ENTRIES);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment