From c26cc3f7ba1c560d4a42827f3cb82c0757618568 Mon Sep 17 00:00:00 2001 From: e-alfred Date: Fri, 28 Sep 2018 13:51:45 +0200 Subject: [PATCH] Fix deprecated OCP\DB calls for Nextcloud 14 compatibility (#65) * Fix deprecated OCP\DB calls --- db/citymapper.php | 92 +++++++++++++++++++++---------------------- db/settingsmapper.php | 65 ++++++++++++++---------------- 2 files changed, 74 insertions(+), 83 deletions(-) diff --git a/db/citymapper.php b/db/citymapper.php index 4c48652..cacf5c4 100644 --- a/db/citymapper.php +++ b/db/citymapper.php @@ -7,6 +7,7 @@ * * @author Loic Blot * @copyright Loic Blot 2015 + * @copyright e-alfred 2018 */ namespace OCA\Weather\Db; @@ -16,62 +17,57 @@ use \OCP\IDBConnection; use \OCP\AppFramework\Db\Mapper; class CityMapper extends Mapper { - public function __construct (IDBConnection $db) { - parent::__construct($db, 'weather_city'); - } + public function __construct (IDBConnection $db) { + parent::__construct($db, 'weather_city'); + } - public function load ($id) { - $sql = 'SELECT id, name, user_id FROM ' . - '*PREFIX*weather_city WHERE id = ?'; - $query = \OCP\DB::prepare($sql); - $result = $query->execute(array($id)); + public function load ($id) { + $sql = "SELECT id, name, user_id FROM *PREFIX*weather_city WHERE `id` ='" . $id . "'"; + $result = $this->db->executequery($sql); - if ($row = $result->fetchRow()) { - return $row; - } - return null; - } + if ($row = $result->fetch()) { + return $row; + } + return null; + } - public function count() { - $sql = 'SELECT count(*) AS ct FROM *PREFIX*weather_city WHERE user_id = ?'; - $query = \OCP\DB::prepare($sql); - $result = $query->execute(array($userId)); - if ($row = $result->fetchRow()) { - return $row['ct']; - } - return 0; - } + public function count() { + $sql = "SELECT count(*) AS ct FROM *PREFIX*weather_city WHERE `user_id` ='" . $userId . "'"; + $result = $this->db->executequery($sql); + if ($row = $result->fetch()) { + return $row['ct']; + } + return 0; + } - public function exists ($id) { - return ($this->load($id)); - } + public function exists ($id) { + return ($this->load($id)); + } - public function getAll ($userId) { - $sql = 'SELECT id, name FROM *PREFIX*weather_city WHERE user_id = ?'; - $query = \OCP\DB::prepare($sql); - $result = $query->execute(array($userId)); + public function getAll ($userId) { + $sql = "SELECT id, name FROM *PREFIX*weather_city WHERE `user_id` = '" . $userId . "'"; + $result = $this->db->executequery($sql); - $cities = array(); - while ($row = $result->fetchRow()) { - $cities[] = $row; - } - return $cities; - } + $cities = array(); + while ($row = $result->fetch()) { + $cities[] = $row; + } + return $cities; + } - public function create ($userId, $name) { - $this->db->beginTransaction(); - $query = \OCP\DB::prepare('INSERT INTO *PREFIX*weather_city(user_id, name) VALUES (?,?)'); - $query->execute(array($userId, $name)); - $this->db->commit(); + public function create ($userId, $name) { + $this->db->beginTransaction(); + $sql = "INSERT INTO *PREFIX*weather_city(`user_id`, `name`) VALUES ('" . $userId . "','" . $name . "')"; + $this->db->executequery($sql); + $this->db->commit(); - $sql = 'SELECT max(id) as maxid FROM *PREFIX*weather_city WHERE user_id = ? and name = ?'; - $query = \OCP\DB::prepare($sql); - $result = $query->execute(array($userId, $name)); + $sql = "SELECT max(id) as maxid FROM *PREFIX*weather_city WHERE `user_id` = '" . $userId . "' and `name` = '" . $name . "'"; + $result = $this->db->executequery($sql); - if ($row = $result->fetchRow()) { - return $row['maxid']; - } - return null; - } + if ($row = $result->fetch()) { + return $row['maxid']; + } + return null; + } }; ?> diff --git a/db/settingsmapper.php b/db/settingsmapper.php index bab1934..3df15eb 100644 --- a/db/settingsmapper.php +++ b/db/settingsmapper.php @@ -7,6 +7,7 @@ * * @author Loic Blot * @copyright Loic Blot 2015 + * @copyright e-alfred 2018 */ namespace OCA\Weather\Db; @@ -16,49 +17,43 @@ use \OCP\IDBConnection; use \OCP\AppFramework\Db\Mapper; class SettingsMapper extends Mapper { - public function __construct (IDBConnection $db) { - parent::__construct($db, 'weather_city'); - } + public function __construct (IDBConnection $db) { + parent::__construct($db, 'weather_config'); + } - public function setHome ($userId, $cityId) { - $this->setSetting("home", $userId, $cityId); - } + public function setHome ($userId, $cityId) { + $this->setSetting("home", $userId, $cityId); + } - public function getHome ($userId) { - return $this->getSetting($userId, "home"); - } + public function getHome ($userId) { + return $this->getSetting($userId, "home"); + } - public function setMetric ($userId, $metric) { - $this->setSetting("metric", $userId, $metric); - } + public function setMetric ($userId, $metric) { + $this->setSetting("metric", $userId, $metric); + } - public function getMetric ($userId) { - return $this->getSetting($userId, "metric"); - } + public function getMetric ($userId) { + return $this->getSetting($userId, "metric"); + } - public function setSetting ($settingName, $userId, $settingValue) { - $this->db->beginTransaction(); - $query = \OCP\DB::prepare('DELETE FROM *PREFIX*weather_config ' . - 'WHERE `user` = ? and `key` = ?'); - $query->execute(array($userId, $settingName)); + public function setSetting ($settingName, $userId, $settingValue) { + $sql = "DELETE FROM *PREFIX*weather_config WHERE `user` = '" . $userId . "' and `key` = '" . $settingName . "'"; + $this->db->executequery($sql); - $query = \OCP\DB::prepare('INSERT INTO *PREFIX*weather_config ' . - '(`user`,`key`,`value`) VALUES (?,?,?)'); - $query->execute(array($userId, $settingName, $settingValue)); - $this->db->commit(); - } + $sql = "INSERT INTO *PREFIX*weather_config (`user`,`key`,`value`) VALUES ('" . $userId . "','" . $settingName . "','" . $settingValue . "')"; + $this->db->executequery($sql); + } - public function getSetting ($userId, $settingName) { - $sql = 'SELECT value FROM ' . - '*PREFIX*weather_config WHERE `user` = ? and `key` = ?'; - $query = \OCP\DB::prepare($sql); - $result = $query->execute(array($userId, $settingName)); + public function getSetting ($userId, $settingName) { + $sql = "SELECT value FROM *PREFIX*weather_config WHERE `user` ='" . $userId . "' and `key` ='" . $settingName . "'"; + $result = $this->db->executeQuery($sql); - if ($row = $result->fetchRow()) { - return $row["value"]; - } - return 0; - } + if ($row = $result->fetch()) { + return $row["value"]; + } + return 0; + } }; ?>