Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [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 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -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 |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Greg Aker | 0defe5d | 2012-01-01 18:46:41 -0600 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | /** |
| 29 | * ODBC Database Adapter Class |
| 30 | * |
| 31 | * Note: _DB is an extender class that the app controller |
Jamie Rumbelow | 7efad20 | 2012-02-19 12:37:00 +0000 | [diff] [blame] | 32 | * creates dynamically based on whether the query builder |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 33 | * class is being used or not. |
| 34 | * |
| 35 | * @package CodeIgniter |
| 36 | * @subpackage Drivers |
| 37 | * @category Database |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 38 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | * @link http://codeigniter.com/user_guide/database/ |
| 40 | */ |
| 41 | class CI_DB_odbc_driver extends CI_DB { |
| 42 | |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 43 | public $dbdriver = 'odbc'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 44 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 45 | // the character used to excape - not necessary for ODBC |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 46 | protected $_escape_char = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 47 | |
Andrey Andreev | 5f356bf | 2012-03-20 14:32:27 +0200 | [diff] [blame] | 48 | protected $_like_escape_str = " {escape '%s'} "; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 49 | |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 50 | protected $_random_keyword; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 51 | |
Andrey Andreev | 5f356bf | 2012-03-20 14:32:27 +0200 | [diff] [blame] | 52 | public function __construct($params) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | { |
Timothy Warren | a2097a0 | 2011-10-10 10:10:46 -0400 | [diff] [blame] | 54 | parent::__construct($params); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 55 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 56 | $this->_random_keyword = ' RND('.time().')'; // database specific random keyword |
Andrey Andreev | 46f6dbc | 2012-02-13 01:39:53 +0200 | [diff] [blame] | 57 | |
| 58 | // Legacy support for DSN in the hostname field |
Andrey Andreev | e4c3019 | 2012-06-04 15:08:24 +0300 | [diff] [blame] | 59 | if (empty($this->dsn)) |
Andrey Andreev | 46f6dbc | 2012-02-13 01:39:53 +0200 | [diff] [blame] | 60 | { |
| 61 | $this->dsn = $this->hostname; |
| 62 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Non-persistent database connection |
| 67 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 68 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 69 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 70 | public function db_connect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 71 | { |
Andrey Andreev | 46f6dbc | 2012-02-13 01:39:53 +0200 | [diff] [blame] | 72 | return @odbc_connect($this->dsn, $this->username, $this->password); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 73 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 74 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 75 | // -------------------------------------------------------------------- |
| 76 | |
| 77 | /** |
| 78 | * Persistent database connection |
| 79 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 80 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 81 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 82 | public function db_pconnect() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 83 | { |
Andrey Andreev | 46f6dbc | 2012-02-13 01:39:53 +0200 | [diff] [blame] | 84 | return @odbc_pconnect($this->dsn, $this->username, $this->password); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 85 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 86 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 87 | // -------------------------------------------------------------------- |
| 88 | |
| 89 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 90 | * Execute the query |
| 91 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 92 | * @param string an SQL query |
| 93 | * @return resource |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 94 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 95 | protected function _execute($sql) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 96 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 97 | return @odbc_exec($this->conn_id, $sql); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | // -------------------------------------------------------------------- |
| 101 | |
| 102 | /** |
| 103 | * Begin Transaction |
| 104 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 105 | * @return bool |
| 106 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 107 | public function trans_begin($test_mode = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 108 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 109 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 110 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 111 | { |
| 112 | return TRUE; |
| 113 | } |
| 114 | |
| 115 | // Reset the transaction failure flag. |
| 116 | // If the $test_mode flag is set to TRUE transactions will be rolled back |
| 117 | // even if the queries produce a successful result. |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 118 | $this->_trans_failure = ($test_mode === TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 119 | |
| 120 | return odbc_autocommit($this->conn_id, FALSE); |
| 121 | } |
| 122 | |
| 123 | // -------------------------------------------------------------------- |
| 124 | |
| 125 | /** |
| 126 | * Commit Transaction |
| 127 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 128 | * @return bool |
| 129 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 130 | public function trans_commit() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 131 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 132 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 133 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 134 | { |
| 135 | return TRUE; |
| 136 | } |
| 137 | |
| 138 | $ret = odbc_commit($this->conn_id); |
| 139 | odbc_autocommit($this->conn_id, TRUE); |
| 140 | return $ret; |
| 141 | } |
| 142 | |
| 143 | // -------------------------------------------------------------------- |
| 144 | |
| 145 | /** |
| 146 | * Rollback Transaction |
| 147 | * |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 148 | * @return bool |
| 149 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 150 | public function trans_rollback() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 151 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 152 | // When transactions are nested we only begin/commit/rollback the outermost ones |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 153 | if ( ! $this->trans_enabled OR $this->_trans_depth > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 154 | { |
| 155 | return TRUE; |
| 156 | } |
| 157 | |
| 158 | $ret = odbc_rollback($this->conn_id); |
| 159 | odbc_autocommit($this->conn_id, TRUE); |
| 160 | return $ret; |
| 161 | } |
| 162 | |
| 163 | // -------------------------------------------------------------------- |
| 164 | |
| 165 | /** |
| 166 | * Escape String |
| 167 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | * @param string |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 169 | * @param bool whether or not the string will be used in a LIKE condition |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 170 | * @return string |
| 171 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 172 | public function escape_str($str, $like = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 173 | { |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 174 | if (is_array($str)) |
| 175 | { |
Pascal Kriete | c3a4a8d | 2011-02-14 13:40:08 -0500 | [diff] [blame] | 176 | foreach ($str as $key => $val) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 177 | { |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 178 | $str[$key] = $this->escape_str($val, $like); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | return $str; |
| 182 | } |
| 183 | |
Greg Aker | 757dda6 | 2010-04-14 19:06:19 -0500 | [diff] [blame] | 184 | $str = remove_invisible_characters($str); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 185 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 186 | // escape LIKE condition wildcards |
| 187 | if ($like === TRUE) |
| 188 | { |
Andrey Andreev | 5e18e89 | 2012-03-09 14:25:00 +0200 | [diff] [blame] | 189 | return str_replace(array($this->_like_escape_chr, '%', '_'), |
| 190 | array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'), |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 191 | $str); |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 192 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 193 | |
Derek Jones | e4ed583 | 2009-02-20 21:44:59 +0000 | [diff] [blame] | 194 | return $str; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 195 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 196 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 197 | // -------------------------------------------------------------------- |
| 198 | |
| 199 | /** |
| 200 | * Affected Rows |
| 201 | * |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 202 | * @return int |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 204 | public function affected_rows() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 205 | { |
| 206 | return @odbc_num_rows($this->conn_id); |
| 207 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 208 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 209 | // -------------------------------------------------------------------- |
| 210 | |
| 211 | /** |
| 212 | * Insert ID |
| 213 | * |
Andrey Andreev | 8af7666 | 2012-03-05 14:33:41 +0200 | [diff] [blame] | 214 | * @return bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 215 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 216 | public function insert_id() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 217 | { |
Andrey Andreev | 8af7666 | 2012-03-05 14:33:41 +0200 | [diff] [blame] | 218 | return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | // -------------------------------------------------------------------- |
| 222 | |
| 223 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 224 | * Show table query |
| 225 | * |
| 226 | * Generates a platform-specific query string so that the table names can be fetched |
| 227 | * |
Andrey Andreev | 5f356bf | 2012-03-20 14:32:27 +0200 | [diff] [blame] | 228 | * @param bool |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 229 | * @return string |
| 230 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 231 | protected function _list_tables($prefix_limit = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 232 | { |
Andrey Andreev | e4c3019 | 2012-06-04 15:08:24 +0300 | [diff] [blame] | 233 | $sql = 'SHOW TABLES FROM '.$this->database; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 234 | |
Andrey Andreev | e4c3019 | 2012-06-04 15:08:24 +0300 | [diff] [blame] | 235 | if ($prefix_limit !== FALSE && $this->dbprefix !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 236 | { |
Greg Aker | 0d42489 | 2010-01-26 02:14:44 +0000 | [diff] [blame] | 237 | //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 238 | return FALSE; // not currently supported |
| 239 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 240 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 241 | return $sql; |
| 242 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 243 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 244 | // -------------------------------------------------------------------- |
| 245 | |
| 246 | /** |
| 247 | * Show column query |
| 248 | * |
| 249 | * Generates a platform-specific query string so that the column names can be fetched |
| 250 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | * @param string the table name |
| 252 | * @return string |
| 253 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 254 | protected function _list_columns($table = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 255 | { |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 256 | return 'SHOW COLUMNS FROM '.$table; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | // -------------------------------------------------------------------- |
| 260 | |
| 261 | /** |
| 262 | * Field data query |
| 263 | * |
| 264 | * Generates a platform-specific query so that the column data can be retrieved |
| 265 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 266 | * @param string the table name |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 267 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 268 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 269 | protected function _field_data($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | { |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 271 | return 'SELECT TOP 1 FROM '.$table; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | // -------------------------------------------------------------------- |
| 275 | |
| 276 | /** |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 277 | * Error |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 278 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 279 | * Returns an array containing code and message of the last |
| 280 | * database error that has occured. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 281 | * |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 282 | * @return array |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 283 | */ |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 284 | public function error() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 285 | { |
Andrey Andreev | 4be5de1 | 2012-03-02 15:45:41 +0200 | [diff] [blame] | 286 | return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // -------------------------------------------------------------------- |
| 290 | |
| 291 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | * From Tables |
| 293 | * |
| 294 | * This function implicitly groups FROM tables so there is no confusion |
| 295 | * about operator precedence in harmony with SQL standards |
| 296 | * |
Andrey Andreev | 5f356bf | 2012-03-20 14:32:27 +0200 | [diff] [blame] | 297 | * @param array |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 298 | * @return string |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 299 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 300 | protected function _from_tables($tables) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 301 | { |
Andrey Andreev | c78e56a | 2012-06-08 02:12:07 +0300 | [diff] [blame] | 302 | return is_array($tables) ? implode(', ', $tables) : $tables; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 306 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 308 | * Truncate statement |
| 309 | * |
| 310 | * Generates a platform-specific truncate string from the supplied data |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 311 | * |
| 312 | * If the database does not support the truncate() command, |
| 313 | * then this method maps to 'DELETE FROM table' |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 314 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 315 | * @param string the table name |
| 316 | * @return string |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 317 | */ |
Andrey Andreev | b76029d | 2012-01-26 15:13:19 +0200 | [diff] [blame] | 318 | protected function _truncate($table) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 319 | { |
Andrey Andreev | a6fe36e | 2012-04-05 16:00:32 +0300 | [diff] [blame] | 320 | return 'DELETE FROM '.$table; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 321 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 322 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 323 | // -------------------------------------------------------------------- |
| 324 | |
| 325 | /** |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 326 | * Close DB Connection |
| 327 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 328 | * @return void |
| 329 | */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 330 | protected function _close() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 331 | { |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 332 | @odbc_close($this->conn_id); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 337 | /* End of file odbc_driver.php */ |
Andrey Andreev | 79922c0 | 2012-05-23 12:27:17 +0300 | [diff] [blame] | 338 | /* Location: ./system/database/drivers/odbc/odbc_driver.php */ |