From 41c0d3fcf9c01430ab36d8c42f01021f5d8bdf88 Mon Sep 17 00:00:00 2001 From: Tomas Groth Date: Tue, 14 Jun 2016 21:11:57 +0200 Subject: [PATCH] Fix various pyodbc related issues. Fixes bug 1590657. Fixes: https://launchpad.net/bugs/1590657 --- .../plugins/songs/lib/importers/mediashout.py | 28 +++++++++++-------- openlp/plugins/songs/lib/importers/opspro.py | 6 ++-- .../songs/lib/importers/worshipcenterpro.py | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/openlp/plugins/songs/lib/importers/mediashout.py b/openlp/plugins/songs/lib/importers/mediashout.py index cb3a19640..af9b855a0 100644 --- a/openlp/plugins/songs/lib/importers/mediashout.py +++ b/openlp/plugins/songs/lib/importers/mediashout.py @@ -24,15 +24,17 @@ The :mod:`mediashout` module provides the functionality for importing a MediaShout database into the OpenLP database. """ -# WARNING: See https://docs.python.org/2/library/sqlite3.html for value substitution +# WARNING: See https://docs.python.org/3/library/sqlite3.html for value substitution # in SQL statements import pyodbc +import logging from openlp.core.lib import translate from openlp.plugins.songs.lib.importers.songimport import SongImport VERSE_TAGS = ['V', 'C', 'B', 'O', 'P', 'I', 'E'] +log = logging.getLogger(__name__) class MediaShoutImport(SongImport): @@ -44,17 +46,19 @@ class MediaShoutImport(SongImport): """ Initialise the MediaShout importer. """ - SongImport.__init__(self, manager, **kwargs) + super(MediaShoutImport, self).__init__(manager, **kwargs) + #SongImport.__init__(self, manager, **kwargs) def do_import(self): """ Receive a single file to import. """ try: - conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ={source};' - 'PWD=6NOZ4eHK7k'.format(sorce=self.import_source)) - except: + conn = pyodbc.connect('DRIVER={{Microsoft Access Driver (*.mdb)}};DBQ={source};' + 'PWD=6NOZ4eHK7k'.format(source=self.import_source)) + except Exception as e: # Unfortunately no specific exception type + log.exception(e) self.log_error(self.import_source, translate('SongsPlugin.MediaShoutImport', 'Unable to open the MediaShout database.')) return @@ -63,17 +67,19 @@ class MediaShoutImport(SongImport): songs = cursor.fetchall() self.import_wizard.progress_bar.setMaximum(len(songs)) for song in songs: + topics = [] if self.stop_import_flag: break - cursor.execute('SELECT Type, Number, Text FROM Verses WHERE Record = ? ORDER BY Type, Number', song.Record) + cursor.execute('SELECT Type, Number, Text FROM Verses WHERE Record = ? ORDER BY Type, Number', float(song.Record)) verses = cursor.fetchall() - cursor.execute('SELECT Type, Number, POrder FROM PlayOrder WHERE Record = ? ORDER BY POrder', song.Record) + cursor.execute('SELECT Type, Number, POrder FROM PlayOrder WHERE Record = ? ORDER BY POrder', float(song.Record)) verse_order = cursor.fetchall() - cursor.execute('SELECT Name FROM Themes INNER JOIN SongThemes ON SongThemes.ThemeId = Themes.ThemeId ' - 'WHERE SongThemes.Record = ?', song.Record) - topics = cursor.fetchall() + if cursor.tables(table='TableName', tableType='TABLE').fetchone(): + cursor.execute('SELECT Name FROM Themes INNER JOIN SongThemes ON SongThemes.ThemeId = Themes.ThemeId ' + 'WHERE SongThemes.Record = ?', float(song.Record)) + topics = cursor.fetchall() cursor.execute('SELECT Name FROM Groups INNER JOIN SongGroups ON SongGroups.GroupId = Groups.GroupId ' - 'WHERE SongGroups.Record = ?', song.Record) + 'WHERE SongGroups.Record = ?', float(song.Record)) topics += cursor.fetchall() self.process_song(song, verses, verse_order, topics) diff --git a/openlp/plugins/songs/lib/importers/opspro.py b/openlp/plugins/songs/lib/importers/opspro.py index 8f9674deb..03c5001c6 100644 --- a/openlp/plugins/songs/lib/importers/opspro.py +++ b/openlp/plugins/songs/lib/importers/opspro.py @@ -55,7 +55,7 @@ class OPSProImport(SongImport): """ password = self.extract_mdb_password() try: - conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ={source};' + conn = pyodbc.connect('DRIVER={{Microsoft Access Driver (*.mdb)}};DBQ={source};' 'PWD={password}'.format(source=self.import_source, password=password)) except (pyodbc.DatabaseError, pyodbc.IntegrityError, pyodbc.InternalError, pyodbc.OperationalError) as e: log.warning('Unable to connect the OPS Pro database {source}. {error}'.format(source=self.import_source, @@ -74,11 +74,11 @@ class OPSProImport(SongImport): break # Type means: 0=Original, 1=Projection, 2=Own cursor.execute('SELECT Lyrics, Type, IsDualLanguage FROM Lyrics WHERE SongID = ? AND Type < 2 ' - 'ORDER BY Type DESC', song.ID) + 'ORDER BY Type DESC', float(song.ID)) lyrics = cursor.fetchone() cursor.execute('SELECT CategoryName FROM Category INNER JOIN SongCategory ' 'ON Category.ID = SongCategory.CategoryID WHERE SongCategory.SongID = ? ' - 'ORDER BY CategoryName', song.ID) + 'ORDER BY CategoryName', float(song.ID)) topics = cursor.fetchall() try: self.process_song(song, lyrics, topics) diff --git a/openlp/plugins/songs/lib/importers/worshipcenterpro.py b/openlp/plugins/songs/lib/importers/worshipcenterpro.py index df04823e8..3d5cbe9ba 100644 --- a/openlp/plugins/songs/lib/importers/worshipcenterpro.py +++ b/openlp/plugins/songs/lib/importers/worshipcenterpro.py @@ -49,7 +49,7 @@ class WorshipCenterProImport(SongImport): Receive a single file to import. """ try: - conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};' + conn = pyodbc.connect('DRIVER={{Microsoft Access Driver (*.mdb)}};' 'DBQ={source}'.format(source=self.import_source)) except (pyodbc.DatabaseError, pyodbc.IntegrityError, pyodbc.InternalError, pyodbc.OperationalError) as e: log.warning('Unable to connect the WorshipCenter Pro '