blob: 0aa119907962214185025ce76991c30d455a4309 [file] [log] [blame]
Derek Jones37f4b9c2011-07-01 17:56:50 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * 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 Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @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 Jonesf4a4bd82011-10-20 12:18:42 -050034 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000035 * @link http://codeigniter.com/user_guide/database/
36 */
37class 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 Allard2067d1a2008-11-13 22:59:24 +000070 * @param string the table name
71 * @param array the fields
72 * @param mixed primary key(s)
73 * @param mixed key(s)
Andrey Andreev8f220572012-03-02 13:05:45 +020074 * @param bool should 'IF NOT EXISTS' be added to the SQL
Derek Allard2067d1a2008-11-13 22:59:24 +000075 * @return bool
76 */
Andrey Andreev8f220572012-03-02 13:05:45 +020077 public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
Derek Allard2067d1a2008-11-13 22:59:24 +000078 {
79 $sql = 'CREATE TABLE ';
Barry Mienydd671972010-10-04 16:33:58 +020080
Derek Allard2067d1a2008-11-13 22:59:24 +000081 if ($if_not_exists === TRUE)
82 {
83 $sql .= 'IF NOT EXISTS ';
84 }
Barry Mienydd671972010-10-04 16:33:58 +020085
Andrey Andreev8f220572012-03-02 13:05:45 +020086 $sql .= $this->db->_escape_identifiers($table).' (';
Derek Allard2067d1a2008-11-13 22:59:24 +000087 $current_field_count = 0;
88
Andrey Andreev8f220572012-03-02 13:05:45 +020089 foreach ($fields as $field => $attributes)
Derek Allard2067d1a2008-11-13 22:59:24 +000090 {
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 Andreev8f220572012-03-02 13:05:45 +020096 $sql .= "\n\t".$attributes;
Derek Allard2067d1a2008-11-13 22:59:24 +000097 }
98 else
99 {
100 $attributes = array_change_key_case($attributes, CASE_UPPER);
Barry Mienydd671972010-10-04 16:33:58 +0200101
Andrey Andreev8f220572012-03-02 13:05:45 +0200102 $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 Allard2067d1a2008-11-13 22:59:24 +0000107 }
Barry Mienydd671972010-10-04 16:33:58 +0200108
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 // 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 Andreev8f220572012-03-02 13:05:45 +0200118 $primary_keys = $this->db->protect_identifiers($primary_keys);
119 $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $primary_keys).')';
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 }
121
122 if (is_array($keys) && count($keys) > 0)
123 {
124 foreach ($keys as $key)
125 {
126 if (is_array($key))
127 {
Andrey Andreev8f220572012-03-02 13:05:45 +0200128 $key = $this->db->protect_identifiers($key);
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 }
130 else
131 {
Andrey Andreev8f220572012-03-02 13:05:45 +0200132 $key = array($this->db->protect_identifiers($key));
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 }
Barry Mienydd671972010-10-04 16:33:58 +0200134
Andrey Andreev8f220572012-03-02 13:05:45 +0200135 $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).")";
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 }
137 }
Barry Mienydd671972010-10-04 16:33:58 +0200138
Andrey Andreev8f220572012-03-02 13:05:45 +0200139 return $sql."\n)";
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 }
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 {
175 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
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 {
201 $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
202 }
Barry Mienydd671972010-10-04 16:33:58 +0200203
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 return $sql;
Barry Mienydd671972010-10-04 16:33:58 +0200205
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 }
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 {
222 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
223 return $sql;
224 }
225
226
227}
228
229/* End of file oci8_forge.php */
Andrey Andreev8f220572012-03-02 13:05:45 +0200230/* Location: ./system/database/drivers/oci8/oci8_forge.php */