Connection::parseQueryStatement

@param  QueryStatement $queryStatement Query object.

@return object
761887
protected function parseQueryStatement(QueryStatement &$queryStatement)
    {
        $queryBuilderCache = $queryStatement->getBuilderCache();

        // Projection Option
        if (count($queryBuilderCache->select)) {

            $projection = [];

            foreach ($queryBuilderCache->select as $field) {
                $projection[ $field ] = 1;
            }

            $queryStatement->addOption('projection', $projection);
        }

        // Filter Where In
        if (count($queryBuilderCache->whereIn)) {
            foreach ($queryBuilderCache->whereIn as $field => $clause) {
                if (count($queryBuilderCache->orWhereIn)) {
                    $queryBuilderCache->orWhere[ $field ] = ['$in' => $clause];
                } else {
                    $queryBuilderCache->where[ $field ] = ['$in' => $clause];
                }
            }
        }

        // Filter Where Not In
        if (count($queryBuilderCache->whereNotIn)) {
            foreach ($queryBuilderCache->whereNotIn as $field => $clause) {
                $queryBuilderCache->where[ $field ] = ['$nin' => $clause];
            }
        }

        // Filter Or Where In
        if (count($queryBuilderCache->orWhereIn)) {
            foreach ($queryBuilderCache->orWhereIn as $field => $clause) {
                $queryBuilderCache->orWhere[ $field ] = ['$in' => $clause];
            }
        }

        // Filter Or Where Not In
        if (count($queryBuilderCache->orWhereNotIn)) {
            foreach ($queryBuilderCache->orWhereNotIn as $field => $clause) {
                $queryBuilderCache->orWhere[ $field ] = ['$nin' => $clause];
            }
        }

        // Filter Where Between
        if (count($queryBuilderCache->between)) {
            foreach ($queryBuilderCache->between as $field => $clause) {
                $queryBuilderCache->where[ $field ] = ['$gte' => $clause[ 'start' ], '$lte' => $clause[ 'end' ]];
            }
        }

        // Filter Or Where Between
        if (count($queryBuilderCache->orBetween)) {
            foreach ($queryBuilderCache->orBetween as $field => $clause) {
                $queryBuilderCache->orWhere[ $field ] = ['$gte' => $clause[ 'start' ], '$lte' => $clause[ 'end' ]];
            }
        }

        // Filter Where Not Between
        if (count($queryBuilderCache->notBetween)) {
            foreach ($queryBuilderCache->notBetween as $field => $clause) {
                $queryBuilderCache->where[ $field ][ '$not' ] = [
                    '$gte' => $clause[ 'start' ],
                    '$lte' => $clause[ 'end' ],
                ];
            }
        }

        // Filter Or Where Not Between
        if (count($queryBuilderCache->orNotBetween)) {
            foreach ($queryBuilderCache->orNotBetween as $field => $clause) {
                $queryBuilderCache->orWhere[ $field ][ '$not' ] = [
                    '$gte' => $clause[ 'start' ],
                    '$lte' => $clause[ 'end' ],
                ];
            }
        }

        // Filter Where
        if (count($queryBuilderCache->where)) {
            foreach ($queryBuilderCache->where as $field => $clause) {
                $queryStatement->addFilter($field, $clause);
            }
        }

        // Filter Or Where
        if (count($queryBuilderCache->orWhere)) {
            $orWhere = [];
            foreach ($queryBuilderCache->orWhere as $field => $clause) {
                $orWhere[] = [$field => $clause];
            }

            $queryStatement->addFilter('$or', $orWhere);
        }

        //print_out( json_encode( $queryStatement->getFilter(), JSON_PRETTY_PRINT ) );

        // Limit Option
        if ($queryBuilderCache->limit > 0) {
            $queryStatement->addOption('limit', $queryBuilderCache->limit);
        }

        // Offset Option
        if ($queryBuilderCache->offset > 0) {
            $queryStatement->addOption('skip', $queryBuilderCache->offset);
        }

        // Order Option
        if (count($queryBuilderCache->orderBy)) {

            $sort = [];
            foreach ($queryBuilderCache->orderBy as $field => $direction) {
                $direction = $direction === 'ASC' ? 1 : -1;
                $sort[ $field ] = $direction;
            }

            $queryStatement->addOption('sort', $sort);
        }

        return $queryStatement;
    }
761992
public function getQuery($queryParams)
    {
        return array_key_exists($queryParams, $this->query) ? $this->query[$queryParams] : null;
    }
773187
public function getQuery()
    {
        $idField = $this->documentKey;

        if ($idField == null) {
            throw new QueryException('id should not be null');
        }

        $this->setQuery(sprintf('id:%s', $idField));

        return parent::getQuery();
    }
1147436
public function queryProcessing($queryParams) 
    {
        list($this->query, $this->totalQuery, $this->filterQuery)
            = self::processQuery($this->query, $queryParams);

        $this->countTotal = Util::get($queryParams, 'countTotal', false);
        $this->countFilter = Util::get($queryParams, 'countFilter', false);

        return $this;
    }
1109973
public function prepareQuery(Query $query)
    {
        $parameters = new Parameters($this->driver);

        if ($this->pdo === null)
            $this->connect();

        $sql = $this->driver->toSQL($parameters, $query);

        $statement = $this->prepare($sql);
        $parameters->bindParameters($statement);
        return $statement;
    }
1059063
public function prepare(string $statement) : PreparedStatementInterface
    {
        try {
            $preparedStatement = $this->getConnection()->prepare($statement);
            return new PdoPreparedStatement($preparedStatement);
        } catch (\PDOException $e) {
            throw new ParserRuntimeException('Statement could not be prepared.', 0, $e);
        }
    }
80552
public function getQuery(QueryBuilder $queryBuilder)
    {
        $rule = $this->getRule();
        $activeFrom = $rule->getActiveFrom();
        $activeUntil = $rule->getActiveUntil();

        $resultQueryBuilder = $queryBuilder;

        if (!is_null($activeFrom)) {
            $resultQueryBuilder = $resultQueryBuilder
                ->andWhere('l.dateLog >= :activeFrom')
                ->setParameter(
                    'activeFrom',
                    $activeFrom->format('Y-m-d H:i:s')
                );
        }
        if (!is_null($activeUntil)) {
            $resultQueryBuilder = $resultQueryBuilder
                ->andWhere('l.dateLog <= :activeUntil')
                ->setParameter(
                    'activeUntil',
                    $activeUntil->format('Y-m-d H:i:s')
                );
        }

        return $resultQueryBuilder;
    }
316432
protected function parseOrder(Query $query, $order)
    {
        if (empty($order)) {
            return ' ORDER BY rand()';
        }

        $array = [];

        foreach ($order as $key => $val) {
            if ($val instanceof Expression) {
                $array[] = $val->getValue();
            } elseif ('[rand]' == $val) {
                $array[] = $this->parseRand($query);
            } else {
                if (is_numeric($key)) {
                    list($key, $sort) = explode(' ', strpos($val, ' ') ? $val : $val . ' ');
                } else {
                    $sort = $val;
                }

                $sort    = in_array(strtolower($sort), ['asc', 'desc'], true) ? ' ' . $sort : '';
                $array[] = $this->parseKey($query, $key, true) . $sort;
            }
        }

        return ' ORDER BY ' . implode(',', $array);
    }
1067661
private function _parseQueryString($queryString)
    {
        $queryObjs = json_decode($queryString);
        if (!$queryObjs) {
            throw new SqlException(
                'There was an error parsing your filter query string. '
                . 'The filter query must be in the format of a JSON object.'
            );
        }

        //inject a single object into an array.
        if (!is_array($queryObjs)) {
            $queryObj = $queryObjs;
            $queryObjs = [];
            $queryObjs[] = $queryObj;
        }

        $firstObj = true;
        foreach ($queryObjs as $queryObj) {
            $firstProperty = true;
            foreach ($queryObj as $property => $value) {
                if (is_array($value)) {
                    foreach ($value as $val) {
                        $this->_addFilterComparison($firstObj, $firstProperty, $property, $val);
                    }
                } else {
                    $this->_addFilterComparison($firstObj, $firstProperty, $property, $value);
                }
                $firstProperty = false;
            }
            $firstObj = false;
        }
    }
26423
public static SqlBuilder sql(final String queryStr) {
    SqlBuilder sqlQuery = new SqlBuilder();
    sqlQuery.statement = queryStr;
    return sqlQuery;
  }
1226888
private function getQueryValue(Iterator $queryIterator)
    {
        if (!$queryIterator->valid()) {
            return null;
        }

        $queryValue = $queryIterator->current();
        $queryIterator->next();

        return $queryValue;
    }
1411
public function runQuery($queryString){

		$this->affectedRows = false;
		$result = $this->resource->query($queryString, $this->unbuffered ? MYSQLI_USE_RESULT : MYSQLI_STORE_RESULT);

		$error = preg_replace('~You have an error in your SQL syntax; check the manual that corresponds to your \w+ server version for the right syntax to use~i', 'Syntax error', $this->resource->error);
		if($error && $result === false)
			throw new DriverException($error, $this->resource->errno, $queryString);

		$this->affectedRows = $this->resource->affected_rows;
		return $result;
	}
857232
public function parse_query(string $statement): ?array
  {
    if ( $this->parser === null ){
      $this->parser = new \PHPSQLParser\PHPSQLParser();
    }
    try {
      $r = $this->parser->parse($statement);
      if ( !count($r) ){
        return null;
      }
      if ( isset($r['BRACKET']) && (\count($r) === 1) ){
        return null;
      }
      return $r;
    }
    catch ( \Exception $e ){
      $this->log('Impossible to parse the query '.$statement);
    }
    return null;
  }
333684
public function sqlQuery($queryString)
    {
        try {
            // execute query
            $query = $this->connection->prepare(
                $queryString,
                [\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY]
            );
            $query->execute();

            return $query;
        } catch (\PDOException $e) {
            throw new \Exception($e->getMessage());
        }
    }
292966
public function runQuery($queryString){
		$this->affectedRows = false;

		$result = @pg_query($this->resource, $queryString);
		if($result === false)
			throw new DriverException(pg_last_error($this->resource), null, $queryString);

		$this->affectedRows = @pg_affected_rows($result);
		return $result;
	}
59218
private function parseSelectQuery()
    {
        // Parse select ?
        $selectSql = Column::generateQueryString($this->query->select);

        // Parse table
        $fromSql = Table::generateQueryString($this->query->table);

        $whereSql = null;
        $whereBind = array();


        $sql = [
            'select' => $selectSql,
            'from' => $fromSql,
            'where' => $whereSql
            // TODO: Add other parts.
        ];

        $this->bind = array_merge(
            $this->bind,
            $whereBind
        );

        $this->sql = $this->combineSelectQuery($sql);
    }
1135449
public function prepare(string $queryStatement): void
    {
        try {
            $this->stmt = $this->getPDO()->prepare($queryStatement);
        } catch (PDOException $e) {
            //$dashes = str_repeat('=', 50);
            //Log::notice("Can't prepare query statement ({$this->getConfigKey()}):\n{$dashes}\n{$queryStatement}\n{$dashes}");

            $exception = new QueryException($e->getMessage(), (int)$e->getCode(), $e);
            $exception->setSql($queryStatement);
            throw $exception;
        }
    }