コード例 #1
0
  public TaskStructure createTask(
      String name, String description, String date, int time, long activityId, long projectId) {
    SQLiteDatabase database = dbHelper.getWritableDatabase();
    try {
      ContentValues values = new ContentValues();

      values.put(TaskStructure.COLUMN_NAME, name);
      values.put(TaskStructure.COLUMN_DESCRIPTION, description);
      values.put(TaskStructure.COLUMN_DATE, date);
      values.put(TaskStructure.COLUMN_TIME, time);
      values.put(TaskStructure.ACTIVITY_ID, activityId);
      values.put(TaskStructure.PROJECT_ID, projectId);
      long insertId = database.insert(TaskStructure.TABLE_NAME, null, values);
      Cursor cursor =
          database.query(
              TaskStructure.TABLE_NAME,
              allColumns,
              TaskStructure.COLUMN_ID + " = " + insertId,
              null,
              null,
              null,
              null);
      cursor.moveToFirst();
      TaskStructure task = cursorToTask(cursor);
      return task;
    } finally {
      database.close();
    }
  }
コード例 #2
0
 public void deleteTask(long id) {
   SQLiteDatabase database = dbHelper.getWritableDatabase();
   try {
     database.delete(TaskStructure.TABLE_NAME, TaskStructure.COLUMN_ID + " = " + id, null);
   } finally {
     database.close();
   }
 }
コード例 #3
0
 public void deleteTasks(long projectId) {
   SQLiteDatabase database = dbHelper.getWritableDatabase();
   try {
     int status = database.delete(TaskStructure.TABLE_NAME, "project_id = " + projectId, null);
     if (status != 1) {
       Log.e(ProjectStructure.class.getName(), "Can`t delete tasks for project id: " + projectId);
     }
   } finally {
     database.close();
   }
 }
コード例 #4
0
  public List<TaskStructure> getAllTasks(long projectId, String date) {
    SQLiteDatabase database = dbHelper.getWritableDatabase();
    List<TaskStructure> tasks = null;

    String whereSequence =
        ("project_id = " + projectId) + " and " + ("date = date('" + date + "')");
    try {
      tasks = new ArrayList<TaskStructure>();
      Cursor cursor =
          database.query(
              TaskStructure.TABLE_NAME, allColumns, whereSequence, null, null, null, null);
      cursor.moveToFirst();
      while (!cursor.isAfterLast()) {
        TaskStructure task = cursorToTask(cursor);
        tasks.add(task);
        cursor.moveToNext();
      }
      cursor.close();
    } finally {
      database.close();
    }
    return tasks;
  }