/**
	 * Execute a SPARQL query and return an SMWSparqlResultWrapper object
	 * that contains the results. Compared to SMWSparqlDatabase::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 SMWSparqlResultWrapper
	 */
	public function doQuery( $sparql ) {
		//$result = parent::doQuery( $sparql );
		curl_setopt( $this->m_curlhandle, CURLOPT_URL, $this->m_queryEndpoint );
		curl_setopt( $this->m_curlhandle, CURLOPT_POST, true );
		$parameterString = "query=" . urlencode( $sparql ) . "&restricted=1" .
			( ( $this->m_defaultGraph !== '' )? '&default-graph-uri=' . urlencode( $this->m_defaultGraph ) : '' );
		curl_setopt( $this->m_curlhandle, CURLOPT_POSTFIELDS, $parameterString );
		$xmlResult = curl_exec( $this->m_curlhandle );

		if ( curl_errno( $this->m_curlhandle ) == 0 ) {
			$xmlParser = new SMWSparqlResultParser();
			$result = $xmlParser->makeResultFromXml( $xmlResult );
		} else {
			$this->throwSparqlErrors( $this->m_updateEndpoint, $sparql );
			$result = new SMWSparqlResultWrapper( array(), array(), array(), SMWSparqlResultWrapper::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( SMWSparqlResultWrapper::ERROR_INCOMPLETE );
			} //else debug_zval_dump($comment);
		}
		return $result;
	}
	/**
	 * Execute a SPARQL query and return an SMWSparqlResultWrapper object
	 * that contains the results. The method throws exceptions based on
	 * SMWSparqlDatabase::throwSparqlErrors(). If errors occur and this
	 * method does not throw anything, then an empty result with an error
	 * code is returned.
	 *
	 * @note This function sets the graph that is to be used as part of the
	 * request. Queries should not include additional graph information.
	 *
	 * @param $sparql string with the complete SPARQL query (SELECT or ASK)
	 * @return SMWSparqlResultWrapper
	 */
	public function doQuery( $sparql ) {
		//debug_zval_dump( $sparql );
		curl_setopt( $this->m_curlhandle, CURLOPT_URL, $this->m_queryEndpoint );
		curl_setopt( $this->m_curlhandle, CURLOPT_POST, true );
		$parameterString = "query=" . urlencode( $sparql ) .
			( ( $this->m_defaultGraph !== '' )? '&default-graph-uri=' . urlencode( $this->m_defaultGraph ) : '' );
		curl_setopt( $this->m_curlhandle, CURLOPT_POSTFIELDS, $parameterString );

		$xmlResult = curl_exec( $this->m_curlhandle );

		if ( curl_errno( $this->m_curlhandle ) == 0 ) {
			$xmlParser = new SMWSparqlResultParser();
			return $xmlParser->makeResultFromXml( $xmlResult );
		} else {
			$this->throwSparqlErrors( $this->m_updateEndpoint, $sparql );
			return new SMWSparqlResultWrapper( array(), array(), array(), SMWSparqlResultWrapper::ERROR_UNREACHABLE );
		}
	}
Esempio n. 3
0
 /**
  * Execute a SPARQL query and return an SMWSparqlResultWrapper object
  * that contains the results. The method throws exceptions based on
  * SMWSparqlDatabase::throwSparqlErrors(). If errors occur and this
  * method does not throw anything, then an empty result with an error
  * code is returned.
  *
  * @note This function sets the graph that is to be used as part of the
  * request. Queries should not include additional graph information.
  *
  * @param $sparql string with the complete SPARQL query (SELECT or ASK)
  * @return SMWSparqlResultWrapper
  */
 public function doQuery($sparql)
 {
     //debug_zval_dump( $sparql );
     curl_setopt($this->m_curlhandle, CURLOPT_URL, $this->m_queryEndpoint);
     curl_setopt($this->m_curlhandle, CURLOPT_HTTPHEADER, array('Accept: application/sparql-results+xml,application/xml;q=0.8'));
     curl_setopt($this->m_curlhandle, CURLOPT_POST, true);
     $parameterString = "query=" . urlencode($sparql) . ($this->m_defaultGraph !== '' ? '&default-graph-uri=' . urlencode($this->m_defaultGraph) : '');
     curl_setopt($this->m_curlhandle, CURLOPT_POSTFIELDS, $parameterString);
     curl_setopt($this->m_curlhandle, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded;charset=UTF-8'));
     $xmlResult = curl_exec($this->m_curlhandle);
     if (curl_errno($this->m_curlhandle) == 0) {
         $xmlParser = new SMWSparqlResultParser();
         return $xmlParser->makeResultFromXml($xmlResult);
     } else {
         $this->throwSparqlErrors($this->m_queryEndpoint, $sparql);
         return new SMWSparqlResultWrapper(array(), array(), array(), SMWSparqlResultWrapper::ERROR_UNREACHABLE);
     }
 }