Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        private static TestTable LoadTableFromDDL(string ddl)
        {
            TSqlFragment         sqlF             = ScriptDomFacade.Parse(ddl);
            CreateTableStatement stmt_CreateTable = (CreateTableStatement)((TSqlScript)sqlF).Batches[0].Statements[0];

            string schemaName = stmt_CreateTable.SchemaObjectName.SchemaIdentifier.Dequote();
            string tableName  = stmt_CreateTable.SchemaObjectName.BaseIdentifier.Dequote();
            var    table      = new TestTable(schemaName, tableName);

            foreach (ColumnDefinition col in stmt_CreateTable.Definition.ColumnDefinitions)
            {
                string columnName   = col.ColumnIdentifier.Dequote();
                var    columnDbType = ProcedureGenerator.ResolveToDbDataType(col.DataType);

                table.AddColumn(columnName, columnDbType, true);
            }

            return(table);
        }