Ejemplo n.º 1
0
 /**
  * Get the output string for a query in debugging mode.
  *
  * @param Query $query
  *
  * @return string
  */
 public function getDebugQueryResult(Query $query)
 {
     $this->sortkeys = $query->sortkeys;
     $this->compoundConditionBuilder->setSortKeys($this->sortkeys);
     $sparqlCondition = $this->compoundConditionBuilder->buildCondition($query->getDescription());
     $query->addErrors($this->compoundConditionBuilder->getErrors());
     $entries = array();
     if ($sparqlCondition instanceof SingletonCondition) {
         if ($sparqlCondition->condition === '') {
             // all URIs exist, no querying
             $sparql = 'None (no conditions).';
         } else {
             $condition = $this->compoundConditionBuilder->convertConditionToString($sparqlCondition);
             $namespaces = $sparqlCondition->namespaces;
             $sparql = $this->connection->getSparqlForAsk($condition, $namespaces);
         }
     } elseif ($sparqlCondition instanceof FalseCondition) {
         $sparql = 'None (conditions can not be satisfied by anything).';
     } else {
         $condition = $this->compoundConditionBuilder->convertConditionToString($sparqlCondition);
         $namespaces = $sparqlCondition->namespaces;
         $options = $this->getOptions($query, $sparqlCondition);
         $options['DISTINCT'] = true;
         $sparql = $this->connection->getSparqlForSelect('?' . self::RESULT_VARIABLE, $condition, $options, $namespaces);
     }
     $sparql = str_replace(array('[', ':', ' '), array('[', ':', ' '), $sparql);
     $entries['SPARQL Query'] = '<div class="smwpre">' . $sparql . '</div>';
     return DebugOutputFormatter::formatOutputFor('SPARQLStore', $entries, $query);
 }
Ejemplo n.º 2
0
 /**
  * @since  2.0
  * @param  Query $query
  *
  * @return QueryResult|string
  */
 public function getQueryResult(Query $query)
 {
     if ((!$this->engineOptions->get('smwgIgnoreQueryErrors') || $query->getDescription() instanceof ThingDescription) && $query->querymode != Query::MODE_DEBUG && count($query->getErrors()) > 0) {
         return $this->queryResultFactory->newEmptyQueryResult($query, false);
     }
     // don't query, but return something to the printer
     if ($query->querymode == Query::MODE_NONE || $query->getLimit() < 1) {
         return $this->queryResultFactory->newEmptyQueryResult($query, true);
     }
     $this->compoundConditionBuilder->setSortKeys($query->sortkeys);
     $compoundCondition = $this->compoundConditionBuilder->buildCondition($query->getDescription());
     $query->addErrors($this->compoundConditionBuilder->getErrors());
     if ($query->querymode == Query::MODE_DEBUG) {
         return $this->getDebugQueryResult($query, $compoundCondition);
     } elseif ($query->querymode == Query::MODE_COUNT) {
         return $this->getCountQueryResult($query, $compoundCondition);
     }
     return $this->getInstanceQueryResult($query, $compoundCondition);
 }