Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 01-03-2025, 09:35 AM   #1
d4em
Junior Member
d4em began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jan 2025
Device: None
Update custom column value

I have this code:

Code:
book_ids = self.gui.library_view.get_selected_ids()
        db = self.gui.current_db.new_api

        for book_id in book_ids:
            book = db.format_abspath(book_id, "txt") # This method breaks thread-safe promise of API, fix later
            metadata = db.get_metadata(book_id)
I need to edit one of the columns for these books. I tried the add_custom_book_data(name, val_map, delete_first=False) method in the db class, but I do not know what datatype it wants when it asks for a val_map.

How do I change the value of a column?
d4em is offline   Reply With Quote
Old 01-03-2025, 12:21 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,330
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Use
Code:
set_field(self, name, book_id_to_val_map, allow_case_change=True, do_path_update=True)
        '''
        Set the values of the field specified by ``name``. Returns the set of all book ids that were affected by the change.

        :param book_id_to_val_map: Mapping of book_ids to values that should be applied.
        :param allow_case_change: If True, the case of many-one or many-many fields will be changed.
            For example, if a  book has the tag ``tag1`` and you set the tag for another book to ``Tag1``
            then the both books will have the tag ``Tag1`` if allow_case_change is True, otherwise they will
            both have the tag ``tag1``.
        :param do_path_update: Used internally, you should never change it.
        '''
in cache.py (new_api)
chaley is offline   Reply With Quote
Advert
Old 01-03-2025, 12:50 PM   #3
d4em
Junior Member
d4em began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jan 2025
Device: None
I got it to work, thanks!
Turns out the val_map is just a dictionary with book ids as key
d4em is offline   Reply With Quote
Old 01-03-2025, 01:13 PM   #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,330
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
BTW: add_custom_book_data() does not update custom columns. Instead it updates a look-aside table that plugins can use to store information about books.
chaley is offline   Reply With Quote
Old Today, 07:13 AM   #5
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 6,595
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
Quote:
Originally Posted by chaley View Post
BTW: add_custom_book_data() does not update custom columns. Instead it updates a look-aside table that plugins can use to store information about books.
How do you update custom columns then? (name is tricky)
Terisa de morgan is offline   Reply With Quote
Advert
Old Today, 07:20 AM   #6
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,330
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Terisa de morgan View Post
How do you update custom columns then? (name is tricky)
"Custom book data" isn't custom columns. It is a persistent map of keys to values, intended for plugins to store extra book information pertinent to that plugin. For example, a plugin might want to store some extra dates about a book that the plugin will need later. It can use add_custom_book_data() to store this information.

If you want to update custom columns then use db.new_api.set_field().

Last edited by chaley; Today at 08:15 AM. Reason: spelling
chaley is offline   Reply With Quote
Old Today, 07:31 AM   #7
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 6,595
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
Quote:
Originally Posted by chaley View Post
"Custom book data" isn't custom columns. It is a persustent map of keys to values, intended for plugins to store extra book information pertinent to that plugin. For example, a plugin might want to store some extra dates about a book that the plugin will need later. It can use add_custom_book_data() to store this information.

If you want to update custom columns then use db.new_api.set_field().
Yes, thank you. I've seen it later. I'm using that function in one of my plugins (obviously wrong and I was mislead). After using set_field it's working.
Terisa de morgan is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using RE to extract pattern from custom column into another custom column activedirectory Library Management 1 12-15-2019 08:07 PM
Adding custom column with any lookup-name gives me empty column as a result? Ahu Lee Library Management 16 06-09-2019 12:14 PM
Move selected data from series column to a new custom column fvdham Library Management 3 06-02-2017 03:49 PM
Custom column returns value based on value of another custom column? calvin-c Calibre 3 09-14-2013 02:24 PM
Update custom column's content? Pepin33 Development 1 08-18-2012 02:16 PM


All times are GMT -4. The time now is 10:00 AM.


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