예제 #1
0
 public function testComplex()
 {
     $column = new Column('title', 'string', ['null' => true, 'default' => '', 'length' => 255, 'after' => 'id']);
     $this->assertEquals('title', $column->getName());
     $this->assertEquals('string', $column->getType());
     $this->assertTrue($column->allowNull());
     $this->assertEquals('', $column->getDefault());
     $this->assertEquals(255, $column->getLength());
     $this->assertEquals(255, $column->getLength(100));
     $this->assertNull($column->getDecimals());
     $this->assertEquals(2, $column->getDecimals(2));
     $this->assertTrue($column->isSigned());
     $this->assertFalse($column->isAutoincrement());
     $this->assertFalse($column->isFirst());
     $this->assertEquals('id', $column->getAfter());
 }
예제 #2
0
 protected function createColumn(Column $column, Table $table)
 {
     $col = $this->escapeString($column->getName()) . ' ' . $this->createType($column, $table);
     $col .= $column->isAutoincrement() && in_array($column->getName(), $table->getPrimaryColumns()) ? ' PRIMARY KEY AUTOINCREMENT' : '';
     $col .= $column->allowNull() ? '' : ' NOT NULL';
     if ($column->getDefault() !== null && $column->getDefault() !== '') {
         $col .= ' DEFAULT ';
         if (in_array($column->getType(), [Column::TYPE_INTEGER, Column::TYPE_BOOLEAN])) {
             $col .= intval($column->getDefault());
         } else {
             $col .= "'" . $column->getDefault() . "'";
         }
     } elseif ($column->allowNull() && $column->getDefault() === null) {
         $col .= ' DEFAULT NULL';
     }
     return $col;
 }
예제 #3
0
 protected function createColumn(Column $column, Table $table)
 {
     $col = $this->escapeString($column->getName()) . ' ' . $this->createType($column, $table);
     $col .= !$column->isSigned() ? ' unsigned' : '';
     $col .= $this->createColumnCharset($column);
     $col .= $column->allowNull() ? '' : ' NOT NULL';
     $col .= $this->createColumnDefault($column);
     $col .= $this->createColumnPosition($column);
     $col .= $column->isAutoincrement() ? ' AUTO_INCREMENT' : '';
     return $col;
 }
예제 #4
0
 protected function createColumn(Column $column, Table $table)
 {
     $col = $this->escapeString($column->getName()) . ' ' . $this->createType($column, $table);
     if ($column->getDefault() !== null || $column->isAutoincrement()) {
         $col .= ' DEFAULT ';
         if ($column->isAutoincrement()) {
             $col .= "nextval('" . $table->getName() . "_seq'::regclass)";
         } elseif ($column->getType() == Column::TYPE_INTEGER) {
             $col .= $column->getDefault();
         } elseif ($column->getType() == Column::TYPE_BOOLEAN) {
             $col .= $column->getDefault() ? 'true' : 'false';
         } else {
             $col .= "'" . $column->getDefault() . "'";
         }
     } elseif ($column->allowNull() && $column->getDefault() === null) {
         $col .= ' DEFAULT NULL';
     }
     $col .= $column->allowNull() ? '' : ' NOT NULL';
     return $col;
 }
예제 #5
0
파일: Table.php 프로젝트: lulco/phoenix
 /**
  * @param Column $column
  * @return Table
  */
 public function addColumn(Column $column)
 {
     $this->columns[$column->getName()] = $column;
     return $this;
 }