-
-
Save jezinka/a6327919fe207316f447b456739b577f to your computer and use it in GitHub Desktop.
base methods
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
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