public function testGetFixedProperty()
 {
     $instance = new TableDefinition('foo', 'bar');
     $this->setExpectedException('OutOfBoundsException');
     $instance->getFixedProperty();
 }
 /**
  * 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);
         }
     }
 }
 /**
  * Get the current data stored for the given ID in the given database
  * table. The result is an array of updates, formatted like the one of
  * the table insertion arrays created by preparePropertyTableInserts().
  *
  * @note Tables without IDs as subject are not supported. They will
  * hopefully vanish soon anyway.
  *
  * @since 1.8
  * @param integer $sid
  * @param TableDefinition $tableDeclaration
  * @return array
  */
 private function fetchCurrentContentsForPropertyTable($sid, TableDefinition $propertyTable)
 {
     if (!$propertyTable->usesIdSubject()) {
         // does not occur, but let's be strict
         throw new InvalidArgumentException('Operation not supported for tables without subject IDs.');
     }
     $contents = array();
     $connection = $this->store->getConnection('mw.db');
     $result = $connection->select($connection->tablename($propertyTable->getName()), '*', array('s_id' => $sid), __METHOD__);
     foreach ($result as $row) {
         if (is_object($row)) {
             $resultRow = (array) $row;
             // Always make sure to use int values for ids so
             // that the compare/hash will be of the same type
             if (isset($resultRow['s_id'])) {
                 $resultRow['s_id'] = (int) $resultRow['s_id'];
             }
             if (isset($resultRow['p_id'])) {
                 $resultRow['p_id'] = (int) $resultRow['p_id'];
             }
             if (isset($resultRow['o_id'])) {
                 $resultRow['o_id'] = (int) $resultRow['o_id'];
             }
             $contents[] = $resultRow;
         }
     }
     return $contents;
 }