private void OnQueryExecuted(ScriptStatement statement)
 {
     if (StatementExecuted != null)
     {
         MyCatScriptEventArgs args = new MyCatScriptEventArgs();
         args.Statement = statement;
         StatementExecuted(this, args);
     }
 }
        private List <ScriptStatement> BreakIntoStatements(bool ansiQuotes, bool noBackslashEscapes)
        {
            string currentDelimiter            = Delimiter;
            int    startPos                    = 0;
            List <ScriptStatement> statements  = new List <ScriptStatement>();
            List <int>             lineNumbers = BreakScriptIntoLines();
            MyCatTokenizer         tokenizer   = new MyCatTokenizer(query);

            tokenizer.AnsiQuotes       = ansiQuotes;
            tokenizer.BackslashEscapes = !noBackslashEscapes;

            string token = tokenizer.NextToken();

            while (token != null)
            {
                if (!tokenizer.Quoted)
                {
                    if (token.ToLower() == "delimiter")
                    {
                        tokenizer.NextToken();
                        AdjustDelimiterEnd(tokenizer);
                        currentDelimiter = query.Substring(tokenizer.StartIndex,
                                                           tokenizer.StopIndex - tokenizer.StartIndex).Trim();
                        startPos = tokenizer.StopIndex;
                    }
                    else
                    {
                        // this handles the case where our tokenizer reads part of the
                        // delimiter
                        if (currentDelimiter.StartsWith(token, StringComparison.OrdinalIgnoreCase))
                        {
                            if ((tokenizer.StartIndex + currentDelimiter.Length) <= query.Length)
                            {
                                if (query.Substring(tokenizer.StartIndex, currentDelimiter.Length) == currentDelimiter)
                                {
                                    token = currentDelimiter;
                                    tokenizer.Position  = tokenizer.StartIndex + currentDelimiter.Length;
                                    tokenizer.StopIndex = tokenizer.Position;
                                }
                            }
                        }

                        int delimiterPos = token.IndexOf(currentDelimiter, StringComparison.OrdinalIgnoreCase);
                        if (delimiterPos != -1)
                        {
                            int endPos = tokenizer.StopIndex - token.Length + delimiterPos;
                            if (tokenizer.StopIndex == query.Length - 1)
                            {
                                endPos++;
                            }
                            string          currentQuery = query.Substring(startPos, endPos - startPos);
                            ScriptStatement statement    = new ScriptStatement();
                            statement.text     = currentQuery.Trim();
                            statement.line     = FindLineNumber(startPos, lineNumbers);
                            statement.position = startPos - lineNumbers[statement.line];
                            statements.Add(statement);
                            startPos = endPos + currentDelimiter.Length;
                        }
                    }
                }
                token = tokenizer.NextToken();
            }

            // now clean up the last statement
            if (startPos < query.Length - 1)
            {
                string sqlLeftOver = query.Substring(startPos).Trim();
                if (!String.IsNullOrEmpty(sqlLeftOver))
                {
                    ScriptStatement statement = new ScriptStatement();
                    statement.text     = sqlLeftOver;
                    statement.line     = FindLineNumber(startPos, lineNumbers);
                    statement.position = startPos - lineNumbers[statement.line];
                    statements.Add(statement);
                }
            }
            return(statements);
        }