]>
git.immae.eu Git - github/wallabag/wallabag.git/blob - inc/store/sqlite.class.php
3 * poche, a read it later open source system
6 * @author Nicolas Lœuillet <support@inthepoche.com>
8 * @license http://www.wtfpl.net/ see COPYING file
11 class Sqlite
extends Store
{
13 public static $db_path = 'sqlite:./db/poche.sqlite';
16 function __construct() {
17 parent
::__construct();
19 $this->handle
= new PDO(self
::$db_path);
20 $this->handle
->exec('CREATE TABLE IF NOT EXISTS "entries" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "title" VARCHAR, "url" VARCHAR UNIQUE , "is_read" INTEGER DEFAULT 0, "is_fav" INTEGER DEFAULT 0, "content" BLOB)');
21 $this->handle
->setAttribute(PDO
::ATTR_ERRMODE
, PDO
::ERRMODE_EXCEPTION
);
24 private function getHandle() {
28 private function executeQuery($sql, $params) {
31 $query = $this->getHandle()->prepare($sql);
32 $query->execute($params);
37 logm('execute query error : '.$e->getMessage());
41 public function retrieveOneById($id) {
42 parent
::__construct();
45 $sql = "SELECT * FROM entries WHERE id=?";
46 $params = array(intval($id));
47 $query = $this->executeQuery($sql, $params);
48 $entry = $query->fetchAll();
53 public function getEntriesByView($view) {
54 parent
::__construct();
56 switch ($_SESSION['sort'])
59 $order = 'ORDER BY id';
62 $order = 'ORDER BY id DESC';
65 $order = 'ORDER BY lower(title)';
68 $order = 'ORDER BY lower(title) DESC';
71 $order = 'ORDER BY id';
78 $sql = "SELECT * FROM entries WHERE is_read=? " . $order;
82 $sql = "SELECT * FROM entries WHERE is_fav=? " . $order;
86 $sql = "SELECT * FROM entries WHERE is_read=? " . $order;
91 $query = $this->executeQuery($sql, $params);
92 $entries = $query->fetchAll();
97 public function add() {
98 parent
::__construct();
99 $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)';
100 $params_action = array($url, $parametres_url['title'], $parametres_url['content']);
101 $query = $this->executeQuery($sql_action, $params_action);
104 public function deleteById($id) {
105 parent
::__construct();
106 $sql_action = "DELETE FROM entries WHERE id=?";
107 $params_action = array($id);
108 $query = $this->executeQuery($sql_action, $params_action);
111 public function favoriteById($id) {
112 parent
::__construct();
113 $sql_action = "UPDATE entries SET is_fav=~is_fav WHERE id=?";
114 $params_action = array($id);
115 $query = $this->executeQuery($sql_action, $params_action);
118 public function archiveById($id) {
119 parent
::__construct();
120 $sql_action = "UPDATE entries SET is_read=~is_read WHERE id=?";
121 $params_action = array($id);
122 $query = $this->executeQuery($sql_action, $params_action);
125 public function getLastId() {
126 parent
::__construct();
127 return $this->getHandle()->lastInsertId();
130 public function updateContentById($id) {
131 parent
::__construct();
132 $sql_update = "UPDATE entries SET content=? WHERE id=?";
133 $params_update = array($content, $id);
134 $query = $this->executeQuery($sql_update, $params_update);