odbc_forge.php
Go to the documentation of this file.00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 class CI_DB_odbc_forge extends CI_DB_forge {
00026
00027
00028
00029
00030
00031
00032
00033
00034 function _create_database()
00035 {
00036
00037
00038 if ($this->db->db_debug)
00039 {
00040 return $this->db->display_error('db_unsuported_feature');
00041 }
00042 return FALSE;
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 function _drop_database($name)
00055 {
00056
00057
00058 if ($this->db->db_debug)
00059 {
00060 return $this->db->display_error('db_unsuported_feature');
00061 }
00062 return FALSE;
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
00079 {
00080 $sql = 'CREATE TABLE ';
00081
00082 if ($if_not_exists === TRUE)
00083 {
00084 $sql .= 'IF NOT EXISTS ';
00085 }
00086
00087 $sql .= $this->db->_escape_identifiers($table)." (";
00088 $current_field_count = 0;
00089
00090 foreach ($fields as $field=>$attributes)
00091 {
00092
00093
00094
00095 if (is_numeric($field))
00096 {
00097 $sql .= "\n\t$attributes";
00098 }
00099 else
00100 {
00101 $attributes = array_change_key_case($attributes, CASE_UPPER);
00102
00103 $sql .= "\n\t".$this->db->_protect_identifiers($field);
00104
00105 $sql .= ' '.$attributes['TYPE'];
00106
00107 if (array_key_exists('CONSTRAINT', $attributes))
00108 {
00109 $sql .= '('.$attributes['CONSTRAINT'].')';
00110 }
00111
00112 if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
00113 {
00114 $sql .= ' UNSIGNED';
00115 }
00116
00117 if (array_key_exists('DEFAULT', $attributes))
00118 {
00119 $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
00120 }
00121
00122 if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
00123 {
00124 $sql .= ' NULL';
00125 }
00126 else
00127 {
00128 $sql .= ' NOT NULL';
00129 }
00130
00131 if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
00132 {
00133 $sql .= ' AUTO_INCREMENT';
00134 }
00135 }
00136
00137
00138 if (++$current_field_count < count($fields))
00139 {
00140 $sql .= ',';
00141 }
00142 }
00143
00144 if (count($primary_keys) > 0)
00145 {
00146 $primary_keys = $this->db->_protect_identifiers($primary_keys);
00147 $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
00148 }
00149
00150 if (is_array($keys) && count($keys) > 0)
00151 {
00152 foreach ($keys as $key)
00153 {
00154 if (is_array($key))
00155 {
00156 $key = $this->db->_protect_identifiers($key);
00157 }
00158 else
00159 {
00160 $key = array($this->db->_protect_identifiers($key));
00161 }
00162
00163 $sql .= ",\n\tFOREIGN KEY (" . implode(', ', $key) . ")";
00164 }
00165 }
00166
00167 $sql .= "\n)";
00168
00169 return $sql;
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180 function _drop_table($table)
00181 {
00182
00183 if ($this->db->db_debug)
00184 {
00185 return $this->db->display_error('db_unsuported_feature');
00186 }
00187 return FALSE;
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
00209 {
00210 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
00211
00212
00213 if ($alter_type == 'DROP')
00214 {
00215 return $sql;
00216 }
00217
00218 $sql .= " $column_definition";
00219
00220 if ($default_value != '')
00221 {
00222 $sql .= " DEFAULT \"$default_value\"";
00223 }
00224
00225 if ($null === NULL)
00226 {
00227 $sql .= ' NULL';
00228 }
00229 else
00230 {
00231 $sql .= ' NOT NULL';
00232 }
00233
00234 if ($after_field != '')
00235 {
00236 $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
00237 }
00238
00239 return $sql;
00240
00241 }
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 function _rename_table($table_name, $new_table_name)
00257 {
00258 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
00259 return $sql;
00260 }
00261
00262
00263 }
00264
00265
00266