diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-11-22 12:12:22 +0100 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-11-22 12:12:22 +0100 |
commit | 7ade8b7944d10f4fd1583789309cf003a3eac6f7 (patch) | |
tree | b5b305d5d8ffb781682914a40f19ae8aa9dac477 /system | |
parent | 2eaeee5aa3971932e58ffac48554e554d799249f (diff) |
Fix modify_column() issues (#2020)
Diffstat (limited to 'system')
-rw-r--r-- | system/database/DB_forge.php | 2 | ||||
-rw-r--r-- | system/database/drivers/cubrid/cubrid_forge.php | 10 | ||||
-rw-r--r-- | system/database/drivers/ibase/ibase_forge.php | 11 | ||||
-rw-r--r-- | system/database/drivers/mysql/mysql_forge.php | 2 | ||||
-rw-r--r-- | system/database/drivers/mysqli/mysqli_forge.php | 2 | ||||
-rw-r--r-- | system/database/drivers/oci8/oci8_forge.php | 2 | ||||
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php | 10 | ||||
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php | 11 | ||||
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php | 2 | ||||
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_oci_forge.php | 2 | ||||
-rw-r--r-- | system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php | 13 | ||||
-rw-r--r-- | system/database/drivers/postgre/postgre_forge.php | 13 |
12 files changed, 38 insertions, 42 deletions
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 06e47a6b4..bb1ee4809 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -642,7 +642,7 @@ abstract class CI_DB_forge { show_error('Field information is required.'); } - $sqls = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); + $sqls = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->_process_fields()); $this->_reset(); if ($sqls === FALSE) { diff --git a/system/database/drivers/cubrid/cubrid_forge.php b/system/database/drivers/cubrid/cubrid_forge.php index 05762ba5a..9a7cdb805 100644 --- a/system/database/drivers/cubrid/cubrid_forge.php +++ b/system/database/drivers/cubrid/cubrid_forge.php @@ -108,12 +108,8 @@ class CI_DB_cubrid_forge extends CI_DB_forge { } else { - $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]); - if ( ! empty($field[$i]['new_name'])) - { - $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) - .' AS '.$this->db->escape_identifiers($field[$i]['name']); - } + $alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE '; + $sqls[] = $sql.$alter_type$this->_process_column($field[$i]); } } @@ -139,7 +135,7 @@ class CI_DB_cubrid_forge extends CI_DB_forge { } return $this->db->escape_identifiers($field['name']) - .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name'])) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) .' '.$field['type'].$field['length'] .$field['unsigned'] .$field['null'] diff --git a/system/database/drivers/ibase/ibase_forge.php b/system/database/drivers/ibase/ibase_forge.php index a0c4e6563..39c782816 100644 --- a/system/database/drivers/ibase/ibase_forge.php +++ b/system/database/drivers/ibase/ibase_forge.php @@ -137,7 +137,7 @@ class CI_DB_ibase_forge extends CI_DB_forge { $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); $sqls = array(); - for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++) + for ($i = 0, $c = count($field); $i < $c; $i++) { if ($field[$i]['_literal'] !== FALSE) { @@ -146,13 +146,14 @@ class CI_DB_ibase_forge extends CI_DB_forge { if (isset($field[$i]['type'])) { - $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length']; + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identififers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; } if ( ! empty($field[$i]['default'])) { - $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name']) - .' SET '.$field[$i]['default']; + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET DEFAULT '.$field[$i]['default']; } if (isset($field[$i]['null'])) @@ -165,7 +166,7 @@ class CI_DB_ibase_forge extends CI_DB_forge { if ( ! empty($field[$i]['new_name'])) { - $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name']) + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); } } diff --git a/system/database/drivers/mysql/mysql_forge.php b/system/database/drivers/mysql/mysql_forge.php index 6c5dfc665..1e9145e4f 100644 --- a/system/database/drivers/mysql/mysql_forge.php +++ b/system/database/drivers/mysql/mysql_forge.php @@ -157,7 +157,7 @@ class CI_DB_mysql_forge extends CI_DB_forge { } return $this->db->escape_identifiers($field['name']) - .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name'])) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) .' '.$field['type'].$field['length'] .$field['unsigned'] .$field['null'] diff --git a/system/database/drivers/mysqli/mysqli_forge.php b/system/database/drivers/mysqli/mysqli_forge.php index a70eef88f..1a6e284ee 100644 --- a/system/database/drivers/mysqli/mysqli_forge.php +++ b/system/database/drivers/mysqli/mysqli_forge.php @@ -157,7 +157,7 @@ class CI_DB_mysqli_forge extends CI_DB_forge { } return $this->db->escape_identifiers($field['name']) - .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name'])) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) .' '.$field['type'].$field['length'] .$field['unsigned'] .$field['null'] diff --git a/system/database/drivers/oci8/oci8_forge.php b/system/database/drivers/oci8/oci8_forge.php index bd9d2df3c..a0efa95ea 100644 --- a/system/database/drivers/oci8/oci8_forge.php +++ b/system/database/drivers/oci8/oci8_forge.php @@ -105,7 +105,7 @@ class CI_DB_oci8_forge extends CI_DB_forge { $sql .= ' '.$alter_type.' '; $sql .= (count($field) === 1) - ? $fields[0] + ? $field[0] : '('.implode(',', $field).')'; // RENAME COLUMN must be executed after MODIFY diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php index e8421ec41..cb7d9e697 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_forge.php @@ -108,12 +108,8 @@ class CI_DB_pdo_cubrid_forge extends CI_DB_pdo_forge { } else { - $sqls[] = $sql.' CHANGE '.$this->_process_column($field[$i]); - if ( ! empty($field[$i]['new_name'])) - { - $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) - .' AS '.$this->db->escape_identifiers($field[$i]['name']); - } + $alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE '; + $sqls[] = $sql.$alter_type.$this->_process_column($field[$i]); } } @@ -139,7 +135,7 @@ class CI_DB_pdo_cubrid_forge extends CI_DB_pdo_forge { } return $this->db->escape_identifiers($field['name']) - .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name'])) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) .' '.$field['type'].$field['length'] .$field['unsigned'] .$field['null'] diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php index 474188f4e..7b86de97f 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_forge.php @@ -123,7 +123,7 @@ class CI_DB_pdo_firebird_forge extends CI_DB_pdo_forge { $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); $sqls = array(); - for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++) + for ($i = 0, $c = count($field); $i < $c; $i++) { if ($field[$i]['_literal'] !== FALSE) { @@ -132,13 +132,14 @@ class CI_DB_pdo_firebird_forge extends CI_DB_pdo_forge { if (isset($field[$i]['type'])) { - $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length']; + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; } if ( ! empty($field[$i]['default'])) { - $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name']) - .' SET '.$field[$i]['default']; + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET DEFAULT '.$field[$i]['default']; } if (isset($field[$i]['null'])) @@ -151,7 +152,7 @@ class CI_DB_pdo_firebird_forge extends CI_DB_pdo_forge { if ( ! empty($field[$i]['new_name'])) { - $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name']) + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); } } diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php index 866b6fb21..85d9445d3 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_forge.php @@ -171,7 +171,7 @@ class CI_DB_pdo_mysql_forge extends CI_DB_pdo_forge { } return $this->db->escape_identifiers($field['name']) - .(empty($field['new_name']) ? '' : $this->db->escape_identifiers($field['new_name'])) + .(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name'])) .' '.$field['type'].$field['length'] .$field['unsigned'] .$field['null'] diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php index 8052d218f..6d51a14b1 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_forge.php @@ -105,7 +105,7 @@ class CI_DB_pdo_oci_forge extends CI_DB_pdo_forge { $sql .= ' '.$alter_type.' '; $sql .= (count($field) === 1) - ? $fields[0] + ? $field[0] : '('.implode(',', $field).')'; // RENAME COLUMN must be executed after MODIFY diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php index 484c1603d..a24c898af 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_forge.php @@ -103,7 +103,7 @@ class CI_DB_pdo_pgsql_forge extends CI_DB_pdo_forge { $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); $sqls = array(); - for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++) + for ($i = 0, $c = count($field); $i < $c; $i++) { if ($field[$i]['_literal'] !== FALSE) { @@ -112,24 +112,25 @@ class CI_DB_pdo_pgsql_forge extends CI_DB_pdo_forge { if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) { - $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length']; + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; } if ( ! empty($field[$i]['default'])) { - $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name']) - .' SET '.$field[$i]['default']; + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET DEFAULT '.$field[$i]['default']; } if (isset($field[$i]['null'])) { - $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name']) + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) .($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL'); } if ( ! empty($field[$i]['new_name'])) { - $sqls[] = $sql.' RENAME '.$this->db->escape_identifiers($field[$i]['name']) + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); } } diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index 425622fac..5e378385c 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -96,7 +96,7 @@ class CI_DB_postgre_forge extends CI_DB_forge { $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table); $sqls = array(); - for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++) + for ($i = 0, $c = count($field); $i < $c; $i++) { if ($field[$i]['_literal'] !== FALSE) { @@ -105,24 +105,25 @@ class CI_DB_postgre_forge extends CI_DB_forge { if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type'])) { - $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length']; + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' TYPE '.$field[$i]['type'].$field[$i]['length']; } if ( ! empty($field[$i]['default'])) { - $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name']) - .' SET '.$field[$i]['default']; + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) + .' SET DEFAULT '.$field[$i]['default']; } if (isset($field[$i]['null'])) { - $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name']) + $sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name']) .($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL'); } if ( ! empty($field[$i]['new_name'])) { - $sqls[] = $sql.' RENAME '.$this->db->escape_identifiers($field[$i]['name']) + $sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name']) .' TO '.$this->db->escape_identifiers($field[$i]['new_name']); } } |