Skip to content

Commit cbf95bb

Browse files
authored
Fix length type in MySQLSchemaManager with ATTR_STRINGIFY_FETCHES enabled (#7028)
Fixes #7027 <!-- Fill in the relevant information below to help triage your pull request. --> | Q | A |------------- | ----------- | Type | bug | Fixed issues | #7027 #### Summary The length var was type string, which broke on the constructor of `Column`
1 parent 32c74d1 commit cbf95bb

File tree

5 files changed

+76
-15
lines changed

5 files changed

+76
-15
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ jobs:
182182
php-version: "8.2"
183183
mysql-version: "9.1"
184184
extension: "mysqli"
185+
- config-file-suffix: "-stringify_fetches"
186+
php-version: "8.2"
187+
mysql-version: "9.1"
188+
extension: "pdo_mysql"
185189
- php-version: "8.2"
186190
mysql-version: "9.1"
187191
extension: "mysqli"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
4+
colors="true"
5+
beStrictAboutOutputDuringTests="true"
6+
failOnRisky="true"
7+
failOnWarning="true"
8+
failOnNotice="true"
9+
failOnPhpunitDeprecation="true"
10+
displayDetailsOnTestsThatTriggerErrors="true"
11+
displayDetailsOnTestsThatTriggerDeprecations="true"
12+
>
13+
<php>
14+
<ini name="error_reporting" value="-1" />
15+
16+
<var name="db_driver" value="pdo_mysql"/>
17+
<!-- see \PDO::ATTR_STRINGIFY_FETCHES-->
18+
<var name="db_driver_option_17" value="true"/>
19+
<var name="db_host" value="127.0.0.1" />
20+
<var name="db_port" value="3306"/>
21+
<var name="db_user" value="root" />
22+
<var name="db_dbname" value="doctrine_tests" />
23+
<var name="db_charset" value="utf8mb4" />
24+
</php>
25+
26+
<testsuites>
27+
<testsuite name="Doctrine DBAL Test Suite">
28+
<directory>../../../tests</directory>
29+
</testsuite>
30+
</testsuites>
31+
32+
<source>
33+
<include>
34+
<directory>../../../src</directory>
35+
</include>
36+
</source>
37+
</phpunit>

src/Schema/MySQLSchemaManager.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,12 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
130130
switch ($dbType) {
131131
case 'char':
132132
case 'varchar':
133-
$length = $tableColumn['character_maximum_length'];
133+
$length = (int) $tableColumn['character_maximum_length'];
134134
break;
135135

136136
case 'binary':
137137
case 'varbinary':
138-
$length = $tableColumn['character_octet_length'];
138+
$length = (int) $tableColumn['character_octet_length'];
139139
break;
140140

141141
case 'tinytext':
@@ -167,10 +167,10 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
167167
case 'real':
168168
case 'numeric':
169169
case 'decimal':
170-
$precision = $tableColumn['numeric_precision'];
170+
$precision = (int) $tableColumn['numeric_precision'];
171171

172172
if (isset($tableColumn['numeric_scale'])) {
173-
$scale = $tableColumn['numeric_scale'];
173+
$scale = (int) $tableColumn['numeric_scale'];
174174
}
175175

176176
break;

tests/Functional/Query/QueryBuilderTest.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Doctrine\DBAL\Tests\FunctionalTestCase;
2525
use Doctrine\DBAL\Tests\TestUtil;
2626
use Doctrine\DBAL\Types\Types;
27+
use PDO;
2728

2829
use function array_change_key_case;
2930

@@ -555,24 +556,21 @@ public function testPlatformDoesNotSupportCTE(): void
555556
*/
556557
private function prepareExpectedRows(array $rows): array
557558
{
558-
if (! TestUtil::isDriverOneOf('ibm_db2', 'pdo_oci', 'pdo_sqlsrv', 'oci8')) {
559-
return $rows;
560-
}
561-
562-
if (! TestUtil::isDriverOneOf('ibm_db2')) {
559+
if (
560+
TestUtil::isDriverOneOf('pdo_oci', 'pdo_sqlsrv', 'oci8')
561+
|| (TestUtil::getConnectionParams()['driverOptions'][PDO::ATTR_STRINGIFY_FETCHES] ?? false) === true
562+
) {
563563
foreach ($rows as &$row) {
564564
foreach ($row as &$value) {
565565
$value = (string) $value;
566566
}
567567
}
568568
}
569569

570-
if (! TestUtil::isDriverOneOf('ibm_db2', 'pdo_oci', 'oci8')) {
571-
return $rows;
572-
}
573-
574-
foreach ($rows as &$row) {
575-
$row = array_change_key_case($row, CASE_UPPER);
570+
if (TestUtil::isDriverOneOf('ibm_db2', 'pdo_oci', 'oci8')) {
571+
foreach ($rows as &$row) {
572+
$row = array_change_key_case($row, CASE_UPPER);
573+
}
576574
}
577575

578576
return $rows;

tests/Functional/Schema/MySQLSchemaManagerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Doctrine\DBAL\Tests\Functional\Schema\MySQL\CustomType;
2222
use Doctrine\DBAL\Tests\Functional\Schema\MySQL\PointType;
2323
use Doctrine\DBAL\Tests\TestUtil;
24+
use Doctrine\DBAL\Types\BinaryType;
2425
use Doctrine\DBAL\Types\BlobType;
2526
use Doctrine\DBAL\Types\FloatType;
2627
use Doctrine\DBAL\Types\JsonType;
@@ -546,6 +547,27 @@ public function testListUnsignedFloatTypeColumns(): void
546547
self::assertTrue($columns['col_smallfloat_unsigned']->getUnsigned());
547548
}
548549

550+
public function testConfigurableLengthColumns(): void
551+
{
552+
$table = Table::editor()
553+
->setUnquotedName('test_configurable_length_columns')
554+
->setColumns(
555+
Column::editor()
556+
->setUnquotedName('col_binary')
557+
->setTypeName(Types::BINARY)
558+
->setLength(16)
559+
->create(),
560+
)
561+
->create();
562+
563+
$this->dropAndCreateTable($table);
564+
565+
$columns = $this->schemaManager->listTableColumns('test_configurable_length_columns');
566+
567+
self::assertInstanceOf(BinaryType::class, $columns['col_binary']->getType());
568+
self::assertSame(16, $columns['col_binary']->getLength());
569+
}
570+
549571
public function testJsonColumnType(): void
550572
{
551573
$table = Table::editor()

0 commit comments

Comments
 (0)