blob: a0c4e6563c3329834c83b2ad65f51b5f183e6cd9 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Timothy Warren76e04352012-02-14 11:55:17 -05002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Timothy Warren76e04352012-02-14 11:55:17 -05006 *
7 * NOTICE OF LICENSE
Timothy Warren817af192012-02-16 08:28:00 -05008 *
Timothy Warren76e04352012-02-14 11:55:17 -05009 * Licensed under the Open Software License version 3.0
Timothy Warren817af192012-02-16 08:28:00 -050010 *
Timothy Warren76e04352012-02-14 11:55:17 -050011 * 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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Timothy Warren76e04352012-02-14 11:55:17 -050028
Timothy Warren76e04352012-02-14 11:55:17 -050029/**
30 * Interbase/Firebird Forge Class
31 *
32 * @category Database
33 * @author EllisLab Dev Team
34 * @link http://codeigniter.com/user_guide/database/
35 */
Andrey Andreev26086872012-07-05 11:21:58 +030036class CI_DB_ibase_forge extends CI_DB_forge {
Timothy Warren76e04352012-02-14 11:55:17 -050037
Andrey Andreevc98e93a2012-11-02 02:04:59 +020038 /**
Andrey Andreeva287a342012-11-05 23:19:59 +020039 * CREATE TABLE IF statement
Andrey Andreevc98e93a2012-11-02 02:04:59 +020040 *
41 * @var string
42 */
Andrey Andreeva287a342012-11-05 23:19:59 +020043 protected $_create_table_if = FALSE;
44
45 /**
46 * RENAME TABLE statement
47 *
48 * @var string
49 */
50 protected $_rename_table = FALSE;
51
52 /**
53 * DROP TABLE IF statement
54 *
55 * @var string
56 */
57 protected $_drop_table_if = FALSE;
58
59 /**
60 * UNSIGNED support
61 *
62 * @var array
63 */
64 protected $_unsigned = array(
65 'SMALLINT' => 'INTEGER',
66 'INTEGER' => 'INT64',
67 'FLOAT' => 'DOUBLE PRECISION'
68 );
69
70 /**
71 * NULL value representation in CREATE/ALTER TABLE statements
72 *
73 * @var string
74 */
75 protected $_null = 'NULL';
Andrey Andreevd947eba2012-04-09 14:58:28 +030076
Andrey Andreevc98e93a2012-11-02 02:04:59 +020077 // --------------------------------------------------------------------
78
Timothy Warren76e04352012-02-14 11:55:17 -050079 /**
80 * Create database
81 *
Andrey Andreevc98e93a2012-11-02 02:04:59 +020082 * @param string $db_name
Timothy Warrenc2b712e2012-02-17 15:58:08 -050083 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -050084 */
Andrey Andreevd947eba2012-04-09 14:58:28 +030085 public function create_database($db_name)
Timothy Warren76e04352012-02-14 11:55:17 -050086 {
Andrey Andreevd947eba2012-04-09 14:58:28 +030087 // Firebird databases are flat files, so a path is required
88
Timothy Warrenc2b712e2012-02-17 15:58:08 -050089 // Hostname is needed for remote access
Andrey Andreevd947eba2012-04-09 14:58:28 +030090 empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
91
92 return parent::create_database('"'.$db_name.'"');
Timothy Warren76e04352012-02-14 11:55:17 -050093 }
94
95 // --------------------------------------------------------------------
96
97 /**
98 * Drop database
99 *
Andrey Andreeva287a342012-11-05 23:19:59 +0200100 * @param string $db_name (ignored)
Timothy Warren76e04352012-02-14 11:55:17 -0500101 * @return bool
102 */
Andrey Andreevd947eba2012-04-09 14:58:28 +0300103 public function drop_database($db_name = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500104 {
Andrey Andreevd947eba2012-04-09 14:58:28 +0300105 if ( ! ibase_drop_db($this->conn_id))
106 {
107 return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
108 }
Andrey Andreev5d281762012-06-11 22:05:40 +0300109 elseif ( ! empty($this->db->data_cache['db_names']))
110 {
111 $key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
112 if ($key !== FALSE)
113 {
114 unset($this->db->data_cache['db_names'][$key]);
115 }
116 }
Andrey Andreevd947eba2012-04-09 14:58:28 +0300117
118 return TRUE;
Timothy Warren76e04352012-02-14 11:55:17 -0500119 }
Andrey Andreevd947eba2012-04-09 14:58:28 +0300120
Timothy Warren76e04352012-02-14 11:55:17 -0500121 // --------------------------------------------------------------------
122
123 /**
Andrey Andreeva287a342012-11-05 23:19:59 +0200124 * ALTER TABLE
Timothy Warren76e04352012-02-14 11:55:17 -0500125 *
Andrey Andreeva287a342012-11-05 23:19:59 +0200126 * @param string $alter_type ALTER type
127 * @param string $table Table name
128 * @param mixed $field Column definition
129 * @return string|string[]
130 */
131 protected function _alter_table($alter_type, $table, $field)
132 {
133 if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
134 {
135 return parent::_alter_table($alter_type, $table, $field);
136 }
137
138 $sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
139 $sqls = array();
140 for ($i = 0, $c = count($field), $sql .= $alter_type.' '; $i < $c; $i++)
141 {
142 if ($field[$i]['_literal'] !== FALSE)
143 {
144 return FALSE;
145 }
146
147 if (isset($field[$i]['type']))
148 {
149 $sqls[] = $sql.' TYPE '.$field[$i]['type'].$field[$i]['length'];
150 }
151
152 if ( ! empty($field[$i]['default']))
153 {
154 $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
155 .' SET '.$field[$i]['default'];
156 }
157
158 if (isset($field[$i]['null']))
159 {
160 $sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
161 .($field[$i]['null'] === TRUE ? 'NULL' : '1')
162 .' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
163 .' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
164 }
165
166 if ( ! empty($field[$i]['new_name']))
167 {
168 $sqls[] = $sql.' ALTER '.$this->db->escape_identifiers($field[$i]['name'])
169 .' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
170 }
171 }
172
173 return $sqls;
174 }
175
176 // --------------------------------------------------------------------
177
178 /**
179 * Process column
180 *
181 * @param array $field
Timothy Warrenc2b712e2012-02-17 15:58:08 -0500182 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500183 */
Andrey Andreeva287a342012-11-05 23:19:59 +0200184 protected function _process_column($field)
Timothy Warren76e04352012-02-14 11:55:17 -0500185 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200186 return $this->db->escape_identifiers($field['name'])
187 .' '.$field['type'].$field['length']
188 .$field['null']
189 .$field['unique']
190 .$field['default'];
Timothy Warren76e04352012-02-14 11:55:17 -0500191 }
192
193 // --------------------------------------------------------------------
194
195 /**
Andrey Andreeva287a342012-11-05 23:19:59 +0200196 * Field attribute TYPE
Timothy Warren76e04352012-02-14 11:55:17 -0500197 *
Andrey Andreeva287a342012-11-05 23:19:59 +0200198 * Performs a data type mapping between different databases.
Timothy Warren76e04352012-02-14 11:55:17 -0500199 *
Andrey Andreeva287a342012-11-05 23:19:59 +0200200 * @param array &$attributes
201 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500202 */
Andrey Andreeva287a342012-11-05 23:19:59 +0200203 protected function _attr_type(&$attributes)
Timothy Warren76e04352012-02-14 11:55:17 -0500204 {
Andrey Andreeva287a342012-11-05 23:19:59 +0200205 switch (strtoupper($attributes['TYPE']))
206 {
207 case 'TINYINT':
208 $attributes['TYPE'] = 'SMALLINT';
209 $attributes['UNSIGNED'] = FALSE;
210 return;
211 case 'MEDIUMINT':
212 $attributes['TYPE'] = 'INTEGER';
213 $attributes['UNSIGNED'] = FALSE;
214 return;
215 case 'INT':
216 $attributes['TYPE'] = 'INTEGER';
217 return;
218 case 'BIGINT':
219 $attributes['TYPE'] = 'INT64';
220 return;
221 default: return;
222 }
223 }
224
225 // --------------------------------------------------------------------
226
227 /**
228 * Field attribute AUTO_INCREMENT
229 *
230 * @param array &$attributes
231 * @param array &$field
232 * @return void
233 */
234 protected function _attr_auto_increment(&$attributes, &$field)
235 {
236 // Not supported
Timothy Warren76e04352012-02-14 11:55:17 -0500237 }
238
Timothy Warren76e04352012-02-14 11:55:17 -0500239}
240
Andrey Andreev26086872012-07-05 11:21:58 +0300241/* End of file ibase_forge.php */
242/* Location: ./system/database/drivers/ibase/ibase_forge.php */