function parse($sql) { $this->sql = preg_replace("/([()=])/", " \\1 ", $sql); $this->sql = CPerfQuery::removeSpaces($this->sql); $match = array(); if (preg_match("/^(select) /i", $this->sql, $match)) { $this->type = strtolower($match[1]); } else { $this->type = "unknown"; } if ($this->type == "select") { //0 TODO replace literals with placeholders //1 remove subqueries from sql if (!$this->parse_subqueries()) { return false; } //2 parse from $this->from = new CPerfQueryFrom(); if (!$this->from->parse($this->sql)) { return false; } $tables_regex = "(?:" . implode("|", $this->from->getTableAliases()) . ")"; $this->where = new CPerfQueryWhere($tables_regex); if (preg_match("/ where (.+?)(\$| group | having | order )/i", $this->sql, $match)) { $this->where->parse($match[1]); } return true; } else { return false; } }
function parse($sql) { $sql = CPerfQuery::removeSpaces($sql); if (preg_match("/^select(.*) from (.*?) (where|group|having|order)/is", $sql, $match)) { $this->sql = $match[2]; } elseif (preg_match("/^select(.*) from (.*?)\$/is", $sql, $match)) { $this->sql = $match[2]; } else { $this->sql = ""; } if ($this->sql) { $arJoinTables = preg_split("/(,|inner\\s+join|left\\s+join)(?= [a-z0-9_]+)/is", $this->sql); foreach ($arJoinTables as $str) { $table = new CPerfQueryTable(); if ($table->parse($str)) { $this->tables[] = $table; } } if (count($this->tables) <= 0) { return false; } $tables_regex = "(?:" . implode("|", $this->getTableAliases()) . ")"; foreach ($this->tables as $table) { $where = new CPerfQueryWhere($tables_regex); if ($where->parse($table->join)) { $this->joins = array_merge($this->joins, $where->joins); } } } return !empty($this->tables); }