blob: f7785182114057ca00ed755df7c81fa2d76136bf [file] [log] [blame]
Andrey Andreevb76029d2012-01-26 15:13:19 +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 Andreevb76029d2012-01-26 15:13:19 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreevb76029d2012-01-26 15:13:19 +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 Andreevb76029d2012-01-26 15:13:19 +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 Andreevb76029d2012-01-26 15:13:19 +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'} ";
Andrey Andreevb76029d2012-01-26 15:13:19 +020050 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 Andreevb76029d2012-01-26 15:13:19 +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 Andreev46f6dbc2012-02-13 01:39:53 +020065
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 Andreevb76029d2012-01-26 15:13:19 +020078 public function db_connect()
Derek Allard2067d1a2008-11-13 22:59:24 +000079 {
Andrey Andreev46f6dbc2012-02-13 01:39:53 +020080 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 Andreevb76029d2012-01-26 15:13:19 +020090 public function db_pconnect()
Derek Allard2067d1a2008-11-13 22:59:24 +000091 {
Andrey Andreev46f6dbc2012-02-13 01:39:53 +020092 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 Andreevb76029d2012-01-26 15:13:19 +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 Andreevb76029d2012-01-26 15:13:19 +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);
Derek Allard2067d1a2008-11-13 22:59:24 +0000119 }
120
121 // --------------------------------------------------------------------
122
123 /**
124 * Begin Transaction
125 *
Barry Mienydd671972010-10-04 16:33:58 +0200126 * @return bool
127 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200128 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000129 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreevb76029d2012-01-26 15:13:19 +0200131 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 {
133 return TRUE;
134 }
135
136 // Reset the transaction failure flag.
137 // If the $test_mode flag is set to TRUE transactions will be rolled back
138 // even if the queries produce a successful result.
Andrey Andreevb76029d2012-01-26 15:13:19 +0200139 $this->_trans_failure = ($test_mode === TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000140
141 return odbc_autocommit($this->conn_id, FALSE);
142 }
143
144 // --------------------------------------------------------------------
145
146 /**
147 * Commit Transaction
148 *
Barry Mienydd671972010-10-04 16:33:58 +0200149 * @return bool
150 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200151 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000152 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreevb76029d2012-01-26 15:13:19 +0200154 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 {
156 return TRUE;
157 }
158
159 $ret = odbc_commit($this->conn_id);
160 odbc_autocommit($this->conn_id, TRUE);
161 return $ret;
162 }
163
164 // --------------------------------------------------------------------
165
166 /**
167 * Rollback Transaction
168 *
Barry Mienydd671972010-10-04 16:33:58 +0200169 * @return bool
170 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200171 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 // When transactions are nested we only begin/commit/rollback the outermost ones
Andrey Andreevb76029d2012-01-26 15:13:19 +0200174 if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 {
176 return TRUE;
177 }
178
179 $ret = odbc_rollback($this->conn_id);
180 odbc_autocommit($this->conn_id, TRUE);
181 return $ret;
182 }
183
184 // --------------------------------------------------------------------
185
186 /**
187 * Escape String
188 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000190 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 * @return string
192 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200193 public function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000195 if (is_array($str))
196 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500197 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200198 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000199 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200200 }
201
202 return $str;
203 }
204
Greg Aker757dda62010-04-14 19:06:19 -0500205 $str = remove_invisible_characters($str);
Barry Mienydd671972010-10-04 16:33:58 +0200206
Derek Jonese4ed5832009-02-20 21:44:59 +0000207 // escape LIKE condition wildcards
208 if ($like === TRUE)
209 {
Andrey Andreev5e18e892012-03-09 14:25:00 +0200210 return str_replace(array($this->_like_escape_chr, '%', '_'),
211 array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
Andrey Andreevb76029d2012-01-26 15:13:19 +0200212 $str);
Derek Jonese4ed5832009-02-20 21:44:59 +0000213 }
Barry Mienydd671972010-10-04 16:33:58 +0200214
Derek Jonese4ed5832009-02-20 21:44:59 +0000215 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000216 }
Barry Mienydd671972010-10-04 16:33:58 +0200217
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 // --------------------------------------------------------------------
219
220 /**
221 * Affected Rows
222 *
Andrey Andreevb76029d2012-01-26 15:13:19 +0200223 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000224 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200225 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000226 {
227 return @odbc_num_rows($this->conn_id);
228 }
Barry Mienydd671972010-10-04 16:33:58 +0200229
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 // --------------------------------------------------------------------
231
232 /**
233 * Insert ID
234 *
Andrey Andreev8af76662012-03-05 14:33:41 +0200235 * @return bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200237 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 {
Andrey Andreev8af76662012-03-05 14:33:41 +0200239 return ($this->db->db_debug) ? $this->db->display_error('db_unsuported_feature') : FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000240 }
241
242 // --------------------------------------------------------------------
243
244 /**
245 * "Count All" query
246 *
247 * Generates a platform-specific query string that counts all records in
248 * the specified database
249 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000250 * @param string
Andrey Andreevb76029d2012-01-26 15:13:19 +0200251 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200253 public function count_all($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000254 {
255 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000256 {
257 return 0;
258 }
259
Andrey Andreev97715482012-03-09 14:21:54 +0200260 $query = $this->query($this->_count_string.$this->protect_identifiers('numrows').' FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE));
Derek Allard2067d1a2008-11-13 22:59:24 +0000261 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000262 {
263 return 0;
264 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000265
Andrey Andreevb76029d2012-01-26 15:13:19 +0200266 $query = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500267 $this->_reset_select();
Andrey Andreevb76029d2012-01-26 15:13:19 +0200268 return (int) $query->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 }
270
271 // --------------------------------------------------------------------
272
273 /**
274 * Show table query
275 *
276 * Generates a platform-specific query string so that the table names can be fetched
277 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200278 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000279 * @return string
280 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200281 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000282 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200283 $sql = 'SHOW TABLES FROM `'.$this->database.'`';
Derek Allard2067d1a2008-11-13 22:59:24 +0000284
Andrey Andreevb76029d2012-01-26 15:13:19 +0200285 if ($prefix_limit !== FALSE && $this->dbprefix != '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000286 {
Greg Aker0d424892010-01-26 02:14:44 +0000287 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 return FALSE; // not currently supported
289 }
Barry Mienydd671972010-10-04 16:33:58 +0200290
Derek Allard2067d1a2008-11-13 22:59:24 +0000291 return $sql;
292 }
Barry Mienydd671972010-10-04 16:33:58 +0200293
Derek Allard2067d1a2008-11-13 22:59:24 +0000294 // --------------------------------------------------------------------
295
296 /**
297 * Show column query
298 *
299 * Generates a platform-specific query string so that the column names can be fetched
300 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 * @param string the table name
302 * @return string
303 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200304 protected function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200306 return 'SHOW COLUMNS FROM '.$table;
Derek Allard2067d1a2008-11-13 22:59:24 +0000307 }
308
309 // --------------------------------------------------------------------
310
311 /**
312 * Field data query
313 *
314 * Generates a platform-specific query so that the column data can be retrieved
315 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 * @param string the table name
Andrey Andreevb76029d2012-01-26 15:13:19 +0200317 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200319 protected function _field_data($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000320 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200321 return 'SELECT TOP 1 FROM '.$table;
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 }
323
324 // --------------------------------------------------------------------
325
326 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200327 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200329 * Returns an array containing code and message of the last
330 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200332 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000333 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200334 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200336 return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
Derek Allard2067d1a2008-11-13 22:59:24 +0000337 }
338
339 // --------------------------------------------------------------------
340
341 /**
342 * Escape the SQL Identifiers
343 *
344 * This function escapes column and table names
345 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000346 * @param string
347 * @return string
348 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200349 public function _escape_identifiers($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 {
351 if ($this->_escape_char == '')
352 {
353 return $item;
354 }
355
356 foreach ($this->_reserved_identifiers as $id)
357 {
358 if (strpos($item, '.'.$id) !== FALSE)
359 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200360 $item = str_replace('.', $this->_escape_char.'.', $item);
Barry Mienydd671972010-10-04 16:33:58 +0200361
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 // remove duplicates if the user already included the escape
Andrey Andreevb76029d2012-01-26 15:13:19 +0200363 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item);
Barry Mienydd671972010-10-04 16:33:58 +0200364 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000365 }
Barry Mienydd671972010-10-04 16:33:58 +0200366
Derek Allard2067d1a2008-11-13 22:59:24 +0000367 if (strpos($item, '.') !== FALSE)
368 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200369 $item = str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item);
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 }
Barry Mienydd671972010-10-04 16:33:58 +0200371
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 // remove duplicates if the user already included the escape
Andrey Andreevb76029d2012-01-26 15:13:19 +0200373 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $this->_escape_char.$item.$this->_escape_char);
Derek Allard2067d1a2008-11-13 22:59:24 +0000374 }
Barry Mienydd671972010-10-04 16:33:58 +0200375
Derek Allard2067d1a2008-11-13 22:59:24 +0000376 // --------------------------------------------------------------------
377
378 /**
379 * From Tables
380 *
381 * This function implicitly groups FROM tables so there is no confusion
382 * about operator precedence in harmony with SQL standards
383 *
Andrey Andreev5f356bf2012-03-20 14:32:27 +0200384 * @param array
Andrey Andreevb76029d2012-01-26 15:13:19 +0200385 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000386 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200387 protected function _from_tables($tables)
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 {
389 if ( ! is_array($tables))
390 {
391 $tables = array($tables);
392 }
Barry Mienydd671972010-10-04 16:33:58 +0200393
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 return '('.implode(', ', $tables).')';
395 }
396
397 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200398
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 /**
400 * Insert statement
401 *
402 * Generates a platform-specific insert string from the supplied data
403 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000404 * @param string the table name
405 * @param array the insert keys
406 * @param array the insert values
407 * @return string
408 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200409 protected function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200410 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200411 return 'INSERT INTO '.$table.' ('.implode(', ', $keys).') VALUES ('.implode(', ', $values).')';
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 }
Barry Mienydd671972010-10-04 16:33:58 +0200413
Derek Allard2067d1a2008-11-13 22:59:24 +0000414 // --------------------------------------------------------------------
415
416 /**
417 * Update statement
418 *
419 * Generates a platform-specific update string from the supplied data
420 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000421 * @param string the table name
422 * @param array the update data
423 * @param array the where clause
424 * @param array the orderby clause
425 * @param array the limit clause
426 * @return string
427 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200428 protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500430 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000431 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200432 $valstr[] = $key.' = '.$val;
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 }
Barry Mienydd671972010-10-04 16:33:58 +0200434
Andrey Andreevb76029d2012-01-26 15:13:19 +0200435 return 'UPDATE '.$table.' SET '.implode(', ', $valstr)
436 .(($where != '' && count($where) > 0) ? ' WHERE '.implode(' ', $where) : '')
437 .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '')
438 .( ! $limit ? '' : ' LIMIT '.$limit);
Derek Allard2067d1a2008-11-13 22:59:24 +0000439 }
440
Barry Mienydd671972010-10-04 16:33:58 +0200441
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 // --------------------------------------------------------------------
443
444 /**
445 * Truncate statement
446 *
447 * Generates a platform-specific truncate string from the supplied data
448 * If the database does not support the truncate() command
449 * This function maps to "DELETE FROM table"
450 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 * @param string the table name
452 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200453 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200454 protected function _truncate($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 {
456 return $this->_delete($table);
457 }
Barry Mienydd671972010-10-04 16:33:58 +0200458
Derek Allard2067d1a2008-11-13 22:59:24 +0000459 // --------------------------------------------------------------------
460
461 /**
462 * Delete statement
463 *
464 * Generates a platform-specific delete string from the supplied data
465 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 * @param string the table name
467 * @param array the where clause
468 * @param string the limit clause
469 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200470 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200471 protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 {
473 $conditions = '';
474
475 if (count($where) > 0 OR count($like) > 0)
476 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200477 $conditions = "\nWHERE ".implode("\n", $this->ar_where);
Derek Allard2067d1a2008-11-13 22:59:24 +0000478
479 if (count($where) > 0 && count($like) > 0)
480 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200481 $conditions .= ' AND ';
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 }
483 $conditions .= implode("\n", $like);
484 }
485
Andrey Andreevb76029d2012-01-26 15:13:19 +0200486 return 'DELETE FROM '.$table.$conditions.( ! $limit ? '' : ' LIMIT '.$limit);
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 }
488
489 // --------------------------------------------------------------------
490
491 /**
492 * Limit string
493 *
494 * Generates a platform-specific LIMIT clause
495 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 * @param string the sql query string
Andrey Andreevb76029d2012-01-26 15:13:19 +0200497 * @param int the number of rows to limit the query to
498 * @param int the offset value
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 * @return string
500 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200501 protected function _limit($sql, $limit, $offset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 {
Andrey Andreevb76029d2012-01-26 15:13:19 +0200503 return $sql.($offset == 0 ? '' : $offset.', ').$limit;
Derek Allard2067d1a2008-11-13 22:59:24 +0000504 }
505
506 // --------------------------------------------------------------------
507
508 /**
509 * Close DB Connection
510 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 * @param resource
512 * @return void
513 */
Andrey Andreevb76029d2012-01-26 15:13:19 +0200514 protected function _close($conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 {
516 @odbc_close($conn_id);
517 }
518
Derek Allard2067d1a2008-11-13 22:59:24 +0000519}
520
Derek Allard2067d1a2008-11-13 22:59:24 +0000521/* End of file odbc_driver.php */
Andrey Andreev19aee032012-03-20 15:31:42 +0200522/* Location: ./system/database/drivers/odbc/odbc_driver.php */