blob: 1b18de8032909d81eae023e73b55be58598a07d1 [file] [log] [blame]
Timothy Warren817af192012-02-16 08:28:00 -05001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
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
Timothy Warren7221f942012-02-14 15:02:33 -050017 * licensing@ellislab.com so we can send you a copy immediately.
Timothy Warren76e04352012-02-14 11:55:17 -050018 *
Timothy Warren7221f942012-02-14 15:02:33 -050019 * @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
Timothy Warren76e04352012-02-14 11:55:17 -050026 */
27
Timothy Warren76e04352012-02-14 11:55:17 -050028/**
29 * Firebird/Interbase Database Adapter Class
30 *
31 * Note: _DB is an extender class that the app controller
Jamie Rumbelowffe7a0a2012-04-26 13:48:18 +010032 * creates dynamically based on whether the query builder
Timothy Warren76e04352012-02-14 11:55:17 -050033 * class is being used or not.
34 *
Timothy Warren7221f942012-02-14 15:02:33 -050035 * @package CodeIgniter
36 * @subpackage Drivers
37 * @category Database
38 * @author EllisLab Dev Team
39 * @link http://codeigniter.com/user_guide/database/
Timothy Warren76e04352012-02-14 11:55:17 -050040 */
41class CI_DB_interbase_driver extends CI_DB {
42
43 public $dbdriver = 'interbase';
44
45 // The character used to escape with
Timothy Warren95562142012-02-20 17:37:21 -050046 protected $_escape_char = '"';
Timothy Warren76e04352012-02-14 11:55:17 -050047
48 // clause and character used for LIKE escape sequences
Timothy Warren95562142012-02-20 17:37:21 -050049 protected $_like_escape_str = " ESCAPE '%s' ";
50 protected $_like_escape_chr = '!';
Timothy Warren76e04352012-02-14 11:55:17 -050051
52 /**
53 * The syntax to count rows is slightly different across different
54 * database engines, so this string appears in each driver and is
55 * used for the count_all() and count_all_results() functions.
56 */
Andrey Andreev131772c2012-03-20 23:35:03 +020057 protected $_count_string = 'SELECT COUNT(*) AS ';
58 protected $_random_keyword = ' Random()'; // database specific random keyword
Andrey Andreev00df2e32012-03-02 18:37:16 +020059
Timothy Warren76e04352012-02-14 11:55:17 -050060 // Keeps track of the resource for the current transaction
61 protected $trans;
62
63 /**
64 * Non-persistent database connection
65 *
Timothy Warren7221f942012-02-14 15:02:33 -050066 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -050067 */
Timothy Warren4be822b2012-02-14 12:07:34 -050068 public function db_connect()
Timothy Warren76e04352012-02-14 11:55:17 -050069 {
Timothy Warren3c4281f2012-02-16 19:00:10 -050070 return @ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set);
Timothy Warren76e04352012-02-14 11:55:17 -050071 }
72
73 // --------------------------------------------------------------------
74
75 /**
76 * Persistent database connection
77 *
Timothy Warren7221f942012-02-14 15:02:33 -050078 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -050079 */
Timothy Warren4be822b2012-02-14 12:07:34 -050080 public function db_pconnect()
Timothy Warren76e04352012-02-14 11:55:17 -050081 {
Timothy Warren3c4281f2012-02-16 19:00:10 -050082 return @ibase_pconnect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set);
Timothy Warren76e04352012-02-14 11:55:17 -050083 }
84
85 // --------------------------------------------------------------------
86
87 /**
Andrey Andreev08856b82012-03-03 03:19:28 +020088 * Database version number
Timothy Warren76e04352012-02-14 11:55:17 -050089 *
Timothy Warren7221f942012-02-14 15:02:33 -050090 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -050091 */
Andrey Andreev08856b82012-03-03 03:19:28 +020092 public function version()
Timothy Warren76e04352012-02-14 11:55:17 -050093 {
Andrey Andreev08856b82012-03-03 03:19:28 +020094 if (isset($this->data_cache['version']))
95 {
96 return $this->data_cache['version'];
97 }
98
Timothy Warren3d985a12012-02-15 11:38:00 -050099 if (($service = ibase_service_attach($this->hostname, $this->username, $this->password)))
100 {
Andrey Andreev08856b82012-03-03 03:19:28 +0200101 $this->data_cache['version'] = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
Andrey Andreev00df2e32012-03-02 18:37:16 +0200102
Timothy Warrenab189e12012-02-22 10:34:23 -0500103 // Don't keep the service open
104 ibase_service_detach($service);
Andrey Andreev08856b82012-03-03 03:19:28 +0200105 return $this->data_cache['version'];
Timothy Warren3d985a12012-02-15 11:38:00 -0500106 }
Andrey Andreev00df2e32012-03-02 18:37:16 +0200107
Timothy Warren3d985a12012-02-15 11:38:00 -0500108 return FALSE;
Timothy Warren76e04352012-02-14 11:55:17 -0500109 }
110
111 // --------------------------------------------------------------------
112
113 /**
114 * Execute the query
115 *
Timothy Warren7221f942012-02-14 15:02:33 -0500116 * @param string an SQL query
117 * @return resource
Timothy Warren76e04352012-02-14 11:55:17 -0500118 */
Timothy Warren95562142012-02-20 17:37:21 -0500119 protected function _execute($sql)
Timothy Warren76e04352012-02-14 11:55:17 -0500120 {
Timothy Warren7221f942012-02-14 15:02:33 -0500121 return @ibase_query($this->conn_id, $sql);
Timothy Warren76e04352012-02-14 11:55:17 -0500122 }
123
124 // --------------------------------------------------------------------
125
126 /**
Timothy Warren76e04352012-02-14 11:55:17 -0500127 * Begin Transaction
128 *
Timothy Warren7221f942012-02-14 15:02:33 -0500129 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500130 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500131 public function trans_begin($test_mode = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500132 {
Timothy Warren76e04352012-02-14 11:55:17 -0500133 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreev131772c2012-03-20 23:35:03 +0200134 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Timothy Warren76e04352012-02-14 11:55:17 -0500135 {
136 return TRUE;
137 }
138
139 // Reset the transaction failure flag.
140 // If the $test_mode flag is set to TRUE transactions will be rolled back
141 // even if the queries produce a successful result.
Andrey Andreev131772c2012-03-20 23:35:03 +0200142 $this->_trans_failure = ($test_mode === TRUE);
Timothy Warren76e04352012-02-14 11:55:17 -0500143
Timothy Warren7221f942012-02-14 15:02:33 -0500144 $this->trans = @ibase_trans($this->conn_id);
Andrey Andreev00df2e32012-03-02 18:37:16 +0200145
Timothy Warren76e04352012-02-14 11:55:17 -0500146 return TRUE;
147 }
148
149 // --------------------------------------------------------------------
150
151 /**
152 * Commit Transaction
153 *
Timothy Warren7221f942012-02-14 15:02:33 -0500154 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500155 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500156 public function trans_commit()
Timothy Warren76e04352012-02-14 11:55:17 -0500157 {
Timothy Warren76e04352012-02-14 11:55:17 -0500158 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreev131772c2012-03-20 23:35:03 +0200159 if ( ! $this->trans_enabled OR $this->_trans->depth > 0)
Timothy Warren76e04352012-02-14 11:55:17 -0500160 {
161 return TRUE;
162 }
Andrey Andreev00df2e32012-03-02 18:37:16 +0200163
Timothy Warren2062a862012-02-20 19:38:10 -0500164 return @ibase_commit($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500165 }
166
167 // --------------------------------------------------------------------
168
169 /**
170 * Rollback Transaction
171 *
Timothy Warren7221f942012-02-14 15:02:33 -0500172 * @return bool
Timothy Warren76e04352012-02-14 11:55:17 -0500173 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500174 public function trans_rollback()
Timothy Warren76e04352012-02-14 11:55:17 -0500175 {
Timothy Warren76e04352012-02-14 11:55:17 -0500176 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreev131772c2012-03-20 23:35:03 +0200177 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Timothy Warren76e04352012-02-14 11:55:17 -0500178 {
179 return TRUE;
180 }
181
Timothy Warren2062a862012-02-20 19:38:10 -0500182 return @ibase_rollback($this->trans);
Timothy Warren76e04352012-02-14 11:55:17 -0500183 }
184
185 // --------------------------------------------------------------------
186
187 /**
188 * Escape String
189 *
Timothy Warren7221f942012-02-14 15:02:33 -0500190 * @param string
191 * @param bool whether or not the string will be used in a LIKE condition
192 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500193 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500194 public function escape_str($str, $like = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500195 {
196 if (is_array($str))
197 {
198 foreach ($str as $key => $val)
199 {
200 $str[$key] = $this->escape_str($val, $like);
201 }
202
203 return $str;
204 }
205
206 // escape LIKE condition wildcards
207 if ($like === TRUE)
208 {
Andrey Andreev131772c2012-03-20 23:35:03 +0200209 return str_replace(array($this->_like_escape_chr, '%', '_'),
210 array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
211 $str);
Timothy Warren76e04352012-02-14 11:55:17 -0500212 }
213
214 return $str;
215 }
216
217 // --------------------------------------------------------------------
218
219 /**
220 * Affected Rows
221 *
Andrey Andreev131772c2012-03-20 23:35:03 +0200222 * @return int
Timothy Warren76e04352012-02-14 11:55:17 -0500223 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500224 public function affected_rows()
Timothy Warren76e04352012-02-14 11:55:17 -0500225 {
Timothy Warren7221f942012-02-14 15:02:33 -0500226 return @ibase_affected_rows($this->conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500227 }
228
229 // --------------------------------------------------------------------
230
231 /**
232 * Insert ID
233 *
Andrey Andreev131772c2012-03-20 23:35:03 +0200234 * @param string $generator_name
235 * @param int $inc_by
236 * @return int
Timothy Warren76e04352012-02-14 11:55:17 -0500237 */
Timothy Warren817af192012-02-16 08:28:00 -0500238 public function insert_id($generator_name, $inc_by=0)
Timothy Warren76e04352012-02-14 11:55:17 -0500239 {
Timothy Warren07b660b2012-02-20 13:23:06 -0500240 //If a generator hasn't been used before it will return 0
Timothy Warrenfed2d1d2012-02-20 15:42:45 -0500241 return ibase_gen_id('"'.$generator_name.'"', $inc_by);
Timothy Warren76e04352012-02-14 11:55:17 -0500242 }
243
244 // --------------------------------------------------------------------
245
246 /**
247 * "Count All" query
248 *
249 * Generates a platform-specific query string that counts all records in
250 * the specified database
251 *
Timothy Warren7221f942012-02-14 15:02:33 -0500252 * @param string
253 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500254 */
Timothy Warren4be822b2012-02-14 12:07:34 -0500255 public function count_all($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500256 {
257 if ($table == '')
258 {
259 return 0;
260 }
261
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200262 $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
Timothy Warren76e04352012-02-14 11:55:17 -0500263 if ($query->num_rows() == 0)
264 {
265 return 0;
266 }
267
Andrey Andreev131772c2012-03-20 23:35:03 +0200268 $query = $query->row();
Timothy Warren76e04352012-02-14 11:55:17 -0500269 $this->_reset_select();
Andrey Andreev131772c2012-03-20 23:35:03 +0200270 return (int) $query->numrows;
Timothy Warren76e04352012-02-14 11:55:17 -0500271 }
272
273 // --------------------------------------------------------------------
274
275 /**
276 * List table query
277 *
278 * Generates a platform-specific query string so that the table names can be fetched
279 *
Andrey Andreev131772c2012-03-20 23:35:03 +0200280 * @param bool
Timothy Warren7221f942012-02-14 15:02:33 -0500281 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500282 */
Timothy Warren95562142012-02-20 17:37:21 -0500283 protected function _list_tables($prefix_limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500284 {
Andrey Andreev60c9c992012-03-20 23:46:09 +0200285 $sql = 'SELECT "RDB$RELATION_NAME" FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\'';
Timothy Warren76e04352012-02-14 11:55:17 -0500286
Andrey Andreev131772c2012-03-20 23:35:03 +0200287 if ($prefix_limit !== FALSE && $this->dbprefix != '')
Timothy Warren76e04352012-02-14 11:55:17 -0500288 {
Andrey Andreev131772c2012-03-20 23:35:03 +0200289 return $sql.' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Timothy Warren76e04352012-02-14 11:55:17 -0500290 }
Andrey Andreev131772c2012-03-20 23:35:03 +0200291
Timothy Warren76e04352012-02-14 11:55:17 -0500292 return $sql;
293 }
294
295 // --------------------------------------------------------------------
296
297 /**
298 * Show column query
299 *
300 * Generates a platform-specific query string so that the column names can be fetched
301 *
Timothy Warren7221f942012-02-14 15:02:33 -0500302 * @param string the table name
303 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500304 */
Timothy Warren95562142012-02-20 17:37:21 -0500305 protected function _list_columns($table = '')
Timothy Warren76e04352012-02-14 11:55:17 -0500306 {
Andrey Andreev131772c2012-03-20 23:35:03 +0200307 return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = \''.$this->escape_str($table)."'";
Timothy Warren76e04352012-02-14 11:55:17 -0500308 }
309
310 // --------------------------------------------------------------------
311
312 /**
313 * Field data query
314 *
315 * Generates a platform-specific query so that the column data can be retrieved
316 *
Timothy Warren7221f942012-02-14 15:02:33 -0500317 * @param string the table name
Andrey Andreev131772c2012-03-20 23:35:03 +0200318 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500319 */
Timothy Warren95562142012-02-20 17:37:21 -0500320 protected function _field_data($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500321 {
Timothy Warren8be31a92012-02-15 11:48:57 -0500322 // Need to find a more efficient way to do this
Andrey Andreev00df2e32012-03-02 18:37:16 +0200323 // but Interbase/Firebird seems to lack the
Timothy Warren8be31a92012-02-15 11:48:57 -0500324 // limit clause
Andrey Andreev131772c2012-03-20 23:35:03 +0200325 return 'SELECT * FROM '.$table;
Timothy Warren76e04352012-02-14 11:55:17 -0500326 }
327
328 // --------------------------------------------------------------------
329
330 /**
Andrey Andreev00df2e32012-03-02 18:37:16 +0200331 * Error
Timothy Warren76e04352012-02-14 11:55:17 -0500332 *
Andrey Andreev00df2e32012-03-02 18:37:16 +0200333 * Returns an array containing code and message of the last
334 * database error that has occured.
Timothy Warren76e04352012-02-14 11:55:17 -0500335 *
Andrey Andreev00df2e32012-03-02 18:37:16 +0200336 * @return array
Timothy Warren76e04352012-02-14 11:55:17 -0500337 */
Andrey Andreev00df2e32012-03-02 18:37:16 +0200338 public function error()
Timothy Warren76e04352012-02-14 11:55:17 -0500339 {
Andrey Andreev00df2e32012-03-02 18:37:16 +0200340 return array('code' => ibase_errcode(), 'message' => ibase_errmsg());
Timothy Warren76e04352012-02-14 11:55:17 -0500341 }
342
343 // --------------------------------------------------------------------
344
345 /**
Timothy Warren76e04352012-02-14 11:55:17 -0500346 * From Tables
347 *
Timothy Warren4be822b2012-02-14 12:07:34 -0500348 * This public function implicitly groups FROM tables so there is no confusion
Timothy Warren76e04352012-02-14 11:55:17 -0500349 * about operator precedence in harmony with SQL standards
350 *
Andrey Andreev131772c2012-03-20 23:35:03 +0200351 * @param array
352 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500353 */
Timothy Warren95562142012-02-20 17:37:21 -0500354 protected function _from_tables($tables)
Timothy Warren76e04352012-02-14 11:55:17 -0500355 {
356 if ( ! is_array($tables))
357 {
358 $tables = array($tables);
359 }
360
Timothy Warren817af192012-02-16 08:28:00 -0500361 //Interbase/Firebird doesn't like grouped tables
Timothy Warrend19e47a2012-02-14 23:40:40 -0500362 return implode(', ', $tables);
Timothy Warren76e04352012-02-14 11:55:17 -0500363 }
364
365 // --------------------------------------------------------------------
366
367 /**
Timothy Warren76e04352012-02-14 11:55:17 -0500368 * Update statement
369 *
370 * Generates a platform-specific update string from the supplied data
371 *
Timothy Warren7221f942012-02-14 15:02:33 -0500372 * @param string the table name
373 * @param array the update data
374 * @param array the where clause
375 * @param array the orderby clause
Andrey Andreev00541ae2012-04-09 11:43:10 +0300376 * @param array the limit clause (ignored)
377 * @param array the like clause
Timothy Warren7221f942012-02-14 15:02:33 -0500378 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500379 */
Andrey Andreev00541ae2012-04-09 11:43:10 +0300380 protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array())
Timothy Warren76e04352012-02-14 11:55:17 -0500381 {
382 foreach ($values as $key => $val)
383 {
Andrey Andreev131772c2012-03-20 23:35:03 +0200384 $valstr[] = $key.' = '.$val;
Timothy Warren76e04352012-02-14 11:55:17 -0500385 }
386
Andrey Andreev00541ae2012-04-09 11:43:10 +0300387 $where = empty($where) ? '' : ' WHERE '.implode(' ', $where);
388
389 if ( ! empty($like))
390 {
391 $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like);
392 }
Timothy Warren76e04352012-02-14 11:55:17 -0500393
Andrey Andreev131772c2012-03-20 23:35:03 +0200394 return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
Andrey Andreev00541ae2012-04-09 11:43:10 +0300395 .$where
Andrey Andreev131772c2012-03-20 23:35:03 +0200396 .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '');
Timothy Warren76e04352012-02-14 11:55:17 -0500397 }
398
399
400 // --------------------------------------------------------------------
401
402 /**
403 * Truncate statement
404 *
405 * Generates a platform-specific truncate string from the supplied data
Andrey Andreeva6fe36e2012-04-05 16:00:32 +0300406 *
407 * If the database does not support the truncate() command,
408 * then this method maps to 'DELETE FROM table'
Timothy Warren76e04352012-02-14 11:55:17 -0500409 *
Timothy Warren7221f942012-02-14 15:02:33 -0500410 * @param string the table name
411 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500412 */
Timothy Warren95562142012-02-20 17:37:21 -0500413 protected function _truncate($table)
Timothy Warren76e04352012-02-14 11:55:17 -0500414 {
Andrey Andreeva6fe36e2012-04-05 16:00:32 +0300415 return 'DELETE FROM '.$table;
Timothy Warren76e04352012-02-14 11:55:17 -0500416 }
417
418 // --------------------------------------------------------------------
419
420 /**
421 * Delete statement
422 *
423 * Generates a platform-specific delete string from the supplied data
424 *
Timothy Warren7221f942012-02-14 15:02:33 -0500425 * @param string the table name
426 * @param array the where clause
Andrey Andreevc01d3162012-04-09 12:55:11 +0300427 * @param array the like clause
Andrey Andreeva2548362012-04-09 13:03:11 +0300428 * @param string the limit clause (ignored)
Timothy Warren7221f942012-02-14 15:02:33 -0500429 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500430 */
Andrey Andreeva2548362012-04-09 13:03:11 +0300431 protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Timothy Warren76e04352012-02-14 11:55:17 -0500432 {
Andrey Andreevc01d3162012-04-09 12:55:11 +0300433 $conditions = array();
Timothy Warren76e04352012-02-14 11:55:17 -0500434
Andrey Andreevc01d3162012-04-09 12:55:11 +0300435 empty($where) OR $conditions[] = implode(' ', $where);
436 empty($like) OR $conditions[] = implode(' ', $like);
Timothy Warren76e04352012-02-14 11:55:17 -0500437
Andrey Andreevc01d3162012-04-09 12:55:11 +0300438 return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : '');
Timothy Warren76e04352012-02-14 11:55:17 -0500439 }
440
441 // --------------------------------------------------------------------
442
443 /**
444 * Limit string
445 *
446 * Generates a platform-specific LIMIT clause
447 *
Timothy Warren7221f942012-02-14 15:02:33 -0500448 * @param string the sql query string
Andrey Andreev131772c2012-03-20 23:35:03 +0200449 * @param int the number of rows to limit the query to
450 * @param int the offset value
Timothy Warren7221f942012-02-14 15:02:33 -0500451 * @return string
Timothy Warren76e04352012-02-14 11:55:17 -0500452 */
Timothy Warren95562142012-02-20 17:37:21 -0500453 protected function _limit($sql, $limit, $offset)
Timothy Warren76e04352012-02-14 11:55:17 -0500454 {
Timothy Warren56784f62012-02-29 11:58:20 -0500455 // Limit clause depends on if Interbase or Firebird
Andrey Andreev08856b82012-03-03 03:19:28 +0200456 if (stripos($this->version(), 'firebird') !== FALSE)
Timothy Warren56784f62012-02-29 11:58:20 -0500457 {
Andrey Andreev131772c2012-03-20 23:35:03 +0200458 $select = 'FIRST '. (int) $limit
459 .($offset > 0 ? ' SKIP '. (int) $offset : '');
Timothy Warren56784f62012-02-29 11:58:20 -0500460 }
461 else
462 {
Andrey Andreev131772c2012-03-20 23:35:03 +0200463 $select = 'ROWS '
464 .($offset > 0 ? (int) $offset.' TO '.($limit + $offset) : (int) $limit);
Timothy Warren56784f62012-02-29 11:58:20 -0500465 }
Andrey Andreev00df2e32012-03-02 18:37:16 +0200466
Andrey Andreev131772c2012-03-20 23:35:03 +0200467 return preg_replace('`SELECT`i', 'SELECT '.$select, $sql);
Timothy Warren76e04352012-02-14 11:55:17 -0500468 }
469
470 // --------------------------------------------------------------------
471
472 /**
473 * Close DB Connection
474 *
Timothy Warren7221f942012-02-14 15:02:33 -0500475 * @param resource
476 * @return void
Timothy Warren76e04352012-02-14 11:55:17 -0500477 */
Timothy Warren95562142012-02-20 17:37:21 -0500478 protected function _close($conn_id)
Timothy Warren76e04352012-02-14 11:55:17 -0500479 {
Timothy Warren7221f942012-02-14 15:02:33 -0500480 @ibase_close($conn_id);
Timothy Warren76e04352012-02-14 11:55:17 -0500481 }
Andrey Andreev00df2e32012-03-02 18:37:16 +0200482
Timothy Warren76e04352012-02-14 11:55:17 -0500483}
484
Timothy Warren76e04352012-02-14 11:55:17 -0500485/* End of file interbase_driver.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400486/* Location: ./system/database/drivers/interbase/interbase_driver.php */