![]() |
#1 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,646
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Question on editing database directly
I accidentally erased timestamps of a few books while working in Calibre. No big deal:
1. Close Calibre. 2. Grab latest db backup open in SQLiteStudio. 3. Go to books table, find book, copy timestamp column. 4. Go to my library db. Paste the timestamp into same book. 5. Commit. I've done this before with custom column, never directly on books column. It didn't work this time. SQLIteStudio reported on commit: [11:19:09] An error occurred while committing the data: no such function: title_sort What does this mean? I can restore the date through GUI, will lose exact timestamp info though. Last edited by ownedbycats; 03-15-2025 at 10:25 AM. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Several tables, including books, use sqlite triggers that ensure the data written to the table are correctly processed. The triggers reference functions in calibre's db layer, for example title_sort(). This is why using SQL browsers to modify the db often doesn't work. The only safe way to do it is by using calibre's API via a python script run with calibre-debug or via a python template.
|
![]() |
![]() |
![]() |
#3 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,646
Karma: 74166147
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Ah, that makes sense. For future, is there a way to edit the time part of date column directly, aside from maybe changing the column format?
|
![]() |
![]() |
![]() |
#4 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Here is a template that changes the date (timestamp) to whatever you put in line 9. Be sure to get an example so the timezone is correct. Code:
python: def evaluate(book, context): db = context.db.new_api # Get the current timestamp. v = db.field_for('timestamp', book.id) print(1, v) # The corrected timespamp goes here db.set_field('timestamp', {book.id: '2023-06-23 09:36:34+00:00'}) # See if the timestamp changed. v = db.field_for('timestamp', book.id) print(2, v) # return the new timestamp return str(v) |
|
![]() |
![]() |
![]() |
#5 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,185
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
|
If you have multiple books and don't want to enter the value manually for each, another solution would be like this:
Notes:
Edit: An earlier version of this post was deleted, because I realized after posting that I needed to check some things in calibre, which I did not available at the time. Sorry to the mods for the inconvenience. Edit2: Instead of using sql viewer to export to csv, it is better to open the backup library with calibre itself and use the catalog function to export to csv. Last edited by capink; 03-17-2025 at 09:45 AM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Newbie question: download epubs directly from the internet into koreader | camifran | KOReader | 2 | 02-26-2017 02:19 PM |
[Android] Can any app directly read the Calibre database? | SoulkeepHL | Devices | 2 | 01-10-2013 08:21 PM |
manually editing database | teje | Calibre | 9 | 02-05-2010 02:11 AM |
question/suggestion: convert directly and make importing of sourcefile optional | dura | Calibre | 0 | 09-09-2009 06:05 AM |
japi - a text editor capable of editing ePub directly | hekkel | ePub | 5 | 02-20-2009 08:46 AM |