2010-08-26 47 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