blob: 36d980b67d2ed65616e670799df1e3ad852e3bd5 [file] [log] [blame]
Timothy Warren76e04352012-02-14 11:55:17 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 5.1.6 or newer
6 *
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 *
19 * @package CodeIgniter
20 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
23 * @link http://codeigniter.com
24 * @since Version 3.0
25 * @filesource
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Interbase/Firebird Forge Class
32 *
33 * @category Database
34 * @author EllisLab Dev Team
35 * @link http://codeigniter.com/user_guide/database/
36 */
37class CI_DB_interbase_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()
47 {
48 // In Interbase/Firebird, a database is created when you connect to the database.
49 // We'll return TRUE so that an error isn't generated
50 return TRUE;
51 }
52
53 // --------------------------------------------------------------------
54
55 /**
56 * Drop database
57 *
58 * @access private
59 * @param string the database name - not used in this driver
60 * - the current db is dropped
61 * @return bool
62 */
63 function _drop_database($name='')
64 {
65 return ibase_drop_db($this->conn_id);
66 }
67 // --------------------------------------------------------------------
68
69 /**
70 * Create Table
71 *
72 * @access private
73 * @param string the table name
74 * @param array the fields
75 * @param mixed primary key(s)
76 * @param mixed key(s)
77 * @param boolean should 'IF NOT EXISTS' be added to the SQL
78 * @return bool
79 */
80 function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
81 {
82 $sql = 'CREATE TABLE ';
83
84 $sql .= $this->db->_escape_identifiers($table)."(";
85 $current_field_count = 0;
86
87 foreach ($fields as $field=>$attributes)
88 {
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 {
94 $sql .= "\n\t$attributes";
95 }
96 else
97 {
98 $attributes = array_change_key_case($attributes, CASE_UPPER);
99
100 $sql .= "\n\t".$this->db->_protect_identifiers($field);
101
102 $sql .= ' '.$attributes['TYPE'];
103
104 if (array_key_exists('CONSTRAINT', $attributes))
105 {
106 $sql .= '('.$attributes['CONSTRAINT'].')';
107 }
108
109 if (array_key_exists('UNSIGNED', $attributes) && $attributes['UNSIGNED'] === TRUE)
110 {
111 $sql .= ' UNSIGNED';
112 }
113
114 if (array_key_exists('DEFAULT', $attributes))
115 {
116 $sql .= ' DEFAULT \''.$attributes['DEFAULT'].'\'';
117 }
118
119 if (array_key_exists('NULL', $attributes) && $attributes['NULL'] === TRUE)
120 {
121 $sql .= ' NULL';
122 }
123 else
124 {
125 $sql .= ' NOT NULL';
126 }
127
128 if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
129 {
130 $sql .= ' AUTO_INCREMENT';
131 }
132 }
133
134 // don't add a comma on the end of the last field
135 if (++$current_field_count < count($fields))
136 {
137 $sql .= ',';
138 }
139 }
140
141 if (count($primary_keys) > 0)
142 {
143 $primary_keys = $this->db->_protect_identifiers($primary_keys);
144 $sql .= ",\n\tPRIMARY KEY (" . implode(', ', $primary_keys) . ")";
145 }
146
147 if (is_array($keys) && count($keys) > 0)
148 {
149 foreach ($keys as $key)
150 {
151 if (is_array($key))
152 {
153 $key = $this->db->_protect_identifiers($key);
154 }
155 else
156 {
157 $key = array($this->db->_protect_identifiers($key));
158 }
159
160 $sql .= ",\n\tUNIQUE (" . implode(', ', $key) . ")";
161 }
162 }
163
164 $sql .= "\n)";
165
166 return $sql;
167 }
168
169 // --------------------------------------------------------------------
170
171 /**
172 * Drop Table
173 *
174 * @access private
175 * @return bool
176 */
177 function _drop_table($table)
178 {
179 if ($this->db->db_debug)
180 {
181 return $this->db->display_error('db_unsuported_feature');
182 }
183 return array();
184 }
185
186 // --------------------------------------------------------------------
187
188 /**
189 * Alter table query
190 *
191 * Generates a platform-specific query so that a table can be altered
192 * Called by add_column(), drop_column(), and column_alter(),
193 *
194 * @access private
195 * @param string the ALTER type (ADD, DROP, CHANGE)
196 * @param string the column name
197 * @param string the table name
198 * @param string the column definition
199 * @param string the default value
200 * @param boolean should 'NOT NULL' be added
201 * @param string the field after which we should add the new field
202 * @return object
203 */
204 function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '')
205 {
206 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table)." $alter_type ".$this->db->_protect_identifiers($column_name);
207
208 // DROP has everything it needs now.
209 /*if ($alter_type == 'DROP')
210 {
211 // SQLite does not support dropping columns
212 // http://www.sqlite.org/omitted.html
213 // http://www.sqlite.org/faq.html#q11
214 return FALSE;
215 }*/
216
217 $sql .= " $column_definition";
218
219 if ($default_value != '')
220 {
221 $sql .= " DEFAULT \"$default_value\"";
222 }
223
224 if ($null === NULL)
225 {
226 $sql .= ' NULL';
227 }
228 else
229 {
230 $sql .= ' NOT NULL';
231 }
232
233 if ($after_field != '')
234 {
235 $sql .= ' AFTER ' . $this->db->_protect_identifiers($after_field);
236 }
237
238 return $sql;
239
240 }
241
242 // --------------------------------------------------------------------
243
244 /**
245 * Rename a table
246 *
247 * Generates a platform-specific query so that a table can be renamed
248 *
249 * @access private
250 * @param string the old table name
251 * @param string the new table name
252 * @return string
253 */
254 function _rename_table($table_name, $new_table_name)
255 {
256 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
257 return $sql;
258 }
259}
260
261/* End of file interbase_forge.php */
262/* Location: ./system/database/drivers/interbase/interbase_forge.php */