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 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 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 |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 70 | * @param string the table name |
| 71 | * @param array the fields |
| 72 | * @param mixed primary key(s) |
| 73 | * @param mixed key(s) |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 74 | * @param bool should 'IF NOT EXISTS' be added to the SQL |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 75 | * @return bool |
| 76 | */ |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 77 | public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 78 | { |
| 79 | $sql = 'CREATE TABLE '; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 80 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 81 | if ($if_not_exists === TRUE) |
| 82 | { |
| 83 | $sql .= 'IF NOT EXISTS '; |
| 84 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 85 | |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 86 | $sql .= $this->db->_escape_identifiers($table).' ('; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | $current_field_count = 0; |
| 88 | |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 89 | foreach ($fields as $field => $attributes) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 90 | { |
| 91 | // Numeric field names aren't allowed in databases, so if the key is |
| 92 | // numeric, we know it was assigned by PHP and the developer manually |
| 93 | // entered the field information, so we'll simply add it to the list |
| 94 | if (is_numeric($field)) |
| 95 | { |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 96 | $sql .= "\n\t".$attributes; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 97 | } |
| 98 | else |
| 99 | { |
| 100 | $attributes = array_change_key_case($attributes, CASE_UPPER); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 101 | |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 102 | $sql .= "\n\t".$this->db->protect_identifiers($field).' '.$attributes['TYPE'] |
| 103 | .((isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') |
| 104 | .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '') |
| 105 | .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? '' : ' NOT NULL') |
| 106 | .(isset($attributes['CONSTRAINT']) ? ' CONSTRAINT '.$attributes['CONSTRAINT'] : ''); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 108 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | // don't add a comma on the end of the last field |
| 110 | if (++$current_field_count < count($fields)) |
| 111 | { |
| 112 | $sql .= ','; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | if (count($primary_keys) > 0) |
| 117 | { |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 118 | $primary_keys = $this->db->protect_identifiers($primary_keys); |
| 119 | $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $primary_keys).')'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | if (is_array($keys) && count($keys) > 0) |
| 123 | { |
| 124 | foreach ($keys as $key) |
| 125 | { |
| 126 | if (is_array($key)) |
| 127 | { |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 128 | $key = $this->db->protect_identifiers($key); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 129 | } |
| 130 | else |
| 131 | { |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 132 | $key = array($this->db->protect_identifiers($key)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 133 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 134 | |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 135 | $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).")"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 138 | |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 139 | return $sql."\n)"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | // -------------------------------------------------------------------- |
| 143 | |
| 144 | /** |
| 145 | * Drop Table |
| 146 | * |
| 147 | * @access private |
| 148 | * @return bool |
| 149 | */ |
| 150 | function _drop_table($table) |
| 151 | { |
| 152 | return FALSE; |
| 153 | } |
| 154 | |
| 155 | // -------------------------------------------------------------------- |
| 156 | |
| 157 | /** |
| 158 | * Alter table query |
| 159 | * |
| 160 | * Generates a platform-specific query so that a table can be altered |
| 161 | * Called by add_column(), drop_column(), and column_alter(), |
| 162 | * |
| 163 | * @access private |
| 164 | * @param string the ALTER type (ADD, DROP, CHANGE) |
| 165 | * @param string the column name |
| 166 | * @param string the table name |
| 167 | * @param string the column definition |
| 168 | * @param string the default value |
| 169 | * @param boolean should 'NOT NULL' be added |
| 170 | * @param string the field after which we should add the new field |
| 171 | * @return object |
| 172 | */ |
| 173 | function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') |
| 174 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 175 | $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 176 | |
| 177 | // DROP has everything it needs now. |
| 178 | if ($alter_type == 'DROP') |
| 179 | { |
| 180 | return $sql; |
| 181 | } |
| 182 | |
| 183 | $sql .= " $column_definition"; |
| 184 | |
| 185 | if ($default_value != '') |
| 186 | { |
| 187 | $sql .= " DEFAULT \"$default_value\""; |
| 188 | } |
| 189 | |
| 190 | if ($null === NULL) |
| 191 | { |
| 192 | $sql .= ' NULL'; |
| 193 | } |
| 194 | else |
| 195 | { |
| 196 | $sql .= ' NOT NULL'; |
| 197 | } |
| 198 | |
| 199 | if ($after_field != '') |
| 200 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 201 | return $sql.' AFTER '.$this->db->protect_identifiers($after_field); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 202 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 203 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 204 | return $sql; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 205 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | // -------------------------------------------------------------------- |
| 209 | |
| 210 | /** |
| 211 | * Rename a table |
| 212 | * |
| 213 | * Generates a platform-specific query so that a table can be renamed |
| 214 | * |
| 215 | * @access private |
| 216 | * @param string the old table name |
| 217 | * @param string the new table name |
| 218 | * @return string |
| 219 | */ |
| 220 | function _rename_table($table_name, $new_table_name) |
| 221 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 222 | return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* End of file oci8_forge.php */ |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 228 | /* Location: ./system/database/drivers/oci8/oci8_forge.php */ |