Fix deprecated OCP\DB calls for Nextcloud 14 compatibility (#65)
* Fix deprecated OCP\DB callsmaster
parent
c5c07d8dae
commit
c26cc3f7ba
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* @author Loic Blot <loic.blot@unix-experience.fr>
|
||||
* @copyright Loic Blot 2015
|
||||
* @copyright e-alfred 2018
|
||||
*/
|
||||
|
||||
namespace OCA\Weather\Db;
|
||||
|
@ -21,22 +22,19 @@ class CityMapper extends Mapper {
|
|||
}
|
||||
|
||||
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));
|
||||
$sql = "SELECT id, name, user_id FROM *PREFIX*weather_city WHERE `id` ='" . $id . "'";
|
||||
$result = $this->db->executequery($sql);
|
||||
|
||||
if ($row = $result->fetchRow()) {
|
||||
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()) {
|
||||
$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;
|
||||
|
@ -47,12 +45,11 @@ class CityMapper extends Mapper {
|
|||
}
|
||||
|
||||
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));
|
||||
$sql = "SELECT id, name FROM *PREFIX*weather_city WHERE `user_id` = '" . $userId . "'";
|
||||
$result = $this->db->executequery($sql);
|
||||
|
||||
$cities = array();
|
||||
while ($row = $result->fetchRow()) {
|
||||
while ($row = $result->fetch()) {
|
||||
$cities[] = $row;
|
||||
}
|
||||
return $cities;
|
||||
|
@ -60,15 +57,14 @@ class CityMapper extends Mapper {
|
|||
|
||||
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));
|
||||
$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()) {
|
||||
if ($row = $result->fetch()) {
|
||||
return $row['maxid'];
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* @author Loic Blot <loic.blot@unix-experience.fr>
|
||||
* @copyright Loic Blot 2015
|
||||
* @copyright e-alfred 2018
|
||||
*/
|
||||
|
||||
namespace OCA\Weather\Db;
|
||||
|
@ -17,7 +18,7 @@ use \OCP\AppFramework\Db\Mapper;
|
|||
|
||||
class SettingsMapper extends Mapper {
|
||||
public function __construct (IDBConnection $db) {
|
||||
parent::__construct($db, 'weather_city');
|
||||
parent::__construct($db, 'weather_config');
|
||||
}
|
||||
|
||||
public function setHome ($userId, $cityId) {
|
||||
|
@ -37,24 +38,18 @@ class SettingsMapper extends Mapper {
|
|||
}
|
||||
|
||||
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));
|
||||
$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));
|
||||
$sql = "SELECT value FROM *PREFIX*weather_config WHERE `user` ='" . $userId . "' and `key` ='" . $settingName . "'";
|
||||
$result = $this->db->executeQuery($sql);
|
||||
|
||||
if ($row = $result->fetchRow()) {
|
||||
if ($row = $result->fetch()) {
|
||||
return $row["value"];
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue