示例#1
0
 protected function createTable($name, $columns = array())
 {
     $table = new Table($name);
     foreach ($columns as $column) {
         $table->addColumn($column);
     }
     $createTableCommand = new CreateTableCommand();
     $createTableCommand->setConnection($this->connection)->setEventDispatcher($this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcher'))->setTable($table)->execute();
 }
示例#2
0
 protected function setUp()
 {
     $table = new Table('foo');
     $table->addColumn(new IntegerColumn('bar_id'));
     $tableReferenced = new Table('bar');
     $this->foreignKey = new ForeignKey(new Table('foo'), new Table('bar'));
     $this->foreignKey->setColumns('bar_id');
     $this->foreignKey->setReferencedColumns('bar_id');
 }
 public function testCreateTableWithNotAutoIncrementPrimaryKey()
 {
     $primaryKey = new PrimaryKey();
     $primaryKey->disableAutoIncrement();
     $table = new Table('foo');
     $table->addConstraint($primaryKey);
     $this->getCreateTableCommand()->setTable($table)->execute();
     $getTableCommand = new GetTableCommand();
     $getTableCommand->setConnection($this->connection);
     $getTableCommand->setTableName('foo');
     $tableInfo = $getTableCommand->execute();
     $this->assertEquals('integer', $tableInfo->getColumn('foo_id')->getType());
 }
示例#4
0
 /**
  * Load contsraints to table.
  *
  * @param Table $table A table.
  *
  * @return void
  */
 private function loadConstraints(Table $table)
 {
     foreach ($this->getConstraints() as $constraint) {
         switch ($constraint['constraint_type']) {
             case 'FOREIGN KEY':
                 // TODO Find a better way to define foreign key
                 $foreignKey = new ForeignKey(new Table($constraint['table_name']), new Table($constraint['column_name']));
                 $foreignKey->setColumns($constraint['references_table']);
                 $foreignKey->setReferencedColumns($constraint['references_field']);
                 $table->addConstraint($foreignKey);
                 break;
             case 'PRIMARY KEY':
                 $table->addConstraint(new PrimaryKey($constraint['column_name'], $table));
                 break;
             case 'UNIQUE':
                 $table->addConstraint(new Unique($constraint['column_name'], new Table($constraint['table_name'])));
                 break;
         }
     }
 }
示例#5
0
文件: Info.php 项目: czogori/rentgen
 /**
  * Get table information.
  *
  * @param Table $table Table instance.
  *
  * @return Table Table instance.
  */
 public function getTable(Table $table)
 {
     return $this->container->get('rentgen.get_table')->setTableName($table->getName())->execute();
 }
示例#6
0
文件: TableApi.php 项目: czogori/dami
 /**
  * Constructor.
  *
  * @param string       $table        Table name.
  * @param Schema       $schema
  * @param Manipulation $manipulation
  * @param array        $actions
  */
 public function __construct($name, Schema $schema = null, Manipulation $manipulation, &$actions)
 {
     parent::__construct($name, $schema);
     $this->manipulation = $manipulation;
     $this->actions =& $actions;
 }
示例#7
0
 public function testSchema()
 {
     $table = new Table('foo');
     $table->setSchema(new Schema('bar'));
     $this->assertThat(new Schema('bar'), $this->logicalAnd($this->equalTo($table->getSchema())));
 }