public function testGetters()
 {
     $diType = SMWDataItem::TYPE_NUMBER;
     $name = 'smw_di_number';
     $instance = new TableDefinition($diType, $name);
     $this->assertInternalType('array', $instance->getFields(StoreFactory::getStore('SMWSQLStore3')));
     $this->assertEquals($diType, $instance->getDiType());
     $this->assertEquals($name, $instance->getName());
 }
 /**
  * Helper function to compute from and where strings for a DB query so that
  * only rows of the given value object match. The parameter $tableindex
  * counts that tables used in the query to avoid duplicate table names. The
  * parameter $proptable provides the SMWSQLStore3Table object that is
  * queried.
  *
  * @todo Maybe do something about redirects. The old code was
  * $oid = $this->store->smwIds->getSMWPageID($value->getDBkey(),$value->getNamespace(),$value->getInterwiki(),false);
  *
  * @note This method cannot handle DIContainer objects with sortkey
  * properties correctly. This should never occur, but it would be good
  * to fail in a more controlled way if it ever does.
  *
  * @param string $from
  * @param string $where
  * @param TableDefinition $propTable
  * @param SMWDataItem $value
  * @param integer $tableIndex
  */
 private function prepareValueQuery(&$from, &$where, TableDefinition $propTable, $value, $tableIndex = 1)
 {
     $db = $this->store->getConnection();
     if ($value instanceof SMWDIContainer) {
         // recursive handling of containers
         $keys = array_keys($propTable->getFields($this->store));
         $joinfield = "t{$tableIndex}." . reset($keys);
         // this must be a type 'p' object
         $proptables = $this->store->getPropertyTables();
         $semanticData = $value->getSemanticData();
         foreach ($semanticData->getProperties() as $subproperty) {
             $tableid = $this->store->findPropertyTableID($subproperty);
             $subproptable = $proptables[$tableid];
             foreach ($semanticData->getPropertyValues($subproperty) as $subvalue) {
                 $tableIndex++;
                 if ($subproptable->usesIdSubject()) {
                     // simply add property table to check values
                     $from .= " INNER JOIN " . $db->tableName($subproptable->getName()) . " AS t{$tableIndex} ON t{$tableIndex}.s_id={$joinfield}";
                 } else {
                     // exotic case with table that uses subject title+namespace in container object (should never happen in SMW core)
                     $from .= " INNER JOIN " . $db->tableName(SMWSql3SmwIds::TABLE_NAME) . " AS ids{$tableIndex} ON ids{$tableIndex}.smw_id={$joinfield}" . " INNER JOIN " . $db->tableName($subproptable->getName()) . " AS t{$tableIndex} ON " . "t{$tableIndex}.s_title=ids{$tableIndex}.smw_title AND t{$tableIndex}.s_namespace=ids{$tableIndex}.smw_namespace";
                 }
                 if (!$subproptable->isFixedPropertyTable()) {
                     // the ID we get should be !=0, so no point in filtering the converse
                     $where .= ($where ? ' AND ' : '') . "t{$tableIndex}.p_id=" . $db->addQuotes($this->store->smwIds->getSMWPropertyID($subproperty));
                 }
                 $this->prepareValueQuery($from, $where, $subproptable, $subvalue, $tableIndex);
             }
         }
     } elseif (!is_null($value)) {
         // add conditions for given value
         $diHandler = $this->store->getDataItemHandlerForDIType($value->getDIType());
         foreach ($diHandler->getWhereConds($value) as $fieldname => $value) {
             $where .= ($where ? ' AND ' : '') . "t{$tableIndex}.{$fieldname}=" . $db->addQuotes($value);
         }
     }
 }