public HashMap<String, String> getGeneralInfo(long projectId, String date) { ActivityDataSource activityDataSource = new ActivityDataSource(context); List<ActivityStructure> activities = activityDataSource.getAllActivities(); SQLiteDatabase database = dbHelper.getReadableDatabase(); List<TaskStructure> tasks = null; HashMap<String, String> info = new HashMap<String, String>(); try { for (ActivityStructure activity : activities) { tasks = new ArrayList<TaskStructure>(); String whereSequence = ("project_id = " + projectId) + " and " + ("activity_id = " + activity.getId()) + " and " + ("date = date('" + date + "')"); 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(); info.put(activity.getName(), totalTime(tasks)); } return info; } finally { database.close(); } }
public int updateTask(String nameTask, String descriptionTask, int time, long taskId) { SQLiteDatabase database = dbHelper.getReadableDatabase(); try { ContentValues values = new ContentValues(); values.put(TaskStructure.COLUMN_NAME, nameTask); values.put(TaskStructure.COLUMN_DESCRIPTION, descriptionTask); values.put(TaskStructure.COLUMN_TIME, time); String whereClause = ("_id = " + taskId); return database.update(TaskStructure.TABLE_NAME, values, whereClause, null); } finally { database.close(); } }
public TaskStructure getTask(long taskId) { SQLiteDatabase database = dbHelper.getReadableDatabase(); try { Cursor cursor = database.query( TaskStructure.TABLE_NAME, allColumns, ("_id = " + taskId), null, null, null, null); cursor.moveToFirst(); TaskStructure task = cursorToTask(cursor); cursor.close(); return task; } finally { database.close(); } }
public boolean taskExists(String name, Session session) { SQLiteDatabase database = dbHelper.getReadableDatabase(); try { String whereSequence = ("name = '" + name + "'") + " and " + ("project_id = " + session.getProjectId()) + " and " + ("date = date('" + session.getDate(Session.RELEVANT) + "')"); Cursor cursor = database.query( TaskStructure.TABLE_NAME, allColumns, whereSequence, null, null, null, null); TaskStructure task = null; if (cursor.moveToFirst()) { task = cursorToTask(cursor); } return task != null; } finally { database.close(); } }