blob: 147c6348345e948ed0528d54de6133c9ae0c4487 [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 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 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
368 $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
370 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000371 {
372 return 0;
373 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000374
375 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500376 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000377 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000378 }
379
380 // --------------------------------------------------------------------
381
382 /**
383 * List table query
384 *
385 * Generates a platform-specific query string so that the table names can be fetched
386 *
387 * @access private
388 * @param boolean
389 * @return string
390 */
391 function _list_tables($prefix_limit = FALSE)
392 {
393 $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
Barry Mienydd671972010-10-04 16:33:58 +0200394
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 // for future compatibility
396 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
397 {
Greg Aker0d424892010-01-26 02:14:44 +0000398 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000399 return FALSE; // not currently supported
400 }
Barry Mienydd671972010-10-04 16:33:58 +0200401
Derek Allard2067d1a2008-11-13 22:59:24 +0000402 return $sql;
403 }
404
405 // --------------------------------------------------------------------
406
407 /**
408 * List column query
409 *
410 * Generates a platform-specific query string so that the column names can be fetched
411 *
412 * @access private
413 * @param string the table name
414 * @return string
415 */
416 function _list_columns($table = '')
417 {
Barry Mienydd671972010-10-04 16:33:58 +0200418 return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'";
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 }
420
421 // --------------------------------------------------------------------
422
423 /**
424 * Field data query
425 *
426 * Generates a platform-specific query so that the column data can be retrieved
427 *
428 * @access public
429 * @param string the table name
430 * @return object
431 */
432 function _field_data($table)
433 {
Barry Mienydd671972010-10-04 16:33:58 +0200434 return "SELECT TOP 1 * FROM ".$table;
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 }
436
437 // --------------------------------------------------------------------
438
439 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200440 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200442 * Returns an array containing code and message of the last
443 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000444 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200445 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200447 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200449 $query = $this->query('SELECT @@ERROR AS code');
450 $query = $query->row();
451 return array('code' => $query->code, 'message' => mssql_get_last_message());
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 }
453
454 // --------------------------------------------------------------------
455
456 /**
457 * Escape the SQL Identifiers
458 *
459 * This function escapes column and table names
460 *
461 * @access private
462 * @param string
463 * @return string
464 */
465 function _escape_identifiers($item)
466 {
467 if ($this->_escape_char == '')
468 {
469 return $item;
470 }
471
472 foreach ($this->_reserved_identifiers as $id)
473 {
474 if (strpos($item, '.'.$id) !== FALSE)
475 {
Barry Mienydd671972010-10-04 16:33:58 +0200476 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
477
Derek Allard2067d1a2008-11-13 22:59:24 +0000478 // remove duplicates if the user already included the escape
479 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200480 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 }
482
483 if (strpos($item, '.') !== FALSE)
484 {
Barry Mienydd671972010-10-04 16:33:58 +0200485 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 }
487 else
488 {
489 $str = $this->_escape_char.$item.$this->_escape_char;
490 }
Barry Mienydd671972010-10-04 16:33:58 +0200491
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 // remove duplicates if the user already included the escape
493 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
494 }
Barry Mienydd671972010-10-04 16:33:58 +0200495
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 // --------------------------------------------------------------------
497
498 /**
499 * From Tables
500 *
501 * This function implicitly groups FROM tables so there is no confusion
502 * about operator precedence in harmony with SQL standards
503 *
504 * @access public
505 * @param type
506 * @return type
507 */
508 function _from_tables($tables)
509 {
510 if ( ! is_array($tables))
511 {
512 $tables = array($tables);
513 }
Barry Mienydd671972010-10-04 16:33:58 +0200514
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 return implode(', ', $tables);
516 }
517
518 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200519
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 /**
521 * Insert statement
522 *
523 * Generates a platform-specific insert string from the supplied data
524 *
525 * @access public
526 * @param string the table name
527 * @param array the insert keys
528 * @param array the insert values
529 * @return string
530 */
531 function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200532 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000533 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
534 }
Barry Mienydd671972010-10-04 16:33:58 +0200535
Derek Allard2067d1a2008-11-13 22:59:24 +0000536 // --------------------------------------------------------------------
537
538 /**
539 * Update statement
540 *
541 * Generates a platform-specific update string from the supplied data
542 *
543 * @access public
544 * @param string the table name
545 * @param array the update data
546 * @param array the where clause
547 * @param array the orderby clause
548 * @param array the limit clause
549 * @return string
550 */
551 function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
552 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500553 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000554 {
555 $valstr[] = $key." = ".$val;
556 }
Barry Mienydd671972010-10-04 16:33:58 +0200557
Derek Allard2067d1a2008-11-13 22:59:24 +0000558 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200559
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200561
Derek Allard2067d1a2008-11-13 22:59:24 +0000562 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
563
564 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
565
566 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200567
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 return $sql;
569 }
570
Barry Mienydd671972010-10-04 16:33:58 +0200571
Derek Allard2067d1a2008-11-13 22:59:24 +0000572 // --------------------------------------------------------------------
573
574 /**
575 * Truncate statement
576 *
577 * Generates a platform-specific truncate string from the supplied data
578 * If the database does not support the truncate() command
579 * This function maps to "DELETE FROM table"
580 *
581 * @access public
582 * @param string the table name
583 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200584 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000585 function _truncate($table)
586 {
587 return "TRUNCATE ".$table;
588 }
Barry Mienydd671972010-10-04 16:33:58 +0200589
Derek Allard2067d1a2008-11-13 22:59:24 +0000590 // --------------------------------------------------------------------
591
592 /**
593 * Delete statement
594 *
595 * Generates a platform-specific delete string from the supplied data
596 *
597 * @access public
598 * @param string the table name
599 * @param array the where clause
600 * @param string the limit clause
601 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200602 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000603 function _delete($table, $where = array(), $like = array(), $limit = FALSE)
604 {
605 $conditions = '';
606
607 if (count($where) > 0 OR count($like) > 0)
608 {
609 $conditions = "\nWHERE ";
610 $conditions .= implode("\n", $this->ar_where);
611
612 if (count($where) > 0 && count($like) > 0)
613 {
614 $conditions .= " AND ";
615 }
616 $conditions .= implode("\n", $like);
617 }
618
619 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200620
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 return "DELETE FROM ".$table.$conditions.$limit;
622 }
623
624 // --------------------------------------------------------------------
625
626 /**
627 * Limit string
628 *
629 * Generates a platform-specific LIMIT clause
630 *
631 * @access public
632 * @param string the sql query string
633 * @param integer the number of rows to limit the query to
634 * @param integer the offset value
635 * @return string
636 */
637 function _limit($sql, $limit, $offset)
638 {
639 $i = $limit + $offset;
Barry Mienydd671972010-10-04 16:33:58 +0200640
641 return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
Derek Allard2067d1a2008-11-13 22:59:24 +0000642 }
643
644 // --------------------------------------------------------------------
645
646 /**
647 * Close DB Connection
648 *
649 * @access public
650 * @param resource
651 * @return void
652 */
653 function _close($conn_id)
654 {
655 @mssql_close($conn_id);
Barry Mienydd671972010-10-04 16:33:58 +0200656 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000657
658}
659
660
661
662/* End of file mssql_driver.php */
Andrey Andreev11454e02012-02-22 16:05:47 +0200663/* Location: ./system/database/drivers/mssql/mssql_driver.php */