@@ -25,16 +25,32 @@ function init() {
2525 tx.executeSql('CREATE TABLE IF NOT EXISTS Queue(ind INTEGER NOT NULL, guid TEXT, image TEXT, name TEXT, artist TEXT, url TEXT)');
2626 });
2727
28− /*
29− Schema Upgrade to v1.2 which adds a new favourited boolean variable which is needed to track the favourite status
30− of an episode.
31− */
32− if (db.version != "1.2") {
33− console.log("Upgrading database from %1 -> v1.2".arg(db.version))
34− db.changeVersion(db.version, "1.2", function(tx) {
35− tx.executeSql('ALTER TABLE Episode ADD favourited BOOLEAN');
36− tx.executeSql('UPDATE Episode SET favourited=?', [false]);
37− });
28+ try {
29+ /*
30+ Schema Upgrade to v1.1 which adds a new queued boolean variable which is needed to track the queued status
31+ of a episode properly.
32+ */
33+ if (db.version === "1.0" || db.version === "") {
34+ console.log("Upgrading database from %1 -> v1.1".arg(db.version))
35+ db.changeVersion(db.version, "1.1", function(tx) {
36+ tx.executeSql('ALTER TABLE Episode ADD queued BOOLEAN');
37+ tx.executeSql('UPDATE Episode SET queued=0');
38+ });
39+ }
40+
41+ /*
42+ Schema Upgrade to v1.2 which adds a new favourited boolean variable which is needed to track the favourite status
43+ of an episode.
44+ */
45+ if (db.version === "1.1") {
46+ console.log("Upgrading database from %1 -> v1.2".arg(db.version))
47+ db.changeVersion("1.1", "1.2", function(tx) {
48+ tx.executeSql('ALTER TABLE Episode ADD favourited BOOLEAN');
49+ tx.executeSql('UPDATE Episode SET favourited=?', [false]);
50+ });
51+ }
52+ } catch(ex) {
53+ console.log(ex)
3854 }
3955
4056 return db;
@@ -212,15 +228,15 @@ function updateEpisodes(refreshModel) {
212228 var ers = tx2.executeSql("SELECT rowid FROM Episode WHERE guid=?", [track.guid]);
213229 if (ers.rows.length === 0) {
214230 tx2.executeSql("INSERT INTO Episode(podcast, name, description, audiourl, guid, listened, queued, favourited, duration, published) VALUES(?, ?, ? , ?, ?, ?, ?, ?, ?, ?)", [pid,
215− track.name,
216− track.description,
217− track.audiourl,
218− track.guid,
219− false,
220− false,
221− false,
222− track.duration,
223− track.published]);
231+ track.name,
232+ track.description,
233+ track.audiourl,
234+ track.guid,
235+ false,
236+ false,
237+ false,
238+ track.duration,
239+ track.published]);
224240 }
225241 });
226242 }