private void WriteTable(string sql) { using var status = WaitStatus.StartRows(Path.GetFileName(_filePath)); var fileMode = _truncateExistingFile ? FileMode.Create : FileMode.Append; using var stream = File.Open(_filePath, fileMode, FileAccess.Write, FileShare.None); using var writer = new StreamWriter(stream, _fileEncoding); using var statement = _notebook.Prepare(sql); var args = statement.GetArgs(_env.Vars); statement.ExecuteStream(args, OnHeader, OnRow, CancellationToken.None); void OnHeader(List <string> columnNames) { if (_headerRow) { writer.WriteLine(string.Join(_separator, columnNames.Select(c => CsvUtil.QuoteCsv(c, _separator)))); } } void OnRow(object[] row) { _cancel.ThrowIfCancellationRequested(); CsvUtil.WriteCsvLine(writer, _separator, row); status.IncrementRows(); } }
private void Execute() { var sql = _inputText.SqlText.Trim(); if (string.IsNullOrWhiteSpace(sql)) { return; } using var output = WaitForm.GoWithCancel(TopLevelControl, "Console", "Executing...", out var success, cancel => { return(SqlUtil.WithCancellation(_manager.Notebook, () => { using var status = WaitStatus.StartRows("Script output"); return _manager.ExecuteScript(sql, onRow: status.IncrementRows); }, cancel)); }); _manager.SetDirty(); _manager.Rescan(); if (!success) { return; } _inputText.SqlText = ""; Log(sql, output); TakeFocus(); }
private void WriteTable(SimpleDataTable sdt) { using var status = WaitStatus.StartRows(Path.GetFileName(_filePath)); var fileMode = _truncateExistingFile ? FileMode.Create : FileMode.Append; using var stream = File.Open(_filePath, fileMode, FileAccess.Write, FileShare.None); using var writer = new StreamWriter(stream, _fileEncoding); if (_headerRow) { writer.WriteLine(string.Join(_separator, sdt.Columns.Select(c => CsvUtil.QuoteCsv(c, _separator)))); } CsvUtil.WriteCsv(sdt.Rows, writer, status.IncrementRows, _separator, _cancel); }