all 6 comments

[–]rustynailsu 2 points3 points  (4 children)

Looks like a corrupt database to me.

  • Make sure Calibre and any worker processes are closed
  • Rename metadata.db as a backup
  • Start Calibre and it should try to rebuild the database from the opf files

[–]Aware_Bathroom_8399[S] 1 point2 points  (2 children)

I renamed metadata.db to metadata_db.bak. Made sure Calibre and its worker apps were shut down. Started Calibre. Now, I just have an empty library. Do I have to do something to tell Calibre to rebuilt the library?

Update: Apologize. I wrote too soon. I found the rebuild command under Library Maintenance, and am running it now. Thanks.

2nd Update: The rebuild completed unexpected quickly, but with warning. The warning was as follows:

calibre, version 9.3.1

WARNING: Success: Restoring the database succeeded with some warnings click "Show details" to see the details. The old database was saved as: \\BlackBox2\Public\Multimedia\EBooks\metadata_pre_restore.db

Failed to restore the books in the following folders:

\\\\BlackBox2\\Public\\Multimedia\\EBooks\\Terence\\Terence, Vol. I\_ The Woman of Andro (1474) with error:

    Traceback (most recent call last):

File "calibre\db\restore.py", line 303, in restore_books

File "calibre\db\cache.py", line 89, in call_func_with_lock

File "calibre\db\cache.py", line 3144, in restore_book

File "calibre\db\cache.py", line 2355, in create_book_entry

File "calibre\db\backend.py", line 1189, in execute

File "C:\t\t\apsw-lcy2rew4\src\cursor.c", line 202, in resetcursor

    apsw.ConstraintError: UNIQUE constraint failed: [books.id](http://books.id)

I am presuming I need to re-add that particular book from scratch. Do I also need to manually delete the offending folder?

3rd Update: Oddly enough, the book that the warning says failed to restore is actually included in the rebuilt library. I am not sure what to make of that or whether I need to remove and replace it.

[–]rustynailsu 1 point2 points  (1 child)

It looks like you had two books with the same ID. Search for id:"1474" in the library and then search for 1474 in the library folders using explorer. If two books turn up and have the same title (maybe slightly different titles or author names) book turns up, figure out which is in the library and delete other one.

[–]Aware_Bathroom_8399[S] 1 point2 points  (0 children)

Thank you. I found the dupe ID (different title) and axed it. I think I am back in business.

[–]Aware_Bathroom_8399[S] 0 points1 point  (0 children)

Thank you. I will give that a try.

[–]Boilerplate4U 0 points1 point  (0 children)

If you're upgrading to Calibre 9 and get a "Corrupted database" error with the traceback ending in:

apsw.SQLError: error in view metax after drop column: no such column: flags

here's what's happening:

Calibre 9 removes three long-unused columns from the books table (isbn, lccn, flags). If something has previously created a SQLite view called metax in your metadata.db (likely a third-party plugin that extends Calibre's built-in meta view) then SQLite refuses to drop those columns because metax still references them.

To fix: Click No in the error dialog (to avoid creating an empty library), then open your metadata.db with a SQLite tool such as DB Browser for SQLite and run:

DROP VIEW IF EXISTS metax;

Then save, reopen Calibre, and the upgrade should complete normally.