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