/**
  * Find subproperties or subcategories. This may require iterative computation,
  * and temporary tables are used in many cases.
  *
  * @param QuerySegment $query
  */
 private function resolveHierarchyForSegment(QuerySegment &$query)
 {
     $db = $this->connection;
     $hierarchytables = $this->resolverOptions->get('hierarchytables');
     if ($query->type === QuerySegment::Q_PROP_HIERARCHY) {
         $depth = $this->resolverOptions->get('smwgQSubpropertyDepth');
         $smwtable = $db->tableName($hierarchytables['_SUBP']);
     } else {
         $depth = $this->resolverOptions->get('smwgQSubcategoryDepth');
         $smwtable = $db->tableName($hierarchytables['_SUBC']);
     }
     if ($depth <= 0) {
         // treat as value, no recursion
         $query->type = QuerySegment::Q_VALUE;
         return;
     }
     $values = '';
     $valuecond = '';
     foreach ($query->joinfield as $value) {
         $values .= ($values ? ',' : '') . '(' . $db->addQuotes($value) . ')';
         $valuecond .= ($valuecond ? ' OR ' : '') . 'o_id=' . $db->addQuotes($value);
     }
     // Try to safe time (SELECT is cheaper than creating/dropping 3 temp tables):
     $res = $db->select($smwtable, 's_id', $valuecond, __METHOD__, array('LIMIT' => 1));
     if (!$db->fetchObject($res)) {
         // no subobjects, we are done!
         $db->freeResult($res);
         $query->type = QuerySegment::Q_VALUE;
         return;
     }
     $db->freeResult($res);
     $tablename = $db->tableName($query->alias);
     $this->executedQueries[$query->alias] = array("Recursively computed hierarchy for element(s) {$values}.");
     $query->joinTable = $query->alias;
     $query->joinfield = "{$query->alias}.id";
     if ($this->queryMode == Query::MODE_DEBUG) {
         return;
         // No real queries in debug mode.
     }
     $db->query($this->getCreateTempIDTableSQL($tablename), __METHOD__);
     if (array_key_exists($values, $this->hierarchyCache)) {
         // Just copy known result.
         $db->query("INSERT INTO {$tablename} (id) SELECT id" . ' FROM ' . $this->hierarchyCache[$values], __METHOD__);
         return;
     }
     $this->fillHierarchyCacheForTableId($tablename, $values, $smwtable, $depth);
 }
 public function testUnregisteredKeyThrowsException()
 {
     $instance = new ResolverOptions();
     $this->setExpectedException('InvalidArgumentException');
     $instance->get('Foo');
 }