updateCell method
Perbarui nilai satu sel. Implementasi spesifik per engine.
Implementation
@override
Future<void> updateCell(
String collection,
String column,
Object? newValue,
Map<String, dynamic> row,
) async {
if (column == '_rowid_') {
throw UnsupportedError('Cannot edit internal rowid column.');
}
final pkCols = await _pkColumns(collection);
late final String where;
late final List<Object?> whereArgs;
if (pkCols.isNotEmpty) {
where = pkCols.map((c) => '$c = ?').join(' AND ');
whereArgs = pkCols.map((c) => row[c]).toList();
} else if (row.containsKey('_rowid_')) {
final rowid = row['_rowid_'];
if (rowid == null) {
throw StateError(
'Cannot update row: no primary key and _rowid_ is null',
);
}
where = 'rowid = ?';
whereArgs = [rowid];
} else {
final cols = row.keys.where((k) => k != '_rowid_').toList();
if (cols.isEmpty) {
throw StateError(
'Cannot update row: no primary key and no _rowid_ available',
);
}
where = cols.map((c) => '$c = ?').join(' AND ');
whereArgs = cols.map((c) => row[c]).toList();
}
await _database.rawUpdate(
'UPDATE $collection SET $column = ? WHERE $where',
[newValue, ...whereArgs],
);
}