Esempio n. 1
0
 /**
  * @see		ActiveRecord::instantiate()
  */
 public function instantiate($attributes)
 {
     $res = parent::instantiate($attributes);
     /*
      * We have to set some properties by hand
      */
     if (isset($attributes['COLUMN_TYPE'])) {
         // Size / scale
         if (DataType::check($attributes['COLUMN_TYPE'], DataType::SUPPORTS_SIZE)) {
             if (preg_match('/^\\w+\\((\\d+)(,\\d+)?\\)/', $attributes['COLUMN_TYPE'], $result)) {
                 $res->size = (int) $result[1];
                 if (isset($result[2]) && DataType::check($attributes['COLUMN_TYPE'], DataType::SUPPORTS_SCALE)) {
                     $res->scale = (int) substr($result[2], 1);
                 }
             }
         } elseif (DataType::check($attributes['COLUMN_TYPE'], DataType::SUPPORTS_VALUES)) {
             if (preg_match('/^\\w+\\(\'([^\\)]+)\'\\)/', $attributes['COLUMN_TYPE'], $result)) {
                 $res->setValues(implode("\n", (array) explode("','", $result[1])));
             }
         }
         // Unsigned
         if (preg_match('/ unsigned$/', $attributes['COLUMN_TYPE'])) {
             $res->attribute = 'unsigned';
         } elseif (preg_match('/ unsigned zerofill$/', $attributes['COLUMN_TYPE'])) {
             $res->attribute = 'unsigned zerofill';
         } elseif ($attributes['COLUMN_TYPE'] == 'timestamp') {
             if (strtolower($attributes['EXTRA']) == 'on update current_timestamp') {
                 $res->attribute = 'on update current_timestamp';
             }
         }
     }
     return $res;
 }
Esempio n. 2
0
 /**
  * @see		ActiveRecord::instantiate()
  */
 public function instantiate($attributes)
 {
     $res = parent::instantiate($attributes);
     $res->table = Table::model()->findByAttributes(array('TABLE_SCHEMA' => $attributes['TABLE_SCHEMA'], 'TABLE_NAME' => $attributes['TABLE_NAME']));
     $match = '/^\\s+constraint `' . $attributes['CONSTRAINT_NAME'] . '` .+?$/im';
     if (preg_match($match, $res->table->getShowCreateTable(), $result)) {
         if (preg_match('/on delete (CASCADE|NO ACTION|SET NULL|RESTRICT)/i', $result[0], $result2)) {
             $res->onDelete = $result2[1];
         }
         if (preg_match('/on update (CASCADE|NO ACTION|SET NULL|RESTRICT)/i', $result[0], $result2)) {
             $res->onUpdate = $result2[1];
         }
     }
     return $res;
 }
Esempio n. 3
0
File: Table.php Progetto: cebe/chive
 /**
  * @see		ActiveRecord::instantiate()
  */
 public function instantiate($attributes)
 {
     $res = parent::instantiate($attributes);
     // Check options
     if (isset($attributes['CREATE_OPTIONS'])) {
         $options = strtolower($attributes['CREATE_OPTIONS']);
     } else {
         $options = null;
     }
     if (strpos($options, 'checksum=1') !== false) {
         $res->optionChecksum = $res->originalOptionChecksum = '1';
     }
     if (strpos($options, 'delay_key_write=1') !== false) {
         $res->optionDelayKeyWrite = $res->originalOptionDelayKeyWrite = '1';
     }
     if (strpos($options, 'pack_keys=1') !== false) {
         $res->optionPackKeys = $res->originalOptionPackKeys = '1';
     } elseif (strpos($options, 'pack_keys=0') !== false) {
         $res->optionPackKeys = $res->originalOptionPackKeys = '0';
     }
     // Comment
     if (isset($attributes['TABLE_COMMENT'])) {
         if (isset($attributes['ENGINE']) && $attributes['ENGINE'] == 'InnoDB') {
             $search = 'InnoDB free: \\d+ ..?$';
             if (preg_match('/^' . $search . '/', $attributes['TABLE_COMMENT'])) {
                 $res->comment = '';
             } elseif (preg_match('/; ' . $search . '/', $attributes['TABLE_COMMENT'], $result)) {
                 $res->comment = str_replace($result[0], '', $attributes['TABLE_COMMENT']);
             } else {
                 $res->comment = $attributes['TABLE_COMMENT'];
             }
         } else {
             $res->comment = $attributes['TABLE_COMMENT'];
         }
     }
     $res->originalAttributes['comment'] = $res->comment;
     return $res;
 }