Mercurial > emacs
comparison lisp/progmodes/sql.el @ 109482:c9df47f7bbf3
SQL Mode V2.3 - cleanup connection handling
author | Michael Mauger <mmaug@yahoo.com> |
---|---|
date | Tue, 20 Jul 2010 21:56:55 -0400 |
parents | 597339bd6bef |
children | b4b02bfd4d95 |
comparison
equal
deleted
inserted
replaced
109480:d12162869c07 | 109482:c9df47f7bbf3 |
---|---|
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, | 3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc. | 4 ;; 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
5 | 5 |
6 ;; Author: Alex Schroeder <alex@gnu.org> | 6 ;; Author: Alex Schroeder <alex@gnu.org> |
7 ;; Maintainer: Michael Mauger <mmaug@yahoo.com> | 7 ;; Maintainer: Michael Mauger <mmaug@yahoo.com> |
8 ;; Version: 2.2 | 8 ;; Version: 2.3 |
9 ;; Keywords: comm languages processes | 9 ;; Keywords: comm languages processes |
10 ;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el | 10 ;; URL: http://savannah.gnu.org/cgi-bin/viewcvs/emacs/emacs/lisp/progmodes/sql.el |
11 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode | 11 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?SqlMode |
12 | 12 |
13 ;; This file is part of GNU Emacs. | 13 ;; This file is part of GNU Emacs. |
186 ;; (if (not (string= "" sql-user)) | 186 ;; (if (not (string= "" sql-user)) |
187 ;; (setq params (append (list "-U" sql-user) params))) | 187 ;; (setq params (append (list "-U" sql-user) params))) |
188 ;; (sql-comint product params))) | 188 ;; (sql-comint product params))) |
189 ;; | 189 ;; |
190 ;; (sql-set-product-feature 'xyz | 190 ;; (sql-set-product-feature 'xyz |
191 ;; :sqli-connect-func 'my-sql-comint-xyz) | 191 ;; :sqli-comint-func 'my-sql-comint-xyz) |
192 | 192 |
193 ;; 6) Define a convienence function to invoke the SQL interpreter. | 193 ;; 6) Define a convienence function to invoke the SQL interpreter. |
194 | 194 |
195 ;; (defun my-sql-xyz () | 195 ;; (defun my-sql-xyz () |
196 ;; "Run ixyz by XyzDB as an inferior process." | 196 ;; "Run ixyz by XyzDB as an inferior process." |
234 (require 'comint) | 234 (require 'comint) |
235 ;; Need the following to allow GNU Emacs 19 to compile the file. | 235 ;; Need the following to allow GNU Emacs 19 to compile the file. |
236 (eval-when-compile | 236 (eval-when-compile |
237 (require 'regexp-opt)) | 237 (require 'regexp-opt)) |
238 (require 'custom) | 238 (require 'custom) |
239 (require 'assoc) | |
240 (eval-when-compile ;; needed in Emacs 19, 20 | 239 (eval-when-compile ;; needed in Emacs 19, 20 |
241 (setq max-specpdl-size 2000)) | 240 (setq max-specpdl-size (max max-specpdl-size 2000))) |
242 | 241 |
243 (defvar font-lock-keyword-face) | 242 (defvar font-lock-keyword-face) |
244 (defvar font-lock-set-defaults) | 243 (defvar font-lock-set-defaults) |
245 (defvar font-lock-string-face) | 244 (defvar font-lock-string-face) |
246 | 245 |
537 `sql-database' | 536 `sql-database' |
538 | 537 |
539 If a SQL-VARIABLE is part of the connection, it will not be | 538 If a SQL-VARIABLE is part of the connection, it will not be |
540 prompted for during login." | 539 prompted for during login." |
541 | 540 |
542 :type `(alist :key-type (symbol :tag "Connection") | 541 :type `(alist :key-type (string :tag "Connection") |
543 :value-type | 542 :value-type |
544 (set | 543 (set |
545 (group (const :tag "Product" sql-product) | 544 (group (const :tag "Product" sql-product) |
546 (choice | 545 (choice |
547 ,@(mapcar (lambda (prod-info) | 546 ,@(mapcar (lambda (prod-info) |
552 sql-product-alist))) | 551 sql-product-alist))) |
553 (group (const :tag "Username" sql-user) string) | 552 (group (const :tag "Username" sql-user) string) |
554 (group (const :tag "Password" sql-password) string) | 553 (group (const :tag "Password" sql-password) string) |
555 (group (const :tag "Server" sql-server) string) | 554 (group (const :tag "Server" sql-server) string) |
556 (group (const :tag "Database" sql-database) string) | 555 (group (const :tag "Database" sql-database) string) |
557 (group (const :tag "Port" sql-port) integer))) | 556 (group (const :tag "Port" sql-port) integer) |
557 (repeat :inline t | |
558 (list :tab "Other" | |
559 (symbol :tag " Variable Symbol") | |
560 (sexp :tag "Value Expression"))))) | |
558 :version "24.1" | 561 :version "24.1" |
559 :group 'SQL) | 562 :group 'SQL) |
560 | 563 |
561 ;;;###autoload | 564 ;;;###autoload |
562 (defcustom sql-product 'ansi | 565 (defcustom sql-product 'ansi |
1113 (get-buffer-process sql-buffer))] | 1116 (get-buffer-process sql-buffer))] |
1114 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) | 1117 ["Send Buffer" sql-send-buffer (and (buffer-live-p sql-buffer) |
1115 (get-buffer-process sql-buffer))] | 1118 (get-buffer-process sql-buffer))] |
1116 ["Send String" sql-send-string (and (buffer-live-p sql-buffer) | 1119 ["Send String" sql-send-string (and (buffer-live-p sql-buffer) |
1117 (get-buffer-process sql-buffer))] | 1120 (get-buffer-process sql-buffer))] |
1118 ["--" nil nil] | 1121 "--" |
1119 ["Start SQLi session" sql-product-interactive (sql-get-product-feature sql-product :sqli-comint-func)] | 1122 ["Start SQLi session" sql-product-interactive |
1123 :visible (not sql-connection-alist) | |
1124 :enable (sql-get-product-feature sql-product :sqli-comint-func)] | |
1125 ("Start..." | |
1126 :visible sql-connection-alist | |
1127 :filter sql-connection-menu-filter | |
1128 "--" | |
1129 ["New SQLi Session" sql-product-interactive (sql-get-product-feature sql-product :sqli-comint-func)]) | |
1130 ["--" | |
1131 :visible sql-connection-alist] | |
1120 ["Show SQLi buffer" sql-show-sqli-buffer t] | 1132 ["Show SQLi buffer" sql-show-sqli-buffer t] |
1121 ["Set SQLi buffer" sql-set-sqli-buffer t] | 1133 ["Set SQLi buffer" sql-set-sqli-buffer t] |
1122 ["Pop to SQLi buffer after send" | 1134 ["Pop to SQLi buffer after send" |
1123 sql-toggle-pop-to-buffer-after-send-region | 1135 sql-toggle-pop-to-buffer-after-send-region |
1124 :style toggle | 1136 :style toggle |
1142 | 1154 |
1143 (easy-menu-define | 1155 (easy-menu-define |
1144 sql-interactive-mode-menu sql-interactive-mode-map | 1156 sql-interactive-mode-menu sql-interactive-mode-map |
1145 "Menu for `sql-interactive-mode'." | 1157 "Menu for `sql-interactive-mode'." |
1146 '("SQL" | 1158 '("SQL" |
1147 ["Rename Buffer" sql-rename-buffer t])) | 1159 ["Rename Buffer" sql-rename-buffer t] |
1160 ["Save Connection" sql-save-connection (not sql-connection)])) | |
1148 | 1161 |
1149 ;; Abbreviations -- if you want more of them, define them in your | 1162 ;; Abbreviations -- if you want more of them, define them in your |
1150 ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too. | 1163 ;; ~/.emacs file. Abbrevs have to be enabled in your ~/.emacs, too. |
1151 | 1164 |
1152 (defvar sql-mode-abbrev-table nil | 1165 (defvar sql-mode-abbrev-table nil |
2026 ;; Add a menu item to the SQL->Product menu | 2039 ;; Add a menu item to the SQL->Product menu |
2027 (easy-menu-add-item sql-mode-menu '("Product") | 2040 (easy-menu-add-item sql-mode-menu '("Product") |
2028 ;; Each product is represented by a radio | 2041 ;; Each product is represented by a radio |
2029 ;; button with it's display name. | 2042 ;; button with it's display name. |
2030 `[,display | 2043 `[,display |
2031 (lambda () (interactive) (sql-set-product ',product)) | 2044 (sql-set-product ',product) |
2032 :style radio | 2045 :style radio |
2033 :selected (eq sql-product ',product)] | 2046 :selected (eq sql-product ',product)] |
2034 ;; Maintain the product list in | 2047 ;; Maintain the product list in |
2035 ;; (case-insensitive) alphabetic order of the | 2048 ;; (case-insensitive) alphabetic order of the |
2036 ;; display names. Loop thru each keymap item | 2049 ;; display names. Loop thru each keymap item |
2101 (member feature sql-indirect-features) | 2114 (member feature sql-indirect-features) |
2102 (not not-indirect) | 2115 (not not-indirect) |
2103 (symbolp v)) | 2116 (symbolp v)) |
2104 (symbol-value v) | 2117 (symbol-value v) |
2105 v)) | 2118 v)) |
2106 (message "`%s' is not a known product; use `sql-add-product' to add it first." product)))) | 2119 (message "`%s' is not a known product; use `sql-add-product' to add it first." product) |
2120 nil))) | |
2107 | 2121 |
2108 (defun sql-product-font-lock (keywords-only imenu) | 2122 (defun sql-product-font-lock (keywords-only imenu) |
2109 "Configure font-lock and imenu with product-specific settings. | 2123 "Configure font-lock and imenu with product-specific settings. |
2110 | 2124 |
2111 The KEYWORDS-ONLY flag is passed to font-lock to specify whether | 2125 The KEYWORDS-ONLY flag is passed to font-lock to specify whether |
2478 (message "%s has no SQLi buffer set." (buffer-name (current-buffer))) | 2492 (message "%s has no SQLi buffer set." (buffer-name (current-buffer))) |
2479 (if (null (get-buffer-process sql-buffer)) | 2493 (if (null (get-buffer-process sql-buffer)) |
2480 (message "Buffer %s has no process." (buffer-name sql-buffer)) | 2494 (message "Buffer %s has no process." (buffer-name sql-buffer)) |
2481 (message "Current SQLi buffer is %s." (buffer-name sql-buffer))))) | 2495 (message "Current SQLi buffer is %s." (buffer-name sql-buffer))))) |
2482 | 2496 |
2483 (defun sql--alt-buffer-part (delim part) | |
2484 (unless (string= "" part) | |
2485 (list delim part))) | |
2486 | |
2487 (defun sql--alt-if-not-empty (s) | |
2488 (if (string= "" s) nil s)) | |
2489 | |
2490 (defun sql-make-alternate-buffer-name () | 2497 (defun sql-make-alternate-buffer-name () |
2491 "Return a string that can be used to rename a SQLi buffer. | 2498 "Return a string that can be used to rename a SQLi buffer. |
2492 | 2499 |
2493 This is used to set `sql-alternate-buffer-name' within | 2500 This is used to set `sql-alternate-buffer-name' within |
2494 `sql-interactive-mode'. | 2501 `sql-interactive-mode'. |
2500 parameter. | 2507 parameter. |
2501 | 2508 |
2502 If all else fails, the alternate name would be the user and | 2509 If all else fails, the alternate name would be the user and |
2503 server/database name." | 2510 server/database name." |
2504 | 2511 |
2505 (or | 2512 (let ((name "")) |
2506 ;; If started by sql-connect, use that | 2513 |
2507 (sql--alt-if-not-empty | 2514 ;; Try using the :sqli-login setting |
2508 (when sql-connection (symbol-name sql-connection))) | 2515 (when (string= "" (or name "")) |
2509 | 2516 (setq name |
2510 ;; based on :sqli-login setting | 2517 (apply 'concat |
2511 (sql--alt-if-not-empty | 2518 (apply 'append nil |
2512 (apply 'concat | 2519 (mapcar |
2513 (cdr | 2520 (lambda (v) |
2514 (apply 'append nil | 2521 (cond |
2515 (mapcar | 2522 ((eq v 'user) (list "/" sql-user)) |
2516 (lambda (v) | 2523 ((eq v 'server) (list "." sql-server)) |
2517 (cond | 2524 ((eq v 'database) (list "@" sql-database)) |
2518 ((eq v 'user) (sql--alt-buffer-part "/" sql-user)) | 2525 ((eq v 'port) (list ":" sql-port)) |
2519 ((eq v 'server) (sql--alt-buffer-part "@" sql-server)) | 2526 |
2520 ((eq v 'database) (sql--alt-buffer-part "@" sql-database)) | 2527 ((eq v 'password) nil) |
2521 ((eq v 'port) (sql--alt-buffer-part ":" sql-port)) | 2528 (t nil))) |
2522 | 2529 (sql-get-product-feature sql-product :sqli-login)))))) |
2523 ((eq v 'password) nil) | 2530 |
2524 (t nil))) | 2531 ;; Default: username/server format |
2525 (sql-get-product-feature sql-product :sqli-login)))))) | 2532 (when (string= "" (or name "")) |
2526 | 2533 (setq name |
2527 ;; Default: username/server format | 2534 (concat " " |
2528 (sql--alt-if-not-empty | 2535 (if (string= "" sql-user) |
2529 (concat (if (string= "" sql-user) | 2536 (if (string= "" (user-login-name)) |
2530 (if (string= "" (user-login-name)) | 2537 () |
2531 () | 2538 (concat (user-login-name) "/")) |
2532 (concat (user-login-name) "/")) | 2539 (concat sql-user "/")) |
2533 (concat sql-user "/")) | 2540 (if (string= "" sql-database) |
2534 (if (string= "" sql-database) | 2541 (if (string= "" sql-server) |
2535 (if (string= "" sql-server) | 2542 (system-name) |
2536 (system-name) | 2543 sql-server) |
2537 sql-server) | 2544 sql-database)))) |
2538 sql-database))))) | 2545 |
2546 ;; Return the final string; prefixed by the connection name | |
2547 (if sql-connection | |
2548 (format "<%s>%s" sql-connection (or name "")) | |
2549 (substring (or name " ") 1)))) | |
2539 | 2550 |
2540 (defun sql-rename-buffer () | 2551 (defun sql-rename-buffer () |
2541 "Rename a SQLi buffer." | 2552 "Rename a SQLi buffer." |
2542 (interactive) | 2553 (interactive) |
2543 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name) t)) | 2554 (rename-buffer (format "*SQL: %s*" sql-alternate-buffer-name) t)) |
2957 (intern (completing-read "SQL product: " | 2968 (intern (completing-read "SQL product: " |
2958 (mapcar (lambda (info) (symbol-name (car info))) | 2969 (mapcar (lambda (info) (symbol-name (car info))) |
2959 sql-product-alist) | 2970 sql-product-alist) |
2960 nil 'require-match | 2971 nil 'require-match |
2961 (or (and sql-product (symbol-name sql-product)) "ansi")))) | 2972 (or (and sql-product (symbol-name sql-product)) "ansi")))) |
2962 ((symbolp product) product) ; Product specified | 2973 ((and product ; Product specified |
2974 (symbolp product)) product) | |
2963 (t sql-product))) ; Default to sql-product | 2975 (t sql-product))) ; Default to sql-product |
2964 | 2976 |
2965 (when (sql-get-product-feature product :sqli-comint-func) | 2977 (if product |
2966 (if (and sql-buffer | 2978 (when (sql-get-product-feature product :sqli-comint-func) |
2967 (buffer-live-p sql-buffer) | 2979 (if (and sql-buffer |
2968 (comint-check-proc sql-buffer)) | 2980 (buffer-live-p sql-buffer) |
2969 (pop-to-buffer sql-buffer) | 2981 (comint-check-proc sql-buffer)) |
2970 | 2982 (pop-to-buffer sql-buffer) |
2971 ;; Is the current buffer in sql-mode and | 2983 |
2972 ;; there is a buffer local setting of sql-buffer | 2984 ;; Is the current buffer in sql-mode and |
2973 (let* ((start-buffer | 2985 ;; there is a buffer local setting of sql-buffer |
2974 (and (derived-mode-p 'sql-mode) | 2986 (let* ((start-buffer |
2975 (current-buffer))) | 2987 (and (derived-mode-p 'sql-mode) |
2976 (start-sql-buffer | 2988 (current-buffer))) |
2977 (and start-buffer | 2989 (start-sql-buffer |
2978 (let (found) | 2990 (and start-buffer |
2979 (dolist (var (buffer-local-variables)) | 2991 (let (found) |
2980 (and (consp var) | 2992 (dolist (var (buffer-local-variables)) |
2981 (eq (car var) 'sql-buffer) | 2993 (and (consp var) |
2982 (buffer-live-p (cdr var)) | 2994 (eq (car var) 'sql-buffer) |
2983 (get-buffer-process (cdr var)) | 2995 (buffer-live-p (cdr var)) |
2984 (setq found (cdr var)))) | 2996 (get-buffer-process (cdr var)) |
2985 found))) | 2997 (setq found (cdr var)))) |
2986 new-sqli-buffer) | 2998 found))) |
2987 | 2999 new-sqli-buffer) |
2988 ;; Get credentials. | 3000 |
2989 (apply 'sql-get-login (sql-get-product-feature product :sqli-login)) | 3001 ;; Get credentials. |
2990 | 3002 (apply 'sql-get-login (sql-get-product-feature product :sqli-login)) |
2991 ;; Connect to database. | 3003 |
2992 (message "Login...") | 3004 ;; Connect to database. |
2993 (funcall (sql-get-product-feature product :sqli-comint-func) | 3005 (message "Login...") |
2994 product | 3006 (funcall (sql-get-product-feature product :sqli-comint-func) |
2995 (sql-get-product-feature product :sqli-options)) | 3007 product |
2996 | 3008 (sql-get-product-feature product :sqli-options)) |
2997 ;; Set SQLi mode. | 3009 |
2998 (setq sql-interactive-product product | 3010 ;; Set SQLi mode. |
2999 new-sqli-buffer (current-buffer) | 3011 (setq sql-interactive-product product |
3000 sql-buffer new-sqli-buffer) | 3012 new-sqli-buffer (current-buffer) |
3001 (sql-interactive-mode) | 3013 sql-buffer new-sqli-buffer) |
3002 | 3014 (sql-interactive-mode) |
3003 ;; Set `sql-buffer' in the start buffer | 3015 |
3004 (when (and start-buffer (not start-sql-buffer)) | 3016 ;; Set `sql-buffer' in the start buffer |
3005 (with-current-buffer start-buffer | 3017 (when (and start-buffer (not start-sql-buffer)) |
3006 (setq sql-buffer new-sqli-buffer))) | 3018 (with-current-buffer start-buffer |
3007 | 3019 (setq sql-buffer new-sqli-buffer))) |
3008 ;; All done. | 3020 |
3009 (message "Login...done") | 3021 ;; All done. |
3010 (pop-to-buffer sql-buffer))))) | 3022 (message "Login...done") |
3023 (pop-to-buffer sql-buffer)))) | |
3024 (message "No default SQL product defined. Set `sql-product'."))) | |
3011 | 3025 |
3012 (defun sql-comint (product params) | 3026 (defun sql-comint (product params) |
3013 "Set up a comint buffer to run the SQL processor. | 3027 "Set up a comint buffer to run the SQL processor. |
3014 | 3028 |
3015 PRODUCT is the SQL product. PARAMS is a list of strings which are | 3029 PRODUCT is the SQL product. PARAMS is a list of strings which are |
3030 | 3044 |
3031 ;; Prompt for the connection from those defined in the alist | 3045 ;; Prompt for the connection from those defined in the alist |
3032 (interactive | 3046 (interactive |
3033 (if sql-connection-alist | 3047 (if sql-connection-alist |
3034 (list | 3048 (list |
3035 (intern | 3049 (let ((completion-ignore-case t)) |
3036 (completing-read "Connection: " | 3050 (completing-read "Connection: " |
3037 (mapcar (lambda (c) (symbol-name (car c))) | 3051 (mapcar (lambda (c) (car c)) |
3038 sql-connection-alist) | 3052 sql-connection-alist) |
3039 nil t))) | 3053 nil t nil nil '(())))) |
3040 nil)) | 3054 nil)) |
3041 | 3055 |
3042 ;; Are there connections defined | 3056 ;; Are there connections defined |
3043 (if sql-connection-alist | 3057 (if sql-connection-alist |
3044 ;; Was one selected | 3058 ;; Was one selected |
3045 (when connection | 3059 (when connection |
3046 ;; Get connection settings | 3060 ;; Get connection settings |
3047 (let ((connect-set (aget sql-connection-alist connection))) | 3061 (let ((connect-set (assoc connection sql-connection-alist))) |
3048 ;; Settings are defined | 3062 ;; Settings are defined |
3049 (if connect-set | 3063 (if connect-set |
3050 ;; Set the desired parameters | 3064 ;; Set the desired parameters |
3051 (eval `(let* | 3065 (eval `(let* |
3052 (,@connect-set | 3066 (,@(cdr connect-set) |
3053 ;; :sqli-login params variable | 3067 ;; :sqli-login params variable |
3054 (param-var (sql-get-product-feature sql-product | 3068 (param-var (sql-get-product-feature sql-product |
3055 :sqli-login nil t)) | 3069 :sqli-login nil t)) |
3056 ;; :sqli-login params value | 3070 ;; :sqli-login params value |
3057 (login-params (sql-get-product-feature sql-product | 3071 (login-params (sql-get-product-feature sql-product |
3064 ((eq (car v) 'sql-password) 'password) | 3078 ((eq (car v) 'sql-password) 'password) |
3065 ((eq (car v) 'sql-server) 'server) | 3079 ((eq (car v) 'sql-server) 'server) |
3066 ((eq (car v) 'sql-database) 'database) | 3080 ((eq (car v) 'sql-database) 'database) |
3067 ((eq (car v) 'sql-port) 'port) | 3081 ((eq (car v) 'sql-port) 'port) |
3068 (t (car v)))) | 3082 (t (car v)))) |
3069 connect-set)) | 3083 (cdr connect-set))) |
3070 ;; the remaining params (w/o the connection params) | 3084 ;; the remaining params (w/o the connection params) |
3071 (rem-params (apply 'append nil | 3085 (rem-params (delq nil |
3072 (mapcar | 3086 (mapcar |
3073 (lambda (l) | 3087 (lambda (l) |
3074 (unless (member l set-params) | 3088 (unless (member l set-params) |
3075 (list l))) | 3089 l)) |
3076 login-params))) | 3090 login-params))) |
3077 ;; Remember the connection | 3091 ;; Remember the connection |
3078 (sql-connection connection)) | 3092 (sql-connection connection)) |
3079 | 3093 |
3080 ;; Set the remaining parameters and start the | 3094 ;; Set the remaining parameters and start the |
3081 ;; interactive session | 3095 ;; interactive session |
3082 (eval `(let ((,param-var ',rem-params)) | 3096 (eval `(let ((,param-var ',rem-params)) |
3083 (sql-product-interactive sql-product))))) | 3097 (sql-product-interactive sql-product))))) |
3084 (message "SQL Connection \"%s\" does not exist" connection) | 3098 (message "SQL Connection <%s> does not exist" connection) |
3085 nil))) | 3099 nil))) |
3086 (message "No SQL Connections defined") | 3100 (message "No SQL Connections defined") |
3087 nil)) | 3101 nil)) |
3102 | |
3103 (defun sql-save-connection (name) | |
3104 "Captures the connection information of the current SQLi session. | |
3105 | |
3106 The information is appended to `sql-connection-alist' and | |
3107 optionally is saved to the user's init file." | |
3108 | |
3109 (interactive "sNew connection name: ") | |
3110 | |
3111 (if sql-connection | |
3112 (message "This session was started by a connection; it's already been saved.") | |
3113 | |
3114 (let ((login (sql-get-product-feature sql-product :sqli-login)) | |
3115 (alist sql-connection-alist) | |
3116 connect) | |
3117 | |
3118 ;; Remove the existing connection if the user says so | |
3119 (when (and (assoc name alist) | |
3120 (yes-or-no-p (format "Replace connection definition <%s>? " name))) | |
3121 (setq alist (assq-delete-all name alist))) | |
3122 | |
3123 ;; Add the new connection if it doesn't exist | |
3124 (if (assoc name alist) | |
3125 (message "Connection <%s> already exists" name) | |
3126 (setq connect | |
3127 (append (list name) | |
3128 (delq nil | |
3129 (mapcar | |
3130 (lambda (param) | |
3131 (cond | |
3132 ((eq param 'product) `(sql-product (quote ,sql-product))) | |
3133 ((eq param 'user) `(sql-user ,sql-user)) | |
3134 ((eq param 'database) `(sql-database ,sql-database)) | |
3135 ((eq param 'server) `(sql-server ,sql-server)) | |
3136 ((eq param 'port) `(sql-port ,sql-port)))) | |
3137 (append (list 'product) login))))) | |
3138 | |
3139 (setq alist (append alist (list connect))) | |
3140 | |
3141 ;; confirm whether we want to save the connections | |
3142 (if (yes-or-no-p "Save the connections for future sessions? ") | |
3143 (customize-save-variable 'sql-connection-alist alist) | |
3144 (customize-set-variable 'sql-connection-alist alist)))))) | |
3145 | |
3146 (defun sql-connection-menu-filter (tail) | |
3147 "Generates menu entries for using each connection." | |
3148 (append | |
3149 (mapcar | |
3150 (lambda (conn) | |
3151 (vector | |
3152 (format "Connection <%s>" (car conn)) | |
3153 (list 'sql-connect (car conn)) | |
3154 t)) | |
3155 sql-connection-alist) | |
3156 tail)) | |
3088 | 3157 |
3089 ;;;###autoload | 3158 ;;;###autoload |
3090 (defun sql-oracle () | 3159 (defun sql-oracle () |
3091 "Run sqlplus by Oracle as an inferior process. | 3160 "Run sqlplus by Oracle as an inferior process. |
3092 | 3161 |