public function endElement($parser, $name) { if ('index' === $name) { $this->currTable->addIndex($this->currIndex); } else { if ('unique' === $name) { $this->currTable->addUnique($this->currUnique); } } if (self::DEBUG) { print 'endElement(' . $name . ") called\n"; } $this->popCurrentSchemaTag(); }
/** * Load indexes for this table */ protected function addIndexes(Table $table) { $stmt = $this->dbh->query("PRAGMA index_list('" . $table->getName() . "')"); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $name = $row['name']; $index = new Index($name); $stmt2 = $this->dbh->query("PRAGMA index_info('" . $name . "')"); while ($row2 = $stmt2->fetch(\PDO::FETCH_ASSOC)) { $colname = $row2['name']; $index->addColumn($table->getColumn($colname)); } $table->addIndex($index); } }
/** * Load indexes for this table */ protected function addIndexes(Table $table) { $stmt = $this->dbh->query('PRAGMA index_list("' . $table->getName() . '")'); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $name = $row['name']; $internalName = $name; if (0 === strpos($name, 'sqlite_autoindex')) { $internalName = ''; } $index = $row['unique'] ? new Unique($internalName) : new Index($internalName); $stmt2 = $this->dbh->query("PRAGMA index_info('" . $name . "')"); while ($row2 = $stmt2->fetch(\PDO::FETCH_ASSOC)) { $colname = $row2['name']; $index->addColumn($table->getColumn($colname)); } if (1 === count($table->getPrimaryKey()) && 1 === count($index->getColumns())) { // exclude the primary unique index, since it's autogenerated by sqlite if ($table->getPrimaryKey()[0]->getName() === $index->getColumns()[0]) { continue; } } if ($index instanceof Unique) { $table->addUnique($index); } else { $table->addIndex($index); } } }
public function testIsIndex() { $table = new Table(); $column1 = new Column('category_id'); $column2 = new Column('type'); $table->addColumn($column1); $table->addColumn($column2); $index = new Index('test_index'); $index->setColumns([$column1, $column2]); $table->addIndex($index); $this->assertTrue($table->isIndex(['category_id', 'type'])); $this->assertTrue($table->isIndex(['type', 'category_id'])); $this->assertFalse($table->isIndex(['category_id', 'type2'])); $this->assertFalse($table->isIndex(['asd'])); }
/** * Load indexes for this table */ protected function addIndexes(Table $table) { $dataFetcher = $this->dbh->query("sp_indexes_rowset '" . $table->getName() . "'"); $indexes = array(); foreach ($dataFetcher as $row) { $colName = $this->cleanDelimitedIdentifiers($row["COLUMN_NAME"]); $name = $this->cleanDelimitedIdentifiers($row['INDEX_NAME']); // FIXME -- Add UNIQUE support if (!isset($indexes[$name])) { $indexes[$name] = new Index($name); $table->addIndex($indexes[$name]); } $indexes[$name]->addColumn($table->getColumn($colName)); } }
/** * Adds Indexes to the specified table. * * @param Table $table The Table model class to add columns to. */ protected function addIndexes(Table $table) { $stmt = $this->dbh->query("SELECT COLUMN_NAME, INDEX_NAME FROM USER_IND_COLUMNS WHERE TABLE_NAME = '" . $table->getName() . "' ORDER BY COLUMN_NAME"); $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); $indices = array(); foreach ($rows as $row) { $indices[$row['INDEX_NAME']][] = $row['COLUMN_NAME']; } foreach ($indices as $indexName => $columnNames) { $index = new Index($indexName); foreach ($columnNames as $columnName) { // Oracle deals with complex indices using an internal reference, so... // let's ignore this kind of index if ($table->hasColumn($columnName)) { $index->addColumn($table->getColumn($columnName)); } } // since some of the columns are pruned above, we must only add an index if it has columns if ($index->hasColumns()) { $table->addIndex($index); } } }
public function testGetIndexDDLFulltext() { $table = new Table('foo'); $table->setIdentifierQuoting(true); $column1 = new Column('bar1'); $column1->getDomain()->copy($this->getPlatform()->getDomainForType('LONGVARCHAR')); $table->addColumn($column1); $index = new Index('bar_index'); $index->addColumn($column1); $vendor = new VendorInfo('mysql'); $vendor->setParameter('Index_type', 'FULLTEXT'); $index->addVendorInfo($vendor); $table->addIndex($index); $expected = 'FULLTEXT INDEX `bar_index` (`bar1`)'; $this->assertEquals($expected, $this->getPlatform()->getIndexDDL($index)); }
$table3->addColumns([$column31, $column32]); $table4 = new Table('blog_tag'); $table4->setDescription('The list of tags'); $table4->setNamespace('Blog'); $table4->setPackage('Acme.Blog'); $table4->addColumns([$column41, $column42]); $table5 = new Table('blog_post_tag'); $table5->setNamespace('Blog'); $table5->setPackage('Acme.Blog'); $table5->setCrossRef(); $table5->addColumns([$column51, $column52]); $table5->addForeignKeys([$fkPostTag, $fkTagPost]); $table6 = new Table('cms_page'); $table6->setPhpName('Page'); $table6->setNamespace('Cms'); $table6->setBaseClass('Acme\\Model\\PublicationActiveRecord'); $table6->setPackage('Acme.Cms'); $table6->addColumns([$column61, $column62, $column63, $column64]); $table6->addIndex($pageContentFulltextIdx); $table6->addVendorInfo(new VendorInfo('mysql', ['Engine' => 'MyISAM'])); /* Database */ $database = new Database('acme_blog', new MysqlPlatform()); $database->setSchema('acme'); $database->setTablePrefix('acme_'); $database->setNamespace('Acme\\Model'); $database->setBaseClass('Acme\\Model\\ActiveRecord'); $database->setPackage('Acme'); $database->setHeavyIndexing(); $database->addVendorInfo(new VendorInfo('mysql', ['Engine' => 'InnoDB', 'Charset' => 'utf8'])); $database->addTables([$table1, $table2, $table3, $table4, $table5, $table6]); return $database;
public function testCompareModifiedIndices() { $t1 = new Table(); $c1 = new Column('Foo'); $c1->getDomain()->copy($this->platform->getDomainForType('VARCHAR')); $c1->getDomain()->replaceSize(255); $c1->setNotNull(false); $t1->addColumn($c1); $i1 = new Index('Foo_Index'); $i1->addColumn($c1); $t1->addIndex($i1); $t2 = new Table(); $c2 = new Column('Foo'); $c2->getDomain()->copy($this->platform->getDomainForType('DOUBLE')); $c2->getDomain()->replaceScale(2); $c2->getDomain()->replaceSize(3); $c2->setNotNull(true); $c2->getDomain()->setDefaultValue(new ColumnDefaultValue(123, ColumnDefaultValue::TYPE_VALUE)); $t2->addColumn($c2); $i2 = new Unique('Foo_Index'); $i2->addColumn($c2); $t2->addIndex($i2); $tc = new PropelTableComparator(); $tc->setFromTable($t1); $tc->setToTable($t2); $nbDiffs = $tc->compareIndices(); $tableDiff = $tc->getTableDiff(); $this->assertEquals(1, $nbDiffs); $this->assertEquals(1, count($tableDiff->getModifiedIndices())); $this->assertEquals(array('Foo_Index' => array($i1, $i2)), $tableDiff->getModifiedIndices()); }
public function providerForTestGetIndexDDL() { $table = new Table('foo'); $table->setIdentifierQuoting(true); $column1 = new Column('bar1'); $column1->getDomain()->copy(new Domain('FOOTYPE')); $table->addColumn($column1); $column2 = new Column('bar2'); $column2->getDomain()->copy(new Domain('BARTYPE')); $table->addColumn($column2); $index = new Index('babar'); $index->addColumn($column1); $index->addColumn($column2); $table->addIndex($index); return array(array($index)); }
/** * Load indexes for this table */ protected function addIndexes(Table $table, $oid) { $stmt = $this->dbh->prepare("SELECT\n DISTINCT ON(cls.relname)\n cls.relname as idxname,\n indkey,\n indisunique\n FROM pg_index idx\n JOIN pg_class cls ON cls.oid=indexrelid\n WHERE indrelid = ? AND NOT indisprimary\n ORDER BY cls.relname"); $stmt->bindValue(1, $oid); $stmt->execute(); $stmt2 = $this->dbh->prepare("SELECT a.attname\n FROM pg_catalog.pg_class c JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid\n WHERE c.oid = ? AND a.attnum = ? AND NOT a.attisdropped\n ORDER BY a.attnum"); $indexes = array(); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $name = $row['idxname']; $unique = in_array($row['indisunique'], ['t', true, 1, '1']) ? true : false; if (!isset($indexes[$name])) { if ($unique) { $indexes[$name] = new Unique($name); } else { $indexes[$name] = new Index($name); } $table->addIndex($indexes[$name]); } $arrColumns = explode(' ', $row['indkey']); foreach ($arrColumns as $intColNum) { $stmt2->bindValue(1, $oid); $stmt2->bindValue(2, $intColNum); $stmt2->execute(); $row2 = $stmt2->fetch(\PDO::FETCH_ASSOC); $indexes[$name]->addColumn($table->getColumn($row2['attname'])); } } }
/** * Load indexes for this table */ protected function addIndexes(Table $table) { $stmt = $this->dbh->query("SHOW INDEX FROM `" . $table->getName() . "`"); // Loop through the returned results, grouping the same key_name together // adding each column for that key. $indexes = array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $colName = $row["Column_name"]; $name = $row["Key_name"]; if ($name == "PRIMARY") { continue; } if (!isset($indexes[$name])) { $isUnique = $row["Non_unique"] == 0; if ($isUnique) { $indexes[$name] = new Unique($name); } else { $indexes[$name] = new Index($name); } if ($this->addVendorInfo) { $vi = $this->getNewVendorInfoObject($row); $indexes[$name]->addVendorInfo($vi); } $table->addIndex($indexes[$name]); } $indexes[$name]->addColumn($table->getColumn($colName)); } }
/** * Load indexes for this table */ protected function addIndexes(Table $table) { $stmt = $this->dbh->query(sprintf('SHOW INDEX FROM %s', $this->getPlatform()->quoteIdentifier($table->getName()))); // Loop through the returned results, grouping the same key_name together // adding each column for that key. $indexes = array(); while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { $colName = $row['Column_name']; $name = $row['Key_name']; if ('PRIMARY' === $name) { continue; } if (!isset($indexes[$name])) { $isUnique = 0 == $row['Non_unique']; if ($isUnique) { $indexes[$name] = new Unique($name); } else { $indexes[$name] = new Index($name); } if ($this->addVendorInfo) { $vi = $this->getNewVendorInfoObject($row); $indexes[$name]->addVendorInfo($vi); } $table->addIndex($indexes[$name]); } $indexes[$name]->addColumn($table->getColumn($colName)); } }
protected function addColumn(Table $table, $name) { if (!$table->hasColumn($name)) { $column = new Column($name); // don't know how to define unsigned :( $domain = new Domain('TINYINT', 'tinyint(3) unsigned'); $column->setDomain($domain); $table->addColumn($column); $column_idx_name = $name . '_idx'; if (!$table->hasIndex($column_idx_name)) { $column_idx = new Index($column_idx_name); $column_idx->addColumn(['name' => $column->getName()]); $table->addIndex($column_idx); } } }
public function testAddArrayIndex() { $table = new Table(); $table->addIndex(array('name' => 'author_idx')); $this->assertCount(1, $table->getIndices()); }
/** * Load indexes for this table */ protected function addIndexes(Table $table) { $stmt = $this->dbh->query("sp_indexes_rowset '" . $table->getName() . "'"); $indexes = array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $colName = $row["COLUMN_NAME"]; $name = $row['INDEX_NAME']; // FIXME -- Add UNIQUE support if (!isset($indexes[$name])) { $indexes[$name] = new Index($name); $table->addIndex($indexes[$name]); } $indexes[$name]->addColumn($table->getColumn($colName)); } }