本文整理汇总了PHP中Doctrine\DBAL\Schema\AbstractSchemaManager::listTableDetails方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractSchemaManager::listTableDetails方法的具体用法?PHP AbstractSchemaManager::listTableDetails怎么用?PHP AbstractSchemaManager::listTableDetails使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Schema\AbstractSchemaManager
的用法示例。
在下文中一共展示了AbstractSchemaManager::listTableDetails方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reverseEngineerMappingFromDatabase
private function reverseEngineerMappingFromDatabase()
{
if ($this->tables !== null) {
return;
}
foreach ($this->_sm->listTableNames() as $tableName) {
$tables[strtolower($tableName)] = $this->_sm->listTableDetails($tableName);
}
$this->tables = array();
foreach ($tables as $name => $table) {
/* @var $table Table */
if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$foreignKeys = $table->getForeignKeys();
} else {
$foreignKeys = array();
}
$allForeignKeyColumns = array();
foreach ($foreignKeys as $foreignKey) {
$allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
}
$pkColumns = $table->getPrimaryKey()->getColumns();
sort($pkColumns);
sort($allForeignKeyColumns);
if ($pkColumns == $allForeignKeyColumns) {
if (count($table->getForeignKeys()) > 2) {
throw new \InvalidArgumentException("ManyToMany table '" . $name . "' with more or less than two foreign keys are not supported by the Database Reverese Engineering Driver.");
}
$this->manyToManyTables[$name] = $table;
} else {
$className = Inflector::classify($name);
$this->tables[$name] = $table;
$this->classes[$className] = $name;
}
}
}
示例2: __construct
public function __construct($tableName)
{
$this->tableName = $tableName;
$this->schema = DB::getDoctrineSchemaManager($tableName);
$this->table = $this->schema->listTableDetails($tableName);
$this->analyzeIndexes();
}
示例3: setName
/**
* @param $name
*
* @throws SchemaException
*/
public function setName($name)
{
if (!$this->sm->tablesExist($this->prefix . $name)) {
throw new SchemaException("Table {$name} does not exist!");
}
$this->table = $this->sm->listTableDetails($this->prefix . $name);
}
示例4: reverseEngineerMappingFromDatabase
private function reverseEngineerMappingFromDatabase()
{
if ($this->tables !== null) {
return;
}
foreach ($this->_sm->listTableNames() as $tableName) {
$tables[$tableName] = $this->_sm->listTableDetails($tableName);
}
$this->tables = $this->manyToManyTables = $this->classToTableNames = array();
foreach ($tables as $tableName => $table) {
/* @var $table Table */
if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$foreignKeys = $table->getForeignKeys();
} else {
$foreignKeys = array();
}
$allForeignKeyColumns = array();
foreach ($foreignKeys as $foreignKey) {
$allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
}
$pkColumns = $table->getPrimaryKey()->getColumns();
sort($pkColumns);
sort($allForeignKeyColumns);
if ($pkColumns == $allForeignKeyColumns && count($foreignKeys) == 2) {
$this->manyToManyTables[$tableName] = $table;
} else {
// lower-casing is necessary because of Oracle Uppercase Tablenames,
// assumption is lower-case + underscore separated.
$className = Inflector::classify(strtolower($tableName));
$this->tables[$tableName] = $table;
$this->classToTableNames[$className] = $tableName;
}
}
}
示例5: setName
/**
* Set the table to be manipulated
*
* @param string $table
* @param bool $addPrefix
*/
public function setName($table, $addPrefix = true)
{
$this->tableName = $addPrefix ? $this->prefix . $table : $table;
//make sure the table exists
$this->checkTableExists($this->tableName, true);
//use the to schema to get table details so that changes will be calculated
$this->fromTable = $this->sm->listTableDetails($this->tableName);
$this->toTable = clone $this->fromTable;
}
示例6: testAlterColumnComment
/**
* @group DBAL-1009
*
* @dataProvider getAlterColumnComment
*/
public function testAlterColumnComment($comment1, $expectedComment1, $comment2, $expectedComment2)
{
if (!$this->_conn->getDatabasePlatform()->supportsInlineColumnComments() && !$this->_conn->getDatabasePlatform()->supportsCommentOnStatement() && $this->_conn->getDatabasePlatform()->getName() != 'mssql') {
$this->markTestSkipped('Database does not support column comments.');
}
$offlineTable = new Table('alter_column_comment_test');
$offlineTable->addColumn('comment1', 'integer', array('comment' => $comment1));
$offlineTable->addColumn('comment2', 'integer', array('comment' => $comment2));
$offlineTable->addColumn('no_comment1', 'integer');
$offlineTable->addColumn('no_comment2', 'integer');
$this->_sm->dropAndCreateTable($offlineTable);
$onlineTable = $this->_sm->listTableDetails("alter_column_comment_test");
$this->assertSame($expectedComment1, $onlineTable->getColumn('comment1')->getComment());
$this->assertSame($expectedComment2, $onlineTable->getColumn('comment2')->getComment());
$this->assertNull($onlineTable->getColumn('no_comment1')->getComment());
$this->assertNull($onlineTable->getColumn('no_comment2')->getComment());
$onlineTable->changeColumn('comment1', array('comment' => $comment2));
$onlineTable->changeColumn('comment2', array('comment' => $comment1));
$onlineTable->changeColumn('no_comment1', array('comment' => $comment1));
$onlineTable->changeColumn('no_comment2', array('comment' => $comment2));
$comparator = new Comparator();
$tableDiff = $comparator->diffTable($offlineTable, $onlineTable);
$this->assertInstanceOf('Doctrine\\DBAL\\Schema\\TableDiff', $tableDiff);
$this->_sm->alterTable($tableDiff);
$onlineTable = $this->_sm->listTableDetails("alter_column_comment_test");
$this->assertSame($expectedComment2, $onlineTable->getColumn('comment1')->getComment());
$this->assertSame($expectedComment1, $onlineTable->getColumn('comment2')->getComment());
$this->assertSame($expectedComment1, $onlineTable->getColumn('no_comment1')->getComment());
$this->assertSame($expectedComment2, $onlineTable->getColumn('no_comment2')->getComment());
}
示例7: reverseEngineerMappingFromDatabase
/**
* @return void
*
* @throws \Doctrine\ORM\Mapping\MappingException
*/
private function reverseEngineerMappingFromDatabase()
{
if ($this->tables !== null) {
return;
}
$tables = array();
foreach ($this->_sm->listTableNames() as $tableName) {
$tables[$tableName] = $this->_sm->listTableDetails($tableName);
}
$this->tables = $this->manyToManyTables = $this->classToTableNames = array();
foreach ($tables as $tableName => $table) {
$foreignKeys = $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints() ? $table->getForeignKeys() : array();
$allForeignKeyColumns = array();
foreach ($foreignKeys as $foreignKey) {
$allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
}
if (!$table->hasPrimaryKey()) {
throw new MappingException("Table " . $table->getName() . " has no primary key. Doctrine does not " . "support reverse engineering from tables that don't have a primary key.");
}
$pkColumns = $table->getPrimaryKey()->getColumns();
sort($pkColumns);
sort($allForeignKeyColumns);
if ($pkColumns == $allForeignKeyColumns && count($foreignKeys) == 2) {
$this->manyToManyTables[$tableName] = $table;
} else {
// lower-casing is necessary because of Oracle Uppercase Tablenames,
// assumption is lower-case + underscore separated.
$className = $this->getClassNameForTable($tableName);
$this->tables[$tableName] = $table;
$this->classToTableNames[$className] = $tableName;
}
}
}
示例8: testAlterTableThrowsExceptionForChangedSpatialType
public function testAlterTableThrowsExceptionForChangedSpatialType()
{
$this->setExpectedException('\\RuntimeException', 'The geometry_type of a spatial column cannot be changed (Requested changing type from "POINT" to "LINESTRING" for column "point_2d" in table "points")');
$table = $this->sm->listTableDetails('points');
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('points');
$tableDiff->fromTable = $table;
$tableDiff->changedColumns[] = new ColumnDiff('point_2d', new \Doctrine\DBAL\Schema\Column('point_2d', Type::getType('geometry'), array('customSchemaOptions' => array('geometry_type' => 'LINESTRING'))), array('geometry_type'), $table->getColumn('point_2d'));
$this->sm->alterTable($tableDiff);
}
示例9: testListTableWithBlob
/**
* @group DBAL-197
*/
public function testListTableWithBlob()
{
$table = new \Doctrine\DBAL\Schema\Table('test_blob_table');
$table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
$table->addColumn('binarydata', 'blob', array());
$table->setPrimaryKey(array('id'));
$this->_sm->createTable($table);
$blobTable = $this->_sm->listTableDetails('test_blob_table');
}
示例10: getPrimaryKey
/**
* Get the primary key from the table.
*
* @param string $table
* @return string|null
*/
public function getPrimaryKey($table)
{
//todo try
//return $this->schema->listTableDetails($table)->getPrimaryKey();
try {
$primaryKeys = $this->schema->listTableDetails($table)->getPrimaryKeyColumns();
return reset($primaryKeys);
} catch (DBALException $e) {
return false;
}
}
示例11: testAlterTableScenario
public function testAlterTableScenario()
{
if (!$this->_sm->getDatabasePlatform()->supportsAlterTable()) {
$this->markTestSkipped('Alter Table is not supported by this platform.');
}
$this->createTestTable('alter_table');
$this->createTestTable('alter_table_foreign');
$table = $this->_sm->listTableDetails('alter_table');
$this->assertTrue($table->hasColumn('id'));
$this->assertTrue($table->hasColumn('test'));
$this->assertTrue($table->hasColumn('foreign_key_test'));
$this->assertEquals(0, count($table->getForeignKeys()));
$this->assertEquals(1, count($table->getIndexes()));
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
$tableDiff->addedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', Type::getType('integer'));
$tableDiff->removedColumns['test'] = $table->getColumn('test');
$this->_sm->alterTable($tableDiff);
$table = $this->_sm->listTableDetails('alter_table');
$this->assertFalse($table->hasColumn('test'));
$this->assertTrue($table->hasColumn('foo'));
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
$tableDiff->addedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo'));
$this->_sm->alterTable($tableDiff);
$table = $this->_sm->listTableDetails('alter_table');
$this->assertEquals(2, count($table->getIndexes()));
$this->assertTrue($table->hasIndex('foo_idx'));
$this->assertEquals(array('foo'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns()));
$this->assertFalse($table->getIndex('foo_idx')->isPrimary());
$this->assertFalse($table->getIndex('foo_idx')->isUnique());
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
$tableDiff->changedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo', 'foreign_key_test'));
$this->_sm->alterTable($tableDiff);
$table = $this->_sm->listTableDetails('alter_table');
$this->assertEquals(2, count($table->getIndexes()));
$this->assertTrue($table->hasIndex('foo_idx'));
$this->assertEquals(array('foo', 'foreign_key_test'), array_map('strtolower', $table->getIndex('foo_idx')->getColumns()));
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff("alter_table");
$tableDiff->removedIndexes[] = new \Doctrine\DBAL\Schema\Index('foo_idx', array('foo', 'foreign_key_test'));
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('foreign_key_test'), 'alter_table_foreign', array('id'));
$tableDiff->addedForeignKeys[] = $fk;
$this->_sm->alterTable($tableDiff);
$table = $this->_sm->listTableDetails('alter_table');
// dont check for index size here, some platforms automatically add indexes for foreign keys.
$this->assertFalse($table->hasIndex('foo_idx'));
$this->assertEquals(1, count($table->getForeignKeys()));
$fks = $table->getForeignKeys();
$foreignKey = current($fks);
$this->assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName()));
$this->assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns()));
$this->assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns()));
}
示例12: testAutoincrementDetection
public function testAutoincrementDetection()
{
if (!$this->_sm->getDatabasePlatform()->supportsIdentityColumns()) {
$this->markTestSkipped('This test is only supported on platforms that have autoincrement');
}
$table = new \Doctrine\DBAL\Schema\Table('test_autoincrement');
$table->setSchemaConfig($this->_sm->createSchemaConfig());
$table->addColumn('id', 'integer', array('autoincrement' => true));
$table->setPrimaryKey(array('id'));
$this->_sm->createTable($table);
$inferredTable = $this->_sm->listTableDetails('test_autoincrement');
$this->assertTrue($inferredTable->hasColumn('id'));
$this->assertTrue($inferredTable->getColumn('id')->getAutoincrement());
}
示例13: setFields
/**
* @param EloquentModel $model
* @return $this
*/
protected function setFields(EloquentModel $model)
{
$tableDetails = $this->manager->listTableDetails($model->getTableName());
$primaryColumnNames = $tableDetails->getPrimaryKey()->getColumns();
$columnNames = [];
foreach ($tableDetails->getColumns() as $column) {
$model->addProperty(new VirtualPropertyModel($column->getName(), $this->resolveType($column->getType()->getName())));
if (!in_array($column->getName(), $primaryColumnNames)) {
$columnNames[] = $column->getName();
}
}
$fillableProperty = new PropertyModel('fillable');
$fillableProperty->setAccess('protected')->setValue($columnNames)->setDocBlock(new DocBlockModel('@var array'));
$model->addProperty($fillableProperty);
return $this;
}
示例14: _get_doctrine_table_diff
/**
* Create an empty Doctrine DBAL TableDiff from the Blueprint.
*
* @param Schema_Blueprint $blueprint
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
* @return \Doctrine\DBAL\Schema\TableDiff
*/
protected function _get_doctrine_table_diff(Schema_Blueprint $blueprint, SchemaManager $schema)
{
$table = $this->get_table_prefix() . $blueprint->get_table();
$table_diff = new TableDiff($table);
$table_diff->fromTable = $schema->listTableDetails($table);
return $table_diff;
}
示例15: getDoctrineTableDiff
/**
* Create an empty Doctrine DBAL TableDiff from the Blueprint.
*
* @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
* @return \Doctrine\DBAL\Schema\TableDiff
*/
protected function getDoctrineTableDiff(Blueprint $blueprint, SchemaManager $schema)
{
$table = $this->getTablePrefix() . $blueprint->getTable();
$tableDiff = new TableDiff($table);
$tableDiff->fromTable = $schema->listTableDetails($table);
return $tableDiff;
}