コード例 #1
0
 /**
  * @since 2.2
  *
  * @param Description $description
  *
  * @return QuerySegment
  */
 public function interpretDescription(Description $description)
 {
     $query = new QuerySegment();
     $cqid = QuerySegment::$qnum;
     $cquery = new QuerySegment();
     $cquery->type = QuerySegment::Q_CLASS_HIERARCHY;
     $cquery->joinfield = array();
     foreach ($description->getCategories() as $category) {
         $categoryId = $this->queryBuilder->getStore()->getObjectIds()->getSMWPageID($category->getDBkey(), NS_CATEGORY, $category->getInterwiki(), '');
         if ($categoryId != 0) {
             $cquery->joinfield[] = $categoryId;
         }
     }
     if (count($cquery->joinfield) == 0) {
         // Empty result.
         $query->type = QuerySegment::Q_VALUE;
         $query->joinTable = '';
         $query->joinfield = '';
     } else {
         // Instance query with disjunction of classes (categories)
         $query->joinTable = $this->queryBuilder->getStore()->findPropertyTableID(new DIProperty('_INST'));
         $query->joinfield = "{$query->alias}.s_id";
         $query->components[$cqid] = "{$query->alias}.o_id";
         $this->queryBuilder->addQuerySegmentForId($cqid, $cquery);
     }
     return $query;
 }
 /**
  * TODO: One instance of the SMW IDs table on s_id always suffices (swm_id is KEY)! Doable in execution ... (PERFORMANCE)
  *
  * @since 2.2
  *
  * @param Description $description
  *
  * @return QuerySegment
  */
 public function interpretDescription(Description $description)
 {
     $query = new QuerySegment();
     $query->joinTable = SMWSql3SmwIds::tableName;
     $query->joinfield = "{$query->alias}.smw_id";
     $query->where = "{$query->alias}.smw_namespace=" . $this->queryBuilder->getStore()->getConnection('mw.db')->addQuotes($description->getNamespace());
     return $query;
 }
コード例 #3
0
 /**
  * Given an Description that is just a conjunction or disjunction of
  * ValueDescription objects, create and return a plain WHERE condition
  * string for it.
  *
  * @param $query
  * @param ValueDescription $description
  * @param DataItemHandler $diHandler for that table
  * @param string $operator SQL operator "AND" or "OR"
  */
 private function mapValueDescription($query, ValueDescription $description, DataItemHandler $diHandler, $operator)
 {
     $where = '';
     $dataItem = $description->getDataItem();
     $db = $this->queryBuilder->getStore()->getConnection('mw.db');
     // TODO Better get the handle from the property type
     // Some comparators (e.g. LIKE) could use DI values of
     // a different type; we care about the property table, not
     // about the value
     // Do not support smw_id joined data for now.
     $indexField = $diHandler->getIndexField();
     //Hack to get to the field used as index
     $keys = $diHandler->getWhereConds($dataItem);
     $value = $keys[$indexField];
     // See if the getSQLCondition method exists and call it if this is the case.
     // Invoked by SMAreaValueDescription, SMGeoCoordsValueDescription
     if (method_exists($description, 'getSQLCondition')) {
         $fields = $diHandler->getTableFields();
         $where = $description->getSQLCondition($query->alias, array_keys($fields), $this->queryBuilder->getStore()->getConnection(DB_SLAVE));
     }
     if ($where == '') {
         $comparator = $this->comparatorMapper->mapComparator($description, $value);
         $where = "{$query->alias}.{$indexField}{$comparator}" . $db->addQuotes($value);
     }
     if ($where !== '') {
         if ($query->where && substr($query->where, -1) != '(') {
             $query->where .= " {$operator} ";
         }
         $query->where .= "({$where})";
     }
 }
コード例 #4
0
 /**
  * Only type '_wpg' objects can appear on query level (essentially as nominal classes)
  *
  * @since 2.2
  *
  * @param Description $description
  *
  * @return QuerySegment
  */
 public function interpretDescription(Description $description)
 {
     $query = new QuerySegment();
     if (!$description->getDataItem() instanceof DIWikiPage) {
         return $query;
     }
     if ($description->getComparator() === SMW_CMP_EQ) {
         $query->type = QuerySegment::Q_VALUE;
         $oid = $this->queryBuilder->getStore()->getObjectIds()->getSMWPageID($description->getDataItem()->getDBkey(), $description->getDataItem()->getNamespace(), $description->getDataItem()->getInterwiki(), $description->getDataItem()->getSubobjectName());
         $query->joinfield = array($oid);
     } else {
         // Join with SMW IDs table needed for other comparators (apply to title string).
         $query->joinTable = SMWSql3SmwIds::tableName;
         $query->joinfield = "{$query->alias}.smw_id";
         $value = $description->getDataItem()->getSortKey();
         $comparator = $this->comparatorMapper->mapComparator($description, $value);
         $query->where = "{$query->alias}.smw_sortkey{$comparator}" . $this->queryBuilder->getStore()->getConnection('mw.db')->addQuotes($value);
     }
     return $query;
 }
コード例 #5
0
 /**
  * We bypass the storage interface here (which is legal as we control it,
  * and safe if we are careful with changes ...)
  *
  * This should be faster, but we must implement the unescaping that concepts
  * do on getWikiValue
  */
 private function getConceptForId($id)
 {
     return $this->queryBuilder->getStore()->getConnection('mw.db')->selectRow('smw_fpt_conc', array('concept_txt', 'concept_features', 'concept_size', 'concept_depth', 'cache_date'), array('s_id' => $id), __METHOD__);
 }