Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ jobs:
php-version: "8.2"
mysql-version: "9.1"
extension: "mysqli"
- config-file-suffix: "-stringify_fetches"
php-version: "8.2"
mysql-version: "9.1"
extension: "pdo_mysql"
- php-version: "8.2"
mysql-version: "9.1"
extension: "mysqli"
Expand Down
37 changes: 37 additions & 0 deletions ci/github/phpunit/pdo_mysql-stringify_fetches.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
failOnNotice="true"
failOnPhpunitDeprecation="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
>
<php>
<ini name="error_reporting" value="-1" />

<var name="db_driver" value="pdo_mysql"/>
<!-- see \PDO::ATTR_STRINGIFY_FETCHES-->
<var name="db_driver_option_17" value="true"/>
<var name="db_host" value="127.0.0.1" />
<var name="db_port" value="3306"/>
<var name="db_user" value="root" />
<var name="db_dbname" value="doctrine_tests" />
<var name="db_charset" value="utf8mb4" />
</php>

<testsuites>
<testsuite name="Doctrine DBAL Test Suite">
<directory>../../../tests</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory>../../../src</directory>
</include>
</source>
</phpunit>
8 changes: 4 additions & 4 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
switch ($dbType) {
case 'char':
case 'varchar':
$length = $tableColumn['character_maximum_length'];
$length = (int) $tableColumn['character_maximum_length'];
break;

case 'binary':
case 'varbinary':
$length = $tableColumn['character_octet_length'];
$length = (int) $tableColumn['character_octet_length'];
break;

case 'tinytext':
Expand Down Expand Up @@ -167,10 +167,10 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
case 'real':
case 'numeric':
case 'decimal':
$precision = $tableColumn['numeric_precision'];
$precision = (int) $tableColumn['numeric_precision'];

if (isset($tableColumn['numeric_scale'])) {
$scale = $tableColumn['numeric_scale'];
$scale = (int) $tableColumn['numeric_scale'];
}

break;
Expand Down
20 changes: 9 additions & 11 deletions tests/Functional/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\Types\Types;
use PDO;

use function array_change_key_case;

Expand Down Expand Up @@ -555,24 +556,21 @@ public function testPlatformDoesNotSupportCTE(): void
*/
private function prepareExpectedRows(array $rows): array
{
if (! TestUtil::isDriverOneOf('ibm_db2', 'pdo_oci', 'pdo_sqlsrv', 'oci8')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This took quite some time for me to understand all the negated ifs, IMHO keeping the flow as straight forward as possible makes it easier to understand what is going on

return $rows;
}

if (! TestUtil::isDriverOneOf('ibm_db2')) {
if (
TestUtil::isDriverOneOf('pdo_oci', 'pdo_sqlsrv', 'oci8')
|| (TestUtil::getConnectionParams()['driverOptions'][PDO::ATTR_STRINGIFY_FETCHES] ?? false) === true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally did not check for pdo_mysqldriver as this would allow us to easily add the same job for other DB engines, if the ATTR_STRINGIFY_FETCHES option is relevant as well

) {
foreach ($rows as &$row) {
foreach ($row as &$value) {
$value = (string) $value;
}
}
}

if (! TestUtil::isDriverOneOf('ibm_db2', 'pdo_oci', 'oci8')) {
return $rows;
}

foreach ($rows as &$row) {
$row = array_change_key_case($row, CASE_UPPER);
if (TestUtil::isDriverOneOf('ibm_db2', 'pdo_oci', 'oci8')) {
foreach ($rows as &$row) {
$row = array_change_key_case($row, CASE_UPPER);
}
}

return $rows;
Expand Down
22 changes: 22 additions & 0 deletions tests/Functional/Schema/MySQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Doctrine\DBAL\Tests\Functional\Schema\MySQL\CustomType;
use Doctrine\DBAL\Tests\Functional\Schema\MySQL\PointType;
use Doctrine\DBAL\Tests\TestUtil;
use Doctrine\DBAL\Types\BinaryType;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\FloatType;
use Doctrine\DBAL\Types\JsonType;
Expand Down Expand Up @@ -546,6 +547,27 @@ public function testListUnsignedFloatTypeColumns(): void
self::assertTrue($columns['col_smallfloat_unsigned']->getUnsigned());
}

public function testConfigurableLengthColumns(): void
{
$table = Table::editor()
->setUnquotedName('test_configurable_length_columns')
->setColumns(
Column::editor()
->setUnquotedName('col_binary')
->setTypeName(Types::BINARY)
->setLength(16)
->create(),
)
->create();

$this->dropAndCreateTable($table);

$columns = $this->schemaManager->listTableColumns('test_configurable_length_columns');

self::assertInstanceOf(BinaryType::class, $columns['col_binary']->getType());
self::assertSame(16, $columns['col_binary']->getLength());
}

public function testJsonColumnType(): void
{
$table = Table::editor()
Expand Down