Skip to content

Commit

Permalink
Merge branch 'master' into ease-local-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Dec 2, 2024
2 parents 026bcf5 + 4e9fa61 commit 2f68a80
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- Enh #286: Use constructor to create columns and initialize properties (@Tigrov)
- Enh #288: Refactor `Schema::findColumns()` method (@Tigrov)
- Enh #289: Refactor `Schema::normalizeDefaultValue()` method and move it to `ColumnFactory` class (@Tigrov)
- New #292: Override `QueryBuilder::prepareBinary()` method (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
2 changes: 1 addition & 1 deletion src/Builder/LikeConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function build(LikeConditionInterface $expression, array &$params = []):
* Different pdo_oci8 versions may or may not implement `PDO::quote()`, so {@see Quoter::quoteValue()} may or
* may not quote `\`.
*/
$this->escapingReplacements['\\'] = substr((string) $this->queryBuilder->quoter()->quoteValue('\\'), 1, -1);
$this->escapingReplacements['\\'] = substr($this->queryBuilder->quoter()->quoteValue('\\'), 1, -1);
}

return parent::build($expression, $params);
Expand Down
3 changes: 2 additions & 1 deletion src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Db\Oracle;

use PDO;
use Yiisoft\Db\Command\DataType;
use Yiisoft\Db\Constant\PhpType;
use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder;
Expand Down Expand Up @@ -64,7 +65,7 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
$this->setSql($sql)->bindValues($params);
$this->prepare(false);

/** @psalm-var array<string, array{column: string, value: mixed, dataType: int, size: int}> $returnParams */
/** @psalm-var array<string, array{column: string, value: mixed, dataType: DataType::*, size: int}> $returnParams */
foreach ($returnParams as $name => &$value) {
$this->bindParam($name, $value['value'], $value['dataType'], $value['size']);
}
Expand Down
7 changes: 7 additions & 0 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Yiisoft\Db\Schema\QuoterInterface;
use Yiisoft\Db\Schema\SchemaInterface;

use function bin2hex;

/**
* Implements the Oracle Server specific query builder.
*/
Expand Down Expand Up @@ -54,4 +56,9 @@ public function __construct(QuoterInterface $quoter, SchemaInterface $schema)

parent::__construct($quoter, $schema, $ddlBuilder, $dmlBuilder, $dqlBuilder, $columnDefinitionBuilder);
}

protected function prepareBinary(string $binary): string
{
return "HEXTORAW('" . bin2hex($binary) . "')";
}
}
21 changes: 20 additions & 1 deletion tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public static function buildColumnDefinition(): array
$values["defaultValue('')"][0] = "varchar2(255) DEFAULT ''";
$values['defaultValue(null)'][0] = 'varchar2(255) DEFAULT NULL';
$values['defaultValue($expression)'][0] = 'number(10) DEFAULT (1 + 2)';
$values['notNull()->defaultValue(null)'][0] = 'varchar2(255) NOT NULL';
$values['defaultValue($emptyExpression)'][0] = 'number(10)';
$values['notNull()'][0] = 'varchar2(255) NOT NULL';
$values['null()'][0] = 'varchar2(255) NULL';
$values['integer()->primaryKey()'][0] = 'number(10) PRIMARY KEY';
Expand All @@ -337,4 +337,23 @@ public static function buildColumnDefinition(): array
['number(10) REFERENCES "ref_table" ("id") ON DELETE SET NULL', ColumnBuilder::integer()->reference($referenceSetNull)],
];
}

public static function prepareParam(): array
{
$values = parent::prepareParam();

$values['binary'][0] = "HEXTORAW('737472696e67')";

return $values;
}

public static function prepareValue(): array
{
$values = parent::prepareValue();

$values['binary'][0] = "HEXTORAW('737472696e67')";
$values['paramBinary'][0] = "HEXTORAW('737472696e67')";

return $values;
}
}
16 changes: 15 additions & 1 deletion tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace Yiisoft\Db\Oracle\Tests;

use PHPUnit\Framework\Attributes\DataProviderExternal;
use Throwable;
use Yiisoft\Db\Constant\ColumnType;
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidArgumentException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Oracle\Tests\Provider\QueryBuilderProvider;
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Query\QueryInterface;
Expand Down Expand Up @@ -672,9 +674,21 @@ public function testSelectScalar(array|bool|float|int|string $columns, string $e
parent::testSelectScalar($columns, $expected);
}

/** @dataProvider \Yiisoft\Db\Oracle\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);
}
}

0 comments on commit 2f68a80

Please sign in to comment.