compile method

MssqlStatement compile({
  1. MssqlDialect dialect = MssqlDialect.sql2012,
})

Implementation

MssqlStatement compile({MssqlDialect dialect = MssqlDialect.sql2012}) {
  if (assignments.isEmpty) {
    throw StateError(
      'UPDATE ${source.quoted} sets no columns. Call set() first.',
    );
  }
  _checkPredicate(
    conditions: conditions,
    all: all,
    operation: 'UPDATE',
    target: source.quoted,
  );
  final parameters = MssqlParameterAllocator();
  final sets = <String>[];
  for (final entry in assignments.entries) {
    sets.add(
      '${Col(entry.key).compile(parameters, dialect)} = '
      '${_operandSql(entry.value, parameters, dialect)}',
    );
  }
  final out = StringBuffer('UPDATE ${source.quoted} SET ${sets.join(', ')}');
  // OUTPUT comes after SET and before WHERE, which is also the order the
  // allocator numbers the parameters in.
  if (output != null) out.write(' ${output!.sql}');
  if (conditions.isNotEmpty) {
    out.write(' WHERE ${and(conditions).compile(parameters, dialect)}');
  }
  return MssqlStatement.fromAllocator(out.toString(), parameters);
}