blob: ad773117f192952064ab2de699be42f2a6ad8a8b [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 /**
98 * Select the database
99 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000100 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200101 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200102 public function db_select()
Derek Allard2067d1a2008-11-13 22:59:24 +0000103 {
104 // Not needed for ODBC
105 return TRUE;
106 }
107
108 // --------------------------------------------------------------------
109
110 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000111 * Execute the query
112 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000113 * @param string an SQL query
114 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200115 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200116 protected function _execute($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000117 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 return @odbc_exec($this->conn_id, $sql);
119 }
Barry Mienydd671972010-10-04 16:33:58 +0200120
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 // --------------------------------------------------------------------
122
123 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000124 * Begin Transaction
125 *
Barry Mienydd671972010-10-04 16:33:58 +0200126 * @return bool
127 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200128 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 {
130 if ( ! $this->trans_enabled)
131 {
132 return TRUE;
133 }
Barry Mienydd671972010-10-04 16:33:58 +0200134
Derek Allard2067d1a2008-11-13 22:59:24 +0000135 // When transactions are nested we only begin/commit/rollback the outermost ones
136 if ($this->_trans_depth > 0)
137 {
138 return TRUE;
139 }
140
141 // Reset the transaction failure flag.
142 // If the $test_mode flag is set to TRUE transactions will be rolled back
143 // even if the queries produce a successful result.
144 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
145
146 return odbc_autocommit($this->conn_id, FALSE);
147 }
148
149 // --------------------------------------------------------------------
150
151 /**
152 * Commit Transaction
153 *
Barry Mienydd671972010-10-04 16:33:58 +0200154 * @return bool
155 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200156 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 {
158 if ( ! $this->trans_enabled)
159 {
160 return TRUE;
161 }
162
163 // When transactions are nested we only begin/commit/rollback the outermost ones
164 if ($this->_trans_depth > 0)
165 {
166 return TRUE;
167 }
168
169 $ret = odbc_commit($this->conn_id);
170 odbc_autocommit($this->conn_id, TRUE);
171 return $ret;
172 }
173
174 // --------------------------------------------------------------------
175
176 /**
177 * Rollback Transaction
178 *
Barry Mienydd671972010-10-04 16:33:58 +0200179 * @return bool
180 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200181 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 {
183 if ( ! $this->trans_enabled)
184 {
185 return TRUE;
186 }
187
188 // When transactions are nested we only begin/commit/rollback the outermost ones
189 if ($this->_trans_depth > 0)
190 {
191 return TRUE;
192 }
193
194 $ret = odbc_rollback($this->conn_id);
195 odbc_autocommit($this->conn_id, TRUE);
196 return $ret;
197 }
198
199 // --------------------------------------------------------------------
200
201 /**
202 * Escape String
203 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000205 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 * @return string
207 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200208 public function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000210 if (is_array($str))
211 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500212 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200213 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000214 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200215 }
216
217 return $str;
218 }
219
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 // ODBC doesn't require escaping
Greg Aker757dda62010-04-14 19:06:19 -0500221 $str = remove_invisible_characters($str);
Barry Mienydd671972010-10-04 16:33:58 +0200222
Derek Jonese4ed5832009-02-20 21:44:59 +0000223 // escape LIKE condition wildcards
224 if ($like === TRUE)
225 {
Andrey Andreev6ea625e2012-03-20 14:46:27 +0200226 return str_replace(array($this->_like_escape_chr, '%', '_'),
Andrey Andreevf1bda682012-03-20 14:35:06 +0200227 array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
228 $str);
Derek Jonese4ed5832009-02-20 21:44:59 +0000229 }
Barry Mienydd671972010-10-04 16:33:58 +0200230
Derek Jonese4ed5832009-02-20 21:44:59 +0000231 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 }
Barry Mienydd671972010-10-04 16:33:58 +0200233
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 // --------------------------------------------------------------------
235
236 /**
237 * Affected Rows
238 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200239 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000240 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200241 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000242 {
243 return @odbc_num_rows($this->conn_id);
244 }
Barry Mienydd671972010-10-04 16:33:58 +0200245
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 // --------------------------------------------------------------------
247
248 /**
249 * Insert ID
250 *
Andrey Andreev8af76662012-03-05 14:33:41 +0200251 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 */
Andrey Andreev8af76662012-03-05 14:33:41 +0200253 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 {
Andrey Andreev8af76662012-03-05 14:33:41 +0200255 return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 }
257
258 // --------------------------------------------------------------------
259
260 /**
261 * "Count All" query
262 *
263 * Generates a platform-specific query string that counts all records in
264 * the specified database
265 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000266 * @param string
267 * @return string
268 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200269 public function count_all($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 {
271 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000272 {
273 return 0;
274 }
275
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200276 $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 +0000277
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000279 {
280 return 0;
281 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000282
283 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500284 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000285 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000286 }
287
288 // --------------------------------------------------------------------
289
290 /**
291 * Show table query
292 *
293 * Generates a platform-specific query string so that the table names can be fetched
294 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200295 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 * @return string
297 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200298 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000299 {
300 $sql = "SHOW TABLES FROM `".$this->database."`";
301
302 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
303 {
Greg Aker0d424892010-01-26 02:14:44 +0000304 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 return FALSE; // not currently supported
306 }
Barry Mienydd671972010-10-04 16:33:58 +0200307
Derek Allard2067d1a2008-11-13 22:59:24 +0000308 return $sql;
309 }
Barry Mienydd671972010-10-04 16:33:58 +0200310
Derek Allard2067d1a2008-11-13 22:59:24 +0000311 // --------------------------------------------------------------------
312
313 /**
314 * Show column query
315 *
316 * Generates a platform-specific query string so that the column names can be fetched
317 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 * @param string the table name
319 * @return string
320 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200321 protected function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 {
323 return "SHOW COLUMNS FROM ".$table;
324 }
325
326 // --------------------------------------------------------------------
327
328 /**
329 * Field data query
330 *
331 * Generates a platform-specific query so that the column data can be retrieved
332 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 * @param string the table name
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200334 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200336 protected function _field_data($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 {
338 return "SELECT TOP 1 FROM ".$table;
339 }
340
341 // --------------------------------------------------------------------
342
343 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200344 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200346 * Returns an array containing code and message of the last
347 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200349 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200351 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000352 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200353 return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 }
355
356 // --------------------------------------------------------------------
357
358 /**
359 * Escape the SQL Identifiers
360 *
Timothy Warren9e560a42012-03-19 19:06:46 -0400361 * This function escapes column and table names
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000363 * @param string
364 * @return string
365 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200366 public function _escape_identifiers($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000367 {
368 if ($this->_escape_char == '')
369 {
370 return $item;
371 }
372
373 foreach ($this->_reserved_identifiers as $id)
374 {
375 if (strpos($item, '.'.$id) !== FALSE)
376 {
Barry Mienydd671972010-10-04 16:33:58 +0200377 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
378
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 // remove duplicates if the user already included the escape
380 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200381 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000382 }
Barry Mienydd671972010-10-04 16:33:58 +0200383
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 if (strpos($item, '.') !== FALSE)
385 {
Barry Mienydd671972010-10-04 16:33:58 +0200386 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000387 }
388 else
389 {
390 $str = $this->_escape_char.$item.$this->_escape_char;
391 }
Barry Mienydd671972010-10-04 16:33:58 +0200392
Derek Allard2067d1a2008-11-13 22:59:24 +0000393 // remove duplicates if the user already included the escape
394 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
395 }
Barry Mienydd671972010-10-04 16:33:58 +0200396
Derek Allard2067d1a2008-11-13 22:59:24 +0000397 // --------------------------------------------------------------------
398
399 /**
400 * From Tables
401 *
Timothy Warren9e560a42012-03-19 19:06:46 -0400402 * This function implicitly groups FROM tables so there is no confusion
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 * about operator precedence in harmony with SQL standards
404 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200405 * @param array
406 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000407 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200408 protected function _from_tables($tables)
Derek Allard2067d1a2008-11-13 22:59:24 +0000409 {
410 if ( ! is_array($tables))
411 {
412 $tables = array($tables);
413 }
Barry Mienydd671972010-10-04 16:33:58 +0200414
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 return '('.implode(', ', $tables).')';
416 }
417
418 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200419
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 /**
421 * Insert statement
422 *
423 * Generates a platform-specific insert string from the supplied data
424 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 * @param string the table name
426 * @param array the insert keys
427 * @param array the insert values
428 * @return string
429 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200430 protected function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200431 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000432 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
433 }
Barry Mienydd671972010-10-04 16:33:58 +0200434
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 // --------------------------------------------------------------------
436
437 /**
438 * Update statement
439 *
440 * Generates a platform-specific update string from the supplied data
441 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 * @param string the table name
443 * @param array the update data
444 * @param array the where clause
445 * @param array the orderby clause
446 * @param array the limit clause
447 * @return string
448 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200449 protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500451 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 {
453 $valstr[] = $key." = ".$val;
454 }
Barry Mienydd671972010-10-04 16:33:58 +0200455
Derek Allard2067d1a2008-11-13 22:59:24 +0000456 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200457
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200459
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
461
462 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
463
464 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200465
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 return $sql;
467 }
468
Barry Mienydd671972010-10-04 16:33:58 +0200469
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 // --------------------------------------------------------------------
471
472 /**
473 * Truncate statement
474 *
475 * Generates a platform-specific truncate string from the supplied data
476 * If the database does not support the truncate() command
Timothy Warren9e560a42012-03-19 19:06:46 -0400477 * This function maps to "DELETE FROM table"
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 * @param string the table name
480 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200481 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200482 protected function _truncate($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 {
484 return $this->_delete($table);
485 }
Barry Mienydd671972010-10-04 16:33:58 +0200486
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 // --------------------------------------------------------------------
488
489 /**
490 * Delete statement
491 *
492 * Generates a platform-specific delete string from the supplied data
493 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000494 * @param string the table name
495 * @param array the where clause
496 * @param string the limit clause
497 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200498 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200499 protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000500 {
501 $conditions = '';
502
503 if (count($where) > 0 OR count($like) > 0)
504 {
505 $conditions = "\nWHERE ";
506 $conditions .= implode("\n", $this->ar_where);
507
508 if (count($where) > 0 && count($like) > 0)
509 {
510 $conditions .= " AND ";
511 }
512 $conditions .= implode("\n", $like);
513 }
514
515 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200516
Derek Allard2067d1a2008-11-13 22:59:24 +0000517 return "DELETE FROM ".$table.$conditions.$limit;
518 }
519
520 // --------------------------------------------------------------------
521
522 /**
523 * Limit string
524 *
525 * Generates a platform-specific LIMIT clause
526 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000527 * @param string the sql query string
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200528 * @param int the number of rows to limit the query to
529 * @param int the offset value
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 * @return string
531 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200532 protected function _limit($sql, $limit, $offset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000533 {
534 // Does ODBC doesn't use the LIMIT clause?
535 return $sql;
536 }
537
538 // --------------------------------------------------------------------
539
540 /**
541 * Close DB Connection
542 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 * @param resource
544 * @return void
545 */
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200546 protected function _close($conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000547 {
548 @odbc_close($conn_id);
549 }
Timothy Warren9e560a42012-03-19 19:06:46 -0400550
Derek Allard2067d1a2008-11-13 22:59:24 +0000551}
552
Derek Allard2067d1a2008-11-13 22:59:24 +0000553/* End of file odbc_driver.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400554/* Location: ./system/database/drivers/odbc/odbc_driver.php */