summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Mueller <thomas.mueller@tmit.eu>2013-06-27 16:48:09 +0200
committerJörn Friedrich Dreyer <jfd@butonic.de>2013-06-28 20:16:01 +0200
commit66e1eaac9379e16bb0c9e60b2794b03bda3b9eec (patch)
tree555bc71b1fb10efec476435527dd298fa8966fd6
parent4bbdd67a22fd5ac0efc6b8c9dc3e024a0af45c90 (diff)
downloadnextcloud-server-66e1eaac9379e16bb0c9e60b2794b03bda3b9eec.tar.gz
nextcloud-server-66e1eaac9379e16bb0c9e60b2794b03bda3b9eec.zip
isError should detect a PEAR_Error even if the backend is PDO.
This can happen on errors during schema migration - which is always done with MDB2
-rw-r--r--lib/db.php42
1 files changed, 23 insertions, 19 deletions
diff --git a/lib/db.php b/lib/db.php
index 5e624bf30b9..515563b78e1 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -962,21 +962,21 @@ class OC_DB {
* @return bool
*/
public static function isError($result) {
+ //MDB2 returns an MDB2_Error object
+ if (class_exists('PEAR') === true && PEAR::isError($result)) {
+ return true;
+ }
//PDO returns false on error (and throws an exception)
if (self::$backend===self::BACKEND_PDO and $result === false) {
return true;
- } else
- //MDB2 returns an MDB2_Error object
- if (self::$backend===self::BACKEND_MDB2 and PEAR::isError($result)) {
- return true;
- } else {
- return false;
}
+
+ return false;
}
/**
* check if a result is an error and throws an exception, works with MDB2 and PDOException
* @param mixed $result
- * @param string message
+ * @param string $message
* @return void
* @throws DatabaseException
*/
@@ -992,12 +992,15 @@ class OC_DB {
}
public static function getErrorCode($error) {
- if ( self::$backend==self::BACKEND_MDB2 and PEAR::isError($error) ) {
- $code = $error->getCode();
- } elseif ( self::$backend==self::BACKEND_PDO and self::$PDO ) {
- $code = self::$PDO->errorCode();
+ if ( class_exists('PEAR') === true && PEAR::isError($error) ) {
+ /** @var $error PEAR_Error */
+ return $error->getCode();
+ }
+ if ( self::$backend==self::BACKEND_PDO and self::$PDO ) {
+ return self::$PDO->errorCode();
}
- return $code;
+
+ return -1;
}
/**
* returns the error code and message as a string for logging
@@ -1006,23 +1009,24 @@ class OC_DB {
* @return string
*/
public static function getErrorMessage($error) {
- if ( self::$backend==self::BACKEND_MDB2 and PEAR::isError($error) ) {
+ if ( class_exists('PEAR') === true && PEAR::isError($error) ) {
$msg = $error->getCode() . ': ' . $error->getMessage();
$msg .= ' (' . $error->getDebugInfo() . ')';
- } elseif (self::$backend==self::BACKEND_PDO and self::$PDO) {
+
+ return $msg;
+ }
+ if (self::$backend==self::BACKEND_PDO and self::$PDO) {
$msg = self::$PDO->errorCode() . ': ';
$errorInfo = self::$PDO->errorInfo();
if (is_array($errorInfo)) {
$msg .= 'SQLSTATE = '.$errorInfo[0] . ', ';
$msg .= 'Driver Code = '.$errorInfo[1] . ', ';
$msg .= 'Driver Message = '.$errorInfo[2];
- }else{
- $msg = '';
}
- }else{
- $msg = '';
+ return $msg;
}
- return $msg;
+
+ return '';
}
/**