Invitation to try sqlite-mode

Hello every body.

I’ve been trying out the sqlite-mode and it is really nice and easy to use, so this post is just an invitation to try it out.

As an example, here is a function that grabs highlighted notes from an ebook reader’s database.

(defun my/sqlite-get-notes ()
 "Get notes from the ebook reader database." 
  (interactive) 
  (let* ((db (sqlite-open "/media/Nook/Mantano/mreader.db"))
	 (titles (and db (sqlite-select
			  db 
			  (format "select title from %s" "note"))))
	 (title (and titles (completing-read "title: " titles))))
    (when db 
      (mapc (lambda (note)
	      (insert (format "%d: %s\n" (car note) (cl-second note ))))
	    (sqlite-select
	     db
	     (format "select page_num, highlight_text from %s where title='%s'" "note" title))))))
2 Likes
 As with the ‘sqlite-execute’, you can optionally pass in a list or
 a vector of values that will be bound before executing the select:

      (sqlite-select db "select * from foo where key = ?" [2])
        ⇒ (("bar" 2))

 This is usually more efficient and safer than the method used by
 the previous example.
1 Like

Thanks!, you are right, that is the proper way to do it ( I’m just starting out using the mode). I looked at the sqlite-mode source and I just followed how it is done there, I have not read the docs yet. I was just surprised how nice the API is, and, since I usually avoid SQL stuff, that was the motivation for the post.

2 Likes