2010-03-25 133 views
3

我可以通過做手工連接:如何創建Emacs SQL緩衝區?

的Mx SQL-的Postgres

,並鍵入用戶,數據庫,主機,服務器

我想這樣做:

(連接-foo(用戶 「我」)(數據庫 「巴」)(主機 「大地」))

解決方案迄今:

我抓住了一些C從sql.el中刪除並更改它,以便我可以非交互式地使用它。

(defun sql-create-buffer (profile) 
    "derived from sql-product-interactive in sql.el which is" 
    "covered by GNU General Public License version 3." 

    (setq sql-user  (cdr (assoc 'user profile)) 
     sql-password (cdr (assoc 'password profile)) 
     sql-server (cdr (assoc 'server profile)) 
     sql-database (cdr (assoc 'database profile))) 
    (setq product 'postgres) ;;(cdr (assoc 'product profile))) 
    (when (sql-product-feature :sqli-connect product) 
    (if (comint-check-proc "*SQL*") 
    (pop-to-buffer "*SQL*") 
     ;; Connect to database. 
     (message "Login...") 
     (funcall (sql-product-feature :sqli-connect product)) 
     ;; Set SQLi mode. 
     (setq sql-interactive-product product) 
     (setq sql-buffer (current-buffer)) 
     (sql-interactive-mode) 
     ;; All done. 
     (message "Login...done") 
     (pop-to-buffer sql-buffer)))) 

(setq bar-profile '(
     (product . "postgres") 
     (user  . "me") 
     (password . "") 
     (server . "earth") 
     (database . "bar"))) 

我不知道如何處理'產品'參數,所以我現在就把它硬編碼了。 它是'postgres in sql.el.

(sql-create-buffer bar-profile) 

回答

5

看來,包不打算非交互使用(可能阻止寫的登錄信息到初始化文件,這是一個非常合理的原則)。

但是,如果你真的想避免回答這些問題,你可以簡單地重新定義查詢功能,如:

(defun sql-get-login (&rest what) 
    (setq sql-user  "me" 
     sql-password "secret" 
     sql-server "localhost" 
     sql-database "MyDB")) 
+0

感謝。我抓住了一些代碼,並試圖以非交互方式使用它。 – 2010-03-26 01:17:50

+0

謝謝。我與Sybase有類似的問題。我會嘗試你的解決方案 - 我的.emacs中有我的irc密碼,它和我們的數據庫服務器一樣,無論如何都在防火牆後面。 – 2010-03-27 04:12:25