2010-08-26 45 views
4

elisp是否有SQLite包装?SQLite和elisp?

如果不是,调用通过启动进程控制SQLite的python代码是个好主意吗?有没有更好的方法从elisp使用SQLite?

回答

6

Trey Jackson的起始链接,似乎有一个关于如何编写构建a programmatic interface for elisp to an inferior-process sqlite的教程,例如, sqlite-query<f>。它基于屏幕抓取comint buffer仅用于此目的(例如,不重复使用sql.el)。以下是从该参考复制的不完整示例。

;; 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)))) 

不幸的看起来不像有什么现成的架子在那里,但也许it is a good approach,或许比他们试图用另一种中间语言更好。

(之外,我发现连接源码与emacs的窗口小部件的图形用户界面是有趣的实施例。)

+2

我写了一个[为Emacs Lisp的小SQLite的包装(http://www.jasonfruit.com/ page/emacs_sqlite_and_widgets)来响应这里的代码。 – JasonFruit 2012-01-12 13:57:59

6

Emacs wiki是你的朋友,有几个链接到几个sqlite的工具。

Emacs WIki SQLite,第一个链接可能是您要查找的链接:处理与数据库的交互:sql-mode