Subversion-Projekte lars-tiefland.ci

Revision

Revision 2254 | Zur aktuellen Revision | 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
 *
2257 lars 9
 * Copyright (c) 2014 - 2018, 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/)
2257 lars 32
 * @copyright	Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/)
68 lars 33
 * @license	http://opensource.org/licenses/MIT	MIT License
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
 * PDO 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_pdo_firebird_forge extends CI_DB_pdo_forge {
48
 
49
	/**
50
	 * RENAME TABLE statement
51
	 *
52
	 * @var	string
53
	 */
54
	protected $_rename_table	= FALSE;
55
 
56
	/**
57
	 * UNSIGNED support
58
	 *
59
	 * @var	array
60
	 */
61
	protected $_unsigned		= array(
62
		'SMALLINT'	=> 'INTEGER',
63
		'INTEGER'	=> 'INT64',
64
		'FLOAT'		=> 'DOUBLE PRECISION'
65
	);
66
 
67
	/**
68
	 * NULL value representation in CREATE/ALTER TABLE statements
69
	 *
70
	 * @var	string
71
	 */
72
	protected $_null		= 'NULL';
73
 
74
	// --------------------------------------------------------------------
75
 
76
	/**
77
	 * Create database
78
	 *
79
	 * @param	string	$db_name
80
	 * @return	string
81
	 */
82
	public function create_database($db_name)
83
	{
84
		// Firebird databases are flat files, so a path is required
85
 
86
		// Hostname is needed for remote access
87
		empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
88
 
89
		return parent::create_database('"'.$db_name.'"');
90
	}
91
 
92
	// --------------------------------------------------------------------
93
 
94
	/**
95
	 * Drop database
96
	 *
97
	 * @param	string	$db_name	(ignored)
98
	 * @return	bool
99
	 */
1257 lars 100
	public function drop_database($db_name)
68 lars 101
	{
102
		if ( ! ibase_drop_db($this->conn_id))
103
		{
104
			return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
105
		}
106
		elseif ( ! empty($this->db->data_cache['db_names']))
107
		{
108
			$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
109
			if ($key !== FALSE)
110
			{
111
				unset($this->db->data_cache['db_names'][$key]);
112
			}
113
		}
114
 
115
		return TRUE;
116
	}
117
 
118
	// --------------------------------------------------------------------
119
 
120
	/**
121
	 * ALTER TABLE
122
	 *
123
	 * @param	string	$alter_type	ALTER type
124
	 * @param	string	$table		Table name
125
	 * @param	mixed	$field		Column definition
126
	 * @return	string|string[]
127
	 */
128
	protected function _alter_table($alter_type, $table, $field)
129
 	{
130
		if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
131
		{
132
			return parent::_alter_table($alter_type, $table, $field);
133
		}
134
 
135
		$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
136
		$sqls = array();
137
		for ($i = 0, $c = count($field); $i < $c; $i++)
138
		{
139
			if ($field[$i]['_literal'] !== FALSE)
140
			{
141
				return FALSE;
142
			}
143
 
144
			if (isset($field[$i]['type']))
145
			{
146
				$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
147
					.' TYPE '.$field[$i]['type'].$field[$i]['length'];
148
			}
149
 
150
			if ( ! empty($field[$i]['default']))
151
			{
152
				$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
153
					.' SET DEFAULT '.$field[$i]['default'];
154
			}
155
 
156
			if (isset($field[$i]['null']))
157
			{
158
				$sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
159
					.($field[$i]['null'] === TRUE ? 'NULL' : '1')
160
					.' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
161
					.' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
162
			}
163
 
164
			if ( ! empty($field[$i]['new_name']))
165
			{
166
				$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
167
					.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
168
			}
169
		}
170
 
171
		return $sqls;
172
 	}
173
 
174
	// --------------------------------------------------------------------
175
 
176
	/**
177
	 * Process column
178
	 *
179
	 * @param	array	$field
180
	 * @return	string
181
	 */
182
	protected function _process_column($field)
183
	{
184
		return $this->db->escape_identifiers($field['name'])
185
			.' '.$field['type'].$field['length']
186
			.$field['null']
187
			.$field['unique']
188
			.$field['default'];
189
	}
190
 
191
	// --------------------------------------------------------------------
192
 
193
	/**
194
	 * Field attribute TYPE
195
	 *
196
	 * Performs a data type mapping between different databases.
197
	 *
198
	 * @param	array	&$attributes
199
	 * @return	void
200
	 */
201
	protected function _attr_type(&$attributes)
202
	{
203
		switch (strtoupper($attributes['TYPE']))
204
		{
205
			case 'TINYINT':
206
				$attributes['TYPE'] = 'SMALLINT';
207
				$attributes['UNSIGNED'] = FALSE;
208
				return;
209
			case 'MEDIUMINT':
210
				$attributes['TYPE'] = 'INTEGER';
211
				$attributes['UNSIGNED'] = FALSE;
212
				return;
213
			case 'INT':
214
				$attributes['TYPE'] = 'INTEGER';
215
				return;
216
			case 'BIGINT':
217
				$attributes['TYPE'] = 'INT64';
218
				return;
219
			default: return;
220
		}
221
	}
222
 
223
	// --------------------------------------------------------------------
224
 
225
	/**
226
	 * Field attribute AUTO_INCREMENT
227
	 *
228
	 * @param	array	&$attributes
229
	 * @param	array	&$field
230
	 * @return	void
231
	 */
232
	protected function _attr_auto_increment(&$attributes, &$field)
233
	{
234
		// Not supported
235
	}
236
 
237
}