Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 6 | * |
| 7 | * NOTICE OF LICENSE |
Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 8 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Timothy Warren | 817af19 | 2012-02-16 08:28:00 -0500 | [diff] [blame] | 10 | * |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 11 | * 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 Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 17 | * licensing@ellislab.com so we can send you a copy immediately. |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 18 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 19 | * @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 Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 26 | */ |
| 27 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 28 | /** |
| 29 | * Firebird/Interbase Database Adapter Class |
| 30 | * |
| 31 | * Note: _DB is an extender class that the app controller |
Jamie Rumbelow | ffe7a0a | 2012-04-26 13:48:18 +0100 | [diff] [blame] | 32 | * creates dynamically based on whether the query builder |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 33 | * class is being used or not. |
| 34 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 35 | * @package CodeIgniter |
| 36 | * @subpackage Drivers |
| 37 | * @category Database |
| 38 | * @author EllisLab Dev Team |
| 39 | * @link http://codeigniter.com/user_guide/database/ |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 40 | */ |
Andrey Andreev | 2608687 | 2012-07-05 11:21:58 +0300 | [diff] [blame] | 41 | class CI_DB_ibase_driver extends CI_DB { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 42 | |
Andrey Andreev | 2608687 | 2012-07-05 11:21:58 +0300 | [diff] [blame] | 43 | public $dbdriver = 'ibase'; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 44 | |
| 45 | // The character used to escape with |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 46 | protected $_escape_char = '"'; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 47 | |
| 48 | // clause and character used for LIKE escape sequences |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 49 | protected $_like_escape_str = " ESCAPE '%s' "; |
| 50 | protected $_like_escape_chr = '!'; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 51 | |
Andrey Andreev | 77a5d94 | 2012-07-05 15:42:14 +0300 | [diff] [blame] | 52 | protected $_random_keyword = ' Random()'; // database specific random keyword |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 53 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 54 | // Keeps track of the resource for the current transaction |
| 55 | protected $trans; |
| 56 | |
| 57 | /** |
| 58 | * Non-persistent database connection |
| 59 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 60 | * @return resource |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 61 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 62 | public function db_connect() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 63 | { |
Timothy Warren | 3c4281f | 2012-02-16 19:00:10 -0500 | [diff] [blame] | 64 | return @ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | // -------------------------------------------------------------------- |
| 68 | |
| 69 | /** |
| 70 | * Persistent database connection |
| 71 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 72 | * @return resource |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 73 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 74 | public function db_pconnect() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 75 | { |
Timothy Warren | 3c4281f | 2012-02-16 19:00:10 -0500 | [diff] [blame] | 76 | return @ibase_pconnect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // -------------------------------------------------------------------- |
| 80 | |
| 81 | /** |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 82 | * Database version number |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 83 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 84 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 85 | */ |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 86 | public function version() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 87 | { |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 88 | if (isset($this->data_cache['version'])) |
| 89 | { |
| 90 | return $this->data_cache['version']; |
| 91 | } |
| 92 | |
Timothy Warren | 3d985a1 | 2012-02-15 11:38:00 -0500 | [diff] [blame] | 93 | if (($service = ibase_service_attach($this->hostname, $this->username, $this->password))) |
| 94 | { |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 95 | $this->data_cache['version'] = ibase_server_info($service, IBASE_SVC_SERVER_VERSION); |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 96 | |
Timothy Warren | ab189e1 | 2012-02-22 10:34:23 -0500 | [diff] [blame] | 97 | // Don't keep the service open |
| 98 | ibase_service_detach($service); |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 99 | return $this->data_cache['version']; |
Timothy Warren | 3d985a1 | 2012-02-15 11:38:00 -0500 | [diff] [blame] | 100 | } |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 101 | |
Timothy Warren | 3d985a1 | 2012-02-15 11:38:00 -0500 | [diff] [blame] | 102 | return FALSE; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // -------------------------------------------------------------------- |
| 106 | |
| 107 | /** |
| 108 | * Execute the query |
| 109 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 110 | * @param string an SQL query |
| 111 | * @return resource |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 112 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 113 | protected function _execute($sql) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 114 | { |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 115 | return @ibase_query($this->conn_id, $sql); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | // -------------------------------------------------------------------- |
| 119 | |
| 120 | /** |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 121 | * Begin Transaction |
| 122 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 123 | * @return bool |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 124 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 125 | public function trans_begin($test_mode = FALSE) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 126 | { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 127 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 128 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 129 | { |
| 130 | return TRUE; |
| 131 | } |
| 132 | |
| 133 | // Reset the transaction failure flag. |
| 134 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 135 | // even if the queries produce a successful result. |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 136 | $this->_trans_failure = ($test_mode === TRUE); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 137 | |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 138 | $this->trans = @ibase_trans($this->conn_id); |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 139 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 140 | return TRUE; |
| 141 | } |
| 142 | |
| 143 | // -------------------------------------------------------------------- |
| 144 | |
| 145 | /** |
| 146 | * Commit Transaction |
| 147 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 148 | * @return bool |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 149 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 150 | public function trans_commit() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 151 | { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 152 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 153 | if ( ! $this->trans_enabled OR $this->_trans->depth > 0) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 154 | { |
| 155 | return TRUE; |
| 156 | } |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 157 | |
Timothy Warren | 2062a86 | 2012-02-20 19:38:10 -0500 | [diff] [blame] | 158 | return @ibase_commit($this->trans); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | // -------------------------------------------------------------------- |
| 162 | |
| 163 | /** |
| 164 | * Rollback Transaction |
| 165 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 166 | * @return bool |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 167 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 168 | public function trans_rollback() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 169 | { |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 170 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 171 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 172 | { |
| 173 | return TRUE; |
| 174 | } |
| 175 | |
Timothy Warren | 2062a86 | 2012-02-20 19:38:10 -0500 | [diff] [blame] | 176 | return @ibase_rollback($this->trans); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // -------------------------------------------------------------------- |
| 180 | |
| 181 | /** |
| 182 | * Escape String |
| 183 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 184 | * @param string |
| 185 | * @param bool whether or not the string will be used in a LIKE condition |
| 186 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 187 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 188 | public function escape_str($str, $like = FALSE) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 189 | { |
| 190 | if (is_array($str)) |
| 191 | { |
| 192 | foreach ($str as $key => $val) |
| 193 | { |
| 194 | $str[$key] = $this->escape_str($val, $like); |
| 195 | } |
| 196 | |
| 197 | return $str; |
| 198 | } |
| 199 | |
| 200 | // escape LIKE condition wildcards |
| 201 | if ($like === TRUE) |
| 202 | { |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 203 | return str_replace(array($this->_like_escape_chr, '%', '_'), |
| 204 | array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), |
| 205 | $str); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | return $str; |
| 209 | } |
| 210 | |
| 211 | // -------------------------------------------------------------------- |
| 212 | |
| 213 | /** |
| 214 | * Affected Rows |
| 215 | * |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 216 | * @return int |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 217 | */ |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 218 | public function affected_rows() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 219 | { |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 220 | return @ibase_affected_rows($this->conn_id); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | // -------------------------------------------------------------------- |
| 224 | |
| 225 | /** |
| 226 | * Insert ID |
| 227 | * |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 228 | * @param string $generator_name |
| 229 | * @param int $inc_by |
| 230 | * @return int |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 231 | */ |
Andrey Andreev | 5382b1b | 2012-06-25 01:26:48 +0300 | [diff] [blame] | 232 | public function insert_id($generator_name, $inc_by = 0) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 233 | { |
Timothy Warren | 07b660b | 2012-02-20 13:23:06 -0500 | [diff] [blame] | 234 | //If a generator hasn't been used before it will return 0 |
Timothy Warren | fed2d1d | 2012-02-20 15:42:45 -0500 | [diff] [blame] | 235 | return ibase_gen_id('"'.$generator_name.'"', $inc_by); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | // -------------------------------------------------------------------- |
| 239 | |
| 240 | /** |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 241 | * List table query |
| 242 | * |
| 243 | * Generates a platform-specific query string so that the table names can be fetched |
| 244 | * |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 245 | * @param bool |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 246 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 247 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 248 | protected function _list_tables($prefix_limit = FALSE) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 249 | { |
Andrey Andreev | 60c9c99 | 2012-03-20 23:46:09 +0200 | [diff] [blame] | 250 | $sql = 'SELECT "RDB$RELATION_NAME" FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\''; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 251 | |
Alex Bilbie | 48a2baf | 2012-06-02 11:09:54 +0100 | [diff] [blame] | 252 | if ($prefix_limit !== FALSE && $this->dbprefix !== '') |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 253 | { |
Andrey Andreev | 5382b1b | 2012-06-25 01:26:48 +0300 | [diff] [blame] | 254 | return $sql.' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' " |
| 255 | .sprintf($this->_like_escape_str, $this->_like_escape_chr); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 256 | } |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 257 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 258 | return $sql; |
| 259 | } |
| 260 | |
| 261 | // -------------------------------------------------------------------- |
| 262 | |
| 263 | /** |
| 264 | * Show column query |
| 265 | * |
| 266 | * Generates a platform-specific query string so that the column names can be fetched |
| 267 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 268 | * @param string the table name |
| 269 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 270 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 271 | protected function _list_columns($table = '') |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 272 | { |
Andrey Andreev | 5382b1b | 2012-06-25 01:26:48 +0300 | [diff] [blame] | 273 | return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | // -------------------------------------------------------------------- |
| 277 | |
| 278 | /** |
| 279 | * Field data query |
| 280 | * |
| 281 | * Generates a platform-specific query so that the column data can be retrieved |
| 282 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 283 | * @param string the table name |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 284 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 285 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 286 | protected function _field_data($table) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 287 | { |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame^] | 288 | $this->qb_limit = 1; |
| 289 | $sql = $this->_limit('SELECT * FROM '.$this->protect_identifiers($table)); |
| 290 | $this->qb_limit = 0; |
| 291 | return $sql; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | // -------------------------------------------------------------------- |
| 295 | |
| 296 | /** |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 297 | * Error |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 298 | * |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 299 | * Returns an array containing code and message of the last |
| 300 | * database error that has occured. |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 301 | * |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 302 | * @return array |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 303 | */ |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 304 | public function error() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 305 | { |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 306 | return array('code' => ibase_errcode(), 'message' => ibase_errmsg()); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // -------------------------------------------------------------------- |
| 310 | |
| 311 | /** |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 312 | * From Tables |
| 313 | * |
Timothy Warren | 4be822b | 2012-02-14 12:07:34 -0500 | [diff] [blame] | 314 | * This public function implicitly groups FROM tables so there is no confusion |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 315 | * about operator precedence in harmony with SQL standards |
| 316 | * |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 317 | * @param array |
| 318 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 319 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 320 | protected function _from_tables($tables) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 321 | { |
Andrey Andreev | c78e56a | 2012-06-08 02:12:07 +0300 | [diff] [blame] | 322 | return is_array($tables) ? implode(', ', $tables) : $tables; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // -------------------------------------------------------------------- |
| 326 | |
| 327 | /** |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 328 | * Update statement |
| 329 | * |
| 330 | * Generates a platform-specific update string from the supplied data |
| 331 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 332 | * @param string the table name |
| 333 | * @param array the update data |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 334 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 335 | */ |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 336 | protected function _update($table, $values) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 337 | { |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 338 | $this->qb_limit = FALSE; |
| 339 | return parent::_update($table, $values); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 340 | } |
| 341 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 342 | // -------------------------------------------------------------------- |
| 343 | |
| 344 | /** |
| 345 | * Truncate statement |
| 346 | * |
| 347 | * Generates a platform-specific truncate string from the supplied data |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 348 | * |
| 349 | * If the database does not support the truncate() command, |
| 350 | * then this method maps to 'DELETE FROM table' |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 351 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 352 | * @param string the table name |
| 353 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 354 | */ |
Timothy Warren | 9556214 | 2012-02-20 17:37:21 -0500 | [diff] [blame] | 355 | protected function _truncate($table) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 356 | { |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 357 | return 'DELETE FROM '.$table; |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | // -------------------------------------------------------------------- |
| 361 | |
| 362 | /** |
| 363 | * Delete statement |
| 364 | * |
| 365 | * Generates a platform-specific delete string from the supplied data |
| 366 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 367 | * @param string the table name |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 368 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 369 | */ |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 370 | protected function _delete($table) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 371 | { |
Andrey Andreev | b047865 | 2012-07-18 15:34:46 +0300 | [diff] [blame] | 372 | $this->qb_limit = FALSE; |
| 373 | return parent::_delete($table); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | // -------------------------------------------------------------------- |
| 377 | |
| 378 | /** |
| 379 | * Limit string |
| 380 | * |
| 381 | * Generates a platform-specific LIMIT clause |
| 382 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 383 | * @param string the sql query string |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 384 | * @return string |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 385 | */ |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame^] | 386 | protected function _limit($sql) |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 387 | { |
Timothy Warren | 56784f6 | 2012-02-29 11:58:20 -0500 | [diff] [blame] | 388 | // Limit clause depends on if Interbase or Firebird |
Andrey Andreev | 08856b8 | 2012-03-03 03:19:28 +0200 | [diff] [blame] | 389 | if (stripos($this->version(), 'firebird') !== FALSE) |
Timothy Warren | 56784f6 | 2012-02-29 11:58:20 -0500 | [diff] [blame] | 390 | { |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame^] | 391 | $select = 'FIRST '.$this->qb_limit |
| 392 | .($this->qb_offset ? ' SKIP '.$this->qb_offset : ''); |
Timothy Warren | 56784f6 | 2012-02-29 11:58:20 -0500 | [diff] [blame] | 393 | } |
| 394 | else |
| 395 | { |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 396 | $select = 'ROWS ' |
Andrey Andreev | c9b924c | 2012-07-19 13:06:02 +0300 | [diff] [blame^] | 397 | .($this->qb_offset ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit); |
Timothy Warren | 56784f6 | 2012-02-29 11:58:20 -0500 | [diff] [blame] | 398 | } |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 399 | |
Andrey Andreev | 131772c | 2012-03-20 23:35:03 +0200 | [diff] [blame] | 400 | return preg_replace('`SELECT`i', 'SELECT '.$select, $sql); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | // -------------------------------------------------------------------- |
| 404 | |
| 405 | /** |
| 406 | * Close DB Connection |
| 407 | * |
Timothy Warren | 7221f94 | 2012-02-14 15:02:33 -0500 | [diff] [blame] | 408 | * @return void |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 409 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 410 | protected function _close() |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 411 | { |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 412 | @ibase_close($this->conn_id); |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 413 | } |
Andrey Andreev | 00df2e3 | 2012-03-02 18:37:16 +0200 | [diff] [blame] | 414 | |
Timothy Warren | 76e0435 | 2012-02-14 11:55:17 -0500 | [diff] [blame] | 415 | } |
| 416 | |
Andrey Andreev | 2608687 | 2012-07-05 11:21:58 +0300 | [diff] [blame] | 417 | /* End of file ibase_driver.php */ |
| 418 | /* Location: ./system/database/drivers/ibase/ibase_driver.php */ |