Skip to content

Commit 5ecd3c4

Browse files
pulsejetnickvergessen
authored andcommitted
feat(database): Add option to test for mariadb
There are some behavioral differences that apps may need to check for. See discussion on #51175 for more info. This preserves the existing behavior of getDatabaseProvider() Signed-off-by: Varun Patil <[email protected]>
1 parent 1518ded commit 5ecd3c4

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

lib/private/DB/Connection.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
1717
use Doctrine\DBAL\Exception;
1818
use Doctrine\DBAL\Exception\ConnectionLost;
19+
use Doctrine\DBAL\Platforms\MariaDBPlatform;
1920
use Doctrine\DBAL\Platforms\MySQLPlatform;
2021
use Doctrine\DBAL\Platforms\OraclePlatform;
2122
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
@@ -915,11 +916,13 @@ private function getConnectionName(): string {
915916
}
916917

917918
/**
918-
* @return IDBConnection::PLATFORM_MYSQL|IDBConnection::PLATFORM_ORACLE|IDBConnection::PLATFORM_POSTGRES|IDBConnection::PLATFORM_SQLITE
919+
* @return IDBConnection::PLATFORM_MYSQL|IDBConnection::PLATFORM_ORACLE|IDBConnection::PLATFORM_POSTGRES|IDBConnection::PLATFORM_SQLITE|IDBConnection::PLATFORM_MARIADB
919920
*/
920-
public function getDatabaseProvider(): string {
921+
public function getDatabaseProvider(bool $strict = false): string {
921922
$platform = $this->getDatabasePlatform();
922-
if ($platform instanceof MySQLPlatform) {
923+
if ($strict && $platform instanceof MariaDBPlatform) {
924+
return IDBConnection::PLATFORM_MARIADB;
925+
} elseif ($platform instanceof MySQLPlatform) {
923926
return IDBConnection::PLATFORM_MYSQL;
924927
} elseif ($platform instanceof OraclePlatform) {
925928
return IDBConnection::PLATFORM_ORACLE;

lib/private/DB/ConnectionAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ public function getInner(): Connection {
237237
}
238238

239239
/**
240-
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE
240+
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE|self::PLATFORM_MARIADB
241241
*/
242-
public function getDatabaseProvider(): string {
243-
return $this->inner->getDatabaseProvider();
242+
public function getDatabaseProvider(bool $strict = false): string {
243+
return $this->inner->getDatabaseProvider($strict);
244244
}
245245

246246
/**

lib/private/DB/QueryBuilder/QueryBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function expr() {
9696
return match($this->connection->getDatabaseProvider()) {
9797
IDBConnection::PLATFORM_ORACLE => new OCIExpressionBuilder($this->connection, $this, $this->logger),
9898
IDBConnection::PLATFORM_POSTGRES => new PgSqlExpressionBuilder($this->connection, $this, $this->logger),
99+
IDBConnection::PLATFORM_MARIADB,
99100
IDBConnection::PLATFORM_MYSQL => new MySqlExpressionBuilder($this->connection, $this, $this->logger),
100101
IDBConnection::PLATFORM_SQLITE => new SqliteExpressionBuilder($this->connection, $this, $this->logger),
101102
};
@@ -121,6 +122,7 @@ public function func() {
121122
return match($this->connection->getDatabaseProvider()) {
122123
IDBConnection::PLATFORM_ORACLE => new OCIFunctionBuilder($this->connection, $this, $this->helper),
123124
IDBConnection::PLATFORM_POSTGRES => new PgSqlFunctionBuilder($this->connection, $this, $this->helper),
125+
IDBConnection::PLATFORM_MARIADB,
124126
IDBConnection::PLATFORM_MYSQL => new FunctionBuilder($this->connection, $this, $this->helper),
125127
IDBConnection::PLATFORM_SQLITE => new SqliteFunctionBuilder($this->connection, $this, $this->helper),
126128
};

lib/public/IDBConnection.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ interface IDBConnection {
4444
*/
4545
public const PLATFORM_SQLITE = 'sqlite';
4646

47+
/**
48+
* @since 32.0.0
49+
*/
50+
public const PLATFORM_MARIADB = 'mariadb';
51+
4752
/**
4853
* Gets the QueryBuilder for the connection.
4954
*
@@ -357,11 +362,15 @@ public function migrateToSchema(Schema $toSchema): void;
357362

358363
/**
359364
* Returns the database provider name
365+
*
360366
* @link https://github.com/nextcloud/server/issues/30877
367+
*
368+
* @param bool $strict differentiate between database flavors, e.g. MySQL vs MariaDB
369+
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE|self::PLATFORM_MARIADB
370+
* @since 32.0.0 Optional parameter $strict was added
361371
* @since 28.0.0
362-
* @return self::PLATFORM_MYSQL|self::PLATFORM_ORACLE|self::PLATFORM_POSTGRES|self::PLATFORM_SQLITE
363372
*/
364-
public function getDatabaseProvider(): string;
373+
public function getDatabaseProvider(bool $strict = false): string;
365374

366375
/**
367376
* Get the shard definition by name, if configured

0 commit comments

Comments
 (0)