Processes a raw query.

@param 	$expression <String>
@param 	$type <Integer>
@access 	protected
@return 	<Mixed>
5610
protected function runQueryWithExpression(String $expresison, int $type=1)
	{
		$query = $this->builder()->query($expresison, $type);
		Scheme::destroyColumns();
		return $query;
	}
1244146
protected function processAnalyzers($type, $value)
    {
        if (isset($this->analyzers[$type])) {
            // TODO: order analyzers by priority
            foreach ($this->analyzers[$type] as $array) {
                list($callable) = $array;
                $value = call_user_func_array($callable, array($value));
            }
        }
        return $value;
    }
1272269
public function processFile(string $type)
    {
        $this->alert(strtoupper($type) . ' PROCESS');
        foreach ($this->tables as $key => $table) {
            if ($table->relationTable === true && $type !== 'pivot') {
                continue;
            }

            if ($table->relationTable !== true && $type === 'pivot') {
                continue;
            }

            if (trim($this->option('table')) !== 'all') {
                $tableKey = $this->option('table');
                if ((int) $tableKey !== (int) $key) {
                    continue;
                }
            }

            $table->arqs = [
                $type => $this->getTemplate($type),
            ];

            foreach ($this->marks()[$type] as $mark){
                $table->arqs[$type] = str_replace('{{{' . $mark . '}}}',
                                                        trim($table->marks[$mark]),
                                                        $table->arqs[$type]);
            }

            //$this->info($table->arqs[$type]);
            $this->createFile($type, $table);
        }
    }
444670
public function query($type) {
        $query = $this->getDriver()->newQuery($type);
        $query->setRepository($this);
        $query->from($this->getTable(), $this->getAlias());

        return $query;
    }
36267
public function fetch($type = parent::FETCH_TYPE_NUM)
    {
        $callback = $this->_callback;
        $row = $this->_statement->fetch($type);

        return $row === false ? $row : $callback($row);
    }
91161
public function query($query)
    {
        $results = $this->connection->{$this->type}(
            $this->getDn(),
            $query,
            $this->getSelects(),
            $onlyAttributes = false,
            $this->limit
        );

        return $this->newProcessor()->process($results);
    }
956851
public function postProcessExpression(Expression $expression)
    {
        if ($this->hasHash($expression->hashCode())) {
            $alias = $this->getAlias($expression->hashCode());
            $alias = new Expr\Column($alias);
            $alias->setBuilder($this);
            $expression = new Expr\Raw(sprintf('%s AS %s', $expression->toSQL(), $alias->toSQL()));
        }
        
        return $expression;
    }
144161
protected function doRequestConsulta(string $expression)
    {
        /** @var int $encoding Override because inspectors does not know that second argument can be NULL */
        $encoding = null;
        return $this->getSoapClient()->__soapCall(
            'Consulta',
            [new \SoapVar($expression, $encoding, '', '', 'expresionImpresa', 'http://tempuri.org/')],
            ['soapaction' => 'http://tempuri.org/IConsultaCFDIService/Consulta']
        );
    }
452928
public function process($expression) {
        $tokens = $this->splitSQLIntoTokens($expression);
        $token_count = count($tokens);
        if ($token_count === 0) {
            return null;
        }

        /*
         * Determine if there is an explicit alias after the AS clause.
         * If AS is found, then the next non-whitespace token is captured as the alias.
         * The tokens after (and including) the AS are removed.
         */
        $base_expr = "";
        $stripped = array();
        $capture = false;
        $alias = false;
        $processed = false;

        for ($i = 0; $i < $token_count; ++$i) {
            $token = $tokens[$i];
            $upper = strtoupper($token);

            if ($upper === 'AS') {
                $alias = array('as' => true, "name" => "", "base_expr" => $token);
                $tokens[$i] = "";
                $capture = true;
                continue;
            }

            if (!$this->isWhitespaceToken($upper)) {
                $stripped[] = $token;
            }

            // we have an explicit AS, next one can be the alias
            // but also a comment!
            if ($capture) {
                if (!$this->isWhitespaceToken($upper) && !$this->isCommentToken($upper)) {
                    $alias['name'] .= $token;
                    array_pop($stripped);
                }
                $alias['base_expr'] .= $token;
                $tokens[$i] = "";
                continue;
            }

            $base_expr .= $token;
        }

        if ($alias) {
            // remove quotation from the alias
            $alias['no_quotes'] = $this->revokeQuotation($alias['name']);
            $alias['name'] = trim($alias['name']);
            $alias['base_expr'] = trim($alias['base_expr']);
        }

        $stripped = $this->processExpressionList($stripped);

        // TODO: the last part can also be a comment, don't use array_pop

        // we remove the last token, if it is a colref,
        // it can be an alias without an AS
        $last = array_pop($stripped);
        if (!$alias && $this->isColumnReference($last)) {

            // TODO: it can be a comment, don't use array_pop

            // check the token before the colref
            $prev = array_pop($stripped);

            if ($this->isReserved($prev) || $this->isConstant($prev) || $this->isAggregateFunction($prev)
                    || $this->isFunction($prev) || $this->isExpression($prev) || $this->isSubQuery($prev)
                    || $this->isColumnReference($prev) || $this->isBracketExpression($prev)|| $this->isCustomFunction($prev)) {

                $alias = array('as' => false, 'name' => trim($last['base_expr']),
                               'no_quotes' => $this->revokeQuotation($last['base_expr']),
                               'base_expr' => trim($last['base_expr']));
                // remove the last token
                array_pop($tokens);
            }
        }

        $base_expr = $expression;

        // TODO: this is always done with $stripped, how we do it twice?
        $processed = $this->processExpressionList($tokens);

        // if there is only one part, we copy the expr_type
        // in all other cases we use "EXPRESSION" as global type
        $type = ExpressionType::EXPRESSION;
        if (count($processed) === 1) {
            if (!$this->isSubQuery($processed[0])) {
                $type = $processed[0]['expr_type'];
                $base_expr = $processed[0]['base_expr'];
                $no_quotes = isset($processed[0]['no_quotes']) ? $processed[0]['no_quotes'] : null;
                $processed = $processed[0]['sub_tree']; // it can be FALSE
            }
        }

        $result = array();
        $result['expr_type'] = $type;
        $result['alias'] = $alias;
        $result['base_expr'] = trim($base_expr);
        if (!empty($no_quotes)) {
            $result['no_quotes'] = $no_quotes;
        }
        $result['sub_tree'] = (empty($processed) ? false : $processed);
        return $result;
    }
257624
final protected static function verifyAll(array $expressions, $type = __CLASS__)
    {
        foreach ($expressions as $key => $expression) {
            if (!($expression instanceof $type)) {
                throw new PinqException(
                        'Invalid array of expressions: invalid expression of type %s at index %s, expecting %s',
                        Utilities::getTypeOrClass($expression),
                        $key,
                        $type);
            }
        }

        return $expressions;
    }
756117
public function elemMatch($expression) : self
    {
        return $this->operator('$elemMatch', $expression instanceof Expr ? $expression->getQuery() : $expression);
    }
1098994
public function compile($type = 'select')
    {

        // Raw Type
        if ($this->rawQuery) {
            // Bind value
            $this->bindValue();

            return $this->queryString;
        }

        $this->queryString = '';

        if ($type == 'select') {
            $this->compileSelect();
            $this->compileFrom();
            $this->compileJoin();
            $this->compileWhere();
            $this->compileGroupBy();
            $this->compileOrderBy();
            $this->compileOffset();
        } elseif ($type == 'count') {
            $this->compileCount();
            $this->compileFrom();
            $this->compileJoin();
            $this->compileWhere();
            $this->compileGroupBy();
        } elseif ($type == 'insert') {
            $this->compileInsert();
        } elseif ($type == 'update') {
            $this->compileUpdate();
            $this->compileJoin();
            $this->compileWhere();
        } elseif ($type == 'delete') {
            $this->compileDelete();
            $this->compileFrom();
            $this->compileJoin();
            $this->compileWhere();
            $this->compileGroupBy();
        }

        // Bind value
        $this->bindValue();

        return $this->queryString;
    }
118902
private function formatQueryExpression(array $expression, Closure $converter)
    {
        foreach ($expression as $key => $value) {

            if ('$regex' === $key && !$value instanceof \MongoRegex) {
                $expression[$key] = new \MongoRegex($value);
                continue;
            }

            if (true === $this->isOpType('ignore', $key)) {
                continue;
            }

            if (true === $this->isOpType('single', $key)) {
                $expression[$key] = $converter($value);
                continue;
            }

            if (true === $this->isOpType('multiple', $key)) {
                $value = (array) $value;
                foreach ($value as $subKey => $subValue) {
                    $expression[$key][$subKey] = $converter($subValue);
                }
                continue;
            }

            if (true === $this->isOpType('recursive', $key)) {
                $value = (array) $value;
                $expression[$key] = $this->formatQueryExpression($value, $converter);
                continue;
            }

            $expression[$key] = $converter($value);
        }
        return $expression;
    }
655467
public function search($expression)
    {
        // Apply JMESPath expression on each result, but as a flat sequence.
        return flatmap($this, function (Result $result) use ($expression) {
            return (array) $result->search($expression);
        });
    }
121959
protected function extractEchoType($expression)
    {
        $echoType = self::ECHO_TEXT;
        $expression = trim($expression);
        if (preg_match('/^(text|structure)\s+(.*?)$/ism', $expression, $m)) {
            list(, $echoType, $expression) = $m;
        }
        $this->_echoType = strtolower($echoType);
        return trim($expression);
    }
881291
protected function __query($index, $type = null, array $query = []) {
        $result = $this->client->search([
            'index' => $index,
            'body' => array_merge_recursive($query, $this->additionalQuery())
                ] + ($type ? ['type' => $type] : []));
        return $this->_makeResult($result);
    }
1186514
private function query(string $expression): \DOMNodeList
    {
        return $this->xpath->query(
            $this->expressionTranslator->convertToXpath($expression)
        );
    }