Skip to content

Commit b6a10aa

Browse files
committed
Merge branch '3.10.x' into 4.3.x
* 3.10.x: CI: Update SQL Server to version 2022 (#7069) fix(MariaDb): add support of new reserved word `VECTOR` (11.7+) (#7061) Fix binding null as a boolean parameter on pgsql (#7059)
2 parents 54d70d8 + 3626601 commit b6a10aa

File tree

7 files changed

+118
-4
lines changed

7 files changed

+118
-4
lines changed

.github/workflows/phpunit-sqlserver.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
services:
2121
sqlserver:
22-
image: mcr.microsoft.com/mssql/server:2019-latest
22+
image: mcr.microsoft.com/mssql/server:2022-latest
2323
ports:
2424
- '1433:1433'
2525
env:

src/Driver/AbstractMySQLDriver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Doctrine\DBAL\Platforms\MariaDB1010Platform;
1313
use Doctrine\DBAL\Platforms\MariaDB1052Platform;
1414
use Doctrine\DBAL\Platforms\MariaDB1060Platform;
15+
use Doctrine\DBAL\Platforms\MariaDB110700Platform;
1516
use Doctrine\DBAL\Platforms\MariaDBPlatform;
1617
use Doctrine\DBAL\Platforms\MySQL80Platform;
1718
use Doctrine\DBAL\Platforms\MySQL84Platform;
@@ -38,6 +39,10 @@ public function getDatabasePlatform(ServerVersionProvider $versionProvider): Abs
3839
$version = $versionProvider->getServerVersion();
3940
if (stripos($version, 'mariadb') !== false) {
4041
$mariaDbVersion = $this->getMariaDbMysqlVersionNumber($version);
42+
if (version_compare($mariaDbVersion, '11.7.0', '>=')) {
43+
return new MariaDB110700Platform();
44+
}
45+
4146
if (version_compare($mariaDbVersion, '10.10.0', '>=')) {
4247
return new MariaDB1010Platform();
4348
}

src/Driver/PgSQL/Statement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function bindValue(int|string $param, mixed $value, ParameterType $type =
5757
throw UnknownParameter::new((string) $param);
5858
}
5959

60+
if ($value === null) {
61+
$type = ParameterType::NULL;
62+
}
63+
6064
if ($type === ParameterType::BOOLEAN) {
6165
$this->parameters[$this->parameterMap[$param]] = (bool) $value === false ? 'f' : 't';
6266
$this->parameterTypes[$this->parameterMap[$param]] = ParameterType::STRING;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Platforms\Keywords;
6+
7+
use function array_merge;
8+
9+
/** @deprecated */
10+
class MariaDB117Keywords extends MariaDBKeywords
11+
{
12+
/**
13+
* {@inheritDoc}
14+
*
15+
* @link https://mariadb.com/docs/server/reference/sql-structure/sql-language-structure/reserved-words
16+
*/
17+
protected function getKeywords(): array
18+
{
19+
$keywords = parent::getKeywords();
20+
21+
// New Keywords and Reserved Words
22+
$keywords = array_merge($keywords, ['VECTOR']);
23+
24+
return $keywords;
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Platforms;
6+
7+
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
8+
use Doctrine\DBAL\Platforms\Keywords\MariaDB117Keywords;
9+
use Doctrine\Deprecations\Deprecation;
10+
11+
/**
12+
* Provides the behavior, features and SQL dialect of the MariaDB 11.7 database platform.
13+
*/
14+
class MariaDB110700Platform extends MariaDB1010Platform
15+
{
16+
/** @deprecated */
17+
protected function createReservedKeywordsList(): KeywordList
18+
{
19+
Deprecation::triggerIfCalledFromOutside(
20+
'doctrine/dbal',
21+
'https://github.com/doctrine/dbal/pull/6607',
22+
'%s is deprecated.',
23+
__METHOD__,
24+
);
25+
26+
return new MariaDB117Keywords();
27+
}
28+
}

tests/Functional/BooleanBindingTest.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ protected function setUp(): void
2626
Column::editor()
2727
->setUnquotedName('val')
2828
->setTypeName(Types::BOOLEAN)
29+
->setNotNull(false)
2930
->create(),
3031
)
3132
->create();
@@ -39,7 +40,7 @@ protected function tearDown(): void
3940
}
4041

4142
#[DataProvider('booleanProvider')]
42-
public function testBooleanInsert(bool $input): void
43+
public function testBooleanParameterInsert(?bool $input): void
4344
{
4445
$queryBuilder = $this->connection->createQueryBuilder();
4546

@@ -48,11 +49,37 @@ public function testBooleanInsert(bool $input): void
4849
])->executeStatement();
4950

5051
self::assertSame(1, $result);
52+
53+
self::assertSame($input, $this->connection->convertToPHPValue(
54+
$this->connection->fetchOne('SELECT val FROM boolean_test_table'),
55+
Types::BOOLEAN,
56+
));
57+
}
58+
59+
#[DataProvider('booleanProvider')]
60+
public function testBooleanTypeInsert(?bool $input): void
61+
{
62+
$queryBuilder = $this->connection->createQueryBuilder();
63+
64+
$result = $queryBuilder->insert('boolean_test_table')->values([
65+
'val' => $queryBuilder->createNamedParameter($input, Types::BOOLEAN),
66+
])->executeStatement();
67+
68+
self::assertSame(1, $result);
69+
70+
self::assertSame($input, $this->connection->convertToPHPValue(
71+
$this->connection->fetchOne('SELECT val FROM boolean_test_table'),
72+
Types::BOOLEAN,
73+
));
5174
}
5275

53-
/** @return bool[][] */
76+
/** @return array<string, array{bool|null}> */
5477
public static function booleanProvider(): array
5578
{
56-
return [[true], [false]];
79+
return [
80+
'true' => [true],
81+
'false' => [false],
82+
'null' => [null],
83+
];
5784
}
5885
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Tests\Platforms;
6+
7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
use Doctrine\DBAL\Platforms\MariaDB110700Platform;
9+
10+
class MariaDB110700PlatformTest extends MariaDB1052PlatformTest
11+
{
12+
public function createPlatform(): AbstractPlatform
13+
{
14+
return new MariaDB110700Platform();
15+
}
16+
17+
public function testMariaDb117KeywordList(): void
18+
{
19+
$keywordList = $this->platform->getReservedKeywordsList();
20+
21+
self::assertTrue($keywordList->isKeyword('vector'));
22+
self::assertTrue($keywordList->isKeyword('distinctrow'));
23+
}
24+
}

0 commit comments

Comments
 (0)