4
4
###############################################################################
5
5
# OpenLP - Open Source Lyrics Projection #
6
6
# --------------------------------------------------------------------------- #
7
# Copyright (c) 2008-2018 OpenLP Developers #
7
# Copyright (c) 2008-2019 OpenLP Developers #
8
8
# --------------------------------------------------------------------------- #
9
9
# This program is free software; you can redistribute it and/or modify it #
10
10
# under the terms of the GNU General Public License as published by the Free #
20
20
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21
21
###############################################################################
29
29
from PyQt5 import QtCore
30
from sqlalchemy import Column, ForeignKey, Table, or_, types, func
30
from sqlalchemy import Column, ForeignKey, Table, func, or_, types
31
31
from sqlalchemy.exc import OperationalError
32
32
from sqlalchemy.orm import class_mapper, mapper, relation
33
33
from sqlalchemy.orm.exc import UnmappedClassError
36
36
from openlp.core.common.applocation import AppLocation
37
37
from openlp.core.common.i18n import translate
38
38
from openlp.core.common.path import Path
39
from openlp.core.lib.db import BaseModel, init_db, Manager
39
from openlp.core.lib.db import BaseModel, Manager, init_db
40
40
from openlp.core.lib.ui import critical_error_message_box
41
41
from openlp.plugins.bibles.lib import BibleStrings, LanguageSelection, upgrade
43
44
log = logging.getLogger(__name__)
45
46
RESERVED_CHARACTERS = '\\.^$*+?{}[]()'
83
84
meta_table = Table('metadata', metadata,
84
85
Column('key', types.Unicode(255), primary_key=True, index=True),
85
Column('value', types.Unicode(255)),)
86
Column('value', types.Unicode(255)))
87
88
book_table = Table('book', metadata,
88
89
Column('id', types.Integer, primary_key=True),
89
90
Column('book_reference_id', types.Integer, index=True),
90
91
Column('testament_reference_id', types.Integer),
91
Column('name', types.Unicode(50), index=True),)
92
Column('name', types.Unicode(50), index=True))
92
93
verse_table = Table('verse', metadata,
93
94
Column('id', types.Integer, primary_key=True, index=True),
94
Column('book_id', types.Integer, ForeignKey(
95
'book.id'), index=True),
95
Column('book_id', types.Integer, ForeignKey('book.id'), index=True),
96
96
Column('chapter', types.Integer, index=True),
97
97
Column('verse', types.Integer, index=True),
98
Column('text', types.UnicodeText, index=True),)
98
Column('text', types.UnicodeText, index=True))
101
101
class_mapper(BibleMeta)
158
158
self.name = kwargs['name']
159
159
if not isinstance(self.name, str):
160
160
self.name = str(self.name, 'utf-8')
161
# TODO: To path object
162
file_path = Path(clean_filename(self.name) + '.sqlite')
161
self.file_path = Path(clean_filename(self.name) + '.sqlite')
163
162
if 'file' in kwargs:
164
file_path = kwargs['file']
165
Manager.__init__(self, 'bibles', init_schema, file_path, upgrade)
163
self.file_path = kwargs['file']
164
Manager.__init__(self, 'bibles', init_schema, self.file_path, upgrade)
166
165
if self.session and 'file' in kwargs:
168
167
self._is_web_bible = None
170
169
def get_name(self):
766
765
if AlternativeBookNamesDB.cursor is None:
767
766
file_path = AppLocation.get_directory(AppLocation.DataDir) / 'bibles' / 'alternative_book_names.sqlite'
767
exists = file_path.exists()
768
768
AlternativeBookNamesDB.conn = sqlite3.connect(str(file_path))
769
if not file_path.exists():
770
770
# create new DB, create table alternative_book_names
771
771
AlternativeBookNamesDB.conn.execute(
772
772
'CREATE TABLE alternative_book_names(id INTEGER NOT NULL, '