Пример #1
0
 private function makeQueryResultForInstance(FederateResultSet $federateResultSet, Query $query)
 {
     $resultDataItems = array();
     foreach ($federateResultSet as $resultRow) {
         if (count($resultRow) > 0) {
             $dataItem = Exporter::findDataItemForExpElement($resultRow[0]);
             if (!is_null($dataItem)) {
                 $resultDataItems[] = $dataItem;
             }
         }
     }
     if ($federateResultSet->numRows() > $query->getLimit()) {
         array_pop($resultDataItems);
         $hasFurtherResults = true;
     } else {
         $hasFurtherResults = false;
     }
     $result = new QueryResult($query->getDescription()->getPrintrequests(), $query, $resultDataItems, $this->store, $hasFurtherResults);
     switch ($federateResultSet->getErrorCode()) {
         case FederateResultSet::ERROR_NOERROR:
             break;
         case FederateResultSet::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 FederateResultSet 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 FederateResultSet
  */
 public function doQuery($sparql)
 {
     if ($this->m_queryEndpoint === '') {
         throw new BadHttpDatabaseResponseException(BadHttpDatabaseResponseException::ERROR_NOSERVICE, $sparql, 'not specified');
     }
     $this->httpRequest->setOption(CURLOPT_URL, $this->m_queryEndpoint);
     $this->httpRequest->setOption(CURLOPT_HTTPHEADER, array('Accept: application/sparql-results+xml,application/xml;q=0.8'));
     $this->httpRequest->setOption(CURLOPT_POST, true);
     $parameterString = "query=" . urlencode($sparql) . "&restricted=1" . ($this->m_defaultGraph !== '' ? '&default-graph-uri=' . urlencode($this->m_defaultGraph) : '');
     $this->httpRequest->setOption(CURLOPT_POSTFIELDS, $parameterString);
     $xmlResult = $this->httpRequest->execute();
     if ($this->httpRequest->getLastErrorCode() == 0) {
         $rawResultParser = new RawResultParser();
         $result = $rawResultParser->parse($xmlResult);
     } else {
         $this->mapHttpRequestError($this->m_queryEndpoint, $sparql);
         $result = new FederateResultSet(array(), array(), array(), FederateResultSet::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(FederateResultSet::ERROR_INCOMPLETE);
         }
         //else debug_zval_dump($comment);
     }
     return $result;
 }
Пример #3
0
 public function testGetComments()
 {
     $instance = new FederateResultSet(array(), array(), array('Foo'));
     $this->assertContains('Foo', $instance->getComments());
 }