]>
jfr.im git - z_archive/KronOS.git/blob - video/system/database/drivers/cubrid/cubrid_forge.php
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
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 Esen Sagynov
23 * @link http://codeigniter.com/user_guide/database/
25 class CI_DB_cubrid_forge
extends CI_DB_forge
{
31 * @param string the database name
34 function _create_database($name)
36 // CUBRID does not allow to create a database in SQL. The GUI tools
37 // have to be used for this purpose.
41 // --------------------------------------------------------------------
47 * @param string the database name
50 function _drop_database($name)
52 // CUBRID does not allow to drop a database in SQL. The GUI tools
53 // have to be used for this purpose.
57 // --------------------------------------------------------------------
63 * @param mixed the fields
66 function _process_fields($fields)
68 $current_field_count = 0;
71 foreach ($fields as $field=>$attributes)
73 // Numeric field names aren't allowed in databases, so if the key is
74 // numeric, we know it was assigned by PHP and the developer manually
75 // entered the field information, so we'll simply add it to the list
76 if (is_numeric($field))
78 $sql .= "\n\t$attributes";
82 $attributes = array_change_key_case($attributes, CASE_UPPER);
84 $sql .= "\n\t\"
" . $this->db->_protect_identifiers($field) . "\"
";
86 if (array_key_exists('NAME', $attributes))
88 $sql .= ' '.$this->db->_protect_identifiers($attributes['NAME']).' ';
91 if (array_key_exists('TYPE', $attributes))
93 $sql .= ' '.$attributes['TYPE'];
95 if (array_key_exists('CONSTRAINT', $attributes))
97 switch ($attributes['TYPE'])
102 $sql .= '('.implode(',', $attributes['CONSTRAINT']).')';
104 case 'enum': // As of version 8.4.0 CUBRID does not support
108 $sql .= '("'.implode('","', $attributes['CONSTRAINT
']).'")';
111 $sql .= '('.$attributes['CONSTRAINT'].')';
116 if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
118 //$sql .= ' UNSIGNED';
119 // As of version 8.4.0 CUBRID does not support UNSIGNED INTEGER data type.
120 // Will be supported in the next release as a part of MySQL Compatibility.
123 if (array_key_exists('DEFAULT', $attributes))
125 $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
128 if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
137 if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
139 $sql .= ' AUTO_INCREMENT';
142 if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE)
148 // don't add a comma on the end of the last field
149 if (++$current_field_count < count($fields))
158 // --------------------------------------------------------------------
164 * @param string the table name
165 * @param mixed the fields
166 * @param mixed primary key(s)
167 * @param mixed key(s)
168 * @param boolean should 'IF NOT EXISTS' be added to the SQL
171 function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
173 $sql = 'CREATE TABLE ';
175 if ($if_not_exists === TRUE)
177 //$sql .= 'IF NOT EXISTS ';
178 // As of version 8.4.0 CUBRID does not support this SQL syntax.
181 $sql .= $this->db->_escape_identifiers($table)." (";
183 $sql .= $this->_process_fields($fields);
185 // If there is a PK defined
186 if (count($primary_keys) > 0)
188 $key_name = "pk_
" . $table . "_
" .
189 $this->db->_protect_identifiers(implode('_', $primary_keys));
191 $primary_keys = $this->db->_protect_identifiers($primary_keys);
192 $sql .= ",\n\tCONSTRAINT
" . $key_name . " PRIMARY
KEY(" . implode(', ', $primary_keys) . ")";
195 if (is_array($keys) && count($keys) > 0)
197 foreach ($keys as $key)
201 $key_name = $this->db->_protect_identifiers(implode('_', $key));
202 $key = $this->db->_protect_identifiers($key);
206 $key_name = $this->db->_protect_identifiers($key);
207 $key = array($key_name);
210 $sql .= ",\n\tKEY \"{$key_name
}\" (" . implode(', ', $key) . ")";
219 // --------------------------------------------------------------------
227 function _drop_table($table)
229 return "DROP TABLE
IF EXISTS
".$this->db->_escape_identifiers($table);
232 // --------------------------------------------------------------------
237 * Generates a platform-specific query so that a table can be altered
238 * Called by add_column(), drop_column(), and column_alter(),
241 * @param string the ALTER type (ADD, DROP, CHANGE)
242 * @param string the column name
243 * @param array fields
244 * @param string the field after which we should add the new field
247 function _alter_table($alter_type, $table, $fields, $after_field = '')
249 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ";
251 // DROP has everything it needs now.
252 if ($alter_type == 'DROP')
254 return $sql.$this->db->_protect_identifiers($fields);
257 $sql .= $this->_process_fields($fields);
259 if ($after_field != '')
261 $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
267 // --------------------------------------------------------------------
272 * Generates a platform-specific query so that a table can be renamed
275 * @param string the old table name
276 * @param string the new table name
279 function _rename_table($table_name, $new_table_name)
281 $sql = 'RENAME TABLE '.$this->db->_protect_identifiers($table_name)." AS ".$this->db->_protect_identifiers($new_table_name);
287 /* End of file cubrid_forge.php */
288 /* Location: ./system/database/drivers/cubrid/cubrid_forge.php */