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 02-02-2021, 12:42 PM   #1
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
Export books with tags with SQL

Hello

And first of all thank you for this extraordinary software that is Calibre.

It's probably very simple, but my knowledge in SQL being limited, I'm looking for the query to export a book with all its tags.

Thanks in advance.
Nicolas.Laurent is offline   Reply With Quote
Old 02-02-2021, 03:44 PM   #2
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,642
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Not sure why you think you need to use SQL to save a book.

The Preferences->Save to Disk settings are used to define what gets saved, check the Update metadata in saved copies to put the tags etc into the saved format file(s).

Then use one of the Save to Disk options to save the book to the selected location.

BR
BetterRed is offline   Reply With Quote
Advert
Old 02-02-2021, 04:22 PM   #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,726
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Could they be using calibredb rather than the GUI? I don't mess around much with the cmdline tools myself, so I'm not sure.
ownedbycats is offline   Reply With Quote
Old 02-02-2021, 08:33 PM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,914
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Calibre has 2 main parts per book:
1) the DB entry (actually many pieces: as it is a relational DB)
2) The books format(s) just stored in the file system
The DB entry contains a PATH to the book as well as lots of metadata.

Ownedbycats is referring to the command line tools, that can be used to perform tasks.(see the online help) No need to know SQL as all the tools do the needed lifting (without risking library integrity).
theducks is offline   Reply With Quote
Old 02-03-2021, 03:14 AM   #5
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
Quote:
Originally Posted by Nicolas.Laurent View Post
Hello

And first of all thank you for this extraordinary software that is Calibre.

It's probably very simple, but my knowledge in SQL being limited, I'm looking for the query to export a book with all its tags.

Thanks in advance.

Sorry, I wasn't clear.
What I want is to export the book's metadata, not save it. And I want to do it with an SQL query on the db database because it takes a lot of time to do it from Calibre considering the size of my library (more than 100,000 books).
Nicolas.Laurent is offline   Reply With Quote
Advert
Old 02-03-2021, 03:36 AM   #6
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,642
Karma: 29710510
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Not sure if using SQL against the database file would be any faster than exporting a CSV catalog from the calibre GUI (you may need to add the Create Catalog tool to a Toolbar or menu), or via the calibredb list command ==>> The Command Line Interface

The database is loaded into memory when calibre is running.

However if you're determined to use SQL direct, I would suggest you copy the metadata.db file at the root of the library, and use something like DB Browser for SQLite to do queries against it to export CSV, HTML etc. You'll need to spend a few minutes examining the schema but its fairly straightforward.

BR
BetterRed is offline   Reply With Quote
Old 02-03-2021, 03:41 AM   #7
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,726
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by BetterRed View Post
However if you're determined to use SQL direct, I would suggest you copy the metadata.db file at the root of the library, and use something like DB Browser for SQLite to do queries against it to export CSV, HTML etc. You'll need to spend a few minutes examining the schema but its fairly straightforward.

BR
My software of choice is SQLiteStudio.
ownedbycats is offline   Reply With Quote
Old 02-04-2021, 08:06 AM   #8
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
Quote:
Originally Posted by ownedbycats View Post
My software of choice is SQLiteStudio.
I also use SQLiteStudio

And my question is what is the query to export ALL the tags. I use this one and it doesn't work.

SELECT id,
author_sort,
title,
(SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher,
(SELECT format FROM data WHERE data.book=books.id) formats,
path,
(SELECT name FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags
FROM books
Nicolas.Laurent is offline   Reply With Quote
Old 02-04-2021, 09:47 AM   #9
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,345
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by Nicolas.Laurent View Post
I also use SQLiteStudio

And my question is what is the query to export ALL the tags. I use this one and it doesn't work.

SELECT id,
author_sort,
title,
(SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher,
(SELECT format FROM data WHERE data.book=books.id) formats,
path,
(SELECT name FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags
FROM books
I really don't see why you want to use SQL unless simply as a learning experience. A CSV catalog gives you the same information, except the path, with no hassle at all. Example attached.
Attached Thumbnails
Click image for larger version

Name:	Clipboard01.jpg
Views:	112
Size:	38.2 KB
ID:	185227  
chaley is offline   Reply With Quote
Old 02-04-2021, 11:24 AM   #10
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,345
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
BTW, the reason your SQL doesn't work is that some of the subqueries return multiple rows. You only see the first one. To see all of them you need to use group_concat(), like this:
Code:
SELECT
    id,
    author_sort,
    title,
    (SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher,
    (SELECT group_concat(format) FROM data WHERE data.book=books.id) formats,
    path,
    (SELECT group_concat(name) FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags
FROM books
chaley is offline   Reply With Quote
Old 02-05-2021, 05:39 AM   #11
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
Quote:
Originally Posted by chaley View Post
BTW, the reason your SQL doesn't work is that some of the subqueries return multiple rows. You only see the first one. To see all of them you need to use group_concat(), like this:
Code:
SELECT
    id,
    author_sort,
    title,
    (SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher,
    (SELECT group_concat(format) FROM data WHERE data.book=books.id) formats,
    path,
    (SELECT group_concat(name) FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags
FROM books
you are a genius (which you probably already knew)!
The query works perfectly
Thanks again for your help.
Nicolas.Laurent is offline   Reply With Quote
Old 02-05-2021, 10:27 AM   #12
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,914
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by Nicolas.Laurent View Post
you are a genius (which you probably already knew)!
The query works perfectly
Thanks again for your help.
Charles is one of the longer time contributing developers.
https://calibre-ebook.com/about#contributors
(and yes!, he is brilliant)
theducks is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you export a list of tags? bhagerty Library Management 17 12-14-2022 04:00 PM
Where are the tags on export to the file system? halloleo Library Management 3 03-24-2020 10:56 PM
SQL error attempting to remove books from library Aelbfled Calibre 1 12-30-2017 10:49 AM
Export tags Daedalus.p1 Calibre 4 02-25-2013 04:15 PM


All times are GMT -4. The time now is 03:54 AM.


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