]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(db): Fix md5 for oracle >= 20 46605/head
authorJoas Schilling <coding@schilljs.com>
Fri, 19 Jul 2024 10:54:40 +0000 (12:54 +0200)
committerJoas Schilling <coding@schilljs.com>
Fri, 19 Jul 2024 12:13:56 +0000 (14:13 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/DB/Connection.php
lib/private/DB/ConnectionAdapter.php
lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php
lib/private/DB/QueryBuilder/FunctionBuilder/OCIFunctionBuilder.php

index f59c6b34836def38d1547e5b738d1ba10470ad59..e584690f95d3ae9a273e77e8b9cca7e97b3bf424 100644 (file)
@@ -13,6 +13,7 @@ use Doctrine\DBAL\Cache\QueryCacheProfile;
 use Doctrine\DBAL\Configuration;
 use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
 use Doctrine\DBAL\Driver;
+use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
 use Doctrine\DBAL\Exception;
 use Doctrine\DBAL\Exception\ConnectionLost;
 use Doctrine\DBAL\Platforms\MySQLPlatform;
@@ -749,4 +750,13 @@ class Connection extends PrimaryReadReplicaConnection {
                        throw new \Exception('Database ' . $platform::class . ' not supported');
                }
        }
+
+       /**
+        * @internal Should only be used inside the QueryBuilder, ExpressionBuilder and FunctionBuilder
+        * All apps and API code should not need this and instead use provided functionality from the above.
+        */
+       public function getServerVersion(): string {
+               /** @var ServerInfoAwareConnection $this->_conn */
+               return $this->_conn->getServerVersion();
+       }
 }
index 8a919696eaa2f8a211d41774dad1d4e7fc6db211..b7225169e4c2855b986a553336a2f1ceeaf86870 100644 (file)
@@ -232,4 +232,12 @@ class ConnectionAdapter implements IDBConnection {
        public function getDatabaseProvider(): string {
                return $this->inner->getDatabaseProvider();
        }
+
+       /**
+        * @internal Should only be used inside the QueryBuilder, ExpressionBuilder and FunctionBuilder
+        * All apps and API code should not need this and instead use provided functionality from the above.
+        */
+       public function getServerVersion(): string {
+               return $this->inner->getServerVersion();
+       }
 }
index b168d2c1a844985380c26c255a5639ebeb6b9f5a..2466493c1fa54cb0e752fe79f8e75c85ebda4bb5 100644 (file)
@@ -5,6 +5,7 @@
  */
 namespace OC\DB\QueryBuilder\FunctionBuilder;
 
+use OC\DB\Connection;
 use OC\DB\QueryBuilder\QueryFunction;
 use OC\DB\QueryBuilder\QuoteHelper;
 use OCP\DB\QueryBuilder\IFunctionBuilder;
@@ -13,7 +14,7 @@ use OCP\DB\QueryBuilder\IQueryFunction;
 use OCP\IDBConnection;
 
 class FunctionBuilder implements IFunctionBuilder {
-       /** @var IDBConnection */
+       /** @var IDBConnection|Connection */
        protected $connection;
 
        /** @var IQueryBuilder */
index d0258eafea879412a0813f6e6def4b939c6b0972..a8dc4d8cf14f47c83f38e7526aea20d492aa1e72 100644 (file)
@@ -12,6 +12,9 @@ use OCP\DB\QueryBuilder\IQueryFunction;
 
 class OCIFunctionBuilder extends FunctionBuilder {
        public function md5($input): IQueryFunction {
+               if (version_compare($this->connection->getServerVersion(), '20', '>=')) {
+                       return new QueryFunction('LOWER(STANDARD_HASH(' . $this->helper->quoteColumnName($input) . ", 'MD5'))");
+               }
                return new QueryFunction('LOWER(DBMS_OBFUSCATION_TOOLKIT.md5 (input => UTL_RAW.cast_to_raw(' . $this->helper->quoteColumnName($input) .')))');
        }