blob: a3940aedbc1de50b2b9328c8e9fac377fc5f0def [file] [log] [blame]
Derek Allard39b622d2008-01-16 21:10:09 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allard39b622d2008-01-16 21:10:09 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allard39b622d2008-01-16 21:10:09 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Oracle Forge Class
20 *
21 * @category Database
Derek Allard3d879d52008-01-18 19:41:32 +000022 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000023 * @link http://codeigniter.com/user_guide/database/
Derek Allard39b622d2008-01-16 21:10:09 +000024 */
25class CI_DB_oci8_forge extends CI_DB_forge {
26
27 /**
28 * Create database
29 *
30 * @access public
31 * @param string the database name
32 * @return bool
33 */
34 function _create_database($name)
35 {
36 return FALSE;
37 }
38
39 // --------------------------------------------------------------------
40
41 /**
42 * Drop database
43 *
44 * @access private
45 * @param string the database name
46 * @return bool
47 */
48 function _drop_database($name)
49 {
50 return FALSE;
51 }
52
53 // --------------------------------------------------------------------
54
55 /**
56 * Create Table
57 *
58 * @access private
59 * @param string the table name
60 * @param array the fields
61 * @param mixed primary key(s)
62 * @param mixed key(s)
63 * @param boolean should 'IF NOT EXISTS' be added to the SQL
64 * @return bool
65 */
66 function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
67 {
68 $sql = 'CREATE TABLE ';
69
70 if ($if_not_exists === TRUE)
71 {
72 $sql .= 'IF NOT EXISTS ';
73 }
74
75 $sql .= $this->db->_escape_table($table)." (";
76 $current_field_count = 0;
77
78 foreach ($fields as $field=>$attributes)
79 {
80 // Numeric field names aren't allowed in databases, so if the key is
81 // numeric, we know it was assigned by PHP and the developer manually
82 // entered the field information, so we'll simply add it to the list
83 if (is_numeric($field))
84 {
85 $sql .= "\n\t$attributes";
86 }
87 else
88 {
89 $attributes = array_change_key_case($attributes, CASE_UPPER);
90
91 $sql .= "\n\t".$this->db->_protect_identifiers($field);
92
93 $sql .= ' '.$attributes['TYPE'];
94
95 if (array_key_exists('CONSTRAINT', $attributes))
96 {
97 $sql .= '('.$attributes['CONSTRAINT'].')';
98 }
99
100 if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
101 {
102 $sql .= ' UNSIGNED';
103 }
104
105 if (array_key_exists('DEFAULT', $attributes))
106 {
107 $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
108 }
109
110 if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
111 {
112 $sql .= ' NULL';
113 }
114 else
115 {
116 $sql .= ' NOT NULL';
117 }
118
119 if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
120 {
121 $sql .= ' AUTO_INCREMENT';
122 }
123 }
124
125 // don't add a comma on the end of the last field
126 if (++$current_field_count < count($fields))
127 {
128 $sql .= ',';
129 }
130 }
131
132 if (count($primary_keys) > 0)
133 {
134 $primary_keys = $this->db->_protect_identifiers($primary_keys);
135 $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
136 }
137
138 if (count($keys) > 0)
139 {
140 $keys = $this->db->_protect_identifiers($keys);
141 $sql .= ",\n\tUNIQUE COLUMNS (" . implode(', ', $keys) . ")";
142 }
143
144 $sql .= "\n)";
145
146 return $sql;
147 }
148
149 // --------------------------------------------------------------------
150
151 /**
152 * Drop Table
153 *
154 * @access private
155 * @return bool
156 */
157 function _drop_table($table)
158 {
159 return FALSE;
160 }
161
162 // --------------------------------------------------------------------
163
164 /**
165 * Alter table query
166 *
167 * Generates a platform-specific query so that a table can be altered
168 * Called by add_column(), drop_column(), and column_alter(),
169 *
170 * @access private
171 * @param string the ALTER type (ADD, DROP, CHANGE)
172 * @param string the column name
173 * @param string the table name
174 * @param string the column definition
175 * @param string the default value
176 * @param boolean should 'NOT NULL' be added
177 * @param string the field after which we should add the new field
178 * @return object
179 */
180 function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
181 {
182 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
183
184 // DROP has everything it needs now.
185 if ($alter_type == 'DROP')
186 {
187 return $sql;
188 }
189
190 $sql .= " $column_definition";
191
192 if ($default_value != '')
193 {
194 $sql .= " DEFAULT \"$default_value\"";
195 }
196
197 if ($null === NULL)
198 {
199 $sql .= ' NULL';
200 }
201 else
202 {
203 $sql .= ' NOT NULL';
204 }
205
206 if ($after_field != '')
207 {
208 $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
209 }
210
211 return $sql;
212
213 }
214
Derek Allard2385d302008-04-07 14:01:01 +0000215 // --------------------------------------------------------------------
216
217 /**
218 * Rename a table
219 *
220 * Generates a platform-specific query so that a table can be renamed
221 *
222 * @access private
223 * @param string the old table name
224 * @param string the new table name
225 * @return string
226 */
227 function _rename_table($table_name, $new_table_name)
228 {
229 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
230 return $sql;
231 }
232
233
Derek Allard39b622d2008-01-16 21:10:09 +0000234}
Derek Jonesc7deac92008-05-11 16:27:41 +0000235?>