forked from openlp/openlp
Fix various pyodbc related issues. Fixes bug 1590657.
Fixes: https://launchpad.net/bugs/1590657
This commit is contained in:
parent
e89803a3ad
commit
41c0d3fcf9
@ -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()
|
||||
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 = ?', song.Record)
|
||||
'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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 '
|
||||
|
Loading…
Reference in New Issue
Block a user