Code example for Cursor

Methods: closegetColumnIndexgetStringmoveToFirst

0
	} 
 
	public void deleteScene(long id) throws IOException {
		Cursor cursor = getScene(id);
		String path = getString(cursor, SceneColumn.SCENE_DIRECTORY);
		cursor.close();
		if (new File(path).exists()) {
			Runtime.getRuntime().exec("rm -r " + path);
		} 
		db.delete(TABLE_SCENES, sceneIdClause(id), null);
	} 
	 
	public void deleteRecording(long id) throws IOException {
		Cursor cursor = getRecording(id);
		String path = getString(cursor, RecordingColumn.RECORDING_PATH);
		cursor.close();
		if (new File(path).exists()) {
			Runtime.getRuntime().exec("rm " + path);
		} 
		db.delete(TABLE_RECORDINGS, recordingIdClause(id), null);
	} 
 
	public Cursor getAllScenes() {
		return db.query(TABLE_SCENES, null, null, null, null, null, SceneColumn.SCENE_TITLE.label);
	} 
	 
	public Cursor getAllRecordings() {
		return db.query(TABLE_RECORDINGS, null, null, null, null, null, RecordingColumn.RECORDING_TIMESTAMP.label);
	} 
	 
	public Cursor getScene(long id) {
		Cursor cursor = db.query(TABLE_SCENES, null, sceneIdClause(id), null, null, null, null);
		cursor.moveToFirst();
		return cursor;
	} 
	 
	private String sceneIdClause(long id) {
		return SceneColumn.ID.label + " = " + id;
	} 
 
	public Cursor getRecording(long id) {
		Cursor cursor = db.query(TABLE_RECORDINGS, null, recordingIdClause(id), null, null, null, null);
		cursor.moveToFirst();
		return cursor;
	} 
	 
	private String recordingIdClause(long id) {
		return RecordingColumn.ID.label + " = " + id;
	} 
	 
	public void setRecordingDescription(long id, String description) {
		ContentValues values = new ContentValues();
		values.put(RecordingColumn.RECORDING_DESCRIPTION.label, description);
		db.update(TABLE_RECORDINGS, values, recordingIdClause(id), null);
	} 
 
	public static String getString(Cursor cursor, Column column) {
		return getString(cursor, column.getLabel());
	} 
	 
	public static String getString(Cursor cursor, String column) {
		return cursor.getString(cursor.getColumnIndex(column));
	} 
	 
	public static long getLong(Cursor cursor, Column column) {
		return getLong(cursor, column.getLabel());
	}