Skip to content

Instantly share code, notes, and snippets.

@wirasetiawan29
Created January 5, 2016 13:58
Show Gist options
  • Save wirasetiawan29/6a865c7d59e175d6e4df to your computer and use it in GitHub Desktop.
Save wirasetiawan29/6a865c7d59e175d6e4df to your computer and use it in GitHub Desktop.
/**
* Created by wira on 1/4/16.
*/
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class TaskDBHelper extends SQLiteOpenHelper {
public TaskDBHelper(Context context) {
super(context, TaskContract.DB_NAME, null, TaskContract.DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase sqlDB) {
String sqlQuery =
String.format("CREATE TABLE %s (" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
"%s TEXT)", TaskContract.TABLE,
TaskContract.Columns.TASK);
Log.d("TaskDBHelper","Query to form table: "+sqlQuery);
sqlDB.execSQL(sqlQuery);
}
@Override
public void onUpgrade(SQLiteDatabase sqlDB, int i, int i2) {
sqlDB.execSQL("DROP TABLE IF EXISTS "+TaskContract.TABLE);
onCreate(sqlDB);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment