示例#1
0
        private async Task ExecuteExplainPlanAsyncInternal(StatementExecutionModel executionModel)
        {
            InitializeCommon();

            var actionResult = await SafeTimedActionAsync(() => ExecutionPlanViewer.ExplainAsync(executionModel, _statementExecutionCancellationTokenSource.Token));

            if (_statementExecutionCancellationTokenSource.Token.IsCancellationRequested)
            {
                NotifyExecutionCanceled();
            }
            else
            {
                UpdateTimerMessage(actionResult.Elapsed, false);

                if (actionResult.IsSuccessful)
                {
                    ShowExecutionPlan();
                }
                else
                {
                    var errorMessage = Messages.GetExceptionErrorMessage(actionResult.Exception);
                    AddExecutionLog(actionResult.ExecutedAt, $"Explain plain failed: {errorMessage}");
                    Messages.ShowError(errorMessage);
                }
            }
        }
        public static void Generate(StatementExecutionModel statementModel, IReadOnlyList <ColumnHeader> columnHeaders, TextWriter writer)
        {
            var columnMapBuilder         = new StringBuilder();
            var resultRowPropertyBuilder = new StringBuilder();
            var bindVariableBuilder      = new StringBuilder();
            var parameterBuilder         = new StringBuilder();

            var index = 0;

            if (statementModel.BindVariables.Count > 0)
            {
                parameterBuilder.AppendLine();

                foreach (var bindVariable in statementModel.BindVariables)
                {
                    index++;

                    bindVariableBuilder.Append(bindVariable.InputType.Name);
                    bindVariableBuilder.Append(" ");
                    bindVariableBuilder.Append(bindVariable.Name);

                    if (index < statementModel.BindVariables.Count)
                    {
                        bindVariableBuilder.Append(", ");
                    }

                    var parameterName = $"parameter{bindVariable.Name}";
                    parameterBuilder.Append("\t\t\tvar ");
                    parameterBuilder.Append(parameterName);
                    parameterBuilder.AppendLine(" = command.CreateParameter();");
                    parameterBuilder.Append("\t\t\t");
                    parameterBuilder.Append(parameterName);
                    parameterBuilder.Append(".Value = ");
                    parameterBuilder.Append(bindVariable.Name);
                    parameterBuilder.AppendLine(";");
                    parameterBuilder.Append("\t\t\tcommand.Parameters.Add(");
                    parameterBuilder.Append(parameterName);
                    parameterBuilder.AppendLine(");");
                    parameterBuilder.AppendLine();
                }
            }

            index = 0;
            foreach (var column in columnHeaders)
            {
                index++;

                var dataTypeName = String.Equals(column.DataType.Namespace, "System")
                                        ? column.DataType.Name
                                        : column.DataType.FullName;

                if (column.DataType.IsValueType)
                {
                    dataTypeName = $"{dataTypeName}?";
                }

                columnMapBuilder.Append("\t\t\t\t\t\t\t");
                columnMapBuilder.Append(column.Name);
                columnMapBuilder.Append(" = GetReaderValue<");
                columnMapBuilder.Append(dataTypeName);
                columnMapBuilder.Append(">(reader[nameof(ResultRow.");
                columnMapBuilder.Append(column.Name);
                columnMapBuilder.Append(")])");

                if (index < columnHeaders.Count)
                {
                    columnMapBuilder.AppendLine(",");
                }

                resultRowPropertyBuilder.Append("\tpublic ");
                resultRowPropertyBuilder.Append(dataTypeName);
                resultRowPropertyBuilder.Append(" ");
                resultRowPropertyBuilder.Append(column.Name);
                resultRowPropertyBuilder.AppendLine(" { get; set; }");
            }

            var statementText = statementModel.StatementText.Replace("\"", "\"\"");
            var queryClass    = String.Format(ExportClassTemplate, statementText, bindVariableBuilder, parameterBuilder, columnMapBuilder);

            writer.WriteLine(queryClass);
            writer.WriteLine("public class ResultRow");
            writer.WriteLine("{");
            writer.Write(resultRowPropertyBuilder);
            writer.WriteLine("}");
        }
示例#3
0
        private async Task BuildParentRecordDataGrid(Panel container, string objectName, StatementExecutionModel executionModel, CancellationToken cancellationToken)
        {
            var executionResult = await _connectionAdapter.ExecuteChildStatementAsync(executionModel, cancellationToken);

            await _statementValidator.ApplyReferenceConstraintsAsync(executionResult, _connectionAdapter.DatabaseModel, cancellationToken);

            var resultInfo = executionResult.ResultInfoColumnHeaders.Keys.Last();
            var resultSet  = await _connectionAdapter.FetchRecordsAsync(resultInfo, ConfigurationProvider.Configuration.ResultGrid.FetchRowsBatchSize, cancellationToken);

            if (resultSet.Count == 0)
            {
                container.Children.Add(new TextBlock {
                    Text = "Record not found. "
                });
                return;
            }

            var firstRow      = resultSet[0];
            var columnHeaders = executionResult.ResultInfoColumnHeaders.Values.Last();
            var columnValues  = columnHeaders.Select(
                (t, i) => new CustomTypeAttributeValue
            {
                ColumnHeader = t,
                Value        = firstRow[i]
            }).ToArray();

            var referenceDataGrid =
                new DataGrid
            {
                Style                 = (Style)Application.Current.Resources["ResultSetDataGrid"],
                RowHeaderWidth        = 0,
                CanUserReorderColumns = false,
                ItemsSource           = columnValues,
                CanUserSortColumns    = true
            };

            referenceDataGrid.BeginningEdit    += App.DataGridBeginningEditCancelTextInputHandlerImplementation;
            referenceDataGrid.Sorting          += (sender, args) => args.Handled = args.Column.DisplayIndex != 0;
            referenceDataGrid.MouseDoubleClick += ReferenceDataGridOnMouseDoubleClickHandler;

            var columnNameTemplate =
                new DataGridTextColumn
            {
                Header              = "Column name",
                Binding             = new Binding("ColumnHeader.Name"),
                HeaderStyle         = (Style)Application.Current.Resources["ColumnHeaderClickBubbleCancelation"],
                ElementStyle        = (Style)Application.Current.Resources["SingleRecordColumnName"],
                CellStyle           = (Style)Application.Current.Resources["SingleRecordCell"],
                EditingElementStyle = (Style)Application.Current.Resources["EditingCellTextBox"]
            };

            referenceDataGrid.Columns.Add(columnNameTemplate);

            var columnHyperlinkValueTemplate =
                new DataGridTemplateColumn
            {
                Header                  = ValueProperty,
                HeaderStyle             = (Style)Application.Current.Resources["ColumnHeaderClickBubbleCancelation"],
                CellTemplateSelector    = new SingleRowDataTemplateSelector(_statementValidator, _connectionAdapter),
                CellEditingTemplate     = EditingTemplate,
                ClipboardContentBinding = new Binding(ValueProperty)
                {
                    Converter = CellValueConverter.Instance
                }
            };

            referenceDataGrid.Columns.Add(columnHyperlinkValueTemplate);

            var textBlock = new TextBlock {
                Text = $"Source: {objectName}", Margin = DataGridHelper.DefaultTextBlockMargin, HorizontalAlignment = HorizontalAlignment.Left
            };

            container.Children.Add(textBlock);
            container.Children.Add(referenceDataGrid);
        }
示例#4
0
 public Task ExecuteExplainPlanAsync(StatementExecutionModel executionModel)
 {
     return(ExecuteUsingCancellationToken(t => ExecuteExplainPlanAsyncInternal(executionModel)));
 }