示例#1
0
 public function mapForeignKeys($table, Column $column, $id = null)
 {
     try {
         $relatedRows = $this->db->executeQuery("SELECT * FROM {$table} ORDER BY id ASC")->fetchAll();
         if (isset($relatedRows[0]['name'])) {
             $foreign = 'name';
         } else {
             $comments = json_decode($column->getComment(), true);
             if (!empty($comments) && is_array($comments)) {
                 $foreign = $foreign['foreign'];
             } else {
                 $foreign = 'id';
             }
         }
         $choices = array();
         foreach ($relatedRows as $relatedRow) {
             if (null !== $id && $relatedRow['id'] == $id) {
                 return $relatedRow[$foreign];
             }
             $choices[$relatedRow['id']] = $relatedRow[$foreign];
         }
         return $choices;
     } catch (\Exception $e) {
         return false;
     }
 }
示例#2
0
 /**
  * Do checks for columns.
  *
  * @param Column $column
  * @param array  $alterData
  *
  * @return boolean
  */
 protected function checkColumn(Column $column, array $alterData)
 {
     // Not needed to be implemented yet
     if ($alterData['propertyName'] !== $column->getName()) {
         return false;
     }
     return false;
 }
示例#3
0
 /**
  * Do checks for columns.
  *
  * @param Column        $column
  * @param IgnoredChange $ignoredChange
  *
  * @return boolean
  */
 protected function checkColumn(Column $column, IgnoredChange $ignoredChange)
 {
     // Not needed to be implemented yet
     if ($ignoredChange->getPropertyName() !== $column->getName()) {
         return false;
     }
     return false;
 }
示例#4
0
文件: Field.php 项目: ablunier/crud
 public function getValidationRules()
 {
     if (count($this->validationRules) === 0 && $this->noValidate() === false) {
         if ($this->dbal->getNotnull()) {
             $this->validationRules[] = 'required';
         }
     }
     return implode('|', $this->validationRules);
 }
示例#5
0
 /**
  * Build a Doctrine column object for TYPE/TYPE columns.
  *
  * @param array $tableColumn
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @return \Doctrine\DBAL\Schema\Column
  * @throws \Doctrine\DBAL\DBALException
  * @todo: The $tableColumn source currently only support MySQL definition style.
  */
 protected function getEnumerationTableColumnDefinition(array $tableColumn, AbstractPlatform $platform) : Column
 {
     $options = ['length' => $tableColumn['length'] ?: null, 'unsigned' => false, 'fixed' => false, 'default' => $tableColumn['default'] ?: null, 'notnull' => (bool) ($tableColumn['null'] !== 'YES'), 'scale' => null, 'precision' => null, 'autoincrement' => false, 'comment' => $tableColumn['comment'] ?: null];
     $dbType = $this->getDatabaseType($tableColumn['type']);
     $doctrineType = $platform->getDoctrineTypeMapping($dbType);
     $column = new Column($tableColumn['field'], Type::getType($doctrineType), $options);
     $column->setPlatformOption('unquotedValues', $this->getUnquotedEnumerationValues($tableColumn['type']));
     return $column;
 }
示例#6
0
 /**
  * @param \Doctrine\DBAL\Schema\Column $column
  * @param mixed $value
  */
 public function generateField($column, $value = null)
 {
     if ($value) {
         $this->value = $value;
     }
     $this->setLabel($column->getName());
     $this->name = $column->getName();
     return $this;
 }
 /**
  * @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));
 }
 /**
  * @group DBAL-42
  */
 public function testColumnComment()
 {
     $column = new Column("bar", Type::getType('string'));
     $this->assertNull($column->getComment());
     $column->setComment("foo");
     $this->assertEquals("foo", $column->getComment());
     $columnArray = $column->toArray();
     $this->assertArrayHasKey('comment', $columnArray);
     $this->assertEquals('foo', $columnArray['comment']);
 }
示例#9
0
 /**
  * @param \Doctrine\DBAL\Schema\Column $column
  * @param mixed $value
  * @return string
  */
 protected function getHtmlAttributes($column, $value = null)
 {
     $result = "";
     if (isset($value)) {
         $result .= "value='{$value}' ";
     }
     if ($name = $column->getName()) {
         $fieldName = $this->generateFieldName($name);
         $result .= "id='field_{$name}'  {$fieldName}";
     }
     return $result;
 }
示例#10
0
 /**
  * Maps only needed definitions defined as __CLASS__ properties
  * @param Column $column
  */
 public function __construct(Column $column)
 {
     foreach ($column->toArray() as $type => $value) {
         if (array_key_exists($type, get_class_vars(__CLASS__))) {
             if ($value instanceof Type) {
                 $this->{$type} = $value->getName();
                 continue;
             }
             $this->{$type} = $value;
         }
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 protected function _getPortableTableColumnDefinition($tableColumn)
 {
     $dbType = strtolower($tableColumn['DATA_TYPE']);
     $type = $this->_platform->getDoctrineTypeMapping($dbType);
     $type = $this->extractDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
     $tableColumn['COLUMN_COMMENT'] = $this->removeDoctrineTypeFromComment($tableColumn['COLUMN_COMMENT'], $type);
     $options = array('notnull' => !(bool) $tableColumn['IS_NULLABLE'], 'length' => (int) $tableColumn['CHARACTER_MAXIMUM_LENGTH'], 'default' => isset($tableColumn['COLUMN_DEFAULT']) ? $tableColumn['COLUMN_DEFAULT'] : null, 'autoincrement' => (bool) $tableColumn['IS_AUTO_INCREMENT'], 'scale' => (int) $tableColumn['NUMERIC_SCALE'], 'precision' => (int) $tableColumn['NUMERIC_PRECISION'], 'comment' => isset($tableColumn['COLUMN_COMMENT']) && '' !== $tableColumn['COLUMN_COMMENT'] ? $tableColumn['COLUMN_COMMENT'] : null);
     $column = new Column($tableColumn['COLUMN_NAME'], Type::getType($type), $options);
     if (!empty($tableColumn['COLLATION_NAME'])) {
         $column->setPlatformOption('collation', $tableColumn['COLLATION_NAME']);
     }
     return $column;
 }
 public function testGetIntegerColumnOptions()
 {
     $this->assertPlatform();
     $this->platform->expects($this->once())->method('isCommentedDoctrineType')->will($this->returnValue(true));
     $column = new Column('string_column', Type::getType(Type::INTEGER));
     $column->setNotnull(false);
     $column->setAutoincrement(true);
     $column->setUnsigned(true);
     $result = $this->extension->getColumnOptions($column);
     $this->assertEquals(4, count($result));
     $this->assertTrue($result['unsigned']);
     $this->assertTrue($result['autoincrement']);
     $this->assertFalse($result['notnull']);
     $this->assertEquals('(DC2Type:integer)', $result['comment']);
 }
 /**
  * Check for Sequence Duplicates.
  * 
  * Episodes of the same entity that overlap in time.
  * 
  * @access public
  * @return boolean the result of the operation
  * @param mixed     $oMixed     The Entity to do operation on
  */
 public function execute($oMixed)
 {
     $oOperation = $this->oOperation;
     $oConnection = $this->oConnection;
     # execute operation, only care if its successful
     $bResult = $oOperation->execute($oMixed);
     $sTableName = $this->sTableName;
     if (true === $bResult) {
         try {
             $oInnerQuery = new QueryBuilder($oConnection);
             $oInnerQuery->select('count(*)')->from($sTableName, 's2')->andWhere('s1.' . $this->oFromColum->getName() . ' < s2.' . $this->oToColumn->getName() . ' ')->andWhere('s2.' . $this->oFromColum->getName() . ' < s1.' . $this->oToColumn->getName() . ' ');
             # process the key columns
             foreach ($this->oNaturalKeyColumns as $oColumn) {
                 $oInnerQuery->andWhere('s1.' . $oColumn->getName() . ' = s2.' . $oColumn->getName() . ' ');
             }
             // verify the consistence
             $sSql = "SELECT count(*) FROM '.{$sTableName}.' AS s1\n                    WHERE 1 < (\n                        '.{$oInnerQuery->getSql}().'        \n                ); ";
             $iCount = (int) $oConnection->fetchColumn($sSql, array(), 0);
             if ($iCount > 0) {
                 throw new VoucherException('This entity has a sequence duplicate unable to finish operation');
             }
         } catch (DBALException $e) {
             throw new VoucherException($e->getMessage(), 0, $e);
         }
     }
     return $bResult;
 }
 /**
  * @param string $tableName
  * @param string $columnName
  * @param \Doctrine\DBAL\Schema\Column $column
  * @return array
  */
 protected function getAddColumnSQL($tableName, $columnName, Column $column)
 {
     $query = array();
     $spatial = array('srid' => 4326, 'dimension' => 2, 'index' => false);
     foreach ($spatial as $key => &$val) {
         if ($column->hasCustomSchemaOption('spatial_' . $key)) {
             $val = $column->getCustomSchemaOption('spatial_' . $key);
         }
     }
     // Geometry columns are created by AddGeometryColumn stored procedure
     $query[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $tableName, $columnName, $spatial['srid'], strtoupper($column->getType()->getName()), $spatial['dimension']);
     if ($spatial['index']) {
         // Add a spatial index to the field
         $query[] = sprintf("Select CreateSpatialIndex('%s', '%s')", $tableName, $columnName);
     }
     return $query;
 }
示例#15
0
 /**
  * @param \Doctrine\DBAL\Schema\Column $column
  * @param mixed $value
  */
 public function generateField($column, $value = null)
 {
     $multiple = false;
     $options = $column->getValues();
     $options_temp = array();
     foreach ($options as $index => $option) {
         $option = str_replace("'", '', $option);
         $option = str_replace("\"", '', $option);
         $options_temp[$option] = $option;
     }
     $options = $options_temp;
     if (!$column->hasUniqueValue()) {
         $multiple = true;
     }
     $value = explode(",", $value);
     $name = $column->getName();
     return $this->generateFilledField($options, $name, $multiple, $value);
 }
示例#16
0
 protected function getFormElement()
 {
     if (!empty($this->config['form_type'])) {
         if (!in_array($this->config['form_type'], $this->databaseTypeToFormType)) {
             throw new FactoryException('Unknown form type ' . $this->config['form_type']);
         }
         $formElementType = $this->config['form_type'];
     } else {
         if (!array_key_exists($this->column->getType()->getName(), $this->databaseTypeToFormType)) {
             throw new FactoryException('No form type found for database type ' . $this->column->getType()->getName());
         }
         $formElementType = $this->databaseTypeToFormType[$this->column->getType()->getName()];
     }
     if (isset($this->config['defaults']) && is_array($this->config['defaults'])) {
         $formElementType = 'select';
     }
     $formElement = $this->factory->get($formElementType, []);
     if (!empty($this->config['attr']) && is_array($this->config['attr'])) {
         $formElement->attr($this->config['attr']);
     }
     if ($formElementType !== 'hidden') {
         $formElement->class('form-control')->label($this->getPresentation())->placeholder($this->getPresentation());
     }
     if ($formElementType === 'textarea') {
         $formElement->class('form-control ' . config('anavel-crud.text_editor'));
     }
     if ($formElementType === 'checkbox') {
         $formElement->class('checkbox');
     }
     if (isset($this->config['defaults'])) {
         if (!is_array($this->config['defaults'])) {
             $formElement->val(transcrud($this->config['defaults']));
         } else {
             $defaults = [];
             foreach ($this->config['defaults'] as $key => $default) {
                 $defaults[$key] = transcrud($default);
             }
             $formElement->options($defaults);
         }
     }
     return $formElement;
 }
 /**
  * {@inheritdoc}
  */
 protected function _getPortableTableColumnDefinition($tableColumn)
 {
     $dbType = strtok($tableColumn['type'], '(), ');
     $fixed = null;
     $length = (int) $tableColumn['length'];
     $default = $tableColumn['default'];
     if (!isset($tableColumn['name'])) {
         $tableColumn['name'] = '';
     }
     while ($default != ($default2 = preg_replace("/^\\((.*)\\)\$/", '$1', $default))) {
         $default = trim($default2, "'");
         if ($default == 'getdate()') {
             $default = $this->_platform->getCurrentTimestampSQL();
         }
     }
     switch ($dbType) {
         case 'nchar':
         case 'nvarchar':
         case 'ntext':
             // Unicode data requires 2 bytes per character
             $length = $length / 2;
             break;
         case 'varchar':
             // TEXT type is returned as VARCHAR(MAX) with a length of -1
             if ($length == -1) {
                 $dbType = 'text';
             }
             break;
     }
     if ('char' === $dbType || 'nchar' === $dbType || 'binary' === $dbType) {
         $fixed = true;
     }
     $type = $this->_platform->getDoctrineTypeMapping($dbType);
     $type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
     $tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
     $options = array('length' => $length == 0 || !in_array($type, array('text', 'string')) ? null : $length, 'unsigned' => false, 'fixed' => (bool) $fixed, 'default' => $default !== 'NULL' ? $default : null, 'notnull' => (bool) $tableColumn['notnull'], 'scale' => $tableColumn['scale'], 'precision' => $tableColumn['precision'], 'autoincrement' => (bool) $tableColumn['autoincrement'], 'comment' => $tableColumn['comment'] !== '' ? $tableColumn['comment'] : null);
     $column = new Column($tableColumn['name'], Type::getType($type), $options);
     if (isset($tableColumn['collation']) && $tableColumn['collation'] !== 'NULL') {
         $column->setPlatformOption('collation', $tableColumn['collation']);
     }
     return $column;
 }
 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;
 }
示例#19
0
 /**
  * Creates a column replacement, which has a quoted name.
  *
  * @param Column $column
  *
  * @return Column
  */
 private function createColumnReplacement(Column $column)
 {
     $columnConfig = $column->toArray();
     $columnConfig['platformOptions'] = $column->getPlatformOptions();
     $columnConfig['customSchemaOptions'] = $column->getCustomSchemaOptions();
     return new Column($this->platform->quoteIdentifier($column->getName()), $column->getType(), $columnConfig);
 }
示例#20
0
文件: Schema.php 项目: seytar/psx
 protected function getType(Column $column)
 {
     $type = 0;
     if ($column->getLength() > 0) {
         $type += $column->getLength();
     }
     $type = $type | SerializeTrait::getTypeByDoctrineType($column->getType());
     if (!$column->getNotnull()) {
         $type = $type | TableInterface::IS_NULL;
     }
     if ($column->getAutoincrement()) {
         $type = $type | TableInterface::AUTO_INCREMENT;
     }
     return $type;
 }
 /**
  * @param Column $column
  * @param Collection $foreignKeyColumns
  * @param Collection $foreignTables
  * @param Collection $indexes
  * @return ColumnInterface
  */
 protected function buildColumn(Column $column, Collection $foreignKeyColumns, Collection $foreignTables, Collection $indexes)
 {
     $uniqued = $indexes->filter(function (Index $index) use($column) {
         return $index->getColumns()[0] == $column->getName() && $index->isUnique();
     })->count() > 0;
     if ($column->getAutoincrement()) {
         return new ColumnAutoincrement($column, null, null, $uniqued);
     } else {
         if ($foreignKeyColumns->has($column->getName())) {
             $table = $foreignKeyColumns->get($column->getName());
             return new ColumnSelect($column, $table, $foreignTables->get($table), $uniqued);
         } else {
             if ($column->getType()->getName() == Type::INTEGER) {
                 return new ColumnNumericText($column, null, null, $uniqued);
             } else {
                 return new ColumnText($column, null, null, $uniqued);
             }
         }
     }
 }
示例#22
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);
 }
示例#23
0
 public function diffColumn(Column $column1, Column $column2)
 {
     $changedProperties = array();
     if ($column1->getType() != $column2->getType()) {
         //espo: fix problem with executing query for custom types
         $column1DbTypeName = method_exists($column1->getType(), 'getDbTypeName') ? $column1->getType()->getDbTypeName() : $column1->getType()->getName();
         $column2DbTypeName = method_exists($column2->getType(), 'getDbTypeName') ? $column2->getType()->getDbTypeName() : $column2->getType()->getName();
         if (strtolower($column1DbTypeName) != strtolower($column2DbTypeName)) {
             $changedProperties[] = 'type';
         }
         //END: espo
     }
     if ($column1->getNotnull() != $column2->getNotnull()) {
         $changedProperties[] = 'notnull';
     }
     if ($column1->getDefault() != $column2->getDefault()) {
         $changedProperties[] = 'default';
     }
     if ($column1->getUnsigned() != $column2->getUnsigned()) {
         $changedProperties[] = 'unsigned';
     }
     if ($column1->getType() instanceof \Doctrine\DBAL\Types\StringType) {
         // check if value of length is set at all, default value assumed otherwise.
         $length1 = $column1->getLength() ?: 255;
         $length2 = $column2->getLength() ?: 255;
         /** Fox: column length can be increased only */
         /*if ($length1 != $length2) {
               $changedProperties[] = 'length';
           }*/
         if ($length2 > $length1) {
             $changedProperties[] = 'length';
         }
         /** Fox: end */
         if ($column1->getFixed() != $column2->getFixed()) {
             $changedProperties[] = 'fixed';
         }
     }
     if ($column1->getType() instanceof \Doctrine\DBAL\Types\DecimalType) {
         if (($column1->getPrecision() ?: 10) != ($column2->getPrecision() ?: 10)) {
             $changedProperties[] = 'precision';
         }
         if ($column1->getScale() != $column2->getScale()) {
             $changedProperties[] = 'scale';
         }
     }
     if ($column1->getAutoincrement() != $column2->getAutoincrement()) {
         $changedProperties[] = 'autoincrement';
     }
     // only allow to delete comment if its set to '' not to null.
     if ($column1->getComment() !== null && $column1->getComment() != $column2->getComment()) {
         $changedProperties[] = 'comment';
     }
     $options1 = $column1->getCustomSchemaOptions();
     $options2 = $column2->getCustomSchemaOptions();
     $commonKeys = array_keys(array_intersect_key($options1, $options2));
     foreach ($commonKeys as $key) {
         if ($options1[$key] !== $options2[$key]) {
             $changedProperties[] = $key;
         }
     }
     $diffKeys = array_keys(array_diff_key($options1, $options2) + array_diff_key($options2, $options1));
     $changedProperties = array_merge($changedProperties, $diffKeys);
     return $changedProperties;
 }
示例#24
0
 /**
  * Get the field type for a given column.
  *
  * @param string                       $name
  * @param \Doctrine\DBAL\Schema\Column $column
  *
  * @return string
  */
 protected function getFieldTypeFor($name, $column)
 {
     $contentKey = $this->schemaManager->getKeyForTable($name);
     if ($contentKey && isset($this->contenttypes[$contentKey]['fields'][$column->getName()])) {
         $type = $this->contenttypes[$contentKey]['fields'][$column->getName()]['type'];
     } elseif ($column->getType()) {
         $type = get_class($column->getType());
     }
     if ($type === 'select' && isset($this->contenttypes[$contentKey]['fields'][$column->getName()]['multiple']) && $this->contenttypes[$contentKey]['fields'][$column->getName()]['multiple'] === true) {
         $type = 'selectmultiple';
     }
     if (isset($this->typemap[$type])) {
         $type = $this->typemap[$type];
     } else {
         $type = $this->typemap['text'];
     }
     return $type;
 }
 /**
  * Build field mapping from a schema column definition
  *
  * @param string                       $tableName
  * @param \Doctrine\DBAL\Schema\Column $column
  *
  * @return array
  */
 private function buildFieldMapping($tableName, Column $column)
 {
     $fieldMapping = array('fieldName' => $this->getFieldNameForColumn($tableName, $column->getName(), false), 'columnName' => $column->getName(), 'type' => $column->getType()->getName(), 'nullable' => !$column->getNotNull());
     // Type specific elements
     switch ($fieldMapping['type']) {
         case Type::TARRAY:
         case Type::BLOB:
         case Type::GUID:
         case Type::JSON_ARRAY:
         case Type::OBJECT:
         case Type::SIMPLE_ARRAY:
         case Type::STRING:
         case Type::TEXT:
             $fieldMapping['length'] = $column->getLength();
             $fieldMapping['options']['fixed'] = $column->getFixed();
             break;
         case Type::DECIMAL:
         case Type::FLOAT:
             $fieldMapping['precision'] = $column->getPrecision();
             $fieldMapping['scale'] = $column->getScale();
             break;
         case Type::INTEGER:
         case Type::BIGINT:
         case Type::SMALLINT:
             $fieldMapping['options']['unsigned'] = $column->getUnsigned();
             break;
     }
     // Comment
     if (($comment = $column->getComment()) !== null) {
         $fieldMapping['options']['comment'] = $comment;
     }
     // Weather
     if (($default = $column->getDefault()) !== null) {
         $fieldMapping['options']['default'] = $default;
     }
     return $fieldMapping;
 }
示例#26
0
 /**
  * Set the renamed columns on the table diff.
  *
  * @param  \Doctrine\DBAL\Schema\TableDiff  $tableDiff
  * @param  \Illuminate\Support\Fluent  $command
  * @param  \Doctrine\DBAL\Schema\Column  $column
  * @return \Doctrine\DBAL\Schema\TableDiff
  */
 protected function setRenamedColumns(TableDiff $tableDiff, Fluent $command, Column $column)
 {
     $newColumn = new Column($command->to, $column->getType(), $column->toArray());
     $tableDiff->renamedColumns = array($command->from => $newColumn);
     return $tableDiff;
 }
示例#27
0
 /**
  * @param Column $column
  */
 protected function _addColumn(Column $column)
 {
     $columnName = $column->getName();
     $columnName = strtolower($columnName);
     if (isset($this->_columns[$columnName])) {
         throw SchemaException::columnAlreadyExists($this->getName(), $columnName);
     }
     $this->_columns[$columnName] = $column;
 }
 public function acceptColumn(Table $table, Column $column)
 {
     $this->addViolation('Table ' . $table->getName() . ' column ' . $column->getName(), $this->isReservedWord($column->getName()));
 }
 /**
  * {@inheritdoc}
  */
 protected function _getPortableTableColumnDefinition($tableColumn)
 {
     $tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
     if (strtolower($tableColumn['type']) === 'varchar' || strtolower($tableColumn['type']) === 'bpchar') {
         // get length from varchar definition
         $length = preg_replace('~.*\\(([0-9]*)\\).*~', '$1', $tableColumn['complete_type']);
         $tableColumn['length'] = $length;
     }
     $matches = array();
     $autoincrement = false;
     if (preg_match("/^nextval\\('(.*)'(::.*)?\\)\$/", $tableColumn['default'], $matches)) {
         $tableColumn['sequence'] = $matches[1];
         $tableColumn['default'] = null;
         $autoincrement = true;
     }
     if (preg_match("/^'(.*)'::.*\$/", $tableColumn['default'], $matches)) {
         $tableColumn['default'] = $matches[1];
     }
     if (stripos($tableColumn['default'], 'NULL') === 0) {
         $tableColumn['default'] = null;
     }
     $length = isset($tableColumn['length']) ? $tableColumn['length'] : null;
     if ($length == '-1' && isset($tableColumn['atttypmod'])) {
         $length = $tableColumn['atttypmod'] - 4;
     }
     if ((int) $length <= 0) {
         $length = null;
     }
     $fixed = null;
     if (!isset($tableColumn['name'])) {
         $tableColumn['name'] = '';
     }
     $precision = null;
     $scale = null;
     $dbType = strtolower($tableColumn['type']);
     if (strlen($tableColumn['domain_type']) && !$this->_platform->hasDoctrineTypeMappingFor($tableColumn['type'])) {
         $dbType = strtolower($tableColumn['domain_type']);
         $tableColumn['complete_type'] = $tableColumn['domain_complete_type'];
     }
     $type = $this->_platform->getDoctrineTypeMapping($dbType);
     $type = $this->extractDoctrineTypeFromComment($tableColumn['comment'], $type);
     $tableColumn['comment'] = $this->removeDoctrineTypeFromComment($tableColumn['comment'], $type);
     switch ($dbType) {
         case 'smallint':
         case 'int2':
             $length = null;
             break;
         case 'int':
         case 'int4':
         case 'integer':
             $length = null;
             break;
         case 'bigint':
         case 'int8':
             $length = null;
             break;
         case 'bool':
         case 'boolean':
             if ($tableColumn['default'] === 'true') {
                 $tableColumn['default'] = true;
             }
             if ($tableColumn['default'] === 'false') {
                 $tableColumn['default'] = false;
             }
             $length = null;
             break;
         case 'text':
             $fixed = false;
             break;
         case 'varchar':
         case 'interval':
         case '_varchar':
             $fixed = false;
             break;
         case 'char':
         case 'bpchar':
             $fixed = true;
             break;
         case 'float':
         case 'float4':
         case 'float8':
         case 'double':
         case 'double precision':
         case 'real':
         case 'decimal':
         case 'money':
         case 'numeric':
             if (preg_match('([A-Za-z]+\\(([0-9]+)\\,([0-9]+)\\))', $tableColumn['complete_type'], $match)) {
                 $precision = $match[1];
                 $scale = $match[2];
                 $length = null;
             }
             break;
         case 'year':
             $length = null;
             break;
     }
     if ($tableColumn['default'] && preg_match("('([^']+)'::)", $tableColumn['default'], $match)) {
         $tableColumn['default'] = $match[1];
     }
     $options = array('length' => $length, 'notnull' => (bool) $tableColumn['isnotnull'], 'default' => $tableColumn['default'], 'primary' => (bool) ($tableColumn['pri'] == 't'), 'precision' => $precision, 'scale' => $scale, 'fixed' => $fixed, 'unsigned' => false, 'autoincrement' => $autoincrement, 'comment' => isset($tableColumn['comment']) && $tableColumn['comment'] !== '' ? $tableColumn['comment'] : null);
     $column = new Column($tableColumn['field'], Type::getType($type), $options);
     if (isset($tableColumn['collation']) && !empty($tableColumn['collation'])) {
         $column->setPlatformOption('collation', $tableColumn['collation']);
     }
     return $column;
 }
 /**
  * @group DBAL-106
  */
 public function testDiffDecimalWithNullPrecision()
 {
     $column = new Column('foo', Type::getType('decimal'));
     $column->setPrecision(null);
     $column2 = new Column('foo', Type::getType('decimal'));
     $c = new Comparator();
     $this->assertEquals(array(), $c->diffColumn($column, $column2));
 }