blob: b70713ce976f8d2eab8ef6ad32ae2f1961c07b12 [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
55 * used for the count_all() and count_all_results() functions.
56 */
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
60
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 {
128 $sql = $this->_prep_query($sql);
129 return @odbc_exec($this->conn_id, $sql);
130 }
Barry Mienydd671972010-10-04 16:33:58 +0200131
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 // --------------------------------------------------------------------
133
134 /**
135 * Prep the query
136 *
137 * If needed, each database adapter can prep the query string
138 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 * @param string an SQL query
140 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200141 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200142 protected function _prep_query($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 {
144 return $sql;
145 }
146
147 // --------------------------------------------------------------------
148
149 /**
150 * Begin Transaction
151 *
Barry Mienydd671972010-10-04 16:33:58 +0200152 * @return bool
153 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200154 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 {
156 if ( ! $this->trans_enabled)
157 {
158 return TRUE;
159 }
Barry Mienydd671972010-10-04 16:33:58 +0200160
Derek Allard2067d1a2008-11-13 22:59:24 +0000161 // When transactions are nested we only begin/commit/rollback the outermost ones
162 if ($this->_trans_depth > 0)
163 {
164 return TRUE;
165 }
166
167 // Reset the transaction failure flag.
168 // If the $test_mode flag is set to TRUE transactions will be rolled back
169 // even if the queries produce a successful result.
170 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
171
172 return odbc_autocommit($this->conn_id, FALSE);
173 }
174
175 // --------------------------------------------------------------------
176
177 /**
178 * Commit Transaction
179 *
Barry Mienydd671972010-10-04 16:33:58 +0200180 * @return bool
181 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200182 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000183 {
184 if ( ! $this->trans_enabled)
185 {
186 return TRUE;
187 }
188
189 // When transactions are nested we only begin/commit/rollback the outermost ones
190 if ($this->_trans_depth > 0)
191 {
192 return TRUE;
193 }
194
195 $ret = odbc_commit($this->conn_id);
196 odbc_autocommit($this->conn_id, TRUE);
197 return $ret;
198 }
199
200 // --------------------------------------------------------------------
201
202 /**
203 * Rollback Transaction
204 *
Barry Mienydd671972010-10-04 16:33:58 +0200205 * @return bool
206 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200207 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 {
209 if ( ! $this->trans_enabled)
210 {
211 return TRUE;
212 }
213
214 // When transactions are nested we only begin/commit/rollback the outermost ones
215 if ($this->_trans_depth > 0)
216 {
217 return TRUE;
218 }
219
220 $ret = odbc_rollback($this->conn_id);
221 odbc_autocommit($this->conn_id, TRUE);
222 return $ret;
223 }
224
225 // --------------------------------------------------------------------
226
227 /**
228 * Escape String
229 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000231 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 * @return string
233 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200234 public function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000236 if (is_array($str))
237 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500238 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200239 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000240 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200241 }
242
243 return $str;
244 }
245
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 // ODBC doesn't require escaping
Greg Aker757dda62010-04-14 19:06:19 -0500247 $str = remove_invisible_characters($str);
Barry Mienydd671972010-10-04 16:33:58 +0200248
Derek Jonese4ed5832009-02-20 21:44:59 +0000249 // escape LIKE condition wildcards
250 if ($like === TRUE)
251 {
252 $str = str_replace( array('%', '_', $this->_like_escape_chr),
253 array($this->_like_escape_chr.'%', $this->_like_escape_chr.'_', $this->_like_escape_chr.$this->_like_escape_chr),
254 $str);
255 }
Barry Mienydd671972010-10-04 16:33:58 +0200256
Derek Jonese4ed5832009-02-20 21:44:59 +0000257 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 }
Barry Mienydd671972010-10-04 16:33:58 +0200259
Derek Allard2067d1a2008-11-13 22:59:24 +0000260 // --------------------------------------------------------------------
261
262 /**
263 * Affected Rows
264 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200265 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000266 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200267 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 {
269 return @odbc_num_rows($this->conn_id);
270 }
Barry Mienydd671972010-10-04 16:33:58 +0200271
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 // --------------------------------------------------------------------
273
274 /**
275 * Insert ID
276 *
Andrey Andreev8af76662012-03-05 14:33:41 +0200277 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 */
Andrey Andreev8af76662012-03-05 14:33:41 +0200279 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 {
Andrey Andreev8af76662012-03-05 14:33:41 +0200281 return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 }
283
284 // --------------------------------------------------------------------
285
286 /**
287 * "Count All" query
288 *
289 * Generates a platform-specific query string that counts all records in
290 * the specified database
291 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 * @param string
293 * @return string
294 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200295 public function count_all($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 {
297 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000298 {
299 return 0;
300 }
301
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200302 $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 +0000303
Derek Allard2067d1a2008-11-13 22:59:24 +0000304 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000305 {
306 return 0;
307 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000308
309 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500310 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000311 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000312 }
313
314 // --------------------------------------------------------------------
315
316 /**
317 * Show table query
318 *
319 * Generates a platform-specific query string so that the table names can be fetched
320 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200321 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 * @return string
323 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200324 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 {
326 $sql = "SHOW TABLES FROM `".$this->database."`";
327
328 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
329 {
Greg Aker0d424892010-01-26 02:14:44 +0000330 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 return FALSE; // not currently supported
332 }
Barry Mienydd671972010-10-04 16:33:58 +0200333
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 return $sql;
335 }
Barry Mienydd671972010-10-04 16:33:58 +0200336
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 // --------------------------------------------------------------------
338
339 /**
340 * Show column query
341 *
342 * Generates a platform-specific query string so that the column names can be fetched
343 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 * @param string the table name
345 * @return string
346 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200347 protected function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 {
349 return "SHOW COLUMNS FROM ".$table;
350 }
351
352 // --------------------------------------------------------------------
353
354 /**
355 * Field data query
356 *
357 * Generates a platform-specific query so that the column data can be retrieved
358 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 * @param string the table name
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200360 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200362 protected function _field_data($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000363 {
364 return "SELECT TOP 1 FROM ".$table;
365 }
366
367 // --------------------------------------------------------------------
368
369 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200370 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000371 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200372 * Returns an array containing code and message of the last
373 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200375 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200377 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000378 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200379 return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 }
381
382 // --------------------------------------------------------------------
383
384 /**
385 * Escape the SQL Identifiers
386 *
387 * This function escapes column and table names
388 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 * @param string
390 * @return string
391 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200392 public function _escape_identifiers($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000393 {
394 if ($this->_escape_char == '')
395 {
396 return $item;
397 }
398
399 foreach ($this->_reserved_identifiers as $id)
400 {
401 if (strpos($item, '.'.$id) !== FALSE)
402 {
Barry Mienydd671972010-10-04 16:33:58 +0200403 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
404
Derek Allard2067d1a2008-11-13 22:59:24 +0000405 // remove duplicates if the user already included the escape
406 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200407 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000408 }
Barry Mienydd671972010-10-04 16:33:58 +0200409
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 if (strpos($item, '.') !== FALSE)
411 {
Barry Mienydd671972010-10-04 16:33:58 +0200412 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 }
414 else
415 {
416 $str = $this->_escape_char.$item.$this->_escape_char;
417 }
Barry Mienydd671972010-10-04 16:33:58 +0200418
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 // remove duplicates if the user already included the escape
420 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
421 }
Barry Mienydd671972010-10-04 16:33:58 +0200422
Derek Allard2067d1a2008-11-13 22:59:24 +0000423 // --------------------------------------------------------------------
424
425 /**
426 * From Tables
427 *
428 * This function implicitly groups FROM tables so there is no confusion
429 * about operator precedence in harmony with SQL standards
430 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200431 * @param array
432 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200434 protected function _from_tables($tables)
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 {
436 if ( ! is_array($tables))
437 {
438 $tables = array($tables);
439 }
Barry Mienydd671972010-10-04 16:33:58 +0200440
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 return '('.implode(', ', $tables).')';
442 }
443
444 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200445
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 /**
447 * Insert statement
448 *
449 * Generates a platform-specific insert string from the supplied data
450 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 * @param string the table name
452 * @param array the insert keys
453 * @param array the insert values
454 * @return string
455 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200456 protected function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200457 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
459 }
Barry Mienydd671972010-10-04 16:33:58 +0200460
Derek Allard2067d1a2008-11-13 22:59:24 +0000461 // --------------------------------------------------------------------
462
463 /**
464 * Update statement
465 *
466 * Generates a platform-specific update string from the supplied data
467 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000468 * @param string the table name
469 * @param array the update data
470 * @param array the where clause
471 * @param array the orderby clause
472 * @param array the limit clause
473 * @return string
474 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200475 protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000476 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500477 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 {
479 $valstr[] = $key." = ".$val;
480 }
Barry Mienydd671972010-10-04 16:33:58 +0200481
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200483
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200485
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
487
488 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
489
490 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200491
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 return $sql;
493 }
494
Barry Mienydd671972010-10-04 16:33:58 +0200495
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 // --------------------------------------------------------------------
497
498 /**
499 * Truncate statement
500 *
501 * Generates a platform-specific truncate string from the supplied data
502 * If the database does not support the truncate() command
503 * This function maps to "DELETE FROM table"
504 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000505 * @param string the table name
506 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200507 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200508 protected function _truncate($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000509 {
510 return $this->_delete($table);
511 }
Barry Mienydd671972010-10-04 16:33:58 +0200512
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 // --------------------------------------------------------------------
514
515 /**
516 * Delete statement
517 *
518 * Generates a platform-specific delete string from the supplied data
519 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 * @param string the table name
521 * @param array the where clause
522 * @param string the limit clause
523 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200524 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200525 protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000526 {
527 $conditions = '';
528
529 if (count($where) > 0 OR count($like) > 0)
530 {
531 $conditions = "\nWHERE ";
532 $conditions .= implode("\n", $this->ar_where);
533
534 if (count($where) > 0 && count($like) > 0)
535 {
536 $conditions .= " AND ";
537 }
538 $conditions .= implode("\n", $like);
539 }
540
541 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200542
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 return "DELETE FROM ".$table.$conditions.$limit;
544 }
545
546 // --------------------------------------------------------------------
547
548 /**
549 * Limit string
550 *
551 * Generates a platform-specific LIMIT clause
552 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 * @param string the sql query string
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200554 * @param int the number of rows to limit the query to
555 * @param int the offset value
Derek Allard2067d1a2008-11-13 22:59:24 +0000556 * @return string
557 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200558 protected function _limit($sql, $limit, $offset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000559 {
560 // Does ODBC doesn't use the LIMIT clause?
561 return $sql;
562 }
563
564 // --------------------------------------------------------------------
565
566 /**
567 * Close DB Connection
568 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000569 * @param resource
570 * @return void
571 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200572 protected function _close($conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000573 {
574 @odbc_close($conn_id);
575 }
576
Derek Allard2067d1a2008-11-13 22:59:24 +0000577}
578
Derek Allard2067d1a2008-11-13 22:59:24 +0000579/* End of file odbc_driver.php */
Andrey Andreev063f5962012-02-27 12:20:52 +0200580/* Location: ./system/database/drivers/odbc/odbc_driver.php */