From a46efe79c6a306131b2fb8b53d4941a5f1b67ef3 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Wed, 14 May 2014 10:28:41 -0400 Subject: [PATCH] Fixes #3469: Fixed the bug that `QueryBuilder::getColumnType()` may drop the provided column precision in certain cases --- framework/CHANGELOG.md | 1 + framework/db/QueryBuilder.php | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 3aec4ba..10d6d3b 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -28,6 +28,7 @@ Yii Framework 2 Change Log - Bug #3431: Allow using extended ErrorHandler class from the app namespace (cebe) - Bug #3436: Fixed the issue that `ServiceLocator` still returns the old component after calling `set()` with a new definition (qiangxue) - Bug #3458: Fixed the bug that the image rendered by `CaptchaAction` was using a wrong content type (MDMunir, qiangxue) +- Bug #3469: Fixed the bug that `QueryBuilder::getColumnType()` may drop the provided column precision in certain cases (qiangxue, Ragazzo) - Bug: Fixed inconsistent return of `\yii\console\Application::runAction()` (samdark) - Enh #2264: `CookieCollection::has()` will return false for expired or removed cookies (qiangxue) - Enh #2435: `yii\db\IntegrityException` is now thrown on database integrity errors instead of general `yii\db\Exception` (samdark) diff --git a/framework/db/QueryBuilder.php b/framework/db/QueryBuilder.php index 1e487c4..2a3d0e1 100644 --- a/framework/db/QueryBuilder.php +++ b/framework/db/QueryBuilder.php @@ -591,7 +591,13 @@ class QueryBuilder extends \yii\base\Object return $this->typeMap[$type]; } elseif (preg_match('/^(\w+)\((.+?)\)(.*)$/', $type, $matches)) { if (isset($this->typeMap[$matches[1]])) { - return preg_replace('/\(.+\)/', '(' . $matches[2] . ')', $this->typeMap[$matches[1]]) . $matches[3]; + $ptype = $this->typeMap[$matches[1]]; + if (strpos($ptype, '(') !== false) { + // replace the precision in $ptype with the actual one + return preg_replace('/\(.+\)/', '(' . $matches[2] . ')', $ptype) . $matches[3]; + } else { + return "{$ptype}({$matches[2]}){$matches[3]}"; + } } } elseif (preg_match('/^(\w+)\s+/', $type, $matches)) { if (isset($this->typeMap[$matches[1]])) {