From 0082f4fc9ab47e3684f158d069683f631eb5887b Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 6 Feb 2024 17:26:39 +0700 Subject: [PATCH 1/8] Update test according to main PR --- tests/CommandTest.php | 5 +++-- tests/QueryBuilderTest.php | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 80c0d44b..c9731874 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -527,9 +527,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/QueryBuilderTest.php b/tests/QueryBuilderTest.php index e4ce2c6a..b0d79a26 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -598,10 +598,11 @@ public function testUpdate( string $table, array $columns, array|string $condition, - string $expectedSQL, - array $expectedParams + array $params, + string $expectedSql, + array $expectedParams, ): void { - parent::testUpdate($table, $columns, $condition, $expectedSQL, $expectedParams); + parent::testUpdate($table, $columns, $condition, $params, $expectedSql, $expectedParams); } /** From 14010bc3109eb17a95604f2bb0320cbac89e9f2f Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 6 Feb 2024 11:06:44 +0000 Subject: [PATCH 2/8] Apply Rector changes (CI) --- tests/CommandTest.php | 2 +- tests/QueryBuilderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index c9731874..43a405a3 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -528,7 +528,7 @@ public function testUpdate( array|string $conditions, array $params, array $expectedValues, - int $expectedCount, + int $expectedCount = null, ): void { parent::testUpdate($table, $columns, $conditions, $params, $expectedValues, $expectedCount); } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index e51df703..6e99d10c 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -614,7 +614,7 @@ public function testUpdate( array|string $condition, array $params, string $expectedSql, - array $expectedParams, + array $expectedParams = null, ): void { parent::testUpdate($table, $columns, $condition, $params, $expectedSql, $expectedParams); } From d5d285e8631ca16c5631b0eb1375070b3aa11e31 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 30 Mar 2024 09:01:35 +0700 Subject: [PATCH 3/8] Adapt SqlParser to the driver --- src/Builder/ExpressionBuilder.php | 16 +++++++ src/DQLQueryBuilder.php | 3 ++ src/SqlParser.php | 64 ++++++++++++++++++++++++++++ tests/Provider/SqlParserProvider.php | 35 +++++++++++++++ tests/SqlParserTest.php | 25 +++++++++++ 5 files changed, 143 insertions(+) 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/src/Builder/ExpressionBuilder.php b/src/Builder/ExpressionBuilder.php new file mode 100644 index 00000000..21917787 --- /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 00000000..114d19a4 --- /dev/null +++ b/src/SqlParser.php @@ -0,0 +1,64 @@ +length - 1; + + while ($this->position < $length) { + $pos = $this->position++; + + match ($this->sql[$pos]) { + ':' => ($word = $this->parseWord()) === '' + ? $this->skipChars(':') + : $result = ':' . $word, + '"' => $this->skipToAfterChar('"'), + "'" => $this->skipQuotedWithoutEscape($this->sql[$pos]), + 'q', 'Q' => $this->sql[$this->position] === "'" + ? $this->skipQuotedWithQ() + : null, + '-' => $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; + } + + /** + * Skips quoted string with Q-operator. + */ + private function skipQuotedWithQ(): void + { + $endChar = match ($this->sql[++$this->position]) { + '[' => ']', + '<' => '>', + '{' => '}', + '(' => ')', + default => $this->sql[$this->position], + }; + + ++$this->position; + + $this->skipToAfterString("$endChar'"); + } +} diff --git a/tests/Provider/SqlParserProvider.php b/tests/Provider/SqlParserProvider.php new file mode 100644 index 00000000..5d7be748 --- /dev/null +++ b/tests/Provider/SqlParserProvider.php @@ -0,0 +1,35 @@ + Date: Sat, 30 Mar 2024 09:29:29 +0700 Subject: [PATCH 4/8] Revert "Apply Rector changes (CI)" This reverts commit 14010bc3109eb17a95604f2bb0320cbac89e9f2f. --- tests/CommandTest.php | 2 +- tests/QueryBuilderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 43a405a3..c9731874 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -528,7 +528,7 @@ public function testUpdate( array|string $conditions, array $params, array $expectedValues, - int $expectedCount = null, + int $expectedCount, ): void { parent::testUpdate($table, $columns, $conditions, $params, $expectedValues, $expectedCount); } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 6e99d10c..e51df703 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -614,7 +614,7 @@ public function testUpdate( array|string $condition, array $params, string $expectedSql, - array $expectedParams = null, + array $expectedParams, ): void { parent::testUpdate($table, $columns, $condition, $params, $expectedSql, $expectedParams); } From 1816199f9c07b289372b6e39ea5820969108682d Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 30 Mar 2024 09:32:21 +0700 Subject: [PATCH 5/8] Disable Rector for ./tests directory --- rector.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 7a9f3ac6..34351531 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 From e60186cfea4834b547d407587501a5f56c47718f Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 30 Mar 2024 10:16:28 +0700 Subject: [PATCH 6/8] Fix psalm issue --- src/ColumnSchema.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ColumnSchema.php b/src/ColumnSchema.php index 6768c494..b0da3736 100644 --- a/src/ColumnSchema.php +++ b/src/ColumnSchema.php @@ -47,6 +47,7 @@ public function dbTypecast(mixed $value): mixed } if (is_string($value)) { + /** @var non-empty-string $placeholder */ $placeholder = uniqid('exp_' . preg_replace('/[^a-z0-9]/i', '', $this->getName())); return new Expression('TO_BLOB(UTL_RAW.CAST_TO_RAW(:' . $placeholder . '))', [$placeholder => $value]); } From 1ec1e063fbea2158bc827f7251cdfa7c1c188877 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 1 Apr 2024 19:22:21 +0700 Subject: [PATCH 7/8] Update according main PR --- src/Builder/ExpressionBuilder.php | 4 ++-- src/SqlParser.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Builder/ExpressionBuilder.php b/src/Builder/ExpressionBuilder.php index 21917787..ad381158 100644 --- a/src/Builder/ExpressionBuilder.php +++ b/src/Builder/ExpressionBuilder.php @@ -4,10 +4,10 @@ namespace Yiisoft\Db\Oracle\Builder; -use Yiisoft\Db\Expression\ExpressionBuilder as BaseExpressionBuilder; +use Yiisoft\Db\Expression\AbstractExpressionBuilder; use Yiisoft\Db\Oracle\SqlParser; -final class ExpressionBuilder extends BaseExpressionBuilder +final class ExpressionBuilder extends AbstractExpressionBuilder { protected function createSqlParser(string $sql): SqlParser { diff --git a/src/SqlParser.php b/src/SqlParser.php index 114d19a4..7d03db6a 100644 --- a/src/SqlParser.php +++ b/src/SqlParser.php @@ -4,9 +4,9 @@ namespace Yiisoft\Db\Oracle; -use Yiisoft\Db\Syntax\SqlParser as BaseSqlParser; +use Yiisoft\Db\Syntax\AbstractSqlParser; -final class SqlParser extends BaseSqlParser +final class SqlParser extends AbstractSqlParser { public function getNextPlaceholder(int|null &$position = null): string|null { From d6f3939b40ad517d6a9d50a9b22fd87973e76414 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 10 Apr 2024 19:13:28 +0700 Subject: [PATCH 8/8] Add line to CHANGELOG.md [skip ci] --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d408078..9db75187 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Oracle driver for Yii Database Change Log -## 1.3.1 under development +## 2.0.0 under development -- no changes in this release. +- Enh #255: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov) ## 1.3.0 March 21, 2024