예제 #1
0
        public static void LoadViewOutputColumns(ISchemaMetadataProvider schemaMetadata, string ddl, Action <OutputColumnDescriptor> collector)
        {
            TSqlFragment sqlF = ScriptDomFacade.Parse(ddl);
            //CreateViewStatement stmt_CreateView = (CreateViewStatement)((TSqlScript)sqlF).Batches[0].Statements[0];
            SelectStatement stmt_sel = (SelectStatement)((TSqlScript)sqlF).Batches[0].Statements[0];

            BatchOutputColumnTypeResolver batchResolver = new BatchOutputColumnTypeResolver(schemaMetadata, stmt_sel, new BatchWithoutParameters());

            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());
                }
            }
        }
예제 #2
0
        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());
                }
            }
        }
예제 #3
0
 public override void ExplicitVisit(SelectScalarExpression node)
 {
     // IIF(@limitreached = 1, 1, 0)
     if (hasSetVariable)
     {
         outputSet.Clear();
     }
     else
     {
         //Console.WriteLine("Resolve type for scalar:" + node.AsText());
         OutputColumnDescriptor columnDbType = resolveColumnType
             ? columnTypeResolver.ResolveSelectScalarExpression(node)
             : null;
         if (columnDbType == null || columnDbType.ColumnType == null)
         {
             // put a breakpoint here
             //this column cannot be resolved from this query. if this is a part of a IF statemt try ELSE branch.
         }
         outputSet.AddColumn(new ProcedureOutputColumn(node, columnDbType)); // SelectScalarExpression
     }
 }