View Single Post
Old 09-14-2014, 07:36 PM   #1
Pinguin44
Junior Member
Pinguin44 began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Sep 2014
Device: Kobo Aura
Sql for making a lot of change in Calibre database

Hello,

I know that we can made some change on selected items with a regex but that really take too much time for multiple update. The way for me it's to make multiple change on author, title, publisher, tags as a batch with Sql request.

So i search on this forum and other source on Google but i don't find so many solution. I found one good way here:
https://www.mobileread.com/forums/sho...&highlight=sql

I build a short py script for test:
Code:
from __future__ import (unicode_literals, division, absolute_import,
                        print_function)
from calibre.library.database2 import LibraryDatabase2
db = LibraryDatabase2('/Users/Bernard/Calibre Library Temp')
db.execute('UPDATE authors SET name="Karl Herbert Scheer" WHERE name="KH.SCHEER"')
db.execute('UPDATE authors SET name="Alfred Elton van Vogt" WHERE name="Alfred E. Van Vogt"')
db.execute('UPDATE authors SET name="Alfred Elton van Vogt" WHERE name="AE Van Vogt"')
When i call this script on terminal, i get this:
Code:
iMac-de-xxx:~ Bernard$ calibre-debug -e /Users/Bernard/Desktop/calibre-auto-correct.py 
Python function terminated unexpectedly: 'LibraryDatabase2' object has no attribute 'execute'
Traceback (most recent call last):
  File "/Applications/calibre.app/Contents/Resources/Python/lib/python2.7/site.py", line 208, in main
    return run_entry_point()
  File "/Applications/calibre.app/Contents/Resources/Python/lib/python2.7/site.py", line 114, in run_entry_point
    return getattr(pmod, func)()
  File "site-packages/calibre/debug.py", line 269, in main
  File "site-packages/calibre/debug.py", line 200, in run_script
  File "/Users/Pinguin/Desktop/calibre-auto-correct.py", line 6, in <module>
    db.execute('UPDATE authors SET name="Karl Herbert Scheer" WHERE name="KH.SCHEER"')
AttributeError: 'LibraryDatabase2' object has no attribute 'execute'
iMac-de-xxx:~ Bernard$
Perhaps i miss something somewhere !

Please help me to correct this little py script or give me another working solution to use Sql request with calibre.

Thank you.

Bernard
Pinguin44 is offline   Reply With Quote