diff --git a/CHANGELOG.md b/CHANGELOG.md index 85434d58..ad0621a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ # MySQL driver for Yii Database Change Log -## 1.2.1 under development +## 2.0.0 under development - Enh #320: Minor refactoring of `DDLQueryBuilder::getColumnDefinition()` method (@Tigrov) - Bug #320: Change visibility of `DDLQueryBuilder::getColumnDefinition()` method to `private` (@Tigrov) +- Enh #321: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/composer.json b/composer.json index 010b8b10..a4272589 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "forum": "https://www.yiiframework.com/forum/", "wiki": "https://www.yiiframework.com/wiki/", "chat": "https://t.me/yii3en", - "irc": "irc://irc.freenode.net/yii" + "irc": "ircs://irc.libera.chat:6697/yii" }, "require": { "php": "^8.0", diff --git a/src/Builder/ExpressionBuilder.php b/src/Builder/ExpressionBuilder.php new file mode 100644 index 00000000..b495322d --- /dev/null +++ b/src/Builder/ExpressionBuilder.php @@ -0,0 +1,16 @@ +buildExpression($offset) : (string)$offset) . @@ -83,6 +84,7 @@ protected function defaultExpressionBuilders(): array parent::defaultExpressionBuilders(), [ JsonExpression::class => JsonExpressionBuilder::class, + Expression::class => ExpressionBuilder::class, ] ); } diff --git a/src/SqlParser.php b/src/SqlParser.php new file mode 100644 index 00000000..e89eb612 --- /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 54d373af..9c707717 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 00000000..7e1a91a6 --- /dev/null +++ b/tests/Provider/SqlParserProvider.php @@ -0,0 +1,35 @@ +