diff options
Diffstat (limited to 'system/database/DB_forge.php')
-rwxr-xr-x[-rw-r--r--] | system/database/DB_forge.php | 79 |
1 files changed, 43 insertions, 36 deletions
diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index c5931db27..27f2c372d 100644..100755 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -2,11 +2,11 @@ /** * Code Igniter * - * An open source application development framework for PHP 4.3.2 or newer + * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 @@ -24,9 +24,9 @@ */ class CI_DB_forge { - var $fields = array(); + var $fields = array(); var $keys = array(); - var $primary_keys = array(); + var $primary_keys = array(); var $db_char_set = ''; /** @@ -34,7 +34,7 @@ class CI_DB_forge { * * Grabs the CI super object instance so we can access it. * - */ + */ function CI_DB_forge() { // Assign the main database object to $this->db @@ -55,12 +55,12 @@ class CI_DB_forge { function create_database($db_name) { $sql = $this->_create_database($db_name); - + if (is_bool($sql)) { return $sql; } - + return $this->db->query($sql); } @@ -76,12 +76,12 @@ class CI_DB_forge { function drop_database($db_name) { $sql = $this->_drop_database($db_name); - + if (is_bool($sql)) { return $sql; } - + return $this->db->query($sql); } @@ -103,15 +103,15 @@ class CI_DB_forge { { $this->add_key($one, $primary); } - + return; } - + if ($key == '') { show_error('Key information is required for that operation.'); } - + if ($primary === TRUE) { $this->primary_keys[] = $key; @@ -137,7 +137,7 @@ class CI_DB_forge { { show_error('Field information is required.'); } - + if (is_string($field)) { if ($field == 'id') @@ -157,16 +157,16 @@ class CI_DB_forge { { show_error('Field information is required for that operation.'); } - + $this->fields[] = $field; } } - + if (is_array($field)) { $this->fields = array_merge($this->fields, $field); } - + } // -------------------------------------------------------------------- @@ -179,19 +179,19 @@ class CI_DB_forge { * @return bool */ function create_table($table = '', $if_not_exists = FALSE) - { + { if ($table == '') { show_error('A table name is required for that operation.'); } - + if (count($this->fields) == 0) - { + { show_error('Field information is required.'); } $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists); - + $this->_reset(); return $this->db->query($sql); } @@ -208,12 +208,12 @@ class CI_DB_forge { function drop_table($table_name) { $sql = $this->_drop_table($this->db->dbprefix.$table_name); - + if (is_bool($sql)) { return $sql; } - + return $this->db->query($sql); } @@ -233,7 +233,7 @@ class CI_DB_forge { { show_error('A table name is required for that operation.'); } - + $sql = $this->_rename_table($table_name, $new_table_name); return $this->db->query($sql); } @@ -261,24 +261,25 @@ class CI_DB_forge { foreach ($field as $k => $v) { - $this->add_field(array($k => $field[$k])); + $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) - { + { show_error('Field information is required.'); } - + $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field); $this->_reset(); - + if ($this->db->query($sql) === FALSE) { return FALSE; } } - + return TRUE; + } // -------------------------------------------------------------------- @@ -293,7 +294,7 @@ class CI_DB_forge { */ function drop_column($table = '', $column_name = '') { - + if ($table == '') { show_error('A table name is required for that operation.'); @@ -305,7 +306,7 @@ class CI_DB_forge { } $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name); - + return $this->db->query($sql); } @@ -332,23 +333,29 @@ class CI_DB_forge { foreach ($field as $k => $v) { + // If no name provided, use the current name + if ( ! isset($field[$k]['name'])) + { + $field[$k]['name'] = $k; + } + $this->add_field(array($k => $field[$k])); if (count($this->fields) == 0) - { + { show_error('Field information is required.'); } - + $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields); $this->_reset(); - + if ($this->db->query($sql) === FALSE) { return FALSE; } } - + return TRUE; } @@ -364,9 +371,9 @@ class CI_DB_forge { */ function _reset() { - $this->fields = array(); + $this->fields = array(); $this->keys = array(); - $this->primary_keys = array(); + $this->primary_keys = array(); } } |