Пример #1
0
 /**
  * Determines whether the current column definition should be updated based on the property
  * instance supplied.
  *
  * @param array $columnInfo An array containing the column properties as defined in MySQL's
  *                          information_schema.COLUMNS table.
  * @param phpDataMapper_Property $property
  * @return bool
  */
 protected function shouldUpdateColumnDefinition(array $columnInfo, phpDataMapper_Property $property)
 {
     // Field type
     $expectedType = $this->_propertyColumnTypeMap[$property->type()];
     if (strtolower($expectedType) != $columnInfo['DATA_TYPE']) {
         return true;
     }
     // Length
     if (preg_match('/^[a-z]+\\((\\d+)\\)$/', $columnInfo['COLUMN_TYPE'], $regex_matches)) {
         if ($property->hasOption('length')) {
             $expectedLength = $property->option('length');
         } elseif (isset($this->_defaultLengths[$expectedType])) {
             $expectedLength = $this->_defaultLengths[$expectedType];
         }
         if (isset($expectedLength) && $expectedLength != $regex_matches[1]) {
             return true;
         }
     }
     // Default value
     $defaultValue = $property->option('default');
     if ($property->option('required') && $defaultValue === NULL) {
         $expectedDefault = '';
     } else {
         $expectedDefault = $defaultValue;
     }
     if ($expectedDefault != $columnInfo['COLUMN_DEFAULT']) {
         return true;
     }
     // Nullable
     $expectedNullable = $property->option('required') || $property->option('primary') ? 'NO' : 'YES';
     if ($expectedNullable != $columnInfo['IS_NULLABLE']) {
         return true;
     }
     // Auto increment
     $isSerialInDB = preg_match('/\\bauto_increment\\b/', $columnInfo['EXTRA']);
     if ($isSerialInDB != $property->option('serial', false)) {
         return true;
     }
     return false;
 }
Пример #2
0
 protected function fieldDefaults()
 {
     return array_merge(parent::fieldDefaults(), array('length' => 255));
 }
Пример #3
0
 protected function fieldDefaults()
 {
     return array_merge(parent::fieldDefaults(), array('length' => 11, 'serial' => false));
 }