-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
166 additions
and
5 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
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
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Types; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
use function sprintf; | ||
|
||
class AsciiStringType extends StringType | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSQLDeclaration(array $column, AbstractPlatform $platform) | ||
{ | ||
$length = $column['length'] ?? null; | ||
|
||
if (! isset($column['fixed'])) { | ||
return sprintf('VARCHAR(%d)', $length); | ||
} | ||
|
||
return sprintf('CHAR(%d)', $length); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBindingType() | ||
{ | ||
return ParameterType::ASCII_STRING; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return Types::ASCII_STRING; | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Types; | ||
|
||
use Doctrine\DBAL\Driver\SQLSrv\Driver; | ||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
|
||
class StringBindingTest extends FunctionalTestCase | ||
{ | ||
public function testAsciiStringBinding(): void | ||
{ | ||
if (! $this->driverSupportsAsciiBinding()) { | ||
self::markTestSkipped('Driver does not support ascii string binding'); | ||
} | ||
|
||
$statement = $this->connection->prepare('SELECT sql_variant_property(?, \'BaseType\')'); | ||
|
||
$statement->bindValue(1, 'test', ParameterType::ASCII_STRING); | ||
$results = $statement->execute()->fetchOne(); | ||
|
||
self::assertEquals('varchar', $results); | ||
} | ||
|
||
private function driverSupportsAsciiBinding(): bool | ||
{ | ||
return $this->connection->getDriver() instanceof Driver | ||
|| $this->connection->getDriver() instanceof \Doctrine\DBAL\Driver\PDO\SQLSrv\Driver; | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Types; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
use Doctrine\DBAL\Types\AsciiStringType; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AsciiStringTest extends TestCase | ||
{ | ||
/** @var AbstractPlatform|MockObject */ | ||
private $platform; | ||
|
||
/** @var AsciiStringType */ | ||
private $type; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->platform = $this->createMock(AbstractPlatform::class); | ||
$this->type = new AsciiStringType(); | ||
} | ||
|
||
public function testReturnsBindingType(): void | ||
{ | ||
self::assertEquals($this->type->getBindingType(), ParameterType::ASCII_STRING); | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $column | ||
* | ||
* @dataProvider sqlDeclarationDataProvider | ||
*/ | ||
public function testReturnsSQLDeclaration(string $expectedSql, array $column): void | ||
{ | ||
$declarationSql = $this->type->getSQLDeclaration($column, $this->platform); | ||
self::assertEquals($expectedSql, $declarationSql); | ||
} | ||
|
||
/** | ||
* @return array<int, array{string, array<string, mixed>}> | ||
*/ | ||
public static function sqlDeclarationDataProvider(): array | ||
{ | ||
return [ | ||
['VARCHAR(12)', ['length' => 12]], | ||
['CHAR(12)', ['length' => 12, 'fixed' => true]], | ||
]; | ||
} | ||
} |