X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=m_librarian%2Fdb.py;h=cd2f6442582a99e60f46bbd84969f3063be053ef;hb=bb394bd389c243d3b285f9c434e6b9deb5e8833c;hp=ba091f3442286186c4cacb4de619f51078cb25cf;hpb=991627dd1d4fcdecc04a091ec9c0c8b9e8e8b27c;p=m_librarian.git diff --git a/m_librarian/db.py b/m_librarian/db.py index ba091f3..cd2f644 100755 --- a/m_librarian/db.py +++ b/m_librarian/db.py @@ -45,6 +45,18 @@ if not db_uri: sqlhub.processConnection = connection = connectionForURI(db_uri) if connection.dbName == 'sqlite': + def lower(s): + return s.lower() + + sqlite = connection.module + + class MLConnection(sqlite.Connection): + def __init__(self, *args, **kwargs): + super(MLConnection, self).__init__(*args, **kwargs) + self.create_function('lower', 1, lower) + + connection._connOptions['factory'] = MLConnection + # Speedup SQLite connection connection.query("PRAGMA synchronous=OFF") connection.query("PRAGMA count_changes=OFF") @@ -95,6 +107,7 @@ class Book(SQLObject): title_idx = DatabaseIndex(title) series_idx = DatabaseIndex(series) ser_no_idx = DatabaseIndex(ser_no) + archive_idx = DatabaseIndex(archive) archive_file_idx = DatabaseIndex(archive, file, unique=True) file_idx = DatabaseIndex(file) size_idx = DatabaseIndex(size) @@ -167,13 +180,13 @@ def insert_author(surname, name, misc_name): def update_counters(): for author in Author.select(): - author.count = len(author.books) + author.count = AuthorBook.select(AuthorBook.q.author == author).count() for ext in Extension.select(): ext.count = Book.select(Book.q.extension == ext.name).count() for genre in Genre.select(): - genre.count = len(genre.books) + genre.count = BookGenre.select(BookGenre.q.genre == genre).count() for language in Language.select(): language.count = Book.select(Book.q.language == language.name).count()