Class SqlStatement
Represents a parsed SQL statement.
public abstract class SqlStatement
- Inheritance
-
SqlStatement
- Derived
- Inherited Members
- Extension Methods
Constructors
SqlStatement(IEnumerable<SqlSegment>, WithClause?, SqlSyntaxOptions?)
Initializes a new instance of the SqlStatement class.
protected SqlStatement(IEnumerable<SqlSegment> segments, WithClause? withClause, SqlSyntaxOptions? syntaxOptions = null)
Parameters
segmentsIEnumerable<SqlSegment>The segments that compose the statement.
withClauseWithClauseThe optional CTE definitions attached to the statement.
syntaxOptionsSqlSyntaxOptionsSyntax options governing identifier parsing for the statement.
Properties
Segments
Gets the segments that compose the statement.
public IReadOnlyList<SqlSegment> Segments { get; }
Property Value
SyntaxOptions
Gets the syntax options associated with the statement.
public SqlSyntaxOptions SyntaxOptions { get; }
Property Value
WithClause
Gets the optional WITH clause containing CTE definitions.
public WithClause? WithClause { get; }
Property Value
Methods
AttachSegment(SqlSegment)
Registers the provided segment in the internal collection.
protected void AttachSegment(SqlSegment segment)
Parameters
segmentSqlSegmentThe segment to register.
BuildSql()
Builds the canonical inline SQL representation of the statement.
protected abstract string BuildSql()
Returns
- string
The inline SQL string representing the statement.
DetachSegment(SqlSegment)
Removes the provided segment from the internal collection.
protected void DetachSegment(SqlSegment segment)
Parameters
segmentSqlSegmentThe segment to remove.
EnumerateStatements()
Enumerates the statement itself and all nested statements.
public IEnumerable<SqlStatement> EnumerateStatements()
Returns
- IEnumerable<SqlStatement>
An enumerable containing this statement followed by nested statements.
GetChildStatements()
Retrieves the child statements referenced by this statement.
protected virtual IEnumerable<SqlStatement> GetChildStatements()
Returns
- IEnumerable<SqlStatement>
An enumerable of nested statements.
ReplaceSegment(SqlSegment?, SqlSegment?)
Replaces an existing segment with a new instance.
protected void ReplaceSegment(SqlSegment? previous, SqlSegment? replacement)
Parameters
previousSqlSegmentThe segment currently registered.
replacementSqlSegmentThe new segment to register.
ToSql(SqlFormattingOptions?)
Builds the SQL representation of the statement using the provided formatting options.
public string ToSql(SqlFormattingOptions? options = null)
Parameters
optionsSqlFormattingOptionsFormatting options applied to the SQL output.
Returns
- string
The SQL string representing the statement.