Fix deprecated OCP\DB calls for Nextcloud 14 compatibility (#65)

* Fix deprecated OCP\DB calls
master
e-alfred 2018-09-28 13:51:45 +02:00 committed by Loïc Blot
parent c5c07d8dae
commit c26cc3f7ba
2 changed files with 74 additions and 83 deletions

View File

@ -7,6 +7,7 @@
*
* @author Loic Blot <loic.blot@unix-experience.fr>
* @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;
}
};
?>

View File

@ -7,6 +7,7 @@
*
* @author Loic Blot <loic.blot@unix-experience.fr>
* @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;
}
};
?>