blob: 25a32f364a2822437224ddcafac2c753a30dafa9 [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 /**
141 * Set client character set
142 *
143 * @access public
144 * @param string
145 * @param string
146 * @return resource
147 */
148 function db_set_charset($charset, $collation)
149 {
150 // @todo - add support if needed
151 return TRUE;
152 }
153
154 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200155
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 /**
157 * Execute the query
158 *
159 * @access private called by the base class
160 * @param string an SQL query
161 * @return resource
Barry Mienydd671972010-10-04 16:33:58 +0200162 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000163 function _execute($sql)
164 {
165 $sql = $this->_prep_query($sql);
166 return @mssql_query($sql, $this->conn_id);
167 }
Barry Mienydd671972010-10-04 16:33:58 +0200168
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 // --------------------------------------------------------------------
170
171 /**
172 * Prep the query
173 *
174 * If needed, each database adapter can prep the query string
175 *
176 * @access private called by execute()
177 * @param string an SQL query
178 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200179 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000180 function _prep_query($sql)
181 {
182 return $sql;
183 }
184
185 // --------------------------------------------------------------------
186
187 /**
188 * Begin Transaction
189 *
190 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200191 * @return bool
192 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 function trans_begin($test_mode = FALSE)
194 {
195 if ( ! $this->trans_enabled)
196 {
197 return TRUE;
198 }
Barry Mienydd671972010-10-04 16:33:58 +0200199
Derek Allard2067d1a2008-11-13 22:59:24 +0000200 // When transactions are nested we only begin/commit/rollback the outermost ones
201 if ($this->_trans_depth > 0)
202 {
203 return TRUE;
204 }
205
206 // Reset the transaction failure flag.
207 // If the $test_mode flag is set to TRUE transactions will be rolled back
208 // even if the queries produce a successful result.
209 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
210
211 $this->simple_query('BEGIN TRAN');
212 return TRUE;
213 }
214
215 // --------------------------------------------------------------------
216
217 /**
218 * Commit Transaction
219 *
220 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200221 * @return bool
222 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000223 function trans_commit()
224 {
225 if ( ! $this->trans_enabled)
226 {
227 return TRUE;
228 }
229
230 // When transactions are nested we only begin/commit/rollback the outermost ones
231 if ($this->_trans_depth > 0)
232 {
233 return TRUE;
234 }
235
236 $this->simple_query('COMMIT TRAN');
237 return TRUE;
238 }
239
240 // --------------------------------------------------------------------
241
242 /**
243 * Rollback Transaction
244 *
245 * @access public
Barry Mienydd671972010-10-04 16:33:58 +0200246 * @return bool
247 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 function trans_rollback()
249 {
250 if ( ! $this->trans_enabled)
251 {
252 return TRUE;
253 }
254
255 // When transactions are nested we only begin/commit/rollback the outermost ones
256 if ($this->_trans_depth > 0)
257 {
258 return TRUE;
259 }
260
261 $this->simple_query('ROLLBACK TRAN');
262 return TRUE;
263 }
Barry Mienydd671972010-10-04 16:33:58 +0200264
Derek Allard2067d1a2008-11-13 22:59:24 +0000265 // --------------------------------------------------------------------
266
267 /**
268 * Escape String
269 *
270 * @access public
271 * @param string
Derek Jonese4ed5832009-02-20 21:44:59 +0000272 * @param bool whether or not the string will be used in a LIKE condition
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 * @return string
274 */
Derek Jonese4ed5832009-02-20 21:44:59 +0000275 function escape_str($str, $like = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000277 if (is_array($str))
278 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500279 foreach ($str as $key => $val)
Barry Mienydd671972010-10-04 16:33:58 +0200280 {
Derek Jonese4ed5832009-02-20 21:44:59 +0000281 $str[$key] = $this->escape_str($val, $like);
Barry Mienydd671972010-10-04 16:33:58 +0200282 }
283
284 return $str;
285 }
286
Derek Allard2067d1a2008-11-13 22:59:24 +0000287 // Escape single quotes
Greg Aker757dda62010-04-14 19:06:19 -0500288 $str = str_replace("'", "''", remove_invisible_characters($str));
Barry Mienydd671972010-10-04 16:33:58 +0200289
Derek Jonese4ed5832009-02-20 21:44:59 +0000290 // escape LIKE condition wildcards
291 if ($like === TRUE)
292 {
Phil Sturgeon36b0c942011-04-02 12:16:41 +0100293 $str = str_replace(
294 array($this->_like_escape_chr, '%', '_'),
295 array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
296 $str
297 );
Derek Jonese4ed5832009-02-20 21:44:59 +0000298 }
Barry Mienydd671972010-10-04 16:33:58 +0200299
Derek Jonese4ed5832009-02-20 21:44:59 +0000300 return $str;
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 }
Barry Mienydd671972010-10-04 16:33:58 +0200302
Derek Allard2067d1a2008-11-13 22:59:24 +0000303 // --------------------------------------------------------------------
304
305 /**
306 * Affected Rows
307 *
308 * @access public
309 * @return integer
310 */
311 function affected_rows()
312 {
313 return @mssql_rows_affected($this->conn_id);
314 }
Barry Mienydd671972010-10-04 16:33:58 +0200315
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 // --------------------------------------------------------------------
317
318 /**
319 * Insert ID
320 *
321 * Returns the last id created in the Identity column.
322 *
323 * @access public
324 * @return integer
325 */
326 function insert_id()
327 {
328 $ver = self::_parse_major_version($this->version());
329 $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id");
330 $query = $this->query($sql);
331 $row = $query->row();
332 return $row->last_id;
333 }
334
335 // --------------------------------------------------------------------
336
337 /**
338 * Parse major version
339 *
Barry Mienydd671972010-10-04 16:33:58 +0200340 * Grabs the major version number from the
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 * database server version string passed in.
342 *
343 * @access private
344 * @param string $version
345 * @return int16 major version number
346 */
347 function _parse_major_version($version)
348 {
349 preg_match('/([0-9]+)\.([0-9]+)\.([0-9]+)/', $version, $ver_info);
350 return $ver_info[1]; // return the major version b/c that's all we're interested in.
351 }
352
353 // --------------------------------------------------------------------
354
355 /**
356 * Version number query string
357 *
358 * @access public
359 * @return string
360 */
361 function _version()
362 {
363 return "SELECT @@VERSION AS ver";
364 }
365
366 // --------------------------------------------------------------------
367
368 /**
369 * "Count All" query
370 *
371 * Generates a platform-specific query string that counts all records in
372 * the specified database
373 *
374 * @access public
375 * @param string
376 * @return string
377 */
378 function count_all($table = '')
379 {
380 if ($table == '')
Derek Allarde37ab382009-02-03 16:13:57 +0000381 {
382 return 0;
383 }
384
385 $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 +0000386
387 if ($query->num_rows() == 0)
Derek Allarde37ab382009-02-03 16:13:57 +0000388 {
389 return 0;
390 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000391
392 $row = $query->row();
Greg Aker90248ab2011-08-20 14:23:14 -0500393 $this->_reset_select();
Derek Allarde37ab382009-02-03 16:13:57 +0000394 return (int) $row->numrows;
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 }
396
397 // --------------------------------------------------------------------
398
399 /**
400 * List table query
401 *
402 * Generates a platform-specific query string so that the table names can be fetched
403 *
404 * @access private
405 * @param boolean
406 * @return string
407 */
408 function _list_tables($prefix_limit = FALSE)
409 {
410 $sql = "SELECT name FROM sysobjects WHERE type = 'U' ORDER BY name";
Barry Mienydd671972010-10-04 16:33:58 +0200411
Derek Allard2067d1a2008-11-13 22:59:24 +0000412 // for future compatibility
413 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
414 {
Greg Aker0d424892010-01-26 02:14:44 +0000415 //$sql .= " LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 return FALSE; // not currently supported
417 }
Barry Mienydd671972010-10-04 16:33:58 +0200418
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 return $sql;
420 }
421
422 // --------------------------------------------------------------------
423
424 /**
425 * List column query
426 *
427 * Generates a platform-specific query string so that the column names can be fetched
428 *
429 * @access private
430 * @param string the table name
431 * @return string
432 */
433 function _list_columns($table = '')
434 {
Barry Mienydd671972010-10-04 16:33:58 +0200435 return "SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME = '".$table."'";
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 }
437
438 // --------------------------------------------------------------------
439
440 /**
441 * Field data query
442 *
443 * Generates a platform-specific query so that the column data can be retrieved
444 *
445 * @access public
446 * @param string the table name
447 * @return object
448 */
449 function _field_data($table)
450 {
Barry Mienydd671972010-10-04 16:33:58 +0200451 return "SELECT TOP 1 * FROM ".$table;
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 }
453
454 // --------------------------------------------------------------------
455
456 /**
457 * The error message string
458 *
459 * @access private
460 * @return string
461 */
462 function _error_message()
463 {
Derek Allard64c398b2009-08-17 15:13:45 +0000464 return mssql_get_last_message();
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 }
Barry Mienydd671972010-10-04 16:33:58 +0200466
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 // --------------------------------------------------------------------
468
469 /**
470 * The error message number
471 *
472 * @access private
473 * @return integer
474 */
475 function _error_number()
476 {
477 // Are error numbers supported?
478 return '';
479 }
480
481 // --------------------------------------------------------------------
482
483 /**
484 * Escape the SQL Identifiers
485 *
486 * This function escapes column and table names
487 *
488 * @access private
489 * @param string
490 * @return string
491 */
492 function _escape_identifiers($item)
493 {
494 if ($this->_escape_char == '')
495 {
496 return $item;
497 }
498
499 foreach ($this->_reserved_identifiers as $id)
500 {
501 if (strpos($item, '.'.$id) !== FALSE)
502 {
Barry Mienydd671972010-10-04 16:33:58 +0200503 $str = $this->_escape_char. str_replace('.', $this->_escape_char.'.', $item);
504
Derek Allard2067d1a2008-11-13 22:59:24 +0000505 // remove duplicates if the user already included the escape
506 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
Barry Mienydd671972010-10-04 16:33:58 +0200507 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000508 }
509
510 if (strpos($item, '.') !== FALSE)
511 {
Barry Mienydd671972010-10-04 16:33:58 +0200512 $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 }
514 else
515 {
516 $str = $this->_escape_char.$item.$this->_escape_char;
517 }
Barry Mienydd671972010-10-04 16:33:58 +0200518
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 // remove duplicates if the user already included the escape
520 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
521 }
Barry Mienydd671972010-10-04 16:33:58 +0200522
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 // --------------------------------------------------------------------
524
525 /**
526 * From Tables
527 *
528 * This function implicitly groups FROM tables so there is no confusion
529 * about operator precedence in harmony with SQL standards
530 *
531 * @access public
532 * @param type
533 * @return type
534 */
535 function _from_tables($tables)
536 {
537 if ( ! is_array($tables))
538 {
539 $tables = array($tables);
540 }
Barry Mienydd671972010-10-04 16:33:58 +0200541
Derek Allard2067d1a2008-11-13 22:59:24 +0000542 return implode(', ', $tables);
543 }
544
545 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200546
Derek Allard2067d1a2008-11-13 22:59:24 +0000547 /**
548 * Insert statement
549 *
550 * Generates a platform-specific insert string from the supplied data
551 *
552 * @access public
553 * @param string the table name
554 * @param array the insert keys
555 * @param array the insert values
556 * @return string
557 */
558 function _insert($table, $keys, $values)
Barry Mienydd671972010-10-04 16:33:58 +0200559 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
561 }
Barry Mienydd671972010-10-04 16:33:58 +0200562
Derek Allard2067d1a2008-11-13 22:59:24 +0000563 // --------------------------------------------------------------------
564
565 /**
566 * Update statement
567 *
568 * Generates a platform-specific update string from the supplied data
569 *
570 * @access public
571 * @param string the table name
572 * @param array the update data
573 * @param array the where clause
574 * @param array the orderby clause
575 * @param array the limit clause
576 * @return string
577 */
578 function _update($table, $values, $where, $orderby = array(), $limit = FALSE)
579 {
Pascal Krietec3a4a8d2011-02-14 13:40:08 -0500580 foreach ($values as $key => $val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 {
582 $valstr[] = $key." = ".$val;
583 }
Barry Mienydd671972010-10-04 16:33:58 +0200584
Derek Allard2067d1a2008-11-13 22:59:24 +0000585 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200586
Derek Allard2067d1a2008-11-13 22:59:24 +0000587 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
Barry Mienydd671972010-10-04 16:33:58 +0200588
Derek Allard2067d1a2008-11-13 22:59:24 +0000589 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
590
591 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
592
593 $sql .= $orderby.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200594
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 return $sql;
596 }
597
Barry Mienydd671972010-10-04 16:33:58 +0200598
Derek Allard2067d1a2008-11-13 22:59:24 +0000599 // --------------------------------------------------------------------
600
601 /**
602 * Truncate statement
603 *
604 * Generates a platform-specific truncate string from the supplied data
605 * If the database does not support the truncate() command
606 * This function maps to "DELETE FROM table"
607 *
608 * @access public
609 * @param string the table name
610 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200611 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000612 function _truncate($table)
613 {
614 return "TRUNCATE ".$table;
615 }
Barry Mienydd671972010-10-04 16:33:58 +0200616
Derek Allard2067d1a2008-11-13 22:59:24 +0000617 // --------------------------------------------------------------------
618
619 /**
620 * Delete statement
621 *
622 * Generates a platform-specific delete string from the supplied data
623 *
624 * @access public
625 * @param string the table name
626 * @param array the where clause
627 * @param string the limit clause
628 * @return string
Barry Mienydd671972010-10-04 16:33:58 +0200629 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000630 function _delete($table, $where = array(), $like = array(), $limit = FALSE)
631 {
632 $conditions = '';
633
634 if (count($where) > 0 OR count($like) > 0)
635 {
636 $conditions = "\nWHERE ";
637 $conditions .= implode("\n", $this->ar_where);
638
639 if (count($where) > 0 && count($like) > 0)
640 {
641 $conditions .= " AND ";
642 }
643 $conditions .= implode("\n", $like);
644 }
645
646 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
Barry Mienydd671972010-10-04 16:33:58 +0200647
Derek Allard2067d1a2008-11-13 22:59:24 +0000648 return "DELETE FROM ".$table.$conditions.$limit;
649 }
650
651 // --------------------------------------------------------------------
652
653 /**
654 * Limit string
655 *
656 * Generates a platform-specific LIMIT clause
657 *
658 * @access public
659 * @param string the sql query string
660 * @param integer the number of rows to limit the query to
661 * @param integer the offset value
662 * @return string
663 */
664 function _limit($sql, $limit, $offset)
665 {
666 $i = $limit + $offset;
Barry Mienydd671972010-10-04 16:33:58 +0200667
668 return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
Derek Allard2067d1a2008-11-13 22:59:24 +0000669 }
670
671 // --------------------------------------------------------------------
672
673 /**
674 * Close DB Connection
675 *
676 * @access public
677 * @param resource
678 * @return void
679 */
680 function _close($conn_id)
681 {
682 @mssql_close($conn_id);
Barry Mienydd671972010-10-04 16:33:58 +0200683 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000684
685}
686
687
688
689/* End of file mssql_driver.php */
Andrey Andreev11454e02012-02-22 16:05:47 +0200690/* Location: ./system/database/drivers/mssql/mssql_driver.php */