public function testCreateIndex() { $connection = $this->getMockBuilder('\\DatabaseBase')->disableOriginalConstructor()->setMethods(array('tableExists', 'query'))->getMockForAbstractClass(); $connection->expects($this->any())->method('getType')->will($this->returnValue('sqlite')); $connection->expects($this->any())->method('tableExists')->will($this->returnValue(false)); $connection->expects($this->at(3))->method('query')->with($this->stringContains('PRAGMA index_list("foo")'))->will($this->returnValue(array())); $connection->expects($this->at(4))->method('query')->with($this->stringContains('CREATE INDEX "foo"_index0')); $instance = SQLiteTableBuilder::factory($connection); $table = new Table('foo'); $table->addColumn('bar', 'text'); $table->addIndex('bar'); $instance->create($table); }
public function testCreateIndex() { $connection = $this->getMockBuilder('\\DatabaseBase')->disableOriginalConstructor()->setMethods(array('tableExists', 'query'))->getMockForAbstractClass(); $connection->expects($this->any())->method('getType')->will($this->returnValue('mysql')); $connection->expects($this->any())->method('tableExists')->will($this->returnValue(false)); $connection->expects($this->at(3))->method('query')->with($this->stringContains('SHOW INDEX'))->will($this->returnValue(array())); $connection->expects($this->at(4))->method('query')->with($this->stringContains('ALTER TABLE "foo" ADD INDEX (bar)')); $instance = MySQLTableBuilder::factory($connection); $table = new Table('foo'); $table->addColumn('bar', 'text'); $table->addIndex('bar'); $instance->create($table); }
public function testCreateIndex() { $connection = $this->getMockBuilder('\\DatabaseBase')->disableOriginalConstructor()->setMethods(array('tableExists', 'query', 'indexInfo'))->getMockForAbstractClass(); $connection->expects($this->any())->method('getType')->will($this->returnValue('postgres')); $connection->expects($this->any())->method('tableExists')->will($this->returnValue(false)); $connection->expects($this->any())->method('indexInfo')->will($this->returnValue(false)); $connection->expects($this->at(3))->method('query')->with($this->stringContains('SELECT i.relname AS indexname'))->will($this->returnValue(array())); $connection->expects($this->at(5))->method('query')->with($this->stringContains('CREATE INDEX foo_index0 ON foo (bar)')); $instance = PostgresTableBuilder::factory($connection); $table = new Table('foo'); $table->addColumn('bar', 'text'); $table->addIndex('bar'); $instance->create($table); }
public function testAddOptionWithInvalidKeyThrowsException() { $instance = new Table('Foo'); $this->setExpectedException('RuntimeException'); $instance->addOption('fields', array('foobar')); }
public function testUpdateIndex_NoIndexChange() { $messageReporter = $this->messageReporterFactory->newSpyMessageReporter(); $this->tableBuilder->setMessageReporter($messageReporter); $table = new Table($this->tableName); $table->addColumn('id', FieldType::FIELD_ID_PRIMARY); $table->addColumn('t_text', array(FieldType::TYPE_BLOB, 'NOT NULL')); $table->addColumn('t_num', array(FieldType::TYPE_DOUBLE, 'NOT NULL')); $table->addColumn('t_int', array(FieldType::TYPE_INT)); $table->addIndex(array('id', 'UNIQUE INDEX')); $this->tableBuilder->create($table); $expected = array('Checking index structures for table rdbms_test', 'index id is fine'); if ($this->tableBuilder instanceof SQLiteTableBuilder) { $expected = str_replace('index id is fine', 'creating new index id', $expected); $expected = 'removing index'; } $this->stringValidator->assertThatStringContains($expected, $messageReporter->getMessagesAsString()); }
/** * @since 2.5 * * {@inheritDoc} */ public function drop(Table $table) { $tableName = $table->getName(); if ($this->connection->tableExists($tableName) === false) { // create new table return $this->reportMessage(" ... {$tableName} not found, skipping removal.\n"); } $this->doDropTable($tableName); $this->reportMessage(" ... dropped table {$tableName}.\n"); }
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; }