blob: 6704264c6abdf92cb0baaf24551b8d9a116902e9 [file] [log] [blame]
Andrey Andreev5f356bf2012-03-20 14:32:27 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev5f356bf2012-03-20 14:32:27 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev5f356bf2012-03-20 14:32:27 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -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
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
Derek Allard2067d1a2008-11-13 22:59:24 +000028/**
29 * ODBC Database Adapter Class
30 *
31 * Note: _DB is an extender class that the app controller
32 * creates dynamically based on whether the active record
33 * class is being used or not.
34 *
35 * @package CodeIgniter
36 * @subpackage Drivers
37 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050038 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000039 * @link http://codeigniter.com/user_guide/database/
40 */
41class CI_DB_odbc_driver extends CI_DB {
42
Andrey Andreev5f356bf2012-03-20 14:32:27 +020043 public $dbdriver = 'odbc';
Barry Mienydd671972010-10-04 16:33:58 +020044
Derek Allard2067d1a2008-11-13 22:59:24 +000045 // the character used to excape - not necessary for ODBC
Andrey Andreev5f356bf2012-03-20 14:32:27 +020046 protected $_escape_char = '';
Barry Mienydd671972010-10-04 16:33:58 +020047
Derek Jonese4ed5832009-02-20 21:44:59 +000048 // clause and character used for LIKE escape sequences
Andrey Andreev5f356bf2012-03-20 14:32:27 +020049 protected $_like_escape_str = " {escape '%s'} ";
50 protected $_like_escape_chr = '!';
Barry Mienydd671972010-10-04 16:33:58 +020051
Derek Allard2067d1a2008-11-13 22:59:24 +000052 /**
53 * The syntax to count rows is slightly different across different
54 * database engines, so this string appears in each driver and is
Timothy Warren9e560a42012-03-19 19:06:46 -040055 * used for the count_all() and count_all_results() functions.
Derek Allard2067d1a2008-11-13 22:59:24 +000056 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +020057 protected $_count_string = 'SELECT COUNT(*) AS ';
58 protected $_random_keyword;
Derek Allard2067d1a2008-11-13 22:59:24 +000059
Timothy Warren9e560a42012-03-19 19:06:46 -040060
Andrey Andreev5f356bf2012-03-20 14:32:27 +020061 public function __construct($params)
Derek Allard2067d1a2008-11-13 22:59:24 +000062 {
Timothy Warrena2097a02011-10-10 10:10:46 -040063 parent::__construct($params);
Barry Mienydd671972010-10-04 16:33:58 +020064
Derek Allard2067d1a2008-11-13 22:59:24 +000065 $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
66 }
67
68 /**
69 * Non-persistent database connection
70 *
Derek Allard2067d1a2008-11-13 22:59:24 +000071 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020072 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +020073 public function db_connect()
Derek Allard2067d1a2008-11-13 22:59:24 +000074 {
75 return @odbc_connect($this->hostname, $this->username, $this->password);
76 }
Barry Mienydd671972010-10-04 16:33:58 +020077
Derek Allard2067d1a2008-11-13 22:59:24 +000078 // --------------------------------------------------------------------
79
80 /**
81 * Persistent database connection
82 *
Derek Allard2067d1a2008-11-13 22:59:24 +000083 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020084 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +020085 public function db_pconnect()
Derek Allard2067d1a2008-11-13 22:59:24 +000086 {
87 return @odbc_pconnect($this->hostname, $this->username, $this->password);
88 }
Barry Mienydd671972010-10-04 16:33:58 +020089
Derek Allard2067d1a2008-11-13 22:59:24 +000090 // --------------------------------------------------------------------
91
92 /**
Derek Jones87cbafc2009-02-27 16:29:59 +000093 * Reconnect
94 *
95 * Keep / reestablish the db connection if no queries have been
96 * sent for a length of time exceeding the server's idle timeout
97 *
Derek Jones87cbafc2009-02-27 16:29:59 +000098 * @return void
99 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200100 public function reconnect()
Derek Jones87cbafc2009-02-27 16:29:59 +0000101 {
102 // not implemented in odbc
103 }
104
105 // --------------------------------------------------------------------
106
107 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 * Select the database
109 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000110 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200111 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200112 public function db_select()
Derek Allard2067d1a2008-11-13 22:59:24 +0000113 {
114 // Not needed for ODBC
115 return TRUE;
116 }
117
118 // --------------------------------------------------------------------
119
120 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 * Execute the query
122 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 * @param string an SQL query
124 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200125 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200126 protected function _execute($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 return @odbc_exec($this->conn_id, $sql);
129 }
Barry Mienydd671972010-10-04 16:33:58 +0200130
Derek Allard2067d1a2008-11-13 22:59:24 +0000131 // --------------------------------------------------------------------
132
133 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 * Begin Transaction
135 *
Barry Mienydd671972010-10-04 16:33:58 +0200136 * @return bool
137 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200138 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 {
140 if ( ! $this->trans_enabled)
141 {
142 return TRUE;
143 }
Barry Mienydd671972010-10-04 16:33:58 +0200144
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 // When transactions are nested we only begin/commit/rollback the outermost ones
146 if ($this->_trans_depth > 0)
147 {
148 return TRUE;
149 }
150
151 // Reset the transaction failure flag.
152 // If the $test_mode flag is set to TRUE transactions will be rolled back
153 // even if the queries produce a successful result.
154 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
155
156 return odbc_autocommit($this->conn_id, FALSE);
157 }
158
159 // --------------------------------------------------------------------
160
161 /**
162 * Commit Transaction
163 *
Barry Mienydd671972010-10-04 16:33:58 +0200164 * @return bool
165 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200166 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 {
168 if ( ! $this->trans_enabled)
169 {
170 return TRUE;
171 }
172
173 // When transactions are nested we only begin/commit/rollback the outermost ones
174 if ($this->_trans_depth > 0)
175 {
176 return TRUE;
177 }
178
179 $ret = odbc_commit($this->conn_id);
180 odbc_autocommit($this->conn_id, TRUE);
181 return $ret;
182 }
183
184 // --------------------------------------------------------------------
185
186 /**
187 * Rollback Transaction
188 *
Barry Mienydd671972010-10-04 16:33:58 +0200189 * @return bool
190 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200191 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 {
193 if ( ! $this->trans_enabled)
194 {
195 return TRUE;
196 }
197
198 // When transactions are nested we only begin/commit/rollback the outermost ones
199 if ($this->_trans_depth > 0)
200 {
201 return TRUE;
202 }
203
204 $ret = odbc_rollback($this->conn_id);
205 odbc_autocommit($this->conn_id, TRUE);
206 return $ret;
207 }
208
209 // --------------------------------------------------------------------
210
211 /**
212 * Escape String
213 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000215 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 * @return string
217 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200218 public function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000220 if (is_array($str))
221 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500222 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200223 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000224 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200225 }
226
227 return $str;
228 }
229
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 // ODBC doesn't require escaping
Greg Aker757dda62010-04-14 19:06:19 -0500231 $str = remove_invisible_characters($str);
Barry Mienydd671972010-10-04 16:33:58 +0200232
Derek Jonese4ed5832009-02-20 21:44:59 +0000233 // escape LIKE condition wildcards
234 if ($like === TRUE)
235 {
Andrey Andreev6ea625e2012-03-20 14:46:27 +0200236 return str_replace(array($this->_like_escape_chr, '%', '_'),
Andrey Andreevf1bda682012-03-20 14:35:06 +0200237 array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
238 $str);
Derek Jonese4ed5832009-02-20 21:44:59 +0000239 }
Barry Mienydd671972010-10-04 16:33:58 +0200240
Derek Jonese4ed5832009-02-20 21:44:59 +0000241 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000242 }
Barry Mienydd671972010-10-04 16:33:58 +0200243
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 // --------------------------------------------------------------------
245
246 /**
247 * Affected Rows
248 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200249 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000250 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200251 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 {
253 return @odbc_num_rows($this->conn_id);
254 }
Barry Mienydd671972010-10-04 16:33:58 +0200255
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 // --------------------------------------------------------------------
257
258 /**
259 * Insert ID
260 *
Andrey Andreev8af76662012-03-05 14:33:41 +0200261 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 */
Andrey Andreev8af76662012-03-05 14:33:41 +0200263 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 {
Andrey Andreev8af76662012-03-05 14:33:41 +0200265 return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000266 }
267
268 // --------------------------------------------------------------------
269
270 /**
271 * "Count All" query
272 *
273 * Generates a platform-specific query string that counts all records in
274 * the specified database
275 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 * @param string
277 * @return string
278 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200279 public function count_all($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 {
281 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000282 {
283 return 0;
284 }
285
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200286 $query = $this->query($this->_count_string . $this->protect_identifiers('numrows') . " FROM " . $this->protect_identifiers($table, TRUE, NULL, FALSE));
Derek Allarde37ab382009-02-03 16:13:57 +0000287
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000289 {
290 return 0;
291 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000292
293 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500294 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000295 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 }
297
298 // --------------------------------------------------------------------
299
300 /**
301 * Show table query
302 *
303 * Generates a platform-specific query string so that the table names can be fetched
304 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200305 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000306 * @return string
307 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200308 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000309 {
310 $sql = "SHOW TABLES FROM `".$this->database."`";
311
312 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
313 {
Greg Aker0d424892010-01-26 02:14:44 +0000314 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 return FALSE; // not currently supported
316 }
Barry Mienydd671972010-10-04 16:33:58 +0200317
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 return $sql;
319 }
Barry Mienydd671972010-10-04 16:33:58 +0200320
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 // --------------------------------------------------------------------
322
323 /**
324 * Show column query
325 *
326 * Generates a platform-specific query string so that the column names can be fetched
327 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 * @param string the table name
329 * @return string
330 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200331 protected function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 {
333 return "SHOW COLUMNS FROM ".$table;
334 }
335
336 // --------------------------------------------------------------------
337
338 /**
339 * Field data query
340 *
341 * Generates a platform-specific query so that the column data can be retrieved
342 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 * @param string the table name
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200344 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200346 protected function _field_data($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 {
348 return "SELECT TOP 1 FROM ".$table;
349 }
350
351 // --------------------------------------------------------------------
352
353 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200354 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200356 * Returns an array containing code and message of the last
357 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000358 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200359 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200361 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200363 return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
Derek Allard2067d1a2008-11-13 22:59:24 +0000364 }
365
366 // --------------------------------------------------------------------
367
368 /**
369 * Escape the SQL Identifiers
370 *
Timothy Warren9e560a42012-03-19 19:06:46 -0400371 * This function escapes column and table names
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 * @param string
374 * @return string
375 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200376 public function _escape_identifiers($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 {
378 if ($this->_escape_char == '')
379 {
380 return $item;
381 }
382
383 foreach ($this->_reserved_identifiers as $id)
384 {
385 if (strpos($item, '.'.$id) !== FALSE)
386 {
Barry Mienydd671972010-10-04 16:33:58 +0200387 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
388
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 // remove duplicates if the user already included the escape
390 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200391 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 }
Barry Mienydd671972010-10-04 16:33:58 +0200393
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 if (strpos($item, '.') !== FALSE)
395 {
Barry Mienydd671972010-10-04 16:33:58 +0200396 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000397 }
398 else
399 {
400 $str = $this->_escape_char.$item.$this->_escape_char;
401 }
Barry Mienydd671972010-10-04 16:33:58 +0200402
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 // remove duplicates if the user already included the escape
404 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
405 }
Barry Mienydd671972010-10-04 16:33:58 +0200406
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 // --------------------------------------------------------------------
408
409 /**
410 * From Tables
411 *
Timothy Warren9e560a42012-03-19 19:06:46 -0400412 * This function implicitly groups FROM tables so there is no confusion
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 * about operator precedence in harmony with SQL standards
414 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200415 * @param array
416 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000417 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200418 protected function _from_tables($tables)
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 {
420 if ( ! is_array($tables))
421 {
422 $tables = array($tables);
423 }
Barry Mienydd671972010-10-04 16:33:58 +0200424
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 return '('.implode(', ', $tables).')';
426 }
427
428 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200429
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 /**
431 * Insert statement
432 *
433 * Generates a platform-specific insert string from the supplied data
434 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 * @param string the table name
436 * @param array the insert keys
437 * @param array the insert values
438 * @return string
439 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200440 protected function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200441 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
443 }
Barry Mienydd671972010-10-04 16:33:58 +0200444
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 // --------------------------------------------------------------------
446
447 /**
448 * Update statement
449 *
450 * Generates a platform-specific update string from the supplied data
451 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 * @param string the table name
453 * @param array the update data
454 * @param array the where clause
455 * @param array the orderby clause
456 * @param array the limit clause
457 * @return string
458 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200459 protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500461 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 {
463 $valstr[] = $key." = ".$val;
464 }
Barry Mienydd671972010-10-04 16:33:58 +0200465
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200467
Derek Allard2067d1a2008-11-13 22:59:24 +0000468 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200469
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
471
472 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
473
474 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200475
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 return $sql;
477 }
478
Barry Mienydd671972010-10-04 16:33:58 +0200479
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 // --------------------------------------------------------------------
481
482 /**
483 * Truncate statement
484 *
485 * Generates a platform-specific truncate string from the supplied data
486 * If the database does not support the truncate() command
Timothy Warren9e560a42012-03-19 19:06:46 -0400487 * This function maps to "DELETE FROM table"
Derek Allard2067d1a2008-11-13 22:59:24 +0000488 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 * @param string the table name
490 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200491 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200492 protected function _truncate($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000493 {
494 return $this->_delete($table);
495 }
Barry Mienydd671972010-10-04 16:33:58 +0200496
Derek Allard2067d1a2008-11-13 22:59:24 +0000497 // --------------------------------------------------------------------
498
499 /**
500 * Delete statement
501 *
502 * Generates a platform-specific delete string from the supplied data
503 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 * @param string the table name
505 * @param array the where clause
506 * @param string the limit clause
507 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200508 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200509 protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000510 {
511 $conditions = '';
512
513 if (count($where) > 0 OR count($like) > 0)
514 {
515 $conditions = "\nWHERE ";
516 $conditions .= implode("\n", $this->ar_where);
517
518 if (count($where) > 0 && count($like) > 0)
519 {
520 $conditions .= " AND ";
521 }
522 $conditions .= implode("\n", $like);
523 }
524
525 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200526
Derek Allard2067d1a2008-11-13 22:59:24 +0000527 return "DELETE FROM ".$table.$conditions.$limit;
528 }
529
530 // --------------------------------------------------------------------
531
532 /**
533 * Limit string
534 *
535 * Generates a platform-specific LIMIT clause
536 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000537 * @param string the sql query string
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200538 * @param int the number of rows to limit the query to
539 * @param int the offset value
Derek Allard2067d1a2008-11-13 22:59:24 +0000540 * @return string
541 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200542 protected function _limit($sql, $limit, $offset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 {
544 // Does ODBC doesn't use the LIMIT clause?
545 return $sql;
546 }
547
548 // --------------------------------------------------------------------
549
550 /**
551 * Close DB Connection
552 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 * @param resource
554 * @return void
555 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200556 protected function _close($conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000557 {
558 @odbc_close($conn_id);
559 }
Timothy Warren9e560a42012-03-19 19:06:46 -0400560
Derek Allard2067d1a2008-11-13 22:59:24 +0000561}
562
Derek Allard2067d1a2008-11-13 22:59:24 +0000563/* End of file odbc_driver.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400564/* Location: ./system/database/drivers/odbc/odbc_driver.php */