protected function remapType(Column $column) { if (!isset($this->typeMap[$column->getType()])) { throw new Exception('Type "' . $column->getType() . '" is not allowed'); } return $this->typeMap[$column->getType()]; }
protected function createEnumSetColumn(Column $column, Table $table) { $values = []; if ($column->getType() == Column::TYPE_ENUM) { $values = $column->getValues(); } elseif ($column->getType() === Column::TYPE_SET) { $this->createSetCombinations($column->getValues(), '', $values); } return sprintf($this->remapType($column), $column->getName(), implode(',', array_map(function ($value) { return "'{$value}'"; }, $values))); }
private function createColumnCharset(Column $column) { return $this->createCharset($column->getCharset(), $column->getCollation(), ' '); }
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()); }
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; }
/** * @param Column $column * @return Table */ public function addColumn(Column $column) { $this->columns[$column->getName()] = $column; return $this; }