/**
  * @group DBAL-64
  */
 public function testQuotedColumnName()
 {
     $string = Type::getType('string');
     $column = new Column("`bar`", $string, array());
     $mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform();
     $sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform();
     $this->assertEquals('bar', $column->getName());
     $this->assertEquals('`bar`', $column->getQuotedName($mysqlPlatform));
     $this->assertEquals('"bar"', $column->getQuotedName($sqlitePlatform));
 }
 public function getSql(Column $column, $table)
 {
     if (!$table instanceof Table) {
         $table = new Identifier($table);
     }
     $sql = array();
     $normalized = $column->getType()->getNormalizedPostGISColumnOptions($column->getCustomSchemaOptions());
     $srid = $normalized['srid'];
     // PostGIS 1.5 uses -1 for undefined SRID's
     if ($srid <= 0) {
         $srid = -1;
     }
     $type = strtoupper($normalized['geometry_type']);
     if ('ZM' === substr($type, -2)) {
         $dimension = 4;
         $type = substr($type, 0, -2);
     } elseif ('M' === substr($type, -1)) {
         $dimension = 3;
     } elseif ('Z' === substr($type, -1)) {
         $dimension = 3;
         $type = substr($type, 0, -1);
     } else {
         $dimension = 2;
     }
     // Geometry columns are created by the AddGeometryColumn stored procedure
     $sql[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $table->getName(), $column->getName(), $srid, $type, $dimension);
     if ($column->getNotnull()) {
         // Add a NOT NULL constraint to the field
         $sql[] = sprintf('ALTER TABLE %s ALTER %s SET NOT NULL', $table->getQuotedName($this->platform), $column->getQuotedName($this->platform));
     }
     return $sql;
 }
示例#3
0
 /**
  * Returns the SQL clause for renaming a column in a table alteration.
  *
  * @param string $oldColumnName The quoted name of the column to rename.
  * @param Column $column        The column to rename to.
  *
  * @return string
  */
 protected function getAlterTableRenameColumnClause($oldColumnName, Column $column)
 {
     $oldColumnName = new Identifier($oldColumnName);
     return 'RENAME ' . $oldColumnName->getQuotedName($this) . ' TO ' . $column->getQuotedName($this);
 }
示例#4
0
 /**
  * Returns the SQL clause for adding a default constraint in an ALTER TABLE statement.
  *
  * @param  string $tableName The name of the table to generate the clause for.
  * @param  Column $column    The column to generate the clause for.
  *
  * @return string
  */
 private function getAlterTableAddDefaultConstraintClause($tableName, Column $column)
 {
     $columnDef = $column->toArray();
     $columnDef['name'] = $column->getQuotedName($this);
     return 'ADD' . $this->getDefaultConstraintDeclarationSQL($tableName, $columnDef);
 }
 /**
  * Returns the SQL clause for renaming a column in a table alteration.
  *
  * @param string $oldColumnName The quoted name of the column to rename.
  * @param Column $column        The column to rename to.
  *
  * @return string
  */
 protected function getAlterTableRenameColumnClause($oldColumnName, Column $column)
 {
     return 'RENAME ' . $oldColumnName . ' TO ' . $column->getQuotedName($this);
 }
示例#6
0
 /**
  * @param \Doctrine\DBAL\Schema\Column $column The name of the table.
  * @param array $primaries
  *
  * @return array The column data as associative array.
  */
 public function prepareColumnData($column, $primaries = array())
 {
     $columnData = array();
     $columnData['name'] = $column->getQuotedName($this);
     $columnData['type'] = $column->getType();
     $columnData['length'] = $column->getLength();
     $columnData['notnull'] = $column->getNotNull();
     $columnData['fixed'] = $column->getFixed();
     $columnData['unique'] = false;
     // TODO: what do we do about this?
     $columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false;
     if (strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
         $columnData['length'] = 255;
     }
     $columnData['unsigned'] = $column->getUnsigned();
     $columnData['precision'] = $column->getPrecision();
     $columnData['scale'] = $column->getScale();
     $columnData['default'] = $column->getDefault();
     $columnData['columnDefinition'] = $column->getColumnDefinition();
     $columnData['autoincrement'] = $column->getAutoincrement();
     $columnData['comment'] = $this->getColumnComment($column);
     $columnData['platformOptions'] = $column->getPlatformOptions();
     if (in_array($column->getName(), $primaries)) {
         $columnData['primary'] = true;
     }
     return $columnData;
 }
示例#7
0
 /**
  * Gets the SQL to rename a column.
  *
  * @param string table that contains the column
  * @param string old column name
  * @param Column new column
  */
 protected function getRenameColumnSQL($tableName, $oldName, Column $column)
 {
     return 'RENAME COLUMN ' . $tableName . '.' . $oldName . ' TO ' . $column->getQuotedName($this);
 }