diff --git a/resources/fts_sqlite.sql b/resources/fts_sqlite.sql index cda94b4f11..24348c15b8 100644 --- a/resources/fts_sqlite.sql +++ b/resources/fts_sqlite.sql @@ -11,10 +11,10 @@ CREATE TABLE fts_db.books_text ( id INTEGER PRIMARY KEY, format TEXT NOT NULL COLLATE NOCASE, format_hash TEXT NOT NULL COLLATE NOCASE, format_size INTEGER NOT NULL DEFAULT 0, - searchable_text TEXT NOT NULL DEFAULT "", + searchable_text TEXT NOT NULL DEFAULT '', text_size INTEGER NOT NULL DEFAULT 0, - text_hash TEXT NOT NULL COLLATE NOCASE DEFAULT "", - err_msg TEXT DEFAULT "", + text_hash TEXT NOT NULL COLLATE NOCASE DEFAULT '', + err_msg TEXT DEFAULT '', UNIQUE(book, format) ); diff --git a/resources/metadata_sqlite.sql b/resources/metadata_sqlite.sql index f7190ba588..aa7e04c2ad 100644 --- a/resources/metadata_sqlite.sql +++ b/resources/metadata_sqlite.sql @@ -1,7 +1,7 @@ CREATE TABLE authors ( id INTEGER PRIMARY KEY, name TEXT NOT NULL COLLATE NOCASE, sort TEXT COLLATE NOCASE, - link TEXT NOT NULL DEFAULT "", + link TEXT NOT NULL DEFAULT '', UNIQUE(name) ); CREATE TABLE books ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -11,13 +11,13 @@ CREATE TABLE books ( id INTEGER PRIMARY KEY AUTOINCREMENT, pubdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP, series_index REAL NOT NULL DEFAULT 1.0, author_sort TEXT COLLATE NOCASE, - isbn TEXT DEFAULT "" COLLATE NOCASE, - lccn TEXT DEFAULT "" COLLATE NOCASE, - path TEXT NOT NULL DEFAULT "", + isbn TEXT DEFAULT '' COLLATE NOCASE, + lccn TEXT DEFAULT '' COLLATE NOCASE, + path TEXT NOT NULL DEFAULT '', flags INTEGER NOT NULL DEFAULT 1, uuid TEXT, has_cover BOOL DEFAULT 0, - last_modified TIMESTAMP NOT NULL DEFAULT "2000-01-01 00:00:00+00:00"); + last_modified TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00+00:00'); CREATE TABLE books_authors_link ( id INTEGER PRIMARY KEY, book INTEGER NOT NULL, author INTEGER NOT NULL, @@ -72,7 +72,7 @@ CREATE TABLE custom_columns ( datatype TEXT NOT NULL, mark_for_delete BOOL DEFAULT 0 NOT NULL, editable BOOL DEFAULT 1 NOT NULL, - display TEXT DEFAULT "{}" NOT NULL, + display TEXT DEFAULT '{}' NOT NULL, is_multiple BOOL DEFAULT 0 NOT NULL, normalized BOOL NOT NULL, UNIQUE(label) @@ -91,7 +91,7 @@ CREATE TABLE feeds ( id INTEGER PRIMARY KEY, ); CREATE TABLE identifiers ( id INTEGER PRIMARY KEY, book INTEGER NOT NULL, - type TEXT NOT NULL DEFAULT "isbn" COLLATE NOCASE, + type TEXT NOT NULL DEFAULT 'isbn' COLLATE NOCASE, val TEXT NOT NULL COLLATE NOCASE, UNIQUE(book, type) ); @@ -151,7 +151,7 @@ CREATE TABLE annotations ( id INTEGER PRIMARY KEY, annot_id TEXT NOT NULL, annot_type TEXT NOT NULL, annot_data TEXT NOT NULL, - searchable_text TEXT NOT NULL DEFAULT "", + searchable_text TEXT NOT NULL DEFAULT '', UNIQUE(book, user_type, user, format, annot_type, annot_id) ); diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index 4e6bd479de..ffc13cfb30 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -162,7 +162,7 @@ class DBPrefs(dict): # {{{ data = json.dumps(self, indent=2, default=to_json) if not isinstance(data, bytes): data = data.encode('utf-8') - with open(to_filename, "wb") as f: + with open(to_filename, 'wb') as f: f.write(data) except: import traceback @@ -172,7 +172,7 @@ class DBPrefs(dict): # {{{ def read_serialized(cls, library_path, recreate_prefs=False): from_filename = os.path.join(library_path, 'metadata_db_prefs_backup.json') - with open(from_filename, "rb") as f: + with open(from_filename, 'rb') as f: return json.load(f, object_hook=from_json) # }}} @@ -1531,8 +1531,8 @@ class DB: path = os.path.abspath(os.path.join(self.library_path, path, 'cover.jpg')) if windows_atomic_move is not None: if not isinstance(dest, string_or_bytes): - raise Exception("Error, you must pass the dest as a path when" - " using windows_atomic_move") + raise Exception('Error, you must pass the dest as a path when' + ' using windows_atomic_move') if os.access(path, os.R_OK) and dest and not samefile(dest, path): windows_atomic_move.copy_path_to(path, dest) return True @@ -1638,8 +1638,8 @@ class DB: return False if windows_atomic_move is not None: if not isinstance(dest, string_or_bytes): - raise Exception("Error, you must pass the dest as a path when" - " using windows_atomic_move") + raise Exception('Error, you must pass the dest as a path when' + ' using windows_atomic_move') if dest: if samefile(dest, path): # Ensure that the file has the same case as dest @@ -1919,11 +1919,11 @@ class DB: text = 'annotations.searchable_text' if highlight_start is not None and highlight_end is not None: if snippet_size is not None: - text = 'snippet({fts_table}, 0, "{highlight_start}", "{highlight_end}", "…", {snippet_size})'.format( + text = "snippet({fts_table}, 0, '{highlight_start}', '{highlight_end}', '…', {snippet_size})".format( fts_table=fts_table, highlight_start=highlight_start, highlight_end=highlight_end, snippet_size=max(1, min(snippet_size, 64))) else: - text = f'highlight({fts_table}, 0, "{highlight_start}", "{highlight_end}")' + text = f"highlight({fts_table}, 0, '{highlight_start}', '{highlight_end}')" query = 'SELECT {0}.id, {0}.book, {0}.format, {0}.user_type, {0}.user, {0}.annot_data, {1} FROM {0} ' query = query.format('annotations', text) query += ' JOIN {fts_table} ON annotations.id = {fts_table}.rowid'.format(fts_table=fts_table) @@ -1994,7 +1994,7 @@ class DB: new_annot['title'] = annot_data['title'] replacements.append((json.dumps(new_annot), timestamp, annot_id)) if replacements: - self.executemany('UPDATE annotations SET annot_data=?, timestamp=?, searchable_text="" WHERE id=?', replacements) + self.executemany("UPDATE annotations SET annot_data=?, timestamp=?, searchable_text='' WHERE id=?", replacements) if removals: self.executemany('DELETE FROM annotations WHERE id=?', removals) @@ -2085,7 +2085,7 @@ class DB: def annotation_count_for_book(self, book_id): for (count,) in self.execute(''' SELECT count(id) FROM annotations - WHERE book=? AND json_extract(annot_data, "$.removed") IS NULL + WHERE book=? AND json_extract(annot_data, '$.removed') IS NULL ''', (book_id,)): return count return 0 diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index a91a99930c..2ef2f5d449 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -943,7 +943,7 @@ class Cache: # We can't clear the composite caches because a read lock is set. # As a consequence the value of a composite column that calls # virtual_libraries() might be wrong. Oh well. Log and keep running. - print("Couldn't get write lock after vls_for_books_cache was loaded", file=sys.stderr) + print('Couldn\'t get write lock after vls_for_books_cache was loaded', file=sys.stderr) traceback.print_exc() if get_cover: diff --git a/src/calibre/db/fts/connect.py b/src/calibre/db/fts/connect.py index 9ea3d5c35a..c7b6b9ce2e 100644 --- a/src/calibre/db/fts/connect.py +++ b/src/calibre/db/fts/connect.py @@ -39,7 +39,7 @@ class FTS: if conn.fts_dbpath is None: main_db_path = os.path.abspath(conn.db_filename('main')) dbpath = os.path.join(os.path.dirname(main_db_path), 'full-text-search.db') - conn.execute(f'ATTACH DATABASE "{dbpath}" AS fts_db') + conn.execute(f"ATTACH DATABASE '{dbpath}' AS fts_db") SchemaUpgrade(conn) conn.execute('UPDATE fts_db.dirtied_formats SET in_progress=FALSE WHERE in_progress=TRUE') num_dirty = conn.get('''SELECT COUNT(*) from fts_db.dirtied_formats''')[0][0] @@ -160,9 +160,9 @@ class FTS: text = 'books_text.searchable_text' if highlight_start is not None and highlight_end is not None: if snippet_size is not None: - text = f'snippet("{fts_table}", 0, "{highlight_start}", "{highlight_end}", "…", {max(1, min(snippet_size, 64))})' + text = f'''snippet("{fts_table}", 0, '{highlight_start}', '{highlight_end}', '…', {max(1, min(snippet_size, 64))})''' else: - text = f'highlight("{fts_table}", 0, "{highlight_start}", "{highlight_end}")' + text = f'''highlight("{fts_table}", 0, '{highlight_start}', '{highlight_end}')''' text = ', ' + text else: text = ''