/// <summary> /// Applies the SQL query by breaking it into stataments and executing one by one inside a transaction. /// </summary> public void ApplyScript() { ErroredOutDataRow = null; ScriptResult = MySqlStatement.StatementResultType.NotApplied; CreateActualStatementsList(); if (ActualStatementRowsList == null || ActualStatementRowsList.Count == 0) { return; } var connectionStringBuilder = _wbConnection.GetConnectionStringBuilder(); connectionStringBuilder.AllowUserVariables = true; using (var conn = new MySqlConnection(connectionStringBuilder.ConnectionString)) { conn.Open(); MySqlTransaction transaction = conn.BeginTransaction(); var command = new MySqlCommand(string.Empty, conn, transaction); uint executionOrder = 1; foreach (var mySqlRow in ActualStatementRowsList) { // Before attempting to execute the MySqlStatement object, check if the connection is still open. if (conn.State != ConnectionState.Open) { ErroredOutDataRow = mySqlRow; ErroredOutDataRow.RowError = Resources.ConnectionLostErrorText; ScriptResult = MySqlStatement.StatementResultType.ConnectionLost; break; } var rowStatement = mySqlRow.Statement; rowStatement.Execute(command, executionOrder++, _useOptimisticUpdate); ScriptResult = rowStatement.JoinResultTypes(ScriptResult); if (ScriptResult.WithoutErrors()) { continue; } ErroredOutDataRow = mySqlRow; if (ScriptResult == MySqlStatement.StatementResultType.ErrorThrown) { // Check if the result was errored out because the connection was broken and if so, flip the ScriptResult to its proper value. if (conn.State != ConnectionState.Open) { ErroredOutDataRow.RowError = Resources.ConnectionLostErrorText; ScriptResult = MySqlStatement.StatementResultType.ConnectionLost; break; } mySqlRow.ReflectError(); } break; } PostApplyScript(transaction); transaction.Dispose(); } }
/// <summary> /// Event delegate method fired when the <see cref="ApplyButton"/> is clicked. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void ApplyButton_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; ApplyScript(); if (ScriptResult.WithoutErrors()) { DialogResult = ScriptResult.WasApplied() ? DialogResult.OK : DialogResult.Cancel; Cursor = Cursors.Default; Close(); return; } // Handle error message thrown back by the server and show it to the user. var errorMessage = ErroredOutDataRow != null ? ErroredOutDataRow.Statement.ResultText : Resources.StatementExecutionGenericError; Cursor = Cursors.Default; MiscUtilities.ShowCustomizedInfoDialog(InfoDialog.InfoType.Error, _errorDialogSummary, errorMessage, false); }