Class SqlCmdParser
- Namespace
- ItTiger.TigerQuery
- Assembly
- ItTiger.TigerQuery.dll
public sealed class SqlCmdParser
- Inheritance
-
SqlCmdParser
- Inherited Members
Remarks
ReadBatchesAsync(CancellationToken) recognizes GO separators in every
SqlCmdMode. In sqlcmd modes it also expands $(name),
processes :setvar, and applies :ON ERROR EXIT or
:ON ERROR IGNORE to the shared execution context.
In sqlcmd modes the parser also recognizes and validates the :Out and
:Error output directives, which previously failed as unknown commands.
They are represented internally as ordered execution steps that only
TigerQueryEngine consumes; ReadBatchesAsync(CancellationToken)
projects them away and still returns batches only.
Parsing validates TigerQuery/sqlcmd structure only. It does not validate T-SQL. The parser consumes its TextReader and is not thread-safe.
Constructors
SqlCmdParser(TextReader, TigerQueryEngineOptions, QueryExecutionContext)
public SqlCmdParser(TextReader reader, TigerQueryEngineOptions options, QueryExecutionContext context)
Parameters
readerTextReader- The script source. The parser does not dispose it.
optionsTigerQueryEngineOptions- The parsing and variable options.
contextQueryExecutionContext- The mutable context that receives variable and
:ON ERRORstate.
Exceptions
- ArgumentNullException
reader,options, orcontextis null.
Methods
ReadBatchesAsync(CancellationToken)
public IAsyncEnumerable<SqlBatch> ReadBatchesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationToken- A token observed throughout parser enumeration.
Returns
- IAsyncEnumerable<SqlBatch>
- An asynchronous stream of parser-produced batches.
Remarks
Variables are expanded as text is parsed. Undefined ordinary variables
remain as their literal $(name) references. A variable used as a
GO count must expand to one valid int value.
A directive after buffered SQL and before its terminating GO updates
the context before that batch is yielded. Consumers that defer execution
must therefore snapshot relevant context state for each yielded batch.
Recognized :Out and :Error directives are validated but not
returned by this method. Consumers that need output routing must execute
through TigerQueryEngine.
Exceptions
- OperationCanceledException
cancellationTokenis cancelled during enumeration.- TigerQueryException
- A sqlcmd directive,
GOcount, quoted section, or comment is malformed.
ReadElement()
public SqlElement? ReadElement()
Returns
- SqlElement
- The next element, or null at end of input.
Exceptions
- TigerQueryException
- A quoted section or multiline comment is unterminated, or parser state is invalid.