-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
-/**\r
- * Code Igniter\r
- *\r
- * An open source application development framework for PHP 4.3.2 or newer\r
- *\r
- * @package CodeIgniter\r
- * @author ExpressionEngine Dev Team\r
- * @copyright Copyright (c) 2008, EllisLab, Inc.\r
- * @license http://codeigniter.com/user_guide/license.html\r
- * @link http://codeigniter.com\r
- * @since Version 1.0\r
- * @filesource\r
- */\r
-\r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * Database Utility Class\r
- *\r
- * @category Database\r
- * @author ExpressionEngine Dev Team\r
- * @link http://codeigniter.com/user_guide/database/\r
- */\r
-class CI_DB_forge {\r
-\r
- var $fields = array();\r
- var $keys = array();\r
- var $primary_keys = array();\r
- var $db_char_set = '';\r
-\r
- /**\r
- * Constructor\r
- *\r
- * Grabs the CI super object instance so we can access it.\r
- *\r
- */ \r
- function CI_DB_forge()\r
- {\r
- // Assign the main database object to $this->db\r
- $CI =& get_instance();\r
- $this->db =& $CI->db;\r
- log_message('debug', "Database Forge Class Initialized");\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Create database\r
- *\r
- * @access public\r
- * @param string the database name\r
- * @return bool\r
- */\r
- function create_database($db_name)\r
- {\r
- $sql = $this->_create_database($db_name);\r
- \r
- if (is_bool($sql))\r
- {\r
- return $sql;\r
- }\r
- \r
- return $this->db->query($sql);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Drop database\r
- *\r
- * @access public\r
- * @param string the database name\r
- * @return bool\r
- */\r
- function drop_database($db_name)\r
- {\r
- $sql = $this->_drop_database($db_name);\r
- \r
- if (is_bool($sql))\r
- {\r
- return $sql;\r
- }\r
- \r
- return $this->db->query($sql);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Add Key\r
- *\r
- * @access public\r
- * @param string key\r
- * @param string type\r
- * @return void\r
- */\r
- function add_key($key = '', $primary = FALSE)\r
- {\r
- if (is_array($key))\r
- {\r
- foreach($key as $one)\r
- {\r
- $this->add_key($one, $primary);\r
- }\r
- \r
- return;\r
- }\r
- \r
- if ($key == '')\r
- {\r
- show_error('Key information is required for that operation.');\r
- }\r
- \r
- if ($primary === TRUE)\r
- {\r
- $this->primary_keys[] = $key;\r
- }\r
- else\r
- {\r
- $this->keys[] = $key;\r
- }\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Add Field\r
- *\r
- * @access public\r
- * @param string collation\r
- * @return void\r
- */\r
- function add_field($field = '')\r
- {\r
- if ($field == '')\r
- {\r
- show_error('Field information is required.');\r
- }\r
- \r
- if (is_string($field))\r
- {\r
- if ($field == 'id')\r
- {\r
- $this->add_field(array(\r
- 'id' => array(\r
- 'type' => 'INT',\r
- 'constraint' => 9,\r
- 'auto_increment' => TRUE\r
- )\r
- ));\r
- $this->add_key('id', TRUE);\r
- }\r
- else\r
- {\r
- if (strpos($field, ' ') === FALSE)\r
- {\r
- show_error('Field information is required for that operation.');\r
- }\r
- \r
- $this->fields[] = $field;\r
- }\r
- }\r
- \r
- if (is_array($field))\r
- {\r
- $this->fields = array_merge($this->fields, $field);\r
- }\r
- \r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Create Table\r
- *\r
- * @access public\r
- * @param string the table name\r
- * @return bool\r
- */\r
- function create_table($table = '', $if_not_exists = FALSE)\r
- { \r
- if ($table == '')\r
- {\r
- show_error('A table name is required for that operation.');\r
- }\r
- \r
- if (count($this->fields) == 0)\r
- { \r
- show_error('Field information is required.');\r
- }\r
-\r
- $sql = $this->_create_table($this->db->dbprefix.$table, $this->fields, $this->primary_keys, $this->keys, $if_not_exists);\r
- \r
- $this->_reset();\r
- return $this->db->query($sql);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Drop Table\r
- *\r
- * @access public\r
- * @param string the table name\r
- * @return bool\r
- */\r
- function drop_table($table_name)\r
- {\r
- $sql = $this->_drop_table($this->db->dbprefix.$table_name);\r
- \r
- if (is_bool($sql))\r
- {\r
- return $sql;\r
- }\r
- \r
- return $this->db->query($sql);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Rename Table\r
- *\r
- * @access public\r
- * @param string the old table name\r
- * @param string the new table name\r
- * @return bool\r
- */\r
- function rename_table($table_name, $new_table_name)\r
- {\r
- if ($table_name == '' OR $new_table_name == '')\r
- {\r
- show_error('A table name is required for that operation.');\r
- }\r
- \r
- $sql = $this->_rename_table($table_name, $new_table_name);\r
- return $this->db->query($sql);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Column Add\r
- *\r
- * @access public\r
- * @param string the table name\r
- * @param string the column name\r
- * @param string the column definition\r
- * @return bool\r
- */\r
- function add_column($table = '', $field = array(), $after_field = '')\r
- {\r
- if ($table == '')\r
- {\r
- show_error('A table name is required for that operation.');\r
- }\r
-\r
- // add field info into field array, but we can only do one at a time\r
- // so only grab the first field in the event there are more then one\r
- $this->add_field(array_slice($field, 0, 1));\r
-\r
- if (count($this->fields) == 0)\r
- { \r
- show_error('Field information is required.');\r
- }\r
-\r
- $sql = $this->_alter_table('ADD', $this->db->dbprefix.$table, $this->fields, $after_field);\r
-\r
- $this->_reset();\r
- return $this->db->query($sql);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Column Drop\r
- *\r
- * @access public\r
- * @param string the table name\r
- * @param string the column name\r
- * @return bool\r
- */\r
- function drop_column($table = '', $column_name = '')\r
- {\r
- \r
- if ($table == '')\r
- {\r
- show_error('A table name is required for that operation.');\r
- }\r
-\r
- if ($column_name == '')\r
- {\r
- show_error('A column name is required for that operation.');\r
- }\r
-\r
- $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);\r
- \r
- return $this->db->query($sql);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Column Modify\r
- *\r
- * @access public\r
- * @param string the table name\r
- * @param string the column name\r
- * @param string the column definition\r
- * @return bool\r
- */\r
- function modify_column($table = '', $field = array())\r
- {\r
- if ($table == '')\r
- {\r
- show_error('A table name is required for that operation.');\r
- }\r
-\r
- // add field info into field array, but we can only do one at a time\r
- // so only grab the first field in the event there are more then one\r
- $this->add_field(array_slice($field, 0, 1));\r
-\r
- if (count($this->fields) == 0)\r
- { \r
- show_error('Field information is required.');\r
- }\r
-\r
- $sql = $this->_alter_table('CHANGE', $this->db->dbprefix.$table, $this->fields);\r
-\r
- $this->_reset();\r
- return $this->db->query($sql);\r
- }\r
-\r
- // --------------------------------------------------------------------\r
-\r
- /**\r
- * Reset\r
- *\r
- * Resets table creation vars\r
- *\r
- * @access private\r
- * @return void\r
- */\r
- function _reset()\r
- {\r
- $this->fields = array();\r
- $this->keys = array();\r
- $this->primary_keys = array();\r
- }\r
-\r
-}\r
-\r
-/* End of file DB_forge.php */\r
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * Code Igniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Database Utility Class
+ *
+ * @category Database
+ * @author ExpressionEngine Dev Team
+ * @link http://codeigniter.com/user_guide/database/
+ */
+class CI_DB_forge {
+
+ var $fields = array();
+ var $keys = array();
+ var $primary_keys = array();
+ var $db_char_set = '';
+
+ /**
+ * Constructor
+ *
+ * Grabs the CI super object instance so we can access it.
+ *
+ */
+ function CI_DB_forge()
+ {
+ // Assign the main database object to $this->db
+ $CI =& get_instance();
+ $this->db =& $CI->db;
+ log_message('debug', "Database Forge Class Initialized");
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Create database
+ *
+ * @access public
+ * @param string the database name
+ * @return bool
+ */
+ function create_database($db_name)
+ {
+ $sql = $this->_create_database($db_name);
+
+ if (is_bool($sql))
+ {
+ return $sql;
+ }
+
+ return $this->db->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop database
+ *
+ * @access public
+ * @param string the database name
+ * @return bool
+ */
+ function drop_database($db_name)
+ {
+ $sql = $this->_drop_database($db_name);
+
+ if (is_bool($sql))
+ {
+ return $sql;
+ }
+
+ return $this->db->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Add Key
+ *
+ * @access public
+ * @param string key
+ * @param string type
+ * @return void
+ */
+ function add_key($key = '', $primary = FALSE)
+ {
+ if (is_array($key))
+ {
+ foreach($key as $one)
+ {
+ $this->add_key($one, $primary);
+ }
+
+ return;
+ }
+
+ if ($key == '')
+ {
+ show_error('Key information is required for that operation.');
+ }
+
+ if ($primary === TRUE)
+ {
+ $this->primary_keys[] = $key;
+ }
+ else
+ {
+ $this->keys[] = $key;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Add Field
+ *
+ * @access public
+ * @param string collation
+ * @return void
+ */
+ function add_field($field = '')
+ {
+ if ($field == '')
+ {
+ show_error('Field information is required.');
+ }
+
+ if (is_string($field))
+ {
+ if ($field == 'id')
+ {
+ $this->add_field(array(
+ 'id' => array(
+ 'type' => 'INT',
+ 'constraint' => 9,
+ 'auto_increment' => TRUE
+ )
+ ));
+ $this->add_key('id', TRUE);
+ }
+ else
+ {
+ if (strpos($field, ' ') === FALSE)
+ {
+ show_error('Field information is required for that operation.');
+ }
+
+ $this->fields[] = $field;
+ }
+ }
+
+ if (is_array($field))
+ {
+ $this->fields = array_merge($this->fields, $field);
+ }
+
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Create Table
+ *
+ * @access public
+ * @param string the table name
+ * @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);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Drop Table
+ *
+ * @access public
+ * @param string the table name
+ * @return bool
+ */
+ 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);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Rename Table
+ *
+ * @access public
+ * @param string the old table name
+ * @param string the new table name
+ * @return bool
+ */
+ function rename_table($table_name, $new_table_name)
+ {
+ if ($table_name == '' OR $new_table_name == '')
+ {
+ show_error('A table name is required for that operation.');
+ }
+
+ $sql = $this->_rename_table($table_name, $new_table_name);
+ return $this->db->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Column Add
+ *
+ * @access public
+ * @param string the table name
+ * @param string the column name
+ * @param string the column definition
+ * @return bool
+ */
+ function add_column($table = '', $field = array(), $after_field = '')
+ {
+ if ($table == '')
+ {
+ show_error('A table name is required for that operation.');
+ }
+
+ // add field info into field array, but we can only do one at a time
+ // so we cycle through
+
+ foreach ($field as $k => $v)
+ {
+ $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;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Column Drop
+ *
+ * @access public
+ * @param string the table name
+ * @param string the column name
+ * @return bool
+ */
+ function drop_column($table = '', $column_name = '')
+ {
+
+ if ($table == '')
+ {
+ show_error('A table name is required for that operation.');
+ }
+
+ if ($column_name == '')
+ {
+ show_error('A column name is required for that operation.');
+ }
+
+ $sql = $this->_alter_table('DROP', $this->db->dbprefix.$table, $column_name);
+
+ return $this->db->query($sql);
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Column Modify
+ *
+ * @access public
+ * @param string the table name
+ * @param string the column name
+ * @param string the column definition
+ * @return bool
+ */
+ function modify_column($table = '', $field = array())
+ {
+ if ($table == '')
+ {
+ show_error('A table name is required for that operation.');
+ }
+
+ // add field info into field array, but we can only do one at a time
+ // so we cycle through
+
+ foreach ($field as $k => $v)
+ {
+ $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;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
+ * Reset
+ *
+ * Resets table creation vars
+ *
+ * @access private
+ * @return void
+ */
+ function _reset()
+ {
+ $this->fields = array();
+ $this->keys = array();
+ $this->primary_keys = array();
+ }
+
+}
+
+/* End of file DB_forge.php */
/* Location: ./system/database/DB_forge.php */
\ No newline at end of file