Skip to content

Commit

Permalink
Improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed May 5, 2024
1 parent 22532c0 commit 2ccd6ff
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 81 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Enh #260: Support `Traversable` values for `DMLQueryBuilder::batchInsert()` method with empty columns (@Tigrov)
- Enh #255: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov)
- Enh #236: Implement `ColumnSchemaInterface` classes according to the data type of database table columns
for type casting performance. Related with yiisoft/db#752 (@Tigrov)

## 1.3.0 March 21, 2024

Expand All @@ -17,8 +19,6 @@
## 1.2.0 November 12, 2023

- Enh #230: Improve column type #230 (@Tigrov)
- Enh #236: Implement `ColumnSchemaInterface` classes according to the data type of database table columns
for type casting performance. Related with yiisoft/db#752 (@Tigrov)
- Enh #243: Move methods from `Command` to `AbstractPdoCommand` class (@Tigrov)
- Bug #233: Refactor `DMLQueryBuilder`, related with yiisoft/db#746 (@Tigrov)
- Bug #240: Remove `RECURSIVE` expression from CTE queries (@Tigrov)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Db\Oracle;
namespace Yiisoft\Db\Oracle\Column;

use Yiisoft\Db\Command\ParamInterface;
use Yiisoft\Db\Expression\Expression;
Expand All @@ -16,13 +16,12 @@ public function dbTypecast(mixed $value): mixed
{
if ($this->getDbType() === 'BLOB') {
if ($value instanceof ParamInterface && is_string($value->getValue())) {
/** @psalm-var string */
/** @var string */
$value = $value->getValue();
}

if (is_string($value)) {
$placeholder = uniqid('exp_' . preg_replace('/[^a-z0-9]/i', '', $this->getName()));
return new Expression('TO_BLOB(UTL_RAW.CAST_TO_RAW(:' . $placeholder . '))', [$placeholder => $value]);
return new Expression('TO_BLOB(UTL_RAW.CAST_TO_RAW(:value))', ['value' => $value]);
}
}

Expand Down
66 changes: 0 additions & 66 deletions src/ColumnSchema.php

This file was deleted.

16 changes: 9 additions & 7 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Helper\DbArrayHelper;
use Yiisoft\Db\Oracle\Column\BinaryColumnSchema;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\TableSchemaInterface;
Expand Down Expand Up @@ -405,14 +406,14 @@ protected function findColumns(TableSchemaInterface $table): bool
return false;
}

/** @psalm-var ColumnInfoArray $info */
/** @psalm-var string[][] $info */
foreach ($columns as $info) {
/** @psalm-var ColumnInfoArray $info */
$info = array_change_key_case($info);

$column = $this->loadColumnSchema($info);

$table->column($column->getName(), $column);
$table->column($info['column_name'], $column);
}

return true;
Expand Down Expand Up @@ -460,8 +461,9 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface
{
$dbType = $info['data_type'];
$type = $this->extractColumnType($dbType, $info);
/** @psalm-var ColumnInfoArray $info */
$column = $this->createColumnSchema($type, $info['column_name']);

$column = $this->createColumnSchema($type);
$column->name($info['column_name']);
$column->allowNull($info['nullable'] === 'Y');
$column->comment($info['column_comment']);
$column->primaryKey((bool) $info['is_pk']);
Expand All @@ -475,13 +477,13 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface
return $column;
}

protected function createPhpTypeColumnSchema(string $phpType, string $name): ColumnSchemaInterface
protected function createColumnSchemaFromPhpType(string $phpType, string $type): ColumnSchemaInterface
{
if ($phpType === self::PHP_TYPE_RESOURCE) {
return new BinaryColumnSchema($name);
return new BinaryColumnSchema($type, $phpType);
}

return parent::createPhpTypeColumnSchema($phpType, $name);
return parent::createColumnSchemaFromPhpType($phpType, $type);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/ColumnSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use PDO;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Oracle\BinaryColumnSchema;
use Yiisoft\Db\Oracle\Column\BinaryColumnSchema;
use Yiisoft\Db\Oracle\Tests\Support\TestTrait;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Schema\Column\DoubleColumnSchema;
Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/ColumnSchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Yiisoft\Db\Oracle\Tests\Provider;

use Yiisoft\Db\Oracle\BinaryColumnSchema;
use Yiisoft\Db\Oracle\Column\BinaryColumnSchema;

class ColumnSchemaProvider extends \Yiisoft\Db\Tests\Provider\ColumnSchemaProvider
{
Expand Down

0 comments on commit 2ccd6ff

Please sign in to comment.