mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
API for kiwidude
This commit is contained in:
parent
39e8b5305c
commit
d70cb9f6e2
@ -1203,7 +1203,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
if m:
|
||||
return m['mtime']
|
||||
|
||||
def format_metadata(self, id_, fmt, allow_cache=True):
|
||||
def format_metadata(self, id_, fmt, allow_cache=True, update_db=False,
|
||||
commit=False):
|
||||
if not fmt:
|
||||
return {}
|
||||
fmt = fmt.upper()
|
||||
@ -1218,6 +1219,12 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
ans['size'] = stat.st_size
|
||||
ans['mtime'] = utcfromtimestamp(stat.st_mtime)
|
||||
self.format_metadata_cache[id_][fmt] = ans
|
||||
if update_db:
|
||||
self.conn.execute(
|
||||
'UPDATE data SET uncompressed_size=? WHERE format=? AND'
|
||||
' book=?', (stat.st_size, fmt, id_))
|
||||
if commit:
|
||||
self.conn.commit()
|
||||
return ans
|
||||
|
||||
def format_hash(self, id_, fmt):
|
||||
@ -2564,7 +2571,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
return []
|
||||
return result
|
||||
|
||||
def rename_series(self, old_id, new_name):
|
||||
def rename_series(self, old_id, new_name, change_index=True):
|
||||
new_name = new_name.strip()
|
||||
new_id = self.conn.get(
|
||||
'''SELECT id from series
|
||||
@ -2577,22 +2584,24 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
||||
# New series exists. Must update the link, then assign a
|
||||
# new series index to each of the books.
|
||||
|
||||
# Get the list of books where we must update the series index
|
||||
books = self.conn.get('''SELECT books.id
|
||||
FROM books, books_series_link as lt
|
||||
WHERE books.id = lt.book AND lt.series=?
|
||||
ORDER BY books.series_index''', (old_id,))
|
||||
if change_index:
|
||||
# Get the list of books where we must update the series index
|
||||
books = self.conn.get('''SELECT books.id
|
||||
FROM books, books_series_link as lt
|
||||
WHERE books.id = lt.book AND lt.series=?
|
||||
ORDER BY books.series_index''', (old_id,))
|
||||
# Now update the link table
|
||||
self.conn.execute('''UPDATE books_series_link
|
||||
SET series=?
|
||||
WHERE series=?''',(new_id, old_id,))
|
||||
# Now set the indices
|
||||
for (book_id,) in books:
|
||||
# Get the next series index
|
||||
index = self.get_next_series_num_for(new_name)
|
||||
self.conn.execute('''UPDATE books
|
||||
SET series_index=?
|
||||
WHERE id=?''',(index, book_id,))
|
||||
if change_index:
|
||||
# Now set the indices
|
||||
for (book_id,) in books:
|
||||
# Get the next series index
|
||||
index = self.get_next_series_num_for(new_name)
|
||||
self.conn.execute('''UPDATE books
|
||||
SET series_index=?
|
||||
WHERE id=?''',(index, book_id,))
|
||||
self.dirty_books_referencing('series', new_id, commit=False)
|
||||
self.conn.commit()
|
||||
|
||||
@ -3684,4 +3693,12 @@ books_series_link feeds
|
||||
s = self.conn.get('''SELECT book FROM books_plugin_data WHERE name=?''', (name,))
|
||||
return [x[0] for x in s]
|
||||
|
||||
def get_usage_count_by_id(self, field):
|
||||
fm = self.field_metadata[field]
|
||||
if not fm.get('link_column', None):
|
||||
raise ValueError('%s is not an is_multiple field')
|
||||
return self.conn.get(
|
||||
'SELECT {0}, count(*) FROM books_{1}_link GROUP BY {0}'.format(
|
||||
fm['link_column'], fm['table']))
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user