Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 03-15-2025, 10:20 AM   #1
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
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.
ownedbycats is offline   Reply With Quote
Old 03-15-2025, 03:14 PM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
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.
chaley is offline   Reply With Quote
Old 03-16-2025, 07:02 AM   #3
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
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?
ownedbycats is offline   Reply With Quote
Old 03-16-2025, 07:30 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,327
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
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?
Not that I can think of. Perhaps an SFE in action chains along with some dialog to capture the date.

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)
chaley is offline   Reply With Quote
Old 03-16-2025, 10:38 AM   #5
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
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:
  1. In your SQL Viewer/Editor export the data you want to csv. If your SQL Editor does not support exporting to csv, look for another one in google.
  2. Use the Import List plugin to import the timestamps. Import List does not support importing to the original timestamps field, so you will have to import into a custom date column.
  3. Use Action Chains SFE template to copy the timestamps from you custom column.

Notes:
  • For your custom date column, use the iso format. It guarantees parse_date is not confused between months and days, it also includes times and time zone.
  • Import List can match books using uuid. So make sure to choose that for matching books.
  • If you use this method for copying values FROM custom columns, you will find the resulting csv file without the uuid field. In which case you will have to also export the books table to another csv file, and link them using VLOOKUP in excel.
  • You only need to do steps 2 and 3 if you are importing into timestamps. Since Import List supports all other columns, you can directly import into them, with caveat mentioned above for custom columns.

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.
capink is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 01:46 AM.


MobileRead.com is a privately owned, operated and funded community.