Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
ISAICP-6242: Attempt to show the entire query in debug.
Browse files Browse the repository at this point in the history
  • Loading branch information
idimopoulos committed Apr 5, 2021
1 parent d00a711 commit 83dc458
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Drupal\sparql_entity_storage\Exception\SparqlQueryException;
use EasyRdf\Http;
use EasyRdf\Http\Client as HttpClient;
use EasyRdf\Http\Exception as EasyRdfException;
use EasyRdf\Sparql\Client;
use EasyRdf\Sparql\Result;

Expand Down Expand Up @@ -39,6 +40,56 @@ public function query(string $query, array $args = [], array $options = []): Res
}
}

/**
* Execute the query against the endpoint.
*
* @param string $query
* The string query to execute.
* @param array $args
* An array of arguments for the query.
* @param array $options
* An associative array of options to control how the query is run.
*
* @return \EasyRdf\Sparql\Result|\EasyRdf\Graph
* The query result.
*
* @throws \InvalidArgumentException
* If $args value is passed but arguments replacement is not yet
* supported. To be removed in #55.
* @throws \Drupal\sparql_entity_storage\Exception\SparqlQueryException
* Exception during query execution, e.g. timeout.
*
* @see https://github.com/ec-europa/sparql_entity_storage/issues/1
*/
protected function doQuery(string $query, array $args = [], array $options = []) {
// @todo Remove this in #1.
// @see https://github.com/ec-europa/sparql_entity_storage/issues/1
if ($args) {
throw new \InvalidArgumentException('Replacement arguments are not yet supported.');
}

if ($this->logger) {
$query_start = microtime(TRUE);
}

try {
// @todo Implement argument replacement in #1.
// @see https://github.com/ec-europa/sparql_entity_storage/issues/1
$results = $this->easyRdfClient->query($query);
}
catch (EasyRdfException $exception) {
// Re-throw the exception, but with the query as message.
throw new SparqlQueryException('Execution of query failed: ' . htmlentities($query));
}

if ($this->logger) {
$query_end = microtime(TRUE);
$this->log($query, $args, $query_end - $query_start);
}

return $results;
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 83dc458

Please sign in to comment.