Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * Oracle Forge Class |
| 32 | * |
| 33 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame^] | 34 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 35 | * @link http://codeigniter.com/user_guide/database/ |
| 36 | */ |
| 37 | class CI_DB_oci8_forge extends CI_DB_forge { |
| 38 | |
| 39 | /** |
| 40 | * Create database |
| 41 | * |
| 42 | * @access public |
| 43 | * @param string the database name |
| 44 | * @return bool |
| 45 | */ |
| 46 | function _create_database($name) |
| 47 | { |
| 48 | return FALSE; |
| 49 | } |
| 50 | |
| 51 | // -------------------------------------------------------------------- |
| 52 | |
| 53 | /** |
| 54 | * Drop database |
| 55 | * |
| 56 | * @access private |
| 57 | * @param string the database name |
| 58 | * @return bool |
| 59 | */ |
| 60 | function _drop_database($name) |
| 61 | { |
| 62 | return FALSE; |
| 63 | } |
| 64 | |
| 65 | // -------------------------------------------------------------------- |
| 66 | |
| 67 | /** |
| 68 | * Create Table |
| 69 | * |
| 70 | * @access private |
| 71 | * @param string the table name |
| 72 | * @param array the fields |
| 73 | * @param mixed primary key(s) |
| 74 | * @param mixed key(s) |
| 75 | * @param boolean should 'IF NOT EXISTS' be added to the SQL |
| 76 | * @return bool |
| 77 | */ |
| 78 | function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) |
| 79 | { |
| 80 | $sql = 'CREATE TABLE '; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 81 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 82 | if ($if_not_exists === TRUE) |
| 83 | { |
| 84 | $sql .= 'IF NOT EXISTS '; |
| 85 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 86 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | $sql .= $this->db->_escape_identifiers($table)." ("; |
| 88 | $current_field_count = 0; |
| 89 | |
| 90 | foreach ($fields as $field=>$attributes) |
| 91 | { |
| 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)) |
| 96 | { |
| 97 | $sql .= "\n\t$attributes"; |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | $attributes = array_change_key_case($attributes, CASE_UPPER); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 102 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 103 | $sql .= "\n\t".$this->db->_protect_identifiers($field); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 104 | |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 105 | $sql .= ' '.$attributes['TYPE']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 106 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | if (array_key_exists('CONSTRAINT', $attributes)) |
| 108 | { |
| 109 | $sql .= '('.$attributes['CONSTRAINT'].')'; |
| 110 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 111 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 112 | if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE) |
| 113 | { |
| 114 | $sql .= ' UNSIGNED'; |
| 115 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 116 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 117 | if (array_key_exists('DEFAULT', $attributes)) |
| 118 | { |
| 119 | $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\''; |
| 120 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 121 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 122 | if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE) |
| 123 | { |
| 124 | $sql .= ' NULL'; |
| 125 | } |
| 126 | else |
| 127 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 128 | $sql .= ' NOT NULL'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 130 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 131 | if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE) |
| 132 | { |
| 133 | $sql .= ' AUTO_INCREMENT'; |
| 134 | } |
| 135 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 136 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 137 | // don't add a comma on the end of the last field |
| 138 | if (++$current_field_count < count($fields)) |
| 139 | { |
| 140 | $sql .= ','; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | if (count($primary_keys) > 0) |
| 145 | { |
| 146 | $primary_keys = $this->db->_protect_identifiers($primary_keys); |
| 147 | $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")"; |
| 148 | } |
| 149 | |
| 150 | if (is_array($keys) && count($keys) > 0) |
| 151 | { |
| 152 | foreach ($keys as $key) |
| 153 | { |
| 154 | if (is_array($key)) |
| 155 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 156 | $key = $this->db->_protect_identifiers($key); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 157 | } |
| 158 | else |
| 159 | { |
| 160 | $key = array($this->db->_protect_identifiers($key)); |
| 161 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 162 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 163 | $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $key) . ")"; |
| 164 | } |
| 165 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 166 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 167 | $sql .= "\n)"; |
| 168 | |
| 169 | return $sql; |
| 170 | } |
| 171 | |
| 172 | // -------------------------------------------------------------------- |
| 173 | |
| 174 | /** |
| 175 | * Drop Table |
| 176 | * |
| 177 | * @access private |
| 178 | * @return bool |
| 179 | */ |
| 180 | function _drop_table($table) |
| 181 | { |
| 182 | return FALSE; |
| 183 | } |
| 184 | |
| 185 | // -------------------------------------------------------------------- |
| 186 | |
| 187 | /** |
| 188 | * Alter table query |
| 189 | * |
| 190 | * Generates a platform-specific query so that a table can be altered |
| 191 | * Called by add_column(), drop_column(), and column_alter(), |
| 192 | * |
| 193 | * @access private |
| 194 | * @param string the ALTER type (ADD, DROP, CHANGE) |
| 195 | * @param string the column name |
| 196 | * @param string the table name |
| 197 | * @param string the column definition |
| 198 | * @param string the default value |
| 199 | * @param boolean should 'NOT NULL' be added |
| 200 | * @param string the field after which we should add the new field |
| 201 | * @return object |
| 202 | */ |
| 203 | function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') |
| 204 | { |
| 205 | $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name); |
| 206 | |
| 207 | // DROP has everything it needs now. |
| 208 | if ($alter_type == 'DROP') |
| 209 | { |
| 210 | return $sql; |
| 211 | } |
| 212 | |
| 213 | $sql .= " $column_definition"; |
| 214 | |
| 215 | if ($default_value != '') |
| 216 | { |
| 217 | $sql .= " DEFAULT \"$default_value\""; |
| 218 | } |
| 219 | |
| 220 | if ($null === NULL) |
| 221 | { |
| 222 | $sql .= ' NULL'; |
| 223 | } |
| 224 | else |
| 225 | { |
| 226 | $sql .= ' NOT NULL'; |
| 227 | } |
| 228 | |
| 229 | if ($after_field != '') |
| 230 | { |
| 231 | $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field); |
| 232 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 233 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 234 | return $sql; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 235 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | // -------------------------------------------------------------------- |
| 239 | |
| 240 | /** |
| 241 | * Rename a table |
| 242 | * |
| 243 | * Generates a platform-specific query so that a table can be renamed |
| 244 | * |
| 245 | * @access private |
| 246 | * @param string the old table name |
| 247 | * @param string the new table name |
| 248 | * @return string |
| 249 | */ |
| 250 | function _rename_table($table_name, $new_table_name) |
| 251 | { |
| 252 | $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name); |
| 253 | return $sql; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | } |
| 258 | |
| 259 | /* End of file oci8_forge.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 260 | /* Location: ./system/database/drivers/oci8/oci8_forge.php */ |