blob: f9a90ff0a60c81b4b7bc8c8085fa79490818a584 [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 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 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 *
Derek Allard2067d1a2008-11-13 22:59:24 +000042 * @param string the database name
43 * @return bool
44 */
Timothy Warren9f86f5c2012-03-19 17:53:37 -040045 public function _create_database($name)
Derek Allard2067d1a2008-11-13 22:59:24 +000046 {
47 return FALSE;
48 }
49
50 // --------------------------------------------------------------------
51
52 /**
53 * Drop database
54 *
Derek Allard2067d1a2008-11-13 22:59:24 +000055 * @param string the database name
56 * @return bool
57 */
Timothy Warren9f86f5c2012-03-19 17:53:37 -040058 protected function _drop_database($name)
Derek Allard2067d1a2008-11-13 22:59:24 +000059 {
60 return FALSE;
61 }
62
63 // --------------------------------------------------------------------
64
65 /**
66 * Create Table
67 *
Derek Allard2067d1a2008-11-13 22:59:24 +000068 * @param string the table name
69 * @param array the fields
70 * @param mixed primary key(s)
71 * @param mixed key(s)
Andrey Andreev8f220572012-03-02 13:05:45 +020072 * @param bool should 'IF NOT EXISTS' be added to the SQL
Derek Allard2067d1a2008-11-13 22:59:24 +000073 * @return bool
74 */
Andrey Andreev8f220572012-03-02 13:05:45 +020075 public function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
Derek Allard2067d1a2008-11-13 22:59:24 +000076 {
77 $sql = 'CREATE TABLE ';
Barry Mienydd671972010-10-04 16:33:58 +020078
Derek Allard2067d1a2008-11-13 22:59:24 +000079 if ($if_not_exists === TRUE)
80 {
81 $sql .= 'IF NOT EXISTS ';
82 }
Barry Mienydd671972010-10-04 16:33:58 +020083
Andrey Andreev8f220572012-03-02 13:05:45 +020084 $sql .= $this->db->_escape_identifiers($table).' (';
Derek Allard2067d1a2008-11-13 22:59:24 +000085 $current_field_count = 0;
86
Andrey Andreev8f220572012-03-02 13:05:45 +020087 foreach ($fields as $field => $attributes)
Derek Allard2067d1a2008-11-13 22:59:24 +000088 {
89 // Numeric field names aren't allowed in databases, so if the key is
90 // numeric, we know it was assigned by PHP and the developer manually
91 // entered the field information, so we'll simply add it to the list
92 if (is_numeric($field))
93 {
Andrey Andreev8f220572012-03-02 13:05:45 +020094 $sql .= "\n\t".$attributes;
Derek Allard2067d1a2008-11-13 22:59:24 +000095 }
96 else
97 {
98 $attributes = array_change_key_case($attributes, CASE_UPPER);
Barry Mienydd671972010-10-04 16:33:58 +020099
Andrey Andreev8f220572012-03-02 13:05:45 +0200100 $sql .= "\n\t".$this->db->protect_identifiers($field).' '.$attributes['TYPE']
101 .((isset($attributes['UNSINGED']) && $attributes['UNSIGNED'] === TRUE) ? ' UNSIGNED' : '')
102 .(isset($attributes['DEFAULT']) ? " DEFAULT '".$attributes['DEFAULT']."'" : '')
103 .((isset($attributes['NULL']) && $attributes['NULL'] === TRUE) ? '' : ' NOT NULL')
104 .(isset($attributes['CONSTRAINT']) ? ' CONSTRAINT '.$attributes['CONSTRAINT'] : '');
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 }
Barry Mienydd671972010-10-04 16:33:58 +0200106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 // don't add a comma on the end of the last field
108 if (++$current_field_count < count($fields))
109 {
110 $sql .= ',';
111 }
112 }
113
114 if (count($primary_keys) > 0)
115 {
Andrey Andreev8f220572012-03-02 13:05:45 +0200116 $primary_keys = $this->db->protect_identifiers($primary_keys);
117 $sql .= ",\n\tCONSTRAINT ".$table.' PRIMARY KEY ('.implode(', ', $primary_keys).')';
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 }
119
120 if (is_array($keys) && count($keys) > 0)
121 {
122 foreach ($keys as $key)
123 {
124 if (is_array($key))
125 {
Andrey Andreev8f220572012-03-02 13:05:45 +0200126 $key = $this->db->protect_identifiers($key);
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 }
128 else
129 {
Andrey Andreev8f220572012-03-02 13:05:45 +0200130 $key = array($this->db->protect_identifiers($key));
Derek Allard2067d1a2008-11-13 22:59:24 +0000131 }
Barry Mienydd671972010-10-04 16:33:58 +0200132
Andrey Andreev8f220572012-03-02 13:05:45 +0200133 $sql .= ",\n\tUNIQUE COLUMNS (".implode(', ', $key).")";
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 }
135 }
Barry Mienydd671972010-10-04 16:33:58 +0200136
Andrey Andreev8f220572012-03-02 13:05:45 +0200137 return $sql."\n)";
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 }
139
140 // --------------------------------------------------------------------
141
142 /**
143 * Drop Table
144 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 * @return bool
146 */
Timothy Warren9f86f5c2012-03-19 17:53:37 -0400147 protected function _drop_table($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 {
149 return FALSE;
150 }
151
152 // --------------------------------------------------------------------
153
154 /**
155 * Alter table query
156 *
157 * Generates a platform-specific query so that a table can be altered
158 * Called by add_column(), drop_column(), and column_alter(),
159 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 * @param string the ALTER type (ADD, DROP, CHANGE)
161 * @param string the column name
162 * @param string the table name
163 * @param string the column definition
164 * @param string the default value
165 * @param boolean should 'NOT NULL' be added
166 * @param string the field after which we should add the new field
167 * @return object
168 */
Timothy Warren9f86f5c2012-03-19 17:53:37 -0400169 protected function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200171 $sql = 'ALTER TABLE '.$this->db->protect_identifiers($table).' '.$alter_type.' '.$this->db->protect_identifiers($column_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000172
173 // DROP has everything it needs now.
174 if ($alter_type == 'DROP')
175 {
176 return $sql;
177 }
178
179 $sql .= " $column_definition";
180
181 if ($default_value != '')
182 {
183 $sql .= " DEFAULT \"$default_value\"";
184 }
185
186 if ($null === NULL)
187 {
188 $sql .= ' NULL';
189 }
190 else
191 {
192 $sql .= ' NOT NULL';
193 }
194
195 if ($after_field != '')
196 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200197 return $sql.' AFTER '.$this->db->protect_identifiers($after_field);
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 }
Barry Mienydd671972010-10-04 16:33:58 +0200199
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 return $sql;
Barry Mienydd671972010-10-04 16:33:58 +0200201
Derek Allard2067d1a2008-11-13 22:59:24 +0000202 }
203
204 // --------------------------------------------------------------------
205
206 /**
207 * Rename a table
208 *
209 * Generates a platform-specific query so that a table can be renamed
210 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 * @param string the old table name
212 * @param string the new table name
213 * @return string
214 */
Timothy Warren9f86f5c2012-03-19 17:53:37 -0400215 protected function _rename_table($table_name, $new_table_name)
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 {
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200217 return 'ALTER TABLE '.$this->db->protect_identifiers($table_name).' RENAME TO '.$this->db->protect_identifiers($new_table_name);
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 }
219
Derek Allard2067d1a2008-11-13 22:59:24 +0000220}
221
222/* End of file oci8_forge.php */
Timothy Warren9f86f5c2012-03-19 17:53:37 -0400223/* Location: ./system/database/drivers/oci8/oci8_forge.php */