CI_DB_forge::_alter_table PHP Method

_alter_table() protected method

ALTER TABLE
protected _alter_table ( string $alter_type, string $table, mixed $field ) : string | string[]
$alter_type string ALTER type
$table string Table name
$field mixed Column definition
return string | string[]
    protected function _alter_table($alter_type, $table, $field)
    {
        $sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table) . ' ';
        // DROP has everything it needs now.
        if ($alter_type === 'DROP') {
            return $sql . 'DROP COLUMN ' . $this->db->escape_identifiers($field);
        }
        $sql .= $alter_type === 'ADD' ? 'ADD ' : $alter_type . ' COLUMN ';
        $sqls = array();
        for ($i = 0, $c = count($field); $i < $c; $i++) {
            $sqls[] = $sql . ($field[$i]['_literal'] !== FALSE ? $field[$i]['_literal'] : $this->_process_column($field[$i]));
        }
        return $sqls;
    }

Usage Example

コード例 #1
0
ファイル: oci8_forge.php プロジェクト: at15/codeignitordb
 /**
  * ALTER TABLE
  *
  * @param    string $alter_type ALTER type
  * @param    string $table Table name
  * @param    mixed $field Column definition
  * @return    string|string[]
  */
 protected function _alter_table($alter_type, $table, $field)
 {
     if ($alter_type === 'DROP') {
         return parent::_alter_table($alter_type, $table, $field);
     } elseif ($alter_type === 'CHANGE') {
         $alter_type = 'MODIFY';
     }
     $sql = 'ALTER TABLE ' . $this->db->escape_identifiers($table);
     $sqls = array();
     for ($i = 0, $c = count($field); $i < $c; $i++) {
         if ($field[$i]['_literal'] !== FALSE) {
             $field[$i] = "\n\t" . $field[$i]['_literal'];
         } else {
             $field[$i]['_literal'] = "\n\t" . $this->_process_column($field[$i]);
             if ($alter_type === 'MODIFY' && !empty($field[$i]['new_name'])) {
                 $sqls[] = $sql . ' RENAME COLUMN ' . $this->db->escape_identifiers($field[$i]['name']) . ' ' . $this->db->escape_identifiers($field[$i]['new_name']);
             }
         }
     }
     $sql .= ' ' . $alter_type . ' ';
     $sql .= count($field) === 1 ? $field[0] : '(' . implode(',', $field) . ')';
     // RENAME COLUMN must be executed after MODIFY
     array_unshift($sqls, $sql);
     return $sql;
 }
All Usage Examples Of CI_DB_forge::_alter_table