Skip to content

Commit

Permalink
Refactor column PHP type (#275)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Aug 9, 2024
1 parent d0d06ea commit 62a238b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Enh #236: Implement `ColumnSchemaInterface` classes according to the data type of database table columns
for type casting performance. Related with yiisoft/db#752 (@Tigrov)
- Chg #272: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov)
- Enh #275: Refactor PHP type of `ColumnSchemaInterface` instances (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
4 changes: 2 additions & 2 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Yiisoft\Db\Oracle;

use PDO;
use Yiisoft\Db\Constant\PhpType;
use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
use Yiisoft\Db\QueryBuilder\AbstractQueryBuilder;
use Yiisoft\Db\Schema\SchemaInterface;

use function array_keys;
use function count;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function insertWithReturningPks(string $table, array $columns): bool|arra
'value' => '',
];

if (!isset($columnSchemas[$name]) || $columnSchemas[$name]->getPhpType() !== SchemaInterface::PHP_TYPE_INTEGER) {
if (!isset($columnSchemas[$name]) || $columnSchemas[$name]->getPhpType() !== PhpType::INT) {
$returnParams[$phName]['dataType'] = PDO::PARAM_STR;
} else {
$returnParams[$phName]['dataType'] = PDO::PARAM_INT;
Expand Down
8 changes: 4 additions & 4 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,13 @@ private function loadColumnSchema(array $info): ColumnSchemaInterface
return $column;
}

protected function createColumnSchemaFromPhpType(string $phpType, string $type): ColumnSchemaInterface
protected function createColumnSchemaFromType(string $type, bool $isUnsigned = false): ColumnSchemaInterface
{
if ($phpType === self::PHP_TYPE_RESOURCE) {
return new BinaryColumnSchema($type, $phpType);
if ($type === self::TYPE_BINARY) {
return new BinaryColumnSchema($type);
}

return parent::createColumnSchemaFromPhpType($phpType, $type);
return parent::createColumnSchemaFromType($type, $isUnsigned);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/Provider/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function columns(): array
'int_col' => [
'type' => 'integer',
'dbType' => 'NUMBER',
'phpType' => 'integer',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => false,
'autoIncrement' => false,
Expand All @@ -31,7 +31,7 @@ public static function columns(): array
'int_col2' => [
'type' => 'integer',
'dbType' => 'NUMBER',
'phpType' => 'integer',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => true,
'autoIncrement' => false,
Expand All @@ -44,7 +44,7 @@ public static function columns(): array
'tinyint_col' => [
'type' => 'integer',
'dbType' => 'NUMBER',
'phpType' => 'integer',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => true,
'autoIncrement' => false,
Expand All @@ -57,7 +57,7 @@ public static function columns(): array
'smallint_col' => [
'type' => 'integer',
'dbType' => 'NUMBER',
'phpType' => 'integer',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => true,
'autoIncrement' => false,
Expand Down Expand Up @@ -122,7 +122,7 @@ public static function columns(): array
'float_col' => [
'type' => 'double',
'dbType' => 'FLOAT',
'phpType' => 'double',
'phpType' => 'float',
'primaryKey' => false,
'allowNull' => false,
'autoIncrement' => false,
Expand All @@ -135,7 +135,7 @@ public static function columns(): array
'float_col2' => [
'type' => 'double',
'dbType' => 'FLOAT',
'phpType' => 'double',
'phpType' => 'float',
'primaryKey' => false,
'allowNull' => true,
'autoIncrement' => false,
Expand All @@ -148,7 +148,7 @@ public static function columns(): array
'blob_col' => [
'type' => 'binary',
'dbType' => 'BLOB',
'phpType' => 'resource',
'phpType' => 'mixed',
'primaryKey' => false,
'allowNull' => true,
'autoIncrement' => false,
Expand All @@ -161,7 +161,7 @@ public static function columns(): array
'numeric_col' => [
'type' => 'decimal',
'dbType' => 'NUMBER',
'phpType' => 'double',
'phpType' => 'float',
'primaryKey' => false,
'allowNull' => true,
'autoIncrement' => false,
Expand Down Expand Up @@ -252,7 +252,7 @@ public static function columns(): array
'bit_col' => [
'type' => 'integer',
'dbType' => 'NUMBER',
'phpType' => 'integer',
'phpType' => 'int',
'primaryKey' => false,
'allowNull' => false,
'autoIncrement' => false,
Expand All @@ -270,7 +270,7 @@ public static function columns(): array
'id' => [
'type' => 'integer',
'dbType' => 'NUMBER',
'phpType' => 'integer',
'phpType' => 'int',
'primaryKey' => true,
'allowNull' => false,
'autoIncrement' => true,
Expand Down

0 comments on commit 62a238b

Please sign in to comment.