Table of Contents

Class QueryExecutionContext

Namespace
ItTiger.TigerQuery.Engine
Assembly
ItTiger.TigerQuery.dll
Holds mutable per-run parser state and executes batches on a caller-supplied SQL connection.
public sealed class QueryExecutionContext
Inheritance
QueryExecutionContext
Inherited Members

Remarks

The context does not own or dispose the connection. It is mutable and not safe for concurrent parsing or execution.

Constructors

QueryExecutionContext(TigerQueryEngineOptions, SqlConnection)

Initializes a per-run context.
public QueryExecutionContext(TigerQueryEngineOptions options, SqlConnection connection)

Parameters

options TigerQueryEngineOptions
The parser, execution, and callback options.
connection SqlConnection
The SQL connection used by ExecuteBatchAsync(SqlBatch, int, int, CancellationToken). The context does not open or dispose it.

Exceptions

ArgumentNullException
options or connection is null.

Properties

ContinueOnError

Gets or sets whether execution should continue after a nonfatal batch failure.
public bool ContinueOnError { get; set; }

Property Value

bool

Remarks

Initialized from ContinueOnError and updated while parsing :ON ERROR IGNORE or :ON ERROR EXIT.

Mode

Gets the configured parser mode.
public SqlCmdMode Mode { get; }

Property Value

SqlCmdMode

Variables

Gets the case-insensitive variable table for this run.
public IReadOnlyDictionary<string, SqlCmdVariable> Variables { get; }

Property Value

IReadOnlyDictionary<string, SqlCmdVariable>

Remarks

The dictionary cannot be modified through this view, although each SqlCmdVariable reflects subsequent permitted assignments.

Methods

ExecuteBatchAsync(SqlBatch, int, int, CancellationToken)

Executes one batch iteration and materializes each result set for the configured result-set callback.
public Task<int> ExecuteBatchAsync(SqlBatch batch, int batchNumber, int executionIndex, CancellationToken cancellationToken)

Parameters

batch SqlBatch
The batch whose SQL text is submitted.
batchNumber int
The one-based logical batch number.
executionIndex int
The one-based repeat iteration.
cancellationToken CancellationToken
A token passed to provider operations.

Returns

Task<int>
Zero after execution, including for an empty batch.

Remarks

A null or whitespace-only batch is skipped. The supplied connection must already be open. CommandTimeoutSeconds, when set, bounds this one batch rather than the run. Result sets are fully read before they are delivered. When the engine has redirected the result-set channel to a file, the result set is written there and the callback is not invoked.

Exceptions

OperationCanceledException
cancellationToken is cancelled during provider work.
SqlException
SQL Server rejects or fails the batch, including when the batch exceeds CommandTimeoutSeconds.
OutputRoutingException
A redirected result set could not be serialized or written.

ExpandVariables(string)

Expands sqlcmd variable references in text.
public string ExpandVariables(string input)

Parameters

input string
The source text to process.

Returns

string
Expanded text, or the original text in Normal. Undefined references remain literal.

GetVariableValue(string)

Looks up a variable value by case-insensitive name.
public string? GetVariableValue(string name)

Parameters

name string
The name without reference delimiters.

Returns

string
The current value, or null when undefined.

SetVariableFromScript(string, string)

Applies a value parsed from a :setvar command.
public void SetVariableFromScript(string name, string value)

Parameters

name string
The variable name without reference delimiters.
value string
The parsed replacement value.

Remarks

Empty or whitespace names are ignored. Assignments to protected SqlCmdEx programmatic variables are also ignored. Other assignments add or replace variables case-insensitively.