Beispiel #1
0
        private void PopulateCalledProcedures(ProcedureCall call, string sqlScript, string currentDatabase, string defaultSchema)
        {
            var parsed    = BatchParser.GetExecutedProcedures(sqlScript);
            var wellNamed = parsed.Select(p => new StoredProcedure(p, defaultSchema, currentDatabase));

            // Parent list for any children
            var newParentList = call.AllParents.ToList();

            if (!call.IsRoot)
            {
                newParentList.Add(call.StoredProcedure);
            }

            foreach (var proc in wellNamed)
            {
                // If we've already seen this call we're in an infinite loop
                if (newParentList.Contains(proc))
                {
                    var infinite = new ProcedureCall(newParentList, proc, call.Depth + 1)
                    {
                        IsInfiniteLoop = true
                    };
                    call.Children.Add(infinite);
                    continue;
                }

                var definition = _definitionService.GetStoredProcedureDefinition(proc);
                var childCall  = new ProcedureCall(newParentList, proc, call.Depth + 1);
                call.Children.Add(childCall);
                PopulateCalledProcedures(childCall, definition, childCall.StoredProcedure.Database, defaultSchema);
            }
        }
Beispiel #2
0
        public ProcedureCall GetCalledProcedures(string sqlScript, string currentDatabase, string defaultSchema = "dbo")
        {
            if (string.IsNullOrWhiteSpace(sqlScript))
            {
                throw new ArgumentOutOfRangeException(sqlScript);
            }

            if (string.IsNullOrWhiteSpace(currentDatabase))
            {
                throw new ArgumentOutOfRangeException(currentDatabase);
            }

            if (string.IsNullOrWhiteSpace(defaultSchema))
            {
                throw new ArgumentOutOfRangeException(defaultSchema);
            }

            var call = new ProcedureCall(null, null, 0);

            PopulateCalledProcedures(call, sqlScript, currentDatabase, defaultSchema);

            return(call);
        }