private void Initialize(string sqlText) { string curClause = string.Empty; int curClauseIndex = 0; for (int i = 0; i < sqlText.Length;) { //Find new Sql clause int maxLenToSearch = sqlText.Length - i >= 6 ? 6 : sqlText.Length - i; string keyword = StartsWithString(sqlText.Substring(i, maxLenToSearch), keywords, StringComparison.OrdinalIgnoreCase); //Process Sql clause if (keyword != null && curClause != keyword) { if (!string.IsNullOrEmpty(curClause)) { Clauses.Add(SqlClause.Parse(curClause, sqlText.Substring(curClauseIndex, i - curClauseIndex))); } curClause = keyword; curClauseIndex = i + curClause.Length; i = i + curClause.Length; } else { i++; } } if (!string.IsNullOrEmpty(curClause)) { Clauses.Add(SqlClause.Parse(curClause, sqlText.Substring(curClauseIndex))); } }
private void Initialize(string sqlText) { //Clean Sql Text sqlText = sqlText.Replace("\r\n", " "); //Process Sql Text string curClause = string.Empty; int curClauseIndex = 0; for (int i = 0; i < sqlText.Length;) { //Find new Sql clause int maxLenToSearch = sqlText.Length - i >= 10 ? 10 : sqlText.Length - i; string keyword = StartsWithString(sqlText.Substring(i, maxLenToSearch), keywords, StringComparison.OrdinalIgnoreCase); bool isWordStart = i > 0 ? sqlText[i - 1] == ' ' : true; //Process Sql clause if (keyword != null && curClause != keyword && isWordStart) { if (!string.IsNullOrEmpty(curClause)) { Clauses.Add(SqlClause.Parse(curClause, sqlText.Substring(curClauseIndex, i - curClauseIndex))); } curClause = keyword; curClauseIndex = i + curClause.Length; i = i + curClause.Length; } else { i++; } } if (!string.IsNullOrEmpty(curClause)) { Clauses.Add(SqlClause.Parse(curClause, sqlText.Substring(curClauseIndex))); } }