Книга: Beginning Android
delete()
delete()
Like update()
, delete()
receives a
Uri representing the instance or collection to work with and a WHERE
clause and parameters. If the activity is deleting a single instance, the Uri
should represent that instance and the WHERE
clause may be null. But the activity might be requesting to delete an open-ended set of instances, using the WHERE clause to constrain which ones to delete.
As with update()
, though, this is simple if you are using SQLite for database storage (sense a theme?). You can let it handle the idiosyncrasies of parsing and applying the WHERE
clause — all you have to do is call delete()
on the database.
For example, here is delete()
from Provider
:
@Override
public int delete(Uri url, String where, String[] whereArgs) {
int count;
long rowId = 0;
if (isCollectionUri(url)) {
count = db.delete(getTableName(), where, whereArgs);
} else {
String segment = url.getPathSegments().get(1);
rowId = Long.parseLong(segment);
count = db.delete(getTableName(), getIdColumnName() + "="
+ segment + (!TextUtils.isEmpty(where) ? " AND (" + where + ')' : ""),
whereArgs);
}
getContext().getContentResolver().notifyChange(url, null);
return count;
}
This is almost a clone of the update()
implementation described earlier in this chapter — either delete a subset of the entire collection or delete a single instance (if it also satisfies the supplied WHERE
clause).
- 14.4.6. Удаление вершины дерева и удаление дерева: tdelete() и tdestroy()
- Метод RegDelete
- Методы DeleteFile и DeleteFolder
- Метод Delete
- 11.7. Отправка запросов HTTP DELETE с применением NSURLConnection
- delete - Удаление объекта, элемента массива или переменной
- 4.13.3. Оператор delete
- Оператор DELETE
- 2.3 Marking Text to Delete, Move, or Copy
- Совет 7. При использовании контейнеров указателей, для которых вызывался оператор new, не забудьте вызвать delete для ук...
- Установка свойства DeleteCommand
- Права