是否有适用于elisp的SQLite封装程序?
如果没有,调用控制SQLite的python代码通过start-process或其他方式是否是个好主意?还有更好的方法可以从elisp中使用SQLite吗?
从Trey Jackson的起始链接开始,似乎有一个教程,讲述如何构建一个面向elisp的程序接口,连接到sqlite进程,例如sqlite-query<f>
。它基于仅为此目的(即不重用sql.el)而对一个comint缓冲区进行屏幕抓取。以下是从该参考文献中复制的不完整示例。
;; this is emacs lisp code
(defun sqlite-query ( sql-command )
(set-buffer sqlite-output-buffer) ;1
(erase-buffer) ;2
(comint-redirect-send-command-to-process
sql-command
sqlite-output-buffer
(get-buffer-process sqlite-process-buffer) nil) ;3
(accept-process-output
(get-buffer-process sqlite-process-buffer)
1) ;need to wait to obtain results
(let* ((begin (goto-char (point-min))) ;4
(end (goto-char (point-max)))
(num-lines (count-lines begin end))
(counter 0)
(results-rows ()))
(goto-char (point-min))
(while ( < counter num-lines)
(setq results-rows (cons (chomp (thing-at-point 'line)) results-rows))
(forward-line)
(setq counter (+ 1 counter)))
(car `(,results-rows))))
很遗憾,似乎没有现成的解决方案,但也许这是一个不错的方法,可能比尝试使用另一种中间语言更好。
(顺便说一下,我发现将sqlite与emacs的Widget GUI界面连接在一起的示例非常有趣。)
Emacs Wiki是你的好朋友,那里有几个与SQLite相关的工具链接。
Emacs Wiki SQLite中第一个链接可能是你要找的:处理与数据库的交互:sql-mode。