Skip to content

Commit 1332b9e

Browse files
authored
fix(MariaDb): add support of new reserved word VECTOR (11.7+) (#7061)
| Q | A |------------- | ----------- | Type | bug | Fixed issues | #7060 #### Summary Since MariaDb 11.7 there is a new reserved word `VECTOR` which needs to be quoted for e.g. table names. Otherwise dbal will not work with MariaDb LTS 11.8. Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent a4919dd commit 1332b9e

File tree

6 files changed

+107
-1
lines changed

6 files changed

+107
-1
lines changed

src/Driver/AbstractMySQLDriver.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Doctrine\DBAL\Platforms\MariaDb1043Platform;
1414
use Doctrine\DBAL\Platforms\MariaDb1052Platform;
1515
use Doctrine\DBAL\Platforms\MariaDb1060Platform;
16+
use Doctrine\DBAL\Platforms\MariaDb110700Platform;
1617
use Doctrine\DBAL\Platforms\MySQL57Platform;
1718
use Doctrine\DBAL\Platforms\MySQL80Platform;
1819
use Doctrine\DBAL\Platforms\MySQL84Platform;
@@ -42,6 +43,10 @@ public function createDatabasePlatformForVersion($version)
4243

4344
if ($mariadb) {
4445
$mariaDbVersion = $this->getMariaDbMysqlVersionNumber($version);
46+
if (version_compare($mariaDbVersion, '11.7.0', '>=')) {
47+
return new MariaDb110700Platform();
48+
}
49+
4550
if (version_compare($mariaDbVersion, '10.10.0', '>=')) {
4651
return new MariaDb1010Platform();
4752
}

src/Platforms/Keywords/MariaDb102Keywords.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @link https://mariadb.com/kb/en/the-mariadb-library/reserved-words/
1313
*/
14-
final class MariaDb102Keywords extends MariaDBKeywords
14+
class MariaDb102Keywords extends MariaDBKeywords
1515
{
1616
/** @deprecated */
1717
public function getName(): string
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Platforms\Keywords;
6+
7+
use Doctrine\Deprecations\Deprecation;
8+
9+
use function array_merge;
10+
11+
/**
12+
* MariaDB 11.7 reserved keywords list.
13+
*/
14+
class MariaDb117Keywords extends MariaDb102Keywords
15+
{
16+
/**
17+
* {@inheritDoc}
18+
*
19+
* @deprecated
20+
*/
21+
public function getName(): string
22+
{
23+
Deprecation::triggerIfCalledFromOutside(
24+
'doctrine/dbal',
25+
'https://github.com/doctrine/dbal/pull/5433',
26+
'MariaDb117Keywords::getName() is deprecated.',
27+
);
28+
29+
return 'MariaDb117';
30+
}
31+
32+
/**
33+
* {@inheritDoc}
34+
*
35+
* @link https://mariadb.com/docs/server/reference/sql-structure/sql-language-structure/reserved-words
36+
*/
37+
protected function getKeywords(): array
38+
{
39+
$keywords = parent::getKeywords();
40+
41+
// New Keywords and Reserved Words
42+
$keywords = array_merge($keywords, ['VECTOR']);
43+
44+
return $keywords;
45+
}
46+
}
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;
6+
7+
use Doctrine\Deprecations\Deprecation;
8+
9+
/**
10+
* Provides the behavior, features and SQL dialect of the MariaDB 11.7 database platform.
11+
*/
12+
class MariaDb110700Platform extends MariaDb1010Platform
13+
{
14+
/** @deprecated Implement {@see createReservedKeywordsList()} instead. */
15+
protected function getReservedKeywordsClass(): string
16+
{
17+
Deprecation::triggerIfCalledFromOutside(
18+
'doctrine/dbal',
19+
'https://github.com/doctrine/dbal/issues/4510',
20+
'MariaDb110700Platform::getReservedKeywordsClass() is deprecated,'
21+
. ' use MariaDb110700Platform::createReservedKeywordsList() instead.',
22+
);
23+
24+
return Keywords\MariaDb117Keywords::class;
25+
}
26+
}

src/Tools/Console/Command/ReservedWordsCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\DBAL\Platforms\Keywords\DB2Keywords;
88
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
99
use Doctrine\DBAL\Platforms\Keywords\MariaDb102Keywords;
10+
use Doctrine\DBAL\Platforms\Keywords\MariaDb117Keywords;
1011
use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords;
1112
use Doctrine\DBAL\Platforms\Keywords\MySQL80Keywords;
1213
use Doctrine\DBAL\Platforms\Keywords\MySQL84Keywords;
@@ -57,6 +58,7 @@ public function __construct(ConnectionProvider $connectionProvider)
5758
$this->keywordLists = [
5859
'db2' => new DB2Keywords(),
5960
'mariadb102' => new MariaDb102Keywords(),
61+
'mariadb117' => new MariaDb117Keywords(),
6062
'mysql' => new MySQLKeywords(),
6163
'mysql57' => new MySQL57Keywords(),
6264
'mysql80' => new MySQL80Keywords(),
@@ -128,6 +130,7 @@ private function doConfigure(): void
128130
129131
* db2
130132
* mariadb102
133+
* mariadb117
131134
* mysql
132135
* mysql57
133136
* mysql80
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\Tests\Platforms;
6+
7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
use Doctrine\DBAL\Platforms\Keywords\KeywordList;
9+
use Doctrine\DBAL\Platforms\MariaDb110700Platform;
10+
11+
class MariaDb110700PlatformTest extends MariaDb1052PlatformTest
12+
{
13+
public function createPlatform(): AbstractPlatform
14+
{
15+
return new MariaDb110700Platform();
16+
}
17+
18+
public function testMariaDb117KeywordList(): void
19+
{
20+
$keywordList = $this->platform->getReservedKeywordsList();
21+
self::assertInstanceOf(KeywordList::class, $keywordList);
22+
23+
self::assertTrue($keywordList->isKeyword('vector'));
24+
self::assertTrue($keywordList->isKeyword('distinctrow'));
25+
}
26+
}

0 commit comments

Comments
 (0)