diff options
| author | Stefan Monnier | 2012-12-06 12:29:30 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2012-12-06 12:29:30 -0500 |
| commit | 93852cb0cf22a38d75edeb840e498b3aa6a4d7c9 (patch) | |
| tree | f1ab538b6cf3c93241a385104c3bdf246b52e2b9 | |
| parent | 853c1ffc037f4adc402bea59e3beb03860e63ff7 (diff) | |
| download | emacs-93852cb0cf22a38d75edeb840e498b3aa6a4d7c9.tar.gz emacs-93852cb0cf22a38d75edeb840e498b3aa6a4d7c9.zip | |
* lisp/progmodes/sql.el: Use cl-lib and lexical-binding; various cleanup.
(sql-signum): Remove. Use `cl-signum' instead.
(sql-read-passwd): Remove; use read-passwd instread.
(sql-get-login-ext): Use read-string.
(sql-get-login): Use dolist and pcase.
(sql--completion-table): Rename from sql-try-completion.
Use complete-with-action.
(sql-mode): Don't change abbrev-all-caps globally.
(sql-connect): Don't rely on dynamic scoping for `new-name'.
(sql-postgres-completion-object): Initialize vars in their `let'.
(sql-comint-sybase, sql-comint-sqlite, sql-comint-mysql)
(sql-comint-solid, sql-comint-ms, sql-comint-postgres)
(sql-comint-interbase): Use a single append, without setq.
(sql-comint-linter): Same, and unwind-protect the LINTER_MBX var.
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/progmodes/sql.el | 556 |
2 files changed, 294 insertions, 277 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 82b311acf0d..d94ffbab67e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,20 @@ | |||
| 1 | 2012-12-06 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2012-12-06 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * progmodes/sql.el: Use cl-lib and lexical-binding; various cleanup. | ||
| 4 | (sql-signum): Remove. Use `cl-signum' instead. | ||
| 5 | (sql-read-passwd): Remove; use read-passwd instread. | ||
| 6 | (sql-get-login-ext): Use read-string. | ||
| 7 | (sql-get-login): Use dolist and pcase. | ||
| 8 | (sql--completion-table): Rename from sql-try-completion. | ||
| 9 | Use complete-with-action. | ||
| 10 | (sql-mode): Don't change abbrev-all-caps globally. | ||
| 11 | (sql-connect): Don't rely on dynamic scoping for `new-name'. | ||
| 12 | (sql-postgres-completion-object): Initialize vars in their `let'. | ||
| 13 | (sql-comint-sybase, sql-comint-sqlite, sql-comint-mysql) | ||
| 14 | (sql-comint-solid, sql-comint-ms, sql-comint-postgres) | ||
| 15 | (sql-comint-interbase): Use a single append, without setq. | ||
| 16 | (sql-comint-linter): Same, and unwind-protect the LINTER_MBX var. | ||
| 17 | |||
| 3 | * hi-lock.el: Rework the default face and the serialize regexp code. | 18 | * hi-lock.el: Rework the default face and the serialize regexp code. |
| 4 | (hi-lock--auto-select-face-defaults): Remove. | 19 | (hi-lock--auto-select-face-defaults): Remove. |
| 5 | (hi-lock-string-serialize-serial): Remove. | 20 | (hi-lock-string-serialize-serial): Remove. |
diff --git a/lisp/progmodes/sql.el b/lisp/progmodes/sql.el index d84d57cad22..22ba55d9a08 100644 --- a/lisp/progmodes/sql.el +++ b/lisp/progmodes/sql.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; sql.el --- specialized comint.el for SQL interpreters | 1 | ;;; sql.el --- specialized comint.el for SQL interpreters -*- lexical-binding: t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1998-2012 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1998-2012 Free Software Foundation, Inc. |
| 4 | 4 | ||
| @@ -80,14 +80,6 @@ | |||
| 80 | ;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and | 80 | ;; Hint for newbies: take a look at `dabbrev-expand', `abbrev-mode', and |
| 81 | ;; `imenu-add-menubar-index'. | 81 | ;; `imenu-add-menubar-index'. |
| 82 | 82 | ||
| 83 | ;;; Requirements for Emacs 19.34: | ||
| 84 | |||
| 85 | ;; If you are using Emacs 19.34, you will have to get and install | ||
| 86 | ;; the file regexp-opt.el | ||
| 87 | ;; <URL:ftp://ftp.ifi.uio.no/pub/emacs/emacs-20.3/lisp/emacs-lisp/regexp-opt.el> | ||
| 88 | ;; and the custom package | ||
| 89 | ;; <URL:http://www.dina.kvl.dk/~abraham/custom/>. | ||
| 90 | |||
| 91 | ;;; Bugs: | 83 | ;;; Bugs: |
| 92 | 84 | ||
| 93 | ;; sql-ms now uses osql instead of isql. Osql flushes its error | 85 | ;; sql-ms now uses osql instead of isql. Osql flushes its error |
| @@ -169,15 +161,17 @@ | |||
| 169 | ;; | 161 | ;; |
| 170 | ;; ;; Do something with `sql-user', `sql-password', | 162 | ;; ;; Do something with `sql-user', `sql-password', |
| 171 | ;; ;; `sql-database', and `sql-server'. | 163 | ;; ;; `sql-database', and `sql-server'. |
| 172 | ;; (let ((params options)) | 164 | ;; (let ((params |
| 173 | ;; (if (not (string= "" sql-server)) | 165 | ;; (append |
| 174 | ;; (setq params (append (list "-S" sql-server) params))) | ||
| 175 | ;; (if (not (string= "" sql-database)) | ||
| 176 | ;; (setq params (append (list "-D" sql-database) params))) | ||
| 177 | ;; (if (not (string= "" sql-password)) | ||
| 178 | ;; (setq params (append (list "-P" sql-password) params))) | ||
| 179 | ;; (if (not (string= "" sql-user)) | 166 | ;; (if (not (string= "" sql-user)) |
| 180 | ;; (setq params (append (list "-U" sql-user) params))) | 167 | ;; (list "-U" sql-user)) |
| 168 | ;; (if (not (string= "" sql-password)) | ||
| 169 | ;; (list "-P" sql-password)) | ||
| 170 | ;; (if (not (string= "" sql-database)) | ||
| 171 | ;; (list "-D" sql-database)) | ||
| 172 | ;; (if (not (string= "" sql-server)) | ||
| 173 | ;; (list "-S" sql-server)) | ||
| 174 | ;; options))) | ||
| 181 | ;; (sql-comint product params))) | 175 | ;; (sql-comint product params))) |
| 182 | ;; | 176 | ;; |
| 183 | ;; (sql-set-product-feature 'xyz | 177 | ;; (sql-set-product-feature 'xyz |
| @@ -229,22 +223,13 @@ | |||
| 229 | 223 | ||
| 230 | ;;; Code: | 224 | ;;; Code: |
| 231 | 225 | ||
| 226 | (require 'cl-lib) | ||
| 232 | (require 'comint) | 227 | (require 'comint) |
| 233 | ;; Need the following to allow GNU Emacs 19 to compile the file. | 228 | ;; Need the following to allow GNU Emacs 19 to compile the file. |
| 234 | (eval-when-compile | 229 | (eval-when-compile |
| 235 | (require 'regexp-opt)) | 230 | (require 'regexp-opt)) |
| 236 | (require 'custom) | 231 | (require 'custom) |
| 237 | (require 'thingatpt) | 232 | (require 'thingatpt) |
| 238 | (eval-when-compile ;; needed in Emacs 19, 20 | ||
| 239 | (setq max-specpdl-size (max max-specpdl-size 2000))) | ||
| 240 | |||
| 241 | (defun sql-signum (n) | ||
| 242 | "Return 1, 0, or -1 to identify the sign of N." | ||
| 243 | (cond | ||
| 244 | ((not (numberp n)) nil) | ||
| 245 | ((< n 0) -1) | ||
| 246 | ((> n 0) 1) | ||
| 247 | (t 0))) | ||
| 248 | 233 | ||
| 249 | (defvar font-lock-keyword-face) | 234 | (defvar font-lock-keyword-face) |
| 250 | (defvar font-lock-set-defaults) | 235 | (defvar font-lock-set-defaults) |
| @@ -636,12 +621,14 @@ making new SQLi sessions." | |||
| 636 | (set | 621 | (set |
| 637 | (group (const :tag "Product" sql-product) | 622 | (group (const :tag "Product" sql-product) |
| 638 | (choice | 623 | (choice |
| 639 | ,@(mapcar (lambda (prod-info) | 624 | ,@(mapcar |
| 640 | `(const :tag | 625 | (lambda (prod-info) |
| 641 | ,(or (plist-get (cdr prod-info) :name) | 626 | `(const :tag |
| 642 | (capitalize (symbol-name (car prod-info)))) | 627 | ,(or (plist-get (cdr prod-info) :name) |
| 643 | (quote ,(car prod-info)))) | 628 | (capitalize |
| 644 | sql-product-alist))) | 629 | (symbol-name (car prod-info)))) |
| 630 | (quote ,(car prod-info)))) | ||
| 631 | sql-product-alist))) | ||
| 645 | (group (const :tag "Username" sql-user) string) | 632 | (group (const :tag "Username" sql-user) string) |
| 646 | (group (const :tag "Password" sql-password) string) | 633 | (group (const :tag "Password" sql-password) string) |
| 647 | (group (const :tag "Server" sql-server) string) | 634 | (group (const :tag "Server" sql-server) string) |
| @@ -655,8 +642,8 @@ making new SQLi sessions." | |||
| 655 | :group 'SQL) | 642 | :group 'SQL) |
| 656 | 643 | ||
| 657 | (defcustom sql-product 'ansi | 644 | (defcustom sql-product 'ansi |
| 658 | "Select the SQL database product used so that buffers can be | 645 | "Select the SQL database product used. |
| 659 | highlighted properly when you open them." | 646 | This allows highlighting buffers properly when you open them." |
| 660 | :type `(choice | 647 | :type `(choice |
| 661 | ,@(mapcar (lambda (prod-info) | 648 | ,@(mapcar (lambda (prod-info) |
| 662 | `(const :tag | 649 | `(const :tag |
| @@ -818,12 +805,11 @@ for the first time." | |||
| 818 | 805 | ||
| 819 | ;; Customization for ANSI | 806 | ;; Customization for ANSI |
| 820 | 807 | ||
| 821 | (defcustom sql-ansi-statement-starters (regexp-opt '( | 808 | (defcustom sql-ansi-statement-starters |
| 822 | "create" "alter" "drop" | 809 | (regexp-opt '("create" "alter" "drop" |
| 823 | "select" "insert" "update" "delete" "merge" | 810 | "select" "insert" "update" "delete" "merge" |
| 824 | "grant" "revoke" | 811 | "grant" "revoke")) |
| 825 | )) | 812 | "Regexp of keywords that start SQL commands. |
| 826 | "Regexp of keywords that start SQL commands | ||
| 827 | 813 | ||
| 828 | All products share this list; products should define a regexp to | 814 | All products share this list; products should define a regexp to |
| 829 | identify additional keywords in a variable defined by | 815 | identify additional keywords in a variable defined by |
| @@ -1167,10 +1153,10 @@ You can change `sql-prompt-length' on `sql-interactive-mode-hook'.") | |||
| 1167 | Used by `sql-rename-buffer'.") | 1153 | Used by `sql-rename-buffer'.") |
| 1168 | 1154 | ||
| 1169 | (defun sql-buffer-live-p (buffer &optional product connection) | 1155 | (defun sql-buffer-live-p (buffer &optional product connection) |
| 1170 | "Returns non-nil if the process associated with buffer is live. | 1156 | "Return non-nil if the process associated with buffer is live. |
| 1171 | 1157 | ||
| 1172 | BUFFER can be a buffer object or a buffer name. The buffer must | 1158 | BUFFER can be a buffer object or a buffer name. The buffer must |
| 1173 | be a live buffer, have an running process attached to it, be in | 1159 | be a live buffer, have a running process attached to it, be in |
| 1174 | `sql-interactive-mode', and, if PRODUCT or CONNECTION are | 1160 | `sql-interactive-mode', and, if PRODUCT or CONNECTION are |
| 1175 | specified, it's `sql-product' or `sql-connection' must match." | 1161 | specified, it's `sql-product' or `sql-connection' must match." |
| 1176 | 1162 | ||
| @@ -1178,7 +1164,6 @@ specified, it's `sql-product' or `sql-connection' must match." | |||
| 1178 | (setq buffer (get-buffer buffer)) | 1164 | (setq buffer (get-buffer buffer)) |
| 1179 | (and buffer | 1165 | (and buffer |
| 1180 | (buffer-live-p buffer) | 1166 | (buffer-live-p buffer) |
| 1181 | (get-buffer-process buffer) | ||
| 1182 | (comint-check-proc buffer) | 1167 | (comint-check-proc buffer) |
| 1183 | (with-current-buffer buffer | 1168 | (with-current-buffer buffer |
| 1184 | (and (derived-mode-p 'sql-interactive-mode) | 1169 | (and (derived-mode-p 'sql-interactive-mode) |
| @@ -1287,27 +1272,15 @@ Based on `comint-mode-map'.") | |||
| 1287 | ;; Abbreviations -- if you want more of them, define them in your init | 1272 | ;; Abbreviations -- if you want more of them, define them in your init |
| 1288 | ;; file. Abbrevs have to be enabled in your init file, too. | 1273 | ;; file. Abbrevs have to be enabled in your init file, too. |
| 1289 | 1274 | ||
| 1290 | (defvar sql-mode-abbrev-table nil | 1275 | (define-abbrev-table 'sql-mode-abbrev-table |
| 1276 | '(("ins" "insert" nil nil t) | ||
| 1277 | ("upd" "update" nil nil t) | ||
| 1278 | ("del" "delete" nil nil t) | ||
| 1279 | ("sel" "select" nil nil t) | ||
| 1280 | ("proc" "procedure" nil nil t) | ||
| 1281 | ("func" "function" nil nil t) | ||
| 1282 | ("cr" "create" nil nil t)) | ||
| 1291 | "Abbrev table used in `sql-mode' and `sql-interactive-mode'.") | 1283 | "Abbrev table used in `sql-mode' and `sql-interactive-mode'.") |
| 1292 | (unless sql-mode-abbrev-table | ||
| 1293 | (define-abbrev-table 'sql-mode-abbrev-table nil)) | ||
| 1294 | |||
| 1295 | (mapc | ||
| 1296 | ;; In Emacs 22+, provide SYSTEM-FLAG to define-abbrev. | ||
| 1297 | (lambda (abbrev) | ||
| 1298 | (let ((name (car abbrev)) | ||
| 1299 | (expansion (cdr abbrev))) | ||
| 1300 | (condition-case nil | ||
| 1301 | (define-abbrev sql-mode-abbrev-table name expansion nil 0 t) | ||
| 1302 | (error | ||
| 1303 | (define-abbrev sql-mode-abbrev-table name expansion))))) | ||
| 1304 | '(("ins" . "insert") | ||
| 1305 | ("upd" . "update") | ||
| 1306 | ("del" . "delete") | ||
| 1307 | ("sel" . "select") | ||
| 1308 | ("proc" . "procedure") | ||
| 1309 | ("func" . "function") | ||
| 1310 | ("cr" . "create"))) | ||
| 1311 | 1284 | ||
| 1312 | ;; Syntax Table | 1285 | ;; Syntax Table |
| 1313 | 1286 | ||
| @@ -1530,9 +1503,8 @@ function `regexp-opt'. Therefore, take a look at the source before | |||
| 1530 | you define your own `sql-mode-ansi-font-lock-keywords'. You may want | 1503 | you define your own `sql-mode-ansi-font-lock-keywords'. You may want |
| 1531 | to add functions and PL/SQL keywords.") | 1504 | to add functions and PL/SQL keywords.") |
| 1532 | 1505 | ||
| 1533 | (defun sql-oracle-show-reserved-words () | 1506 | (defun sql--oracle-show-reserved-words () |
| 1534 | ;; This function is for use by the maintainer of SQL.EL only. | 1507 | ;; This function is for use by the maintainer of SQL.EL only. |
| 1535 | (interactive) | ||
| 1536 | (if (or (and (not (derived-mode-p 'sql-mode)) | 1508 | (if (or (and (not (derived-mode-p 'sql-mode)) |
| 1537 | (not (derived-mode-p 'sql-interactive-mode))) | 1509 | (not (derived-mode-p 'sql-interactive-mode))) |
| 1538 | (not sql-buffer) | 1510 | (not sql-buffer) |
| @@ -2611,14 +2583,12 @@ adds a fontification pattern to fontify identifiers ending in | |||
| 2611 | (append keywords old-val)))))) | 2583 | (append keywords old-val)))))) |
| 2612 | 2584 | ||
| 2613 | (defun sql-for-each-login (login-params body) | 2585 | (defun sql-for-each-login (login-params body) |
| 2614 | "Iterates through login parameters and returns a list of results." | 2586 | "Iterate through login parameters and return a list of results." |
| 2615 | |||
| 2616 | (delq nil | 2587 | (delq nil |
| 2617 | (mapcar | 2588 | (mapcar |
| 2618 | (lambda (param) | 2589 | (lambda (param) |
| 2619 | (let ((token (or (and (listp param) (car param)) param)) | 2590 | (let ((token (or (car-safe param) param)) |
| 2620 | (plist (or (and (listp param) (cdr param)) nil))) | 2591 | (plist (cdr-safe param))) |
| 2621 | |||
| 2622 | (funcall body token plist))) | 2592 | (funcall body token plist))) |
| 2623 | login-params))) | 2593 | login-params))) |
| 2624 | 2594 | ||
| @@ -2682,6 +2652,34 @@ matching the regular expression `comint-prompt-regexp', a buffer | |||
| 2682 | local variable." | 2652 | local variable." |
| 2683 | (save-excursion (comint-bol nil) (point)))) | 2653 | (save-excursion (comint-bol nil) (point)))) |
| 2684 | 2654 | ||
| 2655 | ;;; SMIE support | ||
| 2656 | |||
| 2657 | ;; Needs a lot more love than I can provide. --Stef | ||
| 2658 | |||
| 2659 | ;; (require 'smie) | ||
| 2660 | |||
| 2661 | ;; (defconst sql-smie-grammar | ||
| 2662 | ;; (smie-prec2->grammar | ||
| 2663 | ;; (smie-bnf->prec2 | ||
| 2664 | ;; ;; Partly based on http://www.h2database.com/html/grammar.html | ||
| 2665 | ;; '((cmd ("SELECT" select-exp "FROM" select-table-exp) | ||
| 2666 | ;; ) | ||
| 2667 | ;; (select-exp ("*") (exp) (exp "AS" column-alias)) | ||
| 2668 | ;; (column-alias) | ||
| 2669 | ;; (select-table-exp (table-exp "WHERE" exp) (table-exp)) | ||
| 2670 | ;; (table-exp) | ||
| 2671 | ;; (exp ("CASE" exp "WHEN" exp "THEN" exp "ELSE" exp "END") | ||
| 2672 | ;; ("CASE" exp "WHEN" exp "THEN" exp "END")) | ||
| 2673 | ;; ;; Random ad-hoc additions. | ||
| 2674 | ;; (foo (foo "," foo)) | ||
| 2675 | ;; ) | ||
| 2676 | ;; '((assoc ","))))) | ||
| 2677 | |||
| 2678 | ;; (defun sql-smie-rules (kind token) | ||
| 2679 | ;; (pcase (cons kind token) | ||
| 2680 | ;; (`(:list-intro . ,_) t) | ||
| 2681 | ;; (`(:before . "(") (smie-rule-parent)))) | ||
| 2682 | |||
| 2685 | ;;; Motion Functions | 2683 | ;;; Motion Functions |
| 2686 | 2684 | ||
| 2687 | (defun sql-statement-regexp (prod) | 2685 | (defun sql-statement-regexp (prod) |
| @@ -2694,7 +2692,7 @@ local variable." | |||
| 2694 | "\\>"))) | 2692 | "\\>"))) |
| 2695 | 2693 | ||
| 2696 | (defun sql-beginning-of-statement (arg) | 2694 | (defun sql-beginning-of-statement (arg) |
| 2697 | "Moves the cursor to the beginning of the current SQL statement." | 2695 | "Move to the beginning of the current SQL statement." |
| 2698 | (interactive "p") | 2696 | (interactive "p") |
| 2699 | 2697 | ||
| 2700 | (let ((here (point)) | 2698 | (let ((here (point)) |
| @@ -2721,10 +2719,10 @@ local variable." | |||
| 2721 | (beginning-of-line) | 2719 | (beginning-of-line) |
| 2722 | ;; If we didn't move, try again | 2720 | ;; If we didn't move, try again |
| 2723 | (when (= here (point)) | 2721 | (when (= here (point)) |
| 2724 | (sql-beginning-of-statement (* 2 (sql-signum arg)))))) | 2722 | (sql-beginning-of-statement (* 2 (cl-signum arg)))))) |
| 2725 | 2723 | ||
| 2726 | (defun sql-end-of-statement (arg) | 2724 | (defun sql-end-of-statement (arg) |
| 2727 | "Moves the cursor to the end of the current SQL statement." | 2725 | "Move to the end of the current SQL statement." |
| 2728 | (interactive "p") | 2726 | (interactive "p") |
| 2729 | (let ((term (sql-get-product-feature sql-product :terminator)) | 2727 | (let ((term (sql-get-product-feature sql-product :terminator)) |
| 2730 | (re-search (if (> 0 arg) 're-search-backward 're-search-forward)) | 2728 | (re-search (if (> 0 arg) 're-search-backward 're-search-forward)) |
| @@ -2733,7 +2731,7 @@ local variable." | |||
| 2733 | (when (consp term) | 2731 | (when (consp term) |
| 2734 | (setq term (car term))) | 2732 | (setq term (car term))) |
| 2735 | ;; Iterate until we've moved the desired number of stmt ends | 2733 | ;; Iterate until we've moved the desired number of stmt ends |
| 2736 | (while (not (= (sql-signum arg) 0)) | 2734 | (while (not (= (cl-signum arg) 0)) |
| 2737 | ;; if we're looking at the terminator, jump by 2 | 2735 | ;; if we're looking at the terminator, jump by 2 |
| 2738 | (if (or (and (> 0 arg) (looking-back term)) | 2736 | (if (or (and (> 0 arg) (looking-back term)) |
| 2739 | (and (< 0 arg) (looking-at term))) | 2737 | (and (< 0 arg) (looking-at term))) |
| @@ -2744,7 +2742,7 @@ local variable." | |||
| 2744 | (setq arg 0) | 2742 | (setq arg 0) |
| 2745 | ;; count it if we're not in a comment | 2743 | ;; count it if we're not in a comment |
| 2746 | (unless (nth 7 (syntax-ppss)) | 2744 | (unless (nth 7 (syntax-ppss)) |
| 2747 | (setq arg (- arg (sql-signum arg)))))) | 2745 | (setq arg (- arg (cl-signum arg)))))) |
| 2748 | (goto-char (if (match-data) | 2746 | (goto-char (if (match-data) |
| 2749 | (match-end 0) | 2747 | (match-end 0) |
| 2750 | here)))) | 2748 | here)))) |
| @@ -2857,10 +2855,6 @@ appended to the SQLi buffer without disturbing your SQL buffer." | |||
| 2857 | t t doc 0))) | 2855 | t t doc 0))) |
| 2858 | doc) | 2856 | doc) |
| 2859 | 2857 | ||
| 2860 | (defun sql-read-passwd (prompt &optional default) | ||
| 2861 | "Read a password using PROMPT. Optional DEFAULT is password to start with." | ||
| 2862 | (read-passwd prompt nil default)) | ||
| 2863 | |||
| 2864 | (defun sql-get-login-ext (symbol prompt history-var plist) | 2858 | (defun sql-get-login-ext (symbol prompt history-var plist) |
| 2865 | "Prompt user with extended login parameters. | 2859 | "Prompt user with extended login parameters. |
| 2866 | 2860 | ||
| @@ -2912,8 +2906,7 @@ value. (The property value is used as the PREDICATE argument to | |||
| 2912 | (read-number prompt (or default last-value 0))) | 2906 | (read-number prompt (or default last-value 0))) |
| 2913 | 2907 | ||
| 2914 | (t | 2908 | (t |
| 2915 | (let ((r (read-from-minibuffer prompt-def last-value nil nil history-var nil))) | 2909 | (read-string prompt-def last-value history-var default)))))) |
| 2916 | (if (string= "" r) (or default "") r))))))) | ||
| 2917 | 2910 | ||
| 2918 | (defun sql-get-login (&rest what) | 2911 | (defun sql-get-login (&rest what) |
| 2919 | "Get username, password and database from the user. | 2912 | "Get username, password and database from the user. |
| @@ -2943,32 +2936,29 @@ supported: | |||
| 2943 | 2936 | ||
| 2944 | In order to ask the user for username, password and database, call the | 2937 | In order to ask the user for username, password and database, call the |
| 2945 | function like this: (sql-get-login 'user 'password 'database)." | 2938 | function like this: (sql-get-login 'user 'password 'database)." |
| 2946 | (interactive) | 2939 | (dolist (w what) |
| 2947 | (mapcar | 2940 | (let ((plist (cdr-safe w))) |
| 2948 | (lambda (w) | 2941 | (pcase (or (car-safe w) w) |
| 2949 | (let ((token (or (and (consp w) (car w)) w)) | 2942 | (`user |
| 2950 | (plist (or (and (consp w) (cdr w)) nil))) | 2943 | (sql-get-login-ext 'sql-user "User: " 'sql-user-history plist)) |
| 2951 | |||
| 2952 | (cond | ||
| 2953 | ((eq token 'user) ; user | ||
| 2954 | (sql-get-login-ext 'sql-user "User: " 'sql-user-history plist)) | ||
| 2955 | 2944 | ||
| 2956 | ((eq token 'password) ; password | 2945 | (`password |
| 2957 | (setq-default sql-password | 2946 | (setq-default sql-password |
| 2958 | (sql-read-passwd "Password: " sql-password))) | 2947 | (read-passwd "Password: " nil sql-password))) |
| 2959 | 2948 | ||
| 2960 | ((eq token 'server) ; server | 2949 | (`server |
| 2961 | (sql-get-login-ext 'sql-server "Server: " 'sql-server-history plist)) | 2950 | (sql-get-login-ext 'sql-server "Server: " 'sql-server-history plist)) |
| 2962 | 2951 | ||
| 2963 | ((eq token 'database) ; database | 2952 | (`database |
| 2964 | (sql-get-login-ext 'sql-database "Database: " 'sql-database-history plist)) | 2953 | (sql-get-login-ext 'sql-database "Database: " |
| 2954 | 'sql-database-history plist)) | ||
| 2965 | 2955 | ||
| 2966 | ((eq token 'port) ; port | 2956 | (`port |
| 2967 | (sql-get-login-ext 'sql-port "Port: " nil (append '(:number t) plist)))))) | 2957 | (sql-get-login-ext 'sql-port "Port: " |
| 2968 | what)) | 2958 | nil (append '(:number t) plist))))))) |
| 2969 | 2959 | ||
| 2970 | (defun sql-find-sqli-buffer (&optional product connection) | 2960 | (defun sql-find-sqli-buffer (&optional product connection) |
| 2971 | "Returns the name of the current default SQLi buffer or nil. | 2961 | "Return the name of the current default SQLi buffer or nil. |
| 2972 | In order to qualify, the SQLi buffer must be alive, be in | 2962 | In order to qualify, the SQLi buffer must be alive, be in |
| 2973 | `sql-interactive-mode' and have a process." | 2963 | `sql-interactive-mode' and have a process." |
| 2974 | (let ((buf sql-buffer) | 2964 | (let ((buf sql-buffer) |
| @@ -3072,29 +3062,29 @@ server/database name." | |||
| 3072 | (sql-for-each-login | 3062 | (sql-for-each-login |
| 3073 | (sql-get-product-feature sql-product :sqli-login) | 3063 | (sql-get-product-feature sql-product :sqli-login) |
| 3074 | (lambda (token plist) | 3064 | (lambda (token plist) |
| 3075 | (cond | 3065 | (pcase token |
| 3076 | ((eq token 'user) | 3066 | (`user |
| 3077 | (unless (string= "" sql-user) | 3067 | (unless (string= "" sql-user) |
| 3078 | (list "/" sql-user))) | 3068 | (list "/" sql-user))) |
| 3079 | ((eq token 'port) | 3069 | (`port |
| 3080 | (unless (or (not (numberp sql-port)) | 3070 | (unless (or (not (numberp sql-port)) |
| 3081 | (= 0 sql-port)) | 3071 | (= 0 sql-port)) |
| 3082 | (list ":" (number-to-string sql-port)))) | 3072 | (list ":" (number-to-string sql-port)))) |
| 3083 | ((eq token 'server) | 3073 | (`server |
| 3084 | (unless (string= "" sql-server) | 3074 | (unless (string= "" sql-server) |
| 3085 | (list "." | 3075 | (list "." |
| 3086 | (if (plist-member plist :file) | 3076 | (if (plist-member plist :file) |
| 3087 | (file-name-nondirectory sql-server) | 3077 | (file-name-nondirectory sql-server) |
| 3088 | sql-server)))) | 3078 | sql-server)))) |
| 3089 | ((eq token 'database) | 3079 | (`database |
| 3090 | (unless (string= "" sql-database) | 3080 | (unless (string= "" sql-database) |
| 3091 | (list "@" | 3081 | (list "@" |
| 3092 | (if (plist-member plist :file) | 3082 | (if (plist-member plist :file) |
| 3093 | (file-name-nondirectory sql-database) | 3083 | (file-name-nondirectory sql-database) |
| 3094 | sql-database)))) | 3084 | sql-database)))) |
| 3095 | 3085 | ||
| 3096 | ((eq token 'password) nil) | 3086 | ;; (`password nil) |
| 3097 | (t nil)))))))) | 3087 | (_ nil)))))))) |
| 3098 | 3088 | ||
| 3099 | ;; If there's a connection, use it and the name thus far | 3089 | ;; If there's a connection, use it and the name thus far |
| 3100 | (if sql-connection | 3090 | (if sql-connection |
| @@ -3527,7 +3517,7 @@ for each match." | |||
| 3527 | (nreverse results))) | 3517 | (nreverse results))) |
| 3528 | 3518 | ||
| 3529 | (defun sql-execute (sqlbuf outbuf command enhanced arg) | 3519 | (defun sql-execute (sqlbuf outbuf command enhanced arg) |
| 3530 | "Executes a command in a SQL interactive buffer and captures the output. | 3520 | "Execute a command in a SQL interactive buffer and capture the output. |
| 3531 | 3521 | ||
| 3532 | The commands are run in SQLBUF and the output saved in OUTBUF. | 3522 | The commands are run in SQLBUF and the output saved in OUTBUF. |
| 3533 | COMMAND must be a string, a function or a list of such elements. | 3523 | COMMAND must be a string, a function or a list of such elements. |
| @@ -3535,7 +3525,7 @@ Functions are called with SQLBUF, OUTBUF and ARG as parameters; | |||
| 3535 | strings are formatted with ARG and executed. | 3525 | strings are formatted with ARG and executed. |
| 3536 | 3526 | ||
| 3537 | If the results are empty the OUTBUF is deleted, otherwise the | 3527 | If the results are empty the OUTBUF is deleted, otherwise the |
| 3538 | buffer is popped into a view window. " | 3528 | buffer is popped into a view window." |
| 3539 | (mapc | 3529 | (mapc |
| 3540 | (lambda (c) | 3530 | (lambda (c) |
| 3541 | (cond | 3531 | (cond |
| @@ -3600,43 +3590,35 @@ The list is maintained in SQL interactive buffers.") | |||
| 3600 | 3590 | ||
| 3601 | (defvar sql-completion-sqlbuf nil) | 3591 | (defvar sql-completion-sqlbuf nil) |
| 3602 | 3592 | ||
| 3603 | (defun sql-try-completion (string collection &optional predicate) | 3593 | (defun sql--completion-table (string pred action) |
| 3604 | (when sql-completion-sqlbuf | 3594 | (when sql-completion-sqlbuf |
| 3605 | (with-current-buffer sql-completion-sqlbuf | 3595 | (with-current-buffer sql-completion-sqlbuf |
| 3606 | (let ((schema (and (string-match "\\`\\(\\sw\\(:?\\sw\\|\\s_\\)*\\)[.]" string) | 3596 | (let ((schema (and (string-match "\\`\\(\\sw\\(:?\\sw\\|\\s_\\)*\\)[.]" string) |
| 3607 | (downcase (match-string 1 string))))) | 3597 | (downcase (match-string 1 string))))) |
| 3608 | 3598 | ||
| 3609 | ;; If we haven't loaded any object name yet, load local schema | 3599 | ;; If we haven't loaded any object name yet, load local schema |
| 3610 | (unless sql-completion-object | 3600 | (unless sql-completion-object |
| 3611 | (sql-build-completions nil)) | 3601 | (sql-build-completions nil)) |
| 3612 | 3602 | ||
| 3613 | ;; If they want another schema, load it if we haven't yet | 3603 | ;; If they want another schema, load it if we haven't yet |
| 3614 | (when schema | 3604 | (when schema |
| 3615 | (let ((schema-dot (concat schema ".")) | 3605 | (let ((schema-dot (concat schema ".")) |
| 3616 | (schema-len (1+ (length schema))) | 3606 | (schema-len (1+ (length schema))) |
| 3617 | (names sql-completion-object) | 3607 | (names sql-completion-object) |
| 3618 | has-schema) | 3608 | has-schema) |
| 3619 | 3609 | ||
| 3620 | (while (and (not has-schema) names) | 3610 | (while (and (not has-schema) names) |
| 3621 | (setq has-schema (and | 3611 | (setq has-schema (and |
| 3622 | (>= (length (car names)) schema-len) | 3612 | (>= (length (car names)) schema-len) |
| 3623 | (string= schema-dot | 3613 | (string= schema-dot |
| 3624 | (downcase (substring (car names) | 3614 | (downcase (substring (car names) |
| 3625 | 0 schema-len)))) | 3615 | 0 schema-len)))) |
| 3626 | names (cdr names))) | 3616 | names (cdr names))) |
| 3627 | (unless has-schema | 3617 | (unless has-schema |
| 3628 | (sql-build-completions schema))))) | 3618 | (sql-build-completions schema))))) |
| 3629 | 3619 | ||
| 3630 | ;; Try to find the completion | 3620 | ;; Try to find the completion |
| 3631 | (cond | 3621 | (complete-with-action action sql-completion-object string pred)))) |
| 3632 | ((not predicate) | ||
| 3633 | (try-completion string sql-completion-object)) | ||
| 3634 | ((eq predicate t) | ||
| 3635 | (all-completions string sql-completion-object)) | ||
| 3636 | ((eq predicate 'lambda) | ||
| 3637 | (test-completion string sql-completion-object)) | ||
| 3638 | ((eq (car predicate) 'boundaries) | ||
| 3639 | (completion-boundaries string sql-completion-object nil (cdr predicate))))))) | ||
| 3640 | 3622 | ||
| 3641 | (defun sql-read-table-name (prompt) | 3623 | (defun sql-read-table-name (prompt) |
| 3642 | "Read the name of a database table." | 3624 | "Read the name of a database table." |
| @@ -3652,7 +3634,7 @@ The list is maintained in SQL interactive buffers.") | |||
| 3652 | (completion-ignore-case t)) | 3634 | (completion-ignore-case t)) |
| 3653 | 3635 | ||
| 3654 | (if (sql-get-product-feature product :completion-object) | 3636 | (if (sql-get-product-feature product :completion-object) |
| 3655 | (completing-read prompt (function sql-try-completion) | 3637 | (completing-read prompt #'sql--completion-table |
| 3656 | nil nil tname) | 3638 | nil nil tname) |
| 3657 | (read-from-minibuffer prompt tname)))) | 3639 | (read-from-minibuffer prompt tname)))) |
| 3658 | 3640 | ||
| @@ -3720,6 +3702,7 @@ must tell Emacs. Here's how to do that in your init file: | |||
| 3720 | (if sql-mode-menu | 3702 | (if sql-mode-menu |
| 3721 | (easy-menu-add sql-mode-menu)); XEmacs | 3703 | (easy-menu-add sql-mode-menu)); XEmacs |
| 3722 | 3704 | ||
| 3705 | ;; (smie-setup sql-smie-grammar #'sql-smie-rules) | ||
| 3723 | (set (make-local-variable 'comment-start) "--") | 3706 | (set (make-local-variable 'comment-start) "--") |
| 3724 | ;; Make each buffer in sql-mode remember the "current" SQLi buffer. | 3707 | ;; Make each buffer in sql-mode remember the "current" SQLi buffer. |
| 3725 | (make-local-variable 'sql-buffer) | 3708 | (make-local-variable 'sql-buffer) |
| @@ -3733,7 +3716,7 @@ must tell Emacs. Here's how to do that in your init file: | |||
| 3733 | (set (make-local-variable 'paragraph-separate) "[\f]*$") | 3716 | (set (make-local-variable 'paragraph-separate) "[\f]*$") |
| 3734 | (set (make-local-variable 'paragraph-start) "[\n\f]") | 3717 | (set (make-local-variable 'paragraph-start) "[\n\f]") |
| 3735 | ;; Abbrevs | 3718 | ;; Abbrevs |
| 3736 | (setq abbrev-all-caps 1) | 3719 | (setq-local abbrev-all-caps 1) |
| 3737 | ;; Contains the name of database objects | 3720 | ;; Contains the name of database objects |
| 3738 | (set (make-local-variable 'sql-contains-names) t) | 3721 | (set (make-local-variable 'sql-contains-names) t) |
| 3739 | ;; Catch changes to sql-product and highlight accordingly | 3722 | ;; Catch changes to sql-product and highlight accordingly |
| @@ -3959,13 +3942,13 @@ is specified in the connection settings." | |||
| 3959 | (setq set-params | 3942 | (setq set-params |
| 3960 | (mapcar | 3943 | (mapcar |
| 3961 | (lambda (v) | 3944 | (lambda (v) |
| 3962 | (cond | 3945 | (pcase (car v) |
| 3963 | ((eq (car v) 'sql-user) 'user) | 3946 | (`sql-user 'user) |
| 3964 | ((eq (car v) 'sql-password) 'password) | 3947 | (`sql-password 'password) |
| 3965 | ((eq (car v) 'sql-server) 'server) | 3948 | (`sql-server 'server) |
| 3966 | ((eq (car v) 'sql-database) 'database) | 3949 | (`sql-database 'database) |
| 3967 | ((eq (car v) 'sql-port) 'port) | 3950 | (`sql-port 'port) |
| 3968 | (t (car v)))) | 3951 | (s s))) |
| 3969 | (cdr connect-set))) | 3952 | (cdr connect-set))) |
| 3970 | 3953 | ||
| 3971 | ;; the remaining params (w/o the connection params) | 3954 | ;; the remaining params (w/o the connection params) |
| @@ -3984,7 +3967,7 @@ is specified in the connection settings." | |||
| 3984 | 3967 | ||
| 3985 | ;; Start the SQLi session with revised list of login parameters | 3968 | ;; Start the SQLi session with revised list of login parameters |
| 3986 | (eval `(let ((,param-var ',rem-params)) | 3969 | (eval `(let ((,param-var ',rem-params)) |
| 3987 | (sql-product-interactive sql-product new-name)))) | 3970 | (sql-product-interactive ',sql-product ',new-name)))) |
| 3988 | 3971 | ||
| 3989 | (message "SQL Connection <%s> does not exist" connection) | 3972 | (message "SQL Connection <%s> does not exist" connection) |
| 3990 | nil))) | 3973 | nil))) |
| @@ -4028,16 +4011,16 @@ optionally is saved to the user's init file." | |||
| 4028 | (if (assoc name alist) | 4011 | (if (assoc name alist) |
| 4029 | (message "Connection <%s> already exists" name) | 4012 | (message "Connection <%s> already exists" name) |
| 4030 | (setq connect | 4013 | (setq connect |
| 4031 | (append (list name) | 4014 | (cons name |
| 4032 | (sql-for-each-login | 4015 | (sql-for-each-login |
| 4033 | `(product ,@login) | 4016 | `(product ,@login) |
| 4034 | (lambda (token _plist) | 4017 | (lambda (token _plist) |
| 4035 | (cond | 4018 | (pcase token |
| 4036 | ((eq token 'product) `(sql-product ',product)) | 4019 | (`product `(sql-product ',product)) |
| 4037 | ((eq token 'user) `(sql-user ,user)) | 4020 | (`user `(sql-user ,user)) |
| 4038 | ((eq token 'database) `(sql-database ,database)) | 4021 | (`database `(sql-database ,database)) |
| 4039 | ((eq token 'server) `(sql-server ,server)) | 4022 | (`server `(sql-server ,server)) |
| 4040 | ((eq token 'port) `(sql-port ,port))))))) | 4023 | (`port `(sql-port ,port))))))) |
| 4041 | 4024 | ||
| 4042 | (setq alist (append alist (list connect))) | 4025 | (setq alist (append alist (list connect))) |
| 4043 | 4026 | ||
| @@ -4047,7 +4030,7 @@ optionally is saved to the user's init file." | |||
| 4047 | (customize-set-variable 'sql-connection-alist alist))))))) | 4030 | (customize-set-variable 'sql-connection-alist alist))))))) |
| 4048 | 4031 | ||
| 4049 | (defun sql-connection-menu-filter (tail) | 4032 | (defun sql-connection-menu-filter (tail) |
| 4050 | "Generates menu entries for using each connection." | 4033 | "Generate menu entries for using each connection." |
| 4051 | (append | 4034 | (append |
| 4052 | (mapcar | 4035 | (mapcar |
| 4053 | (lambda (conn) | 4036 | (lambda (conn) |
| @@ -4114,7 +4097,8 @@ the call to \\[sql-product-interactive] with | |||
| 4114 | new-sqli-buffer) | 4097 | new-sqli-buffer) |
| 4115 | 4098 | ||
| 4116 | ;; Get credentials. | 4099 | ;; Get credentials. |
| 4117 | (apply 'sql-get-login (sql-get-product-feature product :sqli-login)) | 4100 | (apply #'sql-get-login |
| 4101 | (sql-get-product-feature product :sqli-login)) | ||
| 4118 | 4102 | ||
| 4119 | ;; Connect to database. | 4103 | ;; Connect to database. |
| 4120 | (message "Login...") | 4104 | (message "Login...") |
| @@ -4225,7 +4209,7 @@ The default comes from `process-coding-system-alist' and | |||
| 4225 | (sql-comint product parameter))) | 4209 | (sql-comint product parameter))) |
| 4226 | 4210 | ||
| 4227 | (defun sql-oracle-save-settings (sqlbuf) | 4211 | (defun sql-oracle-save-settings (sqlbuf) |
| 4228 | "Saves most SQL*Plus settings so they may be reset by \\[sql-redirect]." | 4212 | "Save most SQL*Plus settings so they may be reset by \\[sql-redirect]." |
| 4229 | ;; Note: does not capture the following settings: | 4213 | ;; Note: does not capture the following settings: |
| 4230 | ;; | 4214 | ;; |
| 4231 | ;; APPINFO | 4215 | ;; APPINFO |
| @@ -4297,7 +4281,7 @@ The default comes from `process-coding-system-alist' and | |||
| 4297 | ;; Restore the changed settings | 4281 | ;; Restore the changed settings |
| 4298 | (sql-redirect sqlbuf saved-settings)) | 4282 | (sql-redirect sqlbuf saved-settings)) |
| 4299 | 4283 | ||
| 4300 | (defun sql-oracle-list-all (sqlbuf outbuf enhanced table-name) | 4284 | (defun sql-oracle-list-all (sqlbuf outbuf enhanced _table-name) |
| 4301 | ;; Query from USER_OBJECTS or ALL_OBJECTS | 4285 | ;; Query from USER_OBJECTS or ALL_OBJECTS |
| 4302 | (let ((settings (sql-oracle-save-settings sqlbuf)) | 4286 | (let ((settings (sql-oracle-save-settings sqlbuf)) |
| 4303 | (simple-sql | 4287 | (simple-sql |
| @@ -4336,7 +4320,7 @@ The default comes from `process-coding-system-alist' and | |||
| 4336 | 4320 | ||
| 4337 | (sql-oracle-restore-settings sqlbuf settings))) | 4321 | (sql-oracle-restore-settings sqlbuf settings))) |
| 4338 | 4322 | ||
| 4339 | (defun sql-oracle-list-table (sqlbuf outbuf enhanced table-name) | 4323 | (defun sql-oracle-list-table (sqlbuf outbuf _enhanced table-name) |
| 4340 | "Implements :list-table under Oracle." | 4324 | "Implements :list-table under Oracle." |
| 4341 | (let ((settings (sql-oracle-save-settings sqlbuf))) | 4325 | (let ((settings (sql-oracle-save-settings sqlbuf))) |
| 4342 | 4326 | ||
| @@ -4413,15 +4397,17 @@ The default comes from `process-coding-system-alist' and | |||
| 4413 | "Create comint buffer and connect to Sybase." | 4397 | "Create comint buffer and connect to Sybase." |
| 4414 | ;; Put all parameters to the program (if defined) in a list and call | 4398 | ;; Put all parameters to the program (if defined) in a list and call |
| 4415 | ;; make-comint. | 4399 | ;; make-comint. |
| 4416 | (let ((params options)) | 4400 | (let ((params |
| 4417 | (if (not (string= "" sql-server)) | 4401 | (append |
| 4418 | (setq params (append (list "-S" sql-server) params))) | 4402 | (if (not (string= "" sql-user)) |
| 4419 | (if (not (string= "" sql-database)) | 4403 | (list "-U" sql-user)) |
| 4420 | (setq params (append (list "-D" sql-database) params))) | 4404 | (if (not (string= "" sql-password)) |
| 4421 | (if (not (string= "" sql-password)) | 4405 | (list "-P" sql-password)) |
| 4422 | (setq params (append (list "-P" sql-password) params))) | 4406 | (if (not (string= "" sql-database)) |
| 4423 | (if (not (string= "" sql-user)) | 4407 | (list "-D" sql-database)) |
| 4424 | (setq params (append (list "-U" sql-user) params))) | 4408 | (if (not (string= "" sql-server)) |
| 4409 | (list "-S" sql-server)) | ||
| 4410 | options))) | ||
| 4425 | (sql-comint product params))) | 4411 | (sql-comint product params))) |
| 4426 | 4412 | ||
| 4427 | 4413 | ||
| @@ -4506,14 +4492,13 @@ The default comes from `process-coding-system-alist' and | |||
| 4506 | "Create comint buffer and connect to SQLite." | 4492 | "Create comint buffer and connect to SQLite." |
| 4507 | ;; Put all parameters to the program (if defined) in a list and call | 4493 | ;; Put all parameters to the program (if defined) in a list and call |
| 4508 | ;; make-comint. | 4494 | ;; make-comint. |
| 4509 | (let ((params)) | 4495 | (let ((params |
| 4510 | (if (not (string= "" sql-database)) | 4496 | (append options |
| 4511 | (setq params (append (list (expand-file-name sql-database)) | 4497 | (if (not (string= "" sql-database)) |
| 4512 | params))) | 4498 | `(,(expand-file-name sql-database)))))) |
| 4513 | (setq params (append options params)) | ||
| 4514 | (sql-comint product params))) | 4499 | (sql-comint product params))) |
| 4515 | 4500 | ||
| 4516 | (defun sql-sqlite-completion-object (sqlbuf schema) | 4501 | (defun sql-sqlite-completion-object (sqlbuf _schema) |
| 4517 | (sql-redirect-value sqlbuf ".tables" "\\sw\\(?:\\sw\\|\\s_\\)*" 0)) | 4502 | (sql-redirect-value sqlbuf ".tables" "\\sw\\(?:\\sw\\|\\s_\\)*" 0)) |
| 4518 | 4503 | ||
| 4519 | 4504 | ||
| @@ -4556,18 +4541,19 @@ The default comes from `process-coding-system-alist' and | |||
| 4556 | "Create comint buffer and connect to MySQL." | 4541 | "Create comint buffer and connect to MySQL." |
| 4557 | ;; Put all parameters to the program (if defined) in a list and call | 4542 | ;; Put all parameters to the program (if defined) in a list and call |
| 4558 | ;; make-comint. | 4543 | ;; make-comint. |
| 4559 | (let ((params)) | 4544 | (let ((params |
| 4560 | (if (not (string= "" sql-database)) | 4545 | (append |
| 4561 | (setq params (append (list sql-database) params))) | 4546 | options |
| 4562 | (if (not (string= "" sql-server)) | 4547 | (if (not (string= "" sql-user)) |
| 4563 | (setq params (append (list (concat "--host=" sql-server)) params))) | 4548 | (list (concat "--user=" sql-user))) |
| 4564 | (if (not (= 0 sql-port)) | 4549 | (if (not (string= "" sql-password)) |
| 4565 | (setq params (append (list (concat "--port=" (number-to-string sql-port))) params))) | 4550 | (list (concat "--password=" sql-password))) |
| 4566 | (if (not (string= "" sql-password)) | 4551 | (if (not (= 0 sql-port)) |
| 4567 | (setq params (append (list (concat "--password=" sql-password)) params))) | 4552 | (list (concat "--port=" (number-to-string sql-port)))) |
| 4568 | (if (not (string= "" sql-user)) | 4553 | (if (not (string= "" sql-server)) |
| 4569 | (setq params (append (list (concat "--user=" sql-user)) params))) | 4554 | (list (concat "--host=" sql-server))) |
| 4570 | (setq params (append options params)) | 4555 | (if (not (string= "" sql-database)) |
| 4556 | (list sql-database))))) | ||
| 4571 | (sql-comint product params))) | 4557 | (sql-comint product params))) |
| 4572 | 4558 | ||
| 4573 | 4559 | ||
| @@ -4607,13 +4593,15 @@ The default comes from `process-coding-system-alist' and | |||
| 4607 | "Create comint buffer and connect to Solid." | 4593 | "Create comint buffer and connect to Solid." |
| 4608 | ;; Put all parameters to the program (if defined) in a list and call | 4594 | ;; Put all parameters to the program (if defined) in a list and call |
| 4609 | ;; make-comint. | 4595 | ;; make-comint. |
| 4610 | (let ((params options)) | 4596 | (let ((params |
| 4611 | ;; It only makes sense if both username and password are there. | 4597 | (append |
| 4612 | (if (not (or (string= "" sql-user) | 4598 | (if (not (string= "" sql-server)) |
| 4613 | (string= "" sql-password))) | 4599 | (list sql-server)) |
| 4614 | (setq params (append (list sql-user sql-password) params))) | 4600 | ;; It only makes sense if both username and password are there. |
| 4615 | (if (not (string= "" sql-server)) | 4601 | (if (not (or (string= "" sql-user) |
| 4616 | (setq params (append (list sql-server) params))) | 4602 | (string= "" sql-password))) |
| 4603 | (list sql-user sql-password)) | ||
| 4604 | options))) | ||
| 4617 | (sql-comint product params))) | 4605 | (sql-comint product params))) |
| 4618 | 4606 | ||
| 4619 | 4607 | ||
| @@ -4695,22 +4683,25 @@ The default comes from `process-coding-system-alist' and | |||
| 4695 | "Create comint buffer and connect to Microsoft SQL Server." | 4683 | "Create comint buffer and connect to Microsoft SQL Server." |
| 4696 | ;; Put all parameters to the program (if defined) in a list and call | 4684 | ;; Put all parameters to the program (if defined) in a list and call |
| 4697 | ;; make-comint. | 4685 | ;; make-comint. |
| 4698 | (let ((params options)) | 4686 | (let ((params |
| 4699 | (if (not (string= "" sql-server)) | 4687 | (append |
| 4700 | (setq params (append (list "-S" sql-server) params))) | 4688 | (if (not (string= "" sql-user)) |
| 4701 | (if (not (string= "" sql-database)) | 4689 | (list "-U" sql-user)) |
| 4702 | (setq params (append (list "-d" sql-database) params))) | 4690 | (if (not (string= "" sql-database)) |
| 4703 | (if (not (string= "" sql-user)) | 4691 | (list "-d" sql-database)) |
| 4704 | (setq params (append (list "-U" sql-user) params))) | 4692 | (if (not (string= "" sql-server)) |
| 4705 | (if (not (string= "" sql-password)) | 4693 | (list "-S" sql-server)) |
| 4706 | (setq params (append (list "-P" sql-password) params)) | 4694 | options))) |
| 4707 | (if (string= "" sql-user) | 4695 | (setq params |
| 4708 | ;; if neither user nor password is provided, use system | 4696 | (if (not (string= "" sql-password)) |
| 4709 | ;; credentials. | 4697 | `("-P" ,sql-password ,@params) |
| 4710 | (setq params (append (list "-E") params)) | 4698 | (if (string= "" sql-user) |
| 4711 | ;; If -P is passed to ISQL as the last argument without a | 4699 | ;; If neither user nor password is provided, use system |
| 4712 | ;; password, it's considered null. | 4700 | ;; credentials. |
| 4713 | (setq params (append params (list "-P"))))) | 4701 | `("-E" ,@params) |
| 4702 | ;; If -P is passed to ISQL as the last argument without a | ||
| 4703 | ;; password, it's considered null. | ||
| 4704 | `(,@params "-P")))) | ||
| 4714 | (sql-comint product params))) | 4705 | (sql-comint product params))) |
| 4715 | 4706 | ||
| 4716 | 4707 | ||
| @@ -4754,48 +4745,58 @@ Try to set `comint-output-filter-functions' like this: | |||
| 4754 | 4745 | ||
| 4755 | (defun sql-comint-postgres (product options) | 4746 | (defun sql-comint-postgres (product options) |
| 4756 | "Create comint buffer and connect to Postgres." | 4747 | "Create comint buffer and connect to Postgres." |
| 4757 | ;; username and password are ignored. Mark Stosberg suggest to add | 4748 | ;; username and password are ignored. Mark Stosberg suggests to add |
| 4758 | ;; the database at the end. Jason Beegan suggest using --pset and | 4749 | ;; the database at the end. Jason Beegan suggests using --pset and |
| 4759 | ;; pager=off instead of \\o|cat. The later was the solution by | 4750 | ;; pager=off instead of \\o|cat. The later was the solution by |
| 4760 | ;; Gregor Zych. Jason's suggestion is the default value for | 4751 | ;; Gregor Zych. Jason's suggestion is the default value for |
| 4761 | ;; sql-postgres-options. | 4752 | ;; sql-postgres-options. |
| 4762 | (let ((params options)) | 4753 | (let ((params |
| 4763 | (if (not (string= "" sql-database)) | 4754 | (append |
| 4764 | (setq params (append params (list sql-database)))) | 4755 | (if (not (= 0 sql-port)) |
| 4765 | (if (not (string= "" sql-server)) | 4756 | (list "-p" (number-to-string sql-port))) |
| 4766 | (setq params (append (list "-h" sql-server) params))) | 4757 | (if (not (string= "" sql-user)) |
| 4767 | (if (not (string= "" sql-user)) | 4758 | (list "-U" sql-user)) |
| 4768 | (setq params (append (list "-U" sql-user) params))) | 4759 | (if (not (string= "" sql-server)) |
| 4769 | (if (not (= 0 sql-port)) | 4760 | (list "-h" sql-server)) |
| 4770 | (setq params (append (list "-p" (number-to-string sql-port)) params))) | 4761 | options |
| 4762 | (if (not (string= "" sql-database)) | ||
| 4763 | (list sql-database))))) | ||
| 4771 | (sql-comint product params))) | 4764 | (sql-comint product params))) |
| 4772 | 4765 | ||
| 4773 | (defun sql-postgres-completion-object (sqlbuf schema) | 4766 | (defun sql-postgres-completion-object (sqlbuf schema) |
| 4774 | (let (cl re fs a r) | 4767 | (sql-redirect sqlbuf "\\t on") |
| 4775 | (sql-redirect sqlbuf "\\t on") | 4768 | (let ((aligned |
| 4776 | (setq a (car (sql-redirect-value sqlbuf "\\a" "Output format is \\(.*\\)[.]$" 1))) | 4769 | (string= "aligned" |
| 4777 | (when (string= a "aligned") | 4770 | (car (sql-redirect-value |
| 4778 | (sql-redirect sqlbuf "\\a")) | 4771 | sqlbuf "\\a" |
| 4779 | (setq fs (or (car (sql-redirect-value sqlbuf "\\f" "Field separator is \"\\(.\\)[.]$" 1)) "|")) | 4772 | "Output format is \\(.*\\)[.]$" 1))))) |
| 4780 | 4773 | (when aligned | |
| 4781 | (setq re (concat "^\\([^" fs "]*\\)" fs "\\([^" fs "]*\\)" fs "[^" fs "]*" fs "[^" fs "]*$")) | ||
| 4782 | (setq cl (if (not schema) | ||
| 4783 | (sql-redirect-value sqlbuf "\\d" re '(1 2)) | ||
| 4784 | (append (sql-redirect-value sqlbuf (format "\\dt %s.*" schema) re '(1 2)) | ||
| 4785 | (sql-redirect-value sqlbuf (format "\\dv %s.*" schema) re '(1 2)) | ||
| 4786 | (sql-redirect-value sqlbuf (format "\\ds %s.*" schema) re '(1 2))))) | ||
| 4787 | |||
| 4788 | ;; Restore tuples and alignment to what they were | ||
| 4789 | (sql-redirect sqlbuf "\\t off") | ||
| 4790 | (when (not (string= a "aligned")) | ||
| 4791 | (sql-redirect sqlbuf "\\a")) | 4774 | (sql-redirect sqlbuf "\\a")) |
| 4792 | 4775 | (let* ((fs (or (car (sql-redirect-value | |
| 4793 | ;; Return the list of table names (public schema name can be omitted) | 4776 | sqlbuf "\\f" "Field separator is \"\\(.\\)[.]$" 1)) |
| 4794 | (mapcar (lambda (tbl) | 4777 | "|")) |
| 4795 | (if (string= (car tbl) "public") | 4778 | (re (concat "^\\([^" fs "]*\\)" fs "\\([^" fs "]*\\)" |
| 4796 | (cadr tbl) | 4779 | fs "[^" fs "]*" fs "[^" fs "]*$")) |
| 4797 | (format "%s.%s" (car tbl) (cadr tbl)))) | 4780 | (cl (if (not schema) |
| 4798 | cl))) | 4781 | (sql-redirect-value sqlbuf "\\d" re '(1 2)) |
| 4782 | (append (sql-redirect-value | ||
| 4783 | sqlbuf (format "\\dt %s.*" schema) re '(1 2)) | ||
| 4784 | (sql-redirect-value | ||
| 4785 | sqlbuf (format "\\dv %s.*" schema) re '(1 2)) | ||
| 4786 | (sql-redirect-value | ||
| 4787 | sqlbuf (format "\\ds %s.*" schema) re '(1 2)))))) | ||
| 4788 | |||
| 4789 | ;; Restore tuples and alignment to what they were. | ||
| 4790 | (sql-redirect sqlbuf "\\t off") | ||
| 4791 | (when (not aligned) | ||
| 4792 | (sql-redirect sqlbuf "\\a")) | ||
| 4793 | |||
| 4794 | ;; Return the list of table names (public schema name can be omitted) | ||
| 4795 | (mapcar (lambda (tbl) | ||
| 4796 | (if (string= (car tbl) "public") | ||
| 4797 | (cadr tbl) | ||
| 4798 | (format "%s.%s" (car tbl) (cadr tbl)))) | ||
| 4799 | cl)))) | ||
| 4799 | 4800 | ||
| 4800 | 4801 | ||
| 4801 | 4802 | ||
| @@ -4834,13 +4835,15 @@ The default comes from `process-coding-system-alist' and | |||
| 4834 | "Create comint buffer and connect to Interbase." | 4835 | "Create comint buffer and connect to Interbase." |
| 4835 | ;; Put all parameters to the program (if defined) in a list and call | 4836 | ;; Put all parameters to the program (if defined) in a list and call |
| 4836 | ;; make-comint. | 4837 | ;; make-comint. |
| 4837 | (let ((params options)) | 4838 | (let ((params |
| 4838 | (if (not (string= "" sql-user)) | 4839 | (append |
| 4839 | (setq params (append (list "-u" sql-user) params))) | 4840 | (if (not (string= "" sql-database)) |
| 4840 | (if (not (string= "" sql-password)) | 4841 | (list sql-database)) ; Add to the front! |
| 4841 | (setq params (append (list "-p" sql-password) params))) | 4842 | (if (not (string= "" sql-password)) |
| 4842 | (if (not (string= "" sql-database)) | 4843 | (list "-p" sql-password)) |
| 4843 | (setq params (cons sql-database params))) ; add to the front! | 4844 | (if (not (string= "" sql-user)) |
| 4845 | (list "-u" sql-user)) | ||
| 4846 | options))) | ||
| 4844 | (sql-comint product params))) | 4847 | (sql-comint product params))) |
| 4845 | 4848 | ||
| 4846 | 4849 | ||
| @@ -4922,19 +4925,18 @@ buffer. | |||
| 4922 | "Create comint buffer and connect to Linter." | 4925 | "Create comint buffer and connect to Linter." |
| 4923 | ;; Put all parameters to the program (if defined) in a list and call | 4926 | ;; Put all parameters to the program (if defined) in a list and call |
| 4924 | ;; make-comint. | 4927 | ;; make-comint. |
| 4925 | (let ((params options) | 4928 | (let* ((login |
| 4926 | (login nil) | 4929 | (if (not (string= "" sql-user)) |
| 4927 | (old-mbx (getenv "LINTER_MBX"))) | 4930 | (concat sql-user "/" sql-password))) |
| 4928 | (if (not (string= "" sql-user)) | 4931 | (params |
| 4929 | (setq login (concat sql-user "/" sql-password))) | 4932 | (append |
| 4930 | (setq params (append (list "-u" login) params)) | 4933 | (if (not (string= "" sql-server)) |
| 4931 | (if (not (string= "" sql-server)) | 4934 | (list "-n" sql-server)) |
| 4932 | (setq params (append (list "-n" sql-server) params))) | 4935 | (list "-u" login) |
| 4933 | (if (string= "" sql-database) | 4936 | options))) |
| 4934 | (setenv "LINTER_MBX" nil) | 4937 | (cl-letf (((getenv "LINTER_MBX") |
| 4935 | (setenv "LINTER_MBX" sql-database)) | 4938 | (unless (string= "" sql-database) sql-database))) |
| 4936 | (sql-comint product params) | 4939 | (sql-comint product params)))) |
| 4937 | (setenv "LINTER_MBX" old-mbx))) | ||
| 4938 | 4940 | ||
| 4939 | 4941 | ||
| 4940 | 4942 | ||