2013-02-06 52 views
1

如你所知calibre有一個叫做metadata.db並提出了SQLite數據庫, 我想從所有書籍查詢與此列:如何從Calibre數據庫查詢?

bookId Title Date Size Rating Tags Publisher PublishedDate Author Cover   
------ ----- ---- ---- ------ ---- --------- ------------- ------ ----- 

但是,該數據庫包含此表:

Books Table 
----------- 
Name 
id 
title 
sort 
timestamp 
pubdate 
series_index 
author_sort 
isbn 
lccn 
path 
flags 
uuid 
has_cover 
last_modified 


Authors Table 
------------- 
Name 
id 
name 
sort 
link 


Publishers Table 
---------------- 
Name 
id 
name 
sort 

他們之間沒有任何關係,我怎麼才能得到我的查詢?

+1

發現這個源代碼(蟒蛇),還有SQL的小片段可能幫助你:http://bazaar.launchpad.net/~kovid/calibre/trunk/view/head:/src/口徑/分貝/ tables.py – booyaa

回答

4
SELECT id, title, 
       (SELECT name FROM books_authors_link AS bal JOIN authors ON(author = authors.id) WHERE book = books.id) authors, 
       (SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher, 
       (SELECT rating FROM ratings WHERE ratings.id IN (SELECT rating from books_ratings_link WHERE book=books.id)) rating, 
       (SELECT MAX(uncompressed_size) FROM data WHERE book=books.id) size, 
       (SELECT name FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags, 
       (SELECT format FROM data WHERE data.book=books.id) formats, 
       isbn, 
       path, 
       pubdate 
     FROM books