Esempio n. 1
0
        public void CalledWithNoProcsGeneratesNoChildren()
        {
            var sw    = new ScriptWalker(new FakeDefinitionService());
            var procs = sw.GetCalledProcedures("print 'nothing'", "master");

            Assert.AreEqual(0, procs.Children.Count);
        }
Esempio n. 2
0
        public void CalledWithProcsAndNoLookupsGeneratesFirstLevelOfChildren()
        {
            var fds = new FakeDefinitionService();

            fds.AddDefinition(new StoredProcedure("master", "dbo", "ProcOne"), "create procedure dbo.ProcOne as");
            fds.AddDefinition(new StoredProcedure("master", "dbo", "ProcTwo"), "create procedure dbo.ProcTwo as");
            var sw    = new ScriptWalker(fds);
            var procs = sw.GetCalledProcedures("exec dbo.ProcOne; exec dbo.ProcTwo;", "master");

            Assert.AreEqual(2, procs.Children.Count);
        }
Esempio n. 3
0
        public void InfiniteLoopIdentifiedAtLevelOne()
        {
            var fds = new FakeDefinitionService();

            fds.AddDefinition(new StoredProcedure("master", "dbo", "ProcOne"), "create procedure dbo.ProcOne as");
            fds.AddDefinition(new StoredProcedure("master", "dbo", "ProcTwo"), "create procedure dbo.ProcTwo as exec dbo.ProcTwo;");
            var sw    = new ScriptWalker(fds);
            var procs = sw.GetCalledProcedures("exec dbo.ProcOne; exec dbo.ProcTwo;", "master");

            Debug.WriteLine(procs.GetCallHierarchy());
            // script -> ProcTwo -> ProcTwo => second proc call should be detected as the infinite loop
            Assert.IsTrue(procs.Children[1].Children[0].IsInfiniteLoop);
        }
Esempio n. 4
0
        public void MultipleLevelOutput()
        {
            var fds = new FakeDefinitionService();

            fds.AddDefinition(new StoredProcedure("master", "dbo", "ProcOne"), "create procedure dbo.ProcOne as");
            fds.AddDefinition(new StoredProcedure("master", "dbo", "ProcTwo"), "create procedure dbo.ProcTwo as exec dbo.ProcThree;");
            fds.AddDefinition(new StoredProcedure("master", "dbo", "ProcThree"), "create procedure dbo.ProcThree as exec dbo.ProcFour;");
            fds.AddDefinition(new StoredProcedure("master", "dbo", "ProcFour"), "create procedure dbo.ProcFour as return;");
            var sw    = new ScriptWalker(fds);
            var procs = sw.GetCalledProcedures("exec dbo.ProcOne; exec dbo.ProcTwo; exec ProcOne; exec ProcTwo;", "master");

            Debug.WriteLine(procs.GetCallHierarchy());

            Assert.IsTrue(true);
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var result = Parser.Default.ParseArguments <Options>(args);

            if (result.Tag == ParserResultType.NotParsed)
            {
                return;
            }

            var options = (result as Parsed <Options>).Value;

            SqlConnectionStringBuilder builder = null;

            try
            {
                builder = new SqlConnectionStringBuilder(options.Server);
            }
            catch (ArgumentException ae)
            {
                WriteError($"Connection string is not valid: {ae.Message}");
                return;
            }
            var database = builder.InitialCatalog;

            if (string.IsNullOrWhiteSpace(database))
            {
                System.Console.WriteLine("Connection string does not specify database, defaulting to master");
                database = "master";
            }

            // Establish connection
            ScriptWalker sw = null;

            try
            {
                sw = new ScriptWalker(new SQLDatabaseDefinitionService(options.Server));
            }
            catch (SqlException sx)
            {
                WriteError($"Unable to connect to database: {sx.Message}");
                return;
            }
            var callChain = sw.GetCalledProcedures(options.Script, database);

            System.Console.WriteLine(callChain.GetCallHierarchy());
        }