/// <summary> /// Event delegate method fired when the <see cref="QueryTextBox"/> has been validated. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> private void QueryTextBox_Validated(object sender, EventArgs e) { if (!QueryChangedTimer.Enabled) { return; } QueryChangedTimer.Stop(); // Identify the statements that would exceed the server's max allowed packet value and highlight them for the user. string queryText = QueryTextBox.Text.Trim(); if (queryText.Length <= 0) { return; } QueryTextBox.ReadOnly = true; Cursor = Cursors.WaitCursor; bool statementsExceedingMaxAllowedPacketValueFound = false; bool reachedEnd = false; int statementStartPosition = 0; do { int statementEndPosition = queryText.IndexOf(";", statementStartPosition, StringComparison.Ordinal); if (statementEndPosition < 0) { reachedEnd = true; statementEndPosition = queryText.Length - 1; } // Get SQL statement string sqlStatement = queryText.Substring(statementStartPosition, statementEndPosition - statementStartPosition).Trim(); // TODO: Split statement in tokens using MySQL parser classes and paint them accordingly. // Highlight the statement if it exceeds the MySQL Servers's max allowed packet value. if (sqlStatement.ExceedsMySqlMaxAllowedPacketValue(MySqlMaxAllowedPacket)) { QueryTextBox.Select(statementStartPosition, statementEndPosition - statementStartPosition); QueryTextBox.SelectionBackColor = Color.GreenYellow; statementsExceedingMaxAllowedPacketValueFound = true; } statementStartPosition = statementEndPosition + 1; reachedEnd = reachedEnd || statementStartPosition >= queryText.Length; }while (!reachedEnd); QueryWarningPictureBox.Visible = statementsExceedingMaxAllowedPacketValueFound; QueryWarningLabel.Visible = statementsExceedingMaxAllowedPacketValueFound; QueryTextBox.ReadOnly = false; OriginalQueryButton.Enabled = !string.Equals(OriginalSqlScript, SqlScript, StringComparison.InvariantCultureIgnoreCase); ApplyButton.Enabled = SqlScript.Trim().Length > 0; Cursor = Cursors.Default; }
/// <summary> /// Initializes a new instance of the <see cref="MySqlScriptDialog"/> class. /// </summary> /// <param name="wbConnection">The connection to a MySQL server instance selected by users.</param> /// <param name="sqlScript">The proposed SQL query for user review and possible modification.</param> /// <param name="operationsInfoText">The text showing original operations information reflected on the SQL script.</param> /// <param name="useOptimisticUpdate">Flag indicating whether optimistic locking is used for the update of rows.</param> public MySqlScriptDialog(MySqlWorkbenchConnection wbConnection, string sqlScript, string operationsInfoText, bool useOptimisticUpdate = false) : this() { _errorDialogSummary = Resources.ScriptErrorThrownSummary; _operationsInfoText = operationsInfoText; _showOriginalOperationsInformation = !string.IsNullOrEmpty(_operationsInfoText); _useOptimisticUpdate = useOptimisticUpdate; _wbConnection = wbConnection; OriginalSqlScript = sqlScript; SqlScript = OriginalSqlScript; CreateOriginalStatementsList(); ApplyButton.Enabled = SqlScript.Trim().Length > 0; SetOriginalOperationsInfoAvailability(); }
/// <summary> /// Initializes a new instance of the <see cref="MySqlScriptDialog"/> class. /// </summary> /// <param name="mySqlTable">The <see cref="MySqlDataTable"/> object containing data changes to be committed to the database.</param> /// <param name="refreshRowsDataAfterPush">Flag indicating whether rows data is refreshed after their push operation is executed.</param> public MySqlScriptDialog(MySqlDataTable mySqlTable, bool refreshRowsDataAfterPush) : this() { if (mySqlTable != null) { switch (mySqlTable.OperationType) { case MySqlDataTable.DataOperationType.Export: _errorDialogSummary = string.Format(Resources.ExportDataGenericErrorText, mySqlTable.TableName); break; case MySqlDataTable.DataOperationType.Append: _errorDialogSummary = string.Format(Resources.AppendDataDetailsDoneErrorText, mySqlTable.TableName); break; case MySqlDataTable.DataOperationType.Edit: _errorDialogSummary = string.Format(Resources.EditedDataForTable, mySqlTable.TableName) + Resources.EditedDataCommittedError; break; default: _errorDialogSummary = Resources.ScriptErrorThrownSummary; break; } _mySqlTable = mySqlTable; _refreshRowsDataAfterPush = refreshRowsDataAfterPush; _showOriginalOperationsInformation = true; _useOptimisticUpdate = _mySqlTable.UseOptimisticUpdate; _wbConnection = _mySqlTable.WbConnection; CreateOriginalStatementsList(); SetOriginalOperationsInfoAvailability(); } SqlScript = OriginalSqlScript; ApplyButton.Enabled = SqlScript.Trim().Length > 0; }