aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/DB/Connection.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-07-01 16:59:47 +0200
committerJoas Schilling <coding@schilljs.com>2024-07-19 11:21:14 +0200
commit829f2b9bc7290c0b1b1a9db373ee26199c9bcc4d (patch)
tree5641e35ffe42897566f58acb1d71a0d9afba4729 /lib/private/DB/Connection.php
parentbd383627a7ef3cb0a8e608b35de067d341f46da4 (diff)
downloadnextcloud-server-829f2b9bc7290c0b1b1a9db373ee26199c9bcc4d.tar.gz
nextcloud-server-829f2b9bc7290c0b1b1a9db373ee26199c9bcc4d.zip
fix(db): Promote the use of `getDatabaseProvider` to reduce the impage of removed upstream platforms
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/DB/Connection.php')
-rw-r--r--lib/private/DB/Connection.php20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php
index c24754a52bd..7aa3a020113 100644
--- a/lib/private/DB/Connection.php
+++ b/lib/private/DB/Connection.php
@@ -17,6 +17,7 @@ use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\OraclePlatform;
+use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Schema;
@@ -25,6 +26,7 @@ use OC\DB\QueryBuilder\QueryBuilder;
use OC\SystemConfig;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Diagnostics\IEventLogger;
+use OCP\IDBConnection;
use OCP\IRequestId;
use OCP\PreConditionNotMetException;
use OCP\Profiler\IProfiler;
@@ -729,4 +731,22 @@ class Connection extends PrimaryReadReplicaConnection {
private function getConnectionName(): string {
return $this->isConnectedToPrimary() ? 'primary' : 'replica';
}
+
+ /**
+ * @return IDBConnection::PLATFORM_MYSQL|IDBConnection::PLATFORM_ORACLE|IDBConnection::PLATFORM_POSTGRES|IDBConnection::PLATFORM_SQLITE
+ */
+ public function getDatabaseProvider(): string {
+ $platform = $this->getDatabasePlatform();
+ if ($platform instanceof MySQLPlatform) {
+ return IDBConnection::PLATFORM_MYSQL;
+ } elseif ($platform instanceof OraclePlatform) {
+ return IDBConnection::PLATFORM_ORACLE;
+ } elseif ($platform instanceof PostgreSQLPlatform) {
+ return IDBConnection::PLATFORM_POSTGRES;
+ } elseif ($platform instanceof SqlitePlatform) {
+ return IDBConnection::PLATFORM_SQLITE;
+ } else {
+ throw new \Exception('Database ' . $platform::class . ' not supported');
+ }
+ }
}