public virtual string GetPlanForQuery(string query) { IList<ParseError> errors; var fragment = new TSql120Parser(false).Parse(new StringReader(query), out errors ); var visitor = new ProcedureVisitor(); fragment.Accept(visitor); foreach (var proc in visitor.Procedures) { var procName = proc.ProcedureReference.Name; return GetPlanForProc(procName); } foreach (var func in visitor.Functions) { var procName = func.Name; return GetPlanForFunc(procName, func.Parameters); } return ""; }
public virtual string GetPlanForQuery(string query) { IList <ParseError> errors; var fragment = new TSql120Parser(false).Parse(new StringReader(query), out errors); var visitor = new ProcedureVisitor(); fragment.Accept(visitor); foreach (var proc in visitor.Procedures) { var procName = proc.ProcedureReference.Name; return(GetPlanForProc(procName)); } foreach (var func in visitor.Functions) { var procName = func.Name; return(GetPlanForFunc(procName, func.Parameters)); } return(""); }
public void CreateSchemas() { IList<ParseError> errors; var fragment = new TSql120Parser(false).Parse(new StringReader(_scripts), out errors); if (fragment == null) return; var visitor = new ProcedureVisitor(); fragment.Accept(visitor); foreach (var procedure in visitor.Procedures) { var browser = new SolutionBrowserForm(procedure.ProcedureReference.Name.BaseIdentifier.Value.Quote()); browser.ShowDialog(); var destination = browser.DestinationItem; if (destination == null) continue; var parentProjectItem = destination; var name = browser.GetObjectName(); var script = GetScript(name); for (var i = 1; i <= parentProjectItem.ProjectItems.Count; i++) { var item = parentProjectItem.ProjectItems.Item(i); if (item.Name.UnQuote() == name.UnQuote()) { CreateNewFile(item, name, script); return; } } var folder = parentProjectItem.ProjectItems.AddFolder(name.UnQuote()); CreateNewFile(folder, name, script); } foreach (var procedure in visitor.Functions) { var browser = new SolutionBrowserForm(procedure .Name.BaseIdentifier.Value.Quote()); browser.ShowDialog(); var destination = browser.DestinationItem; if (destination == null) continue; var parentProjectItem = destination; var name = browser.GetObjectName(); var script = GetScript(name); for (var i = 1; i <= parentProjectItem.ProjectItems.Count; i++) { var item = parentProjectItem.ProjectItems.Item(i); if (item.Name.UnQuote() == name.UnQuote()) { CreateNewFile(item, name, script); return; } } var folder = parentProjectItem.ProjectItems.AddFolder(name.UnQuote()); CreateNewFile(folder, name, script); } }
public void CreateSchemas() { IList <ParseError> errors; var fragment = new TSql120Parser(false).Parse(new StringReader(_scripts), out errors); if (fragment == null) { return; } var visitor = new ProcedureVisitor(); fragment.Accept(visitor); foreach (var procedure in visitor.Procedures) { var browser = new SolutionBrowserForm(procedure.ProcedureReference.Name.BaseIdentifier.Value.Quote()); browser.ShowDialog(); var destination = browser.DestinationItem; if (destination == null) { continue; } var parentProjectItem = destination; var name = browser.GetObjectName(); var script = GetScript(name); for (var i = 1; i <= parentProjectItem.ProjectItems.Count; i++) { var item = parentProjectItem.ProjectItems.Item(i); if (item.Name.UnQuote() == name.UnQuote()) { CreateNewFile(item, name, script); return; } } var folder = parentProjectItem.ProjectItems.AddFolder(name.UnQuote()); CreateNewFile(folder, name, script); } foreach (var procedure in visitor.Functions) { var browser = new SolutionBrowserForm(procedure .Name.BaseIdentifier.Value.Quote()); browser.ShowDialog(); var destination = browser.DestinationItem; if (destination == null) { continue; } var parentProjectItem = destination; var name = browser.GetObjectName(); var script = GetScript(name); for (var i = 1; i <= parentProjectItem.ProjectItems.Count; i++) { var item = parentProjectItem.ProjectItems.Item(i); if (item.Name.UnQuote() == name.UnQuote()) { CreateNewFile(item, name, script); return; } } var folder = parentProjectItem.ProjectItems.AddFolder(name.UnQuote()); CreateNewFile(folder, name, script); } }
public void Go() { IList <ParseError> errors; var fragment = new TSql120Parser(false).Parse(new StringReader(_scripts), out errors); if (fragment == null) { return; } var visitor = new ProcedureVisitor(); fragment.Accept(visitor); using (var procedureRepository = new ProcedureRepository(DacpacPath.Get(_sourceProject))) using (var functionRepository = new FunctionRepository(DacpacPath.Get(_sourceProject))) { foreach (var procedure in visitor.Procedures) { var browser = new SolutionBrowserForm("test " + procedure.ProcedureReference.Name.BaseIdentifier.Value.UnQuote() + " does something"); browser.ShowDialog(); var destination = browser.DestinationItem; if (destination == null) { continue; } if (String.IsNullOrEmpty(DacpacPath.Get(_sourceProject)) && !File.Exists(DacpacPath.Get(_sourceProject))) { MessageBox.Show("Cannot find dacpac for project"); return; } var parentProjectItem = destination; var name = browser.GetObjectName(); var proc = procedureRepository.FirstOrDefault(p => p.Name.EqualsName(procedure.ProcedureReference.Name)); if (proc == null) { MessageBox.Show(string.Format("Cannot find stored procedure {0} in project compiled dacpac", procedure.ProcedureReference.Name)); return; } var testBuilder = new ProcedureBuilder(procedure.ProcedureReference.Name.BaseIdentifier.Value.UnQuote(), name, proc); var script = testBuilder.GetScript(); CreateNewFile(parentProjectItem, name, script); } foreach (var procedure in visitor.Functions) { var browser = new SolutionBrowserForm("test " + procedure.Name.BaseIdentifier.Value.UnQuote() + " does something"); browser.ShowDialog(); var destination = browser.DestinationItem; if (destination == null) { continue; } if (String.IsNullOrEmpty(DacpacPath.Get(_sourceProject)) && !File.Exists(DacpacPath.Get(_sourceProject))) { MessageBox.Show("Cannot find dacpac for project"); return; } var parentProjectItem = destination; var name = browser.GetObjectName(); var proc = functionRepository.FirstOrDefault(p => p.Name.EqualsName(procedure.Name)); if (proc == null) { MessageBox.Show(string.Format("Cannot find stored procedure {0} in project compiled dacpac", procedure.Name)); return; } var testBuilder = new ProcedureBuilder(procedure.Name.BaseIdentifier.Value.UnQuote(), name, proc); var script = testBuilder.GetScript(); CreateNewFile(parentProjectItem, name, script); } } }
public void Go(){ IList<ParseError> errors; var fragment = new TSql120Parser(false).Parse(new StringReader(_scripts), out errors); if (fragment == null) return; var visitor = new ProcedureVisitor(); fragment.Accept(visitor); using (var procedureRepository = new ProcedureRepository(DacpacPath.Get(_sourceProject))) using (var functionRepository = new FunctionRepository(DacpacPath.Get(_sourceProject))) { foreach (var procedure in visitor.Procedures) { var browser = new SolutionBrowserForm("test " + procedure.ProcedureReference.Name.BaseIdentifier.Value.UnQuote() + " does something"); browser.ShowDialog(); var destination = browser.DestinationItem; if (destination == null) continue; if (String.IsNullOrEmpty(DacpacPath.Get(_sourceProject)) && !File.Exists(DacpacPath.Get(_sourceProject))) { MessageBox.Show("Cannot find dacpac for project"); return; } var parentProjectItem = destination; var name = browser.GetObjectName(); var proc = procedureRepository.FirstOrDefault(p => p.Name.EqualsName(procedure.ProcedureReference.Name)); if (proc == null) { MessageBox.Show(string.Format("Cannot find stored procedure {0} in project compiled dacpac", procedure.ProcedureReference.Name)); return; } var testBuilder = new ProcedureBuilder(procedure.ProcedureReference.Name.BaseIdentifier.Value.UnQuote(), name, proc); var script = testBuilder.GetScript(); CreateNewFile(parentProjectItem, name , script); } foreach (var procedure in visitor.Functions) { var browser = new SolutionBrowserForm("test " + procedure.Name.BaseIdentifier.Value.UnQuote() + " does something"); browser.ShowDialog(); var destination = browser.DestinationItem; if (destination == null) continue; if (String.IsNullOrEmpty(DacpacPath.Get(_sourceProject)) && !File.Exists(DacpacPath.Get(_sourceProject))) { MessageBox.Show("Cannot find dacpac for project"); return; } var parentProjectItem = destination; var name = browser.GetObjectName(); var proc = functionRepository.FirstOrDefault(p => p.Name.EqualsName(procedure.Name)); if (proc == null) { MessageBox.Show(string.Format("Cannot find stored procedure {0} in project compiled dacpac", procedure.Name)); return; } var testBuilder = new ProcedureBuilder(procedure.Name.BaseIdentifier.Value.UnQuote(), name, proc); var script = testBuilder.GetScript(); CreateNewFile(parentProjectItem, name, script); } } }