Merge lp:~googol-deactivatedaccount/openlp/bug-872975 into lp:openlp

Proposed by Andreas Preikschat
Status: Merged
Approved by: Tim Bentley
Approved revision: 1792
Merged at revision: 1792
Proposed branch: lp:~googol-deactivatedaccount/openlp/bug-872975
Merge into: lp:openlp
Diff against target: 77 lines (+26/-16)
1 file modified
openlp/plugins/songs/lib/olp1import.py (+26/-16)
To merge this branch: bzr merge lp:~googol-deactivatedaccount/openlp/bug-872975
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Review via email: mp+80806@code.launchpad.net

Description of the change

- fixed bug #872975 (Importing from v1 fails with error about missing 'settings' table)

To post a comment you must log in.
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/plugins/songs/lib/olp1import.py'
2--- openlp/plugins/songs/lib/olp1import.py 2011-09-12 16:35:32 +0000
3+++ openlp/plugins/songs/lib/olp1import.py 2011-10-31 14:22:23 +0000
4@@ -78,30 +78,35 @@
5 connection = sqlite.connect(self.importSource, mode=0444,
6 encoding=(encoding, 'replace'))
7 cursor = connection.cursor()
8- # Determine if we're using a new or an old DB.
9+ # Determine if the db supports linking audio to songs.
10 cursor.execute(u'SELECT name FROM sqlite_master '
11 u'WHERE type = \'table\' AND name = \'tracks\'')
12- new_db = len(cursor.fetchall()) > 0
13+ db_has_tracks = len(cursor.fetchall()) > 0
14+ # Determine if the db contains theme information.
15+ cursor.execute(u'SELECT name FROM sqlite_master '
16+ u'WHERE type = \'table\' AND name = \'settings\'')
17+ db_has_themes = len(cursor.fetchall()) > 0
18 # "cache" our list of authors.
19 cursor.execute(u'-- types int, unicode')
20 cursor.execute(u'SELECT authorid, authorname FROM authors')
21 authors = cursor.fetchall()
22- if new_db:
23+ if db_has_tracks:
24 # "cache" our list of tracks.
25 cursor.execute(u'-- types int, unicode')
26 cursor.execute(u'SELECT trackid, fulltrackname FROM tracks')
27 tracks = cursor.fetchall()
28- # "cache" our list of themes.
29- cursor.execute(u'-- types int, unicode')
30- cursor.execute(u'SELECT settingsid, settingsname FROM settings')
31- themes = {}
32- for theme_id, theme_name in cursor.fetchall():
33- if theme_name in self.availableThemes:
34- themes[theme_id] = theme_name
35+ if db_has_themes:
36+ # "cache" our list of themes.
37+ themes = {}
38+ cursor.execute(u'-- types int, unicode')
39+ cursor.execute(u'SELECT settingsid, settingsname FROM settings')
40+ for theme_id, theme_name in cursor.fetchall():
41+ if theme_name in self.availableThemes:
42+ themes[theme_id] = theme_name
43 # Import the songs.
44- cursor.execute(u'-- types int, unicode, unicode, unicode, int')
45- cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, '
46- u'copyrightinfo, settingsid FROM songs')
47+ cursor.execute(u'-- types int, unicode, unicode, unicode')
48+ cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS ' \
49+ u'lyrics, copyrightinfo FROM songs')
50 songs = cursor.fetchall()
51 self.importWizard.progressBar.setMaximum(len(songs))
52 for song in songs:
53@@ -112,8 +117,13 @@
54 self.title = song[1]
55 lyrics = song[2].replace(u'\r\n', u'\n')
56 self.addCopyright(song[3])
57- if themes.has_key(song[4]):
58- self.themeName = themes[song[4]]
59+ if db_has_themes:
60+ cursor.execute(u'-- types int')
61+ cursor.execute(
62+ u'SELECT settingsid FROM songs WHERE songid = %s' % song_id)
63+ theme_id = cursor.fetchone()[0]
64+ if themes.has_key(theme_id):
65+ self.themeName = themes[theme_id]
66 verses = lyrics.split(u'\n\n')
67 for verse in verses:
68 if verse.strip():
69@@ -131,7 +141,7 @@
70 break
71 if self.stopImportFlag:
72 break
73- if new_db:
74+ if db_has_tracks:
75 cursor.execute(u'-- types int, int')
76 cursor.execute(u'SELECT trackid, listindex '
77 u'FROM songtracks '