private function makeQueryResultForInstance(RepositoryResult $repositoryResult, Query $query)
 {
     $resultDataItems = array();
     foreach ($repositoryResult as $resultRow) {
         if (count($resultRow) > 0 && $resultRow[0] instanceof ExpElement) {
             $dataItem = Exporter::getInstance()->findDataItemForExpElement($resultRow[0]);
             if (!is_null($dataItem)) {
                 $resultDataItems[] = $dataItem;
             }
         }
     }
     if ($repositoryResult->numRows() > $query->getLimit()) {
         if (count($resultDataItems) > 1) {
             array_pop($resultDataItems);
         }
         $hasFurtherResults = true;
     } else {
         $hasFurtherResults = false;
     }
     $result = new QueryResult($query->getDescription()->getPrintrequests(), $query, $resultDataItems, $this->store, $hasFurtherResults);
     switch ($repositoryResult->getErrorCode()) {
         case RepositoryResult::ERROR_NOERROR:
             break;
         case RepositoryResult::ERROR_INCOMPLETE:
             $result->addErrors(array(wfMessage('smw_db_sparqlqueryincomplete')->inContentLanguage()->text()));
             break;
         default:
             $result->addErrors(array(wfMessage('smw_db_sparqlqueryproblem')->inContentLanguage()->text()));
             break;
     }
     return $result;
 }
 /**
  * Execute a SPARQL query and return an RepositoryResult object
  * that contains the results. Compared to GenericHttpDatabaseConnector::doQuery(),
  * this also supports the parameter "restricted=1" which 4Store provides
  * to enforce strict resource bounds on query answering. The method also
  * checks if these bounds have been met, and records this in the query
  * result.
  *
  * @note The restricted option in 4Store mainly enforces the given soft
  * limit more strictly. To disable/configure it, simply change the soft
  * limit settings of your 4Store server.
  *
  * @param $sparql string with the complete SPARQL query (SELECT or ASK)
  * @return RepositoryResult
  */
 public function doQuery($sparql)
 {
     if ($this->repositoryClient->getQueryEndpoint() === '') {
         throw new BadHttpDatabaseResponseException(BadHttpDatabaseResponseException::ERROR_NOSERVICE, $sparql, 'not specified');
     }
     $this->httpRequest->setOption(CURLOPT_URL, $this->repositoryClient->getQueryEndpoint());
     $this->httpRequest->setOption(CURLOPT_HTTPHEADER, array('Accept: application/sparql-results+xml,application/xml;q=0.8'));
     $this->httpRequest->setOption(CURLOPT_POST, true);
     $defaultGraph = $this->repositoryClient->getDefaultGraph();
     $parameterString = "query=" . urlencode($sparql) . "&restricted=1" . ($defaultGraph !== '' ? '&default-graph-uri=' . urlencode($defaultGraph) : '');
     $this->httpRequest->setOption(CURLOPT_POSTFIELDS, $parameterString);
     $httpResponse = $this->httpRequest->execute();
     if ($this->httpRequest->getLastErrorCode() == 0) {
         $xmlResponseParser = new XmlResponseParser();
         $result = $xmlResponseParser->parse($httpResponse);
     } else {
         $this->mapHttpRequestError($this->repositoryClient->getQueryEndpoint(), $sparql);
         $result = new RepositoryResult();
         $result->setErrorCode(RepositoryResult::ERROR_UNREACHABLE);
     }
     foreach ($result->getComments() as $comment) {
         if (strpos($comment, 'warning: hit complexity limit') === 0 || strpos($comment, 'some results have been dropped') === 0) {
             $result->setErrorCode(RepositoryResult::ERROR_INCOMPLETE);
         }
         //else debug_zval_dump($comment);
     }
     return $result;
 }
 /**
  * @see GenericHttpRepositoryConnector::doQuery
  */
 public function doQuery($sparql)
 {
     if ($this->repositoryClient->getQueryEndpoint() === '') {
         throw new BadHttpDatabaseResponseException(BadHttpDatabaseResponseException::ERROR_NOSERVICE, $sparql, 'not specified');
     }
     $this->httpRequest->setOption(CURLOPT_URL, $this->repositoryClient->getQueryEndpoint());
     $this->httpRequest->setOption(CURLOPT_HTTPHEADER, array('Accept: application/sparql-results+xml,application/xml;q=0.8', 'Content-Type: application/x-www-form-urlencoded;charset=UTF-8'));
     $this->httpRequest->setOption(CURLOPT_POST, true);
     $defaultGraph = $this->repositoryClient->getDefaultGraph();
     $parameterString = "query=" . urlencode($sparql) . ($defaultGraph !== '' ? '&default-graph-uri=' . urlencode($defaultGraph) : '') . '&output=xml';
     $this->httpRequest->setOption(CURLOPT_POSTFIELDS, $parameterString);
     $httpResponse = $this->httpRequest->execute();
     if ($this->httpRequest->getLastErrorCode() == 0) {
         $xmlResponseParser = new XmlResponseParser();
         return $xmlResponseParser->parse($httpResponse);
     }
     $this->mapHttpRequestError($this->repositoryClient->getQueryEndpoint(), $sparql);
     $repositoryResult = new RepositoryResult();
     $repositoryResult->setErrorCode(RepositoryResult::ERROR_UNREACHABLE);
     return $repositoryResult;
 }
 public function testGetComments()
 {
     $instance = new RepositoryResult(array(), array(), array('Foo'));
     $this->assertContains('Foo', $instance->getComments());
 }