Runs a SPARQL against repository triplestore.

@param string $query SPARQL query to run
@param int $nTries how many times request should be repeated in case of
error before giving up
@return \EasyRdf\Sparql\Result
517058
public function runSparql(string $query, int $nTries = null): Result {
        return $this->sparqlClient->query($query, $nTries ?? $this->sparqlNTries);
    }
1135335
public function search($query = '', $options = null): ResultSet
    {
        return $this->getType()->search($query, $options = null);
    }
499093
public function runCount($query)
	{
		if (isset($this->stored_query_totals[md5(serialize($query))])) {
			return $this->stored_query_totals[md5(serialize($query))];
		}
		
		$query['terms'] = trim($query['terms']);
		if (isset($query['numericFilters'])) {
			$query['numericFilters'] = implode(',', $query['numericFilters']);
		}
		if (isset($query['facets'])) {
			$query['facets'] = implode(',', $query['facets']);
		}
		
		try {
			return array_get($this->getIndex()->search(array_get($query, 'terms'), array_get($query, 'query')), 'nbHits');
		} catch (\Exception $e) {
			return 0;
		}
	}
714084
protected function executeQuery($query)
    {
        $content = $this->getAdapter()->get($query)->getBody();

        $json = json_decode($content, true);

        if (!empty($json['errors'])) {
            throw new NoResult(sprintf('Could not execute query: %s', $query));
        }

        if (empty($json['result']) || empty($json['result']['addressMatches'])) {
            throw new NoResult(sprintf('Could not find results for given query: %s', $query));
        }

        return array(array_merge($this->getDefaults(), array(
            'longitude'    => $json['result']['addressMatches'][0]['coordinates']['x'],
            'latitude'     => $json['result']['addressMatches'][0]['coordinates']['y'],
            'streetName'   => $json['result']['addressMatches'][0]['addressComponents']['streetName'],
            'city'         => $json['result']['addressMatches'][0]['addressComponents']['city'],
            'zipcode'      => $json['result']['addressMatches'][0]['addressComponents']['zip'],
            'countryCode'  => 'US',
        )));
    }
990718
public static function query($query)
    {
        $res = self::connection()->sql_query($query);

        if (!$res || self::connection()->sql_errno()) {
            // SQL statement failed
            $errorMsg = sprintf(
                'SQL Error: %s [errno: %s]',
                self::connection()->sql_error(),
                self::connection()->sql_errno()
            );

            if (defined('TYPO3_cliMode')) {
                throw new \Exception($errorMsg);
            } else {
                debug('SQL-QUERY: ' . $query, $errorMsg, __LINE__, __FILE__);
            }

            $res = null;
        }

        return $res;
    }
128446
public function withQuery(string $query): UriInterface
    {
        $query = $this->marshalQueryAndFragment($query);

        if ( $this->query === $query ) {
            return $this;
        }

        $instance = clone $this;
        $instance->query = $query;

        return $instance;
    }
159805
public function searchDelete($query) {
		$request = new CPS_SearchDeleteRequest($query);
		$this->_lastResponse = $this->_connection->sendRequest($request);
		return $this->_lastResponse->getHits();
	}
513736
public function runCount($query)
	{
		if (isset($this->stored_query_totals[md5(serialize($query))])) {
			return $this->stored_query_totals[md5(serialize($query))];
		}
		
		try {
			return array_get($this->getClient()->search($query), 'hits.total');
		} catch (\Elasticsearch\Common\Exceptions\Missing404Exception $e) {
			return 0;
		}
	}
1130453
public function select($query, $bindings = array())
	{
		return $this->run($query, $bindings, function($me, $query, $bindings)
		{
			if ($me->pretending()) return array();

			// For select statements, we'll simply execute the query and return an array
			// of the database result set. Each element in the array will be a single
			// row from the database table, and will either be an array or objects.
			$statement = $me->getReadPdo()->prepare($query);

			$statement->execute($me->prepareBindings($bindings));

			return $statement->fetchAll($me->getFetchMode());
		});
	}
161385
public function query(DataStructure\Query\Query $queries)
    {
        $logicFunc = 'andWhere';
        if ($queries instanceof DataStructure\OrQuery) {
            $logicFunc = 'orWhere';
        }

        foreach ($queries as $query) {

            if ($this->isExcludedProperty($query->getProperty())) {
                continue;
            }

            $value = $this->unlockSpecialProperty($query->getProperty(), $query->getValue());

            if ($query instanceof Expression\Equal) {

                $this->criteria->{$logicFunc}(Criteria::expr()->eq($query->getProperty(), $value));

            } elseif ($query instanceof Expression\NotEqual) {

                $this->criteria->{$logicFunc}(Criteria::expr()->neq($query->getProperty(), $value));

            } elseif ($query instanceof Expression\GreaterThan) {

                $this->criteria->{$logicFunc}(Criteria::expr()->gt($query->getProperty(), $value));

            } elseif ($query instanceof Expression\GreaterThanEqual) {

                $this->criteria->{$logicFunc}(Criteria::expr()->gte($query->getProperty(), $value));

            } elseif ($query instanceof Expression\LesserThan) {

                $this->criteria->{$logicFunc}(Criteria::expr()->lt($query->getProperty(), $value));

            } elseif ($query instanceof Expression\LesserThanEqual) {

                $this->criteria->{$logicFunc}(Criteria::expr()->lte($query->getProperty(), $value));

            } elseif ($query instanceof Expression\In) {

                $this->criteria->{$logicFunc}(Criteria::expr()->in($query->getProperty(), $value));

            } elseif ($query instanceof Expression\NotIn) {

                $this->criteria->{$logicFunc}(Criteria::expr()->notIn($query->getProperty(), $query->getValue()));

            }

        }
    }
831101
public function query($query)
    {
        // Replace prefix placeholder with prefix
        $query = str_replace("{prefix}", $this->prefix, $query);

        // Log last query and query count
        $this->lastQuery = $query;
        $this->queryCount++;

        // Query database
        return $this->connection->query($query);
    }
557976
public function one($query)
    {
        $authSession = $this->repositoryDispatcher->getCookieAuthSession();

        $url = null;
        $options = [
            RequestOptions::HEADERS => [
                'Cookie' => $authSession->getName() . '=' . $authSession->getValue(),
            ],
        ];

        // Prepares request options
        if (is_scalar($query)) {
            $url = $this->endpoint . '/rest/api/2/issue/' . $query;
        } elseif (is_array($query)
            && (array_key_exists('id', $query) || array_key_exists('key', $query))
        ) {
            // Prepares key by query
            if (isset($query['id'])) {
                $url = $this->endpoint . '/rest/api/2/issue/' . $query['id'];
                unset($query['id']);
            } elseif (isset($query['key'])) {
                $url = $this->endpoint . '/rest/api/2/issue/' . $query['key'];
                unset($query['key']);
            }

            // Prepares query params
            foreach ($query as $param => $value) {
                if ('fields' === $param) {
                    if (is_array($value)) {
                        $query[$param] = implode(',', $value);
                    }
                } elseif ('expand' === $param) {
                    if (is_array($value)) {
                        $query[$param] = implode(',', $value);
                    }
                } else {
                    unset($query[$param]);
                }
            }

            $options[RequestOptions::QUERY] = $query;
        } else {
            throw new \Exception('Bad params');
        }

        $response = $this->client->request('GET', $url, $options);

        $body = $response->getBody();
        $body->seek(0);
        $contents = $body->getContents();

        $issue = $this->createInstance(json_decode($contents, true));

        return $issue;
    }
1258811
protected function retryQuery($query, array $params = [])
    {
        $liteAttempts = $mainAttempts = 0;
        $liteRetryCount = (int)(getenv('DB_LITE_RETRY_COUNT') ?: static::LITE_RETRY_COUNT);
        $retryTimeout = (int)(getenv('DB_RETRY_TIMEOUT') ?: static::RETRY_TIMEOUT);
        $mainRetryCount = (int)(getenv('DB_MAIN_RETRY_COUNT') ?: static::MAIN_RETRY_COUNT);
        do {
            try {
                return parent::query($query, $params);
            } catch (\PDOException $e) {
                switch (substr($e->getCode(), 0, 2)) {
                    case '0Z':
                    case '2D':
                    case '3B':
                        $liteAttempts++;
                        if ($liteAttempts <= $liteRetryCount) {
                            usleep($retryTimeout);
                            continue 2;
                        }
                        break;
                    case '40':
                    case '55':
                        $mainAttempts++;
                        if ($mainAttempts <= $mainRetryCount) {
                            usleep($retryTimeout);
                            continue 2;
                        }
                }
            }

            throw $e;
        } while(true);
    }
508113
protected function prepareQuery($query)
    {
        $query = $query->with($this->withs);

        if ($this->withCounts) {
            $query = $query->withCount($this->withCounts);
        }

        if ($this->orderBy) {
            $query = $query->orderBy($this->orderBy, $this->orderByDirection);
        }

        if ( ! empty($this->has)) {
            foreach ($this->has as $has) {
                $query = $query->has($has['relation'], $has['operator'], $has['value']);
            }
        }

        if ( ! empty($this->whereHas)) {
            foreach ($this->whereHas as $has) {
                $query = $query->whereHas($has[0], isset($has[1]) ? $has[1] : null);
            }
        }

        return $query;
    }
610035
protected function processRequest(Builder $query, $results)
    {
        // Here we validate the results being returned to be associative.
        // When they are not we wrap them in an array making it easier for
        // elicit to them parse as a model.
        if (array_keys($results) !== range(0, count($results) - 1)) {
            return [$results];
        }

        // Here we return the results directly, assuming the items in
        // the array are a collection.
        return $results;
    }
898304
public function selectOne( $query, $bindings = [] )
	{
		$query = $this->bind_params( $query, $bindings );

		$result = $this->db->get_row( $query );

		if ( $result === false || $this->db->last_error ) {
			throw new QueryException( $query, $bindings, new \Exception( $this->db->last_error ) );
		}

		return $result;
	}
1166505
public static function executeNone(string $query): int
  {
    self::realQuery($query);

    $n = self::$mysqli->affected_rows;

    if (self::$mysqli->more_results()) self::$mysqli->next_result();

    return $n;
  }