Subversion-Projekte lars-tiefland.ci

Revision

Revision 2257 | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
68 lars 1
<?php
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
2414 lars 9
 * Copyright (c) 2014 - 2019, British Columbia Institute of Technology
68 lars 10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
 * copies of the Software, and to permit persons to whom the Software is
16
 * furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in
19
 * all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 *
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
2414 lars 32
 * @copyright	Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
33
 * @license	https://opensource.org/licenses/MIT	MIT License
68 lars 34
 * @link	https://codeigniter.com
35
 * @since	Version 3.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
39
 
40
/**
41
 * Interbase/Firebird Forge Class
42
 *
43
 * @category	Database
44
 * @author		EllisLab Dev Team
45
 * @link		https://codeigniter.com/user_guide/database/
46
 */
47
class CI_DB_ibase_forge extends CI_DB_forge {
48
 
49
	/**
50
	 * CREATE TABLE IF statement
51
	 *
52
	 * @var	string
53
	 */
54
	protected $_create_table_if	= FALSE;
55
 
56
	/**
57
	 * RENAME TABLE statement
58
	 *
59
	 * @var	string
60
	 */
61
	protected $_rename_table	= FALSE;
62
 
63
	/**
64
	 * DROP TABLE IF statement
65
	 *
66
	 * @var	string
67
	 */
68
	protected $_drop_table_if	= FALSE;
69
 
70
	/**
71
	 * UNSIGNED support
72
	 *
73
	 * @var	array
74
	 */
75
	protected $_unsigned		= array(
76
		'SMALLINT'	=> 'INTEGER',
77
		'INTEGER'	=> 'INT64',
78
		'FLOAT'		=> 'DOUBLE PRECISION'
79
	);
80
 
81
	/**
82
	 * NULL value representation in CREATE/ALTER TABLE statements
83
	 *
84
	 * @var	string
85
	 */
86
	protected $_null		= 'NULL';
87
 
88
	// --------------------------------------------------------------------
89
 
90
	/**
91
	 * Create database
92
	 *
93
	 * @param	string	$db_name
2107 lars 94
	 * @return	bool
68 lars 95
	 */
96
	public function create_database($db_name)
97
	{
98
		// Firebird databases are flat files, so a path is required
99
 
100
		// Hostname is needed for remote access
101
		empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
102
 
103
		return parent::create_database('"'.$db_name.'"');
104
	}
105
 
106
	// --------------------------------------------------------------------
107
 
108
	/**
109
	 * Drop database
110
	 *
111
	 * @param	string	$db_name	(ignored)
112
	 * @return	bool
113
	 */
1257 lars 114
	public function drop_database($db_name)
68 lars 115
	{
116
		if ( ! ibase_drop_db($this->conn_id))
117
		{
118
			return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
119
		}
120
		elseif ( ! empty($this->db->data_cache['db_names']))
121
		{
122
			$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
123
			if ($key !== FALSE)
124
			{
125
				unset($this->db->data_cache['db_names'][$key]);
126
			}
127
		}
128
 
129
		return TRUE;
130
	}
131
 
132
	// --------------------------------------------------------------------
133
 
134
	/**
135
	 * ALTER TABLE
136
	 *
137
	 * @param	string	$alter_type	ALTER type
138
	 * @param	string	$table		Table name
139
	 * @param	mixed	$field		Column definition
140
	 * @return	string|string[]
141
	 */
142
	protected function _alter_table($alter_type, $table, $field)
143
 	{
144
		if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
145
		{
146
			return parent::_alter_table($alter_type, $table, $field);
147
		}
148
 
149
		$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
150
		$sqls = array();
151
		for ($i = 0, $c = count($field); $i < $c; $i++)
152
		{
153
			if ($field[$i]['_literal'] !== FALSE)
154
			{
155
				return FALSE;
156
			}
157
 
158
			if (isset($field[$i]['type']))
159
			{
160
				$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identififers($field[$i]['name'])
161
					.' TYPE '.$field[$i]['type'].$field[$i]['length'];
162
			}
163
 
164
			if ( ! empty($field[$i]['default']))
165
			{
166
				$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
167
					.' SET DEFAULT '.$field[$i]['default'];
168
			}
169
 
170
			if (isset($field[$i]['null']))
171
			{
172
				$sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
173
					.($field[$i]['null'] === TRUE ? 'NULL' : '1')
174
					.' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
175
					.' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
176
			}
177
 
178
			if ( ! empty($field[$i]['new_name']))
179
			{
180
				$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
181
					.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
182
			}
183
		}
184
 
185
		return $sqls;
186
 	}
187
 
188
	// --------------------------------------------------------------------
189
 
190
	/**
191
	 * Process column
192
	 *
193
	 * @param	array	$field
194
	 * @return	string
195
	 */
196
	protected function _process_column($field)
197
	{
198
		return $this->db->escape_identifiers($field['name'])
199
			.' '.$field['type'].$field['length']
200
			.$field['null']
201
			.$field['unique']
202
			.$field['default'];
203
	}
204
 
205
	// --------------------------------------------------------------------
206
 
207
	/**
208
	 * Field attribute TYPE
209
	 *
210
	 * Performs a data type mapping between different databases.
211
	 *
212
	 * @param	array	&$attributes
213
	 * @return	void
214
	 */
215
	protected function _attr_type(&$attributes)
216
	{
217
		switch (strtoupper($attributes['TYPE']))
218
		{
219
			case 'TINYINT':
220
				$attributes['TYPE'] = 'SMALLINT';
221
				$attributes['UNSIGNED'] = FALSE;
222
				return;
223
			case 'MEDIUMINT':
224
				$attributes['TYPE'] = 'INTEGER';
225
				$attributes['UNSIGNED'] = FALSE;
226
				return;
227
			case 'INT':
228
				$attributes['TYPE'] = 'INTEGER';
229
				return;
230
			case 'BIGINT':
231
				$attributes['TYPE'] = 'INT64';
232
				return;
233
			default: return;
234
		}
235
	}
236
 
237
	// --------------------------------------------------------------------
238
 
239
	/**
240
	 * Field attribute AUTO_INCREMENT
241
	 *
242
	 * @param	array	&$attributes
243
	 * @param	array	&$field
244
	 * @return	void
245
	 */
246
	protected function _attr_auto_increment(&$attributes, &$field)
247
	{
248
		// Not supported
249
	}
250
 
251
}