Skip to content

Commit

Permalink
Refactor column PHP type
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Aug 8, 2024
1 parent d0d06ea commit 6516106
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
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 6516106

Please sign in to comment.