From ca6e276102ef079daac1ceae276463d6884346b6 Mon Sep 17 00:00:00 2001 From: Sergei Tigrov Date: Fri, 12 Apr 2024 18:45:18 +0700 Subject: [PATCH] Update test according to main PR (#293) Co-authored-by: Sergei Predvoditelev --- CHANGELOG.md | 4 +-- rector.php | 5 +++- src/Builder/ExpressionBuilder.php | 16 ++++++++++ src/DQLQueryBuilder.php | 3 ++ src/SqlParser.php | 45 ++++++++++++++++++++++++++++ tests/CommandTest.php | 5 ++-- tests/Provider/SqlParserProvider.php | 25 ++++++++++++++++ tests/QueryBuilderTest.php | 12 ++++++++ tests/SqlParserTest.php | 25 ++++++++++++++++ 9 files changed, 135 insertions(+), 5 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 4b8514d94..3ffbea6b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # MSSQL Server driver for Yii Database Change Log -## 1.2.1 under development +## 2.0.0 under development -- no changes in this release. +- Enh #293: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/rector.php b/rector.php index c80d86e9a..7e1860eec 100644 --- a/rector.php +++ b/rector.php @@ -11,7 +11,10 @@ return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ __DIR__ . '/src', - __DIR__ . '/tests', + /** + * Disabled ./tests directory due to different branches with main package when testing + */ + // __DIR__ . '/tests', ]); // register a single rule diff --git a/src/Builder/ExpressionBuilder.php b/src/Builder/ExpressionBuilder.php new file mode 100644 index 000000000..b9dac17a5 --- /dev/null +++ b/src/Builder/ExpressionBuilder.php @@ -0,0 +1,16 @@ + InConditionBuilder::class, LikeCondition::class => LikeConditionBuilder::class, + Expression::class => ExpressionBuilder::class, ]); } diff --git a/src/SqlParser.php b/src/SqlParser.php new file mode 100644 index 000000000..95bda82d4 --- /dev/null +++ b/src/SqlParser.php @@ -0,0 +1,45 @@ +length - 1; + + while ($this->position < $length) { + $pos = $this->position++; + + match ($this->sql[$pos]) { + ':' => ($word = $this->parseWord()) === '' + ? $this->skipChars(':') + : $result = ':' . $word, + '"', "'" => $this->skipQuotedWithoutEscape($this->sql[$pos]), + '[' => $this->sql[$this->position] === '[' + ? $this->skipToAfterString(']]') + : $this->skipQuotedWithoutEscape(']'), + '-' => $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 387e46176..13a2d037a 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -241,9 +241,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..2accafbdc --- /dev/null +++ b/tests/Provider/SqlParserProvider.php @@ -0,0 +1,25 @@ +