From 79dbd912465b0bbe39bb2c24ebf45b7bda7b00ca Mon Sep 17 00:00:00 2001 From: Brandon Kelly Date: Fri, 21 Feb 2020 01:50:50 -0800 Subject: [PATCH] =?UTF-8?q?Fix=20#17881:=20`yii\db\Query::queryScalar()`?= =?UTF-8?q?=20wasn=E2=80=99t=20reverting=20the=20`select`,=20`orderBy`,=20?= =?UTF-8?q?`limit`,=20and=20`offset`=20params=20if=20an=20exception=20occu?= =?UTF-8?q?rred?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/CHANGELOG.md | 1 + framework/db/Query.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 4c4d246333..5d50319ef5 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -11,6 +11,7 @@ Yii Framework 2 Change Log - Bug #17829: `yii\helpers\ArrayHelper::filter` now correctly filters data when passing a filter with more than 2 levels (rhertogh) - Enh #7622: Allow `yii\data\ArrayDataProvider` to control the sort flags for `sortModels` through `yii\data\Sort::sortFlags` property (askobara) - Bug #17863: `\yii\helpers\BaseInflector::slug()` doesn't work with an empty string as a replacement argument (haruatari) +- Bug #17881: `yii\db\Query::queryScalar()` wasn’t reverting the `select`, `orderBy`, `limit`, and `offset` params if an exception occurred (brandonkelly) - Bug #17875: Use `move_uploaded_file()` function instead of `copy()` and `unlink()` for saving uploaded files in case of POST request (sup-ham) diff --git a/framework/db/Query.php b/framework/db/Query.php index d815bc7b78..093b340904 100644 --- a/framework/db/Query.php +++ b/framework/db/Query.php @@ -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(); }