diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2013-07-31 17:19:50 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2013-07-31 17:19:50 +0200 |
commit | 85ebc80c7eaf88e4d57a52adb8e4c32d8cc34b64 (patch) | |
tree | 0012345c93b1fe8a242963bede0db370598d6f2b /inc/store/sqlite.class.php | |
parent | 6588517b2d46cbc524260758d1fafd92b19ab681 (diff) | |
parent | 6d37de5f828b700843567a91418671919eed4be4 (diff) | |
download | wallabag-d697309bc1b83b8315eae42748a6f906dab7b289.tar.gz wallabag-d697309bc1b83b8315eae42748a6f906dab7b289.tar.zst wallabag-d697309bc1b83b8315eae42748a6f906dab7b289.zip |
Merge branch 'dev'0.3
Diffstat (limited to 'inc/store/sqlite.class.php')
-rw-r--r-- | inc/store/sqlite.class.php | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/inc/store/sqlite.class.php b/inc/store/sqlite.class.php index d5208a29..21081608 100644 --- a/inc/store/sqlite.class.php +++ b/inc/store/sqlite.class.php | |||
@@ -17,7 +17,6 @@ class Sqlite extends Store { | |||
17 | parent::__construct(); | 17 | parent::__construct(); |
18 | 18 | ||
19 | $this->handle = new PDO(self::$db_path); | 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); | 20 | $this->handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
22 | } | 21 | } |
23 | 22 | ||
@@ -25,6 +24,63 @@ class Sqlite extends Store { | |||
25 | return $this->handle; | 24 | return $this->handle; |
26 | } | 25 | } |
27 | 26 | ||
27 | public function isInstalled() { | ||
28 | $sql = "SELECT name FROM sqlite_sequence WHERE name=?"; | ||
29 | $query = $this->executeQuery($sql, array('config')); | ||
30 | $hasConfig = $query->fetchAll(); | ||
31 | |||
32 | if (count($hasConfig) == 0) | ||
33 | return FALSE; | ||
34 | |||
35 | if (!$this->getLogin() || !$this->getPassword()) | ||
36 | return FALSE; | ||
37 | |||
38 | return TRUE; | ||
39 | } | ||
40 | |||
41 | public function install($login, $password) { | ||
42 | $this->getHandle()->exec('CREATE TABLE IF NOT EXISTS "config" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE , "name" VARCHAR UNIQUE, "value" BLOB)'); | ||
43 | |||
44 | $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)'); | ||
45 | |||
46 | if (!$this->getLogin()) { | ||
47 | $sql_login = 'INSERT INTO config ( name, value ) VALUES (?, ?)'; | ||
48 | $params_login = array('login', $login); | ||
49 | $query = $this->executeQuery($sql_login, $params_login); | ||
50 | } | ||
51 | |||
52 | if (!$this->getPassword()) { | ||
53 | $sql_pass = 'INSERT INTO config ( name, value ) VALUES (?, ?)'; | ||
54 | $params_pass = array('password', $password); | ||
55 | $query = $this->executeQuery($sql_pass, $params_pass); | ||
56 | } | ||
57 | |||
58 | return TRUE; | ||
59 | } | ||
60 | |||
61 | public function getLogin() { | ||
62 | $sql = "SELECT value FROM config WHERE name=?"; | ||
63 | $query = $this->executeQuery($sql, array('login')); | ||
64 | $login = $query->fetchAll(); | ||
65 | |||
66 | return isset($login[0]['value']) ? $login[0]['value'] : FALSE; | ||
67 | } | ||
68 | |||
69 | public function getPassword() { | ||
70 | $sql = "SELECT value FROM config WHERE name=?"; | ||
71 | $query = $this->executeQuery($sql, array('password')); | ||
72 | $pass = $query->fetchAll(); | ||
73 | |||
74 | return isset($pass[0]['value']) ? $pass[0]['value'] : FALSE; | ||
75 | } | ||
76 | |||
77 | public function updatePassword($password) | ||
78 | { | ||
79 | $sql_update = "UPDATE config SET value=? WHERE name='password'"; | ||
80 | $params_update = array($password); | ||
81 | $query = $this->executeQuery($sql_update, $params_update); | ||
82 | } | ||
83 | |||
28 | private function executeQuery($sql, $params) { | 84 | private function executeQuery($sql, $params) { |
29 | try | 85 | try |
30 | { | 86 | { |
@@ -107,6 +163,7 @@ class Sqlite extends Store { | |||
107 | $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; | 163 | $sql_action = 'INSERT INTO entries ( url, title, content ) VALUES (?, ?, ?)'; |
108 | $params_action = array($url, $title, $content); | 164 | $params_action = array($url, $title, $content); |
109 | $query = $this->executeQuery($sql_action, $params_action); | 165 | $query = $this->executeQuery($sql_action, $params_action); |
166 | return $query; | ||
110 | } | 167 | } |
111 | 168 | ||
112 | public function deleteById($id) { | 169 | public function deleteById($id) { |
@@ -114,6 +171,7 @@ class Sqlite extends Store { | |||
114 | $sql_action = "DELETE FROM entries WHERE id=?"; | 171 | $sql_action = "DELETE FROM entries WHERE id=?"; |
115 | $params_action = array($id); | 172 | $params_action = array($id); |
116 | $query = $this->executeQuery($sql_action, $params_action); | 173 | $query = $this->executeQuery($sql_action, $params_action); |
174 | return $query; | ||
117 | } | 175 | } |
118 | 176 | ||
119 | public function favoriteById($id) { | 177 | public function favoriteById($id) { |