1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
\r
5 * An open source application development framework for PHP 4.3.2 or newer
\r
7 * @package CodeIgniter
\r
8 * @author ExpressionEngine Dev Team
\r
9 * @copyright Copyright (c) 2008, EllisLab, Inc.
\r
10 * @license http://codeigniter.com/user_guide/license.html
\r
11 * @link http://codeigniter.com
\r
12 * @since Version 1.0
\r
16 // ------------------------------------------------------------------------
\r
21 * @category Database
\r
22 * @author ExpressionEngine Dev Team
\r
23 * @link http://codeigniter.com/database/
\r
25 class CI_DB_odbc_forge extends CI_DB_forge {
\r
31 * @param string the database name
\r
34 function _create_database()
\r
36 // ODBC has no "create database" command since it's
\r
37 // designed to connect to an existing database
\r
38 if ($this->db->db_debug)
\r
40 return $this->db->display_error('db_unsuported_feature');
\r
45 // --------------------------------------------------------------------
\r
51 * @param string the database name
\r
54 function _drop_database($name)
\r
56 // ODBC has no "drop database" command since it's
\r
57 // designed to connect to an existing database
\r
58 if ($this->db->db_debug)
\r
60 return $this->db->display_error('db_unsuported_feature');
\r
65 // --------------------------------------------------------------------
\r
71 * @param string the table name
\r
72 * @param array the fields
\r
73 * @param mixed primary key(s)
\r
74 * @param mixed key(s)
\r
75 * @param boolean should 'IF NOT EXISTS' be added to the SQL
\r
78 function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
\r
80 $sql = 'CREATE TABLE ';
\r
82 if ($if_not_exists === TRUE)
\r
84 $sql .= 'IF NOT EXISTS ';
\r
87 $sql .= $this->db->_escape_identifiers($table)." (";
\r
88 $current_field_count = 0;
\r
90 foreach ($fields as $field=>$attributes)
\r
92 // Numeric field names aren't allowed in databases, so if the key is
\r
93 // numeric, we know it was assigned by PHP and the developer manually
\r
94 // entered the field information, so we'll simply add it to the list
\r
95 if (is_numeric($field))
\r
97 $sql .= "\n\t$attributes";
\r
101 $attributes = array_change_key_case($attributes, CASE_UPPER);
\r
103 $sql .= "\n\t".$this->db->_protect_identifiers($field);
\r
105 $sql .= ' '.$attributes['TYPE'];
\r
107 if (array_key_exists('CONSTRAINT', $attributes))
\r
109 $sql .= '('.$attributes['CONSTRAINT'].')';
\r
112 if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
\r
114 $sql .= ' UNSIGNED';
\r
117 if (array_key_exists('DEFAULT', $attributes))
\r
119 $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
\r
122 if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
\r
128 $sql .= ' NOT NULL';
\r
131 if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
\r
133 $sql .= ' AUTO_INCREMENT';
\r
137 // don't add a comma on the end of the last field
\r
138 if (++$current_field_count < count($fields))
\r
144 if (count($primary_keys) > 0)
\r
146 $primary_keys = $this->db->_protect_identifiers($primary_keys);
\r
147 $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
\r
150 if (is_array($keys) && count($keys) > 0)
\r
152 foreach ($keys as $key)
\r
154 if (is_array($key))
\r
156 $key = $this->db->_protect_identifiers($key);
\r
160 $key = array($this->db->_protect_identifiers($key));
\r
163 $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
\r
172 // --------------------------------------------------------------------
\r
180 function _drop_table($table)
\r
182 // Not a supported ODBC feature
\r
183 if ($this->db->db_debug)
\r
185 return $this->db->display_error('db_unsuported_feature');
\r
190 // --------------------------------------------------------------------
\r
193 * Alter table query
\r
195 * Generates a platform-specific query so that a table can be altered
\r
196 * Called by add_column(), drop_column(), and column_alter(),
\r
199 * @param string the ALTER type (ADD, DROP, CHANGE)
\r
200 * @param string the column name
\r
201 * @param string the table name
\r
202 * @param string the column definition
\r
203 * @param string the default value
\r
204 * @param boolean should 'NOT NULL' be added
\r
205 * @param string the field after which we should add the new field
\r
208 function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
\r
210 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
\r
212 // DROP has everything it needs now.
\r
213 if ($alter_type == 'DROP')
\r
218 $sql .= " $column_definition";
\r
220 if ($default_value != '')
\r
222 $sql .= " DEFAULT \"$default_value\"";
\r
225 if ($null === NULL)
\r
231 $sql .= ' NOT NULL';
\r
234 if ($after_field != '')
\r
236 $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
\r
244 // --------------------------------------------------------------------
\r
249 * Generates a platform-specific query so that a table can be renamed
\r
252 * @param string the old table name
\r
253 * @param string the new table name
\r
256 function _rename_table($table_name, $new_table_name)
\r
258 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
\r
265 /* End of file odbc_forge.php */
\r
266 /* Location: ./system/database/drivers/odbc/odbc_forge.php */