private string Execute(string sql) { _manager.PushStatus("Running console command..."); _manager.CommitOpenEditors(); string response; try { Dictionary <string, object> newVars; var result = _manager.ExecuteScriptEx(sql, _variables, true, out newVars); _variables = newVars; UpdateConsoleState(); _manager.SetDirty(); _manager.Rescan(); var parts = new List <string>(); if (result.ScalarResult == null && !result.TextOutput.Any() && !result.DataTables.Any()) { parts.Add("<div style=\"overflow: hidden;\"> </div>"); } if (result.ScalarResult != null) { parts.Add( "<div style=\"overflow: hidden;\">" + $"Returned: {WebUtility.HtmlEncode(result.ScalarResult.ToString())}" + "</div>" ); } if (result.TextOutput.Any()) { parts.Add( "<div style=\"overflow: hidden; overflow-x: auto; padding-bottom: 18px;\"><pre style=\"margin: 0; padding: 0;\"><font face=\"Segoe UI\" size=\"2\">" + string.Join("<br>", result.TextOutput.Select(WebUtility.HtmlEncode)) + "</font></pre></div>" ); } var sb = new StringBuilder(); // inline the CSS so it gets included when the user copies tables to the clipboard var cellCss = "border: 1px solid rgb(229, 229, 229); padding: 3px; padding-left: 6px; " + "padding-right: 6px; text-align: left; vertical-align: top; font: 'Segoe UI' 9pt; " + "max-height: 100px; overflow-y: auto;"; foreach (var dt in result.DataTables) { sb.Append("<div style=\"overflow-x: auto; overflow-y: hidden; padding-bottom: 18px;\">"); sb.Append("<table style=\"border-collapse: collapse;\"><thead><tr>"); foreach (var col in dt.Columns) { sb.Append($"<td style=\"{cellCss}\"><pre style=\"margin: 0; padding: 0;\">" + $"<font face=\"Segoe UI\" size=\"2\"><b>{WebUtility.HtmlEncode(col)}</b></font></pre></td>"); } sb.Append("</tr></thead><tbody>"); int count = 0; foreach (var row in dt.Rows) { if (count >= 100) { break; } sb.Append("<tr>"); foreach (var cell in row) { string cellText = cell.ToString(); var cellBytes = cell as byte[]; if (cellBytes != null) { if (ArrayUtil.IsSqlArray(cellBytes)) { cellText = "[" + string.Join(", ", ArrayUtil.GetArrayElements(cellBytes)) + "]"; } } sb.Append($"<td style=\"{cellCss}\"><pre style=\"margin:0; padding:0;\">" + $"<font face=\"Segoe UI\" size=\"2\">{WebUtility.HtmlEncode(cellText)}</font></pre></td>"); } sb.Append("</tr>"); count++; } sb.Append("</tbody></table></div>"); if (dt.Rows.Count > 100) { sb.Append($"<div>Table has {dt.Rows.Count} rows, showing 100.</div>"); } } parts.Add(sb.ToString()); var html = string.Join("", parts); response = html; } catch (Exception ex) { response = $"<div style=\"overflow: hidden; color: red;\">{WebUtility.HtmlEncode(ex.Message)}</div>"; } _manager.PopStatus(); return($"<div class=\"response\">{response}</div>"); }