Merge lp:~qqworini/ubuntu-rssreader-app/database_v1 into lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk

Proposed by Joey Chan
Status: Merged
Approved by: Roman Shchekin
Approved revision: 12
Merged at revision: 12
Proposed branch: lp:~qqworini/ubuntu-rssreader-app/database_v1
Merge into: lp:~ubuntu-shorts-dev/ubuntu-rssreader-app/trunk
Diff against target: 771 lines (+724/-20)
2 files modified
.bzrignore (+1/-0)
databasemodule_v2.js (+723/-20)
To merge this branch: bzr merge lp:~qqworini/ubuntu-rssreader-app/database_v1
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Roman Shchekin Approve
Review via email: mp+165346@code.launchpad.net

Commit message

first complete version of database, feel free to find bugs or help us to improve it :)

some functions seems not perfect enough, we should discuss them some time.

Description of the change

first complete version of database, feel free to find bugs or help us to improve it :)

some functions seems not perfect enough, we should discuss them some time.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Roman Shchekin (mrqtros) wrote :

Very good work, Joey! I have very hot time - making my graduate project, so I will active participate in development after final or stable design guides! ;)

23.05.13 15:19 Ubuntu Phone Apps Jenkins Bot написал(а):

Review: Approve continuous-integration

PASSED: Continuous integration, rev:11

http://91.189.93.125:8080/job/ubuntu-rssreader-app-ci/2/

Executed test runs:
SUCCESS: http://91.189.93.125:8080/job/ubuntu-rssreader-app-ci/2/

Click here to trigger a rebuild:

http://91.189.93.125:8080/job/ubuntu-rssreader-app-ci/2/

--
http://91.189.93.125:8080/job/ubuntu-rssreader-app-ci/2/

Your team Ubuntu RSS Feed Reader Developers is requested to review the proposed merge of lp:~qqworini/ubuntu-rssreader-app/database_v1 into lp:ubuntu-rssreader-app.

Revision history for this message
Roman Shchekin (mrqtros) wrote :

Seems good ;)

review: Approve
Revision history for this message
Roman Shchekin (mrqtros) wrote :

I think that we shouldn't use separate table for settings because of QSettings.
Maybe Guys from Toolkit team will provide its functionality in QML?

And only for Joey - I agree with your advice (using object instead of variable args), but why you are not used this technique in function
function addArticle(title, link, description, pubdate, guid, feed_id)
with huge amout of args? :)
Mb better will be
function addArticle(title, articleObj)

Revision history for this message
Joey Chan (qqworini) wrote :

> I think that we shouldn't use separate table for settings because of
> QSettings.
> Maybe Guys from Toolkit team will provide its functionality in QML?
>
> And only for Joey - I agree with your advice (using object instead of variable
> args), but why you are not used this technique in function
> function addArticle(title, link, description, pubdate, guid, feed_id)
> with huge amout of args? :)
> Mb better will be
> function addArticle(title, articleObj)

1. of course qsetting is better, setting table will be replaced if qsetting port to qml;
2. using object instead of variable args, this is a solution for function overload or unknown args' length, in function "addArticle", all args are fixed, no need to use obj;
besides, you can find many "update" functions for every table, like feed and article, I've tried to use obj to make those functions overload, but later I found this is not optimised, because some functions like "updateArticleStatus", it's much high frequency use than other functions. So finally I decided to separate them instead of "overload" them

12. By Joey Chan

bugs fixed for database module

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2013-04-04 11:05:43 +0000
3+++ .bzrignore 2013-05-28 03:32:25 +0000
4@@ -4,3 +4,4 @@
5 debian/app-template/
6 debian/*.debhelper.log
7 debian/*.substvars
8+RE:\.?[^.]+
9
10=== modified file 'databasemodule_v2.js'
11--- databasemodule_v2.js 2013-05-14 17:57:48 +0000
12+++ databasemodule_v2.js 2013-05-28 03:32:25 +0000
13@@ -5,7 +5,15 @@
14 var gDbCache = undefined
15 function openStdDataBase() {
16 if (gDbCache === undefined)
17- gDbCache = SQL.LocalStorage.openDatabaseSync("RSS Reader", "1.0", "App main DB", 10000) // Look, I changed DB name.
18+ {
19+ gDbCache = SQL.LocalStorage.openDatabaseSync("RSS Reader", "1.0", "App main DB", 1000000) // Look, I changed DB name.
20+ }
21+
22+ // check table exist after open the database
23+ gDbCache.transaction(function(tx){
24+ checkTableExists(tx/*, opts*/);
25+ }
26+ )
27 return gDbCache
28 }
29
30@@ -14,27 +22,722 @@
31 * NOTE 1 - it's JS function with variable number of arguments.
32 * NOTE 2 - mb "checkTableExisting" is better name.
33 */
34+
35+/*
36+The best way to do function overloading with parameters is not to check the argument length or the types;
37+checking the types will just make your code slow and you have the fun of Arrays, nulls, Objects, etc.
38+What most developers do is tack on an object as the last argument to their methods.
39+This object can hold anything.
40+
41+function foo(a, b, opts) {
42+
43+}
44+
45+
46+foo(1, 2, {"method":"add"});
47+foo(3, 4, {"test":"equals", "bar":"tree"});
48+
49+
50+copied from stackoverflow: http://stackoverflow.com/questions/456177/function-overloading-in-javascript-best-practices
51+
52+I suggest change "function checkTableExists" to: function checkTableExists(transaction, opts ),
53+no need to check argument length or the types
54+
55+or just make it simple, like below
56+*/
57 function checkTableExists(transaction /* and additional string keys */) {
58- for (var i = 1; i < arguments.length; i++) { // First argument is transaction so i = 1.
59- var arg = arguments[i]
60- switch (arg) {
61- case "feeds":
62- transaction.executeSql('CREATE TABLE IF NOT EXISTS ...')
63- break
64- case "articles":
65- transaction.executeSql('CREATE TABLE IF NOT EXISTS ...')
66- break
67- // ...
68- case "all": // Check all tables existing.
69- transaction.executeSql('CREATE TABLE IF NOT EXISTS ...')
70- transaction.executeSql('CREATE TABLE IF NOT EXISTS ...')
71- transaction.executeSql('CREATE TABLE IF NOT EXISTS ...')
72- break
73- default:
74- // mb some staff.
75- break;
76- }
77+// for (var i = 1; i < arguments.length; i++) { // First argument is transaction so i = 1.
78+// var arg = arguments[i]
79+// switch (arg) {
80+// case "feeds":
81+// transaction.executeSql('CREATE TABLE IF NOT EXISTS ...')
82+// break
83+// case "articles":
84+// transaction.executeSql('CREATE TABLE IF NOT EXISTS ...')
85+// break
86+// // ...
87+// case "all": // Check all tables existing.
88+ transaction.executeSql('PRAGMA foreign_keys = ON;') // enable foreign key support
89+ transaction.executeSql("CREATE TABLE IF NOT EXISTS feed (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,source VARCHAR(99) NULL,title VARCHAR(99) NULL,link VARCHAR(99) NULL,description TEXT NULL,pubdate INTEGER NULL,image VARCHAR(99) NULL);")
90+ transaction.executeSql("CREATE TABLE IF NOT EXISTS tag (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,name VARCHAR(99) NOT NULL UNIQUE );")
91+ transaction.executeSql("CREATE TABLE IF NOT EXISTS feed_tag (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,feed_id INTEGER NULL,tag_id INTEGER NULL,FOREIGN KEY(feed_id) REFERENCES feed(id) on delete cascade);")
92+ transaction.executeSql("CREATE TABLE IF NOT EXISTS article ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, title VARCHAR(99) NULL, link VARCHAR(99) NULL, description TEXT NULL, pubdate INTEGER NULL, status char(1) NULL DEFAULT '0', favourite char(1) NULL DEFAULT '0', image VARCHAR(99) NULL, guid VARCHAR(99) NULL, feed_id INTEGER NULL,count INTEGER NULL DEFAULT 0);")
93+ transaction.executeSql("CREATE TABLE IF NOT EXISTS settings ( id INTEGER, current_database_version VARCHAR(99) NULL, database_last_updated VARCHAR(99) NULL, view_mode char(1) NULL DEFAULT '0', update_interval INTEGER NULL DEFAULT 0, network_mode char(1) NULL DEFAULT '0');")
94+ var rs = transaction.executeSql("select * from settings")
95+ if (rs.rows.length == 0)
96+ {
97+ transaction.executeSql('INSERT INTO settings VALUES(?, ?, ?, ?, ?, ?)',
98+ [1 , 1.0, "000000", '0', 0, '0'])
99 }
100+// break
101+// default:
102+// // mb some staff.
103+// break;
104+// }
105+// }
106 }
107
108 // TODO More staff, discussed in Joey's letters and scheme.
109+
110+
111+
112+
113+/* feed operations
114+ * include select, insert, update and delete operations
115+ *
116+ *
117+ */
118+// select
119+function loadFeeds()
120+{
121+ var db = openStdDataBase()
122+ var dbResult
123+// var feeds
124+ db.transaction(function(tx) {
125+ dbResult = tx.executeSql("SELECT * FROM feed")
126+ console.log("feed SELECTED: ", dbResult.rows.length)
127+ //feeds = dbResultLocal.rows
128+ }
129+ )
130+ return dbResult; // I suggest that return the whole result in order to know if error occurs
131+}
132+
133+// insert
134+function addFeed(title, source) // from user input
135+{
136+ var dbResult
137+ var db = openStdDataBase()
138+ db.transaction(function (tx) {
139+// ensureFeedTableExists(tx)
140+
141+ /* Check uniqueness.
142+ */
143+ dbResult = tx.executeSql("SELECT * FROM feed WHERE source=?", [source])
144+ if (dbResult.rows.length > 0) {
145+ console.log("Database, addFeed: already exist feed with source: ", source)
146+ //dbResult.exist = true // TODO TMP, mb need string with error, will see later.
147+ return {"error": true, "exist": true};
148+ }
149+
150+ dbResult = tx.executeSql('INSERT INTO feed (title, source) VALUES(?, ?)',
151+ [title , source])
152+ console.log("feed INSERT ID: ", dbResult.insertId)
153+ }
154+ )
155+ return dbResult;
156+}
157+
158+// update
159+function updateFeedByUser(id, title, source) // from user input
160+{
161+ var db = openStdDataBase()
162+ var dbResult
163+ db.transaction(function (tx) {
164+// ensureFeedTableExists(tx)
165+ dbResult = tx.executeSql('UPDATE feed SET title=?, source=? WHERE id=?',
166+ [title, source, id])
167+ console.log("feed UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
168+ }
169+ )
170+ return dbResult
171+}
172+
173+function updateFeedByXml(id, link, description, pubdate) // from xml file
174+{
175+ var db = openStdDataBase()
176+ var dbResult
177+ db.transaction(function (tx) {
178+// ensureFeedTableExists(tx)
179+ dbResult = tx.executeSql('UPDATE feed SET link=?, description=?, pubdate=? WHERE id=?',
180+ [link, description, pubdate, id])
181+ console.log("feed UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
182+ }
183+ )
184+ return dbResult
185+}
186+
187+function updateFeedImage(id, image) // offline image path
188+{
189+ var db = openStdDataBase()
190+ var dbResult
191+ db.transaction(function (tx) {
192+// ensureFeedTableExists(tx)
193+ dbResult = tx.executeSql('UPDATE feed SET image=? WHERE id=?',
194+ [image, id])
195+ console.log("feed UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
196+ }
197+ )
198+ return dbResult
199+}
200+
201+function updateFeedCount(id, count) //
202+{
203+ var db = openStdDataBase()
204+ var dbResult
205+ db.transaction(function (tx) {
206+// ensureFeedTableExists(tx)
207+ dbResult = tx.executeSql('UPDATE feed SET count=? WHERE id=?',
208+ [count, id])
209+ console.log("feed UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
210+ }
211+ )
212+ return dbResult
213+}
214+
215+// delete
216+function deleteFeed(id)
217+{
218+ var db = openStdDataBase()
219+ var dbResult
220+ db.transaction(function (tx) {
221+// ensureFeedTableExists(tx)
222+ tx.executeSql('PRAGMA foreign_keys = ON;') // enable foreign key support
223+ dbResult = tx.executeSql('delete from feed WHERE id=?',
224+ [id])
225+ console.log("feed delete, AFFECTED ROWS: ", dbResult.rowsAffected)
226+ }
227+ )
228+ return dbResult
229+}
230+
231+
232+
233+/* article operations
234+ * include select, insert, update and delete operations
235+ *
236+ *
237+ */
238+// select
239+function loadArticles()
240+{
241+ var db = openStdDataBase()
242+ var dbResult
243+
244+ db.transaction(function(tx) {
245+ dbResult = tx.executeSql("SELECT * FROM article")
246+ console.log("article SELECTED: ", dbResult.rows.length)
247+
248+ }
249+ )
250+ return dbResult;
251+}
252+
253+// insert
254+function addArticle(title, link, description, pubdate, guid, feed_id)
255+{
256+ var dbResult
257+ var db = openStdDataBase()
258+ db.transaction(function (tx) {
259+// ensureFeedTableExists(tx)
260+
261+ /* Check uniqueness.
262+ */
263+ dbResult = tx.executeSql("SELECT * FROM article WHERE guid=?", [guid])
264+ if (dbResult.rows.length > 0) {
265+ console.log("Database, add article: already exist article with source: ", guid)
266+ //dbResult.exist = true // TODO TMP, mb need string with error, will see later.
267+ return {"error": true, "exist": true};
268+ }
269+
270+ dbResult = tx.executeSql('INSERT INTO article (title, link, description, pubdate, guid, feed_id) VALUES(?, ?, ?, ?, ?, ?)',
271+ [title , link, description, pubdate, guid, feed_id])
272+ console.log("article INSERT ID: ", dbResult.insertId)
273+ }
274+ )
275+ return dbResult;
276+}
277+
278+// update
279+function updateArticleStatus(id, status)
280+{
281+ var db = openStdDataBase()
282+ var dbResult
283+ db.transaction(function (tx) {
284+// ensureFeedTableExists(tx)
285+ dbResult = tx.executeSql('UPDATE article SET status=? WHERE id=?',
286+ [status, id])
287+ console.log("article UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
288+ }
289+ )
290+ return dbResult
291+}
292+
293+function updateArticleFavourite(id, favourite)
294+{
295+ var db = openStdDataBase()
296+ var dbResult
297+ db.transaction(function (tx) {
298+// ensureFeedTableExists(tx)
299+ dbResult = tx.executeSql('UPDATE article SET favourite=? WHERE id=?',
300+ [favourite, id])
301+ console.log("article UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
302+ }
303+ )
304+ return dbResult
305+}
306+
307+function updateArticleImage(id, image) // offline image path
308+{
309+ var db = openStdDataBase()
310+ var dbResult
311+ db.transaction(function (tx) {
312+// ensureFeedTableExists(tx)
313+ dbResult = tx.executeSql('UPDATE article SET image=? WHERE id=?',
314+ [image, id])
315+ console.log("article UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
316+ }
317+ )
318+ return dbResult
319+}
320+
321+
322+// delete
323+function deleteArticle(id)
324+{
325+ var db = openStdDataBase()
326+ var dbResult
327+ db.transaction(function (tx) {
328+// ensureFeedTableExists(tx)
329+ dbResult = tx.executeSql('delete from article WHERE id=?',
330+ [id])
331+ console.log("article delete, AFFECTED ROWS: ", dbResult.rowsAffected)
332+ }
333+ )
334+ return dbResult
335+}
336+
337+// clear article table, only status='2' and favourite='1' remain
338+function clearArticle(feed_id)
339+{
340+ var db = openStdDataBase()
341+ var dbResult
342+ db.transaction(function (tx) {
343+// ensureFeedTableExists(tx)
344+ dbResult = tx.executeSql("delete from article WHERE (status='0' OR status='1') AND favourite='0' AND feed_id=?", [feed_id])
345+ console.log("article delete, AFFECTED ROWS: ", dbResult.rowsAffected)
346+ }
347+ )
348+ return dbResult
349+}
350+
351+
352+/* tag operations
353+ * include select, insert, update and delete operations
354+ *
355+ *
356+ */
357+// select
358+function loadTags()
359+{
360+ var db = openStdDataBase()
361+ var dbResult
362+
363+ db.transaction(function(tx) {
364+ dbResult = tx.executeSql("SELECT * FROM tag")
365+ console.log("tag SELECTED: ", dbResult.rows.length)
366+
367+ }
368+ )
369+ return dbResult;
370+}
371+
372+// insert
373+function addTag(name)
374+{
375+ var dbResult
376+ var db = openStdDataBase()
377+ db.transaction(function (tx) {
378+// ensureFeedTableExists(tx)
379+
380+ /* Check uniqueness.
381+ */
382+ dbResult = tx.executeSql("SELECT * FROM tag WHERE name=?", [name])
383+ if (dbResult.rows.length > 0) {
384+ console.log("Database, add tag: already exist tag with source: ", name)
385+ //dbResult.exist = true // TODO TMP, mb need string with error, will see later.
386+ return {"error": true, "exist": true};
387+ }
388+
389+ dbResult = tx.executeSql('INSERT INTO tag (name) VALUES(?)',
390+ [name])
391+ console.log("article INSERT ID: ", dbResult.insertId)
392+ }
393+ )
394+ return dbResult;
395+}
396+
397+// update
398+function updateTag(id, name)
399+{
400+ var db = openStdDataBase()
401+ var dbResult
402+ db.transaction(function (tx) {
403+// ensureFeedTableExists(tx)
404+ dbResult = tx.executeSql('UPDATE tag SET name=? WHERE id=?',
405+ [name, id])
406+ console.log("tag UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
407+ }
408+ )
409+ return dbResult
410+}
411+
412+// delete
413+function deleteTag(id)
414+{
415+ var db = openStdDataBase()
416+ var dbResult
417+ db.transaction(function (tx) {
418+// ensureFeedTableExists(tx)
419+ dbResult = tx.executeSql('delete from tag WHERE id=?',
420+ [id])
421+ console.log("tag delete, AFFECTED ROWS: ", dbResult.rowsAffected)
422+ }
423+ )
424+ return dbResult
425+}
426+
427+
428+/* feed_tag operations
429+ * include select, insert and delete operations
430+ *
431+ *
432+ */
433+// select
434+function loadFeedTags()
435+{
436+ var db = openStdDataBase()
437+ var dbResult
438+
439+ db.transaction(function(tx) {
440+ dbResult = tx.executeSql("SELECT * FROM feed_tag")
441+ console.log("feed_tag SELECTED: ", dbResult.rows.length)
442+
443+ }
444+ )
445+ return dbResult;
446+}
447+
448+// insert
449+function addFeedTag(feed_id, tag_id)
450+{
451+ var dbResult
452+ var db = openStdDataBase()
453+ db.transaction(function (tx) {
454+// ensureFeedTableExists(tx)
455+
456+ /* Check uniqueness.
457+ */
458+ dbResult = tx.executeSql("SELECT * FROM feed_tag WHERE feed_id=? AND tag_id=? ", [feed_id, tag_id])
459+ if (dbResult.rows.length > 0) {
460+ console.log("Database, add feed_tag: already exist feed_tag with source: ", feed_id, tag_id)
461+ //dbResult.exist = true // TODO TMP, mb need string with error, will see later.
462+ return {"error": true, "exist": true};
463+ }
464+
465+ dbResult = tx.executeSql('INSERT INTO feed_tag (feed_id, tag_id) VALUES(?, ?)',
466+ [feed_id, tag_id])
467+ console.log("feed_tag INSERT ID: ", dbResult.insertId)
468+ }
469+ )
470+ return dbResult;
471+}
472+
473+// delete
474+function deleteFeedTag(id)
475+{
476+ var db = openStdDataBase()
477+ var dbResult
478+ db.transaction(function (tx) {
479+// ensureFeedTableExists(tx)
480+ dbResult = tx.executeSql('delete from feed_tag WHERE id=?',
481+ [id])
482+ console.log("feed_tag delete, AFFECTED ROWS: ", dbResult.rowsAffected)
483+ }
484+ )
485+ return dbResult
486+}
487+
488+
489+/* settings operations
490+ * include select and update operations
491+ *
492+ *
493+ */
494+// select //for each setting
495+function getDBVersion()
496+{
497+ var db = openStdDataBase()
498+ var dbResult
499+ var dbVersion = ""
500+
501+ db.transaction(function(tx) {
502+ dbResult = tx.executeSql("SELECT current_database_version FROM settings where id=1")
503+ if (dbResult.rows.length > 0)
504+ {
505+ dbVersion = dbResult.rows.item(0).current_database_version ;
506+ }
507+
508+ }
509+ )
510+ return dbVersion;
511+}
512+
513+function getDBLastUpdate()
514+{
515+ var db = openStdDataBase()
516+ var dbResult
517+ var dbLastUpdate = ""
518+
519+ db.transaction(function(tx) {
520+ dbResult = tx.executeSql("SELECT database_last_updated FROM settings where id=1")
521+ if (dbResult.rows.length > 0)
522+ {
523+ dbLastUpdate = dbResult.rows.item(0).database_last_updated ;
524+ }
525+
526+ }
527+ )
528+ return dbLastUpdate;
529+}
530+
531+function getViewMode()
532+{
533+ var db = openStdDataBase()
534+ var dbResult
535+ var dbViewMode = ""
536+
537+ db.transaction(function(tx) {
538+ dbResult = tx.executeSql("SELECT view_mode FROM settings where id=1")
539+ if (dbResult.rows.length > 0)
540+ {
541+ dbViewMode = dbResult.rows.item(0).view_mode ;
542+ }
543+
544+ }
545+ )
546+ return dbViewMode;
547+}
548+
549+function getUpdateInterval()
550+{
551+ var db = openStdDataBase()
552+ var dbResult
553+ var dbUpdateInterval = 0
554+
555+ db.transaction(function(tx) {
556+ dbResult = tx.executeSql("SELECT update_interval FROM settings where id=1")
557+ if (dbResult.rows.length > 0)
558+ {
559+ dbUpdateInterval = dbResult.rows.item(0).update_interval ;
560+ }
561+
562+ }
563+ )
564+ return dbUpdateInterval;
565+}
566+
567+function getNetworkMode()
568+{
569+ var db = openStdDataBase()
570+ var dbResult
571+ var dbNetworkMode = ""
572+
573+ db.transaction(function(tx) {
574+ dbResult = tx.executeSql("SELECT network_mode FROM settings where id=1")
575+ if (dbResult.rows.length > 0)
576+ {
577+ dbNetworkMode = dbResult.rows.item(0).network_mode ;
578+ }
579+
580+ }
581+ )
582+ return dbNetworkMode;
583+}
584+
585+// update //for each setting
586+function setDBVersion(current_database_version)
587+{
588+ var db = openStdDataBase()
589+ var dbResult
590+ db.transaction(function (tx) {
591+// ensureFeedTableExists(tx)
592+ dbResult = tx.executeSql('UPDATE settings SET current_database_version=? WHERE id=1',
593+ [current_database_version])
594+ console.log("settings UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
595+ }
596+ )
597+ return dbResult
598+}
599+
600+function setDBLastUpdate(database_last_updated)
601+{
602+ var db = openStdDataBase()
603+ var dbResult
604+ db.transaction(function (tx) {
605+// ensureFeedTableExists(tx)
606+ dbResult = tx.executeSql('UPDATE settings SET database_last_updated=? WHERE id=1',
607+ [database_last_updated])
608+ console.log("settings UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
609+ }
610+ )
611+ return dbResult
612+}
613+
614+function setViewMode(view_mode)
615+{
616+ var db = openStdDataBase()
617+ var dbResult
618+ db.transaction(function (tx) {
619+// ensureFeedTableExists(tx)
620+ dbResult = tx.executeSql('UPDATE settings SET view_mode=? WHERE id=1',
621+ [view_mode])
622+ console.log("settings UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
623+ }
624+ )
625+ return dbResult
626+}
627+
628+function setUpdateInterval(update_interval)
629+{
630+ var db = openStdDataBase()
631+ var dbResult
632+ db.transaction(function (tx) {
633+// ensureFeedTableExists(tx)
634+ dbResult = tx.executeSql('UPDATE settings SET update_interval=? WHERE id=1',
635+ [update_interval])
636+ console.log("settings UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
637+ }
638+ )
639+ return dbResult
640+}
641+
642+function setNetworkMode(network_mode)
643+{
644+ var db = openStdDataBase()
645+ var dbResult
646+ db.transaction(function (tx) {
647+// ensureFeedTableExists(tx)
648+ dbResult = tx.executeSql('UPDATE settings SET network_mode=? WHERE id=1',
649+ [network_mode])
650+ console.log("settings UPDATE, AFFECTED ROWS: ", dbResult.rowsAffected)
651+ }
652+ )
653+ return dbResult
654+}
655+
656+
657+
658+/* operations for testing
659+ * include clear and drop operations
660+ * not completed yet
661+ *
662+ */
663+// clear
664+function clearData(table)
665+{
666+ var db = openStdDataBase()
667+
668+ switch(table)
669+ {
670+ case "feed":
671+ db.transaction(function(tx) {
672+ tx.executeSql("delete from feed")
673+ console.log("feed clear")
674+ }
675+ )
676+ break;
677+ case "article":
678+ db.transaction(function(tx) {
679+ tx.executeSql("delete from article")
680+ console.log("article clear")
681+ }
682+ )
683+ break;
684+ case "tag":
685+ db.transaction(function(tx) {
686+ tx.executeSql("delete from tag")
687+ console.log("tag clear")
688+ }
689+ )
690+ break;
691+ case "feed_tag":
692+ db.transaction(function(tx) {
693+ tx.executeSql("delete from feed_tag")
694+ console.log("feed_tag clear")
695+ }
696+ )
697+ break;
698+ case "settings":
699+ db.transaction(function(tx) {
700+ tx.executeSql("delete from settings")
701+ console.log("settings clear")
702+ }
703+ )
704+ break;
705+ default:
706+ db.transaction(function(tx) {
707+ tx.executeSql("delete from feed_tag")
708+ tx.executeSql("delete from feed")
709+ tx.executeSql("delete from tag")
710+ tx.executeSql("delete from article")
711+ tx.executeSql("delete from settings")
712+ console.log("DATABASE clear")
713+ }
714+ )
715+ }
716+}
717+
718+// drop
719+function dropTable(table)
720+{
721+ var db = openStdDataBase()
722+
723+ switch(table)
724+ {
725+ case "feed":
726+ db.transaction(function(tx) {
727+ tx.executeSql("DROP TABLE IF EXISTS feed")
728+ console.log("feed deleted")
729+ }
730+ )
731+ break;
732+ case "article":
733+ db.transaction(function(tx) {
734+ tx.executeSql("DROP TABLE IF EXISTS article")
735+ console.log("article deleted")
736+ }
737+ )
738+ break;
739+ case "tag":
740+ db.transaction(function(tx) {
741+ tx.executeSql("DROP TABLE IF EXISTS tag")
742+ console.log("tag deleted")
743+ }
744+ )
745+ break;
746+ case "feed_tag":
747+ db.transaction(function(tx) {
748+ tx.executeSql("DROP TABLE IF EXISTS feed_tag")
749+ console.log("feed_tag deleted")
750+ }
751+ )
752+ break;
753+ case "settings":
754+ db.transaction(function(tx) {
755+ tx.executeSql("DROP TABLE IF EXISTS settings")
756+ console.log("settings deleted")
757+ }
758+ )
759+ break;
760+ default:
761+ db.transaction(function(tx) {
762+ tx.executeSql("DROP TABLE IF EXISTS feed")
763+ tx.executeSql("DROP TABLE IF EXISTS article")
764+ tx.executeSql("DROP TABLE IF EXISTS tag")
765+ tx.executeSql("DROP TABLE IF EXISTS feed_tag")
766+ tx.executeSql("DROP TABLE IF EXISTS settings")
767+ console.log("DATABASE deleted")
768+ }
769+ )
770+ }
771+}

Subscribers

People subscribed via source and target branches