Table of Contents

Class SqlNodeInterpreterContext

Namespace
LfrlAnvil.Sql.Expressions.Visitors
Assembly
LfrlAnvil.Sql.Core.dll

Represents a context for an SqlNodeInterpreter instance that contains the ongoing result of SQL nodes' interpretation.

public sealed class SqlNodeInterpreterContext
Inheritance
SqlNodeInterpreterContext
Inherited Members

Properties

ChildDepth

Gets the current SQL child node depth.

public int ChildDepth { get; }

Property Value

int

Indent

Gets the current SQL statement indentation level.

public int Indent { get; }

Property Value

int

Parameters

Gets the collection of registered SQL parameters.

public IReadOnlyCollection<SqlNodeInterpreterContextParameter> Parameters { get; }

Property Value

IReadOnlyCollection<SqlNodeInterpreterContextParameter>

Sql

Underlying SQL builder.

public StringBuilder Sql { get; }

Property Value

StringBuilder

Methods

AddParameter(string, TypeNullability?, int?)

Registers a new SQL parameter in this context.

public void AddParameter(string name, TypeNullability? type, int? index)

Parameters

name string

Parameter's name.

type TypeNullability?

Optional runtime type of this parameter.

index int?

Optional 0-based position of this parameter.

Remarks

When SQL parameter with the provided name already exists, then its type and index are validated: when new type does not equal old type, then the existing entry's type is set to null, and when new index does not equal old index, then the existing entry's index is set to null.

AppendIndent()

Appends a new line with the current Indent to Sql.

public StringBuilder AppendIndent()

Returns

StringBuilder

Sql.

AppendShortIndent()

Appends a new line with the current Indent reduced by 2 to Sql.

public StringBuilder AppendShortIndent()

Returns

StringBuilder

Sql.

Clear()

Resets this context to initial empty state.

public void Clear()

Create(int)

Creates a new SqlNodeInterpreterContext instance.

[Pure]
public static SqlNodeInterpreterContext Create(int capacity = 1024)

Parameters

capacity int

Initial capacity of the underlying Sql builder. Equal to 1024 by default.

Returns

SqlNodeInterpreterContext

New SqlNodeInterpreterContext instance.

Create(StringBuilder)

Creates a new SqlNodeInterpreterContext instance with a prepared SQL builder.

[Pure]
public static SqlNodeInterpreterContext Create(StringBuilder builder)

Parameters

builder StringBuilder

SQL builder.

Returns

SqlNodeInterpreterContext

New SqlNodeInterpreterContext instance.

DecreaseChildDepth()

Decreases ChildDepth by 1, if possible.

public void DecreaseChildDepth()

DecreaseIndent()

Decreases Indent by 2, if possible.

public void DecreaseIndent()

IncreaseChildDepth()

Increases ChildDepth by 1.

public void IncreaseChildDepth()

IncreaseIndent()

Increases Indent by 2.

public void IncreaseIndent()

TempChildDepthIncrease()

Increases ChildDepth by 1 and creates a new disposable SqlNodeInterpreterContext.TemporaryChildDepthIncrease instance.

public SqlNodeInterpreterContext.TemporaryChildDepthIncrease TempChildDepthIncrease()

Returns

SqlNodeInterpreterContext.TemporaryChildDepthIncrease

New SqlNodeInterpreterContext.TemporaryChildDepthIncrease instance.

TempIndentIncrease()

Increases Indent by 2 and creates a new disposable SqlNodeInterpreterContext.TemporaryIndentIncrease instance.

public SqlNodeInterpreterContext.TemporaryIndentIncrease TempIndentIncrease()

Returns

SqlNodeInterpreterContext.TemporaryIndentIncrease

New SqlNodeInterpreterContext.TemporaryIndentIncrease instance.

ToSnapshot()

Creates a new SqlNodeInterpreterContextSnapshot instance from the current state of this context.

[Pure]
public SqlNodeInterpreterContextSnapshot ToSnapshot()

Returns

SqlNodeInterpreterContextSnapshot

New SqlNodeInterpreterContextSnapshot instance.

TryGetParameter(string, out SqlNodeInterpreterContextParameter)

Attempts to retrieve an SQL parameter by its name.

public bool TryGetParameter(string name, out SqlNodeInterpreterContextParameter result)

Parameters

name string

Parameter's name.

result SqlNodeInterpreterContextParameter

out parameter that returns found SQL parameter info.

Returns

bool

true when SQL parameter exists, otherwise false.