chenyanming / calibredb.el

Emacs calibre client - An Ebook Management Solution in Emacs.
GNU General Public License v3.0
318 stars 16 forks source link

Invalid library #44

Closed c1-g closed 3 years ago

c1-g commented 3 years ago

Here's the configuration

(use-package calibredb
  :straight t
  :config
  (setq calibredb-root-dir "/storage/library")
  (setq calibredb-db-dir (expand-file-name "metadata.db" calibredb-root-dir))
  (setq calibredb-ref-default-bibliography (concat (file-name-as-directory calibredb-root-dir) "muhbib.bib")))

And after reading through other people's closed issues of the same problem, I've tried theses suggestion from you, here are the results

  1. Did you try to use calibre to generate an empty library and read by calibredb.el? If it is ok, maybe your metadata was broken.

The new library still gets INVALID LIBRARY error.

  1. If it still not ok, try to find that if .sqliterc is existed or not? Try to delete .sqliterc and try again. Post the content of .sqliterc here.

There is no .sqliterc in my home directory

  1. If it still no ok, post your calibre version and sqlite version. I will check if the version problems.

My Calibre is on 5.14.0_1 and my sqlite is on 3.35.5

My operating system is FreeBSD 13.0.

My sql-sqlite-program is "/usr/local/bin/sqlite3" and my calibredb-program is "calibredb".

Here's my metadata.db just in case, metadata.db.gz

chenyanming commented 3 years ago

The database you attached is working alright. image Would you set calibredb-program in full path, for example:

(setq calibredb-program "/Applications/calibre.app/Contents/MacOS/calibredb")
chenyanming commented 3 years ago

Did you setup calibredb-library-alist?

c1-g commented 3 years ago

Okay, here's my current configuration,

(use-package calibredb
  :straight t
  :config
  (setq calibredb-program (executable-find "calibredb"))
  (setq calibredb-root-dir "/storage/library/")
  (setq calibredb-library-alist '(("/storage/library/")))
  (setq calibredb-db-dir (expand-file-name "metadata.db" calibredb-root-dir))
  (setq calibredb-ref-default-bibliography (concat (file-name-as-directory calibredb-root-dir) "muhbib.bib")))

Now my calibredb-program is "/usr/local/bin/calibredb"

Still INVALID LIBRARY

chenyanming commented 3 years ago

Would you run (calibredb-candidates) to check the if all book results show or not? Or (calibredb-candidate 1) to check the id = 1 book record (change the id number if the metadata.db does not have id = 1 record).

For example, if I call (calibredb-candidate 1), I can get the following result

((#(" How to Write Effective Requirements for IT - Simply Put!: Use Four Sim mobi     2020-12-27  Hathaway, Thomas & Hathaway, Angela (worldheflefjdlfj)   1.80Mb" 0 1
    (rear-nonsticky t display
                    (raise 0.0)
                    font-lock-face
                    (:family "FontAwesome" :height 1.2 :inherit all-the-icons-dsilver)
                    face
                    (:family "FontAwesome" :height 1.2 :inherit all-the-icons-dsilver))
    2 72
    (face calibredb-title-face)
    73 81
    (keymap
     (keymap
      (mouse-1 . calibredb-format-mouse-1))
     help-echo "Filter with this format" mouse-face calibredb-mouse-face face calibredb-format-face)
    82 93
    (keymap
     (keymap
      (mouse-1 . calibredb-date-mouse-1))
     help-echo "Filter with this date" mouse-face calibredb-mouse-face face calibredb-date-face)
    94 102
    (keymap
     (keymap
      (mouse-1 . calibredb-author-mouse-1))
     help-echo "Filter with this author: Hathaway" mouse-face calibredb-mouse-face face calibredb-author-face author "Hathaway")
    103 121
    (keymap
     (keymap
      (mouse-1 . calibredb-author-mouse-1))
     help-echo "Filter with this author:  Thomas & Hathaway" mouse-face calibredb-mouse-face face calibredb-author-face author " Thomas & Hathaway")
    122 129
    (keymap
     (keymap
      (mouse-1 . calibredb-author-mouse-1))
     help-echo "Filter with this author:  Angela" mouse-face calibredb-mouse-face face calibredb-author-face author " Angela")
    131 147
    (keymap
     (keymap
      (mouse-1 . calibredb-tag-mouse-1))
     help-echo "Filter with this tag: worldheflefjdlfj" mouse-face calibredb-mouse-face face calibredb-tag-face tag "worldheflefjdlfj")
    151 155
    (face calibredb-size-face)
    155 157
    (face calibredb-size-face))
  ((:id "1")
   (:author-sort "Hathaway, Thomas & Hathaway, Angela")
   (:book-dir "Thomas Hathaway/How to Write Effective Requirements for IT - Simply Put!_ Use Four Simple Rules to Improve the Q (1)")
   (:book-name "How to Write Effective Requirements for IT - Thomas Hathaway")
   (:book-format "mobi")
   (:book-pubdate "2016-09-02 16:00:00+00:00")
   (:book-title "How to Write Effective Requirements for IT - Simply Put!: Use Four Simple Rules to Improve the Quality of Your IT Requirements (Business Analysis Fundamentals - Simply Put! Book 2)")
   (:file-path "~/OneDrive/Org/Doc/Calibre/Thomas Hathaway/How to Write Effective Requirements for IT - Simply Put!_ Use Four Simple Rules to Improve the Q (1)/How to Write Effective Requirements for IT - Thomas Hathaway.mobi")
   (:tag "worldheflefjdlfj")
   (:size "1.80")
   (:comment "Use 4 Simple Rules to Write Effective Requirements! Failure rates of projects suffering from poor requirements are still astronomical. Don’t allow your project to become another casualty. The techniques presented in this book will help anyone, regardless of job title or role, to communicate their future needs to others. “How to Write Requirements for IT - Simply Put!” also includes optional exercises with instant feedback to increase retention.")
   (:ids "mobi-asin:ad9b50e1-33b9-42fd-bada-505a1225755e")
   (:publisher "BA-EXPERTS")
   (:series "")
   (:lang_code "eng")
   (:last_modified "2020-12-27 13:27:38.379853+00:00"))))

calibredb-candidate simply run SELECT * FROM 'calibredb-query-string' WHERE id = 1 on metadata.db with calibredb-query-string and splite the column with calibredb-sql-separator. If this can not be run, that may have some problems on the sqlite. Try to change calibredb-sql-separator to other separator character.

c1-g commented 3 years ago

Hi, After I evaluated (calibredb-candidates) and (calibredb-candidate 1), both of them results in a nil. When I looked at the backtrace of calibredb-candidates, I found that the query-result part is a string "Unmatched '\"'.\nToo many ('s.\nSELECT: Command not found.\nFROM: Command not found.\nToo many )'s.\nBadly placed ()'s.\nFROM: Command not found.\nLEFT: Command not found.\nON: Command not found.\nGROUP: Command not found.\nToo many )'s.\nSELECT: Command not found.\nFROM: Command not found.\nLEFT: Command not found.\nON: Command not found.\nToo many )'s.\nSELECT: Command not found.\nFROM: Command not found.\nLEFT: Command not found.\nON: Command not found.\nToo many )'s.\nSELECT: Command not found.\nFROM: Command not found.\nLEFT: Command not found.\nON: Command not found.\nToo many )'s.\nSELECT: Command not found.\nFROM: Command not found.\nToo many )'s.\nBadly placed ()'s.\nFROM: Command not found.\nLEFT: Command not found.\nON: Command not found.\nLEFT: Command not found.\nON: Command not found.\nLEFT: Command not found.\nON: Command not found.\nLEFT: Command not found.\nON: Command not found.\nLEFT: Command not found.\nON: Command not found.\nLEFT: Command not found.\nON: Command not found.\nLEFT: Command not found.\nON: Command not found.\nUnmatched '\"'.\n" I guess this is an unexpected behavior. Is it a sqlite problem?

Edit: I run SELECT * FROM books; on my metadata.db and it works just fine so I think the problem is in the calibredb-query-string

c1-g commented 3 years ago

calibredb-query-string is fine. I fixed the issue by editing the code of calibredb-query to this,

(defun calibredb-query (sql-query)
  "Query calibre databse and return the result.
Argument SQL-QUERY is the sqlite sql query string."
  (interactive)
  (if (file-exists-p calibredb-db-dir)
    (shell-command-to-string
       (format "%s -list -noheader %s -init %s"
               sql-sqlite-program
               (shell-quote-argument (expand-file-name calibredb-db-dir))
               (make-temp-file "calibredb-query-string" nil nil sql-query))) nil))

Omitting the -separator and -nullvalue option in the shell command because the default just works and, dump the SQL statements in a temporary file then call it with the -init option to avoid using quotes. I guess that my FreeBSD's csh shell has a bit of a compatibility issue. Also, I set my calibredb-sql-newline to "\n" and calibredb-sql-separator to "|".