Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [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 |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 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 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * Oracle Forge Class |
| 30 | * |
| 31 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 32 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 33 | * @link http://codeigniter.com/user_guide/database/ |
| 34 | */ |
| 35 | class CI_DB_oci8_forge extends CI_DB_forge { |
| 36 | |
| 37 | /** |
| 38 | * Create database |
| 39 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | * @param string the database name |
| 41 | * @return bool |
| 42 | */ |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 43 | public function _create_database($name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 44 | { |
| 45 | return FALSE; |
| 46 | } |
| 47 | |
| 48 | // -------------------------------------------------------------------- |
| 49 | |
| 50 | /** |
| 51 | * Drop database |
| 52 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | * @param string the database name |
| 54 | * @return bool |
| 55 | */ |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 56 | public function _drop_database($name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 57 | { |
| 58 | return FALSE; |
| 59 | } |
| 60 | |
| 61 | // -------------------------------------------------------------------- |
| 62 | |
| 63 | /** |
| 64 | * Create Table |
| 65 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 66 | * @param string the table name |
| 67 | * @param array the fields |
| 68 | * @param mixed primary key(s) |
| 69 | * @param mixed key(s) |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 70 | * @param bool should 'IF NOT EXISTS' be added to the SQL |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | * @return bool |
| 72 | */ |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 73 | public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 74 | { |
| 75 | $sql = 'CREATE TABLE '; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 76 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 77 | if ($if_not_exists === TRUE) |
| 78 | { |
| 79 | $sql .= 'IF NOT EXISTS '; |
| 80 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 81 | |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 82 | $sql .= $this->db->_escape_identifiers($table).' ('; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | $current_field_count = 0; |
| 84 | |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 85 | foreach ($fields as $field => $attributes) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 86 | { |
| 87 | // Numeric field names aren't allowed in databases, so if the key is |
| 88 | // numeric, we know it was assigned by PHP and the developer manually |
| 89 | // entered the field information, so we'll simply add it to the list |
| 90 | if (is_numeric($field)) |
| 91 | { |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 92 | $sql .= "\n\t".$attributes; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 93 | } |
| 94 | else |
| 95 | { |
| 96 | $attributes = array_change_key_case($attributes, CASE_UPPER); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 97 | |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 98 | $sql .= "\n\t".$this->db->protect_identifiers($field).' '.$attributes['TYPE'] |
| 99 | .((isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '') |
| 100 | .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '') |
| 101 | .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? '' : ' NOT NULL') |
| 102 | .(isset($attributes['CONSTRAINT']) ? ' CONSTRAINT '.$attributes['CONSTRAINT'] : ''); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 103 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 104 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 105 | // don't add a comma on the end of the last field |
| 106 | if (++$current_field_count < count($fields)) |
| 107 | { |
| 108 | $sql .= ','; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (count($primary_keys) > 0) |
| 113 | { |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 114 | $primary_keys = $this->db->protect_identifiers($primary_keys); |
| 115 | $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $primary_keys).')'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (is_array($keys) && count($keys) > 0) |
| 119 | { |
| 120 | foreach ($keys as $key) |
| 121 | { |
| 122 | if (is_array($key)) |
| 123 | { |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 124 | $key = $this->db->protect_identifiers($key); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 125 | } |
| 126 | else |
| 127 | { |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 128 | $key = array($this->db->protect_identifiers($key)); |
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 | |
Andrey Andreev | 8f22057 | 2012-03-02 13:05:45 +0200 | [diff] [blame] | 131 | $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).")"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | } |
| 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 | return $sql."\n)"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // -------------------------------------------------------------------- |
| 139 | |
| 140 | /** |
| 141 | * Drop Table |
| 142 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 143 | * @return bool |
| 144 | */ |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 145 | public function _drop_table($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 146 | { |
| 147 | return FALSE; |
| 148 | } |
| 149 | |
| 150 | // -------------------------------------------------------------------- |
| 151 | |
| 152 | /** |
| 153 | * Alter table query |
| 154 | * |
| 155 | * Generates a platform-specific query so that a table can be altered |
| 156 | * Called by add_column(), drop_column(), and column_alter(), |
| 157 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 158 | * @param string the ALTER type (ADD, DROP, CHANGE) |
| 159 | * @param string the column name |
| 160 | * @param string the table name |
| 161 | * @param string the column definition |
| 162 | * @param string the default value |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 163 | * @param bool should 'NOT NULL' be added |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 164 | * @param string the field after which we should add the new field |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 165 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 166 | */ |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 167 | public function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 169 | $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] | 170 | |
| 171 | // DROP has everything it needs now. |
| 172 | if ($alter_type == 'DROP') |
| 173 | { |
| 174 | return $sql; |
| 175 | } |
| 176 | |
| 177 | $sql .= " $column_definition"; |
| 178 | |
| 179 | if ($default_value != '') |
| 180 | { |
| 181 | $sql .= " DEFAULT \"$default_value\""; |
| 182 | } |
| 183 | |
| 184 | if ($null === NULL) |
| 185 | { |
| 186 | $sql .= ' NULL'; |
| 187 | } |
| 188 | else |
| 189 | { |
| 190 | $sql .= ' NOT NULL'; |
| 191 | } |
| 192 | |
| 193 | if ($after_field != '') |
| 194 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 195 | return $sql.' AFTER '.$this->db->protect_identifiers($after_field); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 196 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 197 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 198 | return $sql; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 199 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // -------------------------------------------------------------------- |
| 203 | |
| 204 | /** |
| 205 | * Rename a table |
| 206 | * |
| 207 | * Generates a platform-specific query so that a table can be renamed |
| 208 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 209 | * @param string the old table name |
| 210 | * @param string the new table name |
| 211 | * @return string |
| 212 | */ |
Andrey Andreev | 2f56fba | 2012-03-20 22:32:20 +0200 | [diff] [blame] | 213 | public function _rename_table($table_name, $new_table_name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | { |
Andrey Andreev | 032e7ea | 2012-03-06 19:48:35 +0200 | [diff] [blame] | 215 | 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] | 216 | } |
| 217 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /* End of file oci8_forge.php */ |
Timothy Warren | 215890b | 2012-03-20 09:38:16 -0400 | [diff] [blame] | 221 | /* Location: ./system/database/drivers/oci8/oci8_forge.php */ |