blob: b6b64cc44456572a6bba4f2a8b627ca78fe919c1 [file] [log] [blame]
Derek Jones4b9c6292011-07-01 17:40:48 -05001<?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
8 *
9 * Licensed under the Open Software License version 3.0
10 *
11 * 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
28// ------------------------------------------------------------------------
29
30/**
31 * MS SQL Database Adapter Class
32 *
33 * Note: _DB is an extender class that the app controller
34 * creates dynamically based on whether the active record
35 * class is being used or not.
36 *
37 * @package CodeIgniter
38 * @subpackage Drivers
39 * @category Database
Derek Jonesf4a4bd82011-10-20 12:18:42 -050040 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000041 * @link http://codeigniter.com/user_guide/database/
42 */
43class CI_DB_mssql_driver extends CI_DB {
44
45 var $dbdriver = 'mssql';
Barry Mienydd671972010-10-04 16:33:58 +020046
Derek Allard2067d1a2008-11-13 22:59:24 +000047 // The character used for escaping
48 var $_escape_char = '';
Derek Jonese4ed5832009-02-20 21:44:59 +000049
50 // clause and character used for LIKE escape sequences
51 var $_like_escape_str = " ESCAPE '%s' ";
52 var $_like_escape_chr = '!';
Barry Mienydd671972010-10-04 16:33:58 +020053
Derek Allard2067d1a2008-11-13 22:59:24 +000054 /**
55 * The syntax to count rows is slightly different across different
56 * database engines, so this string appears in each driver and is
57 * used for the count_all() and count_all_results() functions.
58 */
59 var $_count_string = "SELECT COUNT(*) AS ";
60 var $_random_keyword = ' ASC'; // not currently supported
61
62 /**
63 * Non-persistent database connection
64 *
65 * @access private called by the base class
66 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020067 */
Derek Allard2067d1a2008-11-13 22:59:24 +000068 function db_connect()
69 {
70 if ($this->port != '')
71 {
72 $this->hostname .= ','.$this->port;
73 }
74
75 return @mssql_connect($this->hostname, $this->username, $this->password);
76 }
Barry Mienydd671972010-10-04 16:33:58 +020077
Derek Allard2067d1a2008-11-13 22:59:24 +000078 // --------------------------------------------------------------------
79
80 /**
81 * Persistent database connection
82 *
83 * @access private called by the base class
84 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +020085 */
Derek Allard2067d1a2008-11-13 22:59:24 +000086 function db_pconnect()
87 {
88 if ($this->port != '')
89 {
90 $this->hostname .= ','.$this->port;
91 }
92
93 return @mssql_pconnect($this->hostname, $this->username, $this->password);
94 }
Barry Mienydd671972010-10-04 16:33:58 +020095
Derek Allard2067d1a2008-11-13 22:59:24 +000096 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020097
Derek Jones87cbafc2009-02-27 16:29:59 +000098 /**
99 * Reconnect
100 *
101 * Keep / reestablish the db connection if no queries have been
102 * sent for a length of time exceeding the server's idle timeout
103 *
104 * @access public
105 * @return void
106 */
107 function reconnect()
108 {
109 // not implemented in MSSQL
110 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000111
Derek Jones87cbafc2009-02-27 16:29:59 +0000112 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200113
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 /**
115 * Select the database
116 *
Andrey Andreev11454e02012-02-22 16:05:47 +0200117 * @param string database name
118 * @return bool
Barry Mienydd671972010-10-04 16:33:58 +0200119 */
Andrey Andreev11454e02012-02-22 16:05:47 +0200120 public function db_select($database = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000121 {
Andrey Andreev024ba2d2012-02-24 11:40:36 +0200122 if ($database === '')
123 {
124 $database = $this->database;
125 }
126
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 // Note: The brackets are required in the event that the DB name
128 // contains reserved characters
Andrey Andreev024ba2d2012-02-24 11:40:36 +0200129 if (@mssql_select_db('['.$database.']', $this->conn_id))
130 {
131 $this->database = $database;
132 return TRUE;
133 }
134
135 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 }
137
138 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200139
Derek Allard2067d1a2008-11-13 22:59:24 +0000140 /**
Derek Allard2067d1a2008-11-13 22:59:24 +0000141 * Execute the query
142 *
143 * @access private called by the base class
144 * @param string an SQL query
145 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200146 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 function _execute($sql)
148 {
149 $sql = $this->_prep_query($sql);
150 return @mssql_query($sql, $this->conn_id);
151 }
Barry Mienydd671972010-10-04 16:33:58 +0200152
Derek Allard2067d1a2008-11-13 22:59:24 +0000153 // --------------------------------------------------------------------
154
155 /**
156 * Prep the query
157 *
158 * If needed, each database adapter can prep the query string
159 *
160 * @access private called by execute()
161 * @param string an SQL query
162 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200163 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 function _prep_query($sql)
165 {
166 return $sql;
167 }
168
169 // --------------------------------------------------------------------
170
171 /**
172 * Begin Transaction
173 *
174 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200175 * @return bool
176 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 function trans_begin($test_mode = FALSE)
178 {
179 if ( ! $this->trans_enabled)
180 {
181 return TRUE;
182 }
Barry Mienydd671972010-10-04 16:33:58 +0200183
Derek Allard2067d1a2008-11-13 22:59:24 +0000184 // When transactions are nested we only begin/commit/rollback the outermost ones
185 if ($this->_trans_depth > 0)
186 {
187 return TRUE;
188 }
189
190 // Reset the transaction failure flag.
191 // If the $test_mode flag is set to TRUE transactions will be rolled back
192 // even if the queries produce a successful result.
193 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
194
195 $this->simple_query('BEGIN TRAN');
196 return TRUE;
197 }
198
199 // --------------------------------------------------------------------
200
201 /**
202 * Commit Transaction
203 *
204 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200205 * @return bool
206 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 function trans_commit()
208 {
209 if ( ! $this->trans_enabled)
210 {
211 return TRUE;
212 }
213
214 // When transactions are nested we only begin/commit/rollback the outermost ones
215 if ($this->_trans_depth > 0)
216 {
217 return TRUE;
218 }
219
220 $this->simple_query('COMMIT TRAN');
221 return TRUE;
222 }
223
224 // --------------------------------------------------------------------
225
226 /**
227 * Rollback Transaction
228 *
229 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200230 * @return bool
231 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 function trans_rollback()
233 {
234 if ( ! $this->trans_enabled)
235 {
236 return TRUE;
237 }
238
239 // When transactions are nested we only begin/commit/rollback the outermost ones
240 if ($this->_trans_depth > 0)
241 {
242 return TRUE;
243 }
244
245 $this->simple_query('ROLLBACK TRAN');
246 return TRUE;
247 }
Barry Mienydd671972010-10-04 16:33:58 +0200248
Derek Allard2067d1a2008-11-13 22:59:24 +0000249 // --------------------------------------------------------------------
250
251 /**
252 * Escape String
253 *
254 * @access public
255 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000256 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 * @return string
258 */
Derek Jonese4ed5832009-02-20 21:44:59 +0000259 function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000260 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000261 if (is_array($str))
262 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500263 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200264 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000265 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200266 }
267
268 return $str;
269 }
270
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 // Escape single quotes
Greg Aker757dda62010-04-14 19:06:19 -0500272 $str = str_replace("'", "''", remove_invisible_characters($str));
Barry Mienydd671972010-10-04 16:33:58 +0200273
Derek Jonese4ed5832009-02-20 21:44:59 +0000274 // escape LIKE condition wildcards
275 if ($like === TRUE)
276 {
Phil Sturgeon36b0c942011-04-02 12:16:41 +0100277 $str = str_replace(
278 array($this->_like_escape_chr, '%', '_'),
279 array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
280 $str
281 );
Derek Jonese4ed5832009-02-20 21:44:59 +0000282 }
Barry Mienydd671972010-10-04 16:33:58 +0200283
Derek Jonese4ed5832009-02-20 21:44:59 +0000284 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 }
Barry Mienydd671972010-10-04 16:33:58 +0200286
Derek Allard2067d1a2008-11-13 22:59:24 +0000287 // --------------------------------------------------------------------
288
289 /**
290 * Affected Rows
291 *
292 * @access public
293 * @return integer
294 */
295 function affected_rows()
296 {
297 return @mssql_rows_affected($this->conn_id);
298 }
Barry Mienydd671972010-10-04 16:33:58 +0200299
Derek Allard2067d1a2008-11-13 22:59:24 +0000300 // --------------------------------------------------------------------
301
302 /**
303 * Insert ID
304 *
305 * Returns the last id created in the Identity column.
306 *
307 * @access public
308 * @return integer
309 */
310 function insert_id()
311 {
312 $ver = self::_parse_major_version($this->version());
313 $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id");
314 $query = $this->query($sql);
315 $row = $query->row();
316 return $row->last_id;
317 }
318
319 // --------------------------------------------------------------------
320
321 /**
322 * Parse major version
323 *
Barry Mienydd671972010-10-04 16:33:58 +0200324 * Grabs the major version number from the
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 * database server version string passed in.
326 *
327 * @access private
328 * @param string $version
329 * @return int16 major version number
330 */
331 function _parse_major_version($version)
332 {
333 preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info);
334 return $ver_info[1]; // return the major version b/c that's all we're interested in.
335 }
336
337 // --------------------------------------------------------------------
338
339 /**
340 * Version number query string
341 *
Andrey Andreev08856b82012-03-03 03:19:28 +0200342 * @return string
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 */
Andrey Andreev08856b82012-03-03 03:19:28 +0200344 protected function _version()
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 {
Andrey Andreev08856b82012-03-03 03:19:28 +0200346 return 'SELECT @@VERSION AS ver';
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 }
348
349 // --------------------------------------------------------------------
350
351 /**
352 * "Count All" query
353 *
354 * Generates a platform-specific query string that counts all records in
355 * the specified database
356 *
357 * @access public
358 * @param string
359 * @return string
360 */
361 function count_all($table = '')
362 {
363 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000364 {
365 return 0;
366 }
367
Andrey Andreev032e7ea2012-03-06 19:48:35 +0200368 $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 +0000369 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000370 {
371 return 0;
372 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000373
374 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500375 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000376 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 }
378
379 // --------------------------------------------------------------------
380
381 /**
382 * List table query
383 *
384 * Generates a platform-specific query string so that the table names can be fetched
385 *
386 * @access private
387 * @param boolean
388 * @return string
389 */
390 function _list_tables($prefix_limit = FALSE)
391 {
392 $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
Barry Mienydd671972010-10-04 16:33:58 +0200393
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 // for future compatibility
395 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
396 {
Greg Aker0d424892010-01-26 02:14:44 +0000397 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 return FALSE; // not currently supported
399 }
Barry Mienydd671972010-10-04 16:33:58 +0200400
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 return $sql;
402 }
403
404 // --------------------------------------------------------------------
405
406 /**
407 * List column query
408 *
409 * Generates a platform-specific query string so that the column names can be fetched
410 *
411 * @access private
412 * @param string the table name
413 * @return string
414 */
415 function _list_columns($table = '')
416 {
Barry Mienydd671972010-10-04 16:33:58 +0200417 return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'";
Derek Allard2067d1a2008-11-13 22:59:24 +0000418 }
419
420 // --------------------------------------------------------------------
421
422 /**
423 * Field data query
424 *
425 * Generates a platform-specific query so that the column data can be retrieved
426 *
427 * @access public
428 * @param string the table name
429 * @return object
430 */
431 function _field_data($table)
432 {
Barry Mienydd671972010-10-04 16:33:58 +0200433 return "SELECT TOP 1 * FROM ".$table;
Derek Allard2067d1a2008-11-13 22:59:24 +0000434 }
435
436 // --------------------------------------------------------------------
437
438 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200439 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200441 * Returns an array containing code and message of the last
442 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200444 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200446 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200448 $query = $this->query('SELECT @@ERROR AS code');
449 $query = $query->row();
450 return array('code' => $query->code, 'message' => mssql_get_last_message());
Derek Allard2067d1a2008-11-13 22:59:24 +0000451 }
452
453 // --------------------------------------------------------------------
454
455 /**
456 * Escape the SQL Identifiers
457 *
458 * This function escapes column and table names
459 *
460 * @access private
461 * @param string
462 * @return string
463 */
464 function _escape_identifiers($item)
465 {
466 if ($this->_escape_char == '')
467 {
468 return $item;
469 }
470
471 foreach ($this->_reserved_identifiers as $id)
472 {
473 if (strpos($item, '.'.$id) !== FALSE)
474 {
Barry Mienydd671972010-10-04 16:33:58 +0200475 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
476
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 // remove duplicates if the user already included the escape
478 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200479 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 }
481
482 if (strpos($item, '.') !== FALSE)
483 {
Barry Mienydd671972010-10-04 16:33:58 +0200484 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 }
486 else
487 {
488 $str = $this->_escape_char.$item.$this->_escape_char;
489 }
Barry Mienydd671972010-10-04 16:33:58 +0200490
Derek Allard2067d1a2008-11-13 22:59:24 +0000491 // remove duplicates if the user already included the escape
492 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
493 }
Barry Mienydd671972010-10-04 16:33:58 +0200494
Derek Allard2067d1a2008-11-13 22:59:24 +0000495 // --------------------------------------------------------------------
496
497 /**
498 * From Tables
499 *
500 * This function implicitly groups FROM tables so there is no confusion
501 * about operator precedence in harmony with SQL standards
502 *
503 * @access public
504 * @param type
505 * @return type
506 */
507 function _from_tables($tables)
508 {
509 if ( ! is_array($tables))
510 {
511 $tables = array($tables);
512 }
Barry Mienydd671972010-10-04 16:33:58 +0200513
Derek Allard2067d1a2008-11-13 22:59:24 +0000514 return implode(', ', $tables);
515 }
516
517 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200518
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 /**
520 * Insert statement
521 *
522 * Generates a platform-specific insert string from the supplied data
523 *
524 * @access public
525 * @param string the table name
526 * @param array the insert keys
527 * @param array the insert values
528 * @return string
529 */
530 function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200531 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
533 }
Barry Mienydd671972010-10-04 16:33:58 +0200534
Derek Allard2067d1a2008-11-13 22:59:24 +0000535 // --------------------------------------------------------------------
536
537 /**
538 * Update statement
539 *
540 * Generates a platform-specific update string from the supplied data
541 *
542 * @access public
543 * @param string the table name
544 * @param array the update data
545 * @param array the where clause
546 * @param array the orderby clause
547 * @param array the limit clause
548 * @return string
549 */
550 function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
551 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500552 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 {
554 $valstr[] = $key." = ".$val;
555 }
Barry Mienydd671972010-10-04 16:33:58 +0200556
Derek Allard2067d1a2008-11-13 22:59:24 +0000557 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200558
Derek Allard2067d1a2008-11-13 22:59:24 +0000559 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200560
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
562
563 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
564
565 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200566
Derek Allard2067d1a2008-11-13 22:59:24 +0000567 return $sql;
568 }
569
Barry Mienydd671972010-10-04 16:33:58 +0200570
Derek Allard2067d1a2008-11-13 22:59:24 +0000571 // --------------------------------------------------------------------
572
573 /**
574 * Truncate statement
575 *
576 * Generates a platform-specific truncate string from the supplied data
577 * If the database does not support the truncate() command
578 * This function maps to "DELETE FROM table"
579 *
580 * @access public
581 * @param string the table name
582 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200583 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000584 function _truncate($table)
585 {
586 return "TRUNCATE ".$table;
587 }
Barry Mienydd671972010-10-04 16:33:58 +0200588
Derek Allard2067d1a2008-11-13 22:59:24 +0000589 // --------------------------------------------------------------------
590
591 /**
592 * Delete statement
593 *
594 * Generates a platform-specific delete string from the supplied data
595 *
596 * @access public
597 * @param string the table name
598 * @param array the where clause
599 * @param string the limit clause
600 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200601 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 function _delete($table, $where = array(), $like = array(), $limit = FALSE)
603 {
604 $conditions = '';
605
606 if (count($where) > 0 OR count($like) > 0)
607 {
608 $conditions = "\nWHERE ";
609 $conditions .= implode("\n", $this->ar_where);
610
611 if (count($where) > 0 && count($like) > 0)
612 {
613 $conditions .= " AND ";
614 }
615 $conditions .= implode("\n", $like);
616 }
617
618 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200619
Derek Allard2067d1a2008-11-13 22:59:24 +0000620 return "DELETE FROM ".$table.$conditions.$limit;
621 }
622
623 // --------------------------------------------------------------------
624
625 /**
626 * Limit string
627 *
628 * Generates a platform-specific LIMIT clause
629 *
630 * @access public
631 * @param string the sql query string
632 * @param integer the number of rows to limit the query to
633 * @param integer the offset value
634 * @return string
635 */
636 function _limit($sql, $limit, $offset)
637 {
638 $i = $limit + $offset;
Barry Mienydd671972010-10-04 16:33:58 +0200639
640 return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
Derek Allard2067d1a2008-11-13 22:59:24 +0000641 }
642
643 // --------------------------------------------------------------------
644
645 /**
646 * Close DB Connection
647 *
648 * @access public
649 * @param resource
650 * @return void
651 */
652 function _close($conn_id)
653 {
654 @mssql_close($conn_id);
Barry Mienydd671972010-10-04 16:33:58 +0200655 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000656
657}
658
659
660
661/* End of file mssql_driver.php */
Andrey Andreev11454e02012-02-22 16:05:47 +0200662/* Location: ./system/database/drivers/mssql/mssql_driver.php */