From 3917d888bde42336abb1d2ecbef04ae7530e5c14 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 7 Jan 2016 10:14:05 +0100 Subject: Remove OC_DB::isError --- lib/private/db.php | 17 ++--------------- lib/private/share/share.php | 6 +++--- lib/private/user/database.php | 4 ++-- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/lib/private/db.php b/lib/private/db.php index f339855fb20..bac0f600e95 100644 --- a/lib/private/db.php +++ b/lib/private/db.php @@ -262,15 +262,6 @@ class OC_DB { $schemaManager->removeDBStructure($file); } - /** - * check if a result is an error, works with Doctrine - * @param mixed $result - * @return bool - */ - public static function isError($result) { - //Doctrine returns false on error (and throws an exception) - return $result === false; - } /** * check if a result is an error and throws an exception, works with \Doctrine\DBAL\DBALException * @param mixed $result @@ -279,20 +270,16 @@ class OC_DB { * @throws \OC\DatabaseException */ public static function raiseExceptionOnError($result, $message = null) { - if(self::isError($result)) { + if($result === false) { if ($message === null) { $message = self::getErrorMessage(); } else { $message .= ', Root cause:' . self::getErrorMessage(); } - throw new \OC\DatabaseException($message, self::getErrorCode()); + throw new \OC\DatabaseException($message, \OC::$server->getDatabaseConnection()->errorCode()); } } - public static function getErrorCode() { - $connection = \OC::$server->getDatabaseConnection(); - return $connection->errorCode(); - } /** * returns the error code and message as a string for logging * works with DoctrineException diff --git a/lib/private/share/share.php b/lib/private/share/share.php index fff437b3ff7..b10de850356 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -491,7 +491,7 @@ class Share extends Constants { public static function getShareByToken($token, $checkPasswordProtection = true) { $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1); $result = $query->execute(array($token)); - if (\OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage() . ', token=' . $token, \OCP\Util::ERROR); } $row = $result->fetchRow(); @@ -1722,7 +1722,7 @@ class Share extends Constants { $root = strlen($root); $query = \OC_DB::prepare('SELECT '.$select.' FROM `*PREFIX*share` '.$where, $queryLimit); $result = $query->execute($queryArgs); - if (\OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage() . ', select=' . $select . ' where=', \OCP\Util::ERROR); @@ -1786,7 +1786,7 @@ class Share extends Constants { if (isset($row['parent'])) { $query = \OC_DB::prepare('SELECT `file_target` FROM `*PREFIX*share` WHERE `id` = ?'); $parentResult = $query->execute(array($row['parent'])); - if (\OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('OCP\Share', 'Can\'t select parent: ' . \OC_DB::getErrorMessage() . ', select=' . $select . ' where=' . $where, \OCP\Util::ERROR); diff --git a/lib/private/user/database.php b/lib/private/user/database.php index 98850771212..5bee509e8bd 100644 --- a/lib/private/user/database.php +++ b/lib/private/user/database.php @@ -210,7 +210,7 @@ class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend { $query = OC_DB::prepare('SELECT `uid`, `displayname` FROM `*PREFIX*users` WHERE LOWER(`uid`) = LOWER(?)'); $result = $query->execute(array($uid)); - if (OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('core', OC_DB::getErrorMessage(), \OCP\Util::ERROR); return false; } @@ -287,7 +287,7 @@ class OC_User_Database extends OC_User_Backend implements \OCP\IUserBackend { public function countUsers() { $query = OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`'); $result = $query->execute(); - if (OC_DB::isError($result)) { + if ($result === false) { \OCP\Util::writeLog('core', OC_DB::getErrorMessage(), \OCP\Util::ERROR); return false; } -- cgit v1.2.3