Beispiel #1
0
        /// <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;
        }