コード例 #1
0
 public function testFormatSQLStatement()
 {
     $instance = new DebugOutputFormatter();
     $sql = '';
     $alias = '';
     $this->assertInternalType('string', $instance->doFormatSQLStatement($sql, $alias));
 }
コード例 #2
0
 public function testFormatDebugOutputWithQuery()
 {
     $description = $this->getMockBuilder('\\SMW\\Query\\Language\\Description')->disableOriginalConstructor()->getMockForAbstractClass();
     $query = $this->getMockBuilder('\\SMWQuery')->disableOriginalConstructor()->getMock();
     $query->expects($this->any())->method('getDescription')->will($this->returnValue($description));
     $query->expects($this->any())->method('getErrors')->will($this->returnValue(array()));
     $instance = new DebugOutputFormatter();
     $this->assertInternalType('string', $instance->formatOutputFor('foo', array(), $query));
 }
コード例 #3
0
ファイル: QueryEngine.php プロジェクト: Rikuforever/wiki
 /**
  * Using a preprocessed internal query description referenced by $rootid, compute
  * the proper debug output for the given query.
  *
  * @param Query $query
  * @param integer $rootid
  *
  * @return string
  */
 private function getDebugQueryResult(Query $query, $rootid)
 {
     $qobj = $this->querySegmentList[$rootid];
     $entries = array();
     $sqlOptions = $this->getSQLOptions($query, $rootid);
     $entries['SQL Query'] = '';
     $entries['SQL Explain'] = '';
     if (isset($qobj->joinfield) && $qobj->joinfield !== '') {
         $this->doPrepareDebugQueryResult($qobj, $sqlOptions, $entries);
     } else {
         $entries['SQL Query'] = 'Empty result, no SQL query created.';
     }
     $auxtables = '';
     foreach ($this->querySegmentListProcessor->getListOfResolvedQueries() as $table => $log) {
         $auxtables .= "<li>Temporary table {$table}";
         foreach ($log as $q) {
             $auxtables .= "<br />&#160;&#160;<tt>{$q}</tt>";
         }
         $auxtables .= '</li>';
     }
     if ($auxtables) {
         $entries['Auxilliary Tables Used'] = "<ul>{$auxtables}</ul>";
     } else {
         $entries['Auxilliary Tables Used'] = 'No auxilliary tables used.';
     }
     return DebugOutputFormatter::formatOutputFor('SQLStore', $entries, $query);
 }
コード例 #4
0
 private function getDebugQueryResult(Query $query, Condition $compoundCondition)
 {
     $entries = array();
     if ($this->isSingletonConditionWithElementMatch($compoundCondition)) {
         if ($compoundCondition->condition === '') {
             // all URIs exist, no querying
             $sparql = 'None (no conditions).';
         } else {
             $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
             $namespaces = $compoundCondition->namespaces;
             $sparql = $this->connection->getSparqlForAsk($condition, $namespaces);
         }
     } elseif ($compoundCondition instanceof FalseCondition) {
         $sparql = 'None (conditions can not be satisfied by anything).';
     } else {
         $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
         $namespaces = $compoundCondition->namespaces;
         $options = $this->getOptions($query, $compoundCondition);
         $options['DISTINCT'] = true;
         $sparql = $this->connection->getSparqlForSelect('?' . self::RESULT_VARIABLE, $condition, $options, $namespaces);
     }
     $sparql = str_replace(array('[', ':', ' '), array('&#x005B;', '&#x003A;', '&#x0020;'), $sparql);
     $entries['SPARQL Query'] = '<div class="smwpre">' . $sparql . '</div>';
     return DebugOutputFormatter::formatOutputFor('SPARQLStore', $entries, $query);
 }
コード例 #5
0
 private function getDebugQueryResult(Query $query, Condition $compoundCondition)
 {
     $entries = array();
     if ($this->isSingletonConditionWithElementMatch($compoundCondition)) {
         if ($compoundCondition->condition === '') {
             // all URIs exist, no querying
             $sparql = 'None (no conditions).';
         } else {
             $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
             $namespaces = $compoundCondition->namespaces;
             $sparql = $this->connection->getSparqlForAsk($condition, $namespaces);
         }
     } elseif ($compoundCondition instanceof FalseCondition) {
         $sparql = 'None (conditions can not be satisfied by anything).';
     } else {
         $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
         $namespaces = $compoundCondition->namespaces;
         $options = $this->getOptions($query, $compoundCondition);
         $options['DISTINCT'] = true;
         $sparql = $this->connection->getSparqlForSelect('?' . self::RESULT_VARIABLE, $condition, $options, $namespaces);
     }
     $entries['SPARQL Query'] = QueryDebugOutputFormatter::doFormatSPARQLStatement($sparql);
     return QueryDebugOutputFormatter::getStringFrom('SPARQLStore', $entries, $query);
 }
コード例 #6
0
 private function doExecuteDebugQueryResult($qobj, $sqlOptions, &$entries)
 {
     if (!isset($qobj->joinfield) || $qobj->joinfield === '') {
         return $entries['SQL Query'] = 'Empty result, no SQL query created.';
     }
     $db = $this->store->getConnection('mw.db.queryengine');
     list($startOpts, $useIndex, $tailOpts) = $db->makeSelectOptions($sqlOptions);
     $sql = "SELECT DISTINCT " . "{$qobj->alias}.smw_id AS id," . "{$qobj->alias}.smw_title AS t," . "{$qobj->alias}.smw_namespace AS ns," . "{$qobj->alias}.smw_iw AS iw," . "{$qobj->alias}.smw_subobject AS so," . "{$qobj->alias}.smw_sortkey AS sortkey " . "FROM " . $db->tableName($qobj->joinTable) . " AS {$qobj->alias}" . $qobj->from . ($qobj->where === '' ? '' : ' WHERE ') . $qobj->where . "{$tailOpts} {$startOpts} {$useIndex} " . "LIMIT " . $sqlOptions['LIMIT'] . ' ' . "OFFSET " . $sqlOptions['OFFSET'];
     $res = $db->query('EXPLAIN ' . $sql, __METHOD__);
     $entries['SQL Explain'] = QueryDebugOutputFormatter::doFormatSQLExplainOutput($db->getType(), $res);
     $entries['SQL Query'] = QueryDebugOutputFormatter::doFormatSQLStatement($sql, $qobj->alias);
     $db->freeResult($res);
 }