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