Fix #19693: Fix db/Command not caching NULL result with scalar fetchMode

This commit is contained in:
Arkeins
2022-12-04 17:55:12 +01:00
committed by GitHub
parent 173cc5eeb6
commit 948029f583
3 changed files with 7 additions and 2 deletions

View File

@ -4,12 +4,12 @@ Yii Framework 2 Change Log
2.0.48 under development
------------------------
- Bug #19693: Fix db/Command not caching `NULL` result with scalar fetchMode (Arkeins)
- Enh #15376: Added cache usage for `yii2\rbac\DbManager::getRolesByUser()` (manchenkoff)
- Enh #9740: Usage of DI instead of new keyword in Schemas (manchenkoff)
- Enh #19689: Remove empty elements from the `class` array in `yii\helpers\BaseHtml::renderTagAttributes()` to prevent unwanted spaces (MoritzLost)
- Chg #19696: Change visibility of `yii\web\View::isPageEnded` to `protected` (lubosdz, samdark)
2.0.47 November 18, 2022
------------------------

View File

@ -1153,7 +1153,7 @@ class Command extends Component
$cache = $info[0];
$cacheKey = $this->getCacheKey($method, $fetchMode, '');
$result = $cache->get($cacheKey);
if (is_array($result) && isset($result[0])) {
if (is_array($result) && array_key_exists(0, $result)) {
Yii::debug('Query result served from cache', 'yii\db\Command::query');
return $result[0];
}

View File

@ -727,6 +727,11 @@ abstract class QueryTest extends DatabaseTestCase
$this->assertEquals('user1', $query->noCache()->where(['id' => 1])->scalar($db));
$this->assertEquals('user11', $query->cache()->where(['id' => 1])->scalar($db));
}, 10);
$update->bindValues([':id' => 3, ':name' => null])->execute();
$this->assertEquals(null, $query->cache()->where(['id' => 3])->scalar($db));
$update->bindValues([':id' => 3, ':name' => 'user3'])->execute();
$this->assertEquals(null, $query->cache()->where(['id' => 3])->scalar($db), 'Null value should be cached.');
}