public async Task SaveExecutionResult(StatementExecutionBatchResult executionResult)
        {
            IsWaitingForResult = false;
            IsExecuting        = true;

            _exportClockTimer.Start();
            _exportResultInfoCollection.Clear();

            var commandNumber = 0;

            foreach (var statementResult in executionResult.StatementResults)
            {
                commandNumber++;

                var resultNumber = 0;
                foreach (var kvp in statementResult.ResultInfoColumnHeaders)
                {
                    resultNumber++;
                    var exportResultInfo = new ExportResultInfo(commandNumber, resultNumber, kvp.Key, kvp.Value);
                    _exportResultInfoCollection.Add(exportResultInfo);
                }
            }

            var exception = await App.SafeActionAsync(() => _outputViewer.ExecuteUsingCancellationToken(ExportRows));

            _exportClockTimer.Stop();

            IsExecuting = false;

            if (exception != null)
            {
                TraceLog.WriteLine($"Saving result to file failed: {exception}");

                CancelWaitingResults();

                Messages.ShowError(exception.Message);
            }
        }
 public StatementExecutionException(StatementExecutionBatchResult batchResult, Exception inner) : base(inner.Message, inner)
 {
     BatchResult = batchResult;
 }
Exemple #3
0
        private async Task ExecuteDatabaseCommandAsyncInternal(StatementBatchExecutionModel executionModel)
        {
            if (executionModel.Statements.Count == 0)
            {
                return;
            }

            var beforeExecutionText = DocumentPage.Editor.Text;

            Initialize();

            FileResultViewer.Initialize();

            ConnectionAdapter.EnableDatabaseOutput = EnableDatabaseOutput;

            Task <StatementExecutionBatchResult> innerTask = null;
            var actionResult = await SafeTimedActionAsync(() => innerTask = ConnectionAdapter.ExecuteStatementAsync(executionModel, _statementExecutionCancellationTokenSource.Token));

            HasActiveTransaction  = ConnectionAdapter.HasActiveTransaction;
            TransactionIdentifier = ConnectionAdapter.TransanctionIdentifier;

            if (!actionResult.IsSuccessful)
            {
                if (actionResult.Exception is StatementExecutionException executionException)
                {
                    UpdateExecutionLog(executionException.BatchResult.StatementResults);
                    WriteDatabaseOutput(executionException.BatchResult.DatabaseOutput);

                    var lastStatementResult = executionException.BatchResult.StatementResults.Last();
                    var errorPosition       = lastStatementResult.ErrorPosition;
                    if (errorPosition.HasValue && String.Equals(beforeExecutionText, DocumentPage.Editor.Text))
                    {
                        DocumentPage.Editor.CaretOffset = lastStatementResult.StatementModel.Statement.RootNode.SourcePosition.IndexStart + errorPosition.Value;
                    }
                }

                Messages.ShowError(actionResult.Exception.Message);
                return;
            }

            _executionResult = innerTask.Result;

            if (ConnectionAdapter.DebuggerSession != null)
            {
                DebuggerViewer.Initialize(this, ConnectionAdapter.DebuggerSession);
                ConnectionAdapter.DebuggerSession.Attached += delegate { Dispatcher.Invoke(DebuggerSessionSynchronizedHandler); };
                ConnectionAdapter.DebuggerSession.Detached += DebuggerSessionDetachedHandler;
                var exception = await App.SafeActionAsync(() => ConnectionAdapter.DebuggerSession.Start(_statementExecutionCancellationTokenSource.Token));

                if (exception != null)
                {
                    Messages.ShowError(exception.Message);
                }

                return;
            }

            UpdateExecutionLog(_executionResult.StatementResults);

            UpdateHistoryEntries();

            if (_executionResult.StatementResults.Last().ExecutedSuccessfully == false)
            {
                NotifyExecutionCanceled();
                return;
            }

            UpdateTimerMessage(actionResult.Elapsed, false);

            await DisplayExecutionResult();
        }