Code example for Cursor

Methods: closegetColumnIndexOrThrowgetCountgetLongmoveToFirst

0
			return -1; 
		} 
		 
		long result;
		// If there is an existing entry update it with the new key file 
		if ( cursor.getCount() > 0 ) {
			cursor.moveToFirst();
			long id = cursor.getLong(cursor.getColumnIndexOrThrow(KEY_FILE_ID));
			 
			ContentValues vals = new ContentValues();
			vals.put(KEY_FILE_KEYFILE, keyFile);
			vals.put(KEY_FILE_UPDATED, System.currentTimeMillis());
			 
			result = mDb.update(FILE_TABLE, vals, KEY_FILE_ID + " = " + id, null);
		 
		// Otherwise add the new entry 
		} else { 
			ContentValues vals = new ContentValues();
			vals.put(KEY_FILE_FILENAME, fileName);
			vals.put(KEY_FILE_KEYFILE, keyFile);
			vals.put(KEY_FILE_UPDATED, System.currentTimeMillis());
			 
			result = mDb.insert(FILE_TABLE, null, vals);
			 
		} 
		// Delete all but the last five records 
		try { 
			deleteAllBut(MAX_FILES);
		} catch (Exception e) {
			e.printStackTrace();
			assert(true); 
		} 
		 
		cursor.close();
		 
		return result;
		 
	}