aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Mauger2010-07-20 21:56:55 -0400
committerMichael Mauger2010-07-20 21:56:55 -0400
commitd26b0ea9c5d43b366cf4a31be2300d17737a1370 (patch)
tree190b6519a9db819eed066ba565cf826ba496e986
parent7c3320d8b9d3beaf952b20cfe1843181c1c7af65 (diff)
downloademacs-d26b0ea9c5d43b366cf4a31be2300d17737a1370.tar.gz
emacs-d26b0ea9c5d43b366cf4a31be2300d17737a1370.zip
SQL Mode V2.3 - cleanup connection handling
-rw-r--r--etc/NEWS11
-rw-r--r--lisp/ChangeLog16
-rw-r--r--lisp/progmodes/sql.el297
3 files changed, 210 insertions, 114 deletions
diff --git a/etc/NEWS b/etc/NEWS
index a93baf36638..cf5e73ef36b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -296,6 +296,17 @@ either "dev" or "prd". The "dev" connection would connect to the
296SQLite database without prompting; the "prd" connection would prompt 296SQLite database without prompting; the "prd" connection would prompt
297for the users password and then connect to the Oracle database. 297for the users password and then connect to the Oracle database.
298 298
299**** Added SQL->Start... submenu when connections are defined.
300When connections have been defined, There is a submenu available that
301allows the user to select one to start a SQLi session. The "Start
302SQLi Session" item moves to the "Start..." submenu when cnnections
303have been defined.
304
305**** Added "Save Connection" menu item in SQLi buffers.
306When a SQLi session is not started by a connection then
307`sql-save-connection' will gather the login params specified for the
308session and save them as a new connection.
309
299*** Added option `sql-send-terminator'. 310*** Added option `sql-send-terminator'.
300When set makes sure that each command sent with `sql-send-*' commands 311When set makes sure that each command sent with `sql-send-*' commands
301are properly terminated and submitted to the SQL processor. 312are properly terminated and submitted to the SQL processor.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d22e244620a..e9b932cd4ae 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,19 @@
12010-07-20 Michael R. Mauger <mmaug@yahoo.com>
2
3 * progmodes/sql.el: Version 2.3.
4 (sql-connection-alist): Changed keys from symbols to strings;
5 enhanced the widget definition.
6 (sql-mode-menu): Added submenu to select connections.
7 (sql-interactive-mode-menu): Added "Save Connection" item.
8 (sql-add-product): Fixed menu item.
9 (sql-get-product-feature): Improved error handling.
10 (sql--alt-buffer-part, sql--alt-if-not-empty): Removed.
11 (sql-make-alternate-buffer-name): Simplified.
12 (sql-product-interactive): Handle missing product.
13 (sql-connect): Support string keys, minor improvements.
14 (sql-save-connection): New function.
15 (sql-connection-menu-filter): New function.
16
12010-07-20 Michael Albinus <michael.albinus@gmx.de> 172010-07-20 Michael Albinus <michael.albinus@gmx.de>
2 18
3 * net/tramp.el (tramp-file-name-handler): Trace 'quit. 19 * net/tramp.el (tramp-file-name-handler): Trace 'quit.
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el
index d31b7ad0ef5..7f1389103f2 100644
--- a/lisp/progmodes/sql.el
+++ b/lisp/progmodes/sql.el
@@ -5,7 +5,7 @@
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
@@ -188,7 +188,7 @@
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
@@ -236,9 +236,8 @@
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)
@@ -539,7 +538,7 @@ are:
539If a SQL-VARIABLE is part of the connection, it will not be 538If a SQL-VARIABLE is part of the connection, it will not be
540prompted for during login." 539prompted 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)
@@ -554,7 +553,11 @@ prompted for during login."
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
@@ -1115,8 +1118,17 @@ Based on `comint-mode-map'.")
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"
@@ -1144,7 +1156,8 @@ Based on `comint-mode-map'.")
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.
@@ -2028,7 +2041,7 @@ configuration."
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
@@ -2103,7 +2116,8 @@ See `sql-product-alist' for a list of products and supported features."
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.
@@ -2480,13 +2494,6 @@ variable `sql-buffer'. See `sql-help' on how to create such a 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
@@ -2502,40 +2509,44 @@ parameter.
2502If all else fails, the alternate name would be the user and 2509If all else fails, the alternate name would be the user and
2503server/database name." 2510server/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."
@@ -2959,55 +2970,58 @@ If buffer exists and a process is running, just switch to buffer `*SQL*'.
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.
@@ -3032,11 +3046,11 @@ is specified in the connection settings."
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
@@ -3044,12 +3058,12 @@ is specified in the connection settings."
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))
@@ -3066,14 +3080,14 @@ is specified in the connection settings."
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
@@ -3081,11 +3095,66 @@ is specified in the connection settings."
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))
3088 3102
3103(defun sql-save-connection (name)
3104 "Captures the connection information of the current SQLi session.
3105
3106The information is appended to `sql-connection-alist' and
3107optionally 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))
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.