diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index d8611802..024affb9 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -11,6 +11,8 @@ use Yiisoft\Db\Schema\SchemaInterface; use Yiisoft\Db\Sqlite\Column\ColumnDefinitionBuilder; +use function bin2hex; + /** * Implements the SQLite Server specific query builder. */ @@ -55,4 +57,9 @@ public function __construct(QuoterInterface $quoter, SchemaInterface $schema) parent::__construct($quoter, $schema, $ddlBuilder, $dmlBuilder, $dqlBuilder, $columnDefinitionBuilder); } + + protected function prepareBinary(string $binary): string + { + return "x'" . bin2hex($binary) . "'"; + } } diff --git a/src/Schema.php b/src/Schema.php index 327c4f91..8526a0db 100644 --- a/src/Schema.php +++ b/src/Schema.php @@ -573,7 +573,7 @@ private function getPragmaForeignKeyList(string $tableName): array private function getPragmaIndexInfo(string $name): array { $column = $this->db - ->createCommand('PRAGMA INDEX_INFO(' . (string) $this->db->getQuoter()->quoteValue($name) . ')') + ->createCommand('PRAGMA INDEX_INFO(' . $this->db->getQuoter()->quoteValue($name) . ')') ->queryAll(); $column = array_map(array_change_key_case(...), $column); DbArrayHelper::multisort($column, 'seqno'); @@ -593,7 +593,7 @@ private function getPragmaIndexList(string $tableName): array { /** @psalm-var IndexListInfo[] */ return $this->db - ->createCommand('PRAGMA INDEX_LIST(' . (string) $this->db->getQuoter()->quoteValue($tableName) . ')') + ->createCommand('PRAGMA INDEX_LIST(' . $this->db->getQuoter()->quoteValue($tableName) . ')') ->queryAll(); } diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index c3f89526..87d34fe8 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -291,4 +291,23 @@ public static function buildColumnDefinition(): array return $values; } + + public static function prepareParam(): array + { + $values = parent::prepareParam(); + + $values['binary'][0] = "x'737472696e67'"; + + return $values; + } + + public static function prepareValue(): array + { + $values = parent::prepareValue(); + + $values['binary'][0] = "x'737472696e67'"; + $values['paramBinary'][0] = "x'737472696e67'"; + + return $values; + } } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index f33fbc8b..cbff92a7 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Sqlite\Tests; use JsonException; +use PHPUnit\Framework\Attributes\DataProviderExternal; use Yiisoft\Db\Constant\ColumnType; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; @@ -18,6 +19,7 @@ use Yiisoft\Db\QueryBuilder\Condition\JsonOverlapsCondition; use Yiisoft\Db\Schema\Column\ColumnSchemaInterface; use Yiisoft\Db\Sqlite\Column; +use Yiisoft\Db\Sqlite\Tests\Provider\QueryBuilderProvider; use Yiisoft\Db\Sqlite\Tests\Support\TestTrait; use Yiisoft\Db\Tests\Common\CommonQueryBuilderTest; @@ -837,9 +839,21 @@ public function testJsonOverlapsConditionOperator(iterable|ExpressionInterface $ $db->close(); } - /** @dataProvider \Yiisoft\Db\Sqlite\Tests\Provider\QueryBuilderProvider::buildColumnDefinition() */ + #[DataProviderExternal(QueryBuilderProvider::class, 'buildColumnDefinition')] public function testBuildColumnDefinition(string $expected, ColumnSchemaInterface|string $column): void { parent::testBuildColumnDefinition($expected, $column); } + + #[DataProviderExternal(QueryBuilderProvider::class, 'prepareParam')] + public function testPrepareParam(string $expected, mixed $value, int $type): void + { + parent::testPrepareParam($expected, $value, $type); + } + + #[DataProviderExternal(QueryBuilderProvider::class, 'prepareValue')] + public function testPrepareValue(string $expected, mixed $value): void + { + parent::testPrepareValue($expected, $value); + } }