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
=== modified file 'openlp/plugins/songs/lib/olp1import.py'
--- openlp/plugins/songs/lib/olp1import.py 2011-09-12 16:35:32 +0000
+++ openlp/plugins/songs/lib/olp1import.py 2011-10-31 14:22:23 +0000
@@ -78,30 +78,35 @@
78 connection = sqlite.connect(self.importSource, mode=0444,78 connection = sqlite.connect(self.importSource, mode=0444,
79 encoding=(encoding, 'replace'))79 encoding=(encoding, 'replace'))
80 cursor = connection.cursor()80 cursor = connection.cursor()
81 # Determine if we're using a new or an old DB.81 # Determine if the db supports linking audio to songs.
82 cursor.execute(u'SELECT name FROM sqlite_master '82 cursor.execute(u'SELECT name FROM sqlite_master '
83 u'WHERE type = \'table\' AND name = \'tracks\'')83 u'WHERE type = \'table\' AND name = \'tracks\'')
84 new_db = len(cursor.fetchall()) > 084 db_has_tracks = len(cursor.fetchall()) > 0
85 # Determine if the db contains theme information.
86 cursor.execute(u'SELECT name FROM sqlite_master '
87 u'WHERE type = \'table\' AND name = \'settings\'')
88 db_has_themes = len(cursor.fetchall()) > 0
85 # "cache" our list of authors.89 # "cache" our list of authors.
86 cursor.execute(u'-- types int, unicode')90 cursor.execute(u'-- types int, unicode')
87 cursor.execute(u'SELECT authorid, authorname FROM authors')91 cursor.execute(u'SELECT authorid, authorname FROM authors')
88 authors = cursor.fetchall()92 authors = cursor.fetchall()
89 if new_db:93 if db_has_tracks:
90 # "cache" our list of tracks.94 # "cache" our list of tracks.
91 cursor.execute(u'-- types int, unicode')95 cursor.execute(u'-- types int, unicode')
92 cursor.execute(u'SELECT trackid, fulltrackname FROM tracks')96 cursor.execute(u'SELECT trackid, fulltrackname FROM tracks')
93 tracks = cursor.fetchall()97 tracks = cursor.fetchall()
94 # "cache" our list of themes.98 if db_has_themes:
95 cursor.execute(u'-- types int, unicode')99 # "cache" our list of themes.
96 cursor.execute(u'SELECT settingsid, settingsname FROM settings')100 themes = {}
97 themes = {}101 cursor.execute(u'-- types int, unicode')
98 for theme_id, theme_name in cursor.fetchall():102 cursor.execute(u'SELECT settingsid, settingsname FROM settings')
99 if theme_name in self.availableThemes:103 for theme_id, theme_name in cursor.fetchall():
100 themes[theme_id] = theme_name104 if theme_name in self.availableThemes:
105 themes[theme_id] = theme_name
101 # Import the songs.106 # Import the songs.
102 cursor.execute(u'-- types int, unicode, unicode, unicode, int')107 cursor.execute(u'-- types int, unicode, unicode, unicode')
103 cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, '108 cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS ' \
104 u'copyrightinfo, settingsid FROM songs')109 u'lyrics, copyrightinfo FROM songs')
105 songs = cursor.fetchall()110 songs = cursor.fetchall()
106 self.importWizard.progressBar.setMaximum(len(songs))111 self.importWizard.progressBar.setMaximum(len(songs))
107 for song in songs:112 for song in songs:
@@ -112,8 +117,13 @@
112 self.title = song[1]117 self.title = song[1]
113 lyrics = song[2].replace(u'\r\n', u'\n')118 lyrics = song[2].replace(u'\r\n', u'\n')
114 self.addCopyright(song[3])119 self.addCopyright(song[3])
115 if themes.has_key(song[4]):120 if db_has_themes:
116 self.themeName = themes[song[4]]121 cursor.execute(u'-- types int')
122 cursor.execute(
123 u'SELECT settingsid FROM songs WHERE songid = %s' % song_id)
124 theme_id = cursor.fetchone()[0]
125 if themes.has_key(theme_id):
126 self.themeName = themes[theme_id]
117 verses = lyrics.split(u'\n\n')127 verses = lyrics.split(u'\n\n')
118 for verse in verses:128 for verse in verses:
119 if verse.strip():129 if verse.strip():
@@ -131,7 +141,7 @@
131 break141 break
132 if self.stopImportFlag:142 if self.stopImportFlag:
133 break143 break
134 if new_db:144 if db_has_tracks:
135 cursor.execute(u'-- types int, int')145 cursor.execute(u'-- types int, int')
136 cursor.execute(u'SELECT trackid, listindex '146 cursor.execute(u'SELECT trackid, listindex '
137 u'FROM songtracks '147 u'FROM songtracks '