Fix #17881: yii\db\Query::queryScalar() wasn’t reverting the select, orderBy, limit, and offset params if an exception occurred

This commit is contained in:
Brandon Kelly
2020-02-21 01:50:50 -08:00
committed by GitHub
parent 1f8ca7b7b1
commit 79dbd91246
2 changed files with 14 additions and 1 deletions

View File

@ -461,13 +461,25 @@ class Query extends Component implements QueryInterface, ExpressionInterface
$this->orderBy = null;
$this->limit = null;
$this->offset = null;
$command = $this->createCommand($db);
$e = null;
try {
$command = $this->createCommand($db);
} catch (\Exception $e) {
// throw it later
} catch (\Throwable $e) {
// throw it later
}
$this->select = $select;
$this->orderBy = $order;
$this->limit = $limit;
$this->offset = $offset;
if ($e !== null) {
throw $e;
}
return $command->queryScalar();
}