View Single Post
Old 05-11-2023, 11:22 AM   #2628
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
What was wrong with it? I've been using update ToC for months and never come across any problems unless there's entries with duplicate names.
This line in this function:
Code:
    def getDatabaseChapterId(self, bookId, toc_file, connection):
        cursor = connection.cursor()
        t = ("{0}%{1}%".format(bookId,toc_file),)
        cursor.execute('select ContentID from Content where ContentID like ?', t)
        try:
            result = next(cursor)
            chapterContentId = result['ContentID'] # <==============
        except StopIteration:
            chapterContentId = None

        debug_print('getDatabaseChapterId - chapterContentId=%s' % chapterContentId)
        cursor.close()
        return chapterContentId
The connection was built without a row factory so using the row like a named tuple or a dict can't work. It must be subscripted like a normal tuple.

The fix is
Code:
    def getDatabaseChapterId(self, bookId, toc_file, connection):
        cursor = connection.cursor()
        t = ("{0}%{1}%".format(bookId,toc_file),)
        cursor.execute('select ContentID from Content where ContentID like ?', t)
        try:
            result = next(cursor)
            chapterContentId = result[0]  #<===============
        except StopIteration:
            chapterContentId = None

        debug_print('getDatabaseChapterId - chapterContentId=%s' % chapterContentId)
        cursor.close()
        return chapterContentId
chaley is offline