withExpression method

MssqlQuery withExpression(
  1. MssqlCte cte, {
  2. int? maxRecursion,
})

Prefixes the query with an expression already built.

Implementation

MssqlQuery withExpression(MssqlCte cte, {int? maxRecursion}) {
  if (maxRecursion != null && (maxRecursion < 0 || maxRecursion > 32767)) {
    throw ArgumentError.value(
      maxRecursion,
      'maxRecursion',
      'SQL Server accepts 0 to 32767, where 0 means no ceiling.',
    );
  }
  for (final existing in ctes) {
    if (existing.name.toLowerCase() == cte.name.toLowerCase()) {
      throw ArgumentError.value(
        cte.name,
        'cte',
        'The WITH clause already names an expression "${existing.name}". '
            'Two expressions of one name cannot both be referred to.',
      );
    }
  }
  return _with(ctes: <MssqlCte>[...ctes, cte], maxRecursion: maxRecursion);
}