]> source.dussan.org Git - nextcloud-server.git/commitdiff
Move building error string to connection
authorBart Visscher <bartv@thisnet.nl>
Mon, 1 Jul 2013 16:20:27 +0000 (18:20 +0200)
committerBart Visscher <bartv@thisnet.nl>
Sun, 21 Jul 2013 21:17:37 +0000 (23:17 +0200)
lib/db.php
lib/db/connection.php

index 48e1439a336a3186eb9b6efee5cb42fbc48a7770..9270b2a15172941c70ab0c09f9008d6af8ed2c73 100644 (file)
@@ -433,16 +433,8 @@ class OC_DB {
         */
        public static function getErrorMessage($error) {
                if (self::$connection) {
-                       $msg = self::$connection->errorCode() . ': ';
-                       $errorInfo = self::$connection->errorInfo();
-                       if (is_array($errorInfo)) {
-                               $msg .= 'SQLSTATE = '.$errorInfo[0] . ', ';
-                               $msg .= 'Driver Code = '.$errorInfo[1] . ', ';
-                               $msg .= 'Driver Message = '.$errorInfo[2];
-                       }
-                       return $msg;
+                       return self::$connection->getError();
                }
-
                return '';
        }
 
index e18062d78f3ed2b7b0aabdb42e75afffeb2a67b3..1f01fae4f71236d8a249aabb940d0e71d7823521 100644 (file)
@@ -148,6 +148,23 @@ class Connection extends \Doctrine\DBAL\Connection {
                return $this->adapter->insertIfNotExist($table, $input);
        }
 
+       /**
+        * returns the error code and message as a string for logging
+        * works with DoctrineException
+        * @param mixed $error
+        * @return string
+        */
+       public function getError() {
+               $msg = $this->errorCode() . ': ';
+               $errorInfo = $this->errorInfo();
+               if (is_array($errorInfo)) {
+                       $msg .= 'SQLSTATE = '.$errorInfo[0] . ', ';
+                       $msg .= 'Driver Code = '.$errorInfo[1] . ', ';
+                       $msg .= 'Driver Message = '.$errorInfo[2];
+               }
+               return $msg;
+       }
+
        // internal use
        protected function replaceTablePrefix($statement) {
                return str_replace( '*PREFIX*', $this->table_prefix, $statement );