Microsoft.SqlServer.TransactSql.ScriptDom by Microsoft

<PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom" Version="161.8817.2" />

.NET API 5,151,152 bytes

 TSql160Parser

public class TSql160Parser : TSqlParser
The TSql Parser for 16.0.
using Microsoft.SqlServer.TransactSql.ScriptDom.Versioning; using System; using System.Collections.Generic; using System.Globalization; using System.IO; namespace Microsoft.SqlServer.TransactSql.ScriptDom { [Serializable] public class TSql160Parser : TSqlParser { protected SqlEngineType engineType; public TSql160Parser(bool initialQuotedIdentifiers) : base(initialQuotedIdentifiers) { } public TSql160Parser(bool initialQuotedIdentifiers, SqlEngineType engineType) : base(initialQuotedIdentifiers) { this.engineType = engineType; } internal override TSqlLexerBaseInternal GetNewInternalLexer() { return new TSql160LexerInternal(); } private TSql160ParserInternal GetNewInternalParser() { return new TSql160ParserInternal(base.QuotedIdentifier); } private TSql160ParserInternal GetNewInternalParserForInput(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParser = GetNewInternalParser(); InitializeInternalParserInput(newInternalParser, input, out errors, startOffset, startLine, startColumn); return newInternalParser; } public override TSqlFragment Parse(IList<TSqlParserToken> tokens, out IList<ParseError> errors) { errors = new List<ParseError>(); TSql160ParserInternal newInternalParser = GetNewInternalParser(); newInternalParser.InitializeForNewInput(tokens, errors, false); TSqlFragment tSqlFragment = newInternalParser.ParseRuleWithStandardExceptionHandling(newInternalParser.script, "script"); HotswapCreateExternalStreamingJobStatements(tSqlFragment); if (tSqlFragment != null) { VersioningVisitor versioningVisitor = new VersioningVisitor(engineType, SqlVersion.Sql160); tSqlFragment.Accept(versioningVisitor); { foreach (ParseError error in versioningVisitor.GetErrors()) { errors.Add(error); } return tSqlFragment; } } return tSqlFragment; } private void HotswapCreateExternalStreamingJobStatements(TSqlFragment fragment) { if (fragment != null) { foreach (TSqlBatch batch in ((TSqlScript)fragment).Batches) { TSqlStatement tSqlStatement = batch.Statements[0]; ExecutableProcedureReference executableProcedureReference = ConvertToExecutableProcedureReference(tSqlStatement as ExecuteStatement); if (executableProcedureReference != null) { CreateExternalStreamingJobStatement createExternalStreamingJobStatement = new CreateExternalStreamingJobStatement { ScriptTokenStream = executableProcedureReference.ScriptTokenStream, FirstTokenIndex = tSqlStatement.FirstTokenIndex, LastTokenIndex = executableProcedureReference.LastTokenIndex }; createExternalStreamingJobStatement.Name = new StringLiteral { Value = ((Literal)executableProcedureReference.Parameters[0].ParameterValue).Value }; createExternalStreamingJobStatement.Statement = new StringLiteral { Value = ((Literal)executableProcedureReference.Parameters[1].ParameterValue).Value }; batch.Statements[0] = createExternalStreamingJobStatement; } } } } private ExecutableProcedureReference ConvertToExecutableProcedureReference(ExecuteStatement statement) { if (statement == null) return null; ExecutableProcedureReference executableProcedureReference = statement.ExecuteSpecification.ExecutableEntity as ExecutableProcedureReference; if (executableProcedureReference == null || executableProcedureReference.ProcedureReference == null || executableProcedureReference.ProcedureReference.ProcedureReference == null) return null; if (executableProcedureReference.ProcedureReference.ProcedureReference.Name.Identifiers.Count != 2 || executableProcedureReference.ProcedureReference.ProcedureReference.Name.Identifiers[0].Value.ToLower(CultureInfo.CurrentCulture) != "sys" || executableProcedureReference.ProcedureReference.ProcedureReference.Name.Identifiers[1].Value.ToLower(CultureInfo.CurrentCulture) != "sp_create_streaming_job") return null; return executableProcedureReference; } public override ChildObjectName ParseChildObjectName(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointChildObjectName, "entryPointChildObjectName"); } public override SchemaObjectName ParseSchemaObjectName(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointSchemaObjectName, "entryPointSchemaObjectName"); } public override DataTypeReference ParseScalarDataType(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointScalarDataType, "entryPointScalarDataType"); } public override ScalarExpression ParseExpression(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointExpression, "entryPointExpression"); } public override BooleanExpression ParseBooleanExpression(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointBooleanExpression, "entryPointBooleanExpression"); } public override StatementList ParseStatementList(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointStatementList, "entryPointStatementList"); } public override SelectStatement ParseSubQueryExpressionWithOptionalCTE(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointSubqueryExpressionWithOptionalCTE, "entryPointSubqueryExpressionWithOptionalCTE"); } internal IPv4 ParseIPv4(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointIPv4Address, "entryPointIPv4Address"); } public override TSqlFragment ParseConstantOrIdentifier(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointConstantOrIdentifier, "entryPointConstantOrIdentifier"); } public override TSqlFragment ParseConstantOrIdentifierWithDefault(TextReader input, out IList<ParseError> errors, int startOffset, int startLine, int startColumn) { TSql160ParserInternal newInternalParserForInput = GetNewInternalParserForInput(input, out errors, startOffset, startLine, startColumn); return newInternalParserForInput.ParseRuleWithStandardExceptionHandling(newInternalParserForInput.entryPointConstantOrIdentifierWithDefault, "entryPointConstantOrIdentifierWithDefault"); } internal override TSqlStatement PhaseOneParse(TextReader input) { TSql160ParserInternal newInternalParser = GetNewInternalParser(); return PhaseOneParseImpl(newInternalParser, newInternalParser.script, "script", input); } } }