Fix #17486: Fixed error when using batch() without $db parameter with MSSQL

This commit is contained in:
Alexander Kartavenko
2019-08-01 13:17:31 +03:00
committed by Alexander Makarov
parent c670073ffb
commit 4b768a86f5
3 changed files with 31 additions and 3 deletions

View File

@ -4,7 +4,7 @@ Yii Framework 2 Change Log
2.0.25 under development
------------------------
- no changes in this release.
- Bug #17486: Fixed error when using `batch()` without `$db` parameter with MSSQL (alexkart)
2.0.24 July 30, 2019

View File

@ -151,8 +151,8 @@ class BatchQueryResult extends BaseObject implements \Iterator
/**
* Reads and collects rows for batch
* @since 2.0.23
* @return array
* @since 2.0.23
*/
protected function getRows()
{
@ -165,7 +165,7 @@ class BatchQueryResult extends BaseObject implements \Iterator
}
} catch (\PDOException $e) {
$errorCode = isset($e->errorInfo[1]) ? $e->errorInfo[1] : null;
if ($this->db->driverName !== 'sqlsrv' || $errorCode !== $this->mssqlNoMoreRowsErrorCode) {
if ($this->getDbDriverName() !== 'sqlsrv' || $errorCode !== $this->mssqlNoMoreRowsErrorCode) {
throw $e;
}
}
@ -202,4 +202,22 @@ class BatchQueryResult extends BaseObject implements \Iterator
{
return !empty($this->_batch);
}
/**
* Gets db driver name from the db connection that is passed to the `batch()`, if it is not passed it uses
* connection from the active record model
* @return string|null
*/
private function getDbDriverName()
{
if (isset($this->db->driverName)) {
return $this->db->driverName;
}
if (isset($this->_batch[0]->db->driverName)) {
return $this->_batch[0]->db->driverName;
}
return null;
}
}