Skip to content

Instantly share code, notes, and snippets.

@jezinka
Created March 11, 2017 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jezinka/a6327919fe207316f447b456739b577f to your computer and use it in GitHub Desktop.
Save jezinka/a6327919fe207316f447b456739b577f to your computer and use it in GitHub Desktop.
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