public override void ExecuteCommand(CancellationToken token) { var options = new PeterHenell.SSMS.Plugins.Utils.TsqltManager.MockOptionsDictionary(); var ok = new Action <string, PeterHenell.SSMS.Plugins.Utils.TsqltManager.MockOptionsDictionary>((result, checkedOptions) => { int numRows = 0; if (!int.TryParse(result, out numRows)) { ShellManager.ShowMessageBox("Please input a valid number"); return; } else { if (numRows <= 0) { numRows = 0; } else if (numRows > 1000) { numRows = 1000; } } var selectedText = ShellManager.GetSelectedText(); StringBuilder sb = new StringBuilder(); var connectionString = ConnectionManager.GetConnectionStringForCurrentWindow(); var meta = ObjectMetadata.FromQualifiedString(selectedText); sb.AppendLine(TsqltManager.MockTableWithRows(token, options, numRows, meta, connectionString)); ShellManager.ReplaceSelectionWith(sb.ToString()); }); var diagManager = new DialogManager.InputWithCheckboxesDialogManager <PeterHenell.SSMS.Plugins.Utils.TsqltManager.MockOptionsDictionary>(); diagManager.Show("How many rows to select? (0=max)", "1", options, ok, cancelCallback); }
public override void ExecuteCommand(CancellationToken token) { var options = new MockOptionsDictionary(); var ok = new Action <string, MockOptionsDictionary>((result, checkedOptions) => { int numRows = 0; if (!int.TryParse(result, out numRows)) { ShellManager.ShowMessageBox("Please input a valid number"); return; } else { if (numRows <= 0) { numRows = 0; } else if (numRows > 1000) { numRows = 1000; } } string selectedText = ShellManager.GetSelectedText(); var sb = new StringBuilder(); using (var ds = new DataSet()) { QueryManager.Run(ConnectionManager.GetConnectionStringForCurrentWindow(), token, (queryManager) => { queryManager.Fill(string.Format("SET ROWCOUNT {0}; {1}", numRows, selectedText), ds); }); if (ds.Tables.Count == 1) { sb.AppendDropTempTableIfExists("#Actual"); sb.AppendLine(); sb.AppendDropTempTableIfExists("#Expected"); sb.AppendLine(); sb.AppendTempTablesFor(ds.Tables[0], "#Actual"); sb.Append("INSERT INTO #Actual"); ShellManager.AddTextToTopOfSelection(sb.ToString()); sb.Clear(); sb.AppendColumnNameList(ds.Tables[0]); ShellManager.AppendToEndOfSelection( string.Format("{0}SELECT {1}INTO #Expected{0}FROM #Actual{0}WHERE 1=0;{0}", Environment.NewLine, sb.ToString()) ); ShellManager.AppendToEndOfSelection( TsqltManager.GenerateInsertFor(ds.Tables[0], ObjectMetadata.FromQualifiedString("#Expected"), false, false)); } else { return; } } //var meta = ObjectMetadata.FromQualifiedString(selectedText); //ObjectMetadataAccess da = new ObjectMetadataAccess(ConnectionManager.GetConnectionStringForCurrentWindow()); //var table = da.SelectTopNFrom(meta, numRows); //StringBuilder sb = new StringBuilder(); //sb.Append(TsqltManager.GetFakeTableStatement(selectedText)); //sb.AppendLine(); //sb.Append(TsqltManager.GenerateInsertFor(table, meta, options.EachColumnInSelectOnNewRow, options.EachColumnInValuesOnNewRow)); //shellManager.ReplaceSelectionWith(sb.ToString()); }); var diagManager = new DialogManager.InputWithCheckboxesDialogManager <MockOptionsDictionary>(); diagManager.Show("How many rows to select? (0=max)", "1", options, ok, cancelCallback); }