Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve
Browse files Browse the repository at this point in the history
Tigrov committed May 5, 2024
1 parent 21f67d5 commit 9341cb8
Showing 5 changed files with 14 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Db\Mssql;
namespace Yiisoft\Db\Mssql\Column;

use Yiisoft\Db\Command\ParamInterface;
use Yiisoft\Db\Expression\Expression;
62 changes: 0 additions & 62 deletions src/ColumnSchema.php

This file was deleted.

15 changes: 8 additions & 7 deletions src/Schema.php
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Helper\DbArrayHelper;
use Yiisoft\Db\Mssql\Column\BinaryColumnSchema;
use Yiisoft\Db\Schema\Builder\ColumnInterface;
use Yiisoft\Db\Schema\Column\ColumnSchemaInterface;
use Yiisoft\Db\Schema\TableSchemaInterface;
@@ -467,13 +468,13 @@ private function getColumnType(string $dbType, array &$info): string
return self::TYPE_MAP[$dbType] ?? self::TYPE_STRING;
}

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);
}

/**
@@ -577,10 +578,10 @@ protected function findColumns(TableSchemaInterface $table): bool
return false;
}

foreach ($columns as $column) {
$column = $this->loadColumnSchema($column);
foreach ($columns as $info) {
$column = $this->loadColumnSchema($info);
foreach ($table->getPrimaryKey() as $primaryKey) {
if (strcasecmp($column->getName(), $primaryKey) === 0) {
if (strcasecmp($info['column_name'], $primaryKey) === 0) {
$column->primaryKey(true);
break;
}
@@ -590,7 +591,7 @@ protected function findColumns(TableSchemaInterface $table): bool
$table->sequenceName('');
}

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

return true;
7 changes: 4 additions & 3 deletions tests/ColumnSchemaTest.php
Original file line number Diff line number Diff line change
@@ -7,9 +7,10 @@
use PDO;
use Yiisoft\Db\Command\Param;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Mssql\BinaryColumnSchema;
use Yiisoft\Db\Mssql\Column\BinaryColumnSchema;
use Yiisoft\Db\Mssql\Tests\Support\TestTrait;
use Yiisoft\Db\Query\Query;
use Yiisoft\Db\Schema\Column\BooleanColumnSchema;
use Yiisoft\Db\Schema\Column\DoubleColumnSchema;
use Yiisoft\Db\Schema\Column\IntegerColumnSchema;
use Yiisoft\Db\Schema\Column\StringColumnSchema;
@@ -78,6 +79,7 @@ public function testColumnSchemaInstance()
$this->assertInstanceOf(StringColumnSchema::class, $tableSchema->getColumn('char_col'));
$this->assertInstanceOf(DoubleColumnSchema::class, $tableSchema->getColumn('float_col'));
$this->assertInstanceOf(BinaryColumnSchema::class, $tableSchema->getColumn('blob_col'));
$this->assertInstanceOf(BooleanColumnSchema::class, $tableSchema->getColumn('bool_col'));
}

/** @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\ColumnSchemaProvider::predefinedTypes */
@@ -94,10 +96,9 @@ public function testDbTypecastColumns(string $className, array $values)

public function testBinaryColumnSchema()
{
$binaryCol = new BinaryColumnSchema('binary_col');
$binaryCol = new BinaryColumnSchema();
$binaryCol->dbType('varbinary');

$this->assertSame('binary_col', $binaryCol->getName());
$this->assertEquals(
new Expression('CONVERT(VARBINARY(MAX), 0x101112)'),
$binaryCol->dbTypecast("\x10\x11\x12"),
2 changes: 1 addition & 1 deletion tests/Provider/ColumnSchemaProvider.php
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

namespace Yiisoft\Db\Mssql\Tests\Provider;

use Yiisoft\Db\Mssql\BinaryColumnSchema;
use Yiisoft\Db\Mssql\Column\BinaryColumnSchema;

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

0 comments on commit 9341cb8

Please sign in to comment.