updateWhere method

Future<MssqlWriteOutcome> updateWhere({
  1. required MssqlWriteAssignments values,
  2. required List<MssqlCondition> where,
  3. required String operation,
  4. bool allRows = false,
  5. List<MssqlCondition> scopes = const <MssqlCondition>[],
  6. bool readRows = false,
})

Writes values to every row matching where.

operation names the caller's method in any error, so a refused write says update on dbo.Orders rather than UPDATE on [dbo].[Orders].

Implementation

Future<MssqlWriteOutcome> updateWhere({
  required MssqlWriteAssignments values,
  required List<MssqlCondition> where,
  required String operation,
  bool allRows = false,
  List<MssqlCondition> scopes = const <MssqlCondition>[],
  bool readRows = false,
}) {
  if (values.isEmpty) {
    throw ArgumentError.value(
      values,
      'values',
      '$operation on ${binding.qualifiedName} would write no columns.',
    );
  }
  _requirePredicate(where, allRows, operation);
  var update = MssqlUpdate.tableParts(
    binding.nameParts,
  ).set(values.toOperands());
  for (final condition in <MssqlCondition>[...where, ...scopes]) {
    update = update.where(condition);
  }
  if (where.isEmpty && scopes.isEmpty) update = update.allRows();
  return _runTargeted(
    operation: operation,
    readRows: readRows,
    source: MssqlOutputSource.inserted,
    compile: (clause) => (clause == null ? update : update.returning(clause))
        .compile(dialect: dialect),
  );
}