private void RefreshUIFromDatabase() { try { _server = DataAccessPortal.GetInstance() .ExpectServer(_collection.GetDataAccessPoint(), DataAccessContext.InternalDataProcessing); string sql = _collection.GetSql(); _originalSql = sql; //update the editor to show the user the SQL _scintilla.Text = sql; _server.TestConnection(); LoadDataTableAsync(_server, sql); } catch (QueryBuildingException ex) { ragSmiley1.SetVisible(true); ragSmiley1.Fatal(ex); } catch (Exception ex) { ragSmiley1.SetVisible(true); ragSmiley1.Fatal(ex); } }
public override void ShowData(IViewSQLAndResultsCollection collection) { var point = collection.GetDataAccessPoint(); var db = DataAccessPortal.GetInstance().ExpectDatabase(point, DataAccessContext.InternalDataProcessing); var toRun = new ExtractTableVerbatim(db.Server, collection.GetSql(), Console.OpenStandardOutput(), ",", null); toRun.DoExtraction(); }
/// <summary> /// Runs the query described in <paramref name="collection"/> and extracts the data into <paramref name="toFile"/> /// </summary> /// <param name="collection"></param> /// <param name="toFile"></param> /// <param name="context">Determines which access credentials (if any) are used to run the query</param> public static void ExtractDataToFile(IViewSQLAndResultsCollection collection, FileInfo toFile, DataAccessContext context = DataAccessContext.InternalDataProcessing) { var point = collection.GetDataAccessPoint(); var db = DataAccessPortal.GetInstance().ExpectDatabase(point, context); using (var fs = File.OpenWrite(toFile.FullName)) { var toRun = new ExtractTableVerbatim(db.Server, collection.GetSql(), fs, ",", null); toRun.DoExtraction(); } }
public ConsoleGuiSqlEditor(IBasicActivateItems activator, IViewSQLAndResultsCollection collection) { this.Activator = activator; this._collection = collection; Modal = true; ColorScheme = ConsoleMainWindow.ColorScheme; // Tabs (query and results) TabView = new TabView() { Width = Dim.Fill(), Height = Dim.Fill(), Y = 1 }; textView = new SqlTextView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill(), Text = _orignalSql = collection.GetSql().Replace("\r\n", "\n").Replace("\t", " ") }; textView.AllowsTab = false; TabView.AddTab(queryTab = new Tab("Query", textView), true); tableView = new TableView() { X = 0, Y = 0, Width = Dim.Fill(), Height = Dim.Fill() }; tableView.Style.AlwaysShowHeaders = true; tableView.CellActivated += TableView_CellActivated; TabView.AddTab(resultTab = new Tab("Results", tableView), false); Add(TabView); // Buttons on top of control _btnRunOrCancel = new Button("Run") { X = 0, Y = 0, }; _btnRunOrCancel.Clicked += () => RunOrCancel(); Add(_btnRunOrCancel); var resetSql = new Button("Reset Sq_l") { X = Pos.Right(_btnRunOrCancel) + 1 }; resetSql.Clicked += () => ResetSql(); Add(resetSql); var clearSql = new Button("Clear S_ql") { X = Pos.Right(resetSql) + 1, }; clearSql.Clicked += () => ClearSql(); Add(clearSql); var lblTimeout = new Label("Timeout:") { X = Pos.Right(clearSql) + 1, }; Add(lblTimeout); var tbTimeout = new TextField(_timeout.ToString()) { X = Pos.Right(lblTimeout), Width = 5 }; tbTimeout.TextChanged += TbTimeout_TextChanged; Add(tbTimeout); var btnSave = new Button("Save") { X = Pos.Right(tbTimeout) + 1, }; btnSave.Clicked += () => Save(); Add(btnSave); var btnClose = new Button("Clos_e") { X = Pos.Right(btnSave) + 1, }; btnClose.Clicked += () => { Application.RequestStop(); }; Add(btnClose); var auto = new AutoCompleteProvider(collection.GetQuerySyntaxHelper()); collection.AdjustAutocomplete(auto); var bits = auto.Items.SelectMany(auto.GetBits).OrderBy(a => a).Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList(); textView.Autocomplete.AllSuggestions = bits; textView.Autocomplete.MaxWidth = 40; }