From 2501bb337e75c41f97570f25775e20131faf2f2a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 3 Jul 2014 22:11:25 +0200 Subject: Preparation #2 for SQLite https://github.com/marienfressinaud/FreshRSS/issues/100 --- app/Models/EntryDAOSQLite.php | 42 ++++++++++++++++++++++++++++++++++++++++++ app/Models/EntryDAO_SQLite.php | 42 ------------------------------------------ app/Models/Factory.php | 2 +- 3 files changed, 43 insertions(+), 43 deletions(-) create mode 100644 app/Models/EntryDAOSQLite.php delete mode 100644 app/Models/EntryDAO_SQLite.php (limited to 'app/Models') diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php new file mode 100644 index 000000000..45d3a3ea9 --- /dev/null +++ b/app/Models/EntryDAOSQLite.php @@ -0,0 +1,42 @@ +markRead($id, $is_read); + } + return $affected; + } + } else { + $this->bd->beginTransaction(); + $sql = 'UPDATE `' . $this->prefix . 'entry` e SET e.is_read = ? WHERE e.id=? AND e.is_read<>?'; + $values = array($is_read ? 1 : 0, $ids, $is_read ? 1 : 0); + $stm = $this->bd->prepare($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + $affected = $stm->rowCount(); + if ($affected > 0) { + $sql = 'UPDATE `' . $this->prefix . 'feed` f SET f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 ' + . 'WHERE f.id=(SELECT e.id_feed FROM `' . $this->prefix . 'entry` e WHERE e.id=?)'; + $values = array($ids); + $stm = $this->bd->prepare($sql); + if (!($stm && $stm->execute ($values))) { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); + $this->bd->rollBack (); + return false; + } + } + $this->bd->commit(); + return $affected; + } + } +} diff --git a/app/Models/EntryDAO_SQLite.php b/app/Models/EntryDAO_SQLite.php deleted file mode 100644 index f148f3c63..000000000 --- a/app/Models/EntryDAO_SQLite.php +++ /dev/null @@ -1,42 +0,0 @@ -markRead($id, $is_read); - } - return $affected; - } - } else { - $this->bd->beginTransaction(); - $sql = 'UPDATE `' . $this->prefix . 'entry` e SET e.is_read = ? WHERE e.id=? AND e.is_read<>?'; - $values = array($is_read ? 1 : 0, $ids, $is_read ? 1 : 0); - $stm = $this->bd->prepare($sql); - if (!($stm && $stm->execute ($values))) { - $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); - Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); - $this->bd->rollBack (); - return false; - } - $affected = $stm->rowCount(); - if ($affected > 0) { - $sql = 'UPDATE `' . $this->prefix . 'feed` f SET f.cache_nbUnreads=f.cache_nbUnreads' . ($is_read ? '-' : '+') . '1 ' - . 'WHERE f.id=(SELECT e.id_feed FROM `' . $this->prefix . 'entry` e WHERE e.id=?)'; - $values = array($ids); - $stm = $this->bd->prepare($sql); - if (!($stm && $stm->execute ($values))) { - $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); - Minz_Log::record('SQL error markRead: ' . $info[2], Minz_Log::ERROR); - $this->bd->rollBack (); - return false; - } - } - $this->bd->commit(); - return $affected; - } - } -} diff --git a/app/Models/Factory.php b/app/Models/Factory.php index bea89c114..3ef68c41d 100644 --- a/app/Models/Factory.php +++ b/app/Models/Factory.php @@ -5,7 +5,7 @@ class FreshRSS_Factory { public static function createEntryDao() { $db = Minz_Configuration::dataBase(); if ($db['type'] === 'sqlite') { - return new FreshRSS_EntryDAO_SQLite(); + return new FreshRSS_EntryDAOSQLite(); } else { return new FreshRSS_EntryDAO(); } -- cgit v1.2.3