-
-
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
16 changed files
with
272 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
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\Types; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Platforms\AbstractPlatform; | ||
|
||
class AsciiStringType extends StringType | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSQLDeclaration(array $column, AbstractPlatform $platform) | ||
{ | ||
return $platform->getAsciiStringTypeDeclarationSQL($column); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getBindingType() | ||
{ | ||
return ParameterType::ASCII; | ||
} | ||
|
||
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\ParameterTypes; | ||
|
||
use Doctrine\DBAL\Driver\AbstractSQLServerDriver; | ||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
|
||
class AsciiTest extends FunctionalTestCase | ||
{ | ||
public function testAsciiBinding(): void | ||
{ | ||
if (! $this->connection->getDriver() instanceof AbstractSQLServerDriver) { | ||
self::markTestSkipped('Driver does not support ascii string binding'); | ||
} | ||
|
||
$statement = $this->connection->prepare('SELECT sql_variant_property(?, \'BaseType\')'); | ||
|
||
$statement->bindValue(1, 'test', ParameterType::ASCII); | ||
$results = $statement->execute()->fetchOne(); | ||
|
||
self::assertEquals('varchar', $results); | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Types; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
|
||
class AsciiStringTest extends FunctionalTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$table = new Table('ascii_table'); | ||
$table->addColumn('id', 'ascii_string', [ | ||
'length' => 3, | ||
'fixed' => true, | ||
]); | ||
|
||
$table->addColumn('val', 'ascii_string', ['length' => 4]); | ||
$table->setPrimaryKey(['id']); | ||
|
||
$sm = $this->connection->getSchemaManager(); | ||
$sm->dropAndCreateTable($table); | ||
} | ||
|
||
public function testInsertAndSelect(): void | ||
{ | ||
$id1 = 'id1'; | ||
$id2 = 'id2'; | ||
|
||
$value1 = 'val1'; | ||
$value2 = 'val2'; | ||
|
||
$this->insert($id1, $value1); | ||
$this->insert($id2, $value2); | ||
|
||
self::assertSame($value1, $this->select($id1)); | ||
self::assertSame($value2, $this->select($id2)); | ||
} | ||
|
||
private function insert(string $id, string $value): void | ||
{ | ||
$result = $this->connection->insert('ascii_table', [ | ||
'id' => $id, | ||
'val' => $value, | ||
], [ | ||
ParameterType::ASCII, | ||
ParameterType::ASCII, | ||
]); | ||
|
||
self::assertSame(1, $result); | ||
} | ||
|
||
private function select(string $id): string | ||
{ | ||
$value = $this->connection->fetchOne( | ||
'SELECT val FROM ascii_table WHERE id = ?', | ||
[$id], | ||
[ParameterType::ASCII] | ||
); | ||
|
||
self::assertIsString($value); | ||
|
||
return $value; | ||
} | ||
} |
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,43 @@ | ||
<?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\TestCase; | ||
|
||
class AsciiStringTest extends TestCase | ||
{ | ||
/** @var AsciiStringType */ | ||
private $type; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->type = new AsciiStringType(); | ||
} | ||
|
||
public function testReturnCorrectBindingType(): void | ||
{ | ||
self::assertEquals($this->type->getBindingType(), ParameterType::ASCII); | ||
} | ||
|
||
public function testDelegateToPlatformForSqlDeclaration(): void | ||
{ | ||
$columnDefinitions = [ | ||
[['length' => 12, 'fixed' => true]], | ||
[['length' => 14]], | ||
]; | ||
|
||
foreach ($columnDefinitions as $column) { | ||
$platform = $this->createMock(AbstractPlatform::class); | ||
$platform->expects(self::once()) | ||
->method('getAsciiStringTypeDeclarationSQL') | ||
->with($column); | ||
|
||
$this->type->getSQLDeclaration($column, $platform); | ||
} | ||
} | ||
} |