From 3f073e8d133f39fb639b47f7a95060226f9061a1 Mon Sep 17 00:00:00 2001 From: kikimor Date: Tue, 3 Jul 2018 17:41:35 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B3=D0=B8=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=BD=D0=B5=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC?= =?UTF-8?q?=D0=BE=D0=B5=20=D1=80=D0=B0=D1=81=D0=BA=D0=BE=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Parser.php | 15 ++++++++++++--- tests/SqlParserTest.php | 21 ++++++++++++++++----- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Parser.php b/Parser.php index 2558b39..62303b3 100644 --- a/Parser.php +++ b/Parser.php @@ -233,13 +233,22 @@ private function replaceComment($comment, $queryInComment, $paramName) */ private function getParam($name) { - $name = mb_strtolower(ltrim($name, ':')); + $name = $outName = mb_strtolower(ltrim($name, ':')); + + // Формируем имя параметра на выход точно такое же, какое и забиндено в парметры. + foreach ($this->params as $key => $value) { + if (mb_strtolower($key) == $name) { + $outName = $key; + break; + } + } + $params = array_change_key_case($this->params, CASE_LOWER); if (array_key_exists($name, $params)) { - return [$name, $params[$name]]; + return [$outName, $params[$name]]; } elseif (array_key_exists(':' . $name, $params)) { - return [$name, $params[':' . $name]]; + return [$outName, $params[':' . $name]]; } return false; diff --git a/tests/SqlParserTest.php b/tests/SqlParserTest.php index 0ac443c..c41f46a 100644 --- a/tests/SqlParserTest.php +++ b/tests/SqlParserTest.php @@ -20,6 +20,7 @@ public function sqlData() --*param17 case-insensitive2 --*PARAM18 case-insensitive3 /*param19 :@param19*/ + /*param20 :@param20*/ '; return [ @@ -32,14 +33,15 @@ public function sqlData() [$query, ['param8' => 'v8', 'param9' => 'v9', 'param10' => 'v10'], '/^\s*sql10\s*$/'], ["sql1\n\n\n\n\nsql2", ['param1' => 'v1'], '/^sql1\nsql2$/'], ["sql1", [], '/^sql1$/'], - ["-- test\n".$query, [], '/^-- test$/'], + ["-- test\n" . $query, [], '/^-- test$/'], [$query, ['param11' => [['v1', 'v2']]], "/^:param11_0,:param11_1$/"], ["--*param order by param", ['param' => ['v1', 'bind' => 'text']], "/^order by v1$/"], [$query, ['param12' => 'test'], "/^test multiple$/"], [$query, ['param14' => 'test'], "/^test multiple$/"], [$query, ['PARAM17' => 'test'], "/^case-insensitive2$/"], [$query, ['PARAM18' => 'test'], "/^case-insensitive3$/"], - [$query, ['PARAM19' => [[1, 2]]], "/^:param19_0,:param19_1$/"], + [$query, ['PARAM19' => [[1, 2]]], "/^:PARAM19_0,:PARAM19_1$/"], + [$query, ['PARAM20' => ['bind' => 'tuple', [[1], [2]]]], "/^\(:PARAM20_0_0\),\(:PARAM20_1_0\)$/"], ]; } @@ -56,11 +58,20 @@ public function paramsData() return [ [[], []], [[':simpleName' => 'simpleValue'], [':simpleName' => 'simpleValue']], - [[':simpleNameSimpleValueWithType' => ['simpleValue', \PDO::PARAM_STR]], [':simpleNameSimpleValueWithType' => ['simpleValue', \PDO::PARAM_STR]]], - [[':complexNameSimpleValue' => ['simpleValue', 'bind' => true]], [':complexNameSimpleValue' => 'simpleValue']], + [ + [':simpleNameSimpleValueWithType' => ['simpleValue', \PDO::PARAM_STR]], + [':simpleNameSimpleValueWithType' => ['simpleValue', \PDO::PARAM_STR]] + ], + [ + [':complexNameSimpleValue' => ['simpleValue', 'bind' => true]], + [':complexNameSimpleValue' => 'simpleValue'] + ], [[':complexNameBindText' => ['simpleValue', 'bind' => 'text']], []], [[':complexNameNoBind' => ['bind' => false]], []], - [['arrayName' => [[0, 1, 2, 3]]], [':arrayName_0' => 0, ':arrayName_1' => 1, ':arrayName_2' => 2, ':arrayName_3' => 3]], + [ + ['arrayName' => [[0, 1, 2, 3]]], + [':arrayName_0' => 0, ':arrayName_1' => 1, ':arrayName_2' => 2, ':arrayName_3' => 3] + ], ]; }