MssqlTypedCte class

A common table expression whose exposed fields are declared, and whose members are checked against them before any SQL is written.

MssqlCte is the clause: a name, a query, and a list of column names it takes at face value. This is the description of what comes out of it, and it is what makes the difference between a mistake found here and error 8158 — "has more columns than were specified in the column list" — arriving from the server with nothing but the expression's name attached. The recursive case is where that matters most, since a recursive member is written separately from its anchor and has to agree with it position by position.

Types are compared by family rather than exactly. Depth + 1 widens an int and SQL Server reconciles that happily; what it cannot reconcile is one member projecting text where the other projects a number, and that is what a family comparison catches without refusing the queries that work.

Annotations
  • @immutable

Constructors

MssqlTypedCte({required String name, required Iterable<MssqlCteField> fields, required MssqlSelectQuery query})
A plain expression: one query, named fields.
factory
MssqlTypedCte.recursive({required String name, required Iterable<MssqlCteField> fields, required MssqlSelectQuery anchor, required MssqlSelectQuery recursiveMember, int? maxRecursion})
A recursive expression: an anchor member, then the member that selects from name itself.
factory

Properties

columns → List<String>
The field names, for the WITH name (…) column list.
no setter
fields → List<MssqlCteField>
The fields, in the order the members project them.
final
hashCode → int
The hash code for this object.
no setterinherited
isRecursive → bool
final
maxRecursion → int?
OPTION (MAXRECURSION n), validated on the way in.
final
members → List<MssqlSelectQuery>
One member for a plain expression, two for a recursive one.
final
name → String
final
ref → MssqlSourceRef
This expression as a source, so its columns qualify themselves with whatever the query ends up calling it.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

column(String field) → MssqlTypedColumn<Object?>
The field called field, as a column that can be selected, compared and ordered by.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read() → MssqlQuery
A query that reads this expression, with the WITH clause already on it and every field projected by name.
toCte() → MssqlCte
The clause this compiles to.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited