update method
Updates an existing JSON value identified by the id with a new value.
If a row is affected by update, then this method also synchronizes the
corresponding FTS indexes and returns true.
Implementation
@protected
bool update(SqlId id, Object value) {
Kind? kind;
int rowid;
bool sameKind;
if (id.hasRowId) {
var rows = _updateByRowId!.select([jsonToString(value), id.rowid]);
if (!updated() || rows.length != 1) ////
return false;
kind = rows.first.columnAt(0) as Kind?;
rowid = id.rowid;
sameKind = rows.first.columnAt(1) == 1;
} else {
checkState(id.hasKeyId);
var rows = _updateByKeyId!.select([jsonToString(value), id.keyid]);
if (!updated() || rows.length != 1) ////
return false;
kind = rows.first.columnAt(0) as Kind?;
rowid = rows.first.columnAt(1) as int;
sameKind = rows.first.columnAt(2) == 1;
}
if (!sameKind)
throw JsonSqliteException(
"SQLite.update: the kind of an existing row cannot be changed "
"(id $id, old kind \"$kind\")",
);
if (_searchRowsUpdatersMap[kind] case var updaters?)
for (var entry in updaters.toIterable()) {
SearchRow searchRow = callSRG(entry.rowGetter, value);
entry.indexUpdater.update.executeWith(
StatementParameters.named({
...entry.indexUpdater.index.searchRowToParameters(searchRow),
":$columnRowId": rowid,
}),
);
if (!updated())
throw JsonSqliteException(
"SQLite.update: failed for rowid $rowid, kind \"$kind\","
" search index \"${entry.indexUpdater.index.name}\"",
);
}
return true;
}