| 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 |
* PDO Firebird Database Adapter Class
|
|
|
42 |
*
|
|
|
43 |
* Note: _DB is an extender class that the app controller
|
|
|
44 |
* creates dynamically based on whether the query builder
|
|
|
45 |
* class is being used or not.
|
|
|
46 |
*
|
|
|
47 |
* @package CodeIgniter
|
|
|
48 |
* @subpackage Drivers
|
|
|
49 |
* @category Database
|
|
|
50 |
* @author EllisLab Dev Team
|
|
|
51 |
* @link https://codeigniter.com/user_guide/database/
|
|
|
52 |
*/
|
|
|
53 |
class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver {
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* Sub-driver
|
|
|
57 |
*
|
|
|
58 |
* @var string
|
|
|
59 |
*/
|
|
|
60 |
public $subdriver = 'firebird';
|
|
|
61 |
|
|
|
62 |
// --------------------------------------------------------------------
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* ORDER BY random keyword
|
|
|
66 |
*
|
|
|
67 |
* @var array
|
|
|
68 |
*/
|
|
|
69 |
protected $_random_keyword = array('RAND()', 'RAND()');
|
|
|
70 |
|
|
|
71 |
// --------------------------------------------------------------------
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* Class constructor
|
|
|
75 |
*
|
|
|
76 |
* Builds the DSN if not already set.
|
|
|
77 |
*
|
|
|
78 |
* @param array $params
|
|
|
79 |
* @return void
|
|
|
80 |
*/
|
|
|
81 |
public function __construct($params)
|
|
|
82 |
{
|
|
|
83 |
parent::__construct($params);
|
|
|
84 |
|
|
|
85 |
if (empty($this->dsn))
|
|
|
86 |
{
|
|
|
87 |
$this->dsn = 'firebird:';
|
|
|
88 |
|
|
|
89 |
if ( ! empty($this->database))
|
|
|
90 |
{
|
|
|
91 |
$this->dsn .= 'dbname='.$this->database;
|
|
|
92 |
}
|
|
|
93 |
elseif ( ! empty($this->hostname))
|
|
|
94 |
{
|
|
|
95 |
$this->dsn .= 'dbname='.$this->hostname;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
|
|
99 |
empty($this->role) OR $this->dsn .= ';role='.$this->role;
|
|
|
100 |
}
|
|
|
101 |
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 9) === FALSE)
|
|
|
102 |
{
|
|
|
103 |
$this->dsn .= ';charset='.$this->char_set;
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
// --------------------------------------------------------------------
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Show table query
|
|
|
111 |
*
|
|
|
112 |
* Generates a platform-specific query string so that the table names can be fetched
|
|
|
113 |
*
|
|
|
114 |
* @param bool $prefix_limit
|
|
|
115 |
* @return string
|
|
|
116 |
*/
|
|
|
117 |
protected function _list_tables($prefix_limit = FALSE)
|
|
|
118 |
{
|
|
|
119 |
$sql = 'SELECT "RDB$RELATION_NAME" FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\'';
|
|
|
120 |
|
|
|
121 |
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
|
|
122 |
{
|
|
|
123 |
return $sql.' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
|
|
124 |
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
return $sql;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
// --------------------------------------------------------------------
|
|
|
131 |
|
|
|
132 |
/**
|
|
|
133 |
* Show column query
|
|
|
134 |
*
|
|
|
135 |
* Generates a platform-specific query string so that the column names can be fetched
|
|
|
136 |
*
|
|
|
137 |
* @param string $table
|
|
|
138 |
* @return string
|
|
|
139 |
*/
|
|
|
140 |
protected function _list_columns($table = '')
|
|
|
141 |
{
|
|
|
142 |
return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table);
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
// --------------------------------------------------------------------
|
|
|
146 |
|
|
|
147 |
/**
|
|
|
148 |
* Returns an object with field data
|
|
|
149 |
*
|
|
|
150 |
* @param string $table
|
|
|
151 |
* @return array
|
|
|
152 |
*/
|
|
|
153 |
public function field_data($table)
|
|
|
154 |
{
|
|
|
155 |
$sql = 'SELECT "rfields"."RDB$FIELD_NAME" AS "name",
|
|
|
156 |
CASE "fields"."RDB$FIELD_TYPE"
|
|
|
157 |
WHEN 7 THEN \'SMALLINT\'
|
|
|
158 |
WHEN 8 THEN \'INTEGER\'
|
|
|
159 |
WHEN 9 THEN \'QUAD\'
|
|
|
160 |
WHEN 10 THEN \'FLOAT\'
|
|
|
161 |
WHEN 11 THEN \'DFLOAT\'
|
|
|
162 |
WHEN 12 THEN \'DATE\'
|
|
|
163 |
WHEN 13 THEN \'TIME\'
|
|
|
164 |
WHEN 14 THEN \'CHAR\'
|
|
|
165 |
WHEN 16 THEN \'INT64\'
|
|
|
166 |
WHEN 27 THEN \'DOUBLE\'
|
|
|
167 |
WHEN 35 THEN \'TIMESTAMP\'
|
|
|
168 |
WHEN 37 THEN \'VARCHAR\'
|
|
|
169 |
WHEN 40 THEN \'CSTRING\'
|
|
|
170 |
WHEN 261 THEN \'BLOB\'
|
|
|
171 |
ELSE NULL
|
|
|
172 |
END AS "type",
|
|
|
173 |
"fields"."RDB$FIELD_LENGTH" AS "max_length",
|
|
|
174 |
"rfields"."RDB$DEFAULT_VALUE" AS "default"
|
|
|
175 |
FROM "RDB$RELATION_FIELDS" "rfields"
|
|
|
176 |
JOIN "RDB$FIELDS" "fields" ON "rfields"."RDB$FIELD_SOURCE" = "fields"."RDB$FIELD_NAME"
|
|
|
177 |
WHERE "rfields"."RDB$RELATION_NAME" = '.$this->escape($table).'
|
|
|
178 |
ORDER BY "rfields"."RDB$FIELD_POSITION"';
|
|
|
179 |
|
|
|
180 |
return (($query = $this->query($sql)) !== FALSE)
|
|
|
181 |
? $query->result_object()
|
|
|
182 |
: FALSE;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
// --------------------------------------------------------------------
|
|
|
186 |
|
|
|
187 |
/**
|
|
|
188 |
* Update statement
|
|
|
189 |
*
|
|
|
190 |
* Generates a platform-specific update string from the supplied data
|
|
|
191 |
*
|
|
|
192 |
* @param string $table
|
|
|
193 |
* @param array $values
|
|
|
194 |
* @return string
|
|
|
195 |
*/
|
|
|
196 |
protected function _update($table, $values)
|
|
|
197 |
{
|
|
|
198 |
$this->qb_limit = FALSE;
|
|
|
199 |
return parent::_update($table, $values);
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
// --------------------------------------------------------------------
|
|
|
203 |
|
|
|
204 |
/**
|
|
|
205 |
* Truncate statement
|
|
|
206 |
*
|
|
|
207 |
* Generates a platform-specific truncate string from the supplied data
|
|
|
208 |
*
|
|
|
209 |
* If the database does not support the TRUNCATE statement,
|
|
|
210 |
* then this method maps to 'DELETE FROM table'
|
|
|
211 |
*
|
|
|
212 |
* @param string $table
|
|
|
213 |
* @return string
|
|
|
214 |
*/
|
|
|
215 |
protected function _truncate($table)
|
|
|
216 |
{
|
|
|
217 |
return 'DELETE FROM '.$table;
|
|
|
218 |
}
|
|
|
219 |
|
|
|
220 |
// --------------------------------------------------------------------
|
|
|
221 |
|
|
|
222 |
/**
|
|
|
223 |
* Delete statement
|
|
|
224 |
*
|
|
|
225 |
* Generates a platform-specific delete string from the supplied data
|
|
|
226 |
*
|
|
|
227 |
* @param string $table
|
|
|
228 |
* @return string
|
|
|
229 |
*/
|
|
|
230 |
protected function _delete($table)
|
|
|
231 |
{
|
|
|
232 |
$this->qb_limit = FALSE;
|
|
|
233 |
return parent::_delete($table);
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
// --------------------------------------------------------------------
|
|
|
237 |
|
|
|
238 |
/**
|
|
|
239 |
* LIMIT
|
|
|
240 |
*
|
|
|
241 |
* Generates a platform-specific LIMIT clause
|
|
|
242 |
*
|
|
|
243 |
* @param string $sql SQL Query
|
|
|
244 |
* @return string
|
|
|
245 |
*/
|
|
|
246 |
protected function _limit($sql)
|
|
|
247 |
{
|
|
|
248 |
// Limit clause depends on if Interbase or Firebird
|
|
|
249 |
if (stripos($this->version(), 'firebird') !== FALSE)
|
|
|
250 |
{
|
|
|
251 |
$select = 'FIRST '.$this->qb_limit
|
|
|
252 |
.($this->qb_offset > 0 ? ' SKIP '.$this->qb_offset : '');
|
|
|
253 |
}
|
|
|
254 |
else
|
|
|
255 |
{
|
|
|
256 |
$select = 'ROWS '
|
|
|
257 |
.($this->qb_offset > 0 ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit);
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
return preg_replace('`SELECT`i', 'SELECT '.$select, $sql);
|
|
|
261 |
}
|
|
|
262 |
|
| 1257 |
lars |
263 |
// --------------------------------------------------------------------
|
|
|
264 |
|
|
|
265 |
/**
|
|
|
266 |
* Insert batch statement
|
|
|
267 |
*
|
|
|
268 |
* Generates a platform-specific insert string from the supplied data.
|
|
|
269 |
*
|
|
|
270 |
* @param string $table Table name
|
|
|
271 |
* @param array $keys INSERT keys
|
|
|
272 |
* @param array $values INSERT values
|
|
|
273 |
* @return string|bool
|
|
|
274 |
*/
|
|
|
275 |
protected function _insert_batch($table, $keys, $values)
|
|
|
276 |
{
|
| 2107 |
lars |
277 |
return ($this->db_debug) ? $this->display_error('db_unsupported_feature') : FALSE;
|
| 1257 |
lars |
278 |
}
|
| 68 |
lars |
279 |
}
|