public BatchOutputColumnTypeResolver(ISchemaMetadataProvider schemaMetadata, TSqlFragment bodyFragment, IBatchParameterMetadata parametersMetadata) { SchemaMetadata = schemaMetadata; BodyFragment = bodyFragment; parameters = parametersMetadata; }
public static void LoadFunctionOutputColumns(ISchemaMetadataProvider schemaMetadata, IBatchParameterMetadata parameterMetadata, string functionBodyScript, Action <OutputColumnDescriptor> collector) { functionBodyScript = RemoveTrailingBlockComment(functionBodyScript); if (functionBodyScript.Trim()[0] == '(') { int idx = functionBodyScript.IndexOf('('); int lastix = functionBodyScript.LastIndexOf(')'); functionBodyScript = functionBodyScript.Substring(idx + 1, lastix - idx - 2); functionBodyScript = functionBodyScript.Trim(); } TSqlFragment sqlF = ScriptDomFacade.Parse(functionBodyScript); SelectStatement stmt_sel = (SelectStatement)((TSqlScript)sqlF).Batches[0].Statements[0]; BatchOutputColumnTypeResolver batchResolver = new BatchOutputColumnTypeResolver(schemaMetadata, sqlF, parameterMetadata); StatementOutputColumnTypeResolverV2 resolver = new StatementOutputColumnTypeResolverV2(batchResolver, stmt_sel); QuerySpecification first = TopQuerySpecification(stmt_sel.QueryExpression); foreach (SelectElement se in first.SelectElements) { if (se is SelectScalarExpression scalarExpr) { OutputColumnDescriptor col = resolver.ResolveSelectScalarExpression(scalarExpr); collector(col); } else { throw new NotImplementedException(se.WhatIsThis()); } } }