- Модуль: perfmon
- Путь к файлу: ~/bitrix/modules/perfmon/classes/general/query.php
- Класс: CPerfQueryWhere
- Вызов: CPerfQueryWhere::parse
function parse($sql)
{
//Transform and simplify sql
//
//Remove balanced braces around equals
$sql = $this->_remove_braces(CPerfQuery::removeSpaces($sql));
//Replace "expr1 = or expr1 = or expr1 = ..."
//with "expr1 in (, ...)"
$new_sql = preg_replace_callback("/\( (".$this->equation_regex."(?: OR ".$this->equation_regex.")+) \)/i", array($this, "_or2in"), CPerfQuery::removeSpaces($sql));
if ($new_sql !== null)
$sql = CPerfQuery::removeSpaces($new_sql);
//Replace IN with no more than 5 values to equal
$sql = preg_replace("/ IN[ ]*\([ ]*([0-9]+|'[^']*')([ ]*,[ ]*([0-9]+|'[^']*')[ ]*){0,5}[ ]*\)/i", " = \1 ", $sql);
//Remove complex inner syntax
while (preg_match("/\([^()]*\)/", $sql))
$sql = preg_replace("/\([^()]*\)/", "", $sql);
$this->simplified_sql = $sql;
foreach (preg_split("/ and /i", $sql) as $str)
{
$match = array();
if (preg_match("/(".$this->table_aliases_regex."\.[`"\[\]]{0,1}[a-zA-Z0-9_]+[`"\[\]]{0,1}) = (".$this->table_aliases_regex."\.[`"\[\]]{0,1}[a-zA-Z0-9_]+[`"\[\]]{0,1})/", $str, $match))
{
$join = new CPerfQueryJoin;
$join->parse_left($match[1]);
$join->parse_right($match[2]);
$this->joins[] = $join;
}
elseif (preg_match("/(".$this->table_aliases_regex."\.[`"\[\]]{0,1}[a-zA-Z0-9_]+[`"\[\]]{0,1}) = ([0-9]+|'.+')/", $str, $match))
{
$join = new CPerfQueryJoin;
$join->parse_left($match[1]);
$join->parse_right($match[2]);
$this->joins[] = $join;
}
}
return !empty($this->joins);
}