Пример #1
0
        private void DisplyChildObjects(string rootNodeHader, TreeViewItem currentObjectTreeViewItem,
                                        TSqlObject currentObject, Dictionary <string, TreeViewItem> childObjectTypes)
        {
            var children = currentObject.GetChildren();

            foreach (var child in children.OrderBy(p => p, new SqlObjectComparer()))
            {
                var type = child.ObjectType.Name;
                var typeContainerHeader = GetContainerHeader(type);

                if (!childObjectTypes.ContainsKey(typeContainerHeader))
                {
                    var item = AddTreeItem(typeContainerHeader, currentObjectTreeViewItem, _defaultForeground);
                    childObjectTypes.Add(typeContainerHeader, item);
                }

                var childTreeViewItem = AddTreeItem(child.Name.ToString(), childObjectTypes[typeContainerHeader],
                                                    _defaultForeground);

                DisplayObject(rootNodeHader, child, childTreeViewItem);
            }
            var repository = ModelRepository.GetRepository();

            if (repository.LoadScriptDom())
            {
                TSqlFragment fragment;

                TSqlModelUtils.TryGetFragmentForAnalysis(currentObject, out fragment);
                var frgPrc = new TSqlFragmentProcess.TSqlFragmentProcess(this);
                frgPrc.ProcessTSQLFragment(fragment, currentObjectTreeViewItem);
            }
        }
Пример #2
0
        public void Prc(string DacPac, string DatabaseName, string SchemaName)
        {
            this.databaseName = DatabaseName;
            this.schemaName   = SchemaName;

            using (TSqlModel model = TSqlModel.LoadFromDacpac(DacPac,
                                                              new ModelLoadOptions(DacSchemaModelStorageType.Memory, loadAsScriptBackedModel: true)))
            {
                ModelTypeClass[] Filter = new[] {
                    ModelSchema.View,
                    ModelSchema.Procedure,
                    ModelSchema.Table
                };

                foreach (var vw in model.GetObjects(DacQueryScopes.All, Filter))
                {
                    TSqlFragment frg;
                    if (TSqlModelUtils.TryGetFragmentForAnalysis(vw, out frg))
                    {
                        ProcessTsqlFragment(frg);
                    }
                    int g = 0;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Procedure"/> class.
        /// </summary>
        /// <param name="prefix">The prefix used on stored procedure names.</param>
        public Procedure(dac.TSqlObject tSqlObject, string prefix, IEnumerable <dac.TSqlObject> primaryKeys, IDictionary <dac.TSqlObject, IEnumerable <ForeignKeyConstraintDefinition> > foreignKeys)
        {
            this.Prefix     = prefix ?? "";
            this.RawName    = tSqlObject.Name.Parts.Last();
            this.Name       = this.RawName.Substring(this.Prefix.Length);
            this.Parameters = tSqlObject.GetReferenced(dac.Procedure.Parameters).Select(x => new Parameter(x, primaryKeys, foreignKeys));

            TSqlFragment fragment;

            TSqlModelUtils.TryGetFragmentForAnalysis(tSqlObject, out fragment);
            var selectVisitor = new SelectVisitor();

            fragment.Accept(selectVisitor);

            var bodyColumnTypes = tSqlObject.GetReferenced(dac.Procedure.BodyDependencies)
                                  .Where(x => x.ObjectType.Name == "Column")
                                  .GroupBy(bd => string.Join(".", bd.Name.Parts))
                                  .Select(grp => grp.First())
                                  .ToDictionary(
                key => string.Join(".", key.Name.Parts),
                val => new DataType
            {
                Map      = DataTypeHelper.Instance.GetMap(TypeFormat.SqlServerDbType, val.GetReferenced(dac.Column.DataType).First().Name.Parts.Last()),
                Nullable = dac.Column.Nullable.GetValue <bool>(val)
            },
                StringComparer.InvariantCultureIgnoreCase);

            var unions  = selectVisitor.Nodes.OfType <BinaryQueryExpression>().Select(bq => GetQueryFromUnion(bq)).Where(x => x != null);
            var selects = selectVisitor.Nodes.OfType <QuerySpecification>().Concat(unions);

            this.Selects = selects.Select(s => new Select(s, bodyColumnTypes)).ToList();
        }
Пример #4
0
 public IDictionary <dac.TSqlObject, IEnumerable <ForeignKeyConstraintDefinition> > GetForeignKeys(IEnumerable <dac.TSqlObject> objects)
 {
     return(objects.Select(obj =>
     {
         TSqlFragment fragment;
         TSqlModelUtils.TryGetFragmentForAnalysis(obj, out fragment);
         var foreignKeyConstraintVisitor = new ForeignKeyConstraintVisitor();
         fragment.Accept(foreignKeyConstraintVisitor);
         return new { obj, foreignKeyConstraintVisitor.Nodes };
     }).ToDictionary(key => key.obj, val => val.Nodes.AsEnumerable()));
 }
        /// <summary>
        /// Looks up the fragment representing the name of a <see cref="TSqlObject"/>.
        /// Only some common object types are supported - more can be added as needed.
        ///
        /// Searches for the precise TSqlFragment representing the name of the view.
        /// If it's possible to find this it can provide the most accurate source
        /// position information to support clicking on the error in the errors list
        /// and navigating to that precise view definition in a project file
        /// </summary>
        /// <param name="tSqlObject">The object whose name is requested</param>
        /// <returns><see cref="TSqlFragment"/> or null if no name is found</returns>
        public static TSqlFragment LookupSchemaObjectName(TSqlObject tSqlObject)
        {
            TSqlFragment fragment;

            if (TSqlModelUtils.TryGetFragmentForAnalysis(tSqlObject, out fragment))
            {
                NameFindingVisitor visitor = new NameFindingVisitor(tSqlObject);
                fragment.Accept(visitor);
                return(visitor.Name);
            }
            return(null);
        }
Пример #6
0
        public List <SqlRuleProblem> ProcessObject(TSqlObject sqlObject, int iRule)
        {
            var problems = new List <SqlRuleProblem>();

            _problems     = problems;
            _modelElement = sqlObject;
            _iRule        = iRule;

            TSqlFragment frg;

            if (TSqlModelUtils.TryGetFragmentForAnalysis(sqlObject, out frg))
            {
                if (iRule == 23)
                {
                    foreach (TSqlParserToken parserToken in frg.ScriptTokenStream)
                    {
                        //                       if (parserToken.TokenType == TSqlTokenType.SingleLineComment) SendFeedBack(23, parserToken);
                    }
                }
                ProcessTsqlFragment(frg);
            }

            return(problems);
        }