コード例 #1
0
ファイル: TestResources.cs プロジェクト: benhauman/storelake
 private static void LoadFunctionOutputColumns(TestSchema schema, TestFunction function_source, CreateFunctionStatement stmt_CreateFunction)
 {
     ProcedureGenerator.LoadFunctionOutputColumns(schema, function_source, function_source.FunctionBodyScript, (col) =>
     {
         function_source.AddFunctionColumn(col.OutputColumnName, col.ColumnType.ColumnDbType, col.ColumnType.AllowNull);
     });
 }
コード例 #2
0
ファイル: TestResources.cs プロジェクト: benhauman/storelake
 private static void LoadViewOutputColumnsX(TestSchema schema, TestView vw, CreateViewStatement stmt_CreateFunction)
 {
     ProcedureGenerator.LoadViewOutputColumns(schema, vw.Body, (col) =>
     {
         vw.AddViewColumn(col.OutputColumnName, col.ColumnType.ColumnDbType, col.ColumnType.AllowNull, col.OutputColumnName);
     });
 }
コード例 #3
0
ファイル: TestResources.cs プロジェクト: benhauman/storelake
        internal static TestFunction LoadFunctionMetatadaFromDDL(TestSchema schema, string ddl)
        {
            TSqlFragment            sqlF = ScriptDomFacade.Parse(ddl);
            CreateFunctionStatement stmt_CreateFunction = (CreateFunctionStatement)((TSqlScript)sqlF).Batches[0].Statements[0];

            string schemaName   = stmt_CreateFunction.Name.SchemaIdentifier.Dequote();
            string functionName = stmt_CreateFunction.Name.BaseIdentifier.Dequote();

            if (stmt_CreateFunction.StatementList != null)
            {
                // 'hlsyssec_query_agentsystemacl'
                return(LoadMultiStatementTableValuedFunction(schemaName, functionName, stmt_CreateFunction));
            }

            // inline 'hlsur_query_surveyresults'
            string functionBody = GetFragmentStreamAsText(((SelectFunctionReturnType)stmt_CreateFunction.ReturnType).SelectStatement);

            var function = new TestFunction(schemaName, functionName, functionBody, f => LoadFunctionOutputColumns(schema, f, stmt_CreateFunction));

            foreach (ProcedureParameter prm in stmt_CreateFunction.Parameters)
            {
                string parameterName   = prm.VariableName.Dequote();
                var    parameterDbType = ProcedureGenerator.ResolveToDbDataType(prm.DataType);

                function.AddParameter(parameterName, parameterDbType, true);
            }

            return(function);
        }
コード例 #4
0
ファイル: TestResources.cs プロジェクト: benhauman/storelake
        internal static TestSchema LoadFunctionsMetadata(this TestSchema schema)
        {
            var functionFileNames = ResourceHelper.CollectResourceNamesByPrefix(typeof(ResourceHelper), "SQL.Functions.");

            foreach (var resourceName in functionFileNames)
            {
                string ddl = ResourceHelper.LoadResourceText(typeof(ResourceHelper), resourceName);
                schema.AddFunction(LoadFunctionMetatadaFromDDL(schema, ddl));
            }

            return(schema);
        }
コード例 #5
0
ファイル: TestResources.cs プロジェクト: benhauman/storelake
        internal static TestSchema LoadViews(this TestSchema schema)
        {
            var viewFileNames = ResourceHelper.CollectResourceNamesByPrefix(typeof(ResourceHelper), "SQL.Views.");

            foreach (var resourceName in viewFileNames)
            {
                string ddl = ResourceHelper.LoadResourceText(typeof(ResourceHelper), resourceName);
                schema.AddView(LoadViewMetatadaFromDDL(schema, ddl));
            }

            return(schema);
        }
コード例 #6
0
ファイル: TestResources.cs プロジェクト: benhauman/storelake
        internal static TestSchema LoadUDTs(this TestSchema schema)
        {
            var tableFileNames = ResourceHelper.CollectResourceNamesByPrefix(typeof(ResourceHelper), "SQL.Types.");

            foreach (var resourceName in tableFileNames)
            {
                string ddl = ResourceHelper.LoadResourceText(typeof(ResourceHelper), resourceName);
                schema.AddUDT(LoadUDTFromDDL(ddl));
            }

            return(schema);
        }
コード例 #7
0
ファイル: TestResources.cs プロジェクト: benhauman/storelake
        private static TestView LoadViewMetatadaFromDDL(TestSchema schema, string ddl)
        {
            TSqlFragment        sqlF = ScriptDomFacade.Parse(ddl);
            CreateViewStatement stmt_CreateFunction = (CreateViewStatement)((TSqlScript)sqlF).Batches[0].Statements[0];
            //string body = ExtractViewDefinition(ddl);
            string body = GetFragmentStreamAsText(stmt_CreateFunction.SelectStatement);

            string schemaName   = stmt_CreateFunction.SchemaObjectName.SchemaIdentifier.Dequote();
            string functionName = stmt_CreateFunction.SchemaObjectName.BaseIdentifier.Dequote();
            var    function     = new TestView(schemaName, functionName, body, f => LoadViewOutputColumnsX(schema, f, stmt_CreateFunction));


            return(function);
        }
コード例 #8
0
ファイル: TestResources.cs プロジェクト: benhauman/storelake
        private static void LoadViewOutputColumns(TestSchema schema, TestView function_source, CreateViewStatement stmt_CreateView)
        {
            BatchOutputColumnTypeResolver batchResolver = new BatchOutputColumnTypeResolver(schema, stmt_CreateView, function_source);

            StatementOutputColumnTypeResolverV2 resolver = new StatementOutputColumnTypeResolverV2(batchResolver, stmt_CreateView.SelectStatement);

            QuerySpecification first = TopQuerySpecification(stmt_CreateView.SelectStatement.QueryExpression);

            foreach (SelectElement se in first.SelectElements)
            {
                if (se is SelectScalarExpression scalarExpr)
                {
                    OutputColumnDescriptor col = resolver.ResolveSelectScalarExpression(scalarExpr);
                    function_source.AddViewColumn(col.OutputColumnName, col.ColumnType.ColumnDbType, col.ColumnType.AllowNull, col.OutputColumnName);
                }
                else
                {
                    throw new NotImplementedException(se.WhatIsThis());
                }
            }
        }