| 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 Informix 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_informix_driver extends CI_DB_pdo_driver {
|
|
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
* Sub-driver
|
|
|
57 |
*
|
|
|
58 |
* @var string
|
|
|
59 |
*/
|
|
|
60 |
public $subdriver = 'informix';
|
|
|
61 |
|
|
|
62 |
// --------------------------------------------------------------------
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* ORDER BY random keyword
|
|
|
66 |
*
|
|
|
67 |
* @var array
|
|
|
68 |
*/
|
|
|
69 |
protected $_random_keyword = array('ASC', 'ASC'); // Currently not supported
|
|
|
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 = 'informix:';
|
|
|
88 |
|
|
|
89 |
// Pre-defined DSN
|
|
|
90 |
if (empty($this->hostname) && empty($this->host) && empty($this->port) && empty($this->service))
|
|
|
91 |
{
|
|
|
92 |
if (isset($this->DSN))
|
|
|
93 |
{
|
|
|
94 |
$this->dsn .= 'DSN='.$this->DSN;
|
|
|
95 |
}
|
|
|
96 |
elseif ( ! empty($this->database))
|
|
|
97 |
{
|
|
|
98 |
$this->dsn .= 'DSN='.$this->database;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
return;
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
if (isset($this->host))
|
|
|
105 |
{
|
|
|
106 |
$this->dsn .= 'host='.$this->host;
|
|
|
107 |
}
|
|
|
108 |
else
|
|
|
109 |
{
|
|
|
110 |
$this->dsn .= 'host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
if (isset($this->service))
|
|
|
114 |
{
|
|
|
115 |
$this->dsn .= '; service='.$this->service;
|
|
|
116 |
}
|
|
|
117 |
elseif ( ! empty($this->port))
|
|
|
118 |
{
|
|
|
119 |
$this->dsn .= '; service='.$this->port;
|
|
|
120 |
}
|
|
|
121 |
|
|
|
122 |
empty($this->database) OR $this->dsn .= '; database='.$this->database;
|
|
|
123 |
empty($this->server) OR $this->dsn .= '; server='.$this->server;
|
|
|
124 |
|
|
|
125 |
$this->dsn .= '; protocol='.(isset($this->protocol) ? $this->protocol : 'onsoctcp')
|
|
|
126 |
.'; EnableScrollableCursors=1';
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
// --------------------------------------------------------------------
|
|
|
131 |
|
|
|
132 |
/**
|
|
|
133 |
* Show table query
|
|
|
134 |
*
|
|
|
135 |
* Generates a platform-specific query string so that the table names can be fetched
|
|
|
136 |
*
|
|
|
137 |
* @param bool $prefix_limit
|
|
|
138 |
* @return string
|
|
|
139 |
*/
|
|
|
140 |
protected function _list_tables($prefix_limit = FALSE)
|
|
|
141 |
{
|
|
|
142 |
$sql = 'SELECT "tabname" FROM "systables"
|
|
|
143 |
WHERE "tabid" > 99 AND "tabtype" = \'T\' AND LOWER("owner") = '.$this->escape(strtolower($this->username));
|
|
|
144 |
|
|
|
145 |
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
|
|
146 |
{
|
|
|
147 |
$sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
|
|
148 |
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
return $sql;
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
// --------------------------------------------------------------------
|
|
|
155 |
|
|
|
156 |
/**
|
|
|
157 |
* Show column query
|
|
|
158 |
*
|
|
|
159 |
* Generates a platform-specific query string so that the column names can be fetched
|
|
|
160 |
*
|
|
|
161 |
* @param string $table
|
|
|
162 |
* @return string
|
|
|
163 |
*/
|
|
|
164 |
protected function _list_columns($table = '')
|
|
|
165 |
{
|
|
|
166 |
if (strpos($table, '.') !== FALSE)
|
|
|
167 |
{
|
|
|
168 |
sscanf($table, '%[^.].%s', $owner, $table);
|
|
|
169 |
}
|
|
|
170 |
else
|
|
|
171 |
{
|
|
|
172 |
$owner = $this->username;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
return 'SELECT "colname" FROM "systables", "syscolumns"
|
|
|
176 |
WHERE "systables"."tabid" = "syscolumns"."tabid"
|
|
|
177 |
AND "systables"."tabtype" = \'T\'
|
|
|
178 |
AND LOWER("systables"."owner") = '.$this->escape(strtolower($owner)).'
|
|
|
179 |
AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table));
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
// --------------------------------------------------------------------
|
|
|
183 |
|
|
|
184 |
/**
|
|
|
185 |
* Returns an object with field data
|
|
|
186 |
*
|
|
|
187 |
* @param string $table
|
|
|
188 |
* @return array
|
|
|
189 |
*/
|
|
|
190 |
public function field_data($table)
|
|
|
191 |
{
|
|
|
192 |
$sql = 'SELECT "syscolumns"."colname" AS "name",
|
|
|
193 |
CASE "syscolumns"."coltype"
|
|
|
194 |
WHEN 0 THEN \'CHAR\'
|
|
|
195 |
WHEN 1 THEN \'SMALLINT\'
|
|
|
196 |
WHEN 2 THEN \'INTEGER\'
|
|
|
197 |
WHEN 3 THEN \'FLOAT\'
|
|
|
198 |
WHEN 4 THEN \'SMALLFLOAT\'
|
|
|
199 |
WHEN 5 THEN \'DECIMAL\'
|
|
|
200 |
WHEN 6 THEN \'SERIAL\'
|
|
|
201 |
WHEN 7 THEN \'DATE\'
|
|
|
202 |
WHEN 8 THEN \'MONEY\'
|
|
|
203 |
WHEN 9 THEN \'NULL\'
|
|
|
204 |
WHEN 10 THEN \'DATETIME\'
|
|
|
205 |
WHEN 11 THEN \'BYTE\'
|
|
|
206 |
WHEN 12 THEN \'TEXT\'
|
|
|
207 |
WHEN 13 THEN \'VARCHAR\'
|
|
|
208 |
WHEN 14 THEN \'INTERVAL\'
|
|
|
209 |
WHEN 15 THEN \'NCHAR\'
|
|
|
210 |
WHEN 16 THEN \'NVARCHAR\'
|
|
|
211 |
WHEN 17 THEN \'INT8\'
|
|
|
212 |
WHEN 18 THEN \'SERIAL8\'
|
|
|
213 |
WHEN 19 THEN \'SET\'
|
|
|
214 |
WHEN 20 THEN \'MULTISET\'
|
|
|
215 |
WHEN 21 THEN \'LIST\'
|
|
|
216 |
WHEN 22 THEN \'Unnamed ROW\'
|
|
|
217 |
WHEN 40 THEN \'LVARCHAR\'
|
|
|
218 |
WHEN 41 THEN \'BLOB/CLOB/BOOLEAN\'
|
|
|
219 |
WHEN 4118 THEN \'Named ROW\'
|
|
|
220 |
ELSE "syscolumns"."coltype"
|
|
|
221 |
END AS "type",
|
|
|
222 |
"syscolumns"."collength" as "max_length",
|
|
|
223 |
CASE "sysdefaults"."type"
|
|
|
224 |
WHEN \'L\' THEN "sysdefaults"."default"
|
|
|
225 |
ELSE NULL
|
|
|
226 |
END AS "default"
|
|
|
227 |
FROM "syscolumns", "systables", "sysdefaults"
|
|
|
228 |
WHERE "syscolumns"."tabid" = "systables"."tabid"
|
|
|
229 |
AND "systables"."tabid" = "sysdefaults"."tabid"
|
|
|
230 |
AND "syscolumns"."colno" = "sysdefaults"."colno"
|
|
|
231 |
AND "systables"."tabtype" = \'T\'
|
|
|
232 |
AND LOWER("systables"."owner") = '.$this->escape(strtolower($this->username)).'
|
|
|
233 |
AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table)).'
|
|
|
234 |
ORDER BY "syscolumns"."colno"';
|
|
|
235 |
|
|
|
236 |
return (($query = $this->query($sql)) !== FALSE)
|
|
|
237 |
? $query->result_object()
|
|
|
238 |
: FALSE;
|
|
|
239 |
}
|
|
|
240 |
|
|
|
241 |
// --------------------------------------------------------------------
|
|
|
242 |
|
|
|
243 |
/**
|
|
|
244 |
* Update statement
|
|
|
245 |
*
|
|
|
246 |
* Generates a platform-specific update string from the supplied data
|
|
|
247 |
*
|
|
|
248 |
* @param string $table
|
|
|
249 |
* @param array $values
|
|
|
250 |
* @return string
|
|
|
251 |
*/
|
|
|
252 |
protected function _update($table, $values)
|
|
|
253 |
{
|
|
|
254 |
$this->qb_limit = FALSE;
|
|
|
255 |
$this->qb_orderby = array();
|
|
|
256 |
return parent::_update($table, $values);
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
// --------------------------------------------------------------------
|
|
|
260 |
|
|
|
261 |
/**
|
|
|
262 |
* Truncate statement
|
|
|
263 |
*
|
|
|
264 |
* Generates a platform-specific truncate string from the supplied data
|
|
|
265 |
*
|
|
|
266 |
* If the database does not support the TRUNCATE statement,
|
|
|
267 |
* then this method maps to 'DELETE FROM table'
|
|
|
268 |
*
|
|
|
269 |
* @param string $table
|
|
|
270 |
* @return string
|
|
|
271 |
*/
|
|
|
272 |
protected function _truncate($table)
|
|
|
273 |
{
|
|
|
274 |
return 'TRUNCATE TABLE ONLY '.$table;
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
// --------------------------------------------------------------------
|
|
|
278 |
|
|
|
279 |
/**
|
|
|
280 |
* Delete statement
|
|
|
281 |
*
|
|
|
282 |
* Generates a platform-specific delete string from the supplied data
|
|
|
283 |
*
|
|
|
284 |
* @param string $table
|
|
|
285 |
* @return string
|
|
|
286 |
*/
|
|
|
287 |
protected function _delete($table)
|
|
|
288 |
{
|
|
|
289 |
$this->qb_limit = FALSE;
|
|
|
290 |
return parent::_delete($table);
|
|
|
291 |
}
|
|
|
292 |
|
|
|
293 |
// --------------------------------------------------------------------
|
|
|
294 |
|
|
|
295 |
/**
|
|
|
296 |
* LIMIT
|
|
|
297 |
*
|
|
|
298 |
* Generates a platform-specific LIMIT clause
|
|
|
299 |
*
|
|
|
300 |
* @param string $sql $SQL Query
|
|
|
301 |
* @return string
|
|
|
302 |
*/
|
|
|
303 |
protected function _limit($sql)
|
|
|
304 |
{
|
|
|
305 |
$select = 'SELECT '.($this->qb_offset ? 'SKIP '.$this->qb_offset : '').'FIRST '.$this->qb_limit.' ';
|
|
|
306 |
return preg_replace('/^(SELECT\s)/i', $select, $sql, 1);
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
}
|