blob: 901787ff34dc1b80a99ccdb6a0e7968410f09bc8 [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 /**
93 * Select the database
94 *
Derek Allard2067d1a2008-11-13 22:59:24 +000095 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020096 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +020097 public function db_select()
Derek Allard2067d1a2008-11-13 22:59:24 +000098 {
99 // Not needed for ODBC
100 return TRUE;
101 }
102
103 // --------------------------------------------------------------------
104
105 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000106 * Execute the query
107 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 * @param string an SQL query
109 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200110 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200111 protected function _execute($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000113 return @odbc_exec($this->conn_id, $sql);
114 }
Barry Mienydd671972010-10-04 16:33:58 +0200115
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 // --------------------------------------------------------------------
117
118 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000119 * Begin Transaction
120 *
Barry Mienydd671972010-10-04 16:33:58 +0200121 * @return bool
122 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200123 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 {
125 if ( ! $this->trans_enabled)
126 {
127 return TRUE;
128 }
Barry Mienydd671972010-10-04 16:33:58 +0200129
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 // When transactions are nested we only begin/commit/rollback the outermost ones
131 if ($this->_trans_depth > 0)
132 {
133 return TRUE;
134 }
135
136 // Reset the transaction failure flag.
137 // If the $test_mode flag is set to TRUE transactions will be rolled back
138 // even if the queries produce a successful result.
139 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
140
141 return odbc_autocommit($this->conn_id, FALSE);
142 }
143
144 // --------------------------------------------------------------------
145
146 /**
147 * Commit Transaction
148 *
Barry Mienydd671972010-10-04 16:33:58 +0200149 * @return bool
150 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200151 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 {
153 if ( ! $this->trans_enabled)
154 {
155 return TRUE;
156 }
157
158 // When transactions are nested we only begin/commit/rollback the outermost ones
159 if ($this->_trans_depth > 0)
160 {
161 return TRUE;
162 }
163
164 $ret = odbc_commit($this->conn_id);
165 odbc_autocommit($this->conn_id, TRUE);
166 return $ret;
167 }
168
169 // --------------------------------------------------------------------
170
171 /**
172 * Rollback Transaction
173 *
Barry Mienydd671972010-10-04 16:33:58 +0200174 * @return bool
175 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200176 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 {
178 if ( ! $this->trans_enabled)
179 {
180 return TRUE;
181 }
182
183 // When transactions are nested we only begin/commit/rollback the outermost ones
184 if ($this->_trans_depth > 0)
185 {
186 return TRUE;
187 }
188
189 $ret = odbc_rollback($this->conn_id);
190 odbc_autocommit($this->conn_id, TRUE);
191 return $ret;
192 }
193
194 // --------------------------------------------------------------------
195
196 /**
197 * Escape String
198 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000200 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 * @return string
202 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200203 public function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000205 if (is_array($str))
206 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500207 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200208 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000209 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200210 }
211
212 return $str;
213 }
214
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 // ODBC doesn't require escaping
Greg Aker757dda62010-04-14 19:06:19 -0500216 $str = remove_invisible_characters($str);
Barry Mienydd671972010-10-04 16:33:58 +0200217
Derek Jonese4ed5832009-02-20 21:44:59 +0000218 // escape LIKE condition wildcards
219 if ($like === TRUE)
220 {
Andrey Andreev6ea625e2012-03-20 14:46:27 +0200221 return str_replace(array($this->_like_escape_chr, '%', '_'),
Andrey Andreevf1bda682012-03-20 14:35:06 +0200222 array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
223 $str);
Derek Jonese4ed5832009-02-20 21:44:59 +0000224 }
Barry Mienydd671972010-10-04 16:33:58 +0200225
Derek Jonese4ed5832009-02-20 21:44:59 +0000226 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000227 }
Barry Mienydd671972010-10-04 16:33:58 +0200228
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 // --------------------------------------------------------------------
230
231 /**
232 * Affected Rows
233 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200234 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200236 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 {
238 return @odbc_num_rows($this->conn_id);
239 }
Barry Mienydd671972010-10-04 16:33:58 +0200240
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 // --------------------------------------------------------------------
242
243 /**
244 * Insert ID
245 *
Andrey Andreev8af76662012-03-05 14:33:41 +0200246 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000247 */
Andrey Andreev8af76662012-03-05 14:33:41 +0200248 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000249 {
Andrey Andreev8af76662012-03-05 14:33:41 +0200250 return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000251 }
252
253 // --------------------------------------------------------------------
254
255 /**
256 * "Count All" query
257 *
258 * Generates a platform-specific query string that counts all records in
259 * the specified database
260 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000261 * @param string
262 * @return string
263 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200264 public function count_all($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 {
266 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000267 {
268 return 0;
269 }
270
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200271 $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 +0000272
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000274 {
275 return 0;
276 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000277
278 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500279 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000280 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000281 }
282
283 // --------------------------------------------------------------------
284
285 /**
286 * Show table query
287 *
288 * Generates a platform-specific query string so that the table names can be fetched
289 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200290 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000291 * @return string
292 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200293 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000294 {
295 $sql = "SHOW TABLES FROM `".$this->database."`";
296
297 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
298 {
Greg Aker0d424892010-01-26 02:14:44 +0000299 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 return FALSE; // not currently supported
301 }
Barry Mienydd671972010-10-04 16:33:58 +0200302
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 return $sql;
304 }
Barry Mienydd671972010-10-04 16:33:58 +0200305
Derek Allard2067d1a2008-11-13 22:59:24 +0000306 // --------------------------------------------------------------------
307
308 /**
309 * Show column query
310 *
311 * Generates a platform-specific query string so that the column names can be fetched
312 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000313 * @param string the table name
314 * @return string
315 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200316 protected function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000317 {
318 return "SHOW COLUMNS FROM ".$table;
319 }
320
321 // --------------------------------------------------------------------
322
323 /**
324 * Field data query
325 *
326 * Generates a platform-specific query so that the column data can be retrieved
327 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 * @param string the table name
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200329 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200331 protected function _field_data($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 {
333 return "SELECT TOP 1 FROM ".$table;
334 }
335
336 // --------------------------------------------------------------------
337
338 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200339 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000340 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200341 * Returns an array containing code and message of the last
342 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200344 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200346 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200348 return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 }
350
351 // --------------------------------------------------------------------
352
353 /**
354 * Escape the SQL Identifiers
355 *
Timothy Warren9e560a42012-03-19 19:06:46 -0400356 * This function escapes column and table names
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000358 * @param string
359 * @return string
360 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200361 public function _escape_identifiers($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 {
363 if ($this->_escape_char == '')
364 {
365 return $item;
366 }
367
368 foreach ($this->_reserved_identifiers as $id)
369 {
370 if (strpos($item, '.'.$id) !== FALSE)
371 {
Barry Mienydd671972010-10-04 16:33:58 +0200372 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
373
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 // remove duplicates if the user already included the escape
375 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200376 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 }
Barry Mienydd671972010-10-04 16:33:58 +0200378
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 if (strpos($item, '.') !== FALSE)
380 {
Barry Mienydd671972010-10-04 16:33:58 +0200381 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000382 }
383 else
384 {
385 $str = $this->_escape_char.$item.$this->_escape_char;
386 }
Barry Mienydd671972010-10-04 16:33:58 +0200387
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 // remove duplicates if the user already included the escape
389 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
390 }
Barry Mienydd671972010-10-04 16:33:58 +0200391
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 // --------------------------------------------------------------------
393
394 /**
395 * From Tables
396 *
Timothy Warren9e560a42012-03-19 19:06:46 -0400397 * This function implicitly groups FROM tables so there is no confusion
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 * about operator precedence in harmony with SQL standards
399 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200400 * @param array
401 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200403 protected function _from_tables($tables)
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 {
405 if ( ! is_array($tables))
406 {
407 $tables = array($tables);
408 }
Barry Mienydd671972010-10-04 16:33:58 +0200409
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 return '('.implode(', ', $tables).')';
411 }
412
413 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200414
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 /**
416 * Insert statement
417 *
418 * Generates a platform-specific insert string from the supplied data
419 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 * @param string the table name
421 * @param array the insert keys
422 * @param array the insert values
423 * @return string
424 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200425 protected function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200426 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
428 }
Barry Mienydd671972010-10-04 16:33:58 +0200429
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 // --------------------------------------------------------------------
431
432 /**
433 * Update statement
434 *
435 * Generates a platform-specific update string from the supplied data
436 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000437 * @param string the table name
438 * @param array the update data
439 * @param array the where clause
440 * @param array the orderby clause
441 * @param array the limit clause
442 * @return string
443 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200444 protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500446 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 {
448 $valstr[] = $key." = ".$val;
449 }
Barry Mienydd671972010-10-04 16:33:58 +0200450
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200452
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200454
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
456
457 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
458
459 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200460
Derek Allard2067d1a2008-11-13 22:59:24 +0000461 return $sql;
462 }
463
Barry Mienydd671972010-10-04 16:33:58 +0200464
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 // --------------------------------------------------------------------
466
467 /**
468 * Truncate statement
469 *
470 * Generates a platform-specific truncate string from the supplied data
471 * If the database does not support the truncate() command
Timothy Warren9e560a42012-03-19 19:06:46 -0400472 * This function maps to "DELETE FROM table"
Derek Allard2067d1a2008-11-13 22:59:24 +0000473 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 * @param string the table name
475 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200476 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200477 protected function _truncate($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 {
479 return $this->_delete($table);
480 }
Barry Mienydd671972010-10-04 16:33:58 +0200481
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 // --------------------------------------------------------------------
483
484 /**
485 * Delete statement
486 *
487 * Generates a platform-specific delete string from the supplied data
488 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 * @param string the table name
490 * @param array the where clause
491 * @param string the limit clause
492 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200493 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200494 protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000495 {
496 $conditions = '';
497
498 if (count($where) > 0 OR count($like) > 0)
499 {
500 $conditions = "\nWHERE ";
501 $conditions .= implode("\n", $this->ar_where);
502
503 if (count($where) > 0 && count($like) > 0)
504 {
505 $conditions .= " AND ";
506 }
507 $conditions .= implode("\n", $like);
508 }
509
510 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200511
Derek Allard2067d1a2008-11-13 22:59:24 +0000512 return "DELETE FROM ".$table.$conditions.$limit;
513 }
514
515 // --------------------------------------------------------------------
516
517 /**
518 * Limit string
519 *
520 * Generates a platform-specific LIMIT clause
521 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 * @param string the sql query string
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200523 * @param int the number of rows to limit the query to
524 * @param int the offset value
Derek Allard2067d1a2008-11-13 22:59:24 +0000525 * @return string
526 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200527 protected function _limit($sql, $limit, $offset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000528 {
529 // Does ODBC doesn't use the LIMIT clause?
530 return $sql;
531 }
532
533 // --------------------------------------------------------------------
534
535 /**
536 * Close DB Connection
537 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000538 * @param resource
539 * @return void
540 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200541 protected function _close($conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000542 {
543 @odbc_close($conn_id);
544 }
Timothy Warren9e560a42012-03-19 19:06:46 -0400545
Derek Allard2067d1a2008-11-13 22:59:24 +0000546}
547
Derek Allard2067d1a2008-11-13 22:59:24 +0000548/* End of file odbc_driver.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400549/* Location: ./system/database/drivers/odbc/odbc_driver.php */