]> source.dussan.org Git - nextcloud-server.git/commitdiff
let insertIfNotExist() throw the native DBALException - no need to hide the real...
authorThomas Müller <thomas.mueller@tmit.eu>
Mon, 9 Mar 2015 21:12:31 +0000 (22:12 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Mon, 9 Mar 2015 21:37:49 +0000 (22:37 +0100)
lib/private/db.php
lib/private/db/adapter.php
lib/private/db/adaptersqlite.php
lib/private/db/connection.php
lib/private/db/mdb2schemamanager.php
lib/public/db.php
lib/public/idbconnection.php
tests/lib/db.php

index 3993ae277481190806e47a636bcc91fcdb96ae0b..c2654926696af2dd3ed6e96838133bd6c9b5fc51 100644 (file)
@@ -20,8 +20,6 @@
  *
  */
 
-define('MDB2_SCHEMA_DUMP_STRUCTURE', '1');
-
 /**
  * This class manages the access to the database. It basically is a wrapper for
  * Doctrine with some adaptions.
@@ -40,8 +38,7 @@ class OC_DB {
         *
         * @return \OC\DB\MDB2SchemaManager
         */
-       private static function getMDB2SchemaManager()
-       {
+       private static function getMDB2SchemaManager() {
                return new \OC\DB\MDB2SchemaManager(\OC::$server->getDatabaseConnection());
        }
 
@@ -166,16 +163,6 @@ class OC_DB {
                return \OC::$server->getDatabaseConnection()->lastInsertId($table);
        }
 
-       /**
-        * Insert a row if a matching row doesn't exists.
-        * @param string $table The table to insert into in the form '*PREFIX*tableName'
-        * @param array $input An array of fieldname/value pairs
-        * @return boolean number of updated rows
-        */
-       public static function insertIfNotExist($table, $input, $compare = null) {
-               return \OC::$server->getDatabaseConnection()->insertIfNotExist($table, $input, $compare);
-       }
-
        /**
         * Start a transaction
         */
@@ -205,7 +192,7 @@ class OC_DB {
         *
         * TODO: write more documentation
         */
-       public static function getDbStructure( $file, $mode = 0) {
+       public static function getDbStructure($file) {
                $schemaManager = self::getMDB2SchemaManager();
                return $schemaManager->getDbStructure($file);
        }
index ee6898dde855bcce73430aa7cf25eb6b1746ca53..bd1604caf2048dc14babe1643d19ecf20966d974 100644 (file)
@@ -43,7 +43,7 @@ class Adapter {
         * insert the @input values when they do not exist yet
         * @param string $table name
         * @param array $input key->value pair, key has to be sanitized properly
-        * @throws \OC\HintException
+        * @throws \Doctrine\DBAL\DBALException
         * @return int count of inserted rows
         */
        public function insertIfNotExist($table, $input, $compare = null) {
@@ -68,19 +68,6 @@ class Adapter {
                $query = substr($query, 0, strlen($query) - 5);
                $query .= ' HAVING COUNT(*) = 0';
 
-               try {
-                       return $this->conn->executeUpdate($query, $inserts);
-               } catch(\Doctrine\DBAL\DBALException $e) {
-                       $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
-                       $entry .= 'Offending command was: ' . $query.'<br />';
-                       \OC_Log::write('core', $entry, \OC_Log::FATAL);
-                       $l = \OC::$server->getL10N('lib');
-                       throw new \OC\HintException(
-                               $l->t('Database Error'),
-                               $l->t('Please contact your system administrator.'),
-                               0,
-                               $e
-                       );
-               }
+               return $this->conn->executeUpdate($query, $inserts);
        }
 }
index 8b3c4ebc839a85d2dbef3716d2d5a0d9882800e8..f93183bee908ea6301e050ca9d81228ee2ef7c2c 100644 (file)
@@ -18,6 +18,13 @@ class AdapterSqlite extends Adapter {
                return $statement;
        }
 
+       /**
+        * @param string $table
+        * @param array $input
+        * @param null $compare
+        * @return int
+        * @throws \Doctrine\DBAL\DBALException
+        */
        public function insertIfNotExist($table, $input, $compare = null) {
                if ($compare === null) {
                        $compare = array_keys($input);
@@ -40,19 +47,6 @@ class AdapterSqlite extends Adapter {
                $query = substr($query, 0, strlen($query) - 5);
                $query .= ')';
 
-               try {
-                       return $this->conn->executeUpdate($query, $inserts);
-               } catch(\Doctrine\DBAL\DBALException $e) {
-                       $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
-                       $entry .= 'Offending command was: ' . $query.'<br />';
-                       \OC_Log::write('core', $entry, \OC_Log::FATAL);
-                       $l = \OC::$server->getL10N('lib');
-                       throw new \OC\HintException(
-                               $l->t('Database Error'),
-                               $l->t('Please contact your system administrator.'),
-                               0,
-                               $e
-                       );
-               }
+               return $this->conn->executeUpdate($query, $inserts);
        }
 }
index cc94c862b85e0b12c67cfe894c7c043f4c0a77d4..cdbfc94a0393e44689edca1b1a9a329cc0721c9a 100644 (file)
@@ -152,16 +152,16 @@ class Connection extends \Doctrine\DBAL\Connection implements IDBConnection {
        }
 
        // internal use
-       public function realLastInsertId($seqName = null)
-       {
+       public function realLastInsertId($seqName = null) {
                return parent::lastInsertId($seqName);
        }
 
        /**
-        * Insert a row if a matching row doesn't exists.
+        * Insert a row if a matching row does not exists.
         * @param string $table. The table to insert into in the form '*PREFIX*tableName'
-        * @param array $input. An array of fieldname/value pairs
-        * @throws \OC\HintException
+        * @param array $input. An array of field name/value pairs
+        * @param array $compare
+        * @throws \Doctrine\DBAL\DBALException
         * @return bool The return value from execute()
         */
        public function insertIfNotExist($table, $input, $compare = null) {
index 358360d0b462feaded4c2f47431516e2a5aa12a3..66c97f9e3b4f5c47903f4b496c3e88700c87290f 100644 (file)
@@ -35,7 +35,7 @@ class MDB2SchemaManager {
         *
         * TODO: write more documentation
         */
-       public function getDbStructure($file, $mode = MDB2_SCHEMA_DUMP_STRUCTURE) {
+       public function getDbStructure($file) {
                return \OC_DB_MDB2SchemaWriter::saveSchemaToFile($file, $this->conn);
        }
 
index 50e519bbe91390a75bdc67bd1a1df7f1f0f7c8ff..d8d81f239b276270ed39291de84a6732830188f7 100644 (file)
@@ -65,7 +65,7 @@ class DB {
         *
         */
        public static function insertIfNotExist($table, $input, $compare = null) {
-               return(\OC_DB::insertIfNotExist($table, $input, $compare));
+               return \OC::$server->getDatabaseConnection()->insertIfNotExist($table, $input, $compare);
        }
 
        /**
index 3cc7ff3248bd3bfbc1cc66dcc130f8d06f78d3a7..c8a2c5796b52ac395b72dec2a5e80c590806fd6a 100644 (file)
@@ -80,7 +80,7 @@ interface IDBConnection {
         * Insert a row if a matching row doesn't exists.
         * @param string $table The table name (will replace *PREFIX*) to perform the replace on.
         * @param array $input
-        * @throws \OC\HintException
+        * @throws \Doctrine\DBAL\DBALException
         *
         * The input array if in the form:
         *
index 73eef3a4d0e84dac7efd44d17f52e8c0e307149d..056ce535436fee59ace0dbc087734982142ecf2a 100644 (file)
@@ -125,7 +125,7 @@ class Test_DB extends \Test\TestCase {
                        );
 
                foreach($categoryEntries as $entry) {
-                       $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table3,
+                       $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table3,
                                array(
                                        'uid' => $entry['user'],
                                        'type' => $entry['type'],
@@ -148,7 +148,7 @@ class Test_DB extends \Test\TestCase {
                );
 
                foreach($categoryEntries as $entry) {
-                       $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2,
+                       $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table2,
                                array(
                                        'addressbookid' => $entry['addressbookid'],
                                        'fullname' => $entry['fullname'],
@@ -180,7 +180,7 @@ class Test_DB extends \Test\TestCase {
                $this->assertEquals($carddata, $rowset[0]['carddata']);
 
                // Try to insert a new row
-               $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table2,
+               $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table2,
                        array(
                                'fullname' => $fullName,
                                'uri' => $uri,
@@ -199,7 +199,7 @@ class Test_DB extends \Test\TestCase {
        }
 
        public function testInsertIfNotExistsViolating() {
-               $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table5,
+               $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table5,
                        array(
                                'storage' => 1,
                                'path_hash' => md5('welcome.txt'),
@@ -207,7 +207,7 @@ class Test_DB extends \Test\TestCase {
                        ));
                $this->assertEquals(1, $result);
 
-               $result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table5,
+               $result = \OCP\DB::insertIfNotExist('*PREFIX*'.$this->table5,
                        array(
                                'storage' => 1,
                                'path_hash' => md5('welcome.txt'),