summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2013-07-01 14:38:28 -0700
committerThomas Müller <thomas.mueller@tmit.eu>2013-07-01 14:38:28 -0700
commitc7770265063045a8de69f4171236ffe33a22c87e (patch)
tree7d2835b7c719e8b4c62ec7ab8c285b4f9099c714 /lib
parentbf901eb52f80692eb945ef5608f0ed58bbce3e26 (diff)
parentc80e76720f4e65a5f7af31f67d70ec66019bcb68 (diff)
downloadnextcloud-server-c7770265063045a8de69f4171236ffe33a22c87e.tar.gz
nextcloud-server-c7770265063045a8de69f4171236ffe33a22c87e.zip
Merge pull request #3775 from owncloud/test_fixes_for_dbschema
use executeAudited, add table name to assert message, skip schema changi...
Diffstat (limited to 'lib')
-rw-r--r--lib/db.php41
1 files changed, 24 insertions, 17 deletions
diff --git a/lib/db.php b/lib/db.php
index 3e2e5bc2194..a93b9eccbdf 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -941,18 +941,21 @@ class OC_DB {
* @return bool
*/
public static function isError($result) {
- if(self::$backend==self::BACKEND_PDO and $result === false) {
+ //MDB2 returns an MDB2_Error object
+ if (class_exists('PEAR') === true && PEAR::isError($result)) {
return true;
- }elseif(self::$backend==self::BACKEND_MDB2 and PEAR::isError($result)) {
+ }
+ //PDO returns false on error (and throws an exception)
+ if (self::$backend===self::BACKEND_PDO and $result === false) {
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
*/
@@ -968,12 +971,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
@@ -982,23 +988,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 '';
}
/**