aboutsummaryrefslogtreecommitdiffstats
path: root/lib/vcategories.php
diff options
context:
space:
mode:
authorThomas Tanghus <thomas@tanghus.net>2012-10-31 20:47:04 +0100
committerThomas Tanghus <thomas@tanghus.net>2012-10-31 20:47:04 +0100
commit8cffbb5f7dca943f0ecebd3d4d414b004f348f06 (patch)
tree1d9f667333345d6e7be0741a841b7047c204eb82 /lib/vcategories.php
parent8fc0f53a4835c139a66d49cab41c7ff541cda63d (diff)
downloadnextcloud-server-8cffbb5f7dca943f0ecebd3d4d414b004f348f06.tar.gz
nextcloud-server-8cffbb5f7dca943f0ecebd3d4d414b004f348f06.zip
Added some more error checking on db queries.
Diffstat (limited to 'lib/vcategories.php')
-rw-r--r--lib/vcategories.php42
1 files changed, 37 insertions, 5 deletions
diff --git a/lib/vcategories.php b/lib/vcategories.php
index ee7c7c8ab1b..3660d84ee10 100644
--- a/lib/vcategories.php
+++ b/lib/vcategories.php
@@ -89,6 +89,9 @@ class OC_VCategories {
try {
$stmt = OCP\DB::prepare($sql);
$result = $stmt->execute(array($this->user, $this->type));
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ }
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);
@@ -118,6 +121,10 @@ class OC_VCategories {
try {
$stmt = OCP\DB::prepare($sql);
$result = $stmt->execute(array($user, $type));
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ return false;
+ }
return ($result->numRows() == 0);
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
@@ -189,6 +196,10 @@ class OC_VCategories {
try {
$stmt = OCP\DB::prepare($sql);
$result = $stmt->execute(array($catid));
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ return false;
+ }
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);
@@ -200,8 +211,6 @@ class OC_VCategories {
$ids[] = (int)$row['objid'];
}
}
- //OCP\Util::writeLog('core', __METHOD__.', count: ' . count($items), OCP\Util::DEBUG);
- //OCP\Util::writeLog('core', __METHOD__.', sql: ' . $sql, OCP\Util::DEBUG);
return $ids;
}
@@ -224,7 +233,7 @@ class OC_VCategories {
*
* TODO: Maybe add the getting permissions for objects?
*
- * @returns array containing the resulting items.
+ * @returns array containing the resulting items or false on error.
*/
public function itemsForCategory($category, $tableinfo, $limit = null, $offset = null) {
$result = null;
@@ -256,9 +265,14 @@ class OC_VCategories {
try {
$stmt = OCP\DB::prepare($sql, $limit, $offset);
$result = $stmt->execute(array($catid));
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ return false;
+ }
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);
+ return false;
}
if(!is_null($result)) {
@@ -370,6 +384,10 @@ class OC_VCategories {
$stmt = OCP\DB::prepare('SELECT `id` FROM `' . self::CATEGORY_TABLE . '` '
. 'WHERE `uid` = ? AND `type` = ?');
$result = $stmt->execute(array($this->user, $this->type));
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ return false;
+ }
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);
@@ -387,6 +405,10 @@ class OC_VCategories {
$stmt = OCP\DB::prepare('DELETE FROM `' . self::CATEGORY_TABLE . '` '
. 'WHERE `uid` = ? AND `type` = ?');
$result = $stmt->execute(array($this->user, $this->type));
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ return;
+ }
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__ . ', exception: '
. $e->getMessage(), OCP\Util::ERROR);
@@ -459,6 +481,9 @@ class OC_VCategories {
$stmt = OCP\DB::prepare('SELECT `id` FROM `' . self::CATEGORY_TABLE . '` '
. 'WHERE `uid` = ?');
$result = $stmt->execute(array($arguments['uid']));
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ }
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);
@@ -485,6 +510,9 @@ class OC_VCategories {
$stmt = OCP\DB::prepare('DELETE FROM `' . self::CATEGORY_TABLE . '` '
. 'WHERE `uid` = ? AND');
$result = $stmt->execute(array($arguments['uid']));
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ }
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__ . ', exception: '
. $e->getMessage(), OCP\Util::ERROR);
@@ -496,14 +524,18 @@ class OC_VCategories {
* @param int $id The id of the object
* @param string $type The type of object (event/contact/task/journal).
* Defaults to the type set in the instance
- * @returns boolean
+ * @returns boolean Returns false on error.
*/
public function purgeObject($id, $type = null) {
$type = is_null($type) ? $this->type : $type;
try {
$stmt = OCP\DB::prepare('DELETE FROM `' . self::RELATION_TABLE . '` '
. 'WHERE `objid` = ? AND `type`= ?');
- $stmt->execute(array($id, $type));
+ $result = $stmt->execute(array($id, $type));
+ if (OC_DB::isError($result)) {
+ OC_Log::write('core', __METHOD__. 'DB error: ' . OC_DB::getErrorMessage($result), OC_Log::ERROR);
+ return false;
+ }
} catch(Exception $e) {
OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
OCP\Util::ERROR);