/** * test if the check method returns the correct values */ public function testCheck() { $types = array('bit', 'tinyint', 'bool', 'smallint', 'mediumint', 'int', 'bigint', 'float', 'double', 'decimal', 'char', 'varchar', 'tinytext', 'text', 'mediumtext', 'longtext', 'tinyblob', 'blob', 'mediumblob', 'longblob', 'binary', 'varbinary', 'enum', 'set', 'date', 'datetime', 'timestamp', 'time', 'year'); $options_bool = array(DataType::SUPPORTS_COLLATION, DataType::SUPPORTS_INDEX, DataType::SUPPORTS_UNIQUE, DataType::SUPPORTS_FULLTEXT, DataType::SUPPORTS_SIZE, DataType::SUPPORTS_SCALE, DataType::SUPPORTS_VALUES, DataType::SUPPORTS_UNSIGNED, DataType::SUPPORTS_UNSIGNED_ZEROFILL, DataType::SUPPORTS_ON_UPDATE_CURRENT_TIMESTAMP, DataType::SUPPORTS_AUTO_INCREMENT); $options_string = array(DataType::GROUP, DataType::INPUT_TYPE); foreach ($types as $type) { foreach ($options_bool as $option) { $this->assertType('bool', DataType::check($type, $option)); } foreach ($options_string as $option) { $this->assertType('string', DataType::check($type, $option)); } } }
public function getColumnDefinition() { if (DataType::check($this->DATA_TYPE, DataType::SUPPORTS_COLLATION)) { $collate = ' CHARACTER SET ' . Collation::getCharacterSet($this->COLLATION_NAME) . ' COLLATE ' . $this->COLLATION_NAME; } else { $collate = ''; } if ($this->attribute) { if ($this->attribute == 'unsigned' && DataType::check($this->DATA_TYPE, DataType::SUPPORTS_UNSIGNED) || $this->attribute == 'unsigned zerofill' && DataType::check($this->DATA_TYPE, DataType::SUPPORTS_UNSIGNED_ZEROFILL) || $this->attribute == 'on update current_timestamp' && DataType::check($this->DATA_TYPE, DataType::SUPPORTS_ON_UPDATE_CURRENT_TIMESTAMP)) { $attribute = ' ' . $this->attribute; } else { $attribute = ''; } } else { $attribute = ''; } if (strlen($this->COLUMN_DEFAULT) > 0 && $this->EXTRA != 'auto_increment') { if ($this->DATA_TYPE == 'timestamp' && strtolower($this->COLUMN_DEFAULT) == 'current_timestamp') { $defaultValue = 'CURRENT_TIMESTAMP'; } elseif ($this->DATA_TYPE == 'bit') { if (preg_match('/b\'[01]+\'/', $this->COLUMN_DEFAULT)) { $defaultValue = $this->COLUMN_DEFAULT; } else { $defaultValue = 'b' . self::$db->quoteValue($this->COLUMN_DEFAULT); } } else { $defaultValue = self::$db->quoteValue($this->COLUMN_DEFAULT); } $default = ' DEFAULT ' . $defaultValue; } else { if ($this->getIsNullable() && $this->EXTRA != 'auto_increment') { $default = ' DEFAULT NULL'; } else { $default = ''; } } return trim(self::$db->quoteColumnName($this->COLUMN_NAME) . ' ' . $this->getColumnType() . $attribute . $collate . ($this->getIsNullable() ? ' NULL' : ' NOT NULL') . $default . ($this->EXTRA == 'auto_increment' ? ' AUTO_INCREMENT' : '') . ($this->createPrimaryKey ? ' PRIMARY KEY' : '') . ($this->createUniqueKey ? ' UNIQUE KEY' : '') . (strlen($this->COLUMN_COMMENT) ? ' COMMENT ' . self::$db->quoteValue($this->COLUMN_COMMENT) : '')); }
</a> <?php } else { ?> <span class="icon"> <?php echo Html::icon('key_unique', 16, true, 'core.uniqueKey'); ?> </span> <?php } ?> </td> <td> <?php if ($canAlter && DataType::check($column->DATA_TYPE, DataType::SUPPORTS_FULLTEXT)) { ?> <a href="javascript:void(0)" onclick="tableStructure.addIndex1('fulltext', $(this).closest('tr').attr('id').substr(8))" class="icon"> <?php echo Html::icon('key_fulltext', 16, false, 'core.fulltextIndex'); ?> </a> <?php } else { ?> <span class="icon"> <?php echo Html::icon('key_fulltext', 16, true, 'core.fulltextIndex'); ?> </span> <?php