From ff49c812fe21ff127be98458b460471c9e54e80e Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 6 Feb 2024 17:24:43 +0700 Subject: [PATCH 1/7] 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 7f3dbd4d..32486c27 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -465,9 +465,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 a54377ea..a14c9116 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -703,10 +703,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 27e9acc438c9fe6cc13716444ba24ad5edf3183c Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 6 Feb 2024 10:33:38 +0000 Subject: [PATCH 2/7] 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 32486c27..2fbc8944 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -466,7 +466,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 a14c9116..f50e2e45 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -705,7 +705,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 4dc6b6515e34562715ccd314c206d6bd2427596f Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 30 Mar 2024 09:00:58 +0700 Subject: [PATCH 3/7] Adapt SqlParser to the driver --- src/Builder/ExpressionBuilder.php | 16 ++++++++++ src/DQLQueryBuilder.php | 3 ++ src/SqlParser.php | 45 ++++++++++++++++++++++++++++ tests/Provider/SqlParserProvider.php | 30 +++++++++++++++++++ tests/SqlParserTest.php | 25 ++++++++++++++++ 5 files changed, 119 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..8b7ca4f4 --- /dev/null +++ b/src/Builder/ExpressionBuilder.php @@ -0,0 +1,16 @@ + LikeConditionBuilder::class, InCondition::class => InConditionBuilder::class, JsonExpression::class => JsonExpressionBuilder::class, + Expression::class => ExpressionBuilder::class, ]); } } diff --git a/src/SqlParser.php b/src/SqlParser.php new file mode 100644 index 00000000..a2ead72b --- /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/Provider/SqlParserProvider.php b/tests/Provider/SqlParserProvider.php new file mode 100644 index 00000000..77912c60 --- /dev/null +++ b/tests/Provider/SqlParserProvider.php @@ -0,0 +1,30 @@ + Date: Sat, 30 Mar 2024 09:28:00 +0700 Subject: [PATCH 4/7] Revert "Apply Rector changes (CI)" This reverts commit 27e9acc438c9fe6cc13716444ba24ad5edf3183c. --- 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 2fbc8944..32486c27 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -466,7 +466,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 f50e2e45..a14c9116 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -705,7 +705,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 7992f28d63a38b1db69fa65772719d1137fb3627 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 30 Mar 2024 09:32:07 +0700 Subject: [PATCH 5/7] Disable Rector for ./tests directory --- rector.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rector.php b/rector.php index 6d4e4d49..8cbdabbd 100644 --- a/rector.php +++ b/rector.php @@ -11,7 +11,10 @@ $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 f83b888ef1983a20456a01706e4ff6d3d0f4f451 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 1 Apr 2024 19:22:06 +0700 Subject: [PATCH 6/7] 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 8b7ca4f4..96ac22ee 100644 --- a/src/Builder/ExpressionBuilder.php +++ b/src/Builder/ExpressionBuilder.php @@ -4,10 +4,10 @@ namespace Yiisoft\Db\Sqlite\Builder; -use Yiisoft\Db\Expression\ExpressionBuilder as BaseExpressionBuilder; +use Yiisoft\Db\Expression\AbstractExpressionBuilder; use Yiisoft\Db\Sqlite\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 a2ead72b..9698d6d6 100644 --- a/src/SqlParser.php +++ b/src/SqlParser.php @@ -4,9 +4,9 @@ namespace Yiisoft\Db\Sqlite; -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 e0c2aeeecfa230cdb1832a039d1d5674566a2755 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 10 Apr 2024 19:09:05 +0700 Subject: [PATCH 7/7] 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 39a530e9..abb54123 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # SQLite driver for Yii Database Change Log -## 1.2.1 under development +## 2.0.0 under development -- no changes in this release. +- Enh #289: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov) ## 1.2.0 March 21, 2024