Skip to content

Instantly share code, notes, and snippets.

@simoales
Created September 27, 2016 20:27
Show Gist options
  • Save simoales/99c48a689fd80def883ee86ab20faedd to your computer and use it in GitHub Desktop.
Save simoales/99c48a689fd80def883ee86ab20faedd to your computer and use it in GitHub Desktop.
private long createToDo() {
helper = new DatabaseHelper(this);
db = helper.getWritableDatabase();
//rawQuery
/*String query = "INSERT INTO todos ("
+ TodosEntry.COLUMN_TEXT + ","
+ TodosEntry.COLUMN_CATEGORY + ","
+ TodosEntry.COLUMN_CREATED + ","
+ TodosEntry.COLUMN_EXPIRED + ","
+ TodosEntry.COLUMN_DONE + ")"
+ " VALUES (\"Go to the gym\", 1, \"2016-01-01\", \"\", 0)";
db.execSQL(query);*/
//Insert method; returns the todo ID
ContentValues values = new ContentValues();
values.put(TodosEntry.COLUMN_TEXT, "Call Mr Bean");
values.put(TodosEntry.COLUMN_CATEGORY, 1);
values.put(TodosEntry.COLUMN_CREATED, "2016-01-02");
values.put(TodosEntry.COLUMN_DONE, 0);
// insert row
long todo_id = db.insert(TodosEntry.TABLE_NAME, null, values);
return todo_id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment