private void OnQueryExecuted(ScriptStatement statement) { if (StatementExecuted != null) { MySqlScriptEventArgs args = new MySqlScriptEventArgs(); args.Statement = statement; StatementExecuted(this, args); } }
private List <ScriptStatement> BreakIntoStatements(bool ansiQuotes, bool noBackslashEscapes) { int startPos = 0; List <ScriptStatement> statements = new List <ScriptStatement>(); List <int> lineNumbers = BreakScriptIntoLines(); SqlTokenizer tokenizer = new SqlTokenizer(query); tokenizer.AnsiQuotes = ansiQuotes; tokenizer.BackslashEscapes = !noBackslashEscapes; string token = tokenizer.NextToken(); while (token != null) { if (!tokenizer.Quoted && !tokenizer.IsSize) { int delimiterPos = token.IndexOf(Delimiter); if (delimiterPos != -1) { int endPos = tokenizer.Index - token.Length + delimiterPos; if (tokenizer.Index == 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 + delimiter.Length; } } token = tokenizer.NextToken(); } // now clean up the last statement if (tokenizer.Index > startPos) { 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); }
private void OnQueryExecuted(ScriptStatement statement) { if (StatementExecuted == null) { return; } MySqlScriptEventArgs args = new MySqlScriptEventArgs { 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(); MySqlTokenizer tokenizer = new MySqlTokenizer(query); tokenizer.AnsiQuotes = ansiQuotes; tokenizer.BackslashEscapes = !noBackslashEscapes; string token = tokenizer.NextToken(); while (token != null) { if (!tokenizer.Quoted) { if (token.ToLower(CultureInfo.InvariantCulture) == "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; }
private List <ScriptStatement> BreakIntoStatements(bool ansiQuotes, bool noBackslashEscapes) { string currentDelimiter = Delimiter; int startPos = 0; List <ScriptStatement> statements = new List <ScriptStatement>(); List <int> lineNumbers = BreakScriptIntoLines(); MySqlTokenizer tokenizer = new MySqlTokenizer(query); tokenizer.AnsiQuotes = ansiQuotes; tokenizer.BackslashEscapes = !noBackslashEscapes; string token = tokenizer.NextToken(); while (token != null) { if (!tokenizer.Quoted) { if (token.ToLower(CultureInfo.InvariantCulture) == "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); }
private List<ScriptStatement> BreakIntoStatements(bool ansiQuotes, bool noBackslashEscapes) { int startPos = 0; List<ScriptStatement> statements = new List<ScriptStatement>(); List<int> lineNumbers = BreakScriptIntoLines(); SqlTokenizer tokenizer = new SqlTokenizer(query); tokenizer.AnsiQuotes = ansiQuotes; tokenizer.BackslashEscapes = !noBackslashEscapes; string token = tokenizer.NextToken(); while (token != null) { if (!tokenizer.Quoted && !tokenizer.IsSize) { int delimiterPos = token.IndexOf(Delimiter); if (delimiterPos != -1) { int endPos = tokenizer.Index - token.Length + delimiterPos; if (tokenizer.Index == 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 + delimiter.Length; } } token = tokenizer.NextToken(); } // now clean up the last statement if (tokenizer.Index > startPos) { 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; }
private List <ScriptStatement> BreakIntoStatements(bool ansiQuotes, bool noBackslashEscapes) { string text = this.Delimiter; int num = 0; List <ScriptStatement> list = new List <ScriptStatement>(); List <int> list2 = this.BreakScriptIntoLines(); MySqlTokenizer mySqlTokenizer = new MySqlTokenizer(this.query); mySqlTokenizer.AnsiQuotes = ansiQuotes; mySqlTokenizer.BackslashEscapes = !noBackslashEscapes; for (string text2 = mySqlTokenizer.NextToken(); text2 != null; text2 = mySqlTokenizer.NextToken()) { if (!mySqlTokenizer.Quoted) { if (text2.ToLower(CultureInfo.InvariantCulture) == "delimiter") { mySqlTokenizer.NextToken(); this.AdjustDelimiterEnd(mySqlTokenizer); text = this.query.Substring(mySqlTokenizer.StartIndex, mySqlTokenizer.StopIndex - mySqlTokenizer.StartIndex).Trim(); num = mySqlTokenizer.StopIndex; } else { if (text.StartsWith(text2, StringComparison.OrdinalIgnoreCase) && mySqlTokenizer.StartIndex + text.Length <= this.query.Length && this.query.Substring(mySqlTokenizer.StartIndex, text.Length) == text) { text2 = text; mySqlTokenizer.Position = mySqlTokenizer.StartIndex + text.Length; mySqlTokenizer.StopIndex = mySqlTokenizer.Position; } int num2 = text2.IndexOf(text, StringComparison.OrdinalIgnoreCase); if (num2 != -1) { int num3 = mySqlTokenizer.StopIndex - text2.Length + num2; if (mySqlTokenizer.StopIndex == this.query.Length - 1) { num3++; } string text3 = this.query.Substring(num, num3 - num); ScriptStatement item = default(ScriptStatement); item.text = text3.Trim(); item.line = MySqlScript.FindLineNumber(num, list2); item.position = num - list2[item.line]; list.Add(item); num = num3 + text.Length; } } } } if (num < this.query.Length - 1) { string text4 = this.query.Substring(num).Trim(); if (!string.IsNullOrEmpty(text4)) { ScriptStatement item2 = default(ScriptStatement); item2.text = text4; item2.line = MySqlScript.FindLineNumber(num, list2); item2.position = num - list2[item2.line]; list.Add(item2); } } return(list); }