emacs-db icon indicating copy to clipboard operation
emacs-db copied to clipboard

db-hash/save does not create the .elc file

Open spiderbit opened this issue 8 years ago • 2 comments

I did debug it a bit, but for me it never created the .elc file to save the data, it created the .el file, so if I comment out the part where it deletes the .elc file, it works, but it does not create the elc file.

have to digg deeper again to give you more details.

spiderbit avatar Nov 06 '16 18:11 spiderbit

so I wrote/copy-pasted a small sample code

(require 'db)
(defvar my-db 
  (db-make 
   `(db-hash 
     :filename ,(format "/tmp/dbtest1"))))

(db-hash-put "001" '(("a" . 10)("b" . 20)) my-db)

(db-hash/save my-db)

the byte-compile part throughs following error:

dbtest1.el:1:1:Error: Odd number of elements in hashtable data

uncommented the following line to see why it cant byte-compile ;; (delete-file (concat filename ".el"))

(throw 'return #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 
data("001" (("a" . 10) ("b" . 20)) ...)))

if I remove the 3 ... it compiles fine:

(throw 'return #s(hash-table size 65 test equal rehash-size 1.5 rehash-threshold 0.8 
data ("001" (("a" . 10) ("b" . 20)))))

spiderbit avatar Nov 06 '16 19:11 spiderbit

Well, I wrote a quick and dirty hack/patch by modifying the save function:

(require 's)
...
(defun db-hash/save (db)
...
(let ((fmt-obj (format
                          "(throw 'return %S)"
                          (plist-get db :db))))
            (insert (s-replace "..." "" fmt-obj)))

which seem to work, no good solution but I dont want to digg into the c function plist-get

testet with that code:

(require 'db)
(defvar my-db
  (db-make 
   `(db-hash 
     :filename ,(format "/tmp/dbtest3"))))

(db-put "001" '(("a" . 10)("b" . 20)) my-db)
(db-put "002" '(("a" . 20)("b" . 30)) my-db)

(db-hash/save my-db)

(defvar my-db2
  (db-make 
   `(db-hash 
     :filename ,(format "/tmp/dbtest3"))))

(db-get "002" my-db2) 

output:

(("a" . 20) ("b" . 30))

spiderbit avatar Nov 06 '16 21:11 spiderbit