From df7cf714cc6a21b5638da4191b3137a26cc9fdde Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 12 Apr 2024 18:44:57 +0700 Subject: [PATCH] Update test according to main PR (#321) Co-authored-by: Sergei Predvoditelev --- CHANGELOG.md | 4 +-- src/Builder/ExpressionBuilder.php | 16 +++++++++++ src/DQLQueryBuilder.php | 4 ++- src/SqlParser.php | 42 ++++++++++++++++++++++++++++ tests/CommandTest.php | 5 ++-- tests/Provider/SqlParserProvider.php | 35 +++++++++++++++++++++++ tests/QueryBuilderTest.php | 7 +++-- tests/SqlParserTest.php | 25 +++++++++++++++++ 8 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 src/Builder/ExpressionBuilder.php create mode 100644 src/SqlParser.php create mode 100644 tests/Provider/SqlParserProvider.php create mode 100644 tests/SqlParserTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 22784d2d2..f2e02afdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # MySQL driver for Yii Database Change Log -## 1.2.1 under development +## 2.0.0 under development -- no changes in this release. +- Enh #321: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/src/Builder/ExpressionBuilder.php b/src/Builder/ExpressionBuilder.php new file mode 100644 index 000000000..b495322de --- /dev/null +++ b/src/Builder/ExpressionBuilder.php @@ -0,0 +1,16 @@ + JsonExpressionBuilder::class, + Expression::class => ExpressionBuilder::class, ] ); } diff --git a/src/SqlParser.php b/src/SqlParser.php new file mode 100644 index 000000000..e89eb612b --- /dev/null +++ b/src/SqlParser.php @@ -0,0 +1,42 @@ +length - 1; + + while ($this->position < $length) { + $pos = $this->position++; + + match ($this->sql[$pos]) { + ':' => ($word = $this->parseWord()) === '' + ? $this->skipChars(':') + : $result = ':' . $word, + '"', "'", '`' => $this->skipQuotedWithEscape($this->sql[$pos]), + '-' => $this->sql[$this->position] === '-' + ? ++$this->position && $this->skipToAfterChar("\n") + : null, + '/' => $this->sql[$this->position] === '*' + ? ++$this->position && $this->skipToAfterString('*/') + : null, + default => null, + }; + + if ($result !== null) { + $position = $pos; + + return $result; + } + } + + return null; + } +} diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 54d373af1..9c707717a 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -120,9 +120,10 @@ public function testUpdate( array $columns, array|string $conditions, array $params, - string $expected + array $expectedValues, + int $expectedCount, ): void { - parent::testUpdate($table, $columns, $conditions, $params, $expected); + parent::testUpdate($table, $columns, $conditions, $params, $expectedValues, $expectedCount); } /** diff --git a/tests/Provider/SqlParserProvider.php b/tests/Provider/SqlParserProvider.php new file mode 100644 index 000000000..7e1a91a61 --- /dev/null +++ b/tests/Provider/SqlParserProvider.php @@ -0,0 +1,35 @@ +