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

Subscribers

People subscribed via source and target branches