/// <summary> /// Writes to the My SQL Output Tool Window. /// </summary> /// <param name="action">The action.</param> /// <param name="message">The message.</param> /// <param name="duration">The duration.</param> /// <param name="messageType">Type of the message.</param> protected override void WriteToMySqlOutput(string action, string message, string duration, MessageType messageType) { base.WriteToMySqlOutput(action, message, duration, messageType); if (_executionModeOption == ExecutionModeOption.ConsoleMode) { BaseShellConsoleEditor.AddMessage(message); } }
/// <summary> /// Prints a <see cref="DocResult"/> in the output window showing extended information about the execution result (documents returned, execution time, etc.). /// </summary> /// <param name="statement">The executed statement.</param> /// <param name="dictionariesList">A list of dictionaries of results and information about them.</param> /// <param name="executionTime">Execution time formatted to seconds.</param> private void PrintGenericResult(string statement, List <Dictionary <string, object> > dictionariesList, string executionTime) { var count = dictionariesList != null ? dictionariesList.Count : 0; switch (_executionModeOption) { case ExecutionModeOption.BatchMode: if (dictionariesList != null && count > 0) { CreateResultPane(dictionariesList, _tabCounter); _tabCounter++; } break; case ExecutionModeOption.ConsoleMode: if (dictionariesList == null) { break; } foreach (var rowData in dictionariesList) { var sb = new StringBuilder(); sb.AppendLine("{"); int i = 0; var rowDataCount = rowData.Count; foreach (var kvp in rowData) { sb.AppendFormat("\t\"{0}\": \"{1}\"{2}{3}", kvp.Key, kvp.Value, i == rowDataCount - 1 ? "" : ",", Environment.NewLine); i++; } sb.AppendLine("},"); BaseShellConsoleEditor.AddMessage(sb.ToString()); } break; } WriteToMySqlOutput(statement, string.Format("{0} documents in set.", count), executionTime, MessageType.Information); }
/// <summary> /// Prints a <see cref="RowResult"/> in the output window showing extended information about the execution result (rows returned, execution time, etc.). /// </summary> /// <param name="statement">The executed statement.</param> /// <param name="rowResult">A <see cref="RowResult"/> instance.</param> private void PrintRowResult(string statement, RowResult rowResult) { string executionTime = rowResult.ExecutionTime; var dictionariesList = rowResult.Data; var count = dictionariesList != null ? dictionariesList.Count : 0; switch (_executionModeOption) { case ExecutionModeOption.BatchMode: if (dictionariesList != null && count > 0) { CreateResultPane(dictionariesList, _tabCounter); _tabCounter++; } break; case ExecutionModeOption.ConsoleMode: if (dictionariesList == null) { break; } // Get columns names var columns = rowResult.GetColumnNames(); // Create console table object for output format var table = new ConsoleTable(columns.ToArray()); foreach (var rowData in dictionariesList) { object[] columnValues = rowData.Select(o => o.Value == null ? (object)"null" : o.Value.ToString()).ToArray(); var formattedColumnValues = new List <Object>(); //Format values foreach (var value in rowData.Values) { if (value is Dictionary <string, object> ) { formattedColumnValues.Add(Utils.GetFormattedValue(value)); continue; } formattedColumnValues.Add(value); } table.AddRow(formattedColumnValues.ToArray()); } if (table.Rows.Count > 0) { BaseShellConsoleEditor.AddMessage(table.ToStringAlternative()); } break; } var resultMessage = new StringBuilder(); // If no items are returned, it is a DDL statement (Drop, Create, etc.) if (count == 0) { var sqlResult = rowResult as SqlResult; if (sqlResult != null) { resultMessage.AppendFormat("Query OK, {0} row(s) affected, {1} warning(s)", sqlResult.AffectedRowCount, rowResult.WarningCount); } else { resultMessage.AppendFormat("Query OK, {0} warning(s)", rowResult.WarningCount); } } else { resultMessage.AppendFormat("{0} row(s) in set.", count); } WriteToMySqlOutput(statement, resultMessage.ToString(), executionTime, MessageType.Information); PrintWarnings(statement, rowResult, executionTime); }