コード例 #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;
        }
コード例 #2
0
 /// <summary>
 /// Event delegate method fired when the <see cref="QueryChangedTimer"/> text changes.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="e">Event arguments.</param>
 private void QueryChangedTimer_Tick(object sender, EventArgs e)
 {
     if (QueryTextBox.Focused)
     {
         QueryTextBox_Validated(QueryTextBox, EventArgs.Empty);
     }
     else
     {
         // The code should never hit this block in which case there is something wrong.
         MySqlSourceTrace.WriteToLog("QueryChangedTimer's Tick event fired but no valid control had focus.");
         QueryChangedTimer.Stop();
     }
 }
コード例 #3
0
 /// <summary>
 /// Resets the timer used on query text changes only if there was a user input.
 /// </summary>
 private void ResetQueryChangedTimer()
 {
     QueryChangedTimer.Stop();
     QueryChangedTimer.Start();
 }