/** * 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; }
public function testSetGetErrorCode() { $instance = new FederateResultSet(array(), array()); $instance->setErrorCode(FederateResultSet::ERROR_INCOMPLETE); $this->assertEquals(FederateResultSet::ERROR_INCOMPLETE, $instance->getErrorCode()); }