diff options
author | Anna Larch <anna@nextcloud.com> | 2023-09-14 14:59:06 +0200 |
---|---|---|
committer | Anna <anna@nextcloud.com> | 2023-09-19 11:56:44 +0200 |
commit | 56419d94f8a128b503a8cd6fe74befe908bb2361 (patch) | |
tree | 4b77648640bd8ac98352a690bd5076f109f50f43 /lib/private/DB/ConnectionAdapter.php | |
parent | 8157d9789070e6d38710b1530aa4d903d74ca2ac (diff) | |
download | nextcloud-server-56419d94f8a128b503a8cd6fe74befe908bb2361.tar.gz nextcloud-server-56419d94f8a128b503a8cd6fe74befe908bb2361.zip |
enh(db): provide database providers via API
To avoid leaking internals (OC), wrap the getDatabasePlatform and provide the
associated constants
fixes https://github.com/nextcloud/server/issues/30877
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'lib/private/DB/ConnectionAdapter.php')
-rw-r--r-- | lib/private/DB/ConnectionAdapter.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/private/DB/ConnectionAdapter.php b/lib/private/DB/ConnectionAdapter.php index 56d554f8313..e27c98194fb 100644 --- a/lib/private/DB/ConnectionAdapter.php +++ b/lib/private/DB/ConnectionAdapter.php @@ -27,6 +27,10 @@ namespace OC\DB; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MySQLPlatform; +use Doctrine\DBAL\Platforms\OraclePlatform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\Schema; use OC\DB\Exceptions\DbalException; use OCP\DB\IPreparedStatement; @@ -242,4 +246,19 @@ class ConnectionAdapter implements IDBConnection { public function getInner(): Connection { return $this->inner; } + + public function getDatabaseProvider(): string { + $platform = $this->inner->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'); + } + } } |