Exemplo n.º 1
0
 /**
  * Tests to get character set name from collation name.
  */
 public function testGetCharset()
 {
     // Get Charset for utf8_unicode_ci
     $this->assertEquals('utf8', Collation::getCharacterSet('utf8_unicode_ci'));
 }
Exemplo n.º 2
0
Arquivo: Table.php Projeto: cebe/chive
 /**
  * Returns the query string for all options which need to be saved.
  *
  * @return	string
  */
 private function getSaveDefinition()
 {
     $sql = '';
     $comma = '';
     if ($this->TABLE_NAME !== @$this->originalAttributes['TABLE_NAME'] && !$this->getIsNewRecord()) {
         //@todo(mburtscher): Privileges are not copied automatically!!!
         $sql .= "\n\t" . 'RENAME ' . self::$db->quoteTableName($this->TABLE_NAME);
         $comma = ',';
     }
     if ($this->TABLE_COLLATION !== @$this->originalAttributes['TABLE_COLLATION']) {
         $sql .= $comma . "\n\t" . 'CHARACTER SET ' . Collation::getCharacterSet($this->TABLE_COLLATION) . ' COLLATE ' . $this->TABLE_COLLATION;
         $comma = ',';
     }
     if ($this->comment !== @$this->originalAttributes['comment']) {
         $sql .= $comma . "\n\t" . 'COMMENT ' . self::$db->quoteValue($this->comment);
         $comma = ',';
     }
     if ($this->ENGINE !== @$this->originalAttributes['ENGINE']) {
         $sql .= $comma . "\n\t" . 'ENGINE ' . $this->ENGINE;
         $comma = ',';
     }
     if ($this->optionChecksum !== $this->originalOptionChecksum) {
         $sql .= $comma . "\n\t" . 'CHECKSUM ' . $this->optionChecksum;
         $comma = ',';
     }
     if ($this->optionPackKeys !== $this->originalOptionPackKeys) {
         $sql .= $comma . "\n\t" . 'PACK_KEYS ' . $this->optionPackKeys;
         $comma = ',';
     }
     if ($this->optionDelayKeyWrite !== $this->originalOptionDelayKeyWrite) {
         $sql .= $comma . "\n\t" . 'DELAY_KEY_WRITE ' . $this->optionDelayKeyWrite;
     }
     return $sql;
 }
Exemplo n.º 3
0
 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) : ''));
 }