blob: 78acd2ce946e053253253f04489c437a5766757b [file] [log] [blame]
Derek Jones4b9c6292011-07-01 17:40:48 -05001<?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
8 *
9 * Licensed under the Open Software License version 3.0
10 *
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 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
28// ------------------------------------------------------------------------
29
30/**
31 * ODBC Database Adapter Class
32 *
33 * Note: _DB is an extender class that the app controller
34 * creates dynamically based on whether the active record
35 * class is being used or not.
36 *
37 * @package CodeIgniter
38 * @subpackage Drivers
39 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050040 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000041 * @link http://codeigniter.com/user_guide/database/
42 */
43class CI_DB_odbc_driver extends CI_DB {
44
45 var $dbdriver = 'odbc';
Barry Mienydd671972010-10-04 16:33:58 +020046
Derek Allard2067d1a2008-11-13 22:59:24 +000047 // the character used to excape - not necessary for ODBC
48 var $_escape_char = '';
Barry Mienydd671972010-10-04 16:33:58 +020049
Derek Jonese4ed5832009-02-20 21:44:59 +000050 // clause and character used for LIKE escape sequences
Timothy Warren142ca8e2012-03-19 18:00:35 -040051 protected $_like_escape_str = " {escape '%s'} ";
52 protected $_like_escape_chr = '!';
Barry Mienydd671972010-10-04 16:33:58 +020053
Derek Allard2067d1a2008-11-13 22:59:24 +000054 /**
55 * The syntax to count rows is slightly different across different
56 * database engines, so this string appears in each driver and is
Timothy Warren142ca8e2012-03-19 18:00:35 -040057 * used for the count_all() and count_all_results() public functions.
Derek Allard2067d1a2008-11-13 22:59:24 +000058 */
Timothy Warren142ca8e2012-03-19 18:00:35 -040059 protected $_count_string = "SELECT COUNT(*) AS ";
60 protected $_random_keyword;
Derek Allard2067d1a2008-11-13 22:59:24 +000061
Timothy Warren142ca8e2012-03-19 18:00:35 -040062 /**
63 * Constructor, to define random keyword
64 */
65 public function __construct($params)
Derek Allard2067d1a2008-11-13 22:59:24 +000066 {
Timothy Warrena2097a02011-10-10 10:10:46 -040067 parent::__construct($params);
Barry Mienydd671972010-10-04 16:33:58 +020068
Derek Allard2067d1a2008-11-13 22:59:24 +000069 $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
70 }
Timothy Warren142ca8e2012-03-19 18:00:35 -040071
72 // --------------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +000073
74 /**
75 * Non-persistent database connection
76 *
Derek Allard2067d1a2008-11-13 22:59:24 +000077 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020078 */
Timothy Warren142ca8e2012-03-19 18:00:35 -040079 protected function db_connect()
Derek Allard2067d1a2008-11-13 22:59:24 +000080 {
81 return @odbc_connect($this->hostname, $this->username, $this->password);
82 }
Barry Mienydd671972010-10-04 16:33:58 +020083
Derek Allard2067d1a2008-11-13 22:59:24 +000084 // --------------------------------------------------------------------
85
86 /**
87 * Persistent database connection
88 *
Derek Allard2067d1a2008-11-13 22:59:24 +000089 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020090 */
Timothy Warren142ca8e2012-03-19 18:00:35 -040091 protected function db_pconnect()
Derek Allard2067d1a2008-11-13 22:59:24 +000092 {
93 return @odbc_pconnect($this->hostname, $this->username, $this->password);
94 }
Barry Mienydd671972010-10-04 16:33:58 +020095
Derek Allard2067d1a2008-11-13 22:59:24 +000096 // --------------------------------------------------------------------
97
98 /**
Derek Jones87cbafc2009-02-27 16:29:59 +000099 * Reconnect
100 *
101 * Keep / reestablish the db connection if no queries have been
102 * sent for a length of time exceeding the server's idle timeout
103 *
Derek Jones87cbafc2009-02-27 16:29:59 +0000104 * @return void
105 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400106 public function reconnect()
Derek Jones87cbafc2009-02-27 16:29:59 +0000107 {
108 // not implemented in odbc
109 }
110
111 // --------------------------------------------------------------------
112
113 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 * Select the database
115 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200117 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400118 protected function db_select()
Derek Allard2067d1a2008-11-13 22:59:24 +0000119 {
120 // Not needed for ODBC
121 return TRUE;
122 }
123
124 // --------------------------------------------------------------------
125
126 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 * Execute the query
128 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 * @param string an SQL query
130 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200131 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400132 protected function _execute($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000133 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 return @odbc_exec($this->conn_id, $sql);
135 }
Barry Mienydd671972010-10-04 16:33:58 +0200136
Derek Allard2067d1a2008-11-13 22:59:24 +0000137 // --------------------------------------------------------------------
138
139 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 * Begin Transaction
141 *
Barry Mienydd671972010-10-04 16:33:58 +0200142 * @return bool
143 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400144 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 {
146 if ( ! $this->trans_enabled)
147 {
148 return TRUE;
149 }
Barry Mienydd671972010-10-04 16:33:58 +0200150
Derek Allard2067d1a2008-11-13 22:59:24 +0000151 // When transactions are nested we only begin/commit/rollback the outermost ones
152 if ($this->_trans_depth > 0)
153 {
154 return TRUE;
155 }
156
157 // Reset the transaction failure flag.
158 // If the $test_mode flag is set to TRUE transactions will be rolled back
159 // even if the queries produce a successful result.
160 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
161
162 return odbc_autocommit($this->conn_id, FALSE);
163 }
164
165 // --------------------------------------------------------------------
166
167 /**
168 * Commit Transaction
169 *
Barry Mienydd671972010-10-04 16:33:58 +0200170 * @return bool
171 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400172 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 {
174 if ( ! $this->trans_enabled)
175 {
176 return TRUE;
177 }
178
179 // When transactions are nested we only begin/commit/rollback the outermost ones
180 if ($this->_trans_depth > 0)
181 {
182 return TRUE;
183 }
184
185 $ret = odbc_commit($this->conn_id);
186 odbc_autocommit($this->conn_id, TRUE);
187 return $ret;
188 }
189
190 // --------------------------------------------------------------------
191
192 /**
193 * Rollback Transaction
194 *
Barry Mienydd671972010-10-04 16:33:58 +0200195 * @return bool
196 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400197 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000198 {
199 if ( ! $this->trans_enabled)
200 {
201 return TRUE;
202 }
203
204 // When transactions are nested we only begin/commit/rollback the outermost ones
205 if ($this->_trans_depth > 0)
206 {
207 return TRUE;
208 }
209
210 $ret = odbc_rollback($this->conn_id);
211 odbc_autocommit($this->conn_id, TRUE);
212 return $ret;
213 }
214
215 // --------------------------------------------------------------------
216
217 /**
218 * Escape String
219 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000221 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000222 * @return string
223 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400224 public function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000225 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000226 if (is_array($str))
227 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500228 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200229 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000230 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200231 }
232
233 return $str;
234 }
235
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 // ODBC doesn't require escaping
Greg Aker757dda62010-04-14 19:06:19 -0500237 $str = remove_invisible_characters($str);
Barry Mienydd671972010-10-04 16:33:58 +0200238
Derek Jonese4ed5832009-02-20 21:44:59 +0000239 // escape LIKE condition wildcards
240 if ($like === TRUE)
241 {
242 $str = str_replace( array('%', '_', $this->_like_escape_chr),
243 array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
244 $str);
245 }
Barry Mienydd671972010-10-04 16:33:58 +0200246
Derek Jonese4ed5832009-02-20 21:44:59 +0000247 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 }
Barry Mienydd671972010-10-04 16:33:58 +0200249
Derek Allard2067d1a2008-11-13 22:59:24 +0000250 // --------------------------------------------------------------------
251
252 /**
253 * Affected Rows
254 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000255 * @return integer
256 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400257 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 {
259 return @odbc_num_rows($this->conn_id);
260 }
Barry Mienydd671972010-10-04 16:33:58 +0200261
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 // --------------------------------------------------------------------
263
264 /**
265 * Insert ID
266 *
Andrey Andreev8af76662012-03-05 14:33:41 +0200267 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 */
Andrey Andreev8af76662012-03-05 14:33:41 +0200269 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 {
Andrey Andreev8af76662012-03-05 14:33:41 +0200271 return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 }
273
274 // --------------------------------------------------------------------
275
276 /**
277 * "Count All" query
278 *
279 * Generates a platform-specific query string that counts all records in
280 * the specified database
281 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 * @param string
283 * @return string
284 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400285 public function count_all($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000286 {
287 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000288 {
289 return 0;
290 }
291
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200292 $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 +0000293
Derek Allard2067d1a2008-11-13 22:59:24 +0000294 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000295 {
296 return 0;
297 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000298
299 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500300 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000301 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000302 }
303
304 // --------------------------------------------------------------------
305
306 /**
307 * Show table query
308 *
309 * Generates a platform-specific query string so that the table names can be fetched
310 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000311 * @param boolean
312 * @return string
313 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400314 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 {
316 $sql = "SHOW TABLES FROM `".$this->database."`";
317
318 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
319 {
Greg Aker0d424892010-01-26 02:14:44 +0000320 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 return FALSE; // not currently supported
322 }
Barry Mienydd671972010-10-04 16:33:58 +0200323
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 return $sql;
325 }
Barry Mienydd671972010-10-04 16:33:58 +0200326
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 // --------------------------------------------------------------------
328
329 /**
330 * Show column query
331 *
332 * Generates a platform-specific query string so that the column names can be fetched
333 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 * @param string the table name
335 * @return string
336 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400337 public function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000338 {
339 return "SHOW COLUMNS FROM ".$table;
340 }
341
342 // --------------------------------------------------------------------
343
344 /**
345 * Field data query
346 *
347 * Generates a platform-specific query so that the column data can be retrieved
348 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 * @param string the table name
350 * @return object
351 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400352 public function _field_data($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 {
354 return "SELECT TOP 1 FROM ".$table;
355 }
356
357 // --------------------------------------------------------------------
358
359 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200360 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200362 * Returns an array containing code and message of the last
363 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000364 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200365 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000366 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200367 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200369 return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 }
371
372 // --------------------------------------------------------------------
373
374 /**
375 * Escape the SQL Identifiers
376 *
Timothy Warren142ca8e2012-03-19 18:00:35 -0400377 * This public function escapes column and table names
Derek Allard2067d1a2008-11-13 22:59:24 +0000378 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 * @param string
380 * @return string
381 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400382 protected function _escape_identifiers($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 {
384 if ($this->_escape_char == '')
385 {
386 return $item;
387 }
388
389 foreach ($this->_reserved_identifiers as $id)
390 {
391 if (strpos($item, '.'.$id) !== FALSE)
392 {
Barry Mienydd671972010-10-04 16:33:58 +0200393 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
394
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 // remove duplicates if the user already included the escape
396 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200397 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 }
Barry Mienydd671972010-10-04 16:33:58 +0200399
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 if (strpos($item, '.') !== FALSE)
401 {
Barry Mienydd671972010-10-04 16:33:58 +0200402 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 }
404 else
405 {
406 $str = $this->_escape_char.$item.$this->_escape_char;
407 }
Barry Mienydd671972010-10-04 16:33:58 +0200408
Derek Allard2067d1a2008-11-13 22:59:24 +0000409 // remove duplicates if the user already included the escape
410 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
411 }
Barry Mienydd671972010-10-04 16:33:58 +0200412
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 // --------------------------------------------------------------------
414
415 /**
416 * From Tables
417 *
Timothy Warren142ca8e2012-03-19 18:00:35 -0400418 * This public function implicitly groups FROM tables so there is no confusion
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 * about operator precedence in harmony with SQL standards
420 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000421 * @param type
422 * @return type
423 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400424 public function _from_tables($tables)
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 {
426 if ( ! is_array($tables))
427 {
428 $tables = array($tables);
429 }
Barry Mienydd671972010-10-04 16:33:58 +0200430
Derek Allard2067d1a2008-11-13 22:59:24 +0000431 return '('.implode(', ', $tables).')';
432 }
433
434 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200435
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 /**
437 * Insert statement
438 *
439 * Generates a platform-specific insert string from the supplied data
440 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 * @param string the table name
442 * @param array the insert keys
443 * @param array the insert values
444 * @return string
445 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400446 public function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200447 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
449 }
Barry Mienydd671972010-10-04 16:33:58 +0200450
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 // --------------------------------------------------------------------
452
453 /**
454 * Update statement
455 *
456 * Generates a platform-specific update string from the supplied data
457 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 * @param string the table name
459 * @param array the update data
460 * @param array the where clause
461 * @param array the orderby clause
462 * @param array the limit clause
463 * @return string
464 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400465 public function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500467 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000468 {
469 $valstr[] = $key." = ".$val;
470 }
Barry Mienydd671972010-10-04 16:33:58 +0200471
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200473
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200475
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
477
478 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
479
480 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200481
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 return $sql;
483 }
484
Barry Mienydd671972010-10-04 16:33:58 +0200485
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 // --------------------------------------------------------------------
487
488 /**
489 * Truncate statement
490 *
491 * Generates a platform-specific truncate string from the supplied data
492 * If the database does not support the truncate() command
Timothy Warren142ca8e2012-03-19 18:00:35 -0400493 * This public function maps to "DELETE FROM table"
Derek Allard2067d1a2008-11-13 22:59:24 +0000494 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000495 * @param string the table name
496 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200497 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400498 public function _truncate($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 {
500 return $this->_delete($table);
501 }
Barry Mienydd671972010-10-04 16:33:58 +0200502
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 // --------------------------------------------------------------------
504
505 /**
506 * Delete statement
507 *
508 * Generates a platform-specific delete string from the supplied data
509 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000510 * @param string the table name
511 * @param array the where clause
512 * @param string the limit clause
513 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200514 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400515 public function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 {
517 $conditions = '';
518
519 if (count($where) > 0 OR count($like) > 0)
520 {
521 $conditions = "\nWHERE ";
522 $conditions .= implode("\n", $this->ar_where);
523
524 if (count($where) > 0 && count($like) > 0)
525 {
526 $conditions .= " AND ";
527 }
528 $conditions .= implode("\n", $like);
529 }
530
531 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200532
Derek Allard2067d1a2008-11-13 22:59:24 +0000533 return "DELETE FROM ".$table.$conditions.$limit;
534 }
535
536 // --------------------------------------------------------------------
537
538 /**
539 * Limit string
540 *
541 * Generates a platform-specific LIMIT clause
542 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 * @param string the sql query string
544 * @param integer the number of rows to limit the query to
545 * @param integer the offset value
546 * @return string
547 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400548 public function _limit($sql, $limit, $offset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000549 {
550 // Does ODBC doesn't use the LIMIT clause?
551 return $sql;
552 }
553
554 // --------------------------------------------------------------------
555
556 /**
557 * Close DB Connection
558 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000559 * @param resource
560 * @return void
561 */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400562 public function _close($conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000563 {
564 @odbc_close($conn_id);
565 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000566}
567
Derek Allard2067d1a2008-11-13 22:59:24 +0000568/* End of file odbc_driver.php */
Timothy Warren142ca8e2012-03-19 18:00:35 -0400569/* Location: ./system/database/drivers/odbc/odbc_driver.php */