public void CalledWithNoProcsGeneratesNoChildren() { var sw = new ScriptWalker(new FakeDefinitionService()); var procs = sw.GetCalledProcedures("print 'nothing'", "master"); Assert.AreEqual(0, procs.Children.Count); }
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); }
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); }
public static HoistingScope GetProgramLevelDeclarations( Program script, bool collectVarNames = false, bool collectLexicalNames = false) { var treeWalker = new ScriptWalker(StrictModeScope.IsStrictModeCode, collectVarNames, collectLexicalNames); treeWalker.Visit(script, null); return(new HoistingScope( treeWalker._functions, treeWalker._varNames, treeWalker._variableDeclarations, treeWalker._lexicalDeclarations, treeWalker._lexicalNames)); }
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); }
public static HoistingScope GetModuleLevelDeclarations( Module module, bool collectVarNames = false, bool collectLexicalNames = false) { //Modules area always strict var treeWalker = new ScriptWalker(true, collectVarNames, collectLexicalNames); treeWalker.Visit(module, null); return(new HoistingScope( treeWalker._functions, treeWalker._varNames, treeWalker._variableDeclarations, treeWalker._lexicalDeclarations, treeWalker._lexicalNames)); }
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()); }
public void VisitChildren() { var walker = new ScriptWalker(); walker.Visit(_script); if (walker._lexicalNameCount != 0) { throw new InvalidOperationException("wrong _lexicalNameCount" + walker._lexicalNameCount); } if (walker._varNameCount != 1856) { throw new InvalidOperationException("wrong _varNameCount " + walker._varNameCount); } if (walker._functionCount != 1610) { throw new InvalidOperationException("wrong _functionCount " + walker._functionCount); } }