]>
jfr.im git - z_archive/KronOS.git/blob - system/database/drivers/mysqli/mysqli_forge.php
26054945789df4a2054dc115d8ac7a8687440771
1 <?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 5.1.6 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
22 * @author ExpressionEngine Dev Team
23 * @link http://codeigniter.com/user_guide/database/
25 class CI_DB_mysqli_forge
extends CI_DB_forge
{
31 * @param string the database name
34 function _create_database($name)
36 return "CREATE DATABASE ".$name;
39 // --------------------------------------------------------------------
45 * @param string the database name
48 function _drop_database($name)
50 return "DROP DATABASE ".$name;
53 // --------------------------------------------------------------------
59 * @param mixed the fields
62 function _process_fields($fields)
64 $current_field_count = 0;
67 foreach ($fields as $field=>$attributes)
69 // Numeric field names aren't allowed in databases, so if the key is
70 // numeric, we know it was assigned by PHP and the developer manually
71 // entered the field information, so we'll simply add it to the list
72 if (is_numeric($field))
74 $sql .= "\n\t$attributes";
78 $attributes = array_change_key_case($attributes, CASE_UPPER);
80 $sql .= "\n\t
".$this->db->_protect_identifiers($field);
82 if (array_key_exists('NAME', $attributes))
84 $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
87 if (array_key_exists('TYPE', $attributes))
89 $sql .= ' '.$attributes['TYPE'];
92 if (array_key_exists('CONSTRAINT', $attributes))
94 $sql .= '('.$attributes['CONSTRAINT'].')';
97 if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
102 if (array_key_exists('DEFAULT', $attributes))
104 $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
107 if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
116 if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
118 $sql .= ' AUTO_INCREMENT';
122 // don't add a comma on the end of the last field
123 if (++$current_field_count < count($fields))
132 // --------------------------------------------------------------------
138 * @param string the table name
139 * @param mixed the fields
140 * @param mixed primary key(s)
141 * @param mixed key(s)
142 * @param boolean should 'IF NOT EXISTS' be added to the SQL
145 function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
147 $sql = 'CREATE TABLE ';
149 if ($if_not_exists === TRUE)
151 $sql .= 'IF NOT EXISTS ';
154 $sql .= $this->db->_escape_identifiers($table)." (";
156 $sql .= $this->_process_fields($fields);
158 if (count($primary_keys) > 0)
160 $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
161 $primary_keys = $this->db->_protect_identifiers($primary_keys);
162 $sql .= ",\n\tPRIMARY KEY
".$key_name." (" . implode(', ', $primary_keys) . ")";
165 if (is_array($keys) && count($keys) > 0)
167 foreach ($keys as $key)
171 $key_name = $this->db->_protect_identifiers(implode('_', $key));
172 $key = $this->db->_protect_identifiers($key);
176 $key_name = $this->db->_protect_identifiers($key);
177 $key = array($key_name);
180 $sql .= ",\n\tKEY {$key_name
} (" . implode(', ', $key) . ")";
184 $sql .= "\n
) DEFAULT CHARACTER SET {$this
->db
->char_set
} COLLATE {$this
->db
->dbcollat
};";
189 // --------------------------------------------------------------------
197 function _drop_table($table)
199 return "DROP TABLE
IF EXISTS
".$this->db->_escape_identifiers($table);
202 // --------------------------------------------------------------------
207 * Generates a platform-specific query so that a table can be altered
208 * Called by add_column(), drop_column(), and column_alter(),
211 * @param string the ALTER type (ADD, DROP, CHANGE)
212 * @param string the column name
213 * @param array fields
214 * @param string the field after which we should add the new field
217 function _alter_table($alter_type, $table, $fields, $after_field = '')
219 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
221 // DROP has everything it needs now.
222 if ($alter_type == 'DROP')
224 return $sql.$this->db->_protect_identifiers($fields);
227 $sql .= $this->_process_fields($fields);
229 if ($after_field != '')
231 $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
237 // --------------------------------------------------------------------
242 * Generates a platform-specific query so that a table can be renamed
245 * @param string the old table name
246 * @param string the new table name
249 function _rename_table($table_name, $new_table_name)
251 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO
".$this->db->_protect_identifiers($new_table_name);
257 /* End of file mysqli_forge.php */
258 /* Location: ./system/database/drivers/mysqli/mysqli_forge.php */