blob: 055c9decbdd9480ed5704d091fbdb6fa866f1100 [file] [log] [blame]
Andrey Andreev1f619a82012-03-20 16:03:04 +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 Andreev1f619a82012-03-20 16:03:04 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev1f619a82012-03-20 16:03:04 +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 * MS SQL 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_mssql_driver extends CI_DB {
42
Andrey Andreev1f619a82012-03-20 16:03:04 +020043 public $dbdriver = 'mssql';
Barry Mienydd671972010-10-04 16:33:58 +020044
Derek Allard2067d1a2008-11-13 22:59:24 +000045 // The character used for escaping
Andrey Andreev1f619a82012-03-20 16:03:04 +020046 protected $_escape_char = '';
Derek Jonese4ed5832009-02-20 21:44:59 +000047
48 // clause and character used for LIKE escape sequences
Andrey Andreev1f619a82012-03-20 16:03:04 +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
Andrey Andreev3b2587e2012-03-28 13:39:34 +030055 * used for the count_all() and count_all_results() methods.
Derek Allard2067d1a2008-11-13 22:59:24 +000056 */
Andrey Andreev1f619a82012-03-20 16:03:04 +020057 protected $_count_string = 'SELECT COUNT(*) AS ';
Andrey Andreev3b2587e2012-03-28 13:39:34 +030058 protected $_random_keyword = ' NEWID()';
Derek Allard2067d1a2008-11-13 22:59:24 +000059
60 /**
61 * Non-persistent database connection
62 *
Derek Allard2067d1a2008-11-13 22:59:24 +000063 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020064 */
Andrey Andreev1f619a82012-03-20 16:03:04 +020065 public function db_connect()
Derek Allard2067d1a2008-11-13 22:59:24 +000066 {
67 if ($this->port != '')
68 {
69 $this->hostname .= ','.$this->port;
70 }
71
72 return @mssql_connect($this->hostname, $this->username, $this->password);
73 }
Barry Mienydd671972010-10-04 16:33:58 +020074
Derek Allard2067d1a2008-11-13 22:59:24 +000075 // --------------------------------------------------------------------
76
77 /**
78 * Persistent database connection
79 *
Derek Allard2067d1a2008-11-13 22:59:24 +000080 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020081 */
Andrey Andreev1f619a82012-03-20 16:03:04 +020082 public function db_pconnect()
Derek Allard2067d1a2008-11-13 22:59:24 +000083 {
84 if ($this->port != '')
85 {
86 $this->hostname .= ','.$this->port;
87 }
88
89 return @mssql_pconnect($this->hostname, $this->username, $this->password);
90 }
Barry Mienydd671972010-10-04 16:33:58 +020091
Derek Allard2067d1a2008-11-13 22:59:24 +000092 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020093
Derek Jones87cbafc2009-02-27 16:29:59 +000094 /**
Derek Allard2067d1a2008-11-13 22:59:24 +000095 * Select the database
96 *
Andrey Andreev11454e02012-02-22 16:05:47 +020097 * @param string database name
98 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +020099 */
Andrey Andreev11454e02012-02-22 16:05:47 +0200100 public function db_select($database = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000101 {
Andrey Andreev024ba2d2012-02-24 11:40:36 +0200102 if ($database === '')
103 {
104 $database = $this->database;
105 }
106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 // Note: The brackets are required in the event that the DB name
108 // contains reserved characters
Andrey Andreev024ba2d2012-02-24 11:40:36 +0200109 if (@mssql_select_db('['.$database.']', $this->conn_id))
110 {
111 $this->database = $database;
112 return TRUE;
113 }
114
115 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000116 }
117
118 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200119
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 /**
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 Andreev1f619a82012-03-20 16:03:04 +0200126 protected function _execute($sql)
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 return @mssql_query($sql, $this->conn_id);
129 }
Barry Mienydd671972010-10-04 16:33:58 +0200130
Derek Allard2067d1a2008-11-13 22:59:24 +0000131 // --------------------------------------------------------------------
132
133 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000134 * Begin Transaction
135 *
Barry Mienydd671972010-10-04 16:33:58 +0200136 * @return bool
137 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200138 public function trans_begin($test_mode = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 {
140 if ( ! $this->trans_enabled)
141 {
142 return TRUE;
143 }
Barry Mienydd671972010-10-04 16:33:58 +0200144
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 // When transactions are nested we only begin/commit/rollback the outermost ones
146 if ($this->_trans_depth > 0)
147 {
148 return TRUE;
149 }
150
151 // Reset the transaction failure flag.
152 // If the $test_mode flag is set to TRUE transactions will be rolled back
153 // even if the queries produce a successful result.
154 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
155
156 $this->simple_query('BEGIN TRAN');
157 return TRUE;
158 }
159
160 // --------------------------------------------------------------------
161
162 /**
163 * Commit Transaction
164 *
Barry Mienydd671972010-10-04 16:33:58 +0200165 * @return bool
166 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200167 public function trans_commit()
Derek Allard2067d1a2008-11-13 22:59:24 +0000168 {
169 if ( ! $this->trans_enabled)
170 {
171 return TRUE;
172 }
173
174 // When transactions are nested we only begin/commit/rollback the outermost ones
175 if ($this->_trans_depth > 0)
176 {
177 return TRUE;
178 }
179
180 $this->simple_query('COMMIT TRAN');
181 return TRUE;
182 }
183
184 // --------------------------------------------------------------------
185
186 /**
187 * Rollback Transaction
188 *
Barry Mienydd671972010-10-04 16:33:58 +0200189 * @return bool
190 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200191 public function trans_rollback()
Derek Allard2067d1a2008-11-13 22:59:24 +0000192 {
193 if ( ! $this->trans_enabled)
194 {
195 return TRUE;
196 }
197
198 // When transactions are nested we only begin/commit/rollback the outermost ones
199 if ($this->_trans_depth > 0)
200 {
201 return TRUE;
202 }
203
204 $this->simple_query('ROLLBACK TRAN');
205 return TRUE;
206 }
Barry Mienydd671972010-10-04 16:33:58 +0200207
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 // --------------------------------------------------------------------
209
210 /**
211 * Escape String
212 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000213 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000214 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000215 * @return string
216 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200217 public function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000219 if (is_array($str))
220 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500221 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200222 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000223 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200224 }
225
226 return $str;
227 }
228
Derek Allard2067d1a2008-11-13 22:59:24 +0000229 // Escape single quotes
Greg Aker757dda62010-04-14 19:06:19 -0500230 $str = str_replace("'", "''", remove_invisible_characters($str));
Barry Mienydd671972010-10-04 16:33:58 +0200231
Derek Jonese4ed5832009-02-20 21:44:59 +0000232 // escape LIKE condition wildcards
233 if ($like === TRUE)
234 {
Phil Sturgeon36b0c942011-04-02 12:16:41 +0100235 $str = str_replace(
236 array($this->_like_escape_chr, '%', '_'),
237 array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
238 $str
239 );
Derek Jonese4ed5832009-02-20 21:44:59 +0000240 }
Barry Mienydd671972010-10-04 16:33:58 +0200241
Derek Jonese4ed5832009-02-20 21:44:59 +0000242 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000243 }
Barry Mienydd671972010-10-04 16:33:58 +0200244
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 // --------------------------------------------------------------------
246
247 /**
248 * Affected Rows
249 *
Andrey Andreev1f619a82012-03-20 16:03:04 +0200250 * @return int
Derek Allard2067d1a2008-11-13 22:59:24 +0000251 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200252 public function affected_rows()
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 {
254 return @mssql_rows_affected($this->conn_id);
255 }
Barry Mienydd671972010-10-04 16:33:58 +0200256
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 // --------------------------------------------------------------------
258
259 /**
Andrey Andreev1f619a82012-03-20 16:03:04 +0200260 * Insert ID
261 *
262 * Returns the last id created in the Identity column.
263 *
264 * @return string
265 */
266 public function insert_id()
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 {
268 $ver = self::_parse_major_version($this->version());
269 $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id");
270 $query = $this->query($sql);
271 $row = $query->row();
272 return $row->last_id;
273 }
274
275 // --------------------------------------------------------------------
276
277 /**
Andrey Andreev1f619a82012-03-20 16:03:04 +0200278 * Parse major version
279 *
280 * Grabs the major version number from the
281 * database server version string passed in.
282 *
283 * @param string $version
284 * @return int major version number
285 */
286 protected function _parse_major_version($version)
Derek Allard2067d1a2008-11-13 22:59:24 +0000287 {
288 preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info);
289 return $ver_info[1]; // return the major version b/c that's all we're interested in.
290 }
291
292 // --------------------------------------------------------------------
293
294 /**
Andrey Andreev1f619a82012-03-20 16:03:04 +0200295 * Version number query string
296 *
297 * @return string
298 */
Timothy Warren8c1b2dc2012-03-19 19:07:18 -0400299 protected function _version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 {
Andrey Andreev08856b82012-03-03 03:19:28 +0200301 return 'SELECT @@VERSION AS ver';
Derek Allard2067d1a2008-11-13 22:59:24 +0000302 }
303
304 // --------------------------------------------------------------------
305
306 /**
307 * "Count All" query
308 *
309 * Generates a platform-specific query string that counts all records in
310 * the specified database
311 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000312 * @param string
313 * @return string
314 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200315 public function count_all($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 {
317 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000318 {
319 return 0;
320 }
321
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200322 $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 +0000323 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000324 {
325 return 0;
326 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000327
328 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500329 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000330 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 }
332
333 // --------------------------------------------------------------------
334
335 /**
336 * List table query
337 *
338 * Generates a platform-specific query string so that the table names can be fetched
339 *
Andrey Andreev1f619a82012-03-20 16:03:04 +0200340 * @param bool
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 * @return string
342 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200343 protected function _list_tables($prefix_limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 {
345 $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
Barry Mienydd671972010-10-04 16:33:58 +0200346
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 // for future compatibility
348 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
349 {
Greg Aker0d424892010-01-26 02:14:44 +0000350 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000351 return FALSE; // not currently supported
352 }
Barry Mienydd671972010-10-04 16:33:58 +0200353
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 return $sql;
355 }
356
357 // --------------------------------------------------------------------
358
359 /**
360 * List column query
361 *
362 * Generates a platform-specific query string so that the column names can be fetched
363 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000364 * @param string the table name
365 * @return string
366 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200367 protected function _list_columns($table = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 {
Barry Mienydd671972010-10-04 16:33:58 +0200369 return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'";
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 }
371
372 // --------------------------------------------------------------------
373
374 /**
375 * Field data query
376 *
377 * Generates a platform-specific query so that the column data can be retrieved
378 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 * @param string the table name
Andrey Andreev1f619a82012-03-20 16:03:04 +0200380 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000381 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200382 protected function _field_data($table)
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 {
Barry Mienydd671972010-10-04 16:33:58 +0200384 return "SELECT TOP 1 * FROM ".$table;
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 }
386
387 // --------------------------------------------------------------------
388
389 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200390 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200392 * Returns an array containing code and message of the last
393 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200395 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200397 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200399 $query = $this->query('SELECT @@ERROR AS code');
400 $query = $query->row();
401 return array('code' => $query->code, 'message' => mssql_get_last_message());
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 }
403
404 // --------------------------------------------------------------------
405
406 /**
407 * Escape the SQL Identifiers
408 *
Timothy Warren8c1b2dc2012-03-19 19:07:18 -0400409 * This function escapes column and table names
Derek Allard2067d1a2008-11-13 22:59:24 +0000410 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000411 * @param string
412 * @return string
413 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200414 public function _escape_identifiers($item)
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 {
416 if ($this->_escape_char == '')
417 {
418 return $item;
419 }
420
421 foreach ($this->_reserved_identifiers as $id)
422 {
423 if (strpos($item, '.'.$id) !== FALSE)
424 {
Barry Mienydd671972010-10-04 16:33:58 +0200425 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
426
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 // remove duplicates if the user already included the escape
428 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200429 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000430 }
431
432 if (strpos($item, '.') !== FALSE)
433 {
Barry Mienydd671972010-10-04 16:33:58 +0200434 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 }
436 else
437 {
438 $str = $this->_escape_char.$item.$this->_escape_char;
439 }
Barry Mienydd671972010-10-04 16:33:58 +0200440
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 // remove duplicates if the user already included the escape
442 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
443 }
Barry Mienydd671972010-10-04 16:33:58 +0200444
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 // --------------------------------------------------------------------
446
447 /**
448 * From Tables
449 *
Timothy Warren8c1b2dc2012-03-19 19:07:18 -0400450 * This function implicitly groups FROM tables so there is no confusion
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 * about operator precedence in harmony with SQL standards
452 *
Andrey Andreev1f619a82012-03-20 16:03:04 +0200453 * @param array
454 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200456 protected function _from_tables($tables)
Derek Allard2067d1a2008-11-13 22:59:24 +0000457 {
458 if ( ! is_array($tables))
459 {
460 $tables = array($tables);
461 }
Barry Mienydd671972010-10-04 16:33:58 +0200462
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 return implode(', ', $tables);
464 }
465
466 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200467
Derek Allard2067d1a2008-11-13 22:59:24 +0000468 /**
Andrey Andreev6d83cde2012-04-05 16:20:50 +0300469 * Truncate statement
470 *
471 * Generates a platform-specific truncate string from the supplied data
472 *
473 * If the database does not support the truncate() command,
474 * then this method maps to 'DELETE FROM table'
475 *
476 * @param string the table name
477 * @return string
478 */
479 protected function _truncate($table)
480 {
481 return 'TRUNCATE TABLE '.$table;
482 }
483
484 // --------------------------------------------------------------------
485
486 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 * Delete statement
488 *
489 * Generates a platform-specific delete string from the supplied data
490 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000491 * @param string the table name
492 * @param array the where clause
493 * @param string the limit clause
494 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200495 */
Andrey Andreevc6a68e02012-03-26 14:30:10 +0300496 protected function _delete($table, $where = array(), $like = array(), $limit = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000497 {
498 $conditions = '';
499
500 if (count($where) > 0 OR count($like) > 0)
501 {
502 $conditions = "\nWHERE ";
503 $conditions .= implode("\n", $this->ar_where);
504
505 if (count($where) > 0 && count($like) > 0)
506 {
507 $conditions .= " AND ";
508 }
509 $conditions .= implode("\n", $like);
510 }
511
512 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200513
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 return "DELETE FROM ".$table.$conditions.$limit;
515 }
516
517 // --------------------------------------------------------------------
518
519 /**
520 * Limit string
521 *
522 * Generates a platform-specific LIMIT clause
523 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 * @param string the sql query string
Andrey Andreev1f619a82012-03-20 16:03:04 +0200525 * @param int the number of rows to limit the query to
526 * @param int the offset value
Derek Allard2067d1a2008-11-13 22:59:24 +0000527 * @return string
528 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200529 protected function _limit($sql, $limit, $offset)
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 {
531 $i = $limit + $offset;
Barry Mienydd671972010-10-04 16:33:58 +0200532
533 return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
Derek Allard2067d1a2008-11-13 22:59:24 +0000534 }
535
536 // --------------------------------------------------------------------
537
538 /**
539 * Close DB Connection
540 *
Derek Allard2067d1a2008-11-13 22:59:24 +0000541 * @param resource
542 * @return void
543 */
Andrey Andreev1f619a82012-03-20 16:03:04 +0200544 protected function _close($conn_id)
Derek Allard2067d1a2008-11-13 22:59:24 +0000545 {
546 @mssql_close($conn_id);
Barry Mienydd671972010-10-04 16:33:58 +0200547 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000548
549}
550
Derek Allard2067d1a2008-11-13 22:59:24 +0000551/* End of file mssql_driver.php */
Timothy Warren215890b2012-03-20 09:38:16 -0400552/* Location: ./system/database/drivers/mssql/mssql_driver.php */