Skip to content

Instantly share code, notes, and snippets.

@vuhung3990
Created September 6, 2014 07:54
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 vuhung3990/51f6d50a05ff408f2f5e to your computer and use it in GitHub Desktop.
Save vuhung3990/51f6d50a05ff408f2f5e to your computer and use it in GitHub Desktop.
public class DatabaseHelper {
private Context context;
private SqliteHelper sqlite;
private String TB_NAME;
private String TB_STRUCT;
public DatabaseHelper(Context context, String DbName, String TB_NAME, String TB_STRUCT) {
this.context = context;
this.TB_NAME = TB_NAME;
this.TB_STRUCT = TB_STRUCT;
sqlite = new SqliteHelper(context, DbName, null, StaticVar.DB_VERSION,
this.TB_NAME, this.TB_STRUCT);
}
public void insert() {
// TODO:
}
public void update() {
// TODO:
}
public void delete() {
// TODO:
}
public SQLiteDatabase getSqliteDb() {
return sqlite.getWritableDatabase();
}
private class SqliteHelper extends SQLiteOpenHelper {
private String TB_NAME;
private String TB_STRUCT;
public SqliteHelper(Context context, String name,
CursorFactory factory, int version, String TB_NAME,
String TB_STRUCT) {
super(context, name, factory, version);
this.TB_NAME = TB_NAME;
this.TB_STRUCT = TB_STRUCT;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TB_NAME + " (" + TB_STRUCT + ")");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TB_NAME);
onCreate(db);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment