summaryrefslogtreecommitdiffstats
path: root/system/database/drivers/mssql/mssql_driver.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/database/drivers/mssql/mssql_driver.php')
-rw-r--r--system/database/drivers/mssql/mssql_driver.php74
1 files changed, 28 insertions, 46 deletions
diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php
index f60ec8168..1630eb7b6 100644
--- a/system/database/drivers/mssql/mssql_driver.php
+++ b/system/database/drivers/mssql/mssql_driver.php
@@ -57,6 +57,16 @@ class CI_DB_mssql_driver extends CI_DB {
protected $_count_string = 'SELECT COUNT(*) AS ';
protected $_random_keyword = ' NEWID()';
+ public function __construct($params)
+ {
+ parent::__construct($params);
+
+ if ( ! empty($this->port))
+ {
+ $this->hostname .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port;
+ }
+ }
+
/**
* Non-persistent database connection
*
@@ -64,11 +74,6 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function db_connect()
{
- if ($this->port != '')
- {
- $this->hostname .= ','.$this->port;
- }
-
return @mssql_connect($this->hostname, $this->username, $this->password);
}
@@ -81,11 +86,6 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function db_pconnect()
{
- if ($this->port != '')
- {
- $this->hostname .= ','.$this->port;
- }
-
return @mssql_pconnect($this->hostname, $this->username, $this->password);
}
@@ -121,7 +121,7 @@ class CI_DB_mssql_driver extends CI_DB {
* Execute the query
*
* @param string an SQL query
- * @return resource
+ * @return mixed resource if rows are returned, bool otherwise
*/
protected function _execute($sql)
{
@@ -137,13 +137,8 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function trans_begin($test_mode = FALSE)
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
@@ -151,10 +146,9 @@ class CI_DB_mssql_driver extends CI_DB {
// Reset the transaction failure flag.
// If the $test_mode flag is set to TRUE transactions will be rolled back
// even if the queries produce a successful result.
- $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
+ $this->_trans_failure = ($test_mode === TRUE);
- $this->simple_query('BEGIN TRAN');
- return TRUE;
+ return $this->simple_query('BEGIN TRAN');
}
// --------------------------------------------------------------------
@@ -166,19 +160,13 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function trans_commit()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- $this->simple_query('COMMIT TRAN');
- return TRUE;
+ return $this->simple_query('COMMIT TRAN');
}
// --------------------------------------------------------------------
@@ -190,19 +178,13 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function trans_rollback()
{
- if ( ! $this->trans_enabled)
- {
- return TRUE;
- }
-
// When transactions are nested we only begin/commit/rollback the outermost ones
- if ($this->_trans_depth > 0)
+ if ( ! $this->trans_enabled OR $this->_trans_depth > 0)
{
return TRUE;
}
- $this->simple_query('ROLLBACK TRAN');
- return TRUE;
+ return $this->simple_query('ROLLBACK TRAN');
}
// --------------------------------------------------------------------
@@ -232,7 +214,7 @@ class CI_DB_mssql_driver extends CI_DB {
// escape LIKE condition wildcards
if ($like === TRUE)
{
- $str = str_replace(
+ return str_replace(
array($this->_like_escape_chr, '%', '_'),
array($this->_like_escape_chr.$this->_like_escape_chr, $this->_like_escape_chr.'%', $this->_like_escape_chr.'_'),
$str
@@ -265,11 +247,13 @@ class CI_DB_mssql_driver extends CI_DB {
*/
public function insert_id()
{
- $ver = self::_parse_major_version($this->version());
- $sql = ($ver >= 8 ? "SELECT SCOPE_IDENTITY() AS last_id" : "SELECT @@IDENTITY AS last_id");
- $query = $this->query($sql);
- $row = $query->row();
- return $row->last_id;
+ $query = (self::_parse_major_version($this->version()) > 7)
+ ? 'SELECT SCOPE_IDENTITY() AS last_id'
+ : 'SELECT @@IDENTITY AS last_id';
+
+ $query = $this->query($query);
+ $query = $query->row();
+ return $query->last_id;
}
// --------------------------------------------------------------------
@@ -381,7 +365,7 @@ class CI_DB_mssql_driver extends CI_DB {
*/
protected function _field_data($table)
{
- return "SELECT TOP 1 * FROM ".$table;
+ return 'SELECT TOP 1 * FROM '.$table;
}
// --------------------------------------------------------------------
@@ -513,9 +497,7 @@ class CI_DB_mssql_driver extends CI_DB {
*/
protected function _limit($sql, $limit, $offset)
{
- $i = $limit + $offset;
-
- return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
+ return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.($limit + $offset).' ', $sql);
}
// --------------------------------------------------------------------