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

bzr-revno: 1792
Fixes: https://launchpad.net/bugs/872975
This commit is contained in:
Andreas Preikschat 2011-10-31 22:39:01 +01:00
commit b0b4656ed6

View File

@ -78,30 +78,35 @@ class OpenLP1SongImport(SongImport):
connection = sqlite.connect(self.importSource, mode=0444, connection = sqlite.connect(self.importSource, mode=0444,
encoding=(encoding, 'replace')) encoding=(encoding, 'replace'))
cursor = connection.cursor() cursor = connection.cursor()
# Determine if we're using a new or an old DB. # Determine if the db supports linking audio to songs.
cursor.execute(u'SELECT name FROM sqlite_master ' cursor.execute(u'SELECT name FROM sqlite_master '
u'WHERE type = \'table\' AND name = \'tracks\'') u'WHERE type = \'table\' AND name = \'tracks\'')
new_db = len(cursor.fetchall()) > 0 db_has_tracks = len(cursor.fetchall()) > 0
# Determine if the db contains theme information.
cursor.execute(u'SELECT name FROM sqlite_master '
u'WHERE type = \'table\' AND name = \'settings\'')
db_has_themes = len(cursor.fetchall()) > 0
# "cache" our list of authors. # "cache" our list of authors.
cursor.execute(u'-- types int, unicode') cursor.execute(u'-- types int, unicode')
cursor.execute(u'SELECT authorid, authorname FROM authors') cursor.execute(u'SELECT authorid, authorname FROM authors')
authors = cursor.fetchall() authors = cursor.fetchall()
if new_db: if db_has_tracks:
# "cache" our list of tracks. # "cache" our list of tracks.
cursor.execute(u'-- types int, unicode') cursor.execute(u'-- types int, unicode')
cursor.execute(u'SELECT trackid, fulltrackname FROM tracks') cursor.execute(u'SELECT trackid, fulltrackname FROM tracks')
tracks = cursor.fetchall() tracks = cursor.fetchall()
# "cache" our list of themes. if db_has_themes:
cursor.execute(u'-- types int, unicode') # "cache" our list of themes.
cursor.execute(u'SELECT settingsid, settingsname FROM settings') themes = {}
themes = {} cursor.execute(u'-- types int, unicode')
for theme_id, theme_name in cursor.fetchall(): cursor.execute(u'SELECT settingsid, settingsname FROM settings')
if theme_name in self.availableThemes: for theme_id, theme_name in cursor.fetchall():
themes[theme_id] = theme_name if theme_name in self.availableThemes:
themes[theme_id] = theme_name
# Import the songs. # Import the songs.
cursor.execute(u'-- types int, unicode, unicode, unicode, int') cursor.execute(u'-- types int, unicode, unicode, unicode')
cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, ' cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS ' \
u'copyrightinfo, settingsid FROM songs') u'lyrics, copyrightinfo FROM songs')
songs = cursor.fetchall() songs = cursor.fetchall()
self.importWizard.progressBar.setMaximum(len(songs)) self.importWizard.progressBar.setMaximum(len(songs))
for song in songs: for song in songs:
@ -112,8 +117,13 @@ class OpenLP1SongImport(SongImport):
self.title = song[1] self.title = song[1]
lyrics = song[2].replace(u'\r\n', u'\n') lyrics = song[2].replace(u'\r\n', u'\n')
self.addCopyright(song[3]) self.addCopyright(song[3])
if themes.has_key(song[4]): if db_has_themes:
self.themeName = themes[song[4]] cursor.execute(u'-- types int')
cursor.execute(
u'SELECT settingsid FROM songs WHERE songid = %s' % song_id)
theme_id = cursor.fetchone()[0]
if themes.has_key(theme_id):
self.themeName = themes[theme_id]
verses = lyrics.split(u'\n\n') verses = lyrics.split(u'\n\n')
for verse in verses: for verse in verses:
if verse.strip(): if verse.strip():
@ -131,7 +141,7 @@ class OpenLP1SongImport(SongImport):
break break
if self.stopImportFlag: if self.stopImportFlag:
break break
if new_db: if db_has_tracks:
cursor.execute(u'-- types int, int') cursor.execute(u'-- types int, int')
cursor.execute(u'SELECT trackid, listindex ' cursor.execute(u'SELECT trackid, listindex '
u'FROM songtracks ' u'FROM songtracks '