Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor column PHP type #275

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading