Table of Contents

Class SqlStatement

Namespace
Utils.Data.Sql
Assembly
Utils.Data.dll

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

segments IEnumerable<SqlSegment>

The segments that compose the statement.

withClause WithClause

The optional CTE definitions attached to the statement.

syntaxOptions SqlSyntaxOptions

Syntax options governing identifier parsing for the statement.

Properties

Segments

Gets the segments that compose the statement.

public IReadOnlyList<SqlSegment> Segments { get; }

Property Value

IReadOnlyList<SqlSegment>

SyntaxOptions

Gets the syntax options associated with the statement.

public SqlSyntaxOptions SyntaxOptions { get; }

Property Value

SqlSyntaxOptions

WithClause

Gets the optional WITH clause containing CTE definitions.

public WithClause? WithClause { get; }

Property Value

WithClause

Methods

AttachSegment(SqlSegment)

Registers the provided segment in the internal collection.

protected void AttachSegment(SqlSegment segment)

Parameters

segment SqlSegment

The 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

segment SqlSegment

The 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

previous SqlSegment

The segment currently registered.

replacement SqlSegment

The 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

options SqlFormattingOptions

Formatting options applied to the SQL output.

Returns

string

The SQL string representing the statement.