Commit a612b492 by Qiang Xue

Merge pull request #4401 from tof06/4342_mssql_driver_updates

4342 mssql driver updates
parents e17e99d3 bbe8bdde
......@@ -68,6 +68,7 @@ Yii Framework 2 Change Log
- Bug #4162: Fixed bug where schema name was not used in ’SHOW CREATE TABLE’ query in `yii\db\mysql\Schema` (stevekr)
- Bug #4241: `yii\widgets\Pjax` was incorrectly setting container id (mitalcoi)
- Bug #4276: Added check for UPLOAD_ERR_NO_FILE in `yii\web\UploadedFile` and return null if no file was uploaded (OmgDef)
- Bug #4342: mssql (dblib) driver does not support getting attributes (tof06)
- Bug: Fixed inconsistent return of `\yii\console\Application::runAction()` (samdark)
- Bug: URL encoding for the route parameter added to `\yii\web\UrlManager` (klimov-paul)
- Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)
......
......@@ -61,4 +61,23 @@ class PDO extends \PDO
return true;
}
/**
* Retrieve a database connection attribute.
* It is necessary to override PDO's method as some MSSQL PDO driver (e.g. dblib) does not
* support getting attributes
*/
public function getAttribute($attribute)
{
try {
return parent::getAttribute($attribute);
} catch (\PDOException $e) {
switch ($attribute) {
case PDO::ATTR_SERVER_VERSION:
return $this->query("SELECT SERVERPROPERTY('productversion')")->fetchColumn();
default:
throw $e;
}
}
}
}
......@@ -17,6 +17,8 @@ use yii\base\InvalidParamException;
*/
class QueryBuilder extends \yii\db\QueryBuilder
{
protected $_oldMssql;
/**
* @var array mapping from abstract column types (keys) to physical column types (values).
*/
......@@ -189,8 +191,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
$originalOrdering = $this->buildOrderBy($query->orderBy);
if ($query->select) {
$select = implode(', ', $query->select);
}
else {
} else {
$select = $query->select = '*';
}
if ($select === '*') {
......@@ -238,8 +239,11 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/
protected function isOldMssql()
{
if ($this->_oldMssql === null) {
$pdo = $this->db->getSlavePdo();
$version = preg_split("/\./", $pdo->getAttribute(\PDO::ATTR_SERVER_VERSION));
return $version[0] < 11;
$this->_oldMssql = $version[0] < 11;
}
return $this->_oldMssql;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment