コード例 #1
0
 public function testAddIndexWithKey()
 {
     $instance = new Table('Foo');
     $instance->addIndexWithKey('bar', array('foobar'));
     $expected = array('indicies' => array('bar' => array('foobar')));
     $this->assertEquals($expected, $instance->getConfiguration());
 }
コード例 #2
0
 private function newPropertyTable($propertyTable, $diHandler)
 {
     // Prepare indexes. By default, property-value tables
     // have the following indexes:
     //
     // sp: getPropertyValues(), getSemanticData(), getProperties()
     // po: ask, getPropertySubjects()
     //
     // The "p" component is omitted for tables with fixed property.
     $indexes = array();
     if ($propertyTable->usesIdSubject()) {
         $fieldarray = array('s_id' => array(FieldType::FIELD_ID, 'NOT NULL'));
         $indexes['sp'] = 's_id';
     } else {
         $fieldarray = array('s_title' => array(FieldType::FIELD_TITLE, 'NOT NULL'), 's_namespace' => array(FieldType::FIELD_NAMESPACE, 'NOT NULL'));
         $indexes['sp'] = 's_title,s_namespace';
     }
     $indexes['po'] = $diHandler->getIndexField();
     if (!$propertyTable->isFixedPropertyTable()) {
         $fieldarray['p_id'] = array(FieldType::FIELD_ID, 'NOT NULL');
         $indexes['po'] = 'p_id,' . $indexes['po'];
         $indexes['sp'] = $indexes['sp'] . ',p_id';
     }
     // TODO Special handling; concepts should be handled differently
     // in the future. See comments in SMW_DIHandler_Concept.php.
     if ($propertyTable->getDiType() === DataItem::TYPE_CONCEPT) {
         unset($indexes['po']);
     }
     $indexes = array_merge($indexes, $diHandler->getTableIndexes());
     $indexes = array_unique($indexes);
     foreach ($diHandler->getTableFields() as $fieldname => $fieldType) {
         $fieldarray[$fieldname] = $fieldType;
     }
     $table = new Table($propertyTable->getName());
     foreach ($fieldarray as $fieldName => $fieldType) {
         $table->addColumn($fieldName, $fieldType);
     }
     foreach ($indexes as $key => $index) {
         $table->addIndexWithKey($key, $index);
     }
     return $table;
 }