blob: ed901bd81c75f1ed4a228feb716358a91d222e6f [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
Andrey Andreev5f356bf2012-03-20 14:32:27 +020060 public function __construct($params)
Derek Allard2067d1a2008-11-13 22:59:24 +000061 {
Timothy Warrena2097a02011-10-10 10:10:46 -040062 parent::__construct($params);
Barry Mienydd671972010-10-04 16:33:58 +020063
Derek Allard2067d1a2008-11-13 22:59:24 +000064 $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
Andrey Andreev9a1fc202012-03-26 12:38:34 +030065
66 // Legacy support for DSN in the hostname field
67 if ($this->dsn == '')
68 {
69 $this->dsn = $this->hostname;
70 }
Derek Allard2067d1a2008-11-13 22:59:24 +000071 }
72
73 /**
74 * Non-persistent database connection
75 *
Derek Allard2067d1a2008-11-13 22:59:24 +000076 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020077 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +020078 public function db_connect()
Derek Allard2067d1a2008-11-13 22:59:24 +000079 {
Andrey Andreev9a1fc202012-03-26 12:38:34 +030080 return @odbc_connect($this->dsn, $this->username, $this->password);
Derek Allard2067d1a2008-11-13 22:59:24 +000081 }
Barry Mienydd671972010-10-04 16:33:58 +020082
Derek Allard2067d1a2008-11-13 22:59:24 +000083 // --------------------------------------------------------------------
84
85 /**
86 * Persistent database connection
87 *
Derek Allard2067d1a2008-11-13 22:59:24 +000088 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020089 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +020090 public function db_pconnect()
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
Andrey Andreev9a1fc202012-03-26 12:38:34 +030092 return @odbc_pconnect($this->dsn, $this->username, $this->password);
Derek Allard2067d1a2008-11-13 22:59:24 +000093 }
Barry Mienydd671972010-10-04 16:33:58 +020094
Derek Allard2067d1a2008-11-13 22:59:24 +000095 // --------------------------------------------------------------------
96
97 /**
Derek Allard2067d1a2008-11-13 22:59:24 +000098 * Execute the query
99 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000100 * @param string an SQL query
101 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200102 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200103 protected function _execute($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000104 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000105 return @odbc_exec($this->conn_id, $sql);
106 }
Barry Mienydd671972010-10-04 16:33:58 +0200107
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 // --------------------------------------------------------------------
109
110 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 * Begin Transaction
112 *
Barry Mienydd671972010-10-04 16:33:58 +0200113 * @return bool
114 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200115 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 {
117 if ( ! $this->trans_enabled)
118 {
119 return TRUE;
120 }
Barry Mienydd671972010-10-04 16:33:58 +0200121
Derek Allard2067d1a2008-11-13 22:59:24 +0000122 // When transactions are nested we only begin/commit/rollback the outermost ones
123 if ($this->_trans_depth > 0)
124 {
125 return TRUE;
126 }
127
128 // Reset the transaction failure flag.
129 // If the $test_mode flag is set to TRUE transactions will be rolled back
130 // even if the queries produce a successful result.
131 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
132
133 return odbc_autocommit($this->conn_id, FALSE);
134 }
135
136 // --------------------------------------------------------------------
137
138 /**
139 * Commit Transaction
140 *
Barry Mienydd671972010-10-04 16:33:58 +0200141 * @return bool
142 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200143 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000144 {
145 if ( ! $this->trans_enabled)
146 {
147 return TRUE;
148 }
149
150 // When transactions are nested we only begin/commit/rollback the outermost ones
151 if ($this->_trans_depth > 0)
152 {
153 return TRUE;
154 }
155
156 $ret = odbc_commit($this->conn_id);
157 odbc_autocommit($this->conn_id, TRUE);
158 return $ret;
159 }
160
161 // --------------------------------------------------------------------
162
163 /**
164 * Rollback Transaction
165 *
Barry Mienydd671972010-10-04 16:33:58 +0200166 * @return bool
167 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200168 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 {
170 if ( ! $this->trans_enabled)
171 {
172 return TRUE;
173 }
174
175 // When transactions are nested we only begin/commit/rollback the outermost ones
176 if ($this->_trans_depth > 0)
177 {
178 return TRUE;
179 }
180
181 $ret = odbc_rollback($this->conn_id);
182 odbc_autocommit($this->conn_id, TRUE);
183 return $ret;
184 }
185
186 // --------------------------------------------------------------------
187
188 /**
189 * Escape String
190 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000192 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 * @return string
194 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200195 public function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000196 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000197 if (is_array($str))
198 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500199 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200200 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000201 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200202 }
203
204 return $str;
205 }
206
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 // ODBC doesn't require escaping
Greg Aker757dda62010-04-14 19:06:19 -0500208 $str = remove_invisible_characters($str);
Barry Mienydd671972010-10-04 16:33:58 +0200209
Derek Jonese4ed5832009-02-20 21:44:59 +0000210 // escape LIKE condition wildcards
211 if ($like === TRUE)
212 {
Andrey Andreev6ea625e2012-03-20 14:46:27 +0200213 return str_replace(array($this->_like_escape_chr, '%', '_'),
Andrey Andreevf1bda682012-03-20 14:35:06 +0200214 array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
215 $str);
Derek Jonese4ed5832009-02-20 21:44:59 +0000216 }
Barry Mienydd671972010-10-04 16:33:58 +0200217
Derek Jonese4ed5832009-02-20 21:44:59 +0000218 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 }
Barry Mienydd671972010-10-04 16:33:58 +0200220
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 // --------------------------------------------------------------------
222
223 /**
224 * Affected Rows
225 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200226 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000227 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200228 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 {
230 return @odbc_num_rows($this->conn_id);
231 }
Barry Mienydd671972010-10-04 16:33:58 +0200232
Derek Allard2067d1a2008-11-13 22:59:24 +0000233 // --------------------------------------------------------------------
234
235 /**
236 * Insert ID
237 *
Andrey Andreev8af76662012-03-05 14:33:41 +0200238 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 */
Andrey Andreev8af76662012-03-05 14:33:41 +0200240 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 {
Andrey Andreev8af76662012-03-05 14:33:41 +0200242 return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 }
244
245 // --------------------------------------------------------------------
246
247 /**
248 * "Count All" query
249 *
250 * Generates a platform-specific query string that counts all records in
251 * the specified database
252 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 * @param string
254 * @return string
255 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200256 public function count_all($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 {
258 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000259 {
260 return 0;
261 }
262
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200263 $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 +0000264
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000266 {
267 return 0;
268 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000269
270 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500271 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000272 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 }
274
275 // --------------------------------------------------------------------
276
277 /**
278 * Show table query
279 *
280 * Generates a platform-specific query string so that the table names can be fetched
281 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200282 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 * @return string
284 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200285 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000286 {
287 $sql = "SHOW TABLES FROM `".$this->database."`";
288
289 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
290 {
Greg Aker0d424892010-01-26 02:14:44 +0000291 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 return FALSE; // not currently supported
293 }
Barry Mienydd671972010-10-04 16:33:58 +0200294
Derek Allard2067d1a2008-11-13 22:59:24 +0000295 return $sql;
296 }
Barry Mienydd671972010-10-04 16:33:58 +0200297
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 // --------------------------------------------------------------------
299
300 /**
301 * Show column query
302 *
303 * Generates a platform-specific query string so that the column names can be fetched
304 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 * @param string the table name
306 * @return string
307 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200308 protected function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000309 {
310 return "SHOW COLUMNS FROM ".$table;
311 }
312
313 // --------------------------------------------------------------------
314
315 /**
316 * Field data query
317 *
318 * Generates a platform-specific query so that the column data can be retrieved
319 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000320 * @param string the table name
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200321 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200323 protected function _field_data($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 {
325 return "SELECT TOP 1 FROM ".$table;
326 }
327
328 // --------------------------------------------------------------------
329
330 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200331 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200333 * Returns an array containing code and message of the last
334 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200336 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200338 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000339 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200340 return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 }
342
343 // --------------------------------------------------------------------
344
345 /**
346 * Escape the SQL Identifiers
347 *
Timothy Warren9e560a42012-03-19 19:06:46 -0400348 * This function escapes column and table names
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 * @param string
351 * @return string
352 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200353 public function _escape_identifiers($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 {
355 if ($this->_escape_char == '')
356 {
357 return $item;
358 }
359
360 foreach ($this->_reserved_identifiers as $id)
361 {
362 if (strpos($item, '.'.$id) !== FALSE)
363 {
Barry Mienydd671972010-10-04 16:33:58 +0200364 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
365
Derek Allard2067d1a2008-11-13 22:59:24 +0000366 // remove duplicates if the user already included the escape
367 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200368 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 }
Barry Mienydd671972010-10-04 16:33:58 +0200370
Derek Allard2067d1a2008-11-13 22:59:24 +0000371 if (strpos($item, '.') !== FALSE)
372 {
Barry Mienydd671972010-10-04 16:33:58 +0200373 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 }
375 else
376 {
377 $str = $this->_escape_char.$item.$this->_escape_char;
378 }
Barry Mienydd671972010-10-04 16:33:58 +0200379
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 // remove duplicates if the user already included the escape
381 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
382 }
Barry Mienydd671972010-10-04 16:33:58 +0200383
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 // --------------------------------------------------------------------
385
386 /**
387 * From Tables
388 *
Timothy Warren9e560a42012-03-19 19:06:46 -0400389 * This function implicitly groups FROM tables so there is no confusion
Derek Allard2067d1a2008-11-13 22:59:24 +0000390 * about operator precedence in harmony with SQL standards
391 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200392 * @param array
393 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200395 protected function _from_tables($tables)
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 {
397 if ( ! is_array($tables))
398 {
399 $tables = array($tables);
400 }
Barry Mienydd671972010-10-04 16:33:58 +0200401
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 return '('.implode(', ', $tables).')';
403 }
404
405 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200406
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 /**
408 * Insert statement
409 *
410 * Generates a platform-specific insert string from the supplied data
411 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 * @param string the table name
413 * @param array the insert keys
414 * @param array the insert values
415 * @return string
416 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200417 protected function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200418 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
420 }
Barry Mienydd671972010-10-04 16:33:58 +0200421
Derek Allard2067d1a2008-11-13 22:59:24 +0000422 // --------------------------------------------------------------------
423
424 /**
425 * Update statement
426 *
427 * Generates a platform-specific update string from the supplied data
428 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 * @param string the table name
430 * @param array the update data
431 * @param array the where clause
432 * @param array the orderby clause
433 * @param array the limit clause
434 * @return string
435 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200436 protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000437 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500438 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 {
440 $valstr[] = $key." = ".$val;
441 }
Barry Mienydd671972010-10-04 16:33:58 +0200442
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200444
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200446
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
448
449 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
450
451 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200452
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 return $sql;
454 }
455
Barry Mienydd671972010-10-04 16:33:58 +0200456
Derek Allard2067d1a2008-11-13 22:59:24 +0000457 // --------------------------------------------------------------------
458
459 /**
460 * Truncate statement
461 *
462 * Generates a platform-specific truncate string from the supplied data
463 * If the database does not support the truncate() command
Timothy Warren9e560a42012-03-19 19:06:46 -0400464 * This function maps to "DELETE FROM table"
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 * @param string the table name
467 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200468 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200469 protected function _truncate($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 {
471 return $this->_delete($table);
472 }
Barry Mienydd671972010-10-04 16:33:58 +0200473
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 // --------------------------------------------------------------------
475
476 /**
477 * Delete statement
478 *
479 * Generates a platform-specific delete string from the supplied data
480 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 * @param string the table name
482 * @param array the where clause
483 * @param string the limit clause
484 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200485 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200486 protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 {
488 $conditions = '';
489
490 if (count($where) > 0 OR count($like) > 0)
491 {
492 $conditions = "\nWHERE ";
493 $conditions .= implode("\n", $this->ar_where);
494
495 if (count($where) > 0 && count($like) > 0)
496 {
497 $conditions .= " AND ";
498 }
499 $conditions .= implode("\n", $like);
500 }
501
502 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200503
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 return "DELETE FROM ".$table.$conditions.$limit;
505 }
506
507 // --------------------------------------------------------------------
508
509 /**
510 * Limit string
511 *
512 * Generates a platform-specific LIMIT clause
513 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 * @param string the sql query string
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200515 * @param int the number of rows to limit the query to
516 * @param int the offset value
Derek Allard2067d1a2008-11-13 22:59:24 +0000517 * @return string
518 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200519 protected function _limit($sql, $limit, $offset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 {
521 // Does ODBC doesn't use the LIMIT clause?
522 return $sql;
523 }
524
525 // --------------------------------------------------------------------
526
527 /**
528 * Close DB Connection
529 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 * @param resource
531 * @return void
532 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200533 protected function _close($conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000534 {
535 @odbc_close($conn_id);
536 }
Timothy Warren9e560a42012-03-19 19:06:46 -0400537
Derek Allard2067d1a2008-11-13 22:59:24 +0000538}
539
Derek Allard2067d1a2008-11-13 22:59:24 +0000540/* End of file odbc_driver.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400541/* Location: ./system/database/drivers/odbc/odbc_driver.php */