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 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 diff --git a/src/Builder/ExpressionBuilder.php b/src/Builder/ExpressionBuilder.php new file mode 100644 index 00000000..96ac22ee --- /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..9698d6d6 --- /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 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/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 @@ +