-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ColumnSchema classes for performance of typecasting (#277)
- Loading branch information
Showing
7 changed files
with
164 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Mssql\Column; | ||
|
||
use Yiisoft\Db\Command\ParamInterface; | ||
use Yiisoft\Db\Expression\Expression; | ||
use Yiisoft\Db\Schema\Column\BinaryColumnSchema as BaseBinaryColumnSchema; | ||
|
||
use function bin2hex; | ||
use function is_string; | ||
|
||
final class BinaryColumnSchema extends BaseBinaryColumnSchema | ||
{ | ||
public function dbTypecast(mixed $value): mixed | ||
{ | ||
if ($this->getDbType() === 'varbinary') { | ||
if ($value instanceof ParamInterface && is_string($value->getValue())) { | ||
/** @psalm-var string */ | ||
$value = $value->getValue(); | ||
} | ||
|
||
if (is_string($value)) { | ||
return new Expression('CONVERT(VARBINARY(MAX), ' . ('0x' . bin2hex($value)) . ')'); | ||
} | ||
} | ||
|
||
return parent::dbTypecast($value); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Mssql\Tests\Provider; | ||
|
||
use Yiisoft\Db\Mssql\Column\BinaryColumnSchema; | ||
|
||
class ColumnSchemaProvider extends \Yiisoft\Db\Tests\Provider\ColumnSchemaProvider | ||
{ | ||
public static function predefinedTypes(): array | ||
{ | ||
$values = parent::predefinedTypes(); | ||
$values['binary'][0] = BinaryColumnSchema::class; | ||
|
||
return $values; | ||
} | ||
|
||
public static function dbTypecastColumns(): array | ||
{ | ||
$values = parent::dbTypecastColumns(); | ||
$values['binary'][0] = BinaryColumnSchema::class; | ||
|
||
return $values; | ||
} | ||
} |