]> source.dussan.org Git - nextcloud-server.git/commitdiff
Bit more cleanup
authorRobin Appelman <icewind@owncloud.com>
Wed, 10 Sep 2014 11:33:59 +0000 (13:33 +0200)
committerRobin Appelman <icewind@owncloud.com>
Wed, 22 Oct 2014 10:29:53 +0000 (12:29 +0200)
lib/private/db.php
lib/private/db/mdb2schemamanager.php
lib/public/idbconnection.php

index 59d61ffa297320431fb7b480a74d20e0fe678982..9b904a1518f52c895dec682515cdb4b20d426bfd 100644 (file)
@@ -41,19 +41,6 @@ class DatabaseException extends Exception {
  * Doctrine with some adaptions.
  */
 class OC_DB {
-       /**
-        * @var \OC\DB\Connection $connection
-        */
-       static private $connection; //the preferred connection to use, only Doctrine
-
-       /**
-        * The existing database connection is closed and connected again
-        */
-       public static function reconnect() {
-               $connection = \OC::$server->getDatabaseConnection();
-               $connection->close();
-               $connection->connect();
-       }
 
        /**
         * @return \OCP\IDBConnection
@@ -69,7 +56,7 @@ class OC_DB {
         */
        private static function getMDB2SchemaManager()
        {
-               return new \OC\DB\MDB2SchemaManager(self::getConnection());
+               return new \OC\DB\MDB2SchemaManager(\OC::$server->getDatabaseConnection());
        }
 
        /**
@@ -282,17 +269,17 @@ class OC_DB {
         * @param string $tableName the table to drop
         */
        public static function dropTable($tableName) {
-
+               $connection = \OC::$server->getDatabaseConnection();
                $tableName = OC_Config::getValue('dbtableprefix', 'oc_' ) . trim($tableName);
 
-               self::$connection->beginTransaction();
+               $connection->beginTransaction();
 
-               $platform = self::$connection->getDatabasePlatform();
+               $platform = $connection->getDatabasePlatform();
                $sql = $platform->getDropTableSQL($platform->quoteIdentifier($tableName));
 
-               self::$connection->query($sql);
+               $connection->executeQuery($sql);
 
-               self::$connection->commit();
+               $connection->commit();
        }
 
        /**
@@ -332,8 +319,8 @@ class OC_DB {
        }
 
        public static function getErrorCode($error) {
-               $code = self::$connection->errorCode();
-               return $code;
+               $connection = \OC::$server->getDatabaseConnection();
+               return $connection->errorCode();
        }
        /**
         * returns the error code and message as a string for logging
@@ -342,10 +329,8 @@ class OC_DB {
         * @return string
         */
        public static function getErrorMessage($error) {
-               if (self::$connection) {
-                       return self::$connection->getError();
-               }
-               return '';
+               $connection = \OC::$server->getDatabaseConnection();
+               return $connection->getError();
        }
 
        /**
index a07c421b9b816af499c2828d0cd51e0c9402b723..fb3230e93af081c7510a2ac73563fba4d545816f 100644 (file)
@@ -21,7 +21,7 @@ class MDB2SchemaManager {
        protected $conn;
 
        /**
-        * @param \OC\DB\Connection $conn
+        * @param \OCP\IDBConnection $conn
         */
        public function __construct($conn) {
                $this->conn = $conn;
@@ -154,7 +154,8 @@ class MDB2SchemaManager {
                $this->conn->commit();
 
                if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) {
-                       \OC_DB::reconnect();
+                       $this->conn->close();
+                       $this->conn->connect();
                }
                return true;
        }
index d7cce2e818b31dad61b82f19a6c99f0c8c09e0c9..ce17d293e86ebb53ccae756bb747e94bc87c8973 100644 (file)
@@ -150,4 +150,12 @@ interface IDBConnection {
         * @return string The quoted parameter.
         */
        public function quote($input, $type = \PDO::PARAM_STR);
+
+       /**
+        * Gets the DatabasePlatform instance that provides all the metadata about
+        * the platform this driver connects to.
+        *
+        * @return \Doctrine\DBAL\Platforms\AbstractPlatform The database platform.
+        */
+       public function getDatabasePlatform();
 }