Skip to content

Commit

Permalink
Dev Backport: MSSQL: database abstraction layer now uses native trans…
Browse files Browse the repository at this point in the history
…action support of the SQLSRV driver.

Dev See yiisoft/yii@0b41f60
  • Loading branch information
c-schmitz committed Dec 10, 2012
1 parent 89b6625 commit 88f92bf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions framework/YiiBase.php
Expand Up @@ -696,6 +696,7 @@ public static function registerAutoloader($callback, $append=false)
'CMssqlColumnSchema' => '/db/schema/mssql/CMssqlColumnSchema.php',
'CMssqlCommandBuilder' => '/db/schema/mssql/CMssqlCommandBuilder.php',
'CMssqlPdoAdapter' => '/db/schema/mssql/CMssqlPdoAdapter.php',
'CMssqlSqlsrvPdoAdapter' => '/db/schema/mssql/CMssqlSqlsrvPdoAdapter.php',
'CMssqlSchema' => '/db/schema/mssql/CMssqlSchema.php',
'CMssqlTableSchema' => '/db/schema/mssql/CMssqlTableSchema.php',
'CMysqlColumnSchema' => '/db/schema/mysql/CMysqlColumnSchema.php',
Expand Down
5 changes: 3 additions & 2 deletions framework/db/CDbConnection.php
Expand Up @@ -415,8 +415,10 @@ protected function createPdoInstance()
if(($pos=strpos($this->connectionString,':'))!==false)
{
$driver=strtolower(substr($this->connectionString,0,$pos));
if($driver==='mssql' || $driver==='dblib' || $driver==='sqlsrv')
if($driver==='mssql' || $driver==='dblib')
$pdoClass='CMssqlPdoAdapter';
else if($driver==='sqlsrv')
$pdoClass='CMssqlSqlsrvPdoAdapter';
}
return new $pdoClass($this->connectionString,$this->username,
$this->password,$this->_attributes);
Expand Down Expand Up @@ -587,7 +589,6 @@ public function getPdoType($type)
'boolean'=>PDO::PARAM_BOOL,
'integer'=>PDO::PARAM_INT,
'string'=>PDO::PARAM_STR,
'resource'=>PDO::PARAM_LOB,
'NULL'=>PDO::PARAM_NULL,
);
return isset($map[$type]) ? $map[$type] : PDO::PARAM_STR;
Expand Down
36 changes: 36 additions & 0 deletions framework/db/schema/mssql/CMssqlSqlsrvPdoAdapter.php
@@ -0,0 +1,36 @@
<?php
/**
* CMssqlSqlsrvPdoAdapter class file.
*
* @author Timur Ruziev <resurtm@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

/**
* This is an extension of default PDO class for MSSQL SQLSRV driver only.
* It provides workaround of the improperly implemented functionalities of PDO SQLSRV driver.
*
* @author Timur Ruziev <resurtm@gmail.com>
* @package system.db.schema.mssql
* @since 1.1.13
*/
class CMssqlSqlsrvPdoAdapter extends PDO
{
/**
* Returns last inserted ID value.
* SQLSRV driver supports PDO::lastInsertId() with one peculiarity: when $sequence's value is null or empty
* string it returns empty string. But when parameter is not specified at all it's working as expected
* and returns actual last inserted ID (like other PDO drivers).
*
* @param string|null the sequence name. Defaults to null.
* @return integer last inserted ID value.
*/
public function lastInsertId($sequence=null)
{
if(!$sequence)
return parent::lastInsertId();
return parent::lastInsertId($sequence);
}
}

0 comments on commit 88f92bf

Please sign in to comment.