When attempting to connect a Kobo device to Calibre, the following error may occur:
ERROR: Error: Error communicating with device
CorruptError: database disk image is malformed
Traceback (most recent call last):
File "calibre\gui2\device.py", line 112, in run
File "calibre\gui2\device.py", line 566, in _books
File "calibre\devices\kobo\driver.py", line 2091, in books
File "C:\t\t\apsw-42s16m2x\src\cursor.c", line 240, in resetcursor
apsw.CorruptError: CorruptError: database disk image is malformed
This occurs when the KoboReader.sqlite database is corrupted or contains invalid entries.
-
Open the Database in SQLite Tool:
- Use SQLiteBrowser or another SQLite tool to open the
KoboReader.sqlitedatabase.
- Use SQLiteBrowser or another SQLite tool to open the
-
Export the Database to SQL:
- Use the tool's export functionality:
File > Export > Database to SQL file - This creates a plain-text SQL file that includes the database schema and data.
- Use the tool's export functionality:
-
Inspect and Edit the SQL File:
- Open the exported SQL file in a text editor.
- Look for invalid entries or table definitions. The issue I've encountered was invalid default values, such as:
"WishlistedDate" TEXT DEFAULT 0000-00-00T00:00:00.000, "DateModified" TEXT DEFAULT 0000-00-00T00:00:00.000,
- These values are invalid in SQLite because they lack quotes around the default date values.
-
Fix the SQL File:
- Correct invalid lines by wrapping default values in quotes:
"WishlistedDate" TEXT DEFAULT '0000-00-00T00:00:00.000', "DateModified" TEXT DEFAULT '0000-00-00T00:00:00.000',
- Correct invalid lines by wrapping default values in quotes:
-
Reimport the SQL File:
- In the SQLite tool, create a new database and import the corrected SQL file:
File > Import > Database from SQL file
- In the SQLite tool, create a new database and import the corrected SQL file:
-
Replace the Corrupted Database:
- Replace the original
KoboReader.sqlitefile on the device with the repaired version.
- Replace the original
-
Verify and Test:
- Run
PRAGMA integrity_check;on the new database to confirm it is valid. - Reconnect the Kobo to Calibre and ensure the device is detected correctly.
- Run