blob: 188c91f9b027589d25150be91f0e67776eb7ac0f [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 *
342 * @access public
343 * @return string
344 */
345 function _version()
346 {
347 return "SELECT @@VERSION AS ver";
348 }
349
350 // --------------------------------------------------------------------
351
352 /**
353 * "Count All" query
354 *
355 * Generates a platform-specific query string that counts all records in
356 * the specified database
357 *
358 * @access public
359 * @param string
360 * @return string
361 */
362 function count_all($table = '')
363 {
364 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000365 {
366 return 0;
367 }
368
369 $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 +0000370
371 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000372 {
373 return 0;
374 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000375
376 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500377 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000378 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000379 }
380
381 // --------------------------------------------------------------------
382
383 /**
384 * List table query
385 *
386 * Generates a platform-specific query string so that the table names can be fetched
387 *
388 * @access private
389 * @param boolean
390 * @return string
391 */
392 function _list_tables($prefix_limit = FALSE)
393 {
394 $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
Barry Mienydd671972010-10-04 16:33:58 +0200395
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 // for future compatibility
397 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
398 {
Greg Aker0d424892010-01-26 02:14:44 +0000399 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000400 return FALSE; // not currently supported
401 }
Barry Mienydd671972010-10-04 16:33:58 +0200402
Derek Allard2067d1a2008-11-13 22:59:24 +0000403 return $sql;
404 }
405
406 // --------------------------------------------------------------------
407
408 /**
409 * List column query
410 *
411 * Generates a platform-specific query string so that the column names can be fetched
412 *
413 * @access private
414 * @param string the table name
415 * @return string
416 */
417 function _list_columns($table = '')
418 {
Barry Mienydd671972010-10-04 16:33:58 +0200419 return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'";
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 }
421
422 // --------------------------------------------------------------------
423
424 /**
425 * Field data query
426 *
427 * Generates a platform-specific query so that the column data can be retrieved
428 *
429 * @access public
430 * @param string the table name
431 * @return object
432 */
433 function _field_data($table)
434 {
Barry Mienydd671972010-10-04 16:33:58 +0200435 return "SELECT TOP 1 * FROM ".$table;
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 }
437
438 // --------------------------------------------------------------------
439
440 /**
Andrey Andreev4be5de12012-03-02 15:45:41 +0200441 * Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200443 * Returns an array containing code and message of the last
444 * database error that has occured.
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 *
Andrey Andreev4be5de12012-03-02 15:45:41 +0200446 * @return array
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 */
Andrey Andreev4be5de12012-03-02 15:45:41 +0200448 public function error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000449 {
Andrey Andreev4be5de12012-03-02 15:45:41 +0200450 $query = $this->query('SELECT @@ERROR AS code');
451 $query = $query->row();
452 return array('code' => $query->code, 'message' => mssql_get_last_message());
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 }
454
455 // --------------------------------------------------------------------
456
457 /**
458 * Escape the SQL Identifiers
459 *
460 * This function escapes column and table names
461 *
462 * @access private
463 * @param string
464 * @return string
465 */
466 function _escape_identifiers($item)
467 {
468 if ($this->_escape_char == '')
469 {
470 return $item;
471 }
472
473 foreach ($this->_reserved_identifiers as $id)
474 {
475 if (strpos($item, '.'.$id) !== FALSE)
476 {
Barry Mienydd671972010-10-04 16:33:58 +0200477 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
478
Derek Allard2067d1a2008-11-13 22:59:24 +0000479 // remove duplicates if the user already included the escape
480 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200481 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 }
483
484 if (strpos($item, '.') !== FALSE)
485 {
Barry Mienydd671972010-10-04 16:33:58 +0200486 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 }
488 else
489 {
490 $str = $this->_escape_char.$item.$this->_escape_char;
491 }
Barry Mienydd671972010-10-04 16:33:58 +0200492
Derek Allard2067d1a2008-11-13 22:59:24 +0000493 // remove duplicates if the user already included the escape
494 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
495 }
Barry Mienydd671972010-10-04 16:33:58 +0200496
Derek Allard2067d1a2008-11-13 22:59:24 +0000497 // --------------------------------------------------------------------
498
499 /**
500 * From Tables
501 *
502 * This function implicitly groups FROM tables so there is no confusion
503 * about operator precedence in harmony with SQL standards
504 *
505 * @access public
506 * @param type
507 * @return type
508 */
509 function _from_tables($tables)
510 {
511 if ( ! is_array($tables))
512 {
513 $tables = array($tables);
514 }
Barry Mienydd671972010-10-04 16:33:58 +0200515
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 return implode(', ', $tables);
517 }
518
519 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200520
Derek Allard2067d1a2008-11-13 22:59:24 +0000521 /**
522 * Insert statement
523 *
524 * Generates a platform-specific insert string from the supplied data
525 *
526 * @access public
527 * @param string the table name
528 * @param array the insert keys
529 * @param array the insert values
530 * @return string
531 */
532 function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200533 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000534 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
535 }
Barry Mienydd671972010-10-04 16:33:58 +0200536
Derek Allard2067d1a2008-11-13 22:59:24 +0000537 // --------------------------------------------------------------------
538
539 /**
540 * Update statement
541 *
542 * Generates a platform-specific update string from the supplied data
543 *
544 * @access public
545 * @param string the table name
546 * @param array the update data
547 * @param array the where clause
548 * @param array the orderby clause
549 * @param array the limit clause
550 * @return string
551 */
552 function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
553 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500554 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000555 {
556 $valstr[] = $key." = ".$val;
557 }
Barry Mienydd671972010-10-04 16:33:58 +0200558
Derek Allard2067d1a2008-11-13 22:59:24 +0000559 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200560
Derek Allard2067d1a2008-11-13 22:59:24 +0000561 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200562
Derek Allard2067d1a2008-11-13 22:59:24 +0000563 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
564
565 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
566
567 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200568
Derek Allard2067d1a2008-11-13 22:59:24 +0000569 return $sql;
570 }
571
Barry Mienydd671972010-10-04 16:33:58 +0200572
Derek Allard2067d1a2008-11-13 22:59:24 +0000573 // --------------------------------------------------------------------
574
575 /**
576 * Truncate statement
577 *
578 * Generates a platform-specific truncate string from the supplied data
579 * If the database does not support the truncate() command
580 * This function maps to "DELETE FROM table"
581 *
582 * @access public
583 * @param string the table name
584 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200585 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 function _truncate($table)
587 {
588 return "TRUNCATE ".$table;
589 }
Barry Mienydd671972010-10-04 16:33:58 +0200590
Derek Allard2067d1a2008-11-13 22:59:24 +0000591 // --------------------------------------------------------------------
592
593 /**
594 * Delete statement
595 *
596 * Generates a platform-specific delete string from the supplied data
597 *
598 * @access public
599 * @param string the table name
600 * @param array the where clause
601 * @param string the limit clause
602 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200603 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000604 function _delete($table, $where = array(), $like = array(), $limit = FALSE)
605 {
606 $conditions = '';
607
608 if (count($where) > 0 OR count($like) > 0)
609 {
610 $conditions = "\nWHERE ";
611 $conditions .= implode("\n", $this->ar_where);
612
613 if (count($where) > 0 && count($like) > 0)
614 {
615 $conditions .= " AND ";
616 }
617 $conditions .= implode("\n", $like);
618 }
619
620 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200621
Derek Allard2067d1a2008-11-13 22:59:24 +0000622 return "DELETE FROM ".$table.$conditions.$limit;
623 }
624
625 // --------------------------------------------------------------------
626
627 /**
628 * Limit string
629 *
630 * Generates a platform-specific LIMIT clause
631 *
632 * @access public
633 * @param string the sql query string
634 * @param integer the number of rows to limit the query to
635 * @param integer the offset value
636 * @return string
637 */
638 function _limit($sql, $limit, $offset)
639 {
640 $i = $limit + $offset;
Barry Mienydd671972010-10-04 16:33:58 +0200641
642 return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
Derek Allard2067d1a2008-11-13 22:59:24 +0000643 }
644
645 // --------------------------------------------------------------------
646
647 /**
648 * Close DB Connection
649 *
650 * @access public
651 * @param resource
652 * @return void
653 */
654 function _close($conn_id)
655 {
656 @mssql_close($conn_id);
Barry Mienydd671972010-10-04 16:33:58 +0200657 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000658
659}
660
661
662
663/* End of file mssql_driver.php */
Andrey Andreev11454e02012-02-22 16:05:47 +0200664/* Location: ./system/database/drivers/mssql/mssql_driver.php */